MailSo: a folded plain-text line no longer leaves two spaces

Unfolding appended a newline before the continuation line, which kept its
own leading whitespace; Header turns the newline into a space, so every
fold became two spaces ("et  checklist"), carried into reply subjects.
The test now compares exactly.
This commit is contained in:
Fathi Ben Nasr 2026-10-22 20:55:38 +00:00
parent 37fcdbe534
commit 7c432e392b
2 changed files with 5 additions and 6 deletions

View file

@ -136,14 +136,12 @@ class HeaderCollection extends \MailSo\Base\Collection
$sHeadersValue = \rtrim($sHeadersValue); $sHeadersValue = \rtrim($sHeadersValue);
} }
// RFC 2047 6.2: only whitespace between two encoded words is // RFC 5322 unfolding removes the line break and keeps the folding
// dropped; after a plain word the folding space is a real space. // whitespace; RFC 2047 6.2 drops it only between two encoded words.
if ('=?' === \substr(\ltrim($sHeadersValue), 0, 2) && '?=' === \substr($sValue, -2)) { if ('=?' === \substr(\ltrim($sHeadersValue), 0, 2) && '?=' === \substr($sValue, -2)) {
$sValue .= \ltrim($sHeadersValue); $sValue .= \ltrim($sHeadersValue);
} else if ('=?' === \substr(\ltrim($sHeadersValue), 0, 2)) {
$sValue .= ' '.\ltrim($sHeadersValue);
} else { } else {
$sValue .= "\n".$sHeadersValue; $sValue .= ' '.\ltrim($sHeadersValue);
} }
} else { } else {
if (null !== $sName) { if (null !== $sName) {

View file

@ -43,7 +43,8 @@ $cases = [
"Hello\r\n world" => 'Hello world', "Hello\r\n world" => 'Hello world',
]; ];
foreach ($cases as $raw => $want) { foreach ($cases as $raw => $want) {
$got = preg_replace('/\s+/', ' ', subject($raw)); // exact: a fold is one space, never two ("et checklist" ended up in replies)
$got = subject($raw);
check($got === $want, "got [{$got}], want [{$want}]"); check($got === $want, "got [{$got}], want [{$want}]");
} }