in reply to Re: parsing text portion out of email
in thread parsing text portion out of email

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
  • Comment on Re^2: parsing text portion out of email

Replies are listed 'Best First'.
Re^3: parsing text portion out of email
by ady (Deacon) on Mar 31, 2005 at 14:32 UTC
    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\