Hacking Gmail

(Grace) #1

142 Part II — Getting Inside Gmail


Building on the Basics


Now that you have seen the basics for retrieving the number of unread messages,
you can look at new and interesting ways of displaying that number. You saw
desktop applications that do this in Chapter 2, so this section concentrates on the
more unusual ways of seeing the number.

New Mail Count in RSS


It’s a fair bet that the majority of the readers of a book like this one will also be
heavy users of RSS. The XML-based family of syndication technologies is now
very popular indeed, and presents a lot of opportunities for keeping track of many
different types of information. I personally use the following technique to keep
tabs on Gmail accounts that I use on an infrequent basis: for accounts where
checking them manually is too much bother but where a desktop alert is too
intrusive.

Start off, in the normal way, by loading the core Perl modules. In this case, you
will need Mail::Webmaiil::Gmail, as ever, and the commonly used XML::RSS
module to help produce the RSS feed, and the ubiquitous CGI module to deal
with the incoming parameters and the correct serving of the feed. XML::RSS is a
little out of the scope of this book, and is nevertheless very simple to understand
from its own documentation.

Then take the username and password from parameters in the URL, and set up
the WWW::Gmail object like so:
use CGI qw(standard);

use Mail::Webmail::Gmail;

my $username = param(“username”);
my $password = param(“password”);

my $gmail = Mail::Webmail::Gmail->new(
username => $username,
password => $password,
);

And then it’s the usual matter of downloading the Inbox and counting the unread
messages:
Free download pdf