0 votes
by (300 points)

E-mail is composed on iPhone builtin app and sent using iCloud or Gmail account. Message is composed to have some text, then image and then again some text.
In message source I see 3 parts

--Apple-Mail-995105A1-ACC6-4F4A-AEE1-3F38A30A09CF
Content-Type: text/plain;
charset=us-ascii
Content-Transfer-Encoding: 7bit

Some preliminary text

--Apple-Mail-995105A1-ACC6-4F4A-AEE1-3F38A30A09CF
Content-Type: image/png;
name=image1.png;
x-apple-part-url=06DE587E-8B61-4657-9F96-EC25111B24F2
Content-Disposition: inline; filename="image1.png"
Content-Transfer-Encoding: base64

iVBORw0KGgoAAAANSUhEUgAAAScAAAKAEAYAAACOO2LJAAAAAXNSR0IArs4c6QAAAe9pVFh0WE1M ...

--Apple-Mail-995105A1-ACC6-4F4A-AEE1-3F38A30A09CF
Content-Type: text/plain;
charset=us-ascii
Content-Transfer-Encoding: 7bit

Some post inline attachment text.

--Apple-Mail-995105A1-ACC6-4F4A-AEE1-3F38A30A09CF--

When I load it BodyText property returns only first part of text - Some preliminary text. The second part of text is added as an attachment. Image is also in Attachments collection but it has ContentDisposition: inline. I thought it would be in Resources collection.

This message is correctly displayed in Thunderbird. I need a way to display it in our application.

Applies to: Rebex Secure Mail

1 Answer

0 votes
by (72.7k points)

Please note that Content-Disposition header is only informative.
What defines the MIME structure are values of used Content-Type headers.

Unfortunately, every client do it by its own way. If you compare for example Thunderbird and MS Outlook you will see other results.

I tried 3 cases with your mail:

1. multipart/mixed

Content-Type: multipart/mixed;
    boundary="Apple-Mail-995105A1-ACC6-4F4A-AEE1-3F38A30A09CF"

--Apple-Mail-995105A1-ACC6-4F4A-AEE1-3F38A30A09CF
Content-Type: text/plain;
...

2. multipart/related

Content-Type: multipart/related;
    boundary="Apple-Mail-995105A1-ACC6-4F4A-AEE1-3F38A30A09CF"

--Apple-Mail-995105A1-ACC6-4F4A-AEE1-3F38A30A09CF
Content-Type: text/plain;
...

3. multipart/alternative

Content-Type: multipart/alternative;
    boundary="Apple-Mail-995105A1-ACC6-4F4A-AEE1-3F38A30A09CF"

--Apple-Mail-995105A1-ACC6-4F4A-AEE1-3F38A30A09CF
Content-Type: text/plain;
...

When I open those mails in MS Outlook, I see:

  1. and 2. case - "Some preliminary text" as body and two attachments.
  2. case - "Some preliminary text" as body and no attachments.

The Rebex MailMessage behavior is as follows:

  1. case - 1x AlternateViews, 2x Attachments, 0x Resources.
  2. case - 1x AlternateViews, 0x Attachments, 2x Resources.
  3. case - 2x AlternateViews, 1x Attachments, 0x Resources.

However, Rebex MailMessage is .NET library, it does not display emails. What do you mean by "I need a way to display it in our application"?

Basically, all MIME parts can be found in one of the MailMessage collections (AlternateViews, Attachments, Resources) - based on the Content-Type used inside the mail.

by (300 points)
What I meant is I need to read e-mail form mailbox, do some processing to it and then display it in web interface ideally exactly like it looks in sending person's e-mail client.  Or how it looks in thunderbird. Currently I don't even know how full body should be displayed in this case. So far I have just been using BodyHtml or BodyText properties.
by (300 points)
Imagine I'm developing my own web e-mail client. Is there any way I can display this e-mail correctly? Thunderbird shows it how it should be shown. Some text, image, rest of the text.
by (72.7k points)
We believe that we are parsing mails correctly. Our target is to parse mails as most similar as MS Outlook does and as most precise as RFC defines.
We are sorry, but Thunderbird is not our reference and we know that it differs in some points (compared to MS Outlook).

To your target:
After loading MailMessage, just display BodyHtml (and process linked images src="cid:ID" - more details at http://forum.rebex.net/776/showing-inline-pictures-in-htmlbody).
If it has no BodyHtml, display BodyText (and process linked images).
Alternatively, you can allow to user display all AlternateViews.
If it has attachments allow user to display/download them.
Because, you have to process inline images manually anyway (to render correct HTML page) you know, which linked resources you processed and which are not displayed in final HTML page - you can display those as regular attachments (if any).
If you want to be as closest as possible to Thuderbird, you can also handle attachments with Content-Disposition: inline.
You can easily get the value like this:
  mail.Attachments[0].ContentDisposition.Inline
...