Created
June 12, 2009 21:13
-
-
Save kbuckler/128925 to your computer and use it in GitHub Desktop.
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/ruby | |
require 'net/imap' | |
require 'date' | |
require 'rubygems' | |
require 'active_support/core_ext/array/grouping' | |
include ActiveSupport::CoreExtensions::Array::Grouping | |
mailbox = "Inbox/Cron" | |
host = '' | |
port = 143 | |
username = '' | |
password = '' | |
conn = Net::IMAP.new(host, port) | |
conn.login(username, password) | |
conn.select(mailbox) | |
date = (Date.today - 10).strftime("%e-%b-%Y") | |
msg_ids = conn.search(["SUBJECT", "Cron", "SINCE", date ]) | |
msg_ids.reverse! | |
puts "Found #{msg_ids.length} messages in #{mailbox} since #{date}" | |
puts "First subject line: #{conn.fetch(msg_ids.first, "BODY[HEADER.FIELDS (SUBJECT)]")}" | |
flags = [:Seen, :Deleted] | |
msg_ids.in_groups_of(200) do |msg_group| | |
conn.store(msg_group.compact, "+FLAGS", flags) | |
conn.expunge | |
end | |
conn.expunge | |
conn.logout |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment