Skip to content

Instantly share code, notes, and snippets.

@motdotla
Created November 19, 2008 01:31
Show Gist options
  • Save motdotla/26368 to your computer and use it in GitHub Desktop.
Save motdotla/26368 to your computer and use it in GitHub Desktop.
# default rails environment to development
ENV['RAILS_ENV'] ||= 'development'
# require rails environment file which basically "boots" up rails for this script
require File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')
require 'net/imap'
require 'net/http'
# mail.yml is the imap config for the email account (ie: username, host, etc.)
config = YAML.load(File.read(File.join(RAILS_ROOT, 'config', 'mail.yml')))
# make a connection to imap account
imap = Net::IMAP.new(config['host'], config['port'], true)
imap.login(config['username'], config['password'])
# select inbox as our mailbox to process
imap.select('Inbox')
# get all emails that are in inbox that have not been deleted
imap.uid_search(["NOT", "DELETED"]).each do |uid|
# fetches the straight up source of the email for tmail to parse
source = imap.uid_fetch(uid, ['RFC822']).first.attr['RFC822']
# comment = Comment.new_from_email(source)
mail = TMail::Mail.parse(source)
puts mail.to
puts mail.from
puts mail.subject
puts mail.body #.split("\n\n").first
# there isn't move in imap so we copy to new mailbox and then delete from inbox
imap.uid_copy(uid, "[Gmail]/All Mail")
imap.uid_store(uid, "+FLAGS", [:Deleted])
end
# expunge removes the deleted emails
imap.expunge
imap.logout
imap.disconnect
lincoln:tasks scottmotte$ ruby mail_fetcher.rb
[email protected]
[email protected]
Gmail is different. Here's what you need to know.
Messages that are easy to find, an inbox that organizes itself, great
spam-fighting tools and built-in chat. Sound cool? Welcome to Gmail.
To get started, you may want to:
- Learn about some of Gmail's unique features on the Getting
Started page<http://mail.google.com/mail/help/intl/en/start.html#utm_source=wel&utm_medium=wel&utm_campaign=en>.
- Follow our Switching
Guide<http://mail.google.com/support/bin/static.py?page=switchguide.html&switch=1&hl=en&utm_source=wel&utm_medium=wel&utm_campaign=en>to
learn how to announce your new Gmail address, import your contacts,
and
forward your email from Yahoo! Mail, Outlook, Hotmail, and others.
- Set up your mobile
phone<http://mail.google.com/support/bin/answer.py?answer=31623&hl=en&utm_source=wel&utm_medium=wel&utm_campaign=en>to
get super-fast access to Gmail.
- Visit our Help
Center<http://mail.google.com/support?hl=en&utm_source=wel&utm_medium=wel&utm_campaign=en>to
find specific answers to all your questions.
Users have often told us that the more they use Gmail, the more they
discover its benefits. So go ahead and give it a try. We'll keep working on
making Gmail the best email service around, and we appreciate your joining
us for the ride.
Thanks,
The Gmail Team
<html>
<font face="Arial, Helvetica, sans-serif">
<p>Messages that are easy to find, an inbox that organizes itself, great
spam-fighting tools and built-in chat. Sound cool? Welcome to Gmail.</p>
<p>To get started, you may want to:</p>
<ul>
<li>Learn about some of Gmail's unique features on the
<a href="http://mail.google.com/mail/help/intl/en/start.html#utm_source=wel&utm_medium=wel&utm_campaign=en">
Getting Started page</a>.
</li>
<li>Follow our <a href="http://mail.google.com/support/bin/static.py?page=switchguide.html&switch=1&hl=en&utm_source=wel&utm_medium=wel&utm_campaign=en">
Switching Guide</a> to learn how to announce your new Gmail address, import your contacts, and forward your email from Yahoo! Mail, Outlook, Hotmail, and others.
</li>
<li><a href="http://mail.google.com/support/bin/answer.py?answer=31623&hl=en&utm_source=wel&utm_medium=wel&utm_campaign=en">
Set up your mobile phone</a> to get super-fast access to Gmail.
</li>
<li>Visit our <a href="http://mail.google.com/support?hl=en&utm_source=wel&utm_medium=wel&utm_campaign=en">
Help Center</a> to find specific answers to all your questions.
</li>
</ul>
<p>Users have often told us that the more they use Gmail, the more they discover
its benefits. So go ahead and give it a try. We'll keep working on making Gmail
the best email service around, and we appreciate your joining us for the ride.
</p>
<p>Thanks,</p>
<p>The Gmail Team</p>
</font>
</html>
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment