Monday, 29 June 2015

iOS Message Formatting Issue - Part 2 (Inline attachments are converted as ATT00001.txt attachment)

This issue is because iOS sending the email message in Multipart/mixed type, Multipart/mixed is used for sending files with different "Content-Type" headers inline (or as attachments). If sending pictures or other easily readable files, most mail clients will display them inline (unless otherwise specified with the "Content-disposition" header). Otherwise it will offer them as attachments. The default content-type for each part is "text/plain".

This issue occurs when an attachment body part in an e-mail message is sent before the message body part of the e-mail message is sent. This issue occurs because the message is sent by the application in an incorrect format. Based on the "Mixed Subtype" definition that is mentioned in section 5.1.3 of RFC 2046, the "mixed" subtype of "multipart" is intended for use when the body parts are independent and have to be bundled in a particular order. Any "multipart" subtypes that an implementation does not recognize must be treated as being of "mixed" subtype.

Content-Disposition: This header field instructs a MIME-enabled email client on how it should display an attached file, and is described in RFC 2183. The values of this field may be Inline or Attachment. When the value of this field is Inline, the attachment is displayed in the message body. When the value of this field is Attachment, the attached file appears as a regular attachment separate from the message body. Other parameters are available when the value is Attachment, such as Filename

  • SimpleEmail - This class is used to send basic text based emails.
  • MultiPartEmail - This class is used to send multipart messages. This allows a text message with attachments either inline or attached.
  • HtmlEmail - This class is used to send HTML formatted emails. It has all of the capabilities as MultiPartEmail allowing attachments to be easily added. It also supports embedded images.
  • ImageHtmlEmail - This class is used to send HTML formatted emails with inline images. It has all of the capabilities as HtmlEmail but transform all image references to inline images.
  • EmailAttachment - This is a simple container class to allow for easy handling of attachments. It is for use with instances of MultiPartEmail and HtmlEmail.

Multipart/Mixed, according to RFC 1521, means that the parts are completely independent of each other (not related to each other) but that their order matters. What is the expected behavior? “Clients usually display the parts one after the other.”

This, however, brings into play another parameter on the MIME part – Content-Disposition. This parameter has a couple of normal values – Inline and Attachment. Attachment is easy to understand – in the context of Exchange, it means “Show me in the well, that I may be blocked by Outlook from being saved or opened.” Inline, on the other hand, we handle differently.

As I mentioned in early post about iOS formatting issue work around is to include any rich text elements in a message, such as bold, italic or underline then iOS will send the message as HTML/Rich Text, It is also changing the Subtype to multipart/related & Content-Disposition: inline

So globally “Mixed” Sub type will make all servers to make it readable based on order the parts been submitted, Since the Disposition for all these messages are “attachment” there is no way for any servers to understand it is inline attachment, Interesting right 


Content-Type: multipart/related;boundary="_004_4A39CC1190D144F4A6C06F64E1";type="multipart/alternative"
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Content-Type: image/jpeg; name="FullSizeRender.jpg"
Content-Description: FullSizeRender.jpg
Content-Disposition: inline; filename="FullSizeRender.jpg"; size=37928;creation-date="Thu, 25 Jun 2015 14:16:03 GMT";modification-date="Thu, 25 Jun 2015 14:16:03 GMT"
Content-Transfer-Encoding: base64
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Not working:

Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="us-ascii"
Content-Type: multipart/mixed;boundary="_003_0E0DB2DAB74A41B9ACC09061E_"
Content-Type: image/jpeg; name="IMG_0085.JPG"
Content-Description: IMG_0085.JPG
Content-Disposition: attachment; filename="IMG_0085.JPG"; size=95335;creation-date="Thu, 25 Jun 2015 13:58:50 GMT";modification-date="Thu, 25 Jun 2015 13:58:50 GMT"
Content-Transfer-Encoding: base64
Content-Type: text/plain; name="ATT00001.txt"
Content-Description: ATT00001.txt
Content-Disposition: attachment; filename="ATT00001.txt"; size=25;creation-date="Thu, 25 Jun 2015 13:58:50 GMT";modification-date="Thu, 25 Jun 2015 13:58:50 GMT"
Content-Transfer-Encoding: base64

Definition Source : Microsoft Technet

No comments:

Post a Comment

Google+ Followers

Blog Archive