I use the following code to eval the msg. content (body / lines) of an E Mail msg received with the INDY 10 components
function LinesFromMsg(aMsg: TIdMessage): TStrings;
var
i: Integer;
begin
for i := 0 to aMsg.MessageParts.AttachmentCount-1 do
begin
if (amsg.MessageParts.Items[i].ContentType ='HTML') then
begin
if (amsg.MessageParts.Items[i] is Tidtext) then
Result := TidText(amsg.MessageParts.Items[i]).body;
end;
end;
end;
regarding this code I have 2 questions :
a) is this the correct way of finding the Tlines part in an arbitray mail message ? ( consider the advice shown at INDY 10 EMAIL MSG PARTS )
b) where can I find a tutorial of all the different Contenttype string values?
The correct
ContentType
value to look for istext/html
. Use Indy'sIsHeaderMediaType()
function to check it, as theContentType
value may have additional attributes associated with it that your comparison needs to ignore.You also need to take the
TIdMessage.ContentType
into account as well, as HTML emails may not be MIME encoded and thus not use the TIdMessage.MessageParts` collection at all.And lastly, you loop needs to use the
MessageParts.Count
property instead of theMessageParts.AttachmentsCount
property.Try this:
With that said, this is technically not the correct way to handle MIME. Officially, a conforming reader is supposed to loop backwards through the MIME parts, as they are ordered from the simpliest form downwards towards the most complex form. So you loop backwards, taking MIME nesting into account, looking for the most complex form you support. Something more like this (untested):