Hacking Gmail

(Grace) #1

Chapter 8 — Checking for Mail 145


my $message = “Your Gmail inbox, $username, has a new message
count of $new_msg”;


$aim = Net::AOLIM->new(‘username’ => $aim_user,
‘password’ => $aim_password,
);


$aim->signon or die “Cannot sign on to AIM”;
$aim->toc_send_im($aim_destuser, $message);


Listing 8-6 shows the entire code for this script.


Listing 8-6:New Mail Alerts to AOL Instant Messenger

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


use CGI qw(standard);


use Mail::Webmail::Gmail;
use Net::AOLIM;


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’} ) {
$new_msgs++;
}
}
}

Free download pdf