Guest User

Untitled

a guest
Jun 10th, 2018
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #!/usr/bin/ruby1.9
  2.  
  3. accounts = [{ :name => 'example',
  4. :server => 'mail.example.com',
  5. :username => 'user@example.com',
  6. :password => 'MySecretPassword',
  7. :method => 'PLAIN' }
  8.  
  9. ]
  10.  
  11. require 'net/imap'
  12.  
  13. def check_mails(account)
  14. imap = Net::IMAP.new(account[:server])
  15. imap.authenticate(account[:method], account[:username], account[:password])
  16. imap.examine('INBOX')
  17. unread = 0
  18. imap.search(["UNSEEN"]).each do |message_id|
  19. unread += 1
  20. status = imap.status("INBOX", ["MESSAGES"])
  21. puts "#{account[:name].capitalize}: #{unread}/#{status["MESSAGES"].to_s}"
  22. imap.disconnect
  23. end
  24.  
  25. accounts.each { |a| check_mails(a) }
Add Comment
Please, Sign In to add comment