Reading Mail
I
n Chapter 7, you built scripts and applications to tell you that
you had new mail. In this chapter, you move on to the next log-
ical step and retrieve that mail from Gmail so you can read it.
Reading an individual mail from Gmail is unlike reading individual
mails from a POP3 or IMAP server. In the more common e-mail
systems, an e-mail is identified by a number and can be retrieved
directly. In Gmail, as you found in Chapter 6, this isn’t possible:
You have to retrieve the entire thread and then retrieve the message
from that. In an ideal world, a Gmail library would hide this horri-
ble fact, and they all do this to a lesser or greater extent.
Chapter 9: Reading Mail
The process with Mail::Webmail::Gmail is remarkably easy. You
log in, retrieve the contents of the Inbox, find the thread with the
message you require, retrieve it, find the message within that
thread, and parse out the contents.
The Basics
Logging in and retrieving the contents of the Inbox, as ever,
looks like this:
my $gmail = Mail::Webmail::Gmail->new(
username => “ben.hammersley\@gmail.com”,
password => “XXXXXXXX”,
);
my $messages =
$gmail->get_messages( label =>
$Mail::Webmail::Gmail::FOLDERS{‘INBOX’} );
̨Locating the mail
̨Retrieving the
message source
̨Parsing the
message source
chapter
in this chapter