Chapter 11 — Dealing with Labels 171
print $_->{“sender_email”}. “\t”
. stripbold( $->{“subject”} )
. “\n”;
}
}
The important section to note here is the code that follows:
if ($label) {
$messages =
$gmail->getmessages( label => $label );
foreach ( @{$messages} ) {
print $->{“sender_email”}. “\t”
. stripbold( $->{“subject”} )
. “\n”;
}
}
By this section of the script, you’ve printed out the labels you know about, and
asked the user to choose one. So now you test to see if the number the user enters
is actually a value option, and if it is, you retrieve all of the messages with the per-
tinent label. That’s done, as ever, with the get_messages()function, which can
be modified by passing the name of a label with it:
$messages = $gmail->get_messages( label => $label );
And this returns messages in the same way as you dealt with in Chapter 8.
In Chapter 9, you requested new mail and gave the option to reply to it. Here, in
Listing 11-3, you can do a similar thing: request mail for a certain label and give
the option to reply to it.
Listing 11-3: Retrieving a Labeled Message and Replying
use Utils;
$gmail = login();
@labels = $gmail->getlabels(); # simply get all labels
$id = 1;
foreach (@labels) { # and iterate through them
print $id. “ “. $. “\n”;
$id++;
Continued