in reply to Re: Parsing a Unix Mbox
in thread Parsing a Unix Mbox

My systems admin installed Mail::Box version 1.324; couldn't install Mail::Box version 2.015 which needs Perl 5.6. I ran the two examples in version 1.324. I need some help with using these modules. Which module do I use to extract the body of the message. Can you show me a sample script to print the body of the message. I ran the example script that loops through each message in the mbox to print the headings. I'm new to perl and perl modules. Is this task difficult to accomplish without using a module? If so could you briefly explain it to me so that I can explain it to my boss. Thanks.

Replies are listed 'Best First'.
Re: Re: Re: Parsing a Unix Mbox
by Corion (Patriarch) on Jul 16, 2002 at 19:55 UTC

    Yes, this task is very difficult to do right without a module, and I won't explain it here, as explaining it means reformulating the mbox manpage (found here for example) and Mail::Box handles it very nicely. I have only used Mail::Box after version 2, but I guess that the basic methods haven't changed that much since :

    #!/usr/bin/perl -w # Some vestige of local delivery # For another method, have a look at Mail::LocalDelivery use strict; use Mail::Box; use Mail::Box::Manager; use Mail::Message; use Mail::Message::Construct; use vars qw($localmailbase $foldername); use vars qw($mgr $folder); $host = 'hera.informatik.uni-frankfurt.de'; $localmailbase = "/home/corion/mail/"; $foldername = "informatik"; $mgr = Mail::Box::Manager->new(folderdir => $localmailbase, default_folder_type => 'mbox', ); $folder = $mgr->open( folder => $foldername, access => 'rw', create => + 1 ); die "Couldn't open mailfolder '$foldername' : $!\n" unless $folder; print "Using folder ",$folder->name,"\n"; my %messageIDs; %messageIDs = map { $_->get("Message-ID"), $_ } ($folder->messages); my $msg; foreach $msg ($folder->messages) { print "*** The content of this message is :\n"; print $msg->body; } $mgr->close($folder);

    I don't have access to any older Mail::Box documentation at the moment, but each message should have the body method, which returns the body of the message as a string.

    perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web