Skip to content

Instantly share code, notes, and snippets.

@kymair
Created December 18, 2012 09:07
Show Gist options
  • Save kymair/4326424 to your computer and use it in GitHub Desktop.
Save kymair/4326424 to your computer and use it in GitHub Desktop.
Handy Ruby script to empty IMAP mailbox
#!/usr/bin/env ruby
MAILBOXES = ['INBOX', 'Deleted Items']
SERVER = 'server'
USERNAME = 'username'
PASSWORD = 'password'
require 'net/imap'
imap = Net::IMAP.new(SERVER)
imap.login(USERNAME, PASSWORD)
MAILBOXES.each do |mailbox|
imap.select(mailbox)
imap.uid_search('ALL').each_slice(200) {|uids| imap.uid_store(uids, "+FLAGS", [:Deleted]) }
imap.expunge
puts "Mailbox \"#{mailbox}\" is now empty."
end
imap.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment