Last active
July 19, 2018 09:23
-
-
Save nabe256/e9a13c09bb9bae7ca578b5a4941c122d to your computer and use it in GitHub Desktop.
move all messages (ruby: net/imap)
This file contains hidden or 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
require 'net/imap' | |
imap = Net::IMAP.new('example.com') | |
imap.authenticate('LOGIN', '[email protected]', 'password') | |
imap.select('INBOX') | |
if not imap.list('INBOX', 'testfolder') | |
imap.create('INBOX.testfolder') | |
end | |
imap.expunge | |
imap.uid_search(["FROM", "[email protected]"]).each_with_index do |message_id, i| | |
puts(message_id) | |
imap.uid_copy(message_id, "INBOX.testfolder") | |
imap.uid_store(message_id, "+FLAGS", [:Deleted]) | |
if i % 100 == 0 | |
imap.expunge | |
end | |
end | |
imap.expunge | |
imap.logout |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment