Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?).

  • Is that valid two have two Content-Type: text/html in the same multipart ?
  • Has the last (empty) part a meaning?
  • Is it possible to have some actual text in additional text/html parts it or can I always ignore it when parsing? (or concatenate parts)

Thanks

like image 333
Martin Trigaux Avatar asked Dec 20 '25 03:12

Martin Trigaux


1 Answers

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).

like image 117
Martin Trigaux Avatar answered Dec 24 '25 05:12

Martin Trigaux



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!