Page 1 of 1

Embedded images allowed in multipart/mixed emails?

Posted: Sun Mar 15, 2009 2:03 pm
by georgeoc
Hi all,

I am writing a MIME parser for my application - it tries to reduce a multipart email to plain text or HTML ready for display to the user, in a similar fashion to an email client.

I already have a routine to rewrite links to embedded images (of the form: <img src="cid:logo.jpg" />) in emails of type multipart/related. However, in my testing, I have just encountered an email of type multipart/mixed with 2 subparts - an HTML message which references an encoded image in exactly the same way. As far as I can see, this is a badly formatted email - the type should instead be multipart/related. Am I correct, or is it allowed to have embedded image references in a multipart/mixed email?

I have tried to find some information in the relevant RFCs and using Google, but I can't find a definitive answer.

If it is a badly-formatted email, I'm not sure what I should do - leave an unresolvable image URL, or do the extra work necessary to process multipart/mixed emails in the same way as multipart/related emails.

Re: Embedded images allowed in multipart/mixed emails?

Posted: Sun Mar 15, 2009 6:40 pm
by Chris Corbyn
Yes, embedded images are allowed in multipart/mixed. You can mix multipart/alternative inside a multipart/mixed where one of the multipart/alternative entities actually contains multipart/related too.

Simple multipart/related:

[text]Content-Type: multipart/related; boundary="relbound" --relboundContent-Type: text/html Some stuff with <img src="cid:some@image" /> --relboundContent-Type: image/jpegContent-ID: <some@image>Content-Transfer-Encoding: base64 <jpeg base64 encoded data> --relbound--[/text]

multipart/mixed, with a simple multipart/related entity:

[text]Content-Type: multipart/mixed; boundary="mixbound" --mixboundContent-Type: multipart/related; boundary="relbound" --relboundContent-Type: text/html Some stuff with <img src="cid:some@image" /> --relboundContent-Type: image/jpegContent-ID: <some@image>Content-Transfer-Encoding: base64 <jpeg base64 encoded data> --relbound-- --mixboundContent-Type: application/octet-streamContent-Disposition: attachment; filename="foo.ext"Content-Transfer-Encoding: base64 <bse64 encoded data here> --mixbound--[/text]

multipart/related inside a multipart/alternative

[text]Content-Type: multipart/alternative; boundary="altbound" --altboundContent-Type: text/plain Plain text message here --altboundContent-Type: multipart/related; boundary="relbound" --relboundContent-Type: text/html Some stuff with <img src="cid:some@image" /> --relboundContent-Type: image/jpegContent-ID: <some@image>Content-Transfer-Encoding: base64 <jpeg base64 encoded data> --relbound-- --altbound--[/text]

All three combined (multipart/alternative containing a multipart/related entity, as part of a multipart/mixed email):

[text]Content-Type: multipart/mixed; boundary="mixbound" --mixboundContent-Type: multipart/alternative; boundary="altbound" --altboundContent-Type: text/plain Plain text message here --altboundContent-Type: multipart/related; boundary="relbound" --relboundContent-Type: text/html Some stuff with <img src="cid:some@image" /> --relboundContent-Type: image/jpegContent-ID: <some@image>Content-Transfer-Encoding: base64 <jpeg base64 encoded data> --relbound-- --altbound-- --mixboundContent-Type: application/octet-streamContent-Disposition: attachment; filename=foo.extContent-Transfer-Encoding: base64 <base64 encoded data here> --mixbound--[/text]

It's also perfectly legal to have more than 2 alternative parts... the appear in increasing order of preference (in increasing order if richness usually).

Re: Embedded images allowed in multipart/mixed emails?

Posted: Tue Mar 17, 2009 10:45 am
by georgeoc
Hi Chris,

Thanks for your reply. I should have explained myself a little clearer. I'm aware of all the possibilities of nested multipart sections which you outline, and indeed my parser already processes such examples correctly.

My question is specifically regarding what I believe to be a badly-formatted email, whose skeleton structure is like this:

Code: Select all

Content-Type: multipart/mixed; boundary="mixedbound"
 
--mixedbound
Content-Type: text/html
 
Some stuff with <img src="cid:some@image" />
 
--mixedbound
Content-Type: image/jpeg
Content-ID: <some@image>
Content-Transfer-Encoding: base64
 
<jpeg base64 encoded data>
 
--mixedbound--
I believe this email is incorrectly labelled as multipart/mixed - it should be multipart/related. Correct? I believe my suspicion is confirmed by Apple Mail, which displays the image as an attachment rather than inline, leaving the href of the HTML image unresolved and marked with a '?'. Outlook, however, seems to display it 'correctly' - i.e. as the author intended.

Re: Embedded images allowed in multipart/mixed emails?

Posted: Tue Mar 17, 2009 10:32 pm
by Chris Corbyn
Yes, that is not valid. They should be using multipart/related not multipart/mixed.