Indy 9.0.18 and "uneven size in DecodeToStream" fix

Giganews Newsgroups
Subject: Indy 9.0.18 and "uneven size in DecodeToStream" fix
Posted by:  Luigi Sandon (…@sandon.it)
Date: Mon, 7 Feb 2005

Why the "uneven size in DecodeToStream" fix is still not present in
IdMessageCoderMime ?

function TIdMessageDecoderMIME.ReadBody(ADestStream: TStream; var VMsgEnd:
Boolean): TIdMessageDecoder;
var
  s: string;
  LDecoder: TIdDecoder;
  LLine: string;
  LBackLog : string;
begin
  VMsgEnd := FALSE;
  Result := nil;
  if FBodyEncoded then begin
    s := TIdMessage(Owner).ContentTransferEncoding;
  end else begin
    s := FHeaders.Values['Content-Transfer-Encoding']; {Do not Localize}
  end;
  if AnsiSameText(s, 'base64') then begin {Do not Localize}
    LDecoder := TIdDecoderMIME.Create(nil);
  end else if AnsiSameText(s, 'quoted-printable') then begin {Do not
Localize}
    LDecoder := TIdDecoderQuotedPrintable.Create(nil);
  end else begin
    LDecoder := nil;
  end;
  try
    repeat
      if FFirstLine = '' then begin // TODO: Improve this. Not very
efficient
        LLine := ReadLn;
      end else begin
        LLine := FFirstLine;
        FFirstLine := '';    {Do not Localize}
      end;
      if LLine = '.' then begin // Do not use ADELIM since always ends with
. (standard) {Do not Localize}
        VMsgEnd := True;
        Break;
      end;
      // New boundary - end self and create new coder
      if MIMEBoundary <> '' then begin
        if AnsiSameText(LLine, '--' + MIMEBoundary) then begin    {Do not
Localize}
          Result := TIdMessageDecoderMIME.Create(Owner);
          Break;
        // End of all coders (not quite ALL coders)
        end
        else if AnsiSameText(LLine, '--' + MIMEBoundary + '--') then begin
{Do not Localize}
          // POP the boundary
          if Owner is TIdMessage then begin
            TIdMessage(Owner).MIMEBoundary.Pop;
          end;
          Break;
        // Data to save, but not decode
        end else if LDecoder = nil then begin
          if (Length(LLine) > 0) and (LLine[1] = '.') then begin // Process
. in front for no encoding    {Do not Localize}
            Delete(LLine, 1, 1);
          end;
          LLine := LLine + EOL;
          ADestStream.WriteBuffer(LLine[1], Length(LLine));
        // Data to decode
        end else begin
          //for TIdDecoderQuotedPrintable, we have
          //to make sure all EOLs are intact
          if LDecoder is TIdDecoderQuotedPrintable then begin
            LDecoder.DecodeToStream(LLine+EOL,ADestStream);

          // Patch for Uneven size in DecodeToStream
          end else if LDecoder is TIdDecoder4to3 then begin
            LLine:=LBackLog+LLine;
            lBackLog:='';
            if (Length(LLine) mod 4) > 0 then begin
              LBackLog:=Copy(LLine,4*(Length(LLine) div
4)+1,Length(LLine)-(Length(LLine) div 4)*4);
              LLine:=Copy(LLine,1,4*(Length(LLine) div 4));
            end;
          LDecoder.DecodeToStream(LLine, ADestStream);
          // End of patch

          end else if LLine <> '' then begin
            LDecoder.DecodeToStream(LLine, ADestStream);
          end;
        end;
      end;
    until False;
  finally FreeAndNil(LDecoder); end;
end;

It was reported many months ago, and without this patch many mails cannot be
parsed correctly.

Was it resolved in another way, or left out for any good reason? I am a bit
tired to add it to any new Indy release... :-)

--
Luigi D. Sandon
…@sandon.it

Replies