Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Gmailize your mbox

by xern (Beadle)
on Jun 22, 2004 at 22:08 UTC ( #368878=snippet: print w/replies, xml ) Need Help??
Description: This snippet can back up your mbox messages onto Gmail.
#!/usr/bin/perl

use strict;
use Email::Folder;
use Mail::Mailer;

my $email = '@gmail.com';
my $folder = Email::Folder->new($ARGV[0] || die);
foreach ($folder->messages){
    print $_->header("Subject").$/;
    my $mailer = new Mail::Mailer;
    $mailer->open({
        To => $email,
        From => $_->header("From"),
        Subject => $_->header("Subject"),
    });
    print $mailer $_->body;
    $mailer->close;
}
Replies are listed 'Best First'.
Re: Gmailize your mbox
by naChoZ (Curate) on Jun 30, 2004 at 14:29 UTC

    Cool, thanx for this little snippet.

    I'm trying to write one for IMAP using Mail::IMAPClient. Ever used it? I'm having trouble figuring it out. I can retrieve the list of messages and stuff like that, but when it comes to actually dumping the contents of the message, I'm stuck.

    --
    Diplomacy is the art of saying "Nice doggie" until you can find a rock.
    naChoZ

Re: Gmailize your mbox
by ghenry (Vicar) on Jun 27, 2005 at 10:06 UTC

    This is a very handy snippet.

    I've modified it ever so slightly:

    #!/usr/bin/perl use strict; use Email::Folder; use Mail::Mailer; my $email = '@gmail.com'; my $tag = 'Mail Tag'; my $folder = Email::Folder->new($ARGV[0] || die "No mbox supplied\n\nU +sage: $0 mboxname\n"); foreach ($folder->messages){ print $_->header("Subject").$/; my $mailer = new Mail::Mailer; $mailer->open({ To => $email, From => $_->header("From"), Subject => "$tag " . $_->header("Subject"), }); print $mailer $_->body; $mailer->close; print "Email with Subject: " . $_->header("Subject") . " sent\n"; }

    Thanks a lot!

    Gavin.

    Walking the road to enlightenment... I found a penguin and a camel on the way.....
    Fancy a yourname@perl.me.uk? Just ask!!!

      This looks to be a very useful piece of code but I have tried it on a test message and it fails to pring the message body.

      Here is the test email that I tried it on (email address, servers and IPs cleaned but otherwise the same):

      From Ed.Davison@mccombs.utexas.edu Mon Jul 31 15:05:58 2006 Received: from 1.2.3.4 ([1.2.3.4]) by exchange.domain ([1.2.3.5]) via Exchange Front-End Server mail.domain ([1.2.3.6]) with Microsoft Exchange Server HTTP-DAV ; Mon, 31 +Jul 2006 15:05:58 +0000 Received: from laptop by mail.domain; 31 Jul 2006 10:05:57 -0500 Subject: test for email parser From: username@domain Reply-To: username@domain To: username Content-Type: text/plain Organization: Organization Date: Mon, 31 Jul 2006 10:05:57 -0500 Message-Id: <1154358357.11169.0.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.6.2 X-Evolution-Source: exchange://user@mail.domain/ Content-Transfer-Encoding: 8bit test entry

      Any ideas why the message body is not being picked up on this one?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://368878]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2021-03-06 10:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (116 votes). Check out past polls.

    Notices?