Hacking Gmail

(Grace) #1

174 Part III — Conquering Gmail


Listing 11-4 (continued)

$message = @{$messages}[ $nums[ $num - 1 ] ];
$msgid = $message->{“id”};

if ($msgid) {
@labels = $gmail->get_labels(); # simply get all labels
$id = 1;
foreach (@labels) { # and iterate through
them
print $id. “\t”. $_. “\n”;
$id++;
}

print “\n”;
print “enter label to set\n”;
$num = <>;
print “\n”;

$label = $labels[ $num - 1 ];
if ($label) {
$gmail->edit_labels(
label => $label,
action => “add”,
msgid => $msgid
); # simply add label to message
print “labeled message\n”;
}
}

The key part of the script is the edit_labelsfunction. Here’s the pertinent
function call:
$gmail->edit_labels(
label => $label,
action => “add”,
msgid => $msgid
);

You set the labelattribute to the label you require, the actionto “add”and the
msgidto the message ID of the message you’re changing. It is, as you can see,
very simple to understand.
Free download pdf