Hacking Gmail

(Grace) #1

156 Part II — Getting Inside Gmail


your Inbox? In Chapter 7 you already made a feed that displays the unread mes-
sage count. Do the same here, only displaying the messages instead.

Listing 9-2 shows the code, which is followed by a walkthrough.

Listing 9-2:Gmail Inbox to RSS

#!/usr/bin/perl

use warnings;
use strict;
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,
);

my $messages =
$gmail->get_messages( label =>
$Mail::Webmail::Gmail::FOLDERS{‘INBOX’} );

my $rss = new XML::RSS( version => ‘2.0’ );

foreach ( @{$messages} ) {

my $message = $gmail->get_indv_email( msg => $_ );

my $messageid = $_->{‘id’};

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

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

my $subject = $message->{ $_->{‘id’} }->{‘subject’}
|| “Subject irretrievable”;
Free download pdf