Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. require 'gmail'
  2. require'colorize'
  3. require 'io/console'
  4.  
  5. print 'Enter your email address: '.yellow
  6. username = gets
  7. print 'Enter your Gmail password: '.yellow
  8. password = STDIN.noecho(&:gets)
  9.  
  10. def mail_actions(mail)
  11. print 'Enter R to mark them as read, D to delete or Q to quit: '.yellow
  12.  
  13. action = gets.chomp
  14. action.upcase!
  15. unread = mail.inbox.find(:unread)
  16.  
  17. case action
  18. when 'D'
  19. unread.each { |email| email.delete! }
  20. puts 'All unread messages are successfully deleted.'.green
  21. when 'R'
  22. unread.each { |email| email.read! }
  23. puts 'All unread messages are succesfully marked as read.'.green
  24. when 'Q'
  25. puts 'Program exits now.'.light_blue
  26. exit(0)
  27. else
  28. puts 'Invalid option, try again.'.red
  29. mail_actions(mail)
  30. end
  31. end
  32.  
  33.  
  34. Gmail.connect(username, password) do |gmail|
  35. if gmail.logged_in?
  36. puts "\n#{Time.now}".light_blue
  37. puts 'Logged in successfully.'.green
  38. puts "You've got #{gmail.inbox.count(:unread)} unread messages.".light_blue
  39. mail_actions(gmail)
  40. else
  41. puts 'Failed to connect, exiting now.'.red
  42. end
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement