From a6165937b150c94e3f6496b02afbc747914c80ba Mon Sep 17 00:00:00 2001 From: michelvaldrighi Date: Sun, 22 Feb 2004 00:31:25 +0000 Subject: [PATCH] fixes to handle ISO-scrambled email subjects in wp-mail git-svn-id: http://svn.automattic.com/wordpress/trunk@907 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions-formatting.php | 14 ++++++++++++++ wp-mail.php | 3 +++ 2 files changed, 17 insertions(+) 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]);