*/
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 . '?=';
}
}