slow operation using RetrieveRaw with a TString

Giganews Newsgroups
Subject: slow operation using RetrieveRaw with a TString
Posted by:  Aurélien
Date: Wed, 18 Nov 2009

Hi,

i use delphi 6 sp 3 with latest indy 10 snapshot.

i encounter some long timings using RetrieveRaw with a TStringStream
object, trying to handle mails with large attachements (greater than 1
MB).

nevertheless, the network activity seems to be ok, the message is
quickly received : it seems that other (slow) operations occur in the
function after the file has been received.

maybe i use indy the wrong way : i need to extract the original file in
eml format, and to store it for further usage, like getting the number
of attachments, extract the attachments, etc...

i hope you will help me... so thanks in advance for your time

here is the source code of my sample applications (extracts from a
bigger dll i have made) :

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdExplicitTLSClientServerBase, IdMessageClient, IdPOP3, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    IdPOP31: TIdPOP3;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  IdPOP31.connect;
  if IdPOP31.Connected then showmessage('connecté')
  else showmessage('pas connecté !');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  IdPOP31.disconnect;
  if IdPOP31.Connected then showmessage('toujours connecté !')
  else showmessage('déconnecté');
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  if IdPOP31.Connected then
showmessage(inttostr(IdPOP31.CheckMessages))
  else showmessage('pas connecté !');
end;

procedure TForm1.Button4Click(Sender: TObject);
var
  Flux: TStringStream;
  Fichier: Textfile;
  cdate1, cdate2, cdate3: string;
begin
  if IdPOP31.Connected then begin
    Flux := TStringStream.Create('');

    cdate1 := timetostr(time);
    if IdPOP31.RetrieveRaw(1, Flux) then begin
      cdate2 := timetostr(time);

      Flux.Position := 0;

      AssignFile(Fichier, 'd:\t\mail.txt');
      FileMode := fmOpenWrite;
      Rewrite(Fichier);
      Write(Fichier, Flux.DataString);
      Flush(Fichier);
      CloseFile(Fichier);

      cdate3 := timetostr(time);
      showmessage('récupération terminée' + #13#10 + cdate1 + #13#10 +
cdate2 + #13#10 + cdate3);
    end else showmessage('la récupération du message a échoué !');

    FreeAndNil(Flux);
  end else showmessage('pas connecté !');
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  if IdPOP31.Connected then begin
    if IdPOP31.Delete(1) then showmessage('message effaçé')
    else showmessage('l''effacement n''a pas eu lieu !');
  end else showmessage('pas connecté !');
end;

end.

--
Aurélien Dellieux

site perso : http://dellieuxa.perso.orange.fr
site boulot :http://www.corwin.fr

Replies