TidSMTPServer.OnMsgReceive weirdness with periods

Giganews Newsgroups
Subject: TidSMTPServer.OnMsgReceive weirdness with periods
Posted by:  Tim Parker-Nance (tim_…@hotmail.com)
Date: Wed, 12 Jul 2006

Hi all

I am not sure if this is related to the 'tidsmtp keeps throwing error 10053'
thread, if it is can you please give me a summary of what to do to get
around this please.

What I want to do is scan the content of a message received for spam in
OnMsgReceive and add some extra headers. idMessage seems the correct
candidate for this. I have created a Server project which does nothing but
save the stream 2 ways 1) As is (Raw) and 2) via idMessage with NoDecode,
NoEncode = False (idMessage). Below is the code:

procedure TfrmSMTPServerTest.IdSMTPServer1MsgReceive(ASender:
TIdSMTPServerContext; AMsg: TStream; var LAction: TIdDataReply);
var
  fs: TFileStream;
begin
  lAction := dOk;
  fs := TFileStream.Create(ExtractFilePath(Application.ExeName)+'
Raw.txt',fmCreate);
  try
    fs.CopyFrom(aMsg,0);
  finally
    FreeAndNil(fs);
  end;
  idMessage1.NoEncode := False;
  idMessage1.NoDecode := False;
  idMessage1.Clear;
  aMsg.Position := 0;
  idMessage1.LoadFromStream(aMsg);
  idMessage1.SaveToFile(ExtractFilePath(Application.ExeName)+'
idMessage.txt');
end;

I have a client application that sends via idSMTP an idMessage with the
following body:
1
2.
3
......4
5
.
6
7.......
8

So I get the following:

1) Raw.txt: All is ok

Received: from localhost[127.0.0.1] (helo=) by localhost[127.0.0.1] with
smtp (Indy SMTP Server)
From: "…@b.com" <…@b.com>
Subject: Test
To: …@d.com
Date: Wed, 12 Jul 2006 16:01:09 +0200
X-Mailer: SMTP Server Test client

1
2.
3
......4
5
.
6
7.......
8

2) idMessage.txt: All is not ok. The single . between 5 and 6 caused a
problem.

Received: from localhost[127.0.0.1] (helo=) by localhost[127.0.0.1] with
smtp (Indy SMTP Server)
From: "…@b.com" <…@b.com>
Subject: Test
To: …@d.com
Date: Wed, 12 Jul 2006 16:01:09 +0200
X-Mailer: SMTP Server Test client

1
2.
3
.....4
5
.

I have also checked with NoDecode, NoEncode = True, it makes no difference
which makes sense because there are no encoded body parts.

So the question is: Is there a problem in idMessage.LoadFromStream with
periods?

If there is then how do I get around this? If there isn't then how do I get
the stream into an idMessage so I can scan the content?

Thanks

Tim

Replies