From bb60fa3f2f31a608aeaeb17b01d53e35ba20686c Mon Sep 17 00:00:00 2001 From: gustavf Date: Thu, 6 Jul 2000 09:02:30 +0000 Subject: [PATCH] Fixed bug: Now using uppercase letters when doing RFC1521 encoding of headers. Also propeprly encoding ?=_. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@596 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/mime.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/functions/mime.php b/functions/mime.php index 25406a60..7cf724df 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -539,23 +539,30 @@ } // Encode a string according to RFC 1522 for use in headers if it - // contains 8-bit characters + // contains 8-bit characters or anything that looks like it should + // be encoded. function encodeHeader ($string) { global $default_charset; - // Encode only if the string contains 8-bit characters - if (ereg("[\200-\377]", $string)) { + // Encode only if the string contains 8-bit characters or =? + if (ereg("([\200-\377])|=\\?", $string)) { $newstring = "=?$default_charset?Q?"; - $newstring .= str_replace(" ", "_", $string); - while (ereg("([\200-\377])", $newstring, $regs)) { + // First the special characters + $string = str_replace("=", "=3D", $string); + $string = str_replace("?", "=3F", $string); + $string = str_replace("_", "=5F", $string); + $string = str_replace(" ", "_", $string); + + + while (ereg("([\200-\377])", $string, $regs)) { $replace = $regs[1]; - $insert = "=" . bin2hex($replace); - $newstring = str_replace($replace, $insert, $newstring); + $insert = "=" . strtoupper(bin2hex($replace)); + $string = str_replace($replace, $insert, $string); } - $newstring .= "?="; - + $newstring = "=?$default_charset?Q?".$string."?="; + return $newstring; } -- 2.25.1