Guest User

Untitled

a guest
Feb 20th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #! /opt/local/bin/ruby
  2.  
  3. require "net/imap"
  4.  
  5. mail_server = ""
  6. puts "Enter Mail server :"
  7. mail_server = gets.rstrip!
  8.  
  9. # ===========================
  10. # Username and Password
  11. user = Hash.new
  12. user[:name] = ""
  13. user[:password] = ""
  14.  
  15. puts "Enter Mailbox username :"
  16. user[:name] = gets.rstrip!
  17.  
  18. puts "Enter Mailbox password :"
  19. user[:password] = gets.rstrip!
  20. # ===========================
  21.  
  22. imap = Net::IMAP.new(mail_server)
  23.  
  24. #imap.authenticate('CRAM-MD5', user[:name], user[:password])
  25. imap.authenticate('CRAM-MD5', user[:name], user[:password])
  26.  
  27. # examine prepares the messages in a mailbox for use
  28. imap.examine('INBOX')
  29.  
  30. stat = imap.status("inbox", ["MESSAGES", "RECENT", "UNSEEN"])
  31. # => {"RECENT"=>0, "MESSAGES"=>44}
  32. puts stat.inspect
  33. puts "Message Count : " + stat["MESSAGES"].to_s
  34. puts "Unseen Count : " + stat["UNSEEN"].to_s
  35.  
  36. # search for desired messages
  37. imap.search(["NOT","SEEN"]).each do |message_id|
  38. puts message_id.to_s
  39. # goal of this script was to make phantom unseen disappear in Mail.app
  40. # future improvement would be to delete these phantom (spam) messages
  41. # that have no body/subject and freak Mail.app out
  42. # fetching the message has the side effect of marking it as seen...
  43. msg = imap.fetch(message_id, "UID")
  44. puts msg.inspect
  45. puts msg.attr["UID"]
  46. end
  47.  
  48.  
  49. # exit nicely
  50. imap.close
  51. imap.disconnect
Add Comment
Please, Sign In to add comment