Created
April 3, 2011 05:25
-
-
Save mh61503891/900218 to your computer and use it in GitHub Desktop.
Gmail Fetcher
This file contains 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
#! ruby | |
# -*- coding: utf-8 -*- | |
# CONFIG | |
IMAP_USER='' | |
IMAP_PASS='' | |
# MAIN | |
require 'net/imap' | |
require 'parsedate' | |
FROMS = %w{ | |
@mynavi.jp | |
@mail.rikunabi.com | |
@en-japan.com | |
@shukatsu.jp | |
@disc.co.jp | |
@mycom.co.jp | |
} | |
FROMS.each{ |from| | |
begin | |
imap = Net::IMAP.new('imap.gmail.com', 993, true) | |
imap.login(IMAP_USER, IMAP_PASS) | |
imap.select('inbox') | |
ids = imap.search(['FROM', from]) | |
$stderr.puts "fetch #{ids.size} items from #{from}" | |
imap.fetch(ids, ['INTERNALDATE']).each{ |f| | |
year, month, day, = ParseDate::parsedate(f.attr['INTERNALDATE']) | |
puts "#{from}\t#{'%04d'%year}-#{'%02d'%month}-#{'%02d'%day}" | |
} | |
rescue => e | |
$stderr.puts e | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment