[BUG Report]There's a bug in DecodeHeader, it does not support GB2312 Charset wh

Giganews Newsgroups
Subject: [BUG Report]There's a bug in DecodeHeader, it does not support GB2312 Charset wh
Posted by:  ÀîÕ½(leadzen) (leadz…@gmail.com)
Date: Mon, 28 Nov 2005

Dear Indy Members:
    I have found this bug in Indy 10, please correct it. The file is
IdCoderHeader.pas, and you can reference to the following code:

function DecodeHeader(Header: string):string;
......
begin
  ......
  if LEncodingStartPos = 0 then begin
    LEncodingStartPos := PosIdx('=?KOI8', Sys.UpperCase(Header), 1); {do not
localize}
  end;

  //The following was added by leadzen to fix the bug in decoding GB2312
charset
  if LEncodingStartPos = 0 then begin
    LEncodingStartPos := PosIdx('=?GB2312', Sys.UpperCase(Header), 1); {do
not localize}
  end;
  //added by leadzen

  while LEncodingStartPos > 0 do begin
    // Assume we will find the encoding
    EncodingFound := True;
  ......

    ......

    if LEncodingStartPos = 0 then begin
      LEncodingStartPos := PosIdx('=?KOI8', Sys.UpperCase(Header),
LPreviousEncodingStartPos + 1); {do not localize}
    end;

    //The following was added by leadzen to fix the bug in decoding GB2312
charset
    if LEncodingStartPos = 0 then begin
      LEncodingStartPos := PosIdx('=?GB2312', Sys.UpperCase(Header),
LPreviousEncodingStartPos + 1); {do not localize}
    end;
    // added by leadzen

    // delete whitespace between adjacent encoded words, but only
    // if we had an encoding before
    if EncodingFound then begin
      EncodingBeforeEnd := encodingendpos;
    end else begin
      EncodingBeforeEnd := -1;
    end;

    ......
end;

That's all

Good luck for you!

ÀîÕ½(leadzen)

Replies