php.net |  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
Votes:10
Avg. Score:3.9 ± 0.5
Reproduced:10 of 10 (100.0%)
Same Version:3 (30.0%)
Same OS:4 (40.0%)
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
 [2015-01-13 03:47 UTC] php dot bohwaz at miam dot kd2 dot org
Description:
------------
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?=
 =?ISO-8859-1?Q?om_thurs_30_sep_=96_hurry,_limited_stocks_in_store?=



Test script:
---------------
<?php

$subject = "=?ISO-8859-1?Q?spring_into_ALDI_for_this_week=92s_special_buys_fr?=
 =?ISO-8859-1?Q?om_thurs_30_sep_=96_hurry,_limited_stocks_in_store?=";

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:
--------------
spring_into_ALDI_for_this_weeks_special_buys_from_thurs_30_sep__hurry,_limited_stocks_in_store

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-05-28 14:45 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2015-05-28 14:45 UTC] cmb@php.net
Verified: <http://3v4l.org/Rnt2K>. (\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
(<https://github.com/moriyoshi/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: (https://github.com/moriyoshi/libmbfl/issues/25).

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 Oct 11 13:01:27 2024 UTC