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

From: Date: Tue, 02 Nov 2021 16:49:18 +0000
Subject: Doc #81575 [Opn->Ver]: Faulty mb_encode_mimeheader() example code
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-19300@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:         cmb@php.net
 Reported by:        php at delegated dot net
 Summary:            Faulty mb_encode_mimeheader() example code
-Status:             Open
+Status:             Verified
 Type:               Documentation Problem
 Package:            mbstring related
 Operating System:   n/a
 PHP Version:        Irrelevant
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[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 (#19300) next »