ZF-328: Zend_Mail / Zend_Mime does not allow use of 'Content-type: multipart/related'

Description

For messages with attachments, the Content-type header is always set to multipart/mixed.

A constant Zend_Mime::MULTIPART_RELATED exists, but never seems to be used, and manually changed content-type headers get overwritten in Zend_Mail_Transport_Abstract::_getHeaders()

See for more info: library/Zend/Mime.php:45 library/Zend/Mail/Abstract.php:133,137

Comments

Scheduling for 0.7.0 release.

Patch:



Index: /Zend/Mail/Transport/Abstract.php
===================================================================
--- /Zend/Mail/Transport/Abstract.php (revision 273)
+++ /Zend/Mail/Transport/Abstract.php (revision 274)
@@ -130,10 +130,13 @@
         if (null !== $boundary) {
             // Build multipart mail
-            if ($this->_mail->hasAttachments) {
-                $type = Zend_Mime::MULTIPART_MIXED;
-            } elseif ($this->_mail->getBodyText() && $this->_mail->getBodyHtml()) {
-                $type = Zend_Mime::MULTIPART_ALTERNATIVE;
-            } else {
-                $type = Zend_Mime::MULTIPART_MIXED;
+            $type = $this->_mail->getType();
+            if (!$type) {
+               if ($this->_mail->hasAttachments) {
+                   $type = Zend_Mime::MULTIPART_MIXED;
+               } elseif ($this->_mail->getBodyText() && $this->_mail->getBodyHtml()) {
+                   $type = Zend_Mime::MULTIPART_ALTERNATIVE;
+               } else {
+                   $type = Zend_Mime::MULTIPART_MIXED;
+               }
             }
 
Index: /Zend/Mail.php
===================================================================
--- /Zend/Mail.php (revision 273)
+++ /Zend/Mail.php (revision 274)
@@ -77,4 +77,10 @@
     protected $_charset = null;
 
+    /**
+     * Mail content type
+     * @var string
+     */
+    protected $_type = null;
+
     /**
      * Mail headers
@@ -172,4 +178,25 @@
     {
         return $this->_charset;
+    }
+
+    /**
+     * Sets Content-type of the message
+     *
+     * @param string $email
+     */
+    public function setType($type)
+    {
+        $this->_type = $type;
+    }
+
+    /**
+     * Return content type
+     * 
+     * @access public
+     * @return string
+     */
+    public function getType()
+    {
+        return $this->_type;
     }
 

Resolved in r4329. setType() only allows setting multipart content-types, and only accessed when a boundary is detected in the transport.