Changeset 12 for trunk/UContact.pas
- Timestamp:
- Feb 4, 2018, 1:11:07 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UContact.pas
r9 r12 6 6 7 7 uses 8 Classes, SysUtils, Contnrs, Dialogs, UDataFile ;8 Classes, SysUtils, Contnrs, Dialogs, UDataFile, LazUTF8, base64; 9 9 10 10 type … … 207 207 Output: TStringList; 208 208 I: Integer; 209 PhotoBase64: string; 210 Line: string; 211 212 function IsAsciiString(Text: string): Boolean; 213 var 214 I: Integer; 215 begin 216 Result := True; 217 for I := 1 to Length(Text) do 218 if Ord(Text[I]) > 128 then begin 219 Result := False; 220 Break; 221 end; 222 end; 223 224 function NewItem(Key, Value: string): string; 225 var 226 Charset: string; 227 begin 228 if not IsAsciiString(Value) then Charset := ';CHARSET=UTF-8' 229 else Charset := ''; 230 Result := Key + Charset + ':' + Value; 231 end; 232 209 233 begin 210 234 inherited; … … 215 239 Add('BEGIN:VCARD'); 216 240 if Version <> '' then Add('VERSION:' + Version); 241 if XTimesContacted <> '' then Add('X-TIMES_CONTACTED:' + XTimesContacted); 242 if XLastTimeContacted <> '' then Add('X-LAST_TIME_CONTACTED:' + XLastTimeContacted); 217 243 if (LastName <> '') or (FirstName <> '') or (MiddleName <> '') or (TitleBefore <> '') or (TitleAfter <> '') then 218 Add('N:' + LastName + ';' + FirstName + ';' + MiddleName + ';' + TitleBefore + ';' + TitleAfter); 219 if FullName <> '' then Add('FN:' + FullName); 244 Add(NewItem('N', LastName + ';' + FirstName + ';' + MiddleName + ';' + TitleBefore + ';' + TitleAfter)); 245 if FullName <> '' then Add(NewItem('FN', FullName)); 246 if TelCell <> '' then Add('TEL;CELL:' + TelCell); 220 247 if TelPrefCell <> '' then Add('TEL;PREF;CELL:' + TelPrefCell); 221 if TelCell <> '' then Add('TEL;CELL:' + TelCell);222 248 if TelHome <> '' then Add('TEL;HOME:' + TelHome); 223 249 if TelHome2 <> '' then Add('TEL;HOME2:' + TelHome2); … … 228 254 if TelHomeVoice <> '' then Add('TEL;HOME;VOICE:' + TelHomeVoice); 229 255 if TelWorkVoice <> '' then Add('TEL;WORK;VOICE:' + TelWorkVoice); 230 if NickName <> '' then Add('X-NICKNAME:' + NickName);231 if XJabber <> '' then Add('X-JABBER:' + XJabber);232 256 if Note <> '' then Add('NOTE:' + Note); 233 257 if AdrHome <> '' then Add('ADR;HOME:' + AdrHome); 234 258 if EmailHome <> '' then Add('EMAIL;HOME:' + EmailHome); 259 if NickName <> '' then Add('X-NICKNAME:' + NickName); 235 260 if EmailInternet <> '' then Add('EMAIL;INTERNET:' + EmailInternet); 261 if XJabber <> '' then Add('X-JABBER:' + XJabber); 236 262 if Role <> '' then Add('TITLE:' + Role); 237 263 if Categories <> '' then Add('CATEGORIES:' + Categories); 238 264 if Organization <> '' then Add('ORG:' + Organization); 239 if XTimesContacted <> '' then Add('X-TIMES_CONTACTED:' + XTimesContacted);240 if XLastTimeContacted <> '' then Add('X-LAST_TIME_CONTACTED:' + XLastTimeContacted);241 265 if (HomeAddressCity <> '') or (HomeAddressStreet <> '') or 242 266 (HomeAddressCountry <> '') then Add('ADR;HOME:;;' + HomeAddressStreet + ';' + HomeAddressCity + ';;;' + HomeAddressCountry); 243 if Photo <> '' then Add('PHOTO;ENCODING=BASE64;JPEG:' + Photo); 267 if Photo <> '' then begin 268 PhotoBase64 := EncodeStringBase64(Photo); 269 270 Line := Copy(PhotoBase64, 1, 73 - Length('PHOTO;ENCODING=BASE64;JPEG:')); 271 System.Delete(PhotoBase64, 1, Length(Line)); 272 Add('PHOTO;ENCODING=BASE64;JPEG:' + Line); 273 while PhotoBase64 <> '' do begin 274 Line := Copy(PhotoBase64, 1, 73); 275 System.Delete(PhotoBase64, 1, Length(Line)); 276 Add(' ' + Line); 277 end; 278 Add(''); 279 end; 244 280 Add('END:VCARD'); 245 281 end; … … 315 351 else if Command = 'X-NICKNAME' then NewRecord.NickName := Line 316 352 else if Command = 'EMAIL;HOME' then NewRecord.EmailHome := Line 317 else if Command = 'EMAIL :INTERNET' then NewRecord.EmailInternet := Line353 else if Command = 'EMAIL;INTERNET' then NewRecord.EmailInternet := Line 318 354 else if Command = 'NOTE' then NewRecord.Note := Line 319 355 else if Command = 'ORG' then NewRecord.Organization := Line … … 322 358 else if Command = 'X-TIMES_CONTACTED' then NewRecord.XTimesContacted := Line 323 359 else if Command = 'X-LAST_TIME_CONTACTED' then NewRecord.XLastTimeContacted := Line 324 else if Command = 'PHOTO ' then begin325 NewRecord.Photo := Line;360 else if Command = 'PHOTO;JPEG' then begin 361 NewRecord.Photo := Trim(Line); 326 362 repeat 327 363 Inc(I); 328 Line := Lines[I]; 329 if Copy(Line, 1, 1) = ' ' then NewRecord.Photo := NewRecord.Photo + Line; 330 until Copy(Line, 1, 1) = ''; 364 Line := Trim(Lines[I]); 365 if Line <> '' then NewRecord.Photo := NewRecord.Photo + Line; 366 until Line = ''; 367 NewRecord.Photo := DecodeStringBase64(NewRecord.Photo); 331 368 end 332 369 else if Assigned(FOnError) then FOnError('Unknown command: ' + Command);
Note:
See TracChangeset
for help on using the changeset viewer.