Changeset 119 for trunk


Ignore:
Timestamp:
Feb 18, 2022, 2:53:31 PM (3 years ago)
Author:
chronos
Message:
  • Modified: Keep original encoding text in loaded contacts attributes for later save.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/UContact.pas

    r116 r119  
    115115  end;
    116116
     117  TPropertyEncoding = (veNone, veQuotedPrintable, veBase64, ve8bit);
     118
    117119  { TContactProperty }
    118120
    119121  TContactProperty = class
    120122  private
     123    function GetEncoding: TPropertyEncoding;
    121124    function GetValueItem(Index: Integer): string;
     125    procedure SetEncoding(AValue: TPropertyEncoding);
    122126    procedure SetValueItem(Index: Integer; AValue: string);
    123127  public
     
    125129    Attributes: TStringList;
    126130    Value: string;
    127     Encoding: string;
    128131    Charset: string;
    129132    procedure EvaluateAttributes;
     
    136139    destructor Destroy; override;
    137140    property ValueItem[Index: Integer]: string read GetValueItem write SetValueItem;
     141    property Encoding: TPropertyEncoding read GetEncoding write SetEncoding;
    138142  end;
    139143
     
    238242  VCardEnd = 'END:VCARD';
    239243  VCardBase64 = 'BASE64';
     244  VCardBase64Short = 'B';
    240245  VCardQuotedPrintable = 'QUOTED-PRINTABLE';
     246  VCardQuotedPrintableShort = 'Q';
     247  VCardEncoding = 'ENCODING';
     248  VCardCharset = 'CHARSET';
    241249
    242250
     
    887895{ TContactProperty }
    888896
     897function TContactProperty.GetEncoding: TPropertyEncoding;
     898var
     899  EncodingText: string;
     900begin
     901  Result := veNone;
     902  if Attributes.IndexOf(VCardBase64) <> -1 then Result := veBase64
     903  else if Attributes.IndexOf(VCardQuotedPrintable) <> -1 then Result := veQuotedPrintable
     904  else if Attributes.IndexOfName(VCardEncoding) <> -1 then begin
     905    EncodingText := UpperCase(Attributes.Values[VCardEncoding]);
     906    if (EncodingText = VCardBase64) or (EncodingText = VCardBase64Short) then Result := veBase64
     907    else if (EncodingText = VCardQuotedPrintable) or (EncodingText = VCardQuotedPrintableShort) then Result := veQuotedPrintable
     908  end;
     909end;
     910
    889911function TContactProperty.GetValueItem(Index: Integer): string;
    890912var
     
    905927end;
    906928
     929procedure TContactProperty.SetEncoding(AValue: TPropertyEncoding);
     930begin
     931  if Attributes.IndexOf(VCardBase64) <> -1 then begin
     932    Attributes.Delete(Attributes.IndexOf(VCardBase64));
     933    if AValue = veBase64 then Attributes.Add(VCardBase64)
     934    else if AValue = veQuotedPrintable then Attributes.Add(VCardQuotedPrintable);
     935  end else
     936  if Attributes.IndexOf(VCardQuotedPrintable) <> -1 then begin
     937    Attributes.Delete(Attributes.IndexOf(VCardQuotedPrintable));
     938    if AValue = veBase64 then Attributes.Add(VCardBase64)
     939    else if AValue = veQuotedPrintable then Attributes.Add(VCardQuotedPrintable);
     940  end else
     941  if Attributes.IndexOfName(VCardEncoding) <> -1 then begin
     942    if AValue = veBase64 then Attributes.Values[VCardEncoding] := VCardBase64
     943    else if AValue = veQuotedPrintable then Attributes.Values[VCardEncoding] := VCardQuotedPrintable
     944    else Attributes.Delete(Attributes.IndexOfName(VCardEncoding));
     945  end;
     946end;
     947
    907948procedure TContactProperty.SetValueItem(Index: Integer; AValue: string);
    908949var
     
    936977  I: Integer;
    937978begin
    938   if Attributes.IndexOf(VCardBase64) <> -1 then begin
    939     Encoding := VCardBase64;
     979  if Encoding <> veNone then
    940980    Value := GetDecodedValue;
    941   end else
    942   if Attributes.IndexOfName('ENCODING') <> -1 then begin
    943     Encoding := Attributes.Values['ENCODING'];
    944     if (Encoding = 'B') or (Encoding = 'b') then Encoding := VCardBase64;
    945     if (Encoding = 'Q') or (Encoding = 'q') then Encoding := VCardQuotedPrintable;
    946     if (Encoding = VCardQuotedPrintable) or (Encoding = VCardBase64) then begin
    947       Value := GetDecodedValue;
    948       Attributes.Delete(Attributes.IndexOfName('ENCODING'));
    949     end else
    950   end else Encoding := '';
    951 
    952   if Attributes.IndexOfName('CHARSET') <> -1 then
    953     Charset := Attributes.Values['CHARSET']
     981
     982  if Attributes.IndexOfName(VCardCharset) <> -1 then
     983    Charset := Attributes.Values[VCardCharset]
    954984    else Charset := '';
    955985
     
    965995function TContactProperty.GetDecodedValue: string;
    966996begin
    967   if Encoding = VCardBase64 then begin
     997  if Encoding = veBase64 then begin
    968998    Result := DecodeStringBase64(Value);
    969999  end else
    970   if Encoding = VCardQuotedPrintable then begin
     1000  if Encoding = veQuotedPrintable then begin
    9711001    Result := DecodeQuotedPrintable(Value, True);
    9721002  end
     
    9761006function TContactProperty.GetEncodedValue: string;
    9771007begin
    978   if Encoding = VCardBase64 then begin
     1008  if Encoding = veBase64 then begin
    9791009    Result := EncodeStringBase64(Value);
    9801010  end else
    981   if Encoding = VCardQuotedPrintable then begin
     1011  if Encoding = veQuotedPrintable then begin
    9821012    Result := EncodeQuotedPrintable(Value, True);
    9831013  end
     
    10141044  Attributes.Assign(Source.Attributes);
    10151045  Value := Source.Value;
    1016   Encoding := Source.Encoding;
    10171046  Charset := Source.Charset;
    10181047end;
     
    15571586      if Attributes.Count > 0 then
    15581587        NameText := NameText + ';' + Attributes.DelimitedText;
    1559       if Encoding <> '' then begin
     1588      if Encoding <> veNone then begin
    15601589        Value2 := GetEncodedValue;
    1561         NameText := NameText + ';ENCODING=' + Encoding;
    15621590      end else Value2 := Value;
    15631591      if Pos(LineEnding, Value2) > 0 then begin
     
    15751603          if UTF8Length(OutText) > ContactsFile.MaxLineLength then begin
    15761604            CutLength := ContactsFile.MaxLineLength;
    1577             if Encoding = VCardQuotedPrintable then begin
     1605            if Encoding = veQuotedPrintable then begin
    15781606              Dec(CutLength); // There will be softline break at the end
    15791607              // Do not cut encoded items at the end of line
     
    15861614            CutText := UTF8Copy(OutText, 1, CutLength);
    15871615            System.Delete(OutText, 1, Length(CutText));
    1588             if Encoding = VCardQuotedPrintable then
     1616            if Encoding = veQuotedPrintable then
    15891617              CutText := CutText + QuotedPrintableEscapeCharacter; // Add soft line break
    15901618            Add(LinePrefix + CutText);
    1591             if Encoding <> VCardQuotedPrintable then
     1619            if Encoding <> veQuotedPrintable then
    15921620              LinePrefix := ' ';
    15931621            Inc(LineIndex);
  • trunk/UContactImage.pas

    r112 r119  
    261261      Modified := True;
    262262      Photo := Contact.Fields[FieldIndex];
    263       if (Photo <> '') and (PhotoProperty.Encoding <> '') then begin
     263      if (Photo <> '') and (PhotoProperty.Encoding <> veNone) then begin
    264264        Stream := TMemoryStream.Create;
    265265        try
     
    295295      if Url <> '' then begin
    296296        Contact.Fields[FieldIndex] := Url;
    297         PhotoProperty.Encoding := '';
     297        PhotoProperty.Encoding := veNone;
    298298      end else begin
    299         PhotoProperty.Encoding := VCardBase64;
     299        PhotoProperty.Encoding := veBase64;
    300300        Stream := TMemoryStream.Create;
    301301        try
Note: See TracChangeset for help on using the changeset viewer.