Chapter 9 — Reading Mail 159
author => “$sender_email”,
description => “$body”,
);
That’s all quite self-explanatory, except for the line that creates the item’s link
element. There you can see a long URL that is completed with the message ID
number. This produces a link to the HTML-only version of the Gmail interface,
but you will have to wait until Chapter 12 to see that fully explained. Skip ahead
if you’re curious.
The only thing left to do here is serve the feed, so you do this:
$rss->channel(
title => “The Gmail inbox for $username”,
link => “http://gmail.google.com/”,
);
print header(‘application/xml+rss’);
print $rss->as_string;
To install and run this script, place it in a CGI-enabled directory on your server,
and remember to CHMOD it to executable.
This script highlights a simple method of gathering messages and doing some-
thing with them. As you saw in the previous chapter, you can easily direct the
get_messages()function, which above retrieves the array of hashes from the
Inbox. You can grab the messages from the Starred folder, for example, by chang-
ing the line in Listing 9-1 to the following:
my $messages = $gmail->get_messages( label =>
$Mail::Webmail::Gmail::FOLDERS{ ‘STARRED’ } );
Moving messages around the labels and default folders is examined in Chapter 10.
There you will also look at finding which labels and folders you have.
And Now
In this chapter, then, you’ve learned how to retrieve e-mails from Gmail using
Perl. You should now be able to access the data of any mail you wish and use it
within your programs. As you will see in the later chapters, this opens many new
opportunities. In the next chapter, you learn how to send mail via Gmail.