Skip Menu |

This queue is for tickets about the MIME-tools CPAN distribution.

Report information
The Basics
Id: 111733
Status: open
Priority: 0/
Queue: MIME-tools

People
Owner: Nobody in particular
Requestors: atnakus.arzah [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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!
Subject: Re: [rt.cpan.org #111733] MIME::Head->recommended_filename balks on apple mail filename header
Date: Wed, 3 Feb 2016 18:28:35 -0500
To: bug-MIME-tools [...] rt.cpan.org
From: Dianne Skoll <dfs [...] roaringpenguin.com>
Hi, I can't replicate the problem. I fed the email foo.eml (attached) into the script test.pl (also attached) as follows: perl test.pl < foo.eml and the output I received was as follows: non-leaf: type=multipart/mixed; fname=; disp= Wide character in print at test.pl line 38, <STDIN> line 26. leaf: type=application/vnd.openxmlformats-officedocument.wordprocessingml.document; fname=Ремонт стиралки.docx; disp=attachment There is a wide character warning, but it's in the print statement, not the subroutine call and it does not cause a crash. Can you write the smallest possible piece of code that replicates the problem and post it? Regards, Dianne.
Subject: REMOVED
Date: Sun, 31 Jan 2016 12:31:38 -0500
To: REMOVED
From: REMOVED
Download Ремонт стиралки.docx
application/vnd.openxmlformats-officedocument.wordprocessingml.document 225b

Message body not shown because it is not plain text.

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #111733] MIME::Head->recommended_filename balks on apple mail filename header
Date: Sun, 7 Feb 2016 18:20:42 -0800
To: Dianne Skoll via RT <bug-MIME-tools [...] rt.cpan.org>
From: Atnakus Arzah <atnakus.arzah [...] gmail.com>
Hi Dianne, You are right; when I tried to replicate the issue with your sample code, I wasn't able to do so. On digging deeper it seems during processing of the email in mimedefang-filter (custom code) somewhere I am modified the Content-Disposition header in the entity to have a binary string with the utf-8 decoded filename. "\x{420}\x{435}\x{43c}\x{43e}\x{43d}\x{442}". When the Content-Disposition header with the above binary string is input to the recommended_filename() function it balks. Regards, Atnakus On Wed, Feb 03, 2016 at 06:28:49PM -0500, Dianne Skoll via RT wrote: Show quoted text
><URL: https://rt.cpan.org/Ticket/Display.html?id=111733 > > >Hi, > >I can't replicate the problem. I fed the email foo.eml (attached) into the >script test.pl (also attached) as follows: > > perl test.pl < foo.eml > >and the output I received was as follows: > >non-leaf: type=multipart/mixed; fname=; disp= >Wide character in print at test.pl line 38, <STDIN> line 26. > leaf: type=application/vnd.openxmlformats-officedocument.wordprocessingml.document; fname=Ремонт стиралки.docx; disp=attachment > > >There is a wide character warning, but it's in the print statement, not >the subroutine call and it does not cause a crash. > >Can you write the smallest possible piece of code that replicates the problem >and post it? > >Regards, > >Dianne. >
Show quoted text
>#!perl -w >use strict; >use warnings; >use MIME::Parser; > >my $parser = MIME::Parser->new(); >$parser->extract_nested_messages(1); >$parser->extract_uuencode(1); >$parser->output_to_core(1); >$parser->tmp_to_core(1); > >my $entity = $parser->parse(\*STDIN); >if (!$entity) { > die qq{Could not parse MIME: $!\n}; >} > >print_entity_structure( $entity, 0 ); >exit(0); > >sub print_entity_structure >{ > my ($in, $level) = @_; > my ($type) = $in->mime_type; > my @parts = $in->parts; > $type =~ tr/A-Z/a-z/; > my ($disposition) = $in->head->mime_attr("Content-Disposition"); > my ($body) = $in->bodyhandle; > > my $fname = $in->head->recommended_filename() || ''; > > $disposition = "inline" unless defined($disposition); > > print " " x $level; > if(!defined($body)) { > print "non-leaf: type=$type; fname=$fname; disp=$disposition\n"; > map { print_entity_structure($_, $level + 1) } @parts; > } else { > print "leaf: type=$type; fname=$fname; disp=$disposition\n"; > } >}
-- Atnakus Arzah <atnakus.arzah@gmail.com> When in doubt, have a cookie!