Subject: | mishandling a 0-length multipart preamble |
The multipart parser does not distinguish between a 0-length preamble
and an omitted preamble. Reading in a multipart with a 0-length
preamble and then writing it out again causes the preamble to be
deleted, breaking any enclosing digital signature.
The attached patch contains a fix.
Subject: | Mail-Box-2.082-preamble.diff |
diff -ru ./lib/Mail/Box/Parser/Perl.pm ../Mail-Box-2.082-2preamble/lib/Mail/Box/Parser/Perl.pm
--- ./lib/Mail/Box/Parser/Perl.pm 2010-02-03 17:25:45.000000000 -0800
+++ ../Mail-Box-2.082-2preamble/lib/Mail/Box/Parser/Perl.pm 2010-02-04 10:14:10.000000000 -0800
@@ -170,10 +170,17 @@
push @$lines, $line;
}
- if(@$lines && $lines->[-1] =~ s/(\r?\n)\z//)
- { $file->seek(-length($1), 1);
- pop @$lines if length($lines->[-1])==0;
- }
+ if(@$lines)
+ {
+ if ($lines->[-1] =~ s/(\r?\n)\z//)
+ { $file->seek(-length($1), 1);
+ pop @$lines if length($lines->[-1])==0;
+ }
+ }
+ else
+ {
+ $lines = undef;
+ }
}
else # File without separators.
{ $lines = ref $file eq 'Mail::Box::FastScalar'
@@ -182,11 +189,11 @@
my $bodyend = $file->tell;
- if($self->{MBPP_strip_gt})
+ if($self->{MBPP_strip_gt} && $lines)
{ map { s/^\>(\>*From\s)/$1/ } @$lines;
}
- unless($self->{MBPP_trusted}) { s/\015$// for @$lines }
+ unless($self->{MBPP_trusted} || !$lines) { s/\015$// for @$lines }
#warn "($bodyend, $msgend, ".@$lines, ")\n";
($bodyend, $lines, $msgend);
Only in ../Mail-Box-2.082-2preamble/lib/Mail/Box/Parser: Perl.pm~
diff -ru ./lib/Mail/Message/Body/Multipart.pm ../Mail-Box-2.082-2preamble/lib/Mail/Message/Body/Multipart.pm
--- ./lib/Mail/Message/Body/Multipart.pm 2010-02-03 17:25:44.000000000 -0800
+++ ../Mail-Box-2.082-2preamble/lib/Mail/Message/Body/Multipart.pm 2010-02-04 10:11:08.000000000 -0800
@@ -240,7 +240,7 @@
->read($parser, $head);
$self->{MMBM_preamble} = $preamble
- if defined $preamble && $preamble->nrLines > 0;
+ if defined $preamble;
# Get the parts.
@@ -265,7 +265,7 @@
->read($parser, $head);
$self->{MMBM_epilogue} = $epilogue
- if defined $epilogue && $epilogue->nrLines > 0;
+ if defined $epilogue;
my $end = defined $epilogue ? ($epilogue->fileLocation)[1]
: @parts ? ($parts[-1]->fileLocation)[1]
Only in ../Mail-Box-2.082-2preamble/lib/Mail/Message/Body: Multipart.pm~