Last active
December 10, 2015 23:18
-
-
Save dux/4507955 to your computer and use it in GitHub Desktop.
read Gmail email like a boss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/mikel/mail | |
require 'rubygems' | |
require 'gmail' | |
require 'mail' | |
gmail = Gmail.new('[email protected]', 'pass') | |
inbox = gmail.mailbox('inbox') | |
for m in inbox.emails | |
mail = Mail.read_from_string m.message | |
p "subject: #{mail.subject}" | |
p "from: #{mail.from[0]}" | |
p "to: #{mail.to[0]}" | |
mail.attachments.each do | attachment | | |
filename = attachment.filename | |
begin | |
File.open('files/' + filename, "w+b", 0644) {|f| f.write attachment.body.decoded} | |
rescue Exception => e | |
puts "Unable to save data for #{filename} because #{e.message}" | |
end | |
end | |
exit | |
end | |
gmail.logout | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment