From fc88ef87f13e415ab6ccc1696e34e311a0869609 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 7 Jul 2007 23:50:46 +0000 Subject: [PATCH] Change Mail::_encodeHeaderValue() to use regexp instead of a for() loop --- mail.php | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/mail.php b/mail.php index a97b624..e78cb41 100644 --- a/mail.php +++ b/mail.php @@ -354,24 +354,12 @@ class Mail */ function _encodeHeaderValue($text) { - $enc = ''; + // perform this on non-ASCII characters; excluding _ and = because we want them to be encoded as they have + // different meanings in mail messages + $text = preg_replace('#([^a-zA-Z0-9\+\-\*!/])#e', '"=" . strtoupper(dechex(ord("\\1")))', $text); + $text = str_replace('=20', '_' , $text); - for ($i = 0; $i < strlen($text); $i++) - { - $char = ord($text[$i]); - // allowed characters: a-zA-Z0-9_\+\-\*_= - if (($char >= 65 AND $char <= 90) OR ($char >= 97 AND $char <= 122) OR ($char >= 48 AND $char <= 57) OR $char == 33 OR $char == 42 OR $char == 43 OR $char == 45 OR $char == 47 OR $char == 61) - { - $enc .= $text[$i]; - } - else - { - // this is a non-ASCII character, so encode it - $enc .= '=' . strtoupper(dechex($char)); - } - } - - return '=?' . $this->charset . '?q?' . $enc . '?='; + return '=?' . $this->charset . '?q?' . $text . '?='; } } -- 2.43.5