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;