Changeset 97 for trunk/UContact.pas


Ignore:
Timestamp:
Feb 4, 2022, 11:30:24 AM (2 years ago)
Author:
chronos
Message:
  • Fixed: Quoted-printable encoded text was not handled correctly for multiple lines.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UContact.pas

    r93 r97  
    603603  end else
    604604  if Encoding = 'QUOTED-PRINTABLE' then begin
    605     Result := DecodeQuotedPrintable(Value);
     605    Result := DecodeQuotedPrintable(Value, True);
    606606  end
    607607  else Result := '';
     
    614614  end else
    615615  if Encoding = 'QUOTED-PRINTABLE' then begin
    616     Result := EncodeQuotedPrintable(Value);
     616    Result := EncodeQuotedPrintable(Value, True);
    617617  end
    618618  else Result := '';
     
    11641164              CutLength := ContactsFile.MaxLineLength;
    11651165              if Encoding = 'QUOTED-PRINTABLE' then begin
    1166                 // Do not cut encoded items
    1167                 if ((CutLength - 2) >= 1) and (OutText[CutLength - 2] = '=') then
     1166                Dec(CutLength); // There will be softline break at the end
     1167                // Do not cut encoded items at the end of line
     1168                if ((CutLength - 1) >= 1) and (OutText[CutLength - 1] = QuotedPrintableEscapeCharacter) then
    11681169                  Dec(CutLength, 2)
    1169                 else if ((CutLength - 1) >= 1) and (OutText[CutLength - 1] = '=') then
     1170                else if OutText[CutLength] = QuotedPrintableEscapeCharacter then
    11701171                  Dec(CutLength, 1);
    11711172              end;
     1173
    11721174              CutText := UTF8Copy(OutText, 1, CutLength);
     1175              System.Delete(OutText, 1, Length(CutText));
     1176              if Encoding = 'QUOTED-PRINTABLE' then
     1177                CutText := CutText + QuotedPrintableEscapeCharacter; // Add soft line break
    11731178              Add(LinePrefix + CutText);
    1174               LinePrefix := ' ';
    1175               System.Delete(OutText, 1, Length(CutText));
     1179              if Encoding <> 'QUOTED-PRINTABLE' then
     1180                LinePrefix := ' ';
    11761181              Inc(LineIndex);
    11771182              Continue;
     
    11991204  CommandPart: string;
    12001205  Names: string;
     1206  QuotedPrintableMultiLine: Boolean;
    12011207begin
    12021208  Result := False;
     
    12281234        CommandPart := GetNext(Line, ':');
    12291235        Names := CommandPart;
     1236        QuotedPrintableMultiLine := Pos('encoding=quoted-printable', LowerCase(CommandPart)) > 0;
    12301237        Value := Line;
    12311238        while True do begin
     
    12371244            Value := Value + Copy(Line2, 2, MaxInt);
    12381245          end else
    1239           if (Length(Line2) > 0) and (Length(Value) > 0) and (Value[Length(Value)] = '=') and
    1240             (Line2[1] = '=') then begin
    1241             Value := Value + Copy(Line2, 2, MaxInt);
     1246          if QuotedPrintableMultiLine and (Length(Value) > 0) and
     1247          (Value[Length(Value)] = QuotedPrintableEscapeCharacter) then begin
     1248            SetLength(Value, Length(Value) - 1);
     1249            Value := Value + Line2;
    12421250          end else begin
    12431251            Dec(I);
Note: See TracChangeset for help on using the changeset viewer.