24.07.2017 Views

Hacking Gmail

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

188 Part III — Conquering <strong>Gmail</strong><br />

Listing 13-2 (continued)<br />

<br />

<br />

<br />

<br />

Ben Hammersley<br />

<br />

<br />

<br />

Heads<br />

<br />

Here’s a nice message.<br />

<br />

Jan&nbsp;6<br />

If you look at this code, and know what you already do about the way <strong>Gmail</strong><br />

works, it’s easy to deduce the structure of the page. Each line of the Inbox is structured<br />

like this:<br />

<br />

<br />

A LINK TO A STAR IMAGE IF THE MESSAGE IS STARRED<br />

<br />

THE AUTHOR NAME<br />

<br />

THE LABEL<br />

THE SUBJECT LINE<br />

<br />

THE DATE.<br />

And so, to retrieve your Inbox, you simply retrieve this page, walk through the<br />

code until you get to the correct table, collect every instance of the preceding<br />

structure, and parse out the details. This is what you shall do now.<br />

Parsing the Inbox<br />

Listing 13-3 shows some Perl code that uses HTML::TokeParser to walk through<br />

the HTML-only Inbox page that you saved earlier and print out details of the<br />

messages therein. Note that it loads the page as a text file from the disk, and just

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!