Skip to content

Instantly share code, notes, and snippets.

@nabe256
Last active July 19, 2018 09:23
Show Gist options
  • Save nabe256/e9a13c09bb9bae7ca578b5a4941c122d to your computer and use it in GitHub Desktop.
Save nabe256/e9a13c09bb9bae7ca578b5a4941c122d to your computer and use it in GitHub Desktop.
move all messages (ruby: net/imap)
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