Re: Mystery of dropping periods solved. Need help to fix.

Giganews Newsgroups
Subject: Re: Mystery of dropping periods solved. Need help to fix.
Posted by:  orlando (seasidebru…@hotmail.com)
Date: Wed, 13 Jul 2005

Is a period a safe character to start a line with?
If not, then I see the problem is in the lines below in unit
IdCoderQuotedPrintable.
I marked the problem area in comments "Problem area if CurrentLine[AtPos] is
a period"
=====================
function TIdEncoderQuotedPrintable.Encode(ASrcStream: TIdStream; const
ABytes: integer): string;
const
  SafeChars = [#33..#60, #62..#126];
  HalfSafeChars = [#32, TAB];
  // Rule #2, #3

var
  st: TIdStringList;
  CurrentLine: shortstring;
  // this is a shortstring for performance reasons.
  // the lines may never get longer than 76, so even if I go a bit
  // further, they won't go longer than 80 or so
  SourceLine: AnsiString;
  CurrentPos: integer;

    procedure WriteToString(const s: shortstring);
    var
      SLen: integer;
    begin
      SLen := Length(s);
      MoveChars(s,1, CurrentLine,CurrentPos, SLen);
      Inc(CurrentPos, SLen);
    end;

    Procedure NewLine(const AtPos: integer);
    begin
      if AtPos = CurrentPos then begin
        WriteToString('=');  {Do not Localize}
        st.Add(Copy(CurrentLine, 1, CurrentPos-1));
        CurrentPos := 1;
      end else begin
        st.Add(Copy(CurrentLine, 1, AtPos-1)+'='); { Do not Localize }
//// Problem area if CurrentLine[AtPos] is a period
        CurrentPos := CurrentPos-AtPos+1;
////  Moving it automatically to the CurrentLine buffer assumes
        MoveChars(CurrentLine, AtPos, CurrentLine, 1, CurrentPos-1);
//// that the period is a safe char to start a line
      end;
    end;

    Procedure FinishLine;
    begin
      st.Add(Copy(CurrentLine, 1, CurrentPos - 1));
      CurrentPos := 1;
    end;

var
  i: integer;
  PossibleBreakPos: integer;
  SourceLen: integer;
begin
  st := TIdStringList.Create;
  SetLength(CurrentLine, 255);
  try
    //ie while not eof
    while (ASrcStream.Position < ASrcStream.Size) do begin
      SourceLine := ReadLnFromStream(ASrcStream, -1, False);
      PossibleBreakPos := 1;
      CurrentPos := 1;
      SourceLen := length(SourceLine);
      for i := 1 to SourceLen do begin
        if CurrentPos < 72 then begin
          PossibleBreakPos := CurrentPos;
        end;
        if not (SourceLine[i] in SafeChars) then begin
          if (SourceLine[i] in HalfSafeChars) then begin
            if i = SourceLen then begin
              WriteToString(CharToHex('=',SourceLine[i]));
            end else begin
              WriteToString(SourceLine[i]);
            end;
          end else begin
            WriteToString(CharToHex('=',SourceLine[i]));
          end;
        end else begin
          if (CurrentPos = 1) and (SourceLine[i] = '.') then begin
            WriteToString(CharToHex('=',SourceLine[i]));
          end else begin
            WriteToString(SourceLine[i]);
          end;
        end;
        if CurrentPos > 74 then begin
          NewLine(PossibleBreakPos);
          PossibleBreakPos := 1;
        end;
      end;
      FinishLine;
    end;
    Result := st.Text;
  finally
    Sys.FreeAndNil(st);
  end;
end;
=====================

"orlando" <seasidebru…@hotmail.com> wrote in message
news:04F08B3A38D2E240seasidebru…@hotmail.com...
> Got the latest snapshot (7/12/2005 11AM) and it still does the same
> thing... on the ftp server for Delphi 6 INDY 10.52.
>
> Here is the problem.
>
> The HTML body has
> =====================
> <p>* From 01 July 2005, Qantas Airways domestic ticketing through the FTU
> will not attract any commission at source, however there will
> <b><u>not</u></b> be any service fee. Members will be able to earn up to
> 3.5% in incentive commissions on Group sales target achievement. Members
> self-ticketing will be able to earn up to 4.0%. This commission will be
> paid quarterly. </p>
> =====================
>
> When it is transmitted to the SMTP server, the lines get broken up like so
> =====================
> <p>* From 01 July 2005, Qantas Airways domestic ticketing through the =
> FTU will not attract any commission at source, however there will <b><=
> u>not</u></b> be any service fee. Members will be able to earn up to 3=
> 5% in incentive commissions on Group sales target achievement. Member=
> s self-ticketing will be able to earn up to 4.0%. This commission will=
> be paid quarterly. </p>
> =====================
>
> Notice the "3.5%" gets changed to "3=5%".  It seems the code to break up
> the lines drops periods if they existed right at the break off point.  Is
> there something I can do to fix this?
>
> Thanks
> Orlando

Replies

In response to

Mystery of dropping periods solved. Need help to fix. posted by orlando on Tue, 12 Jul 2005