#43345 [Opn]: broken mb_encode_mimeheader()

From: Date: Wed, 21 Nov 2007 07:13:56 +0000
Subject: #43345 [Opn]: broken mb_encode_mimeheader()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-119910@lists.php.net to get a copy of this message
ID: 43345 User updated by: wiela at centras dot lt Reported By: wiela at centras dot lt Status: Open Bug Type: mbstring related Operating System: Windows XP HE PHP Version: 5.2.5 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2007-11-20 12:41:59] 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-20 11:14:48] 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+?= ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43345&edit=1

« previous php.bugs (#119910) next »