Previous Section  < Day Day Up >  Next Section

Hack 75. Export Your Gmail

Back up or export your Gmail messages to your computer for safe-keeping or offline reading.

You're nicely settled in to your new Gmail account and may even have brought over all of your email Hack #74 since time began. You're mailing up a storm, taking full advantage of the one gigabyte of storage space you're allotted.

What, now, if you decide Gmail actually isn't for you and you'd like to move out again, either to another Web mail service or back to the more traditional email application running on your computer? Or perhaps you just want a local archive of your Gmail for safe-keeping or offline trawling when you're on a plane and desperately need a copy of that meeting report.

A nifty little archiving script packaged with the libgmail (http://libgmail.sourceforge.net) Python interface to Gmail Section 6.13[Hack #80 is just the ticket. It logs into your Gmail account for you, looks around, prompts you to select a collection of messages to archive, and downloads them to your laptop or desktop.

6.8.1. Installing the Hack

There's really nothing to do beyond downloading (http://sourceforge.net/project/showfiles.php?group_id=113492, or click the Downloads link on the libgmail home page) and unstuffing the libgmail archive (http://libgmail.sourceforge.net).

The only requirement for libgmail is Python (http://www.python.org).


6.8.2. Running the Hack

Among libgmail's demo applications is archive.py, a script that logs into Gmail, downloads your email messages, and saves them on your computer's hard drive in a format (Mbox) suitable for importing into many an email program:

On the command line (whether that be the Windows DOS-alike, Mac OS X's Terminal, or Unix shell), run the archive script like so:

$ python demos/archive.py

You'll be prompted for your Gmail account name and password, after which libgmail will log you in:

Gmail account name: 

raelity



Password:



Please wait, logging in...

Log in successful.

There we are. At this point you can choose to archive just what's in your inbox (0), all messages (2), starred, drafts, sent, or a particular set of labeled messages (6 and 7 in my case). Choose the associated number and hit the return key on your keyboard:

WARNING:root:Live Javascript and constants file versions differ.

Select folder or label to archive: (Ctrl-C to exit)

Note: *All* pages of results will be archived.

  0. inbox

  1. starred

  2. all

  3. drafts

  4. sent

  5. spam

  6. foo

  7. Peeps

Choice: 2

Libgmail begins slurping your messages out of Gmail, one by one, and downloading them to an archive file in the current directory on your computer.

As is stated by he program at the outset, "*All* pages of results will be archived," meaning that all messages in the collection you've chosen will be downloaded, not just those that fit on a single page when you're looking at that collection through the standard Gmail web browser interface.


ff602fe48d89bc3 1 \<b\>Hello from Hotmail\</b\>

   ff602fe48d89bc3 1 Hello from Hotmail



ff5fb9c2829c165 1 Hello Gmail via Gmail Loader

   ff5fb9c2829c165 1 Hello Gmail via Gmail Loader



ff5691f7170cb62 1 Hello Gmail via Gmail Loader

   ff5691f7170cb62 1 Hello Gmail via Gmail Loader



ff3f4310237b607 1 Howdy gmail-lite

   ff3f4310237b607 1 Howdy gmail-lite



ff39c1fc71abbf1 1 Hello from Gmail mobile

   ff39c1fc71abbf1 1 Hello from Gmail mobile



...



fbd0c388dd1684e 1 Hello, Gmail

   fbd0c388dd1684e 1 Hello, Gmail



fbd0c1db3bcffe2 1 Gmail is different. Here's what you need to know.

   fbd0c1db3bcffe2 1 Gmail is different. Here's what you need to know.



Select folder or label to archive: (Ctrl-C to exit)

Note: *All* pages of results will be archived.

  0. inbox

  1. starred

  2. all

  3. drafts

  4. sent

  5. spam

  6. foo

  7. Peeps

Choice: ^C



Done.

And we're done. Choose another collection to download and archive if you wish; otherwise, press Control-C on your keyboard to stop the archive.py script.

Now, if you look in the directory from which you invoked archive.py, you should see a new Mbox-format archive (the one I just created is archive-all-1096849647.72.mbox) of your chosen collection of messages, suitable for importing into many an email program:

jane:~/Desktop/libgmail-0.0.8 rael$ ls

ANNOUNCE                        constants.pyc

CHANGELOG                       demos

README                          libgmail.py

archive-all-1096849647.72.mbox  lib

6.8.3. See Also

    Previous Section  < Day Day Up >  Next Section