Skip Menu |
 

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

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

People
Owner: Nobody in particular
Requestors: frank [...] openminds.be
Cc: dfs+pause [...] roaringpenguin.com
AdminCc:

Bug Information
Severity: Important
Broken in:
  • 5.420
  • 5.427
Fixed in: (no value)



CC: dfs+pause [...] roaringpenguin.com
Subject: Double ; parsing bug in ParseParams
Download (untitled) / with headers
text/plain 1.1k
I was debugging an issue with our anti-spam setup, and ran into the following "bug" in Mime::Tools. It seems there is an increasing number of mailers out there (eg the mailinglist software of the popular Typo3 CMS) that send "strange" multipart headers. They send something like this: Show quoted text
> X-Mailer: TYPO3 Direct Mail module > X-Priority: 3 > Mime-Version: 1.0 > Content-Type: multipart/alternative;; > boundary="----------part_1_499d36ca96aea"
(Notice the double ; between multipart/alternative and the boundary). I couldn't find any specific reference in the RFCs about double-;'s but it seems MIME::Tools fails to parse it correctly. To test this, I wrote a small script: Show quoted text
> #!/usr/bin/perl > # > use MIME::Head; > > my $head = MIME::Head->new->from_file("testmail"); > > print "mimetype: " . $head->mime_type; > print "\n"; > print "boundary: " . $head->multipart_boundary; > print "\n";
Expected output would be: Show quoted text
> mimetype: multipart/alternative > boundary: ----------part_1_499d36ca96aea
while actual output is: Show quoted text
> mimetype: multipart/alternative > boundary:
This has been tested with v5.8.8 and MIME::Tools verions 5.420 and 5.427 (installed from CPAN).
Download (untitled) / with headers
text/plain 705b
I think (but I am not sure, it's been quite a while since my perl-dev days) that this should fix it: MIME/Field/ParamVal.pm line 237: - $raw =~ m/\G$SPCZ\;$SPCZ/og or last; # skip leading separator + $raw =~ m/\G$SPCZ\;+$SPCZ/og or last; # skip leading separator You can use this as a test: # Trivial test with ;; separators instead of ; { my $header = 'stuff;; answer="42"'; my $field = Mail::Field->new('Content-type'); $field->parse( $header ); is( $field->param('_'), 'stuff', 'Got body of header'); is( $field->param('answer'), "42", 'answer param was found correctly'); } Existing tests continue to work
Download (untitled) / with headers
text/plain 765b
Thanks for the report. I prefer the patch at the end of this reply, because it handles things like "; ;" (that is, two semicolons but with space between them.) Regards, David. @@ -234,7 +234,7 @@ sub parse_params { # Extract subsequent parameters. # No, we can't just "split" on semicolons: they're legal in quoted strings! while (1) { # keep chopping away until done... - $raw =~ m/\G$SPCZ\;$SPCZ/og or last; # skip leading separator + $raw =~ m/\G$SPCZ(\;$SPCZ)+/og or last; # skip leading separator $raw =~ m/\G($PARAMNAME)\s*=\s*/og or last; # give up if not a param $param = lc($1); $raw =~ m/\G(\"([^\"]*)\")|\G($ENCTOKEN)|\G($BADTOKEN)|\G($TOKEN)/g or last; # give up if no value"
Download (untitled) / with headers
text/plain 242b
On Do. Feb. 19 12:45:07 2009, DSKOLL wrote: Show quoted text
> Thanks for the report. I prefer the patch at the end of this > reply, because it handles things like "; ;" (that is, two semicolons > but with space between them.) >
Indeed, yours is better :)
Fixed in 5.428 release


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.