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.

Chapter 9 — Reading Mail<br />

159<br />

);<br />

author => “$sender_email”,<br />

description => “$body”,<br />

That’s all quite self-explanatory, except for the line that creates the item’s link<br />

element. There you can see a long URL that is completed with the message ID<br />

number. This produces a link to the HTML-only version of the <strong>Gmail</strong> interface,<br />

but you will have to wait until Chapter 12 to see that fully explained. Skip ahead<br />

if you’re curious.<br />

The only thing left to do here is serve the feed, so you do this:<br />

$rss->channel(<br />

title => “The <strong>Gmail</strong> inbox for $username”,<br />

link => “http://gmail.google.com/”,<br />

);<br />

print header(‘application/xml+rss’);<br />

print $rss->as_string;<br />

To install and run this script, place it in a CGI-enabled directory on your server,<br />

and remember to CHMOD it to executable.<br />

This script highlights a simple method of gathering messages and doing something<br />

with them. As you saw in the previous chapter, you can easily direct the<br />

get_messages() function, which above retrieves the array of hashes from the<br />

Inbox. You can grab the messages from the Starred folder, for example, by changing<br />

the line in Listing 9-1 to the following:<br />

my $messages = $gmail->get_messages( label =><br />

$Mail::Webmail::<strong>Gmail</strong>::FOLDERS{ ‘STARRED’ } );<br />

Moving messages around the labels and default folders is examined in Chapter 10.<br />

There you will also look at finding which labels and folders you have.<br />

And Now . . .<br />

In this chapter, then, you’ve learned how to retrieve e-mails from <strong>Gmail</strong> using<br />

Perl. You should now be able to access the data of any mail you wish and use it<br />

within your programs. As you will see in the later chapters, this opens many new<br />

opportunities. In the next chapter, you learn how to send mail via <strong>Gmail</strong>.

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

Saved successfully!

Ooh no, something went wrong!