Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@twada
Created September 13, 2008 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twada/10564 to your computer and use it in GitHub Desktop.
Save twada/10564 to your computer and use it in GitHub Desktop.
#
# usage: ruby this_script.rb | git am --3way
#
require 'net/imap'
require 'rubygems'
require 'activesupport'
id = 'your.gmail.id'
pass = 'your.gmail.pass'
imap = Net::IMAP.new('imap.gmail.com', 993, true)
imap.login(id, pass)
begin
# select(read-only), examine(read-write)
imap.select('INBOX')
# search INBOX with criteria
criteria = []
criteria << 'SUBJECT' << '[PATCH]'
criteria << 'NOT' << 'ANSWERED'
criteria << 'SINCE' << 2.days.ago.strftime('%d-%b-%Y')
message_ids = imap.search(criteria)
exit(1) if message_ids.empty?
# TODO: how about multiple patch mails? reverse_each?
data = imap.fetch(message_ids[0], 'RFC822')
plain_mail = data[0].attr['RFC822'].gsub(/\r$/, '')
puts plain_mail
ensure
imap.disconnect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment