From 4ce8260f80b3cd665ad24f18c037e3a9e9f90a01 Mon Sep 17 00:00:00 2001 From: DualFroz Date: Sat, 3 Oct 2026 18:30:36 +0200 Subject: [PATCH] Spell out the folding arithmetic in addrAppend() Name the separators that make up the line length instead of the bare 3, and refer to RFC 2822 like MAX_LINE_LENGTH does. --- src/PHPMailer.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/PHPMailer.php b/src/PHPMailer.php index d0d6c52..5ccf8ff 100644 --- a/src/PHPMailer.php +++ b/src/PHPMailer.php @@ -2647,17 +2647,18 @@ class PHPMailer $addresses[] = $this->addrFormat($address); } - //Fold between addresses so that no line exceeds the RFC 5322 limit, - //leaving room for the comma at the end of a folded line + //Fold between addresses so that no line exceeds the RFC 2822 line length limit $header = $type . ': ' . array_shift($addresses); $lineLength = strlen($header); foreach ($addresses as $address) { - if ($lineLength + strlen($address) + 3 > static::MAX_LINE_LENGTH) { + //The address goes after ', ' and must still leave room for the ',' that ends + //the line if the next address gets folded + if ($lineLength + strlen(', ') + strlen($address) + strlen(',') > static::MAX_LINE_LENGTH) { $header .= ',' . static::$LE . ' ' . $address; - $lineLength = strlen($address) + 1; + $lineLength = strlen(' ') + strlen($address); } else { $header .= ', ' . $address; - $lineLength += strlen($address) + 2; + $lineLength += strlen(', ') + strlen($address); } }