Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'gmail'
- require'colorize'
- require 'io/console'
- print 'Enter your email address: '.yellow
- username = gets
- print 'Enter your Gmail password: '.yellow
- password = STDIN.noecho(&:gets)
- def mail_actions(mail)
- print 'Enter R to mark them as read, D to delete or Q to quit: '.yellow
- action = gets.chomp
- action.upcase!
- unread = mail.inbox.find(:unread)
- case action
- when 'D'
- unread.each { |email| email.delete! }
- puts 'All unread messages are successfully deleted.'.green
- when 'R'
- unread.each { |email| email.read! }
- puts 'All unread messages are succesfully marked as read.'.green
- when 'Q'
- puts 'Program exits now.'.light_blue
- exit(0)
- else
- puts 'Invalid option, try again.'.red
- mail_actions(mail)
- end
- end
- Gmail.connect(username, password) do |gmail|
- if gmail.logged_in?
- puts "\n#{Time.now}".light_blue
- puts 'Logged in successfully.'.green
- puts "You've got #{gmail.inbox.count(:unread)} unread messages.".light_blue
- mail_actions(gmail)
- else
- puts 'Failed to connect, exiting now.'.red
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement