Hacking Gmail

(Grace) #1

Chapter 14 — Exporting Your Mail 199


Converting to Mbox


Much more useful, converting to the Mbox format allows your Gmail to be
imported into most popular e-mail applications. Listing 14-2 converts your Gmail
Inbox into an Mbox-compatible file. It needs two modules, in addition to the
Utils.pm module you’ve been using for this section of the book (that, if you’ve for-
gotten, is found in Listing 7-4):

Mail::Internet:Available from http://search.cpan.org/~markov/

Mail::Folder::Mbox:Available from http://search.cpan.org/
~kjohnson

Listing 14-2: Convert to Mbox

use Utils;
use Mail::Internet;
use Mail::Folder::Mbox;

$gmail = login();

$inbox = new Mail::Folder(‘mbox’);
$inbox->create(‘inbox’);
$inbox->open(‘inbox’);

$messages =
$gmail->get_messages( label =>
$Mail::Webmail::Gmail::FOLDERS{“INBOX”} )
; # simply get all messages from INBOX

foreach ( @{$messages} ) { # and iterate through them
$message = $gmail->get_mime_email( msg => $_ ); #
retrive MIME message
@message_lines = split( /\n/, $message ); # split
it into lines
map { $_ .= “\n” } @message_lines; # prevent joining of
lines in the body
$message_inet =
new Mail::Internet( \@message_lines )
; # construct RFC822
compilant message
$inbox->append_message($message_inet); # and append it
into mbox
Continued
Free download pdf