Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Add Comment
Please, Sign In to add comment