Hacking Gmail

(Grace) #1

Chapter 8 — Checking for Mail 143


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


my $new_msgs = 0;


if ( defined($messages) ) {
foreach ( @{$messages} ) {
if ( $_->{‘new’} ) {
$new_msgs++;
}
}
}


Once you have the unread message count, you need to use the XML::RSS module
to produce the feed. Listing 8-5 gives the entire script an airing and shows how


this works.


Listing 8-5:Producing a New Mail Count in an RSS Feed

#!/usr/bin/perl -w
use strict;
use XML::RSS;


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,
);


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


my $new_msgs = 0;


if ( defined($messages) ) {
foreach ( @{$messages} ) {
if ( $_->{‘new’} ) {

Free download pdf