Problem/Motivation
Unicode::mimeHeaderEncode() is used to make sure that strings used with MIME headers are within 7-bit ASCII, by encoding strings according to the MIME standards (RFC 2047). The method folds (wraps) long lines to adhere to the MIME-recommended 78 char line length limit. But it does not account for the field name that normally precedes the string name, so the length limit is easily exceeded anyway.
E.g. PhpMail:
foreach ($message['headers'] as $name => $value) {
$mimeheaders[] = $name . ': ' . Unicode::mimeHeaderEncode($value);
}
For $message['headers']['Subject'] = 'Alle Menschen sind frei und gleich an Würde und Rechten geboren.';
this gives:
Subject: =?UTF-8?B?QWxsZSBNZW5zY2hlbiBzaW5kIGZyZWkgdW5kIGdsZWljaCBhbiBXw7xyZGUgdW4=?=
=?UTF-8?B?ZCBSZWNodGVuIGdlYm9yZW4u?=
where the first line is 86 characters long.
Proposed resolution
Add a $field_name_length = 0
argument to Unicode::mimeHeaderEncode(), and subtract that number from $chunk_size
for the first line. (Subsequent lines do not include the field name.)
Comments
Comment #1
ArlaComment #2
ArlaRelated: why is
$chunk_size
calculated from 75 and not 78?Comment #11
jungleTagging "Bug Smash Initiative" and setting the target version to the current dev branch.
Comment #13
quietone CreditAttribution: quietone as a volunteer commentedThis is a duplicate of a much earlier issue #84883: Unicode::mimeHeaderEncode() doesn't correctly follow RFC 2047.
Therefor closing as a duplicate.
Comment #14
quietone CreditAttribution: quietone as a volunteer commented