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

hellow monks,

i am constructing a new mail same as exixsting mail using MIME::Parser module. its working...
but the size of newly created mail is some kb more than the existig one.

here is my code
my $oldmail = "mailfile.eml"; my $parser = new MIME::Parser; my $entity = new MIME::Entity; $entity = $parser->parse_open($oldmail); $newmail = create_mail($entity); open(NEWMAIL, ">newmail.eml"); print NEWMAIL, $newmail->as_string; sub create_mail { my $mail = shift; my $encodetype = $mail->head->mime_encoding; if ($encodetype eq "base64") { my $body = $mail->bodyhandle; my $fname = $mail->head->recommended_filename; open(BODY, ">$fname") or die "Cant..."; print BODY $body->as_string; close(BODY); my $contype = $mail->head->get("Content-Type"); my $contranencode = $mail->head->get("Content-Transfer-Encodin +g"); my $condispo = $mail->head->get("Content-Disposition"); my $attachment = new MIME::Entity->build( Path => $fname, Type => $contype, Encoding => "base64", Filename => $fname, Disposition => $condispo); return $attachment; } elsif ($mail->parts > 0) { my $ent = new MIME::Entity; my $head = "mailhead.hdr"; open(HEAD, ">$head") or return printerror(); $mail->head->print(\*HEAD); close(HEAD); $ent->head(MIME::Head->from_file($head)); foreach my $part ($mail->parts) { my $subent = compress_mail($part); $ent->add_part($subent); } unlink $head; return $ent; } return $mail; }
any suggestion ...???

Replies are listed 'Best First'.
Re: problem with size of reconstructed email
by ikegami (Patriarch) on Oct 08, 2008 at 07:48 UTC

    If you're worried about the difference, it would help to know what is different. But you neither provided a sample email which demonstrates this difference nor shown the difference between an original email and its regeneration.

      here i am sending some difference between email files.

      (1)
      original mail part
      Content-Type: multipart/mixed; boundary="------------080809010202050907080509" This is a multi-part message in MIME format. --------------080809010202050907080509 Content-Type: multipart/alternative; boundary="------------060805000603060704000609" --------------060805000603060704000609

      duplicate mailpart
      Content-Type: multipart/mixed; boundary="------------080809010202050907080509" This is a multi-part message in MIME format... --------------080809010202050907080509 Content-Type: multipart/alternative; boundary="------------060805000603060704000609" This is a multi-part message in MIME format... --------------060805000603060704000609

      (2)
      original mail
      --------------080809010202050907080509 Content-Type: application/x-gzip; name="hi.tar.gz" Content-Transfer-Encoding: base64 Content-Disposition: inline; filename="hi.tar.gz"

      duplicate mail
      --------------080809010202050907080509 Content-Type: application/x-gzip; name="hi.tar.gz" Content-Transfer-Encoding: base64 Content-Disposition: inline; filename="hi.tar.gz" MIME-Version: 1.0 X-Mailer: MIME-tools 5.420 (Entity 5.420)

      (3)
      original mail part
      This is a multi-part message in MIME format. ------_=_NextPart_001_01C92D01.A2C75F1A Content-Type: multipart/alternative; boundary="----_=_NextPart_002_01C92D01.A2C75F1A" ------_=_NextPart_002_01C92D01.A2C75F1A Content-Type: text/plain;

      duplicate mail
      This is a multi-part message in MIME format... ------_=_NextPart_001_01C92D01.A2C75F1A Content-Type: multipart/alternative; boundary="----_=_NextPart_002_01C92D01.A2C75F1A" This is a multi-part message in MIME format... ------_=_NextPart_002_01C92D01.A2C75F1A Content-Type: text/plain;

      and i got some empty boundraries like
      Content-Type: multipart/alternative; boundary="----_=_NextPart_002_01C92D01.A2C75F1A" ------_=_NextPart_002_01C92D01.A2C75F1A

      so can u suggest me some changes or in code so it will not increase the size of duplicate mail(upto 4-5 kb its okey)
      Thanks
Re: problem with size of reconstructed email
by Anonymous Monk on Oct 08, 2008 at 07:20 UTC
    any suggestion ...??? Don't worry about it, and use binmode