Forum Moderators: coopster & phranque

Message Too Old, No Replies

Donīt know how to parse MIME multi-part messages

Iīve tried many modules but canīt figure it out.

         

phoenix_fly

3:26 pm on Sep 21, 2005 (gmt 0)

10+ Year Member



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 stripe 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

phoenix_fly

rocknbil

7:13 pm on Sep 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you asking to parse multipart per your topic or filter somehow? Have you tried CGI.pm? I use it almost exclusively to parse multipart for file uploading.

I found MIME:Lite to work well for email attachments.

phoenix_fly

12:54 am on Sep 22, 2005 (gmt 0)

10+ Year Member



Hey rocknbil

Thanks for the tip. But Iīm way too lost between all the MIME::Lite and CGI.pm methods. Can you give me a hint of wich method to use, for exemple, to safely extract that body above?

Thanks

phoenix_fly