Board index » delphi » Indy 9.0.2: Sending mail - infinite loop

Indy 9.0.2: Sending mail - infinite loop

Hi there,

I'm trying to send out email messages that are HTML with an attachment (Indy
9.0.2, Delphi 6 SR-1). Everything seems to be going fine up until the
sending of the message itself.

The message is coming from an database, and is stored as:

From: "AUser" a.u...@xyz.com
Subject: Testing, yet again...
To: m...@me.com
Content-Type: multipart/mixed; boundary="=_NextPart_2rfkindysadvnqw3nerasdf"
MIME-Version: 1.0
Organization: MeCo, Inc.
Date: Tue, 9 Oct 2001 15:48:24 -0400
X-Priority: 3
X-Library: Indy 9.0.2-B

This is a multi-part message in MIME format

--=_NextPart_2rfkindysadvnqw3nerasdf
Content-Type: text/html
Content-Transfer-Encoding: 7bit

<HTML><HEAD>
<BASEFONT FACE="Arial" SIZE="2" COLOR="#000000">
</HEAD>
<BODY>
<div>This is <b>YET ANOTHER test</b>.</div>
</BODY></HTML>

--=_NextPart_2rfkindysadvnqw3nerasdf
Content-Type: application/octet-stream;
        name="SomeFile.rtf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
        filename="SomeFile.rtf"

e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcdWMxIFxkZWZmMFxkZWZsYW5nMTAzM1xkZWZsYW5nZmUx
[... deleted for brevity...]
bGFibGUgdXBvbiByZXF1ZXN0DQpccGFyIA0KXHBhciANClxwYXIgfX0=

--=_NextPart_2rfkindysadvnqw3nerasdf--
.

When the message is sent, it gets trapped in:

procedure TIdMessageEncoderMIME.Encode(ASrc, ADest: TStream);
var
  s: string;
  LEncoder: TIdEncoderMIME;
begin
  ASrc.Position := 0;
  LEncoder := TIdEncoderMIME.Create(nil); try
    while ASrc.Position < ASrc.Size do begin
      s := LEncoder.Encode(ASrc, 57) + EOL;
      ADest.WriteBuffer(s[1], Length(s));
    end;
  finally FreeAndNil(LEncoder); end;
end;

... A quick inspection of ASrc.Position and ASrc.Size indicates they are
both 0, so it makes sense that it goes ad infinitum. However, this is not a
Good Thing! First, my message never goes out (this is bad!) and second, it
stops any further attempts, making the message status stop on "Encoding
attachment".

What's going on here, and how can I fix it?

Thanks in advance,

--
Tim Sullivan
Unlimited Intelligence Limited
Dimethylaminoethanol for your software
http://www.uil.net

 

Re:Indy 9.0.2: Sending mail - infinite loop


In article <3bc35ae1$1_1@dnews>, t...@NO.SPAM.FOR.ME.uil.net says...
Quote
> Hi there,

> I'm trying to send out email messages that are HTML with an attachment (Indy
> 9.0.2, Delphi 6 SR-1). Everything seems to be going fine up until the
> sending of the message itself.

I have not tested this myself but I did look at the Indy source-code
involved with sending a message.

It turns out that the stream being passed to the
TIdMessageEncoderMIME.Encode is a TIdTCPStream.  That class is used
internally for reading and writing to a TIdTCPConnection.  Since this is
immediate, the Seek method does not make any sense so it always returns
a -1 indicating failure.  Borland's TStream class defines the properties
position and Size with private static read methods that use Seek.  Thus,
the two properties are failing.

I'm not sure how to fix this one but I have forwarded your comments and
this reply.  There were some concerns mentioned about this internally
which is why I could give a quick reply.

--
Support the anti-Spam amendment - Join at http://www.cauce.org/
J. Peter Mugaas     E-Mail:  oma00...@mail.wvnet.edu
http://wvnvm.wvnet.edu/~oma00215/  ICQ Number:  14297043
Finger for PGP Key

Re:Indy 9.0.2: Sending mail - infinite loop


In article <MPG.162d3269eba3b98f989...@forums.borland.com>, oma00215
@mail.wvnet.edu says...

Quote
> In article <3bc35ae1$1_1@dnews>, t...@NO.SPAM.FOR.ME.uil.net says...
> > Hi there,

> > I'm trying to send out email messages that are HTML with an attachment (Indy
> > 9.0.2, Delphi 6 SR-1). Everything seems to be going fine up until the
> > sending of the message itself.

> I have not tested this myself but I did look at the Indy source-code
> involved with sending a message.

I was on the wrong track.  I did confirm the problem.  For some odd
reason, repeatedly calling the Position and Size property in the source
stream was somehow returning zero.

In any case, it is not a bright idea to repeatedly call those.  

Try this:

procedure TIdMessageEncoderMIME.Encode(ASrc, ADest: TStream);
var
  s: string;
  LEncoder: TIdEncoderMIME;
  LSPos, LSSize : Int64;
begin
  ASrc.Position := 0;
  LSPos := 0;
  LSSize := ASrc.Size;
  LEncoder := TIdEncoderMIME.Create(nil); try
    while LSPos < LSSize do begin
      s := LEncoder.Encode(ASrc, 57) + EOL;
      Inc(LSPos,Length(s));
      ADest.WriteBuffer(s[1], Length(s));
    end;
  finally FreeAndNil(LEncoder); end;
end;
--
Support the anti-Spam amendment - Join at http://www.cauce.org/
J. Peter Mugaas     E-Mail:  oma00...@mail.wvnet.edu
http://wvnvm.wvnet.edu/~oma00215/  ICQ Number:  14297043
Finger for PGP Key

Re:Indy 9.0.2: Sending mail - infinite loop


On Tue, 9 Oct 2001 16:15:06 -0400, "Tim Sullivan"

Quote
<t...@NO.SPAM.FOR.ME.uil.net> wrote:
>... A quick inspection of ASrc.Position and ASrc.Size indicates they are
>both 0, so it makes sense that it goes ad infinitum. However, this is not a

     This is a bug in the de{*word*81}--int64's display wrong.

Other Threads