Re: Email Body problems in idPop3 and idMessage

Giganews Newsgroups
Subject: Re: Email Body problems in idPop3 and idMessage
Posted by:  J. R. (
Date: Tue, 25 Nov 2003

I had not read some of the other posts since I started this a couple of
weeks ago so I missed the message from Dm_Vinny.  Because of that I am
including some code and more description of the problem.  My project is
designed to receive all of the emails received and save them to a database
table.  The problem is when I use the lines:
  MyStream.Position := 0;
to get the message into a string so I can easily save it to the database it
does not give me the body for some messages.  When I look at the message it
appears to be a multi-part MIME message but the body part is empty.  The
actual body is stored in the idMessage.Body.  With messages like this the
SaveToStream does not save the body part of the message.  I would call this
a bug because it should save the entire message even if it is malformed
since it is able to parse it properly when it arrives.  The code below
allows me to see the body text and also shows how I look at the message
after the SaveToStream to see that the body is not encoded properly.  In
looking at the header for the messages that have the problem it appears they
are using Indy 9.0.11 to build the message.  This may indicate that there is
also a bug in the message building routines when sending the message.
Outlook stores the message completly so I would really call it a bug in the
SaveToStream procedure.

// This works fine to extract the body text
  Str := TStringList.Create;
  HTML := False;
  for I := 0 to idMessage1.MessageParts.Count - 1 do begin    // Iterate
    S := LowerCase(idMessage1.MessageParts.Items[i].ContentType);
    if (Pos('text/html', S) > 0) or (Pos('text/plain', S) > 0) then begin
      if (Pos('text/html', S) > 0) then begin
        HTML := True;
      end else if not HTML then begin
  end;    // for
  if idMessage1.MessageParts.Count = 0 then begin

// These lines should place the entire contents of the message into the
Memo1 but does not have the body for the
// problem messages.
  TmpString := TStringList.Create;
  MyStream := TMemoryStream.Create;
  MyStream.Position := 0;

"J. R." <…> wrote in message
> I have a problem with receiving some emails.  We receive emails from a
> company that appears to use Indy 9.0.11 to build the messages.  The
> is supposed to be a multi-part message with a body and an attachment.
> parsing the idMessage1.MessageParts.Items[I]).Body there is no body.  The
> body appears in the IdMessage.Body section.  The problem comes when using
> the SaveToStream function to save the message.  The Body is not saved
> because the TIdMessage thinks the message is a multi-part message and only
> saves the MessageParts of the idMessage and not the Body.  I think this is
> bug in the way Indy is building the message in the first place.  However
> is also a problem that the SaveToStream does not include the Body in a
> multi-part message.  If you need further information please let me know
> I can include some code that demonstrates the problem.


In response to

Email Body problems in idPop3 and idMessage posted by J. R. on Tue, 25 Nov 2003