24.07.2017 Views

Hacking Gmail

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

164 Part II — Getting Inside <strong>Gmail</strong><br />

Listing 10-2 (continued)<br />

foreach ( @{$messages} ) {<br />

if ( $_->{“new”} ) {<br />

print $id . “\t”<br />

. $_->{“sender_email”} . “\t”<br />

. strip_bold( $_->{“subject”} )<br />

. “\n”;<br />

push( @nums, $num );<br />

$id++;<br />

}<br />

$num++;<br />

}<br />

print “\n”;<br />

print “enter message number to reply to\n”;<br />

$num = ;<br />

print “\n”;<br />

$message = @{$messages}[ $nums[ $num - 1 ] ];<br />

$msgid = $message->{“id”};<br />

if ($msgid) { # check if message id is OK<br />

print “body:\n”;<br />

$body = ;<br />

$gmail->send_message(<br />

to => $message->{“sender_email”},<br />

subject => “Re: “ . strip_bold( $message->{“subject”}<br />

),<br />

msgbody => $body<br />

); # we are using sender and subject from the<br />

original message<br />

print “message sent\n”;<br />

}<br />

Running this script produces a list of the new messages and gives you the option<br />

to choose one and reply to it. You should see how this works from the code, but<br />

let’s walk through it.<br />

The start is simple enough. You’re using the Utils.pm module you created in<br />

Chapter 7, and you just want to log in. Logging in creates the <strong>Gmail</strong> object<br />

used in the rest of the script:<br />

use Utils;<br />

$gmail = login();

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!