Subject: | MIME::Field::ParamVal mishandles mixed RFC2231 and non-RFC2231 parameters |
When long parameter values are split per RFC2231 and a non-RFC2231
version is also present, MIME::Field::ParamVal::parse_params will
concatenate both versions together. Apple Mail, at least, uses both
parameter styles; for example:
Content-Disposition: inline;
filename="Once upon a time, there was a really long filename who lived
in the enchanted Internet";
filename*0="Once upon a time, there was a really long filename who l";
filename*1="ived in the enchanted Internet"
parse_params implicitly assigns the non-RFC2231 version to part 0, which
is fine, except that any parts with the same sequence number are
concatenated together. The resulting parsed filename is "Once upon a
time, there was a really long filename who lived in the enchanted
InternetOnce upon a time, there was a really long filename who lived in
the enchanted Internet"
The easiest fix is to have parts with the same sequence number replace
each other. RFC2231 doesn't say what should be done when the same
number is seen again, but there's no reason anyone reading the RFC
should want to use the same sequence number for more than one part
either. The attached patch (against 5.427) does exactly this, which
fixes the reported bug by preferring the RFC2231-style header when it's
present.
Test case:
use MIME::Field::ParamVal;
my ($res, $headerval);
$headerval = q{inline;
filename="Once upon a time, there was a really long filename who lived
in the enchanted Internet";
filename*0="Once upon a time, there was a really long filename who l";
filename*1="ived in the enchanted Internet"
};
$res = MIME::Field::ParamVal::parse_params("", $headerval);
printf("Filename: %s\n", $res->{filename});
Subject: | ParamVal.pm.diff |
--- MIME/Field/ParamVal.pm.orig 2008-12-10 16:35:51.488762758 -0500
+++ MIME/Field/ParamVal.pm 2008-12-10 16:35:56.965546083 -0500
@@ -266,7 +266,7 @@
if (!defined($qstr)) {
$val = rfc2231decode($val);
}
- $rfc2231params{$name}{$num} .= $val;
+ $rfc2231params{$name}{$num} = $val;
} else {
# Make a fake "part zero" for non-RFC2231 params
$rfc2231params{$param}{"0"} = $val;