TIdMessage.SaveToFile raises an exception

Giganews Newsgroups
Subject: TIdMessage.SaveToFile raises an exception
Posted by:  Marc Deroover (mderoov…@sogy.org)
Date: Wed, 22 Sep 2004

Description of the problem:

Take a new form, add a "IdMsgSend: TIdMessage;" VCL on it, and run the
simple code herebelow. You will get an exception, like "External exception
C0000008", in "SaveToFile".  Note that the problem does not come from using
invalid values for the various arguments.

  with IdMsgSend do
        Body.Text := 'Email''s body';
        From.Text := 'm…@disa.be';
        ReplyTo.EMailAddresses := 'm…@disa.be';
        Recipients.EMailAddresses := 'epsilo…@sogy.org';
        Subject := 'Indy test 2';
        Priority := TIdMessagePriority(2); { Message Priority }
        CCList.EMailAddresses := ''; {CC}
        BccList.EMailAddresses := ''; {BBC}
        ReceiptRecipient.Text := '';
        SaveToFile( 'c:\scratch\email.eml');

I am Running DELPHI 5 with Indy code downloaded from "Indy_9_00_14_src.zip"

Cause of the problem (according to me)

Exception is raised by line 1035 of idMessage.pas : "vStream.Free;".
The cause is that (in the same unit):
- we have line 1051 "LIOHS.OutputStream := AStream;"
- and at line 1079 we have "LMsgClient.Disconnect;" that will destroy the
LIOHS OutputBuffer through the "TIdTCPConnection.Disconnect",
"TIdTCPConnection.DisconnectSocket;", and finally
- because of line 1051 the buffer of AStream is also destroyed, and thus
vStream.Free will crash.


The problem can be solved by adding the line "LIOHS.FreeStreams := false;"
before calling the "LMsgClient.Disconnect;" at line 1079 of idMessage.pas.
It works for me but maybe this is not good enought ...

Hope it helps,
Marc Deroover