Chapter 13 — Building an API from the HTML-Only Version 193
There is a lot going on here. You have the entire message, and all of the associated
metadata — the sender, the date, the subject line, and so forth — and you have a
whole collection of actions to perform on the message, with (joy of joys) a seemingly
easy-to-decipher system of URLs to set them going. Later on in this chapter, you
return to this listing to work on these commands.
Meanwhile, you need to get at the message contents. The technique is exactly the
same as when you looked through the Inbox. Listing 13-6 shows the code that
does this.
Listing 13-6: Code to Parse an Individual Message Page
#!/usr/bin/perl
use warnings;
use strict;
use HTML::TokeParser;
open( FILEIN, “Gmail - single message.html” );
undef $/;
my $filecontents =
my $stream = HTML::TokeParser->new( \$filecontents );
$stream->get_tag(“table”);
$stream->get_tag(“table”);
$stream->get_tag(“table”);
$stream->get_tag(“table”);
$stream->get_tag(“table”);
$stream->get_tag(“table”);
$stream->get_tag(“table”);
$stream->get_tag(“table”);
$stream->get_tag(“table”);
$stream->get_tag(“table”);
$stream->get_tag(“table”);
$stream->get_tag(“b”);
my $subject = $stream->get_trimmed_text(“/b”);
$stream->get_tag(“b”);
my $from_true_name = $stream->get_trimmed_text(“/b”);
$stream->get_tag(“/font”);
my $from_email_address = $stream->get_trimmed_text(“/td”);
Continued