Changeset 119
- Timestamp:
- Feb 18, 2022, 2:53:31 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UContact.pas
r116 r119 115 115 end; 116 116 117 TPropertyEncoding = (veNone, veQuotedPrintable, veBase64, ve8bit); 118 117 119 { TContactProperty } 118 120 119 121 TContactProperty = class 120 122 private 123 function GetEncoding: TPropertyEncoding; 121 124 function GetValueItem(Index: Integer): string; 125 procedure SetEncoding(AValue: TPropertyEncoding); 122 126 procedure SetValueItem(Index: Integer; AValue: string); 123 127 public … … 125 129 Attributes: TStringList; 126 130 Value: string; 127 Encoding: string;128 131 Charset: string; 129 132 procedure EvaluateAttributes; … … 136 139 destructor Destroy; override; 137 140 property ValueItem[Index: Integer]: string read GetValueItem write SetValueItem; 141 property Encoding: TPropertyEncoding read GetEncoding write SetEncoding; 138 142 end; 139 143 … … 238 242 VCardEnd = 'END:VCARD'; 239 243 VCardBase64 = 'BASE64'; 244 VCardBase64Short = 'B'; 240 245 VCardQuotedPrintable = 'QUOTED-PRINTABLE'; 246 VCardQuotedPrintableShort = 'Q'; 247 VCardEncoding = 'ENCODING'; 248 VCardCharset = 'CHARSET'; 241 249 242 250 … … 887 895 { TContactProperty } 888 896 897 function TContactProperty.GetEncoding: TPropertyEncoding; 898 var 899 EncodingText: string; 900 begin 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; 909 end; 910 889 911 function TContactProperty.GetValueItem(Index: Integer): string; 890 912 var … … 905 927 end; 906 928 929 procedure TContactProperty.SetEncoding(AValue: TPropertyEncoding); 930 begin 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; 946 end; 947 907 948 procedure TContactProperty.SetValueItem(Index: Integer; AValue: string); 908 949 var … … 936 977 I: Integer; 937 978 begin 938 if Attributes.IndexOf(VCardBase64) <> -1 then begin 939 Encoding := VCardBase64; 979 if Encoding <> veNone then 940 980 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] 954 984 else Charset := ''; 955 985 … … 965 995 function TContactProperty.GetDecodedValue: string; 966 996 begin 967 if Encoding = VCardBase64 then begin997 if Encoding = veBase64 then begin 968 998 Result := DecodeStringBase64(Value); 969 999 end else 970 if Encoding = VCardQuotedPrintable then begin1000 if Encoding = veQuotedPrintable then begin 971 1001 Result := DecodeQuotedPrintable(Value, True); 972 1002 end … … 976 1006 function TContactProperty.GetEncodedValue: string; 977 1007 begin 978 if Encoding = VCardBase64 then begin1008 if Encoding = veBase64 then begin 979 1009 Result := EncodeStringBase64(Value); 980 1010 end else 981 if Encoding = VCardQuotedPrintable then begin1011 if Encoding = veQuotedPrintable then begin 982 1012 Result := EncodeQuotedPrintable(Value, True); 983 1013 end … … 1014 1044 Attributes.Assign(Source.Attributes); 1015 1045 Value := Source.Value; 1016 Encoding := Source.Encoding;1017 1046 Charset := Source.Charset; 1018 1047 end; … … 1557 1586 if Attributes.Count > 0 then 1558 1587 NameText := NameText + ';' + Attributes.DelimitedText; 1559 if Encoding <> ''then begin1588 if Encoding <> veNone then begin 1560 1589 Value2 := GetEncodedValue; 1561 NameText := NameText + ';ENCODING=' + Encoding;1562 1590 end else Value2 := Value; 1563 1591 if Pos(LineEnding, Value2) > 0 then begin … … 1575 1603 if UTF8Length(OutText) > ContactsFile.MaxLineLength then begin 1576 1604 CutLength := ContactsFile.MaxLineLength; 1577 if Encoding = VCardQuotedPrintable then begin1605 if Encoding = veQuotedPrintable then begin 1578 1606 Dec(CutLength); // There will be softline break at the end 1579 1607 // Do not cut encoded items at the end of line … … 1586 1614 CutText := UTF8Copy(OutText, 1, CutLength); 1587 1615 System.Delete(OutText, 1, Length(CutText)); 1588 if Encoding = VCardQuotedPrintable then1616 if Encoding = veQuotedPrintable then 1589 1617 CutText := CutText + QuotedPrintableEscapeCharacter; // Add soft line break 1590 1618 Add(LinePrefix + CutText); 1591 if Encoding <> VCardQuotedPrintable then1619 if Encoding <> veQuotedPrintable then 1592 1620 LinePrefix := ' '; 1593 1621 Inc(LineIndex); -
trunk/UContactImage.pas
r112 r119 261 261 Modified := True; 262 262 Photo := Contact.Fields[FieldIndex]; 263 if (Photo <> '') and (PhotoProperty.Encoding <> '') then begin263 if (Photo <> '') and (PhotoProperty.Encoding <> veNone) then begin 264 264 Stream := TMemoryStream.Create; 265 265 try … … 295 295 if Url <> '' then begin 296 296 Contact.Fields[FieldIndex] := Url; 297 PhotoProperty.Encoding := '';297 PhotoProperty.Encoding := veNone; 298 298 end else begin 299 PhotoProperty.Encoding := VCardBase64;299 PhotoProperty.Encoding := veBase64; 300 300 Stream := TMemoryStream.Create; 301 301 try
Note:
See TracChangeset
for help on using the changeset viewer.