Created
October 12, 2012 18:13
-
-
Save hadley/3880626 to your computer and use it in GitHub Desktop.
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 imap.rb > mail.csv | |
require 'net/imap' | |
username = '' | |
password = '' | |
imap = Net::IMAP.new('imap.gmail.com','993',true) | |
imap.login(username, password) | |
# imap.list("", "*").map{|i| i.name} | |
imap.select('[Gmail]/All Mail') | |
# imap.search(["UNSEEN"]).count | |
def format_date(date) | |
"#{date.mday}-#{Date::MONTHNAMES[date.month]}-#{date.year}" | |
end | |
puts "from,to,all,direct,read,sent" | |
cur = Date.new(2007, 1, 1) | |
today = Date.today | |
while cur < today | |
cur = cur + 7 | |
week = ["SINCE", format_date(cur), "BEFORE", format_date(cur + 7)] | |
# * number of messages recieved | |
all = imap.search(week).count | |
# * number of messages read (SEEN, day month year) | |
read = imap.search(week + ["SEEN"]).count | |
direct = imap.search(week + ["OR", "TO", "[email protected]", "TO", "[email protected]"]).count | |
# * number of messages sent | |
sent = imap.search(week + ["OR", "FROM", "[email protected]", "FROM", "[email protected]"]).count | |
puts "#{cur},#{cur+6},#{all},#{direct},#{read},#{sent}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment