Created
September 13, 2008 04:58
-
-
Save twada/10564 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
# | |
# 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