php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php at delegated dot net
New email:
PHP Version: OS:

 

 [2021-10-31 02:37 UTC] php at delegated dot net
Description:
------------
https://www.php.net/manual/en/function.mb-encode-mimeheader.php provides the example:

<?php
$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 . ">";


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-02 09:54 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem -Package: Documentation problem +Package: mbstring related
 [2021-11-02 16:49 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2021-11-02 16:49 UTC] cmb@php.net
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] git@php.net
Automatic comment on behalf of cmb69
Revision: https://github.com/php/doc-en/commit/936691e7449fe193b474f7d29df152952e9b8df6
Log: Fix #81575: Faulty mb_encode_mimeheader() example code
 [2021-11-02 16:57 UTC] git@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 02:01:28 2024 UTC