diff -Nur blog.bak/nucleus/libs/NOTIFICATION.php blog/nucleus/libs/NOTIFICATION.php --- blog.bak/nucleus/libs/NOTIFICATION.php 2009-03-27 08:51:23.889510000 -0700 +++ blog/nucleus/libs/NOTIFICATION.php 2009-03-28 21:18:38.313504000 -0700 @@ -43,6 +43,24 @@ } /** + * Ensure the from/subject/to is correctly encoded + */ + function encodeBase64($string, $charset = 'UTF-8') { + $m=preg_match_all('/(\w*[\x80-\xFF]+\w*)/', $string, $matches); + if($m) return "=?" . $charset . "?B?" . @base64_encode($string) . "?="; + else return $string; + } + + /** + * for address in the format "name ", only encode name + */ + function encodeAddress($string, $charset = 'UTF-8') { + $m=preg_match_all('/(.*)( <.*?@.*?>)/', $string, $matches); + if($m) return $this->encodeBase64($matches[1][0], $charset) . $matches[2][0]; + else return $string; + } + + /** * Sends email messages to all the email addresses */ function notify($title, $message, $from) { @@ -58,7 +76,7 @@ if ($member->isLoggedIn() && ($member->getEmail() == $address)) continue; - @mail($address, $title, $message , "From: ". $from . "\nContent-Type: text/plain; charset=utf-8"); + @mail($this->encodeAddress($address), $this->encodeBase64($title), $message , "From: ". $this->encodeAddress($from) . "\nContent-Type: text/plain; charset=utf-8"); } } }