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

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