Subject: | empty preamble bug |
Date: | Wed, 1 Sep 2010 08:43:12 +0000 |
To: | "bug-MIME-tools [...] rt.cpan.org" <bug-MIME-tools [...] rt.cpan.org> |
From: | Dietmar Maurer <dietmar [...] proxmox.com> |
Hi all,
when I parse a simple multipart message like:
------------------------------------------------
MIME-Version: 1.0
Received: by 10.220.78.157 with HTTP; Thu, 26 Aug 2010 21:33:17 -0700 (PDT)
Content-Type: multipart/alternative; boundary=90e6ba4fc6ea25d329048ec69d99
--90e6ba4fc6ea25d329048ec69d99
Content-Type: text/plain; charset=ISO-8859-1
HELLO
--90e6ba4fc6ea25d329048ec69d99
Content-Type: text/html; charset=ISO-8859-1
HELLO<br>
--90e6ba4fc6ea25d329048ec69d99--
-------------------------------------------------
and the call $entity->print(\*STDOUT) I get:
------------------------------------------------
MIME-Version: 1.0
Received: by 10.220.78.157 with HTTP; Thu, 26 Aug 2010 21:33:17 -0700 (PDT)
Content-Type: multipart/alternative; boundary=90e6ba4fc6ea25d329048ec69d99
--90e6ba4fc6ea25d329048ec69d99
Content-Type: text/plain; charset=ISO-8859-1
HELLO
...
-------------------------------------------------
Please note the additional line before the first boundary.
The following patch corrects that behavior:
Index: src/lib/MIME/Entity.pm
===================================================================
--- src.orig/lib/MIME/Entity.pm 2010-09-01 10:26:31.000000000 +0200
+++ src/lib/MIME/Entity.pm 2010-09-01 10:32:50.000000000 +0200
@@ -1793,8 +1793,14 @@
my $boundary = $self->head->multipart_boundary;
### Preamble:
- my $preamble = join('', @{ $self->preamble || $DefPreamble });
- $out->print("$preamble\n") if ($preamble ne '' or $self->preamble);
+ if (defined(my $plines = $self->preamble)) {
+ if (scalar(@$plines)) {
+ my $preamble = join('', @$plines);
+ $out->print("$preamble\n");
+ }
+ } else {
+ $out->print("$DefPreamble\n");
+ }
### Parts:
my $part;
- Dietmar