PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Mail » Mail_mimeDecode » Bug #9616

Failure to parse [file]name*0=x; [file]name*1=x

Details

Submitted2006-12-14 17:54 UTC
Froml0c4lh0st dot nl at gmail dot com
Assignedalan_k
StatusClosed
PackageMail_mimeDecode
PHP Version5.1.2
OSWindows
Roadmaps1.6.0

Comments

[2006-12-14 17:54 UTC] l0c4lh0st dot nl at gmail dot com

Description:
------------
When parsing the headers, it fails to recognize the filename*0=x; filename*1=blah; filename*2=blah; (I assume this is used because of long filenames, the filename I had was pretty long).

Anyway, you get the seperate parts (the means, filename*0, filename*1 etc. etc.).

With the fix below you get the full filename.

Test script:
---------------
<?php
/* (It's kinda nasty, but does the trick.) */

// This splits on a semi-colon, if there's no preceeding backslash
// Now works with quoted values; had to glue the \; breaks in PHP
// the regex is already bordering on incomprehensible

$splitRegex = '/([^;\'"]*[\'"]([^\'"]*([^\'"]*)*)[\'"][^;\'"]*|([^;]+))(;|$)/';
preg_match_all($splitRegex, $input, $matches);

/* Start fix. */
if (preg_match('/^([^\*]+)\*0\=/is', $matches[0][0], $aMatches))
{
$matches[0] = array($aMatches[1] . '=' . implode('', $matches[2]));
}
/* End fix. */
?>

Expected result:
----------------
stdClass Object
(
[headers] => Array
(
[content-type] => image/jpeg; name*0="verylongfilenamegoeshereblabla.jpg"
[content-transfer-encoding] => base64
[content-id] => <xxxxxxxxxxx@gmail.com>
[content-disposition] => inline; filename*0="verylongfilenamegoeshereblabla"; filename*1=".jpg"
)

[ctype_primary] => image
[ctype_secondary] => jpeg
[ctype_parameters] => Array
(
[name] => verylongfilenamegoeshereblabla.jpg
)

[disposition] => inline
[d_parameters] => Array
(
[filename] => verylongfilenamegoeshereblabla.jpg
)

)

Actual result:
--------------
stdClass Object
(
[headers] => Array
(
[content-type] => image/jpeg; name*0="verylongfilenamegoeshereblabla.jpg"
[content-transfer-encoding] => base64
[content-id] => <xxxxxxxxxxx@gmail.com>
[content-disposition] => inline; filename*0="verylongfilenamegoeshereblabla"; filename*1=".jpg"
)

[ctype_primary] => image
[ctype_secondary] => jpeg
[ctype_parameters] => Array
(
[name*0] => verylongfilenamegoeshereblabla.jpg
)

[disposition] => inline
[d_parameters] => Array
(
[filename*0] => verylongfilenamegoeshereblabla
[filename*1] => .jpg
)

)