Fixing 8.3+ mb_decode_mimeheader changes

This commit is contained in:
SirLouen 2025-09-26 17:13:11 +02:00
parent 1191a4ef0b
commit 0d5d8854f9
No known key found for this signature in database
GPG Key ID: 87796BFBFE09911B
1 changed files with 9 additions and 3 deletions

View File

@ -3747,10 +3747,16 @@ class PHPMailer
$hasEncodedWord = (bool) preg_match('/=\?.*\?=/s', $value); $hasEncodedWord = (bool) preg_match('/=\?.*\?=/s', $value);
if ($hasEncodedWord && defined('MB_CASE_UPPER')) { if ($hasEncodedWord && defined('MB_CASE_UPPER')) {
$origCharset = mb_internal_encoding(); $origCharset = mb_internal_encoding();
// Always decode to UTF-8 to provide a consistent, modern output encoding // Always decode to UTF-8 to provide a consistent, modern output encoding.
mb_internal_encoding($charset); mb_internal_encoding($charset);
//Undo any RFC2047-encoded spaces-as-underscores if (PHP_VERSION_ID < 80300) {
$value = str_replace('_', '=20', $value); // Undo any RFC2047-encoded spaces-as-underscores.
$value = str_replace('_', '=20', $value);
} else {
// PHP 8.3+ already interprets underscores as spaces. Remove additional
// linear whitespace between adjacent encoded words to avoid double spacing.
$value = preg_replace('/(\?=)\s+(=\?)/', '$1$2', $value);
}
// Decode the header value // Decode the header value
$value = mb_decode_mimeheader($value); $value = mb_decode_mimeheader($value);
mb_internal_encoding($origCharset); mb_internal_encoding($origCharset);