- for ($q=0;$q < count($body);$q++) {
- $body[$q] = ereg_replace("=3D", "=", $body[$q]);
+
+ $replace = charset_decode ($res[1], $replace);
+
+ $string = eregi_replace
+ ('=\?([^?]+)\?(q|b)\?([^?]+)\?=',
+ $replace, $string);
+ // In case there should be more encoding in the string: recurse
+ return (decodeHeader($string));
+ } else
+ return ($string);
+ }
+
+ // Encode a string according to RFC 1522 for use in headers if it
+ // contains 8-bit characters
+ function encodeHeader ($string) {
+ global $default_charset;
+
+ // Encode only if the string contains 8-bit characters
+ if (ereg("[\200-\377]", $string)) {
+ $newstring = "=?$default_charset?Q?";
+ $newstring .= str_replace(" ", "_", $string);
+
+ while (ereg("([\200-\377])", $newstring, $regs)) {
+ $replace = $regs[1];
+ $insert = "=" . bin2hex($replace);
+ $newstring = str_replace($replace, $insert, $newstring);