Fix quoted-printable encoding of the subject.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 28 Sep 2008 15:36:27 +0000 (17:36 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 28 Sep 2008 15:36:27 +0000 (17:36 +0200)
(Pear suxx).

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/plmailer.php

index 95e5a5c..45f3a8a 100644 (file)
@@ -196,6 +196,20 @@ class PlMailer extends Mail_Mime {
         return parent::setFrom($this->correct_emails($email));
     }
 
+    static function encodeQP($char)
+    {
+        return sprintf('=%02X', ord($char));
+    }
+
+    public function setSubject($subject)
+    {
+        if (!preg_match('/^[\x21-\x3C\x3e-\x7e]*$/', $subject)) {
+            $subject = '=?UTF-8?Q?' . preg_replace('/[^\x21-\x3C\x3e-\x7e]/e', 'PlMailer::encodeQP("\0")', $subject)
+                     . '?=';
+        }
+        return parent::setSubject($subject);
+    }
+
     public function addHeader($hdr,$val)
     {
         switch($hdr) {