delphi2010 indy10 mime编码 bug

来源:互联网 发布:软件著作权真伪查询 编辑:程序博客网 时间:2024/04/28 06:12

一直到Update4都没修复这个bug

 

版本 Delphi® 2010 Version 14.0.3513.24210
单元 IdCoderMIME.Pas
1.
procedure TIdDecoderMIMELineByLine.DecodeEnd;
var
  LStream: TMemoryStream;
  LPos: Integer;
begin
  if Length(FLeftFromLastTime) > 0 then begin
    LPos := Length(FLeftFromLastTime)+1;
    SetLength(FLeftFromLastTime, 4);
    while LPos <= 4 do begin
       FLeftFromLastTime[LPos-1] := Ord(FFillChar);     
      //原代码 FLeftFromLastTime[LPos] := Ord(FFillChar);
      Inc(LPos);
    end;
    LStream := TMemoryStream.Create;
    try
      WriteTIdBytesToStream(LStream, FLeftFromLastTime);
      LStream.Position := 0;
      inherited Decode(LStream);
    finally
      FreeAndNil(LStream);
      SetLength(FLeftFromLastTime, 0);
    end;
  end;
  inherited DecodeEnd;
end;

2.
procedure TIdDecoderMIMELineByLine.Decode(ASrcStream: TStream; const ABytes: Integer = -1);
var
  LMod, LDiv: integer;
  LIn, LSrc: TIdBytes;
  LStream: TMemoryStream;
begin
  LIn := FLeftFromLastTime;
  if ReadTIdBytesFromStream(ASrcStream, LSrc, ABytes) > 0 then begin
    AppendBytes(LIn, LSrc);
  end;
  LMod := Length(LIn) mod 4;
  if LMod <> 0 then begin
    LDiv := (Length(LIn) div 4) * 4;
 FLeftFromLastTime := Copy(LIn, LDiv, Length(LIn)-LDiv); 
 LIn := Copy(LIn, 0, LDiv);
   //原代码
   //FLeftFromLastTime := Copy(LIn, LDiv+1, Length(LIn)-LDiv);
   //LIn := Copy(LIn, 1, LDiv);

  end else begin
    SetLength(FLeftFromLastTime, 0);
  end;
  LStream := TMemoryStream.Create;
  try
    WriteTIdBytesToStream(LStream, LIn);
    LStream.Position := 0;
    inherited Decode(LStream, ABytes);
  finally
    FreeAndNil(LStream);
  end;
end;