Loading ...
Sorry, an error occurred while loading the content.

RE: [tmail2000] the method "EncodeQuotedPrintable" is very slow?

Expand Messages
  • Keith Anderson
    Insert a few application.processmessages in the routine so the system responds during the encoding process. ... a ... give
    Message 1 of 3 , Jan 21, 2005
    • 0 Attachment
      Insert a few application.processmessages in the routine so the system
      responds during the encoding process.

      > Code the Method "EncodeQuotedPrintable" Is very slow. If It Deal with
      a
      > long Email,
      > the system is no response.If I can not resolve this problem I have to
      give
      > up this good object.
    • joaofcm00
      Hi Change EncodeQuotedPrintable function as bellow. João function EncodeQuotedPrintable(const Texto: String; const HeaderLine: Boolean): String; var nPos:
      Message 2 of 3 , May 12, 2005
      • 0 Attachment
        Hi

        Change EncodeQuotedPrintable function as bellow.

        João

        function EncodeQuotedPrintable(const Texto: String; const HeaderLine:
        Boolean): String;
        var
        nPos: Integer;
        LineLen: Integer;
        Buffer: TStringList;
        j: Integer;
        re, Line2: ^string;
        b: Boolean;
        begin

        Result := '';
        New( re );
        New( line2 );

        re^ := '';

        j := Length( Texto );

        for nPos := 1 to Length(Texto) do
        begin

        Form1.Gauge1.Progress := Trunc( ( 100 * nPos ) / j );

        b := (Texto[nPos] > #127) or
        (Texto[nPos] = '=') or
        ((Texto[nPos] < #32) and (not (Texto[nPos] in [#9, #10,
        #13]))) or
        ((nPos < Length(Texto)) and (Texto[nPos] = #13) and (Texto
        [nPos+1] <> #10)) or
        ((nPos = Length(Texto)) and (Texto[nPos] = #13)) or
        ((nPos > 1) and (Texto[nPos] = #10) and (Texto[nPos-1] <>
        #13)) or
        ((nPos = 1) and (Texto[nPos] = #10)) or
        ((Texto[nPos] in [#9..#32,
        #39, '?', '<', '>', '(', ')', '"', '_']) and HeaderLine);

        case b of
        True : begin
        if Texto[ nPos ] = '=' then
        re^ := re^ + '3D'
        else
        Re^ := Re^ + '=' + PadL( Format( '%2x', [ Ord(
        Texto[ nPos ] ) ] ), 2, '0');
        end;
        else
        Re^ := Re^ + Texto[nPos];
        end;

        // Encode trailing spaces/tabs

        if not HeaderLine then
        begin

        if (Length(Re^ ) > 2)
        and (Re^[Length(Re^)] = #10)
        and (Re^[Length(Re^)-1] = #13)
        and (Re^[Length(Re^)-2] in [#9, #32]) then
        begin

        LineLen := Length(Re^)-2;
        Line2^ := '';

        while (LineLen >= 1) and (Re^[LineLen] in [#9, #32]) do
        begin

        case Re^[LineLen] of
        #09: Line2^ := '=09'+Line2^;
        #32: Line2^ := '=20'+Line2^;
        end;

        Dec(LineLen);
        if LineLen = 0 then Break;
        end;

        Re^ := Copy(Re^, 1, LineLen)+Line2^+#13#10;
        end;
        end;

        Application.ProcessMessages;
        end;

        Dispose( Line2 );

        // Insert soft linebreaks

        if not HeaderLine then
        begin

        Buffer := TStringList.Create;
        Buffer.Text := Re^;

        nPos := 0;

        while nPos < Buffer.Count do
        begin

        LineLen := Length(Buffer[nPos]);

        while LineLen >= _LINELEN do
        begin

        if (LineLen >= 3)
        and (Buffer[nPos][LineLen] in ['0'..'9', 'A'..'F'])
        and (Buffer[nPos][LineLen-1] in ['0'..'9', 'A'..'F'])
        and (Buffer[nPos][LineLen-2] = '=') then
        Dec(LineLen, 3)
        else
        Dec(LineLen, 1);
        Application.ProcessMessages;
        end;

        if LineLen < Length(Buffer[nPos]) then begin
        Buffer.Insert(nPos+1, Copy(Buffer[nPos], LineLen+1, Length
        (Buffer[nPos])));
        Buffer[nPos] := Copy(Buffer[nPos], 1, LineLen)+'=';
        end;

        Inc(nPos);
        Application.ProcessMessages;
        end;

        Re^ := Buffer.Text;
        Result := Re^;
        Dispose( re );
        Application.ProcessMessages;
        end;
        end;
      Your message has been successfully submitted and would be delivered to recipients shortly.