Subject: | MIME::Head->recommended_filename balks on apple mail filename header |
Date: | Wed, 3 Feb 2016 14:29:42 -0800 |
To: | bug-MIME-tools [...] rt.cpan.org |
From: | Atnakus Arzah <atnakus.arzah [...] gmail.com> |
Hi!
When processing the below email. The function recommended_filename in MIME::Head crashes with the following error:
Wide character in subroutine entry at /home/perluser/perl5/perlbrew/perls/perl-5.20.3/lib/site_perl/5.20.3/MIME/WordDecoder.pm line 616.
From my debugging it looks like the filename in the following header is the culprit:
Content-Disposition: attachment;
filename*=utf-8''%D0%A0%D0%B5%D0%BC%D0%BE%D0%BD%D1%82%20%D1%81%D1%82%D0%B8%D1%80%D0%B0%D0%BB%D0%BA%D0%B8.docx
Snippet of the email showing the relevant headers:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Received: REMOVED
From: REMOVED
Content-Type: multipart/mixed; boundary="Apple-Mail=_AAC51E3A-BCE0-4F2E-BC5E-A157B709E0ED"
Subject: REMOVED
Message-Id: REMOVED
Date: Sun, 31 Jan 2016 12:31:38 -0500
To: REMOVED
Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\))
X-Mailer: Apple Mail (2.2104)
--Apple-Mail=_AAC51E3A-BCE0-4F2E-BC5E-A157B709E0ED
Content-Disposition: attachment;
filename*=utf-8''%D0%A0%D0%B5%D0%BC%D0%BE%D0%BD%D1%82%20%D1%81%D1%82%D0%B8%D1%80%D0%B0%D0%BB%D0%BA%D0%B8.docx
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document;
name="=?utf-8?B?0KDQtdC80L7QvdGCINGB0YLQuNGA0LDQu9C60LguZG9jeA==?="
Content-Transfer-Encoding: base64
UEsDBBQABgAIAAAAIQDpURCwjQEAAMIFAAATAAgCW0NvbnRlbnRfVHlwZXNd
LnhtbCCiBAIooAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Original code:
sub recommended_filename
{
my $self = shift;
# Try these headers in order, taking the first defined,
# non-blank one we find.
my $wd = supported MIME::WordDecoder 'UTF-8';
foreach my $attr_name ( qw( content-disposition.filename content-type.name ) ) {
my $value = $self->mime_attr( $attr_name );
if ( defined $value
&& $value ne ''
&& $value =~ /\S/ ) {
return $wd->decode($value); // XXX: CRASHES HERE
}
}
return undef;
}
Current fix used:
sub recommended_filename
{
my $self = shift;
# Try these headers in order, taking the first defined,
# non-blank one we find.
my $wd = supported MIME::WordDecoder 'UTF-8';
foreach my $attr_name ( qw( content-disposition.filename content-type.name ) ) {
my $value = $self->mime_attr( $attr_name );
if ( defined $value
&& $value ne ''
&& $value =~ /\S/ ) {
eval {return $wd->decode($value);}; // XXX: Wrapped in eval to catch error.
}
}
return undef;
}
Please let me know if this fix is appropriate.
--
Atnakus Arzah <atnakus.arzah@gmail.com>
When in doubt, have a cookie!