Showing posts with label email. Show all posts
Showing posts with label email. Show all posts

14 May 2007

Parsing MBox Mails in Perl

to extract attachments from my Thunderbird mbox files:

#!/usr/bin/perl
use strict;
use Mail::MboxParser;
use Mail::MboxParser::Mail;

# name of mbox file
my $mymailbox="Inbox";
# no parser options
my $parseropts="";

open(FD,"$mymailbox");
# new mbox object
my $mb = Mail::MboxParser->new($mymailbox,decode=>'ALL',parseropts=> $parseropts);
print "Starting decoding of Messages\n";
my $message_counter = 0;
# msg loop
while (my $msg = $mb->next_message) {
$msg->store_all_attachments(path => "./attachments_Inbox/");
print "processed ".++$message_counter." messages\n";
}
print "DONE\n";
close (FD);

Modul Mail::MboxParser at cpan.org