Like many people, for a long time I have been drowning in email. I am perhaps bit unusual in that whilst my personal google inboxes are permanently overflowing, my work inboxes are generally very close to empty. This is because as a (bad) practitioner of GTD and sometime reader of Inbox Zero and similar sites, I do actually know how to get grips with email, and through professional pride apply the techniques fairly religiously when I’m working. In contrast, when it comes to dealing with personal mail, I’ll always favour procrastinating on some other interesting project instead. God forbid I should ever get my personal life in gear!
Well, this bad habit has been stressing me out for a LONG time now. I’m a long-term fan of Gretchen Rubin’s Happiness Project, and the other day stumbled across one of her older posts entitled Measure what you want to manage. I’d been wanting to graph the size of my inboxes over time, to get some grip on how bad my backlog actually is, and her post gave me the nudge to actually sort it out.
As usual, Ruby makes it almost ridiculously easy. There’s a beautiful written gem called gmail which uses IMAP to talk to your gmail account. So then it’s just a matter of writing a little program to append a line of gmail folder sizes to a CSV file every time it gets run:
# sudo gem install gmail
# Note: this is an improved version of Daniel Parker's ruby-gmail
# sudo gem install fastercsv
USERNAME = 'email@example.com'
PASSWORD = 'your.password.goes.here'
CSV_FILE = Pathname(ENV['HOME']).join(
&quot;choose&quot;, &quot;a&quot;, &quot;path&quot;, &quot;to&quot;, &quot;gmail-counts.csv&quot;
labels = FasterCSV.open(CSV_FILE, 'r').shift[2..-1]
FasterCSV.open(CSV_FILE, 'a') do |csv|
Gmail.connect(USERNAME, PASSWORD) do |gmail|
now = Time.now
counts = [ now.to_i.to_s, now.strftime(&quot;%Y/%m/%d.%H:%M:%S&quot;) ]
labels.each do |label|
unread = label.gsub!(/ unread$/, '')
folder = gmail.mailbox(label)
count = unread ? folder.count(:unread) : folder.count
puts &quot;%s: %d (%d unread, %d read)&quot; % \
[ label, count, folder.count(:unread), folder.count(:read) ]
counts &lt;&lt; count
csv &lt;&lt; counts
gmail-counts.csv in the folder referenced in the script, whose header line contains a list of the labels you want counted (append
unread if you want the unread count rather than the total, and prefix “special” gmail folders with
[Google Mail]/. Here’s an example of the header followed by a single line of folder counts:
epoch,datetime,INBOX,INBOX unread,[Google Mail]/Drafts,music
Then make sure the program is automatically run on a regular basis somehow. On Linux this is as simple as adding a new line into your
crontab. My quietrun utility comes in handy for this:
0 6,12,18 * * * quietrun /path/to/script/count-gmail
Then you can use Google Docs or your favourite spreadsheet / charting application to plot some nice graphs. I used this script which is written in the Ploticus graphing language; here is the result:
UPDATE 5 months later! (15th May 2011): I finally made it!