Created
June 8, 2010 17:21
-
-
Save mcansky/430337 to your computer and use it in GitHub Desktop.
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
| #!/bin/env ruby | |
| require 'net/imap' | |
| require 'rubygems' | |
| require 'mail' | |
| email = '####' | |
| server = 'imap.gmail.com' | |
| port = 993 | |
| ssl = true | |
| password = '####' | |
| imap = Net::IMAP.new(server,port,ssl) | |
| imap.login(email,password) | |
| imap.select('INBOX') | |
| imap.search(["ALL"]).each do |message_id| | |
| # message_id is id of the mail in the box used to grab it later | |
| #puts message_id.inspect | |
| # grabbing the message | |
| envelope = imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"] | |
| # enveloppe data | |
| # => ` from (Array) | |
| # => ` name (String) | |
| # => ` mailbox (String) | |
| # => ` host (String) | |
| # => ` sender (Array) | |
| # => ` name (String) | |
| # => ` mailbox (String) | |
| # => ` reply-to | |
| # => ` name (String) | |
| # => ` mailbox (String) | |
| # => ` host (String) | |
| # => ` to | |
| # => ` name (String) | |
| # => ` mailbox (String) | |
| # => ` host (String) | |
| # => ` cc | |
| # => ` name (String) | |
| # => ` mailbox (String) | |
| # => ` host (String) | |
| # => ` bcc | |
| # => ` name (String) | |
| # => ` mailbox (String) | |
| # => ` host (String) | |
| # => ` subject (String) | |
| # => ` message_id (String) | |
| #printf("#{message_id} : #{envelope.subject} from #{envelope.sender[0].mailbox}@#{envelope.sender[0].host} to #{envelope.to[0].mailbox}@#{envelope.to[0].host}, MID : #{envelope.message_id}\n") | |
| source = imap.fetch(message_id, "BODY[]").first.attr['BODY[]'] | |
| #puts source.inspect | |
| mail = Mail.read(source) | |
| puts mail.inspect | |
| end | |
| imap.logout() | |
| #imap.disconnect() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment