#!/usr/local/bin/perl -w #### # # gmail2mbox - download Gmail to a local mbox # ### use strict; use Mail::Webmail::Gmail; use Email::LocalDelivery; use Data::Dumper; =head1 NAME gmail2mbox - download Gmail messages to a local mbox =head1 USAGE gmail2mbox [mailbox[s]] Messages will be delivered to equivalent mboxes on the system. If no mailboxes are supplied then it downloads everything from all mailboxes. =head1 AUTHOR Simon Wistow =head1 COPYRIGHT Copyright, 2006 - Simon Wistow Destributed under the same terms as Perl itself. =cut my $u = shift || die "You must pass a username\n"; my $p = shift || die "You must pass a password\n"; my $gmail = Mail::Webmail::Gmail->new( username => $u, password => $p) || die "Couldn't log in\n"; my @folders = (@ARGV)? @ARGV : ('INBOX', 'STARRED', 'SPAM', 'TRASH', $gmail->get_labels()); print STDERR "Fetching ".join(", ", @folders)."\n"; foreach my $folder (@folders) { my $messages = $gmail->get_messages( label => $folder ); my $count = 1; my $total = @{$messages}; foreach ( @{ $messages } ) { print STDERR "\r$folder ... $count/$total"; $count++; my $message = $gmail->get_mime_email( msg => $_ ); # TODO we could take a command line option that sepcified if we wanted to deliver to Maildir or # MH or whatever and then munge $folder to make Email::FolderType DTRT Email::LocalDelivery->deliver("$message", $folder); } print STDERR "\n"; } print "Done\n";