Andre_br has asked for the wisdom of the Perl Monks concerning the following question:

Hello folks

I just canīt find any module that filters email headers correctly. I am using Email::Filter now. Maybe Iīm doing something wrong, so here it is. Itīs a little dirty yet, so please donīt mind that:

use Net::POP3; use Email::Filter; my $pop = Net::POP3->new($host); if ($pop->login($user, $pass) > 0) { my $msgnums = $pop->list; # hashref of msgnum => size foreach my $msgnum (keys %$msgnums) { my $msg = $pop->getfh($msgnum); my $message; while (<$msg>) { $message .= $_; } my $mail = Email::Filter->new(data => $message); my $body = $mail->body; print $body; # $pop->delete($msgnum); } } $pop->quit;
Email::Filter says this is the body:
This is a multi-part message in MIME format. ------=_NextPart_000_0025_01C5BE3F.21ECA0A0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Hello Just to test! Bye! Andr=E9 ------=_NextPart_000_0025_01C5BE3F.21ECA0A0
Ok, I can strpe out the first block before the \n\n and the last one too. But is this is supposed to work will all mesages? Isnīt there a cleaner way? Also because I will need to treat attachments too, and now I donīt have a clue of how to do that. Maybe this dirty solution doesnīt work with emails carrying attachments.

Please give me a hand if you can

Thanks

Andre_br

Replies are listed 'Best First'.
Re: Problems parsing emails from Net::Pop3 with Email::Filter
by Corion (Patriarch) on Sep 21, 2005 at 06:52 UTC

    Your diagnosis is correct - mails carrying attachments are encoded with MIME. Have a look at MIME::Lite as a MIME parser, or MIME::Parser.

      Hey Corion, thanks for the tip. But I took a look on both of them and coundnīt figure out wich method would serve for my case, and even if thereīs one that does. Can you or someone help me out a little further?