php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #43345 broken mb_encode_mimeheader()
Submitted: 2007-11-20 11:14 UTC Modified: 2008-11-07 15:14 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: wiela at centras dot lt Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.2.5 OS: Windows XP HE
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: wiela at centras dot lt
New email:
PHP Version: OS:

 

 [2007-11-20 11:14 UTC] wiela at centras dot lt
Description:
------------
php v5.2.5, mb_encode_mimeheader(), both QP and base64 encoding schemes incorrectly encodes utf-8 strings.

Reproduce code:
---------------
// $str1 and $str2 characters are in the Latin-Extended-A plane

// $str1 is 'utf-8' string, its base64_encode is:
// 'xITEjMSYxJbErsWgxbLFqsW9'
$str1 = "ĄČĘĖĮ?ŲŪ?";

// $str2 is 'utf-8' string, its base64_encode is:
// 'xIXEjcSZxJfEr8WhxbPFq8W+'
$str2 = "ąčęėį?ųū?"; 

echo mb_encode_mimeheader($str1, 'UTF-8', 'Q');
echo mb_encode_mimeheader($str1, 'UTF-8', 'B');
echo mb_encode_mimeheader($str2, 'UTF-8', 'Q');
echo mb_encode_mimeheader($str2, 'UTF-8', 'B');

Expected result:
----------------
for $str1, QP encoding:
=?UTF-8?Q?=C4=84=C4=8C=C4=98=C4=96=C4=AE=C5=A0=C5=B2=C5=AA=C5=BD?=

for $str1, base64 encoding:
=?UTF-8?B?xITEjMSYxJbErsWgxbLFqsW9?=

for $str2, QP encoding:
=?UTF-8?Q?=C4=85=C4=8D=C4=99=C4=97=C4=AF=C5=A1=C5=B3=C5=AB=C5=BE?=

for $str2, base64 encoding:
=?UTF-8?B?xIXEjcSZxJfEr8WhxbPFq8W+?=



Actual result:
--------------
for $str1, QP encoding:
=?UTF-8?Q?=C3=84=C2=84=C3=84=C2=8C=C3=84=C2=98=C3=84=C2=96=C3=84=C2=AE?=
 =?UTF-8?Q?=C3=85=C2=A0=C3=85=C2=B2=C3=85=C2=AA=C3=85=C2=BD?=

for $str1, base64 encoding:
=?UTF-8?B?w4TChMOEwozDhMKYw4TClsOEwq7DhcKgw4XCssOFwqrDhcK9?=

for $str2, QP encoding:
=?UTF-8?Q?=C3=84=C2=85=C3=84=C2=8D=C3=84=C2=99=C3=84=C2=97=C3=84=C2=AF?=
 =?UTF-8?Q?=C3=85=C2=A1=C3=85=C2=B3=C3=85=C2=AB=C3=85=C2=BE?=

for $str2, base64 encoding:
=?UTF-8?B?w4TChcOEwo3DhMKZw4TCl8OEwq/DhcKhw4XCs8OFwqvDhcK+?=


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-20 12:41 UTC] carsten_sttgt at gmx dot de
> echo mb_encode_mimeheader($str1, 'UTF-8', 'Q');
With also setting mb_internal_encoding(), your example works:

| $str1  = "\xC4\x84\xC4\x8C\xC4\x98\xC4\x96\xC4\xAE"
| $str1 .= "\xC5\xA0\xC5\xB2\xC5\xAA\xC5\xBD";
|
| mb_internal_encoding('UTF-8');
| echo mb_encode_mimeheader($str1, 'UTF-8', 'Q');
 [2007-11-21 07:13 UTC] wiela at centras dot lt
Well, maybe it works, but it isn't supposed to work this way, because the documentation says *nothing* about this:

(PHP 4 >= 4.0.6, PHP 5)

mb_encode_mimeheader -- Encode string for MIME header
Description
string mb_encode_mimeheader ( string str [, string charset [, string transfer_encoding [, string linefeed [, string indent]]]] )


mb_encode_mimeheader() encodes a given string str by the MIME header encoding scheme. Returns a converted version of the string represented in ASCII. 

charset specifies the name of the character set in which str is represented in. The default value is determined by the current NLS setting (mbstring.language). 

transfer_encoding specifies the scheme of MIME encoding. It should be either "B" (Base64) or "Q" (Quoted-Printable). Falls back to "B" if not given. 

linefeed specifies the EOL (end-of-line) marker with which mb_encode_mimeheader() performs line-folding (a RFC term, the act of breaking a line longer than a certain length into multiple lines. The length is currently hard-coded to 74 characters). Falls back to "\r\n" (CRLF) if not given.
 [2008-11-07 15:14 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"mb_internal_encoding() should be set to same encoding."
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Dec 02 12:00:01 2025 UTC