Fold long address headers

addrAppend() joined all addresses onto one line, so a To, Cc, Bcc or
Reply-To header with many recipients could go past the 998 character
limit in RFC 5322. Fold between addresses when the next one would not
fit. Short lists are unchanged.

Fixes #2690
This commit is contained in:
dualfroz committed 2026-10-02 16:44:53 +02:00
1 parent 709e2d5b62
commit 94041263a0
2 files changed
+79 -1

No files matched your search

+15 -1
View File
@@ -2647,7 +2647,21 @@ class PHPMailer
$addresses[] = $this->addrFormat($address);
}
return $type . ': ' . implode(', ', $addresses) . static::$LE;
//Fold between addresses so that no line exceeds the RFC 5322 limit,
//leaving room for the comma at the end of a folded line
$header = $type . ': ' . array_shift($addresses);
$lineLength = strlen($header);
foreach ($addresses as $address) {
if ($lineLength + strlen($address) + 3 > static::MAX_LINE_LENGTH) {
$header .= ',' . static::$LE . ' ' . $address;
$lineLength = strlen($address) + 1;
} else {
$header .= ', ' . $address;
$lineLength += strlen($address) + 2;
}
}
return $header . static::$LE;
}
/**