Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 878
oldergod Avatar asked Dec 11 '22 20:12

oldergod


2 Answers

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.

like image 84
qqx Avatar answered Dec 26 '22 15:12

qqx


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.

like image 25
tripleee Avatar answered Dec 26 '22 15:12

tripleee