0

Here is my little code:

curMessage:TIdMessage;
tidImap: TIdIMAP4;
...
tidImap.UIDRetrieve('123', curMessage);

That works fine! Now when i try to read

curMessage.Body

Then it is empty sometimes. I've understand that it is empty when message IsMsgSinglePartMime is False. So then i can't read message's body from Body property.

I've searched in curMessage's every property, but nowhere could i found the body text. What makes it even more odd, is that when i save curMessage

curMessage.Savefile('...');

then i can see all the body there.

I don't want to make another request to fetch for the body (eg UIDRetrieveText(2)) because i understand that the body data is there somewhere, i just could not find it or is Savefile/SaveStream making some internal requests to server?

Thank you guys in advance!

Peacelyk
  • 1,126
  • 4
  • 24
  • 48
  • You should specify which Indy version. There are sometimes drastic changes between major versions, and it helps to get an answer if we know which one you're using. – Ken White Apr 08 '11 at 14:42
  • indy 10, sorry i didn't specify! It seems that your answer is what i'm looking for. I'll try it out when i reach to my machine where delphi is installed! – Peacelyk Apr 08 '11 at 15:12

1 Answers1

2

You need to be checking TIdMessage.MessageParts.

var
  Msg: TIdMessage;
  i: Integer;
begin
  // Code to retrieve message from server
  for i := to Msg.MessageParts.Count - 1 do
  begin
    if (Msg.MessageParts.Items[i] is TIdAttachment) then
      // Handle attachment
    else
    begin
      if Msg.MessageParts.Items[i] is TIdText then
        HandleText(TIdText(Msg.MessageParts.Items[i]).Body);
    end;
  end;
end;

In Indy 10, TIdMessageParts has been moved into it's own unit, so you may have to add IdMessageParts to your uses clause.

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • 1
    Don't forget to look at the `TIdMessage.ContentType` property to determine when to use the `TIdMessage.MessageParts` collection, and at the `TIdText.ContentType` property to determine which `TIdText` object contains the text you are looking for (if there are multiple present, which is common) – Remy Lebeau Apr 09 '11 at 05:38