Gossamer Forum
Home : General : Perl Programming :

GURU for MIME Parser

Quote Reply
GURU for MIME Parser
   
This works perfect both for text and html messages.

But when I send a html message including an image $body is blank.

In this case, in the email source I found:

------=_NextPart_000_0093_01C4129A.84505FE0
Content-Type: multipart/alternative;
boundary="----=_NextPart_001_0094_01C4129A.84505FE0"

note - boundary is calling the html code part.

I need suggestions!! :(




Code:


use MIME::Parser
my $entity = $parser->parse(\*STDIN) or die "couldn't parse INPUT";
if ($entity->parts > 0) {
for (my $i=0;$i<$entity->parts;$i++) {
my $subEntity = $entity->parts($i);
if (my $io = $subEntity->open("r")) {

my $type = $subEntity->head->mime_attr("Content-Type");
if ($type eq "text/plain" ) {
while (defined($_=$io->getline)) { $body .= $_; }
$io->close;
}
}
}
}
else { $body = $entity->bodyhandle->as_string; }
Quote Reply
Re: [dixi] GURU for MIME Parser In reply to
In Reply To:

This works perfect both for text and html messages.

But when I send a html message including an image $body is blank.

In this case, in the email source I found:

------=_NextPart_000_0093_01C4129A.84505FE0
Content-Type: multipart/alternative;
boundary="----=_NextPart_001_0094_01C4129A.84505FE0"

note - boundary is calling the html code part.

I need suggestions!! :(




Code:


use MIME::Parser
my $entity = $parser->parse(\*STDIN) or die "couldn't parse INPUT";
if ($entity->parts > 0) {
for (my $i=0;$i<$entity->parts;$i++) {
my $subEntity = $entity->parts($i);
if (my $io = $subEntity->open("r")) {

my $type = $subEntity->head->mime_attr("Content-Type");
if ($type eq "text/plain" ) {
while (defined($_=$io->getline)) { $body .= $_; }
$io->close;
}
}
}
}
else { $body = $entity->bodyhandle->as_string; }


The following might help:

Code:
Content-type: multipart/related
Effective-type: multipart/related
Body-file: NONE
Subject: sss
Num-parts: 2
--
Content-type: multipart/alternative
Effective-type: multipart/alternative
Body-file: NONE
Num-parts: 2
--
Content-type: text/plain
Effective-type: text/plain
Body-file: NONE
--
Content-type: text/html
Effective-type: text/html
Body-file: NONE
--
Content-type: image/gif
Effective-type: image/gif
Body-file: NONE
Recommended-filename: logo_email2.gif


--

I guess that the problem is in the way i read data.
Notice: We have a multipart message. I can read text/plain on the higher level.

Code is welcome.