Doc #81575 [Ver->Csd]: Faulty mb_encode_mimeheader() example code

From: Date: Tue, 02 Nov 2021 16:57:35 +0000
Subject: Doc #81575 [Ver->Csd]: Faulty mb_encode_mimeheader() example code
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-19301@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81575&edit=1

 ID:                 81575
 Updated by:         git@php.net
 Reported by:        php at delegated dot net
 Summary:            Faulty mb_encode_mimeheader() example code
-Status:             Verified
+Status:             Closed
 Type:               Documentation Problem
 Package:            mbstring related
 Operating System:   n/a
 PHP Version:        Irrelevant
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

Automatic comment on behalf of cmb69
Revision: https://github.com/php/doc-en/commit/936691e7449fe193b474f7d29df152952e9b8df6
Log: Fix #81575: Faulty mb_encode_mimeheader() example code


Previous Comments:
------------------------------------------------------------------------
[2021-11-02 16:49:18] 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-10-31 02:37:29] 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 . ">";



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=81575&edit=1


Thread (3 messages)

« previous php.doc.bugs (#19301) next »