[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Select body of a mailbox



Paul Schinder wrote:

> At 1:22 AM +0200 8/8/00, Giorgio Valoti wrote:
> >Hi all,
> >I'd like to select the body of every email in mailbox file... This
> >mailbox is just a list of messages separated with a new line; of course,
> >i've already found a way to select the mail headers, but what about the
> >body of the messages?
> >TIA
>
> This doesn't sound like a "normal" mailbox like Eudora or most Unix
> mail clients use, where messages are separated by lines that match
> the regex /^From\s/.  If it was, you could use Mail::Util::read_mbox
> (part of MailTools) to separate the individual messages.
>
> In a normal mail message, everything from the beginning to the first
> blank line is header, while everything after that to the end of the
> message is body.  So look for the first blank line, and everything
> after it is body.

Yep it works... here's tjust a test script:

#! /usr/bin/perl -w

use strict;
use Mail::Util;
use Mail::Header;

my $mailbox = "path:to:mailbox";
open MAILBOX, $mailbox
 or die "Non posso aprire MAILBOX: $!\n";
open HEADER, ">Macintosh HD:Desktop Folder:Header"
 or die "Non posso aprire HEADER: $!";
open BODY, ">Macintosh HD:Desktop Folder:Body"
 or die "Non posso aprire BODY: $!";
my $fh = \*MAILBOX;
my @msgs = Mail::Util::read_mbox($mailbox);



foreach my $msg (@msgs)
{
 my $head = new Mail::Header $msg;
 my $header = $head -> header ($msg);
 print HEADER @$header;
 print BODY @$msg;
}

close MAILBOX;
close HEADER;
close BODY;

Now, with the test file (>13MB) I had to increase the Perl memory partition
to  45MB.... Am I missing something obvious or that's the only way to deal
with this problem?


--
Giorgio Valoti

MagneticMedia Network



# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org