|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #81575 Faulty mb_encode_mimeheader() example code
Submitted: 2021-10-31 02:37 UTC Modified: 2021-11-02 16:49 UTC
From: php at delegated dot net Assigned: cmb (profile)
Status: Closed Package: mbstring related
PHP Version: Irrelevant OS: n/a
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 at delegated dot net
New email:
PHP Version: OS:


 [2021-10-31 02:37 UTC] php at delegated dot net
------------ provides the example:

$name = ""; // kanji
$mbox = "kru";
$doma = "gtinn.mon";
$addr = mb_encode_mimeheader($name, "UTF-7", "Q") . " <" . $mbox . "@" . $doma . ">";
echo $addr;

however, at least for some default Linux MTAs this is not safe. The name part must be quote escaped (if Q is being used, not an issue with B mode):

$addr = '"' . str_replace('"', '\"', mb_encode_mimeheader($name, "UTF-7", "Q")) . "\" <" . $mbox . "@" . $doma . ">";


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-02 09:54 UTC]
-Type: Bug +Type: Documentation Problem -Package: Documentation problem +Package: mbstring related
 [2021-11-02 16:49 UTC]
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2021-11-02 16:49 UTC]
Well, the example as is, is broken anyway, since an empty string
as display-name doesn't make much sense, and claiming that an
empty string (yes, I double-checked the source file with a hex
editor) would be Kanji makes no sense at all.  Looking at the
Japanese translation, that 太郎 was likely lost while converting
the file to UTF-8 encoding or some other changes.

Anyhow, you are right that the result of mb_encode_mimeheader()
isn't an atom, and as such should be quoted.
 [2021-11-02 16:57 UTC]
Automatic comment on behalf of cmb69
Log: Fix #81575: Faulty mb_encode_mimeheader() example code
 [2021-11-02 16:57 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 15 04:01:28 2024 UTC