1. It seems easy to check if mail is in plain text or HTML. Just look to
the header Content-Type: witch start with eather 'multipart' or with
'text/plain'. Is this correct and always the case ?

A few things:
1. If Content-Type is missing in main message header, it is "text/plain". This is the default of all 822-RFC compliant messages (because the SMTP protocol is for plain-text), so if the message is just plain text, and no mime parts, there might not be any mime headers, since they are not needed.


2. If Content-Type is "text/plain", then (of course) it is "text/plain".

3. If Content-Type is multipart/mixed, you need to look at all mime parts and see if one of them has a mime header with Content-Type "text/plain" (it might not exist, for example, if it is an html message with attachments, but no text part). Text parts are usually (but not required to be) the first mime part of a multipart message.

4. If main header Content-Type is "text/html", then there is only one single mime part (html), so there is no pain text part.

5. "Multipart/mixed" are the only ones with different mime parts (i.e. 1 html part and 1 plain text part). There is a chance that the message contains multiple parts of the same time, in this case it won't be "/mixed" (I forgot right now the type). But these are rare.

2. If multipart HTML then part 1 seems to be the plain text part of the
message. Is always plain text sent with all mail readers if sending
HTML, and is this always the first part, or do I have to look to the
part header (as with message header) ?

As I mentioned in #3 above, you need to look at all parts. _Usually_ the plain text part is first, and I haven't seen an example otherwise, but this is by convention, and not required, so you can't trust that all mailers will follow it (there are plenty of popular mailers that don't follow convention nor standards). Also, there might be more than one "text/plain" part, attachments can also be set with a Content-Type of "text/plain", i.e. if it is a .TXT file, and as I mentioned, there is no requirement on the order the parts must appear. But if it is an attachment, it will say "Content-Disposition: attachment", so you cannot just look at the Content-Type header.


I would suggest that if the message is "multipart/mixed", extract the first "text/plain" part that is not an attachment, and that will be your plain text version.

        dZ.


-- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be

Reply via email to