Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /opt/local/bin/ruby
- require "net/imap"
- mail_server = ""
- puts "Enter Mail server :"
- mail_server = gets.rstrip!
- # ===========================
- # Username and Password
- user = Hash.new
- user[:name] = ""
- user[:password] = ""
- puts "Enter Mailbox username :"
- user[:name] = gets.rstrip!
- puts "Enter Mailbox password :"
- user[:password] = gets.rstrip!
- # ===========================
- imap = Net::IMAP.new(mail_server)
- #imap.authenticate('CRAM-MD5', user[:name], user[:password])
- imap.authenticate('CRAM-MD5', user[:name], user[:password])
- # examine prepares the messages in a mailbox for use
- imap.examine('INBOX')
- stat = imap.status("inbox", ["MESSAGES", "RECENT", "UNSEEN"])
- # => {"RECENT"=>0, "MESSAGES"=>44}
- puts stat.inspect
- puts "Message Count : " + stat["MESSAGES"].to_s
- puts "Unseen Count : " + stat["UNSEEN"].to_s
- # search for desired messages
- imap.search(["NOT","SEEN"]).each do |message_id|
- puts message_id.to_s
- # goal of this script was to make phantom unseen disappear in Mail.app
- # future improvement would be to delete these phantom (spam) messages
- # that have no body/subject and freak Mail.app out
- # fetching the message has the side effect of marking it as seen...
- msg = imap.fetch(message_id, "UID")
- puts msg.inspect
- puts msg.attr["UID"]
- end
- # exit nicely
- imap.close
- imap.disconnect
Add Comment
Please, Sign In to add comment