Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Parsing a Unix Mbox

by Corion (Patriarch)
on Jul 16, 2002 at 18:59 UTC ( [id://182200]=note: print w/replies, xml ) Need Help??


in reply to Parsing a Unix Mbox

Yes. I really recommend Mail::Box - the documentation has some examples that should get you started, and the mail handling is painless in my opinion. Installation should be straightforward for you if you have superuser permissions on your system, otherwise a local installation of the modules will work as well.

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

Replies are listed 'Best First'.
Re: Re: Parsing a Unix Mbox
by Anonymous Monk on Jul 16, 2002 at 19:41 UTC
    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.

      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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2024-04-19 00:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found