php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39303 mb_decode_mimeheader() bug
Submitted: 2006-10-30 07:57 UTC Modified: 2006-11-07 01:00 UTC
From: xueron at xueron dot com Assigned:
Status: No Feedback Package: mbstring related
PHP Version: 5.1.6 OS: Redhat Linux AS 4.3
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: xueron at xueron dot com
New email:
PHP Version: OS:

 

 [2006-10-30 07:57 UTC] xueron at xueron dot com
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:
----------------
&#37325;&#35201;&#20250;&#35758;&#36890;&#30693;-06&#24180;&#31532;&#19977;&#23395;&#24230;&#32463;&#27982;&#20998;&#26512;&#20250;&#26280;07&#24180;&#39044;&#31639;&#24037;&#20316;&#21160;&#21592;&#20250;&#35758;

Actual result:
--------------
&#37325;&#35201;&#20250;&#35758;&#36890;&#30693;-06&#24180;&#31532;&#19977;&#24452;&#26579;?&#26757;&#27835;&#40844;&#29394;?7&#24180;&#39044;&#24846;&#12407;&#38827;?&#34987;&#23883;

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-30 08:45 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip


 [2006-11-07 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 15:01:31 2025 UTC