oldergod
oldergod

Reputation: 15000

Is Content-Transfer-Encoding needed for multipart/alternative Content-Type?

I have an app that sends e-mails and for many months, it was working fine. I recently had problems with utf-8 encoded emails sent to iPhone Exchange account (i.e. not IMAP).
All the receiver had to see was a big bunch of meaningless characters like LS0tLS0tPV9QYXJ0XzE0N18[....].

Comparing my email headers with Gmail, I noticed that I had an extra Content-Transfer-Encoding associated with the Content-Type: multipart/alternative;.
My email would look like

Delivered-To: ...
Received: ...
...
MIME-Version: ...
Content-Type: multipart/alternative; 
    boundary="----=_boundary" 
Content-Transfer-Encoding: Base64  # <= the extra setting

----=_boundary
Content-type: text/plain; charset=utf-8
Content-Transfer-Encoding: Base64

YmVu0Cg==

----=_boundary
Content-type: text/html; charset=utf-8
Content-Transfer-Encoding: Base64

PGh0bWwgeG1sbnM6bz0iIj48aGVhZD48dGl0bGU+PC90aXRsZT48L2hlYWQ+PGJvZHk+YmVub2l0
PC9ib2R5PjwvaHRtbD4NCjx9IjAiIC8+Cg==

----=_boundary

If I remove the extra setting, my email is received and display properly.

My questions:

  1. Is the Encoding setting basically needed with Content-Type: multipart/alternative;, even for specific cases ?
  2. Is it safe to remove it and just keep using my app as I used to ?

Edit I found on IETF:

Encoding considerations: Multipart content-types cannot have encodings.

But I also found on Wikipedia:

The content-transfer-encoding of a multipart type must always be "7bit", "8bit" or "binary" to avoid the complications that would be posed by multiple levels of decoding.

Isn't it contradictory ?

Upvotes: 4

Views: 6375

Answers (2)

qqx
qqx

Reputation: 19465

The statements from IETF and wikipedia aren't really contradictory. 7bit, 8bit, or binary aren't really content encodings in that they don't specify any transformation of the content. They simply state that the content hasn't been encoded. In the case of 7bit it also specifies that the content doesn't need to be encoded even if the message needs to be sent over a transport that isn't 8-bit clean.

Only the bottom-most layers of messages should have an actual Content-Transfer-Encoding such as base64 or quoted-printable. In the message that you quote from the outer portion certainly isn't base64 encoded, so stating that it is was not only violating the standard but also incorrect. That would certainly be expected to cause problems with display of that message.

Upvotes: 8

tripleee
tripleee

Reputation: 189297

In practice, each part of a multipart has its own encoding, and it doesn't make sense to declare one for the multipart container. I cannot make sense of the Wikipedia quote anyway; in any event, it is hardly authoritative.

Upvotes: 5

Related Questions