Hacking Gmail

(Grace) #1

Exporting Your Mail


T


he hallmark of a truly great web application is the ease with
which you can remove your data should you want to leave.
In the words of the poet, if you love someone set them free.

Sadly, Gmail doesn’t make it easy to get your mail out of there.
There’s no built-in facility to do so at all, at least at the time of
this writing. Of course, many would say that Gmail is so shiny
that you’d be mad to stop using it. Maybe so, but in this chapter
you look at how to do that anyway.

Exporting as a Massive Text File


The first way to export your mail, and the simplest, is to dump
the lot to a big text file — illustrated in Listing 14-1. It’s not very
useful for re-importing your mail into another application, but it
is good for backups of data that you’d like on paper, for example.

Listing 14-1: Export All Mail to a Text File

use Utils;

$gmail = login();

$messages = $gmail->get_messages();

open OUTPUT, “>mailarchive.txt”;

foreach (@{$messages}) {

my $full_message = $gmail->get_indv_email(msg =>
$message);
....print OUTPUT “Sender: “. $full_message-
>{$id}->{“sender_email”}. “\n”;
Continued

̨Converting to a
big text file

̨Converting to
Mbox

̨Appending to IMAP


chapter


in this chapter

Free download pdf