diff --git a/wp-includes/functions-formatting.php b/wp-includes/functions-formatting.php index fcd8747bec..82b54f4ab7 100644 --- a/wp-includes/functions-formatting.php +++ b/wp-includes/functions-formatting.php @@ -375,4 +375,18 @@ function strip_all_but_one_link($text, $mylink) { return $text; } + +// used by wp-mail to handle charsets in email subjects + +function wp_iso_descrambler($string) { + /* this may only work with iso-8859-1, I'm afraid */ + if (!preg_match('#\=\?(.+)\?Q\?(.+)\?\=#i', $string, $matches)) { + return $string; + } else { + $subject = str_replace('_', ' ', $matches[2]); + $subject = preg_replace('#\=([0-9a-f]{2})#ei', "chr(hexdec(strtolower('$1')))", $subject); + return $subject; + } +} + ?> \ No newline at end of file diff --git a/wp-mail.php b/wp-mail.php index e404b5f4fc..239c74d2f0 100644 --- a/wp-mail.php +++ b/wp-mail.php @@ -73,6 +73,9 @@ for ($iCount=1; $iCount<=$Count; $iCount++) { if (preg_match('/Subject: /', $line)) { $subject = trim($line); $subject = substr($subject, 9, strlen($subject)-9); + if (!preg_match('#\=\?(.+)\?Q\?(.+)\?\=#i', $subject)) { + $subject = wp_iso_descrambler($subject); + } if ($use_phoneemail) { $subject = explode($phoneemail_separator, $subject); $subject = trim($subject[0]);