in reply to parsing text portion out of email

You probably want to check out Email::Simple and Email::MIME.

/J\

Replies are listed 'Best First'.
Re^2: parsing text portion out of email
by ady (Deacon) on Mar 31, 2005 at 14:01 UTC
    WOW!
    Seems Email::Simple did the job in ½ a minute, while i have been hacking at a manual filter for >1hour..., without quite fixing all loose ends.
    Thanks a heap mate! Best regards
    Allan
      NAAHH...
      Too fast there....
      Hangs on this code... gotta figure out why?

      #!/usr/bin/perl -w use strict; use Email::Simple; my $dir = "."; opendir (DH, $dir) or die "Can't open directory $dir: $!"; while (defined (my $file = readdir(DH))) { next if ($file =~ /^\.\.?$/); open (FH, "$dir\\$file") or die "Can't open $dir\\$file: $!\n"; my $e = do { local $/; <FH> }; # slurp .msg file my $mail = Email::Simple->new($e); # convert to mail object (?) $e = $mail->body; # retrieve body text print $e; # dump to STDOUT close(FH) or die "Can't close $dir\\$file: $!\n"; } closedir(DH) or die "Can't close $dir: $!";

      allan

        I would recommend using Email::Folder (Or one of its relatives) to access the collection of e-mails rather than doing it yourself like that:

        use Email::Folder; my $dir = "."; my $folder = Email::Folder->new($dir); foreach my $message ( @{$folder->messages()}) { print $message->body(); }
        (Untested as I don't have a maildir delivery)

        /J\

Re: parsing text portion out of email
by b10m (Vicar) on Mar 31, 2005 at 13:50 UTC

    Two modules the OP can probably use well. If not, then MIME::Parser is a good option. I've recently used that and seems to work quite good. And of course Mail::Box if you have time to spare to dig through the extensive and often non-clear documentation ;)

    --
    b10m

    All code is usually tested, but rarely trusted.