154 Part II — Getting Inside Gmail
Listing 9-1 (continued)
print “sent:
“ . $full_message->{$id}->{“sent”} . “\n”;
print “to:
“ . $full_message->{$id}->{“to”} . “\n”;
print “subject: “ . strip_bold($full_message->{$id}>{“subject”}) . “\n”;
print $full_message->{$id}->{“body”} . “\n\n”;
}
So how does this work? First you use the Utils.pm module you made at the end of
Chapter 7 and have it log you in:
use Utils;
$gmail = login();
Now that you’re logged in, you need to retrieve the messages and loop through
each one, numbering it and printing the sender and subject line.
$messages = $gmail->get_messages(); # simply get all messages
$id = 1;
$num = 0;
@nums;
foreach (@{$messages}) { # and iterate through them
if ($_->{“new”}) {
........print $id . “\t” . $_->{“sender_email”} . “\t” .
strip_bold($_->{“subject”}) . “\n”; # output message data
........push(@nums, $num);
........$id++;
}
$num++;
}
Now you give the option to enter the number (as printed in the preceding code)
of the message you want to see.
print “\n”;
print “enter message number to retrive it\n”;
$num = <>;
print “\n”;
Once a number has been entered, retrieve the message and print it on the screen.
$message = @{$messages}[$nums[$num - 1]];
$msgid = $message->{“id”};
if ($msgid) { # check if message id is OK
my $full_message = $gmail->get_indv_email(msg =>
$message); # and retrive full message (including body but not
Listing 9-1 (continued)
print “sent:
“ . $full_message->{$id}->{“sent”} . “\n”;
print “to:
“ . $full_message->{$id}->{“to”} . “\n”;
print “subject: “ . strip_bold($full_message->{$id}>{“subject”}) . “\n”;
print $full_message->{$id}->{“body”} . “\n\n”;
}
So how does this work? First you use the Utils.pm module you made at the end of
Chapter 7 and have it log you in:
use Utils;
$gmail = login();
Now that you’re logged in, you need to retrieve the messages and loop through
each one, numbering it and printing the sender and subject line.
$messages = $gmail->get_messages(); # simply get all messages
$id = 1;
$num = 0;
@nums;
foreach (@{$messages}) { # and iterate through them
if ($_->{“new”}) {
........print $id . “\t” . $_->{“sender_email”} . “\t” .
strip_bold($_->{“subject”}) . “\n”; # output message data
........push(@nums, $num);
........$id++;
}
$num++;
}
Now you give the option to enter the number (as printed in the preceding code)
of the message you want to see.
print “\n”;
print “enter message number to retrive it\n”;
$num = <>;
print “\n”;
Once a number has been entered, retrieve the message and print it on the screen.
$message = @{$messages}[$nums[$num - 1]];
$msgid = $message->{“id”};
if ($msgid) { # check if message id is OK
my $full_message = $gmail->get_indv_email(msg =>
$message); # and retrive full message (including body but not
