Chapter 11 — Dealing with Labels 175
Creating a New Label
The creation of new labels is done with the same edit_labelsfunction, using
the “create”action. This code that follows creates a new label “fish”. Labels
can have a maximum of 40 characters.
$gmail->edit_labels(
label => “fish”,
action => “create”,
);
When that’s done, you can go back and apply that label to the messages you wish.
Removing Labels
Of course, you might go completely label crazy. In which case, one day you’ll wake
up with regret and want to undo all that you did before. If that’s the case, use the
final variation of the edit_labelsfunction, like so:
$gmail->edit_labels(
label => $label,
action => “remove”,
msgid => $msgid
);
Listing 11-5 puts together the final variation of the chapter, with a script that
allows you to choose a label, display the messages with that label, and choose a
message to remove that label from. Complex? Not hardly!
Listing 11-5: Getting Labeled Messages and Removing Labels
use Utils;
$gmail = login();
@labels = $gmail->get_labels(); # simply get all labels
$id = 1;
foreach (@labels) { # and iterate through them
print $id. “ “. $_. “\n”;
$id++;
}
print “\n”;
print “enter label number to retrieve labeled messages:\n”;
$num = <>;
Continued