EAV in TIdPOP3.CheckMessages

Giganews Newsgroups
Subject: EAV in TIdPOP3.CheckMessages
Posted by:  Thomas Zangl (usen…@tzis.net)
Date: Mon, 06 Dec 2004

Hi,

Sometimes I get an exception:

function TIdPOP3.CheckMessages: longint;
var
  s: string;

begin
  Result := 0;
  SendCmd('STAT', ST_OK);    {Do not Localize}

  // Only gets here if exception is not raised
  s := LastCmdResult.Text[0];
  if Length(s) > 0 then begin
    Result := StrToInt(Copy(s, 1, IndyPos(' ', s) - 1)); // <-- HERE
  end;
end;

It´s caused by some invalid string "s" converted to an Integer. It seems
some POP Servers (courier in my case) sometimes send a bad reply to the
STAT command.

Solution: Replace StrToInt with "StrToIntDef".

Example:

function TIdPOP3.CheckMessages: longint;
var
  s: string;

begin
  Result := 0;
  SendCmd('STAT', ST_OK);    {Do not Localize}

  // Only gets here if exception is not raised
  s := LastCmdResult.Text[0];
  if Length(s) > 0 then begin
    Result := StrToIntDef(Copy(s, 1, IndyPos(' ', s) - 1),0);
  end;
end;

This fixes the EAV. If somebody knows a better way, please post.

Best regards,

--
----------------------------------------------------------------
,yours Thomas Zangl -thom…@tzi.dhs.org- -TZ1-6BONE-
http://tzi.dhs.org -http://www.borg-kindberg.ac.at
Use YAMC! now! Get it athttp://www.borg-kindberg.ac.at/yamc/

Replies