|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68821 Underscores left by mb_decode_mimeheaders
Submitted: 2015-01-13 03:47 UTC Modified: 2015-05-28 14:45 UTC
Avg. Score:3.9 ± 0.6
Reproduced:9 of 9 (100.0%)
Same Version:3 (33.3%)
Same OS:3 (33.3%)
From: php dot bohwaz at miam dot kd2 dot org Assigned:
Status: Verified Package: mbstring related
PHP Version: 5.4.36 OS: Debian/Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: php dot bohwaz at miam dot kd2 dot org
New email:
PHP Version: OS:


 [2015-01-13 03:47 UTC] php dot bohwaz at miam dot kd2 dot org
mb_decode_mimeheaders doesn't decode underscores as per the RFC 2047:

"The 8-bit hexadecimal value 20 (e.g., ISO-8859-1 SPACE) may be represented as "_" (underscore, ASCII 95.). (This character may not pass through some internetwork mail gateways, but its use will greatly enhance readability of "Q" encoded data with mail readers that do not support this encoding.) Note that the "_" always represents hexadecimal 20, even if the SPACE character occupies a different code position in the character set in use."

One example:

Subject: =?ISO-8859-1?Q?spring_into_ALDI_for_this_week=92s_special_buys_fr?=

Test script:

$subject = "=?ISO-8859-1?Q?spring_into_ALDI_for_this_week=92s_special_buys_fr?=

echo mb_decode_mimeheaders($subject);


Expected result:
spring into ALDI for this weeks special buys from thurs 30 sep  hurry, limited stocks in store

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-05-28 14:45 UTC]
-Status: Open +Status: Verified
 [2015-05-28 14:45 UTC]
Verified: <>. (\x92 and \x96 are undefined
for ISO-8859-1, what explains their suppression in PHP 5.6 and
HHVM. Anyhow, this is unrelated to the issue at hand.)

Apparently, the issue is with mbfl_mime_header_decode(), and
therefore should be resolved upstream in libmbfl
 [2017-03-15 11:36 UTC] pudge601 at hotmail dot com
I've just run into this issue today while in the process of switching from using `iconv_mime_decode` to `mb_decode_mimeheader`.

Despite this bug being marked as verified and it being stated that this was a problem with the libmbfl, it doesn't seem like there was any issue raised against that library, so I've raised one just now: (

In the meantime, I'm using this workaround;

$header = preg_replace_callback('/(=\?[^\?]+\?Q\?)([^\?]+)(\?=)/i', function($matches) {
    return $matches[1] . str_replace('_', '=20', $matches[2]) . $matches[3];
}, $header);

Posted here in case anybody else finds this useful.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 07:01:27 2024 UTC