Created
December 18, 2012 09:07
-
-
Save kymair/4326424 to your computer and use it in GitHub Desktop.
Handy Ruby script to empty IMAP mailbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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