Friday, July 3, 2009

Simple biff for gmail

Gmail publishes an atom feed for your inbox. This makes it possible to build a trivial client to show the number of unread messages in your inbox, for use in a statusbar (dwm/wmii bar, conky, etc).

The following shell one-liner does the job, but slowly:

wget -qO - https://username:password@mail.google.com/mail/feed/atom --no-check-certificate \
| egrep '[0-9]+' \
| sed -e 's/[^0-9]//g'


Here's a simple perl script that is about twice as fast:

#!/usr/bin/perl
use strict;
use warnings;

use XML::Atom::Client;

my $api = XML::Atom::Client->new;

$api->username('username');
$api->password('password');

my $feed = $api->getFeed('https://mail.google.com/mail/feed/atom')
or die ("Error: ", $api->errstr, "\n");

print(scalar($feed->entries)||0, "\n");


On ArchLinux this required the following packages: perl-xml-atom, perl-libwww, perl-digest-sha1, perl-datetime, perl-crypt-ssleay.

No comments:

Post a Comment