[php-maint] Bug#660160: php-mail-mimedecode: _decodeHeader is recursive
Jasen Betts
jasen at nikita.treshna.com
Thu Feb 16 23:59:39 UTC 2012
Package: php-mail-mimedecode
Version: 1.5.0-3
Severity: normal
_decodeHeader is recursive in nature re-parsing its output until no
more is found. this leads to some headers that contain encoded versions
of what looks like RFC2047 data to be misrepresented,
EG: "test =?us-ascii?B?PT9VVEYtOD9RP3h4Pz0=?= 123"
should decode to "test =?UTF-8?Q?xx?= 123"
but does not.
it also folds all character sets together losing some of the
information it it meant to retrieve,
here is a corrected version which consistently outputs utf-8:
function _decodeHeader($input) /* undo rfc2047 encoding */
{
$output='';
// Remove white space between encoded-words
$input = preg_replace('/(=\?[^?]+\?(q|b)\?[^?]*\?=)(\s)+=\?/i', '\1=?', $input);
// For each encoded-word...
while (preg_match('/(=\?([^?]+)\?(q|b)\?([^?]*)\?=)/i', $input, $matches)) {
$encoded = $matches[1];
$charset = $matches[2];
$encoding = $matches[3];
$text = $matches[4];
switch (strtolower($encoding)) {
case 'b':
$text = base64_decode($text);
break;
case 'q':
$text = str_replace('_', ' ', $text);
preg_match_all('/=([a-f0-9]{2})/i', $text, $matches);
foreach($matches[1] as $value)
$text = str_replace('='.$value, chr(hexdec($value)), $text);
break;
}
$text= iconv($charset,'UTF-8',$text); // you may not want this?
$pos=strpos($input,$encoded);
$len=strlen($encoded);
$output.=substr($input,0,$pos).$text;
$input=substr($input,$pos+$len);
}
$output .= $input;
return $output;
}
-- System Information:
Debian Release: 6.0.4
APT prefers stable
APT policy: (500, 'stable')
Architecture: amd64 (x86_64)
Kernel: Linux 2.6.32-5-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_NZ.UTF-8, LC_CTYPE=en_NZ.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages php-mail-mimedecode depends on:
ii php-pear 5.3.3-7+squeeze6 PEAR - PHP Extension and Applicati
php-mail-mimedecode recommends no packages.
php-mail-mimedecode suggests no packages.
-- debconf-show failed
More information about the pkg-php-maint
mailing list