Hacking Gmail

(Grace) #1

Chapter 9 — Reading Mail 157


my $body = $message->{ $_->{‘id’} }->{‘body’}
|| “Body irretrievable”;

$rss->add_item(
title => “$subject”,
link =>
http://gmail.google.com/gmail/h/abcde12345/?th=$messageid&v=c
”,
author => “$sender_email”,
description => “$body”,
);


}


$rss->channel(
title => “The Gmail inbox for $username”,
link => “http://gmail.google.com/”,
);


print header(‘application/xml+rss’);
print $rss->as_string;


The first thing to notice is that this script is very simple indeed. That’s because of
the Perl module — the whole point of these modules is to abstract away this sort


of thing. So, the first thing you do is load the modules up and log in as usual:


use XML::RSS;
use Mail::Webmail::Gmail;
use CGI qw(standard);


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


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


Because you want the script to return an RSS feed, you’ve made it into a CGI script,
to be called from, and run by, a server. The easiest way to make this useful is to take


the Gmail account’s username and password from parameters in the script’s URL.
Saving this script as gmailinboxtorss.cgi would allow you to subscribe to the follow-


ing URL:


http://www.example.com/gmailinboxtorss.cgi?username=USERNAME&passw
ord=PASSWORD

Free download pdf