Skip Menu |
 

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

Report information
The Basics
Id: 71677
Status: resolved
Priority: 0/
Queue: MIME-tools

People
Owner: dfs+pause [...] roaringpenguin.com
Requestors: okikarai [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in:
  • 5.425
  • 5.502
Fixed in: (no value)



Subject: Parser behaves badly with attachments containing some characters
Download (untitled) / with headers
text/plain 815b
Tested on the following environments: 1) Distribution: MIME-tools-5.425 Perl version: v5.8.8 OS: Linux 2.6.18-53.el5xen i686 i686 i386 GNU/Linux, Red Hat Enterprise Linux Server release 5.1 (Tikanga) and 2) Distribution: MIME-tools-5.502 Perl version: v5.10.1 OS: Windows 7 During the extraction of attachments from an e-mail, if the attachment name contains one of the following characters such as [, ], {, }. (example: [Untitled].pdf) the generated file will be ".pdf". Plus, if this situation occurs again in this operation (if more attachments have these characters) the next filenames would be named -1, -2, and so on. File: /usr/lib/perl5/site_perl/5.8.8/MIME/Parser/Filer.pm Line 399: $last =~ s{^.*[/\\\[\]:]}{}; Replacing the previous line with: $last =~ s/[\/\\\[\]:]/_/g; should fix the problem.
Subject: Re: [rt.cpan.org #71677] Parser behaves badly with attachments containing some characters
Date: Wed, 19 Oct 2011 13:31:39 -0400
To: bug-MIME-tools [...] rt.cpan.org
From: "David F. Skoll" <dfs [...] roaringpenguin.com>
Download (untitled) / with headers
text/plain 2.7k
Hi, Show quoted text
> During the extraction of attachments from an e-mail, if the > attachment name contains one of the following characters such as > [, ], {, }. (example: [Untitled].pdf) the generated file will be > ".pdf".
Thanks for your bug report. I don't really like your patch because it doesn't quite capture the intent, which is to strip of directories as well. For example, "foo/bar/chunk.pdf" should be exorcised down to "chunk.pdf". Nevertheless, I agree the current behavior is wrong. I propose the following patch. Regards, David. ============================================================================== diff --git a/MANIFEST b/MANIFEST index e125890..bb1bd0c 100644 --- a/MANIFEST +++ b/MANIFEST @@ -76,6 +76,7 @@ t/ticket-52924.t t/ticket-60931.t t/ticket-65681.t t/ticket-66025.t +t/ticket-71677.t t/WordDecoder.t t/WordEncoder.t t/Words.t diff --git a/lib/MIME/Parser/Filer.pm b/lib/MIME/Parser/Filer.pm index f16bf6b..ce93c45 100644 --- a/lib/MIME/Parser/Filer.pm +++ b/lib/MIME/Parser/Filer.pm @@ -396,7 +396,13 @@ sub exorcise_filename { my ($self, $fname) = @_; ### Isolate to last path element: - my $last = $fname; $last =~ s{^.*[/\\\[\]:]}{}; + my $last = $fname; + + ### Path separators are / or \ + $last =~ s{^.*[/\\]}{}; + + ### Convert semi-evil characters to underscores + $last =~ s/[\/\\\[\]:]/_/g; if ($last and !$self->evil_filename($last)) { $self->debug("looks like I can use the last path element"); return $last; diff --git a/t/Filer.t b/t/Filer.t index dd151de..61beea2 100644 --- a/t/Filer.t +++ b/t/Filer.t @@ -33,7 +33,7 @@ BEGIN { 'trailing_space ' => 'trailing_space.dat', '.' => '..dat', '..' => '...dat', - 'index[1].html' => '.html', + 'index[1].html' => 'index_1_.html', " wookie\x{f8}.doc" => "wookie%F8.doc", " wookie\x{042d}.doc" => $wookie, ); diff --git a/t/ticket-71677.t b/t/ticket-71677.t new file mode 100644 index 0000000..68a8b6a --- /dev/null +++ b/t/ticket-71677.t @@ -0,0 +1,25 @@ +#!/usr/bin/perl +use Test::More tests => 2; +use MIME::Parser; + +my $msg = <<'EOF'; +From: <devnull@example.com> +To: <devnull@example.com> +Subject: Weird filename test +MIME-Version: 1.0 +Content-Type: application/octet-stream; name="[wookie].bin" +Content-Disposition: attachment; filename="[wookie].bin" + +Wookie +EOF + +my $parser = MIME::Parser->new(); +$parser->output_to_core(0); +$parser->output_under("testout"); +my $entity = $parser->parse_data($msg); +my $body = $entity->bodyhandle; +my $path = $body->path; +ok(defined($path), 'Path exists'); +ok($path =~ /_wookie_\.bin$/, 'And has the expected form'); + +$parser->filer->purge;
From: okikarai [...] gmail.com
Download (untitled) / with headers
text/plain 194b
Hi David, Thank you for your quick reply. I've tested your patch proposal and it suits me perfectly. Do you have any idea of when you can officially release this version? Best regards, Renato
Download (untitled) / with headers
text/plain 108b
Hi, I have just uploaded MIME-tools-5.503 to CPAN, which I believe resolves this ticket. Regards, David.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.