From: xueron at xueron dot com
Operating system: Redhat Linux AS 4.3
PHP version: 5.1.6
PHP Bug Type: mbstring related
Bug description: mb_decode_mimeheader() bug
Description:
------------
When i use mb_decode_mimeheader() to decode a long MIME-encoded Chinese
subject and convert it to UTF-8, there was something wrong if the subject
was splited into more than one parts, like this:
Subject:
=?gb2312?q?=D6=D8=D2=AA=BB=E1=D2=E9=CD=A8=D6=AA-06=C4=EA=B5=DA=C8=FD=BC?=
=?gb2312?q?=BE=B6=C8=BE=AD=BC=C3=B7=D6=CE=F6=BB=E1=F4=DF07=C4=EA=D4=A4=CB?=
=?gb2312?q?=E3=B9=A4=D7=F7=B6=AF=D4=B1=BB=E1=D2=E9?=
It seems that mb_decode_mimeheader() decode and convert each part and at
last, concatenate them. But in fact, all parts should be decoded and
concatenated and then, do the charset convert.
Reproduce code:
---------------
$s = mb_decode_mimeheader($s);
vs.
$a = imap_mime_header_decode($s);
if (is_array($a) && count($a) > 0) {
$r = ''; $c = array();
for ($i = 0; $i < count($a); $i++) {
if ($a[$i]->charset == 'default') {
array_push($c, 'ASCII');
} else {
array_push($c, $a[$i]->charset);
}
//$e = mb_detect_encoding($a[$i]->text, $c);
//$o = mb_convert_encoding($a[$i]->text, "UTF-8", $c);
//$r .= $o;
$r .= $a[$i]->text;
}
$e = mb_detect_encoding($r, $c);
$r = mb_convert_encoding($r, "UTF-8", $e);
Expected result:
----------------
重要会议通知-06年第三季度经济分析会暨07年预算工作动员会议
Actual result:
--------------
重要会议通知-06年第三径染?梅治龌狒?7年预愎ぷ鞫?被嵋
--
Edit bug report at http://bugs.php.net/?id=39303&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=39303&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=39303&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=39303&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=39303&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=39303&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=39303&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=39303&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=39303&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=39303&r=support
Expected behavior: http://bugs.php.net/fix.php?id=39303&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=39303&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=39303&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=39303&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39303&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=39303&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=39303&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=39303&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=39303&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=39303&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=39303&r=mysqlcfg