|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44570 mb_encode_mimeheader incorrectly folds iso-2022 text
Submitted: 2008-03-30 12:28 UTC Modified: 2008-07-31 16:24 UTC
From: tokul at users dot sourceforge dot net Assigned:
Status: Not a bug Package: mbstring related
PHP Version: 5.2CVS-2008-03-30 (snap) OS: Linux Debian Etch
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
48 - 32 = ?
Subscribe to this entry?

 [2008-03-30 12:28 UTC] tokul at users dot sourceforge dot net
mb_encode_mimeheader incorrectly folds iso-2022 texts. rfc 2047 chapter 3 second paragraph says that folded string must be reverted to ASCII. Code just splits ISO-2022 string without adding appropriate escapes.

Code works as expected only when mbstring.internal_encoding is set to correct value. This dependency of mb_encode_mimeheader() is not documented and catches all users that are not used to mb_encode_mimeheader() quirks.

Reproduce code:
/** See */
$string = "\xe7\xa7\x8b\xe3\x81\xae\xe7\x94\xb0\xe3\x81\xae\x20"

$string_iso2022 = mb_convert_encoding($string,'iso-2022-jp','utf-8');
echo mb_encode_mimeheader($string_iso2022,'iso-2022-jp','b');

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-30 12:45 UTC] tokul at users dot sourceforge dot net
If mbstring.internal_encoding is set, code does not need mb_convert_encoding() call.
 [2008-07-31 16:24 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

That's exactly why mb_encode_mimeheader() converts the given string and encode it to MIME encoding at the same time. You may have been confused by the fact mb_encode_mimeheader() does not take an argument that specifies the encoding of the supplied string contrary to other mbstring functions. You should make sure that the internal encoding is set to the correct value prior to using it.

$string = "\xe7\xa7\x8b\xe3\x81\xae\xe7\x94\xb0\xe3\x81\xae\x20"
//$string = mb_convert_encoding($string,'iso-2022-jp','utf-8');
echo mb_encode_mimeheader($string,'iso-2022-jp','b');


PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 23 00:01:31 2024 UTC