MIME "multipart/related" Structure and Apple Mail. Is it a Bug?

2.4k Views Asked by At

I build a E-Mail with PHP Zend Framework Class Zend_Mail. There is one text- and one html-part with related inline-images. I want to attach one pdf-file too.

My question is about the mime-structure. Two options are possible:

option 1:

Content-Type: multipart/mixed
  Content-Type: multipart/alternative 
    Content-Type: text/plain; charset=UTF-8      
    Content-Type: multipart/related 
      Content-Type: text/html; charset=UTF-8 
      Content-Type: image/jpeg
      Content-Type: image/jpeg
      Content-Type: image/png
  Content-Type: application/pdf 

option 2:

Content-Type: multipart/related;
  Content-Type: multipart/alternative;
    Content-Type: text/plain; charset=utf-8
    Content-Type: text/html; charset=utf-8
  Content-Type: image/jpeg
  Content-Type: image/jpeg
  Content-Type: image/png
  Content-Type: application/pdf

option 2 is built by Zend_Mail, but the pdf is not recognized at Apple Mail Application. It's fine in Thunderbird 3 and Outlook 2007. Only in Apple Mail the PDF-Attachment isn't recognized.

option 1 is ok in Apple Mail, Thunderbord and Outlook. But it would be a little bit tricky to get this structure out of the Zend Framework Class Zend_Mail.

Is this a Bug in Apple Mail or is option 2 not normative?

kind regards, sn

2

There are 2 best solutions below

1
On

Have you tryied specifying the type ? see this page http://framework.zend.com/manual/en/zend.mail.attachments.html

i use this

    $obj_MailAttachment = new Zend_Mime_Part($allegato);
    $obj_MailAttachment->type = 'application/pdf';
    $obj_MailAttachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
    $obj_MailAttachment->encoding = Zend_Mime::ENCODING_BASE64;
    $obj_MailAttachment->filename = 'ordine'.$ordine['numero'].'.pdf';

...

$mail->addAttachment($obj_MailAttachment);
1
On

Both options are violations of RFC822, the header-lines MUST start on the first character of their line; this is important because hearer-folding is triggered by that first character being whitespace SP (#32) or HT (#09), IIRC.

Example:

Content-Type: text/html; charset=UTF-8 

and

Content-Type: text/html;
  charset=UTF-8

are exactly equivalent.

The proper way to do what you're (apparently) attempting is by using the boundary attribute is something like this:

Content-Type: multipart/mixed; boundary="1610edf3f7626f0847a5e75c55287644"
OTHER-HEADERS
--1610edf3f7626f0847a5e75c55287644
Content-Type: multipart/mixed; boundary="embedded_boundary"
OTHER-HEADERS
--embedded_boundary
NESTED-MESSAGE-GOES-HERE
--embedded_boundary--
--1610edf3f7626f0847a5e75c55287644--

One of the parts of nested-portion would contain the PDF-attachment.

Ref: http://www.faqs.org/rfcs/rfc2822.html and the links provided here: Are email headers case sensitive?