Re: How to handle different Content-Type's

Giganews Newsgroups
Subject: Re: How to handle different Content-Type's
Posted by:  Ciaran Costelloe (ccostell…@flogas.ie)
Date: Mon, 19 Jul 2004

"Etienne van Tonder" <e…@infoware.com.au> wrote in message
news:D90E95E063A5E240e…@infoware.com.au...
> I'm having some problems trying to determine how best to handle the
> different content types. Is there a standard way of handling the different
> types

No, it depends what you are interested in or how far you are prepared to go
to support all the types..

> and if so is anyone willing to share some code to show me how to do
> it. Currently I am using the following code but it assumes that if the
> content-type does not include multipart it's either text or html.

As Gambit says, this is incorrect.  As an example, there are rare emails
that contain only a single part which is an attachment (e.g. an Excel
spreadsheet).  There are also some very rare emails that have a "text/" part
which is neither "text/plain" or "text/html".

It depends what you are looking for, but you may want to loop through the
message parts and check in sequence:
(a) if the part is a TIdAttachment and has a filename <> '', then assume
this is a "normal" attachment
(b) if not (a) then see if it is a text/plain or text/html (which is
probably the "message", which you can display easily), and any other "text/"
should be somewhat readable by a human in a TMemo,
(c) if not (a) or (b) and the part has a ContentID, it (usually) belongs to
a previous "text/html", e.g. a logo on a web page (you would really need to
load the parts into a tree structure based on the ParentPart properly to
figure out what ContentID goes with what part to be 100% right, but you will
usually find only one ContentID value in most emails).

The other type left that I can think of is PGP-key parts.

For non-MIME messages, use the above sequence using the
TIdMessage.ContentType rather than the part's ContentType.

Ciaran

Replies

In response to

How to handle different Content-Type's posted by Etienne van Tonder on Mon, 19 Jul 2004