Request #8556: Allow specifying a header charset for a part
authorMichael M Slusarz <slusarz@curecanti.org>
Sun, 15 Nov 2009 02:57:50 +0000 (19:57 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Sun, 15 Nov 2009 02:57:50 +0000 (19:57 -0700)
framework/Mime/lib/Horde/Mime/Part.php
framework/Mime/package.xml

index 1ac91e2..830cfd6 100644 (file)
@@ -201,6 +201,13 @@ class Horde_Mime_Part
     protected $_basepart = false;
 
     /**
+     * The charset to output the headers in.
+     *
+     * @var string
+     */
+    protected $_hdrCharset = null;
+
+    /**
      * Function to run on serialize().
      */
     public function __sleep()
@@ -601,6 +608,28 @@ class Horde_Mime_Part
     }
 
     /**
+     * Set the character set to use when outputting MIME headers.
+     *
+     * @param string $charset  The character set.
+     */
+    public function setHeaderCharset($charset)
+    {
+        $this->_hdrCharset = $charset;
+    }
+
+    /**
+     * Get the character set to use when outputting MIME headers.
+     *
+     * @return string  The character set.
+     */
+    public function getHeaderCharset()
+    {
+        return is_null($this->_hdrCharset)
+            ? $this->getCharset()
+            : $this->_hdrCharset;
+    }
+
+    /**
      * Set the description of this part.
      *
      * @param string $description  The description of this part.
@@ -1026,7 +1055,7 @@ class Horde_Mime_Part
             if (!empty($this->_temp['toString'])) {
                 $hdr_ob->replaceHeader('Content-Transfer-Encoding', $this->_temp['toString']);
             }
-            array_unshift($parts, $hdr_ob->toString(array('charset' => $this->getCharset(), 'defserver' => $options['defserver'])));
+            array_unshift($parts, $hdr_ob->toString(array('charset' => $this->getHeaderCharset(), 'defserver' => $options['defserver'])));
         }
 
         $newfp = $this->_writeStream($parts);
@@ -1457,7 +1486,7 @@ class Horde_Mime_Part
             }
         }
 
-        $result = $mailer->send(Horde_Mime::encodeAddress($email, $this->getCharset()), $headers->toArray(array('charset' => $this->getCharset())), $msg);
+        $result = $mailer->send(Horde_Mime::encodeAddress($email, $this->getCharset()), $headers->toArray(array('charset' => $this->getHeaderCharset())), $msg);
 
         $this->_basepart = $old_basepart;
 
index ec8b32a..8762c08 100644 (file)
@@ -31,7 +31,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
   <api>alpha</api>
  </stability>
  <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Add 'raw' render view to Horde_Mime_Viewer.
+ <notes>* Request #8556: Allow specifying a header charset for a part.
+ * Add 'raw' render view to Horde_Mime_Viewer.
  * Horde_Mime_Part::parseMessage() correctly parses non-MIME parts.
  * Remove dependence on PEAR's Mail_mimeDecode::.
  * Added Horde_Mime::uudecode().