Martin Trigaux
Martin Trigaux

Reputation: 5401

Multiple Content-Type: text/html inside a multipart/mixed

I am trying to parse emails and received the below message for a reply using Apple Mail. It's composed of a multipart/mixed containing an attachment and 2 html parts.

In brief:

multipart/alternative
  \--> text/plain
  \--> multipart/mixed
         \--> text/html
         \--> multipart/alternative
         \--> text/html (empty)

or with the email source:

From: "John Doe" <[email protected]>
... // some headers
Content-Type: multipart/alternative;
 boundary="Apple-Mail=_9331E12B-8BD2-4EC7-B53E-01F3FBEC9227"
Message-Id: <[email protected]>
Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\))
... // rest of headers

--Apple-Mail=_9331E12B-8BD2-4EC7-B53E-01F3FBEC9227
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
    charset=us-ascii

My message in text...


--Apple-Mail=_9331E12B-8BD2-4EC7-B53E-01F3FBEC9227
Content-Type: multipart/mixed;
 boundary="Apple-Mail=_CA6C687E-6AA0-411E-B0FE-F0ABB4CFED1F"


--Apple-Mail=_CA6C687E-6AA0-411E-B0FE-F0ABB4CFED1F
Content-Transfer-Encoding: 7bit
Content-Type: text/html;
    charset=us-ascii

<html><head></head><body>My message in HTML...</body></html>

--Apple-Mail=_CA6C687E-6AA0-411E-B0FE-F0ABB4CFED1F
Content-Disposition: inline;
    filename=myfile.pdf
Content-Type: application/pdf;
    name="myfile.pdf"
Content-Transfer-Encoding: base64

... // base64 content


--Apple-Mail=_CA6C687E-6AA0-411E-B0FE-F0ABB4CFED1F
Content-Transfer-Encoding: 7bit
Content-Type: text/html;
    charset=us-ascii

<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"><base></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div><blockquote type="cite"></blockquote></div><br></body></html>
--Apple-Mail=_CA6C687E-6AA0-411E-B0FE-F0ABB4CFED1F--

--Apple-Mail=_9331E12B-8BD2-4EC7-B53E-01F3FBEC9227--

Notice the last part being an empty <blockquote type="cite"></blockquote> (is it because it's a reply?).

Thanks

Upvotes: 3

Views: 3819

Answers (1)

Martin Trigaux
Martin Trigaux

Reputation: 5401

According to RFC1341 (section 7.2.2)

The primary subtype for multipart, "mixed", is intended for use when the body parts are independent and intended to be displayed serially.

So I would say, Apple's email is valid (even if I don't get the point of the empty part). The two html parts should be considered as different (in my case, best to concatenate them).

Upvotes: 2

Related Questions