title: Multipart messages including multiple attachments ("attachment" and "inline") with Zend Mail – RFC-compliant?
body: <p>Our company has developed its own CMS based on Zend (version 1.8.4). Switching to a new version is out of the question for the moment.</p>
  
  <p>We are using Zend Mail for sending (multipart) messages with embedded images (<code>Content-Disposition: inline;</code>) and downloadable attachments (<code>Content-Disposition: attachment;</code>).</p>
  
  <p>A few days ago, a customer reported problems opening such a mail on his Apple iPhone 5 (internal mail client): In the inbox the mail was indeed marked with a symbol indicating that the mail has attachments. However, after opening the mail, the attachment was not visible. The problem does not exist in the current versions of Outlook, Thunderbird and various webmail clients.</p>
  
  <p>I fixed the problem by changing the Content-Type of the mail depending on the presence of attachments:</p>
  
  <ul>
  <li>mail contains embedded images and downloadable attachments: <code>Content-Type:     multipart/mixed;</code></li>
  <li>mail contains embedded images but no downloadable attachments: <code>Content-Type: multipart/related;</code></li>
  </ul>
  
  <p>I also had to change the function <code>_buildBody</code> in <code>Zend/Mail/Transport/Abstract.php</code> regarding the assembly of boundaries for the different parts.</p>
  
  <p>So, I wonder if Zend Mail sends messages that are not RFC-compliant.</p>
  
  <p>Here is the mail structure before (does not work with Apple Mail) and after (works in most common mail clients) adding my changes. Could you please tell me which version is RFC-compliant?</p>
  
  <p><b>Zend Mail standard structure (not working with Apple Mail):</b></p>
  
  <pre><code>Content-Type: multipart/related; charset="utf-8"; boundary="=_0a0dbd2691e7728ea0f689fba0366bed"
  MIME-Version: 1.0
  
  --=_0a0dbd2691e7728ea0f689fba0366bed
  Content-Type: multipart/alternative; boundary="=_a70ea5862a6842785870a9a4d003a2a7"
  Content-Transfer-Encoding: 8bit
  
  --=_a70ea5862a6842785870a9a4d003a2a7
  Content-Type: text/plain; charset=utf-8
  Content-Transfer-Encoding: quoted-printable
  
  [MAIL_TEXT]
  
  --=_a70ea5862a6842785870a9a4d003a2a7
  Content-Type: text/html; charset=utf-8
  Content-Transfer-Encoding: quoted-printable
  
  [MAIL_HTML]
  
  --=_a70ea5862a6842785870a9a4d003a2a7--
  
  --=_0a0dbd2691e7728ea0f689fba0366bed
  Content-Type: application/pdf
  Content-Transfer-Encoding: base64
  Content-ID: &lt;test.pdf&gt;
  Content-Disposition: attachment; filename="test.pdf"
  
  [PDF_ATTACHED]
  
  Content-Type: image/jpeg
  Content-Transfer-Encoding: base64
  Content-ID: &lt;test.jpg&gt;
  Content-Disposition: inline; filename="test.jpg"
  
  [IMAGE_EMBEDDED]
  
  --=_0a0dbd2691e7728ea0f689fba0366bed--
  </code></pre>
  
  <p><b>Zend Mail customized structure (working in most common mail clients):</b></p>
  
  <pre><code>Content-Type: multipart/mixed; charset="utf-8"; boundary="=_8ab337ec2e38e1a8b82a01a5712a8bdb"
  MIME-Version: 1.0
  
  --=_8ab337ec2e38e1a8b82a01a5712a8bdb
  Content-Type: multipart/related; boundary="=_HTML60dd2cb7fc955f6c8a626c92c76aa2db"
  Content-Transfer-Encoding: 8bit
  
  --=_HTML60dd2cb7fc955f6c8a626c92c76aa2db
  Content-Type: multipart/alternative; boundary="=_ALTd40db860af4718399b954c403d0b0557"
  Content-Transfer-Encoding: 8bit
  
  --=_ALTd40db860af4718399b954c403d0b0557
  Content-Type: text/plain; charset=utf-8
  Content-Transfer-Encoding: quoted-printable
  
  [MAIL_TEXT]
  
  --=_ALTd40db860af4718399b954c403d0b0557
  Content-Type: text/html; charset=utf-8
  Content-Transfer-Encoding: quoted-printable
  
  [MAIL_HTML]
  
  --=_ALTd40db860af4718399b954c403d0b0557--
  
  --=_HTML60dd2cb7fc955f6c8a626c92c76aa2db
  Content-Type: image/jpeg
  Content-Transfer-Encoding: base64
  Content-ID: &lt;gemeinschaft.jpg&gt;
  Content-Disposition: inline; filename="gemeinschaft.jpg"
  
  [IMAGE_EMBEDDED]
  
  --=_HTML60dd2cb7fc955f6c8a626c92c76aa2db--
  
  --=_8ab337ec2e38e1a8b82a01a5712a8bdb
  Content-Type: application/pdf
  Content-Transfer-Encoding: base64
  Content-ID: &lt;glamus-test-schnellwarnung.pdf&gt;
  Content-Disposition: attachment; filename="glamus-test-schnellwarnung.pdf"
  
  [PDF_ATTACHED]
  
  --=_8ab337ec2e38e1a8b82a01a5712a8bdb--
  </code></pre>
  
  <p>Any help is appreciated.</p>
  
  <p>Kind regards,</p>
  
  <p>Nils</p>