From b5c6086eeadfbb3bd151fccb9dd86dd556fc2d9f Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 14 May 2014 04:35:49 -0400
Subject: [PATCH] Fix malformed References: header in send/saved mail (#1489891) - update Mail_mime to 1.8.9 version

---
 program/lib/Mail/mime.php     |   27 +++++++++++++--------------
 CHANGELOG                     |    1 +
 program/lib/Mail/mimePart.php |    9 ++++-----
 3 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 64aef9d..6335f88 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -20,6 +20,7 @@
 - Optimize some framed pages content for better performance (#1489792)
 - Fix mbox files import
 - Fix unintentional draft autosave request if autosave is disabled (#1489882)
+- Fix malformed References: header in send/saved mail (#1489891)
 
 RELEASE 1.0.1
 -------------
diff --git a/program/lib/Mail/mime.php b/program/lib/Mail/mime.php
index e079af7..50297dd 100644
--- a/program/lib/Mail/mime.php
+++ b/program/lib/Mail/mime.php
@@ -491,13 +491,13 @@
      * returns it during the build process.
      *
      * @param mixed  &$obj The object to add the part to, or
-     *                     null if a new object is to be created.
+     *                     anything else if a new object is to be created.
      * @param string $text The text to add.
      *
      * @return object      The text mimePart object
      * @access private
      */
-    function &_addTextPart(&$obj = null, $text = '')
+    function &_addTextPart(&$obj, $text = '')
     {
         $params['content_type'] = 'text/plain';
         $params['encoding']     = $this->_build_params['text_encoding'];
@@ -518,12 +518,12 @@
      * returns it during the build process.
      *
      * @param mixed &$obj The object to add the part to, or
-     *                    null if a new object is to be created.
+     *                    anything else if a new object is to be created.
      *
      * @return object     The html mimePart object
      * @access private
      */
-    function &_addHtmlPart(&$obj = null)
+    function &_addHtmlPart(&$obj)
     {
         $params['content_type'] = 'text/html';
         $params['encoding']     = $this->_build_params['html_encoding'];
@@ -563,12 +563,12 @@
      * the build process.
      *
      * @param mixed &$obj The object to add the part to, or
-     *                    null if a new object is to be created.
+     *                    anything else if a new object is to be created.
      *
      * @return object     The multipart/mixed mimePart object
      * @access private
      */
-    function &_addAlternativePart(&$obj = null)
+    function &_addAlternativePart(&$obj)
     {
         $params['content_type'] = 'multipart/alternative';
         $params['eol']          = $this->_build_params['eol'];
@@ -588,12 +588,12 @@
      * the build process.
      *
      * @param mixed &$obj The object to add the part to, or
-     *                    null if a new object is to be created
+     *                    anything else if a new object is to be created
      *
      * @return object     The multipart/mixed mimePart object
      * @access private
      */
-    function &_addRelatedPart(&$obj = null)
+    function &_addRelatedPart(&$obj)
     {
         $params['content_type'] = 'multipart/related';
         $params['eol']          = $this->_build_params['eol'];
@@ -878,11 +878,11 @@
 
         $this->_checkParams();
 
-        $null        = null;
-        $attachments = count($this->_parts)                 ? true : false;
-        $html_images = count($this->_html_images)           ? true : false;
-        $html        = strlen($this->_htmlbody)             ? true : false;
-        $text        = (!$html && strlen($this->_txtbody))  ? true : false;
+        $null        = -1;
+        $attachments = count($this->_parts) > 0;
+        $html_images = count($this->_html_images) > 0;
+        $html        = strlen($this->_htmlbody) > 0;
+        $text        = !$html && strlen($this->_txtbody);
 
         switch (true) {
         case $text && !$attachments:
@@ -991,7 +991,6 @@
                 $this->_addAttachmentPart($message, $this->_parts[$i]);
             }
             break;
-
         }
 
         if (!isset($message)) {
diff --git a/program/lib/Mail/mimePart.php b/program/lib/Mail/mimePart.php
index c6e9f4a..93e891b 100644
--- a/program/lib/Mail/mimePart.php
+++ b/program/lib/Mail/mimePart.php
@@ -839,7 +839,7 @@
             // Simple e-mail address regexp
             $email_regexp = '([^\s<]+|("[^\r\n"]+"))@\S+';
 
-            $parts = Mail_mimePart::_explodeQuotedString($separator, $value);
+            $parts = Mail_mimePart::_explodeQuotedString("[\t$separator]", $value);
             $value = '';
 
             foreach ($parts as $part) {
@@ -850,7 +850,7 @@
                     continue;
                 }
                 if ($value) {
-                    $value .= $separator==',' ? $separator.' ' : ' ';
+                    $value .= $separator == ',' ? $separator . ' ' : ' ';
                 } else {
                     $value = $name . ': ';
                 }
@@ -869,7 +869,7 @@
                     // check if phrase requires quoting
                     if ($word) {
                         // non-ASCII: require encoding
-                        if (preg_match('#([\x80-\xFF]){1}#', $word)) {
+                        if (preg_match('#([^\s\x21-\x7E]){1}#', $word)) {
                             if ($word[0] == '"' && $word[strlen($word)-1] == '"') {
                                 // de-quote quoted-string, encoding changes
                                 // string to atom
@@ -908,11 +908,10 @@
             $value = preg_replace(
                 '/^'.$name.':('.preg_quote($eol, '/').')* /', '', $value
             );
-
         } else {
             // Unstructured header
             // non-ASCII: require encoding
-            if (preg_match('#([\x80-\xFF]){1}#', $value)) {
+            if (preg_match('#([^\s\x21-\x7E]){1}#', $value)) {
                 if ($value[0] == '"' && $value[strlen($value)-1] == '"') {
                     // de-quote quoted-string, encoding changes
                     // string to atom

--
Gitblit v1.9.1