Skip to content

Instantly share code, notes, and snippets.

@mh61503891
Created April 3, 2011 05:25
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 mh61503891/900218 to your computer and use it in GitHub Desktop.
Save mh61503891/900218 to your computer and use it in GitHub Desktop.
Gmail Fetcher
#! 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