Chapter 11 — Dealing with Labels 173
This is exactly the same technique as you used in Listing 11-2, added to Chapter
10’s method for sending a reply. You should now be able to see how you can build
simple applications and workflows with the Gmail and the Mail::Webmail::Gmail
module.
Setting New Labels.
It’s all very well being able to list the existing labels, but what about setting mes-
sages with them? To do that with Mail::Webmail::Gmail, use the edit_labels
function. Listing 11-4 displays the unlabeled messages and the existing labels, and
allows you to apply one to the other.
First, the listing and then how it works.
Listing 11-4: Labeling Unlabeled Messages
use Utils;
$gmail = login();
$messages = $gmail->getmessages(); # simply get all
messages
$id = 1;
$num = 0;
@nums;
foreach ( @{$messages} ) { # and iterate through
them
if ( $->{“new”} ) {
print $id. “\t”
. $_->{“sender_email”}. “\t”
. stripbold( $->{“subject”} )
. “\n”; # output message data
push( @nums, $num );
$id++;
}
$num++;
}
print “\n”;
print “enter message number to label\n”;
$num = <>;
print “\n”;
Continued