Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
8610fd7697c2d4764e93257c049626ee74b1bffe
[xestiaab/.git] / source / vcard / vcard34conv-v3conv.cpp
1 #include "vcard34conv.h"
2 #include "vcard.h"
3 #include "../version.h"
4 #include "../common/textprocessing.h"
6 #include <wx/ffile.h>
7 #include <wx/tokenzr.h>
8 #include <wx/datetime.h>
9 #include <wx/wx.h>
11 bool vCard34Conv::ConvertToV3(wxString Filename, wxString *wxSData){
13         wxString V3Data;
14         wxString V4Data;
15         
16         // Load the contact into the contact editor.
17         
18         wxFFile ContactFile;
19         wxString wxSContactString;
20         wxString ContactLine;
21         vCard ContactData;
23         vCard ContactDatav3;
24         
25         //wxSContactFilename = Filename;
26         
27         // Check if we are using wxWidgets version 2.8 or less and
28         // execute the required command accordingly.
29         
30 #if wxABI_VERSION < 20900
31         ContactFile.Open(Filename.c_str(), wxT("r"));
32 #else
33         ContactFile.Open(Filename, wxT("r"));
34 #endif  
35         
36         if (ContactFile.IsOpened() == FALSE){
38                 return FALSE;
39         
40         }
41         
42         ContactFile.ReadAll(&wxSContactString, wxConvAuto());
43         
44         // Split the lines.
45         
46         std::map<int, wxString> ContactFileLines;
47         std::map<int, wxString>::iterator striter;
48         
49         wxStringTokenizer wSTContactFileLines(wxSContactString, wxT("\r\n"));
51         int ContactLineSeek = 0;
53         while (wSTContactFileLines.HasMoreTokens() == TRUE){
55                 ContactLine = wSTContactFileLines.GetNextToken();
56                 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
57                 ContactLineSeek++;              
58         
59         }
61         // Get the line.
63         bool QuoteMode = FALSE;
64         bool PropertyFind = TRUE;
65         bool HasExtraNicknames = FALSE;
66         bool IgnoreGender = FALSE;
67         bool ExtraLineSeek = TRUE;
68         bool BirthdayProcessed = FALSE;
69         bool AnniversaryProcessed = FALSE;
70         bool FNProcessed = FALSE;
71         bool GenderProcessed = FALSE;
72         bool NameProcessed = FALSE;
73         bool KindProcessed = FALSE;
74         bool FNFirst = FALSE;
75         bool NicknameFirst = FALSE;
76         bool TitleFirst = FALSE;
77         bool OrganisationFirst = FALSE;
78         bool NoteFirst = FALSE;
79         bool PhotoFirst = FALSE;
80         bool LogoFirst = FALSE;
81         int intExtraNickname = 0;
82         wxString wxSProperty;
83         wxString wxSPropertySeg1;
84         wxString wxSPropertySeg2;
85         wxString wxSPropertyNextLine;
86         size_t ContactLineLen = 0;
87         int QuoteBreakPoint = 0;
88         int FNCount = 0;
89         int NameCount = 0;
90         int NicknameCount = 0;
91         int ADRCount = 0;
92         int EmailCount = 0;
93         int IMPPCount = 0;
94         int TelCount = 0;
95         int LangCount = 0;
96         int TZCount = 0;
97         int GeoCount = 0;
98         int URLCount = 0;
99         int RelatedCount = 0;
100         int TitleCount = 0;
101         int RoleCount = 0;
102         int OrgCount = 0;
103         int NoteCount = 0;
104         int CategoryCount = 0;
105         int PhotoCount = 0;
106         int LogoCount = 0;
107         int SoundCount = 0;
108         int CalAdrCount = 0;
109         int CalReqAdrCount = 0;
110         int FreeBusyCount = 0;
111         int KeyCount = 0;
112         int VendorCount = 0;
113         int XTokenCount = 0;
114         int ItemSeek = 1;
115         //int intValueSeek = 1;
116         
117         wxString strVer;
118     
119     // Setup the version string.
120         
121         strVer.Append(wxT("-//Xestia//Address Book Version "));
122         strVer.Append(wxT(XSDAB_VERSION));
123         strVer.Append(wxT("//KW"));
124         
125         ContactDatav3.AddRaw(wxT("BEGIN"), wxT("VCARD"));
126         ContactDatav3.AddRaw(wxT("VERSION"), wxT("3.0"));
127         ContactDatav3.AddRaw(wxT("PRODID"), strVer);
129         for (std::map<int,wxString>::iterator iter = ContactFileLines.begin(); 
130          iter != ContactFileLines.end(); ++iter){
131         
132                 // Find the colon which splits the start bit from the data part.
133                 
134                 ContactLine = iter->second;
135                 
136                 while (ExtraLineSeek == TRUE){
137                 
138                         // Check if there is extra data on the next line 
139                         // (indicated by space or tab at the start) and add data.
140                 
141                         iter++;
142                         
143                         if (iter == ContactFileLines.end()){
144                         
145                                 iter--;
146                                 break;
147                         
148                         }                       
149                 
150                         wxSPropertyNextLine = iter->second;
151                         
152                 
153                         if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
154                 
155                                 wxSPropertyNextLine.Remove(0, 1);
156                                 //wxSPropertyNextLine.Trim(FALSE);
157                                 //ContactLine.Trim();
158                                 ContactLine.Append(wxSPropertyNextLine);
159                 
160                         } else {
161                         
162                                 iter--;
163                                 ExtraLineSeek = FALSE;
164                         
165                         }
166                 
167                 }
169                 ContactLineLen = ContactLine.Len();
170                 
171                 // Make sure we are not in quotation mode.
172                 // Make sure colon does not have \ or \\ before it.
173                 
174                 wxSProperty.Clear();
175                 
176                 for (int i = 0; i <= ContactLineLen; i++){
177                 
178                         if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
179                         
180                                 PropertyFind = FALSE;
181                         
182                         } else if (PropertyFind == TRUE){
183                         
184                                 wxSProperty.Append(ContactLine.Mid(i, 1));
185                         
186                         }               
187                 
188                         if (ContactLine.Mid(i, 1) == wxT("\"")){
189                         
190                                 if (QuoteMode == TRUE){
191                                 
192                                         QuoteMode = FALSE;
193                                 
194                                 } else {
195                         
196                                         QuoteMode = TRUE;
197                                         
198                                 }
199                         
200                         }
201                         
202                         if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
203                         
204                                 QuoteBreakPoint = i;
205                                 break;
206                         
207                         }
208                 
209                 }
210                 
211                 // Split that line at the point into two variables (ignore the colon).
212                 
213                 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
214                 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
215                 
216                 // Add the data into the contact editor depending on what it is.
217                 
218                 if (wxSProperty == wxT("FN")){
219                         
220                         std::map<int, int> SplitPoints;
221                         std::map<int, int> SplitLength;
222                         std::map<int, int>::iterator SLiter;                    
223                         wxString PropertyData;
224                         wxString PropertyName;
225                         wxString PropertyValue;
226                         wxString PropertyTokens;
227                         int intPrevValue = 4;
229                         //SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
230                         
231                         intPrevValue = 3;
232                         
233                         if (FNFirst == FALSE){
235                                 ContactDatav3.AddRaw(wxT("FN"), wxSPropertySeg2);
236                                 
237                                 if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
238         
239                                 } else {
240                                 
241                                         ContactDatav3.AddRaw(wxT("X-VCARD4-FN;X-FIRST=TRUE;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
242                                                                 
243                                 }
244                                 FNFirst = TRUE;
245                         
246                         } else {
247                         
248                                 if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
250                                         ContactDatav3.AddRaw(wxT("X-VCARD4-FN"), wxSPropertySeg2);
251         
252                                 } else {
253                                 
254                                         ContactDatav3.AddRaw(wxT("X-VCARD4-FN;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))),
255                                                 wxSPropertySeg2);
256                                 
257                                 }
258                         
259                         }       
260                 
261                 } else if (wxSProperty == wxT("N") && NameProcessed == FALSE){
262                 
263                         std::map<int, int> SplitPoints;
264                         std::map<int, int> SplitLength;
265                         std::map<int, int>::iterator SLiter;                    
266                         wxString PropertyData;
267                         wxString PropertyName;
268                         wxString PropertyValue;
269                         wxString PropertyTokens;
270                         int intPrevValue = 3;
272                         intPrevValue = 2;
274                         ContactDatav3.AddRaw(wxT("N"), wxSPropertySeg2);
275                         
276                         if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
280                         } else {
281                         
282                                 ContactDatav3.AddRaw(wxT("X-VCARD4-N;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxT(""));
283                         
284                         }
285                         
286                         NameProcessed = TRUE;
287                 
288                 } else if (wxSProperty == wxT("KIND") && KindProcessed == FALSE){
289                 
290                         // Process Data.
291                 
292                         std::map<int, int> SplitPoints;
293                         std::map<int, int> SplitLength;
294                         std::map<int, int>::iterator SLiter;                    
295                         wxString PropertyData;
296                         wxString PropertyName;
297                         wxString PropertyValue;
298                         wxString PropertyTokens;
299                         int intPrevValue = 5;
301                         intPrevValue = 4;
302                 
303                         ContactDatav3.AddRaw(wxT("X-ADDRESSBOOKSERVER-KIND"), wxSPropertySeg2);
304                 
305                         KindProcessed = TRUE;
306                 
307                 } else if (wxSProperty == wxT("MEMBER")){
308                 
309                         // Process Data.
310                         
311                         std::map<int, int> SplitPoints;
312                         std::map<int, int> SplitLength;
313                         std::map<int, int>::iterator SLiter;                    
314                         wxString PropertyData;
315                         wxString PropertyName;
316                         wxString PropertyValue;
317                         wxString PropertyTokens;
318                         int intPrevValue = 7;
320                         intPrevValue = 6;
322                         ContactDatav3.AddRaw(wxT("X-ADDRESSBOOKSERVER-MEMBER"), wxSPropertySeg2);
323                 
324                 } else if (wxSProperty == wxT("NICKNAME")){
325                         
326                         std::map<int, int> SplitPoints;
327                         std::map<int, int> SplitLength;
328                         std::map<int, int>::iterator SLiter;                    
329                         wxString PropertyData;
330                         wxString PropertyName;
331                         wxString PropertyValue;
332                         wxString PropertyTokens;
333                         int intPrevValue = 10;
335                         intPrevValue = 9;
336                         
337                         if (NicknameFirst == FALSE){
339                                 ContactDatav3.AddRaw(wxT("NICKNAME"), wxSPropertySeg2);
340                                 
341                                 if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
342         
343                                 } else {
344                                 
345                                         ContactDatav3.AddRaw(wxT("X-VCARD4-NICKNAME;X-FIRST=TRUE;") 
346                                                 + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxT(""));
347                                 
348                                 }
349                                 NicknameFirst = TRUE;
350                                 ItemSeek++;
351                         
352                         } else {
353                         
354                                 if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
356                                         ContactDatav3.AddRaw(wxT("X-VCARD4-NICKNAME"), wxSPropertySeg2);
358                                 } else {
359                                 
360                                         ContactDatav3.AddRaw(wxT("X-VCARD4-NICKNAME;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))) + wxT(":"), 
361                                                 wxSPropertySeg2);
362                                                                 
363                                 }
364                         
365                         }
366                         
368                 } else if (wxSProperty == wxT("GENDER") && GenderProcessed == FALSE){
369                 
370                         // Do PID/ALTID/LANG things.
371                         
372                         std::map<int, int> SplitPoints;
373                         std::map<int, int> SplitLength;
374                         std::map<int, int>::iterator SLiter;                    
375                         wxString PropertyData;
376                         wxString PropertyName;
377                         wxString PropertyValue;
378                         wxString PropertyTokens;
379                         int intPrevValue = 8;
381                         
382                         intPrevValue = 7;
383                         
384                         if (wxSPropertySeg2.Mid(1, 1) == wxT(";")){
385                         
386                                 if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
388                                         ContactDatav3.AddRaw(wxT("X-VCARD4-GENDER;X-GENDERTEXT=\"") + wxSPropertySeg2.Mid(2) + wxT("\""), wxSPropertySeg2.Mid(0, 1));
389         
390                                 } else {
391                                 
392                                         ContactDatav3.AddRaw(wxT("X-VCARD4-GENDER;X-GENDERTEXT=\"") + wxSPropertySeg2.Mid(2) + wxT("\";") 
393                                                 + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), 
394                                                 wxSPropertySeg2.Mid(0, 1));                             
395                                                                 
396                                 }
397                         
398                         } else {
400                                 if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
402                                         ContactDatav3.AddRaw(wxT("X-VCARD4-GENDER"), wxSPropertySeg2);
403         
404                                 } else {
405                                         
406                                         ContactDatav3.AddRaw(wxT("X-VCARD4-GENDER;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
407                                                                 
408                                 }
409                         
410                         }
411                         
412                         GenderProcessed = TRUE;
413                 
414                 } else if (wxSProperty == wxT("BDAY") && BirthdayProcessed == FALSE){
416                         // Process date. Preserve the remainder in the string.
417                                 
418                         std::map<int, int> SplitPoints;
419                         std::map<int, int> SplitLength;
420                         std::map<int, int>::iterator SLiter;                    
421                         wxString PropertyData;
422                         wxString PropertyName;
423                         wxString PropertyValue;
424                         wxString PropertyTokens;
425                         bool NoYear = FALSE;
426                         int intPrevValue = 6;
428                         wxString strResults;            
429                 
430                         intPrevValue = 5;
431                 
432                         // Look for type before continuing.
434                         if (wxSPropertySeg2.Mid(0, 2) == wxT("--")){
435                         
436                                 strResults.Append(wxT("1604-"));
437                                 NoYear = TRUE;
439                                 strResults.Append(wxSPropertySeg2.Mid(2, 2) + wxT("-"));
440                                 strResults.Append(wxSPropertySeg2.Mid(4, 2));
441                         
442                         } else {
443                         
444                                 strResults.Append(wxSPropertySeg2.Mid(0, 4) + wxT("-"));
445                                 strResults.Append(wxSPropertySeg2.Mid(4, 2) + wxT("-"));
446                                 strResults.Append(wxSPropertySeg2.Mid(6, 2));
448                         }
449                         
451                         
452                         if (NoYear == TRUE){
454                                 ContactDatav3.AddRaw(wxT("BDAY;X-APPLE-OMIT-YEAR=1604"), strResults);
455                         
456                                 if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
458                                         ContactDatav3.AddRaw(wxT("X-VCARD4-BDAY"), wxSPropertySeg2);
459         
460                                 } else {
461                                         
462                                         ContactDatav3.AddRaw(wxT("X-VCARD4-BDAY;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
463                                 
464                                 }
465                         
466                         } else {
467                         
468                                 ContactDatav3.AddRaw(wxT("BDAY"), strResults);
470                                 if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
472                                         ContactDatav3.AddRaw(wxT("X-VCARD4-BDAY"), wxSPropertySeg2);
474                                 } else {
475                                         
476                                         ContactDatav3.AddRaw(wxT("X-VCARD4-BDAY;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
477                                                                 
478                                 }
479                         
480                         }
481                         
482                         BirthdayProcessed = TRUE;
483                 
484                 } else if (wxSProperty == wxT("ANNIVERSARY") && AnniversaryProcessed == FALSE){
485                         
486                         // Process date. Preserve the remainder in the string.
487                                 
488                         std::map<int, int> SplitPoints;
489                         std::map<int, int> SplitLength;
490                         std::map<int, int>::iterator SLiter;                    
491                         wxString PropertyData;
492                         wxString PropertyName;
493                         wxString PropertyValue;
494                         wxString PropertyTokens;
495                         int intPrevValue = 13;
497                         wxString strResults;
498                         bool NoYear = FALSE;
499                 
500                         intPrevValue = 12;
501                 
502                         // Look for type before continuing.
503                 
504                         if (wxSPropertySeg2.Mid(0, 2) == wxT("--")){
505                         
506                                 strResults.Append(wxT("1604-"));
507                                 NoYear = TRUE;
509                                 strResults.Append(wxSPropertySeg2.Mid(2, 2) + wxT("-"));
510                                 strResults.Append(wxSPropertySeg2.Mid(4, 2));
511                         
512                         } else {
513                         
514                                 strResults.Append(wxSPropertySeg2.Mid(0, 4) + wxT("-"));
515                                 strResults.Append(wxSPropertySeg2.Mid(4, 2) + wxT("-"));
516                                 strResults.Append(wxSPropertySeg2.Mid(6, 2));
518                         }
519                         
520                         if (NoYear == TRUE){
522                                 ContactDatav3.AddRaw(wxT("ANNIVERSARY;X-APPLE-OMIT-YEAR=1604"), strResults);
523                         
524                                 if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
526                                         ContactDatav3.AddRaw(wxT("X-VCARD4-ANNIVERSARY"), wxSPropertySeg2);
528                                 } else {
529                                         
530                                         ContactDatav3.AddRaw(wxT("X-VCARD4-ANNIVERSARY;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
531                                                                 
532                                 }
533                         
534                         } else {
535                         
536                                 ContactDatav3.AddRaw(wxT("ANNIVERSARY"), strResults);
538                                 if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
540                                         ContactDatav3.AddRaw(wxT("X-VCARD4-ANNIVERSARY"), wxSPropertySeg2);
541         
542                                 } else {
543                                         
544                                         ContactDatav3.AddRaw(wxT("X-VCARD4-ANNIVERSARY;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
545                                 
546                                 }
547                         
548                         }
549                         
550                         AnniversaryProcessed = TRUE;
551                 
552                 } else if (wxSProperty == wxT("TZ")){
553                 
554                         std::map<int, int> SplitPoints;
555                         std::map<int, int> SplitLength;
556                         std::map<int, int>::iterator SLiter;                    
557                         wxString PropertyData;
558                         wxString PropertyName;
559                         wxString PropertyValue;
560                         wxString PropertyTokens;
561                         int intPrevValue = 4;
562                         
563                         intPrevValue = 3;
564                         
565                         // Look for type before continuing.
566                         
567                         if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
569                                 ContactDatav3.AddRaw(wxT("X-VCARD4-TZ"), wxSPropertySeg2);
570         
571                         } else {
572                                         
573                                 ContactDatav3.AddRaw(wxT("X-VCARD4-TZ;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
574                                 
575                         }
576                 
577                 } else if (wxSProperty == wxT("ADR")){
578                         
579                         std::map<int, int> SplitPoints;
580                         std::map<int, int> SplitLength;
581                         std::map<int, int>::iterator SLiter;                    
582                         wxString PropertyData;
583                         wxString PropertyName;
584                         wxString PropertyValue;
585                         wxString PropertyTokens;
586                         wxString AddressLabel;
587                         wxString AddressLang;
588                         wxString AddressAltID;
589                         wxString AddressPID;
590                         wxString AddressTokens;
591                         wxString AddressGeo;
592                         wxString AddressTimezone;
593                         wxString AddressType;
594                         wxString AddressMediatype;
595                         wxString AddressPOBox;
596                         wxString AddressExtended;
597                         wxString AddressStreet;
598                         wxString AddressLocality;
599                         wxString AddressCity;
600                         wxString AddressRegion;
601                         wxString AddressPostalCode;
602                         wxString AddressCountry;
603                         int intPrevValue = 5;
604                         
605                         intPrevValue = 4;
606                         
607                         // TODO: Check in value for X-ABLabel and use it if it is there.
608                     
609                         if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
611                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".ADR"), wxSPropertySeg2);
612                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-ABLabel"), _("Address"));
613                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-VCARD4-ADR"), wxSPropertySeg2);
614         
615                         } else {
617                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".ADR"), wxSPropertySeg2);
618                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-ABLabel"), _("Address"));
619                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-VCARD4-ADR;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
620                                                                 
621                         }
622                         
623                         ItemSeek++;
624                 
625                 } else if (wxSProperty == wxT("EMAIL")){
626                 
627                         // TODO: Continue from here! See ADR for good example (Replace initer with intPrevValue).
628                         // Remove inserted comma for Extra Tokens in frmContactEditor.cpp
630                         std::map<int, int> SplitPoints;
631                         std::map<int, int> SplitLength;
632                         std::map<int, int>::iterator SLiter;
633                         std::map<int, int>::iterator SPoint;
634                         wxString PropertyData;
635                         wxString PropertyName;
636                         wxString PropertyValue;
637                         wxString PropertyTokens;
638                         wxString AddressLabel;
639                         wxString AddressLang;
640                         wxString AddressAltID;
641                         wxString AddressPID;
642                         wxString AddressTokens;
643                         wxString AddressGeo;
644                         wxString AddressTimezone;
645                         wxString AddressType;
646                         wxString AddressMediatype;
647                         wxString AddressPOBox;
648                         wxString AddressExtended;
649                         wxString AddressStreet;
650                         wxString AddressLocality;
651                         wxString AddressCity;
652                         wxString AddressRegion;
653                         wxString AddressPostalCode;
654                         wxString AddressCountry;
655                         int intPrevValue = 7;
656                         
657                         intPrevValue = 6;
658                         
659                     // TODO: Check in value for X-ABLabel and use it if it is there.
660                     
661                     if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
662                         
663                         ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".EMAIL"), wxSPropertySeg2);
664                         ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-ABLabel"), _("E-mail Address"));
665                         ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-VCARD4-EMAIL"), wxSPropertySeg2);
666                                                 
667                     } else {
668                         
669                         ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".EMAIL"), wxSPropertySeg2);
670                         ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-ABLabel"), _("E-mail Address"));
671                         ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-VCARD4-EMAIL;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
672                         
673                     }
674                     
675                     ItemSeek++;
676                 
677                 } else if (wxSProperty == wxT("IMPP")){
679                         std::map<int, int> SplitPoints;
680                         std::map<int, int> SplitLength;
681                         std::map<int, int>::iterator SLiter;
682                         std::map<int, int>::iterator SPoint;
683                         wxString PropertyData;
684                         wxString PropertyName;
685                         wxString PropertyValue;
686                         wxString PropertyTokens;
687                         wxString IMPPType;
688                         wxString IMPPAddress;
689                         int intPrevValue = 6;
690                         
691                         SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
692                         
693                         intPrevValue = 5;
694                         
695                         // TODO: Check in value for X-ABLabel and use it if it is there.
696                     
697                         if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
699                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".IMPP"), wxSPropertySeg2);
700                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-ABLabel"), _("Instant Message"));
701                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-VCARD4-IMPP"), wxSPropertySeg2);
702         
703                         } else {
705                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".IMPP"), wxSPropertySeg2);
706                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-ABLabel"), _("Instant Message"));
707                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-VCARD4-IMPP;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
708                                                                 
709                         }
710                     
711             ItemSeek++;
712                 
713                 } else if (wxSProperty == wxT("TEL")){
714                 
715                         // Check TEL and make sure it is functioning properly.
716                 
717                         std::map<int, int> SplitPoints;
718                         std::map<int, int> SplitLength;
719                         std::map<int, int> TypeSplitPoints;
720                         std::map<int, int> TypeSplitLength;
721                         std::map<int, int>::iterator SLiter;
722                         std::map<int, int>::iterator SPoint;                    
723                         std::map<int, int>::iterator TSLiter;
724                         std::map<int, int>::iterator TSPoint;
725                         wxString PropertyData;
726                         wxString PropertyName;
727                         wxString PropertyValue;
728                         wxString PropertyTokens;
729                         wxString TelType;
730                         wxString TelNumber;
731                         wxString TelTypeUI;
732                         wxString TelTypeDetail;
733                         wxString TelTypeOut;
734                         wxString FinalFriendlyString;
735                         int intSplitsFound = 0;
736                         int intSplitSize = 0;
737                         int intPrevValue = 5;
738                         int intType = 0;
739                         int intSplitPoint = 0;
741                         intPrevValue = 4;
742                         
743                         SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
744                         
745                         // Look for type before continuing.
746                         
747                         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
748                         intiter != SplitPoints.end(); ++intiter){
749                         
750                                 SLiter = SplitLength.find(intiter->first);
751                         
752                                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
753                                 
754                                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
755                                 PropertyName = PropertyElement.GetNextToken();                          
756                                 PropertyValue = PropertyElement.GetNextToken();
757                                 
758                                 intPrevValue = intiter->second;
759                                 
760                                 if (PropertyName == wxT("TYPE")){
761                                 
762                                         // Process each value in type and translate each
763                                         // part.
764                                 
765                                         // Strip out the quotes if they are there.
767                                         size_t intPropertyValueLen = PropertyValue.Len();
768                                 
769                                         if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
770                                         
771                                                 PropertyValue.Trim();
772                                                 PropertyValue.RemoveLast();
773                                         
774                                         }                               
775                                 
776                                         if (PropertyValue.Mid(0, 1) == wxT("\"")){
777                                         
778                                                 PropertyValue.Remove(0, 1);
779                                         
780                                         }
781                                         
782                                         TelTypeDetail = PropertyValue;
783                                         
784                                         intSplitSize = 0;
785                                         intSplitsFound = 0;
786                                         intSplitPoint = 0;
787                                         
788                                         for (int i = 0; i <= intPropertyValueLen; i++){
789                         
790                                                 intSplitSize++;
791                         
792                                                 if (PropertyValue.Mid(i, 1) == wxT(",") && PropertyValue.Mid((i - 1), 1) != wxT("\\")){
793                         
794                                                         if (intSplitsFound == 0){
796                                                                 TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
797                                                                 TypeSplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
798                                         
799                                                         } else {
800                                         
801                                                                 TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
802                                                                 TypeSplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));
803                                         
804                                                         }                       
806                                                         intSplitsFound++;
807                                                         i++;
808                                                         intSplitPoint = i;
809                                                         intSplitSize = 0;
810                         
811                                                 }
812                         
813                                         }
814                                         
815                                         TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
816                                         TypeSplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));                                                           
817                                 
818                                         int intTypeSeek = 0;
819                                 
820                                         for (std::map<int, int>::iterator typeiter = TypeSplitPoints.begin(); 
821                                         typeiter != TypeSplitPoints.end(); ++typeiter){
823                                                 wxString TypePropertyName;
824                                                 
825                                                 TSLiter = TypeSplitLength.find(typeiter->first);
826                                                 
827                                                 TypePropertyName = PropertyValue.Mid(typeiter->second, TSLiter->second);
828                                                 
829                                                 if (intTypeSeek == 0){
830                                                 
831                                                 
832                                                 } else {
833                                                                                                 
834                                                         TelTypeUI.Append(wxT(","));                                                     
835                                                 
836                                                 }
837                                         
838                                                 if (TypePropertyName == wxT("home")){
839                                                 
840                                                         intType = 1;
841                                                 
842                                                 } else if (TypePropertyName == wxT("work")){
843                                                 
844                                                         intType = 2;
845                                                 
846                                                 }
847                                                 
848                                                 if (TypePropertyName == wxT("text")){                                           
850                                                         if (!FinalFriendlyString.IsEmpty()){ FinalFriendlyString.Append(_(", Text")); } else { FinalFriendlyString.Append(_("Text")); }
852                                                         TelTypeOut.Append(wxT(";"));                                            
853                                                         TelTypeOut.Append(wxT("type=TEXT"));
854                                                 
855                                                 } else if (TypePropertyName == wxT("voice")){
856                                                 
857                                                         if (!FinalFriendlyString.IsEmpty()){  FinalFriendlyString.Append(_(", Voice")); } else { FinalFriendlyString.Append(_("Voice")); }
859                                                         TelTypeOut.Append(wxT(";"));                                            
860                                                         TelTypeOut.Append(wxT("type=VOICE"));
862                                                         intTypeSeek++;
863                                                 
864                                                 } else if (TypePropertyName == wxT("fax")){
865                                                 
866                                                         if (!FinalFriendlyString.IsEmpty()){  FinalFriendlyString.Append(_(", Fax")); } else { FinalFriendlyString.Append(_("Fax")); }
867                                                 
868                                                         TelTypeOut.Append(wxT(";"));
869                                                         TelTypeOut.Append(wxT("type=FAX"));
870                                                         intTypeSeek++;
871                                                 
872                                                 } else if (TypePropertyName == wxT("cell")){
873                                                 
874                                                         if (!FinalFriendlyString.IsEmpty()){  FinalFriendlyString.Append(_(", Mobile")); } else { FinalFriendlyString.Append(_("Mobile")); }
875                                                 
876                                                         TelTypeOut.Append(wxT(";"));
877                                                         TelTypeOut.Append(wxT("type=CELL"));
878                                                         intTypeSeek++;
879                                                 
880                                                 } else if (TypePropertyName == wxT("video")){
881                                                 
882                                                         if (!FinalFriendlyString.IsEmpty()){  FinalFriendlyString.Append(_(", Video")); } else { FinalFriendlyString.Append(_("Video")); }
884                                                         TelTypeOut.Append(wxT(";"));
885                                                         TelTypeOut.Append(wxT("type=VIDEO"));
886                                                         intTypeSeek++;
887                                                 
888                                                 } else if (TypePropertyName == wxT("pager")){
889                                                 
890                                                         if (!FinalFriendlyString.IsEmpty()){  FinalFriendlyString.Append(_(", Pager")); } else { FinalFriendlyString.Append(_("Pager")); }
892                                                         TelTypeOut.Append(wxT(";"));
893                                                         TelTypeOut.Append(wxT("type=PAGER"));
894                                                         intTypeSeek++;
895                                                 
896                                                 } else if (TypePropertyName == wxT("textphone")){
897                                                 
898                                                         //if (!TelTypeOut.IsEmpty()){ TelTypeOut.Append(wxT(";")); }
899                                                 
900                                                         if (!FinalFriendlyString.IsEmpty()){  FinalFriendlyString.Append(_(", Textphone")); } else { FinalFriendlyString.Append(_("Textphone")); }
901                                                 
902                                                         TelTypeOut.Append(wxT(";"));
903                                                         TelTypeOut.Append(wxT("type=TEXTPHONE"));
904                                                         intTypeSeek++;
905                                                 
906                                                 }
907                                                 
908                                                 
909                                         
910                                         }
911                                 
912                                 }
913                                 
914                                 
915                         
916                         }
917                         
918                         wxString FinalTel;
919                         
920                         // Remove 'tel:' if it is being used.
921                         
922                         if (wxSPropertySeg2.Mid(0, 4) == wxT("tel:")){
923                         
924                                 FinalTel = wxSPropertySeg2.Mid(4);
925                         
926                         } else {
927                         
928                                 FinalTel = wxSPropertySeg2;
929                         
930                         }
931                         
932                         if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
933                         
934                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".TEL") + TelTypeOut, FinalTel);
935                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-ABLabel"), FinalFriendlyString);
936                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-VCARD4-TEL"), wxSPropertySeg2);
937         
938                         } else {
940                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".TEL") + TelTypeOut, FinalTel);
941                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-ABLabel"), FinalFriendlyString);
942                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-VCARD4-TEL;") + wxSPropertySeg1.Mid(4), wxSPropertySeg2);
943                                 
944                         }
945                         
946                         ItemSeek++;
947                 
948                 } else if (wxSProperty == wxT("LANG")){
950                         std::map<int, int> SplitPoints;
951                         std::map<int, int> SplitLength;
952                         std::map<int, int>::iterator SLiter;                    
953                         wxString PropertyData;
954                         wxString PropertyName;
955                         wxString PropertyValue;
956                         wxString PropertyTokens;
957                         int intPrevValue = 6;
958                         
959                         intPrevValue = 5;
960                         
961             if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
962                         
963                 ContactDatav3.AddRaw(wxT("X-VCARD4-LANG"), wxSPropertySeg2);
964                         
965             } else {
966                         
967                 ContactDatav3.AddRaw(wxT("X-VCARD4-LANG;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
968                         
969             }
970                 
971                 } else if (wxSProperty == wxT("GEO")){
972                 
973                         std::map<int, int> SplitPoints;
974                         std::map<int, int> SplitLength;
975                         std::map<int, int>::iterator SLiter;                    
976                         wxString PropertyData;
977                         wxString PropertyName;
978                         wxString PropertyValue;
979                         wxString PropertyTokens;
980                         wxString GeoType;
981                         wxString GeoData;
982                         int intPrevValue = 5;
983                         
984                         intPrevValue = 4;
985                         
986                         SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
987                         
988                         wxString strFinalGeoValue;
989                         wxString strFinalType;
990                         
991                         if (wxSPropertySeg2.Mid(0, 3) == wxT("geo")){
992                         
993                                 strFinalGeoValue = wxSPropertySeg2.Mid(5);
994                                 strFinalType = wxT("geo");
995                         
996                         } else {
997                         
998                                 wxStringTokenizer wSTSplit(wxSPropertySeg2, wxT(":")); 
999                                 strFinalType = wSTSplit.GetNextToken();
1000                                 strFinalGeoValue = wSTSplit.GetNextToken();
1001                         
1002                         }
1003                         
1004                     if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1005                         
1006                         ContactDatav3.AddRaw(wxT("X-VCARD4-GEO;X-GEOTYPE=") + strFinalType, wxSPropertySeg2);
1007                         
1008                     } else {
1009                         
1010                         ContactDatav3.AddRaw(wxT("X-VCARD4-GEO;X-GEOTYPE=") + strFinalType + wxT(";") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
1011                         
1012                     }
1013                 
1014                 } else if (wxSProperty == wxT("RELATED")){
1015                         
1016                         std::map<int, int> SplitPoints;
1017                         std::map<int, int> SplitLength;
1018                         std::map<int, int>::iterator SLiter;                    
1019                         wxString PropertyData;
1020                         wxString PropertyName;
1021                         wxString PropertyValue;
1022                         wxString PropertyTokens;
1023                         wxString RelatedType;
1024                         wxString RelatedTypeOriginal;                   
1025                         wxString RelatedName;
1026                         bool FirstToken = TRUE;
1027                         int intPrevValue = 9;
1028                         
1029                         intPrevValue = 8;
1030                         
1031                         SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1032                         
1033                         wxString strDetail;
1034                         
1035                         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1036                         intiter != SplitPoints.end(); ++intiter){
1037                         
1038                                 SLiter = SplitLength.find(intiter->first);
1039                         
1040                                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second - 1));
1041                                 
1042                                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1043                                 PropertyName = PropertyElement.GetNextToken();                          
1044                                 PropertyValue = PropertyElement.GetNextToken();
1045                                 
1046                                 if (PropertyName == wxT("TYPE") && FirstToken == TRUE){
1047                                 
1048                                         if (PropertyValue == wxT("contact")){
1049                 
1050                                                 strDetail = _("Contact");
1051                 
1052                                         } else if (PropertyValue == wxT("acquaintance")){
1053                 
1054                                                 strDetail = _("Acquaintance");
1055                 
1056                                         } else if (PropertyValue == wxT("friend")){
1057                 
1058                                                 strDetail = _("Friend");
1059                 
1060                                         } else if (PropertyValue == wxT("met")){
1061                 
1062                                                 strDetail = _("Met");
1063                 
1064                                         } else if (PropertyValue == wxT("co-worker")){
1065                 
1066                                                 strDetail = _("Co-worker");
1067                 
1068                                         } else if (PropertyValue == wxT("colleague")){
1069                 
1070                                                 strDetail = _("Colleague");
1071                 
1072                                         } else if (PropertyValue == wxT("co-resident")){
1073                 
1074                                                 strDetail = _("Co-resident");
1075                 
1076                                         } else if (PropertyValue == wxT("neighbor")){
1077                 
1078                                                 strDetail = _("Neighbour");
1079                 
1080                                         } else if (PropertyValue == wxT("child")){
1081                 
1082                                                 strDetail = _("Child");
1083                 
1084                                         } else if (PropertyValue == wxT("parent")){
1085                 
1086                                                 strDetail = _("Parent");
1087                 
1088                                         } else if (PropertyValue == wxT("sibling")){
1089                 
1090                                                 strDetail = _("Sibling");
1091                 
1092                                         } else if (PropertyValue == wxT("spouse")){
1093                 
1094                                                 strDetail = _("Spouse");
1095                 
1096                                         } else if (PropertyValue == wxT("kin")){
1097                 
1098                                                 strDetail = _("Kin");
1099                 
1100                                         } else if (PropertyValue == wxT("muse")){
1101                 
1102                                                 strDetail = _("Muse");
1103                 
1104                                         } else if (PropertyValue == wxT("crush")){
1105                 
1106                                                 strDetail = _("Crush");
1107                 
1108                                         } else if (PropertyValue == wxT("date")){
1109                 
1110                                                 strDetail = _("Date");
1111                 
1112                                         } else if (PropertyValue == wxT("sweetheart")){
1113                 
1114                                                 strDetail = _("Sweetheart");
1115                 
1116                                         } else if (PropertyValue == wxT("me")){
1117                 
1118                                                 strDetail = _("Me");
1119                 
1120                                         } else if (PropertyValue == wxT("agent")){
1121                 
1122                                                 strDetail = _("Agent");
1123                 
1124                                         } else if (PropertyValue == wxT("emergency")){
1125                 
1126                                                 strDetail = _("Emergency");
1127                 
1128                                         } else {
1129                 
1130                                                 strDetail = PropertyValue;
1131                 
1132                                         }
1133                                         
1134                                         FirstToken = FALSE;
1135                                 
1136                                 }
1137                                 
1138                         }
1139                         
1140                         if (strDetail.IsEmpty()){
1141                         
1142                                 strDetail = _("Relation");
1143                         
1144                         }
1145                         
1146                         if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1147                         
1148                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-ABRELATEDNAMES"), wxSPropertySeg2);
1149                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-ABLabel"), strDetail);
1150                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-VCARD4-RELATED"), wxSPropertySeg2);
1151         
1152                         } else {
1154                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-ABRELATEDNAMES"), wxSPropertySeg2);
1155                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-ABLabel"), strDetail);
1156                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-VCARD4-RELATED;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
1157                                                                 
1158                         }
1159                         
1160                         ItemSeek++;
1161                 
1162                 } else if (wxSProperty == wxT("URL")){
1164                         std::map<int, int> SplitPoints;
1165                         std::map<int, int> SplitLength;
1166                         std::map<int, int>::iterator SLiter;                    
1167                         wxString PropertyData;
1168                         wxString PropertyName;
1169                         wxString PropertyValue;
1170                         wxString PropertyTokens;
1171                         int intPrevValue = 5;
1172                         
1173                         intPrevValue = 4;
1174                         
1175                         // Todo: Check for X-ABLabel.
1176                         
1177                         if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1178                         
1179                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".URL"), wxSPropertySeg2);
1180                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-ABLabel"), _("URL"));
1181                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-VCARD4-URL"), wxSPropertySeg2);
1182         
1183                         } else {
1185                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".URL"), wxSPropertySeg2);
1186                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-ABLabel"), _("URL"));
1187                                 ContactDatav3.AddRaw(wxT("item") + wxString::Format(wxT("%i"), ItemSeek) + wxT(".X-VCARD4-URL;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
1188                                 
1189                         }
1190                         
1191                         ItemSeek++;
1192                 
1193                 } else if (wxSProperty == wxT("TITLE")) {
1195                         std::map<int, int> SplitPoints;
1196                         std::map<int, int> SplitLength;
1197                         std::map<int, int>::iterator SLiter;                    
1198                         wxString PropertyData;
1199                         wxString PropertyName;
1200                         wxString PropertyValue;
1201                         wxString PropertyTokens;
1202                         int intPrevValue = 7;
1203                         
1204                         intPrevValue = 6;
1205                         
1206                         // Look for type before continuing.
1207                         
1208                         if (TitleFirst == FALSE){
1210                                 ContactDatav3.AddRaw(wxT("TITLE"), wxSPropertySeg2);
1211                                 
1212                                 if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1213         
1214                                 } else {
1215                                 
1216                                         ContactDatav3.AddRaw(wxT("X-VCARD4-TITLE;X-FIRST=TRUE;") 
1217                                                 + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxT(""));
1218                                 
1219                                 }
1220                                 TitleFirst = TRUE;
1221                                 ItemSeek++;
1222                         
1223                         } else {
1224                         
1225                                 if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1227                                         ContactDatav3.AddRaw(wxT("X-VCARD4-TITLE"), wxSPropertySeg2);
1228         
1229                                 } else {
1230                                 
1231                                         ContactDatav3.AddRaw(wxT("X-VCARD4-TITLE;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))) + wxT(":"), 
1232                                                 wxSPropertySeg2);
1233                                 
1234                                 }
1235                         
1236                         }
1237                         
1238                 } else if (wxSProperty == wxT("ROLE")) {
1239                 
1240                         std::map<int, int> SplitPoints;
1241                         std::map<int, int> SplitLength;
1242                         std::map<int, int>::iterator SLiter;                    
1243                         wxString PropertyData;
1244                         wxString PropertyName;
1245                         wxString PropertyValue;
1246                         wxString PropertyTokens;
1247                         int intPrevValue = 6;
1248                         
1249                         intPrevValue = 5;
1250                         
1251                         if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1253                                 ContactDatav3.AddRaw(wxT("X-VCARD4-ROLE"), wxSPropertySeg2);
1255                         } else {
1256                                         
1257                                 ContactDatav3.AddRaw(wxT("X-VCARD4-ROLE;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
1258                                 
1259                         }
1260                         
1261                 } else if (wxSProperty == wxT("ORG")) {
1263                         std::map<int, int> SplitPoints;
1264                         std::map<int, int> SplitLength;
1265                         std::map<int, int>::iterator SLiter;                    
1266                         wxString PropertyData;
1267                         wxString PropertyName;
1268                         wxString PropertyValue;
1269                         wxString PropertyTokens;
1270                         int intPrevValue = 5;
1271                         
1272                         intPrevValue = 4;
1273                         
1274                         if (OrganisationFirst == FALSE){
1276                                 ContactDatav3.AddRaw(wxT("ORG"), wxSPropertySeg2);
1277                                 
1278                                 if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1279         
1280                                 } else {
1281                                 
1282                                         ContactDatav3.AddRaw(wxT("X-VCARD4-ORG;X-FIRST=TRUE;") 
1283                                                 + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxT(""));
1284                                 
1285                                 }
1286                                 OrganisationFirst = TRUE;
1287                                 ItemSeek++;
1288                         
1289                         } else {
1290                         
1291                                 if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1293                                         ContactDatav3.AddRaw(wxT("X-VCARD4-ORG"), wxSPropertySeg2);
1294         
1295                                 } else {
1296                                 
1297                                         ContactDatav3.AddRaw(wxT("X-VCARD4-ORG;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))) + wxT(":"), 
1298                                                 wxSPropertySeg2);
1299                                 
1300                                 }
1301                         
1302                         }
1303                         
1304                 } else if (wxSProperty == wxT("NOTE")) {
1305                 
1306                         std::map<int, int> SplitPoints;
1307                         std::map<int, int> SplitLength;
1308                         std::map<int, int>::iterator SLiter;                    
1309                         wxString PropertyData;
1310                         wxString PropertyName;
1311                         wxString PropertyValue;
1312                         wxString PropertyTokens;
1313                         int intPrevValue = 6;
1314                         
1315                         intPrevValue = 5;
1316                         
1317                         if (NoteFirst == FALSE){
1319                                 ContactDatav3.AddRaw(wxT("NOTE"), wxSPropertySeg2);
1320                                 
1321                                 if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1322         
1323                                 } else {
1324                                 
1325                                         ContactDatav3.AddRaw(wxT("X-VCARD4-NOTE;X-FIRST=TRUE;") 
1326                                                 + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxT(""));
1327                                                                 
1328                                 }
1329                                 NoteFirst = TRUE;
1330                                 ItemSeek++;
1331                         
1332                         } else {
1333                         
1334                                 if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1336                                         ContactDatav3.AddRaw(wxT("X-VCARD4-NOTE"), wxSPropertySeg2);
1337         
1338                                 } else {
1339                                 
1340                                         ContactDatav3.AddRaw(wxT("X-VCARD4-NOTE;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))) + wxT(":"), 
1341                                                 wxSPropertySeg2);
1342                                 
1343                                 }
1344                         
1345                         }
1346                         
1347                 } else if (wxSProperty == wxT("CATEGORIES")) {
1348                 
1349                         std::map<int, int> SplitPoints;
1350                         std::map<int, int> SplitLength;
1351                         std::map<int, int>::iterator SLiter;                    
1352                         wxString PropertyData;
1353                         wxString PropertyName;
1354                         wxString PropertyValue;
1355                         wxString PropertyTokens;
1356                         wxString PropertyType;
1357                         int intPrevValue = 12;
1358                         
1359                         intPrevValue = 11;
1360                         
1361                     if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1362                         
1363                         ContactDatav3.AddRaw(wxT("X-VCARD4-CATEGORIES"), wxSPropertySeg2);
1364    
1365                     } else {
1366                         
1367                         ContactDatav3.AddRaw(wxT("X-VCARD4-CATEGORIES;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
1369                     }
1370                         
1371                 } else if (wxSProperty == wxT("PHOTO")) {
1372                 
1373                         size_t intPropertyLen = wxSPropertySeg1.Len();
1374                         std::map<int, int> SplitPoints;
1375                         std::map<int, int> SplitLength;
1376                         std::map<int, int>::iterator SLiter;                    
1377                         wxString PropertyData;
1378                         wxString PropertyName;
1379                         wxString PropertyValue;
1380                         wxString PropertyTokens;
1381                         int intSplitsFound = 0;
1382                         int intSplitSize = 0;
1383                         int intPrevValue = 7;
1384                         
1385                         intPropertyLen = wxSPropertySeg2.Len();
1386                         SplitPoints.clear();
1387                         SplitLength.clear();
1388                         intSplitsFound = 0;
1389                         intSplitSize = 0;                       
1390                         
1391                         CaptureString(&wxSPropertySeg2, FALSE);
1392                         
1393                         for (int i = 0; i <= intPropertyLen; i++){
1394                 
1395                                 intSplitSize++;
1396                         
1397                                 if (wxSPropertySeg2.Mid(i, 1) == wxT(";")){
1398                         
1399                                         intSplitsFound++;
1400                                         SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
1401                                         
1402                                         if (intSplitsFound == 6){ 
1403                                         
1404                                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1405                                                 break; 
1406                                                 
1407                                         } else {
1408                                         
1409                                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1410                                         
1411                                         }
1412                                         
1413                                         intSplitSize = 0;                                       
1414                         
1415                                 }
1416                 
1417                         }
1418                         
1419                         wxString wxSPhotoURI;
1420                         wxString wxSPhotoMIME;
1421                         wxString wxSPhotoEncoding;
1422                         wxString wxSPhotoData;
1423                         std::string base64enc;
1424                         
1425                         if (intSplitsFound == 0){
1426                         
1427                         } else {
1428                         
1429                                 std::map<int, int>::iterator striter;
1430                         
1431                                 striter = SplitLength.find(1);
1432                         
1433                                 wxStringTokenizer wSTDataType(wxSPropertySeg2.Mid(0, striter->second), wxT(":"));
1434                         
1435                                 while (wSTDataType.HasMoreTokens() == TRUE){
1436                                 
1437                                         wxSPhotoURI = wSTDataType.GetNextToken();
1438                                         wxSPhotoMIME = wSTDataType.GetNextToken();
1439                                         break;
1440                                 
1441                                 }                       
1442                         
1443                                 wxStringTokenizer wSTDataInfo(wxSPropertySeg2.Mid((striter->second + 1)), wxT(","));                    
1444                         
1445                                 while (wSTDataInfo.HasMoreTokens() == TRUE){
1446                                 
1447                                         wxSPhotoEncoding = wSTDataInfo.GetNextToken();
1448                                         wxSPhotoData = wSTDataInfo.GetNextToken();                                      
1449                                         base64enc = wxSPhotoData.mb_str();
1450                                         break;
1451                                 
1452                                 }
1453                         
1454                         }
1455                         
1456                         
1457                         if (PhotoFirst == FALSE){
1459                                 bool PhotoKeepData = FALSE;
1461                                 wxString wxSPhotoMIMEF;
1462                                 
1463                                 if (wxSPhotoMIME == wxT("image/png")){
1464                                         wxSPhotoMIMEF = wxT("PNG");
1465                                 } else if (wxSPhotoMIME == wxT("image/jpeg")){
1466                                         wxSPhotoMIMEF = wxT("JPEG");
1467                                 } else if (wxSPhotoMIME == wxT("image/gif")){
1468                                         wxSPhotoMIMEF = wxT("GIF");
1469                                 } else if (wxSPhotoMIME == wxT("image/bmp")){
1470                                         wxSPhotoMIMEF = wxT("BMP");                     
1471                                 } else {
1472                                         wxSPhotoMIMEF = wxT("UNKNOWN");
1473                                         PhotoKeepData = TRUE;
1474                                 }
1476                                 ContactDatav3.AddRaw(wxT("PHOTO;ENCODING=b;TYPE=") + wxSPhotoMIMEF, wxSPhotoData);
1478                                 if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1479         
1480                                 } else {
1482                                         if (PhotoKeepData == TRUE){
1483                                 
1484                                                 ContactDatav3.AddRaw(wxT("X-VCARD4-PHOTO;X-FIRST=TRUE;") 
1485                                                         + ContactLine.Mid((intPrevValue - 1), ((QuoteBreakPoint + 1) - (intPrevValue))), wxSPropertySeg2);
1486                                                 
1487                                         } else {
1489                                                 ContactDatav3.AddRaw(wxT("X-VCARD4-PHOTO;X-FIRST=TRUE;") 
1490                                                         + ContactLine.Mid((intPrevValue - 1), ((QuoteBreakPoint + 1) - (intPrevValue))), wxT(""));
1491                                         
1492                                         }
1493                                 
1494                                 }
1495                                 PhotoFirst = TRUE;
1496                                 ItemSeek++;
1497                         
1498                         } else {
1499                         
1500                                 if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1502                                         ContactDatav3.AddRaw(wxT("X-VCARD4-PHOTO"), wxSPropertySeg2);
1503         
1504                                 } else {
1505                                 
1506                                         ContactDatav3.AddRaw(wxT("X-VCARD4-PHOTO;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))) + wxT(":"), 
1507                                                 wxSPropertySeg2);
1508                                 }
1509                         
1510                         }
1511                         
1512                 } else if (wxSProperty == wxT("LOGO")) {
1513                 
1514                         std::map<int, int> SplitPoints;
1515                         std::map<int, int> SplitLength;
1516                         std::map<int, int>::iterator SLiter;                    
1517                         wxString PropertyData;
1518                         wxString PropertyName;
1519                         wxString PropertyValue;
1520                         wxString PropertyTokens;
1521                         int intPrevValue = 6;
1522                         
1523                         intPrevValue = 5;
1524                         
1525                         if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1526                         
1527                                 ContactDatav3.AddRaw(wxT("X-VCARD4-LOGO"), wxSPropertySeg2);
1529                         } else {
1530                         
1531                                 ContactDatav3.AddRaw(wxT("X-VCARD4-LOGO;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
1532                         
1533                         }
1534                         
1535                 } else if (wxSProperty == wxT("SOUND")) {
1536                 
1537                         std::map<int, int> SplitPoints;
1538                         std::map<int, int> SplitLength;
1539                         std::map<int, int>::iterator SLiter;                    
1540                         wxString PropertyData;
1541                         wxString PropertyName;
1542                         wxString PropertyValue;
1543                         wxString PropertyTokens;
1544                         int intPrevValue = 7;
1545                         
1546                         intPrevValue = 6;
1547                         
1548                         if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1549                         
1550                                 ContactDatav3.AddRaw(wxT("X-VCARD4-SOUND"), wxSPropertySeg2);
1552                         } else {
1553                         
1554                                 ContactDatav3.AddRaw(wxT("X-VCARD4-SOUND;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
1555                         
1556                         }
1557                         
1558                 } else if (wxSProperty == wxT("CALURI")){
1559                 
1560                         std::map<int, int> SplitPoints;
1561                         std::map<int, int> SplitLength;
1562                         std::map<int, int>::iterator SLiter;                    
1563                         wxString PropertyData;
1564                         wxString PropertyName;
1565                         wxString PropertyValue;
1566                         wxString PropertyTokens;
1567                         int intPrevValue = 8;
1568             
1569                         intPrevValue = 7;
1570                         
1571             if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1572                         
1573                 ContactDatav3.AddRaw(wxT("X-VCARD4-CALURI"), wxSPropertySeg2);
1575             } else {
1576                         
1577                 ContactDatav3.AddRaw(wxT("X-VCARD4-CALURI;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
1579             }
1580                 
1581                 } else if (wxSProperty == wxT("CALADRURI")){
1583                         std::map<int, int> SplitPoints;
1584                         std::map<int, int> SplitLength;
1585                         std::map<int, int>::iterator SLiter;                    
1586                         wxString PropertyData;
1587                         wxString PropertyName;
1588                         wxString PropertyValue;
1589                         wxString PropertyTokens;
1590                         int intPrevValue = 11;
1591                         
1592                         intPrevValue = 10;
1593                         
1594                     if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1595                         
1596                         ContactDatav3.AddRaw(wxT("X-VCARD4-CALADRURI"), wxSPropertySeg2);
1598                     } else {
1599                         
1600                         ContactDatav3.AddRaw(wxT("X-VCARD4-CALADRURI;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
1602                     }
1603                 
1604                 } else if (wxSProperty == wxT("FBURL")){
1605                 
1606                         std::map<int, int> SplitPoints;
1607                         std::map<int, int> SplitLength;
1608                         std::map<int, int>::iterator SLiter;                    
1609                         wxString PropertyData;
1610                         wxString PropertyName;
1611                         wxString PropertyValue;
1612                         wxString PropertyTokens;
1613                         int intPrevValue = 7;
1614             
1615                         intPrevValue = 6;
1616                         
1617                     if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1618                         
1619                         ContactDatav3.AddRaw(wxT("X-VCARD4-FBURL"), wxSPropertySeg2);
1621                     } else {
1622                         
1623                         ContactDatav3.AddRaw(wxT("X-VCARD4-FBURL;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
1625                     }
1626                 
1627                 } else if (wxSProperty == wxT("KEY")){
1628                 
1629                         std::map<int, int> SplitPoints;
1630                         std::map<int, int> SplitLength;
1631                         std::map<int, int>::iterator SLiter;                    
1632                         wxString PropertyData;
1633                         wxString PropertyName;
1634                         wxString PropertyValue;
1635                         wxString PropertyTokens;
1636                         int intPrevValue = 5;
1637                         
1638                         intPrevValue = 4;
1639                                                 
1640             if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1641                         
1642                 ContactDatav3.AddRaw(wxT("X-VCARD4-KEY"), wxSPropertySeg2);
1644             } else {
1645                         
1646                 ContactDatav3.AddRaw(wxT("X-VCARD4-KEY;") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
1648             }
1649                 
1650                 } else if (wxSProperty == wxT("UID")){
1651                 
1652                         ContactDatav3.AddRaw(wxT("UID"), wxSPropertySeg2);
1653                 
1654                 } else if (wxSProperty.Mid(0, 3) == wxT("VND")){
1655                 
1656                         // Split the Vendor three ways.
1657                         
1658                         wxStringTokenizer wSTVendorDetails(wxSPropertySeg1, wxT("-"));
1659                         
1660                         wxString wxSVNDID;
1661                         wxString wxSVNDPropName;
1662                         
1663                         size_t intPrevValue = (wxSProperty.Len() + 1);
1665                         while (wSTVendorDetails.HasMoreTokens() == TRUE){
1666                         
1667                                 wSTVendorDetails.GetNextToken();
1668                                 wxSVNDID = wSTVendorDetails.GetNextToken();
1669                                 wxSVNDPropName = wSTVendorDetails.GetNextToken();
1670                                 break;
1671                         
1672                         }
1674                     if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1675                         
1676                         ContactDatav3.AddRaw(wxT("X-VCARD4-") + wxSProperty, wxSPropertySeg2);
1678                     } else {
1679                         
1680                         ContactDatav3.AddRaw(wxT("X-VCARD4-") + wxSProperty + wxT(";") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
1682                     }
1683                 
1684                 } else if (wxSProperty.Mid(0, 2) == wxT("X-")){
1685                         
1686                         size_t intPrevValue = (wxSProperty.Len() + 1);
1687                         
1688             if (((QuoteBreakPoint + 1) - intPrevValue) <= 0){
1689                         
1690                 ContactDatav3.AddRaw(wxSProperty, wxSPropertySeg2);
1692             } else {
1693                         
1694                 ContactDatav3.AddRaw(wxSProperty + wxT(";") + ContactLine.Mid(intPrevValue, ((QuoteBreakPoint + 1) - (intPrevValue + 1))), wxSPropertySeg2);
1696             }
1697                         
1698                 }
1699                 
1700                 // Reset the variables.
1701                 
1702                 QuoteMode = FALSE;
1703                 PropertyFind = TRUE;
1704                 ExtraLineSeek = TRUE;
1705                 ContactLineLen = 0;
1706                 QuoteBreakPoint = 0;
1707                 ContactLine.Clear();
1708                 wxSProperty.Clear();    
1709         
1710         }
1711         
1712         ContactDatav3.AddRaw(wxT("END"), wxT("VCARD"));
1713         *wxSData = ContactDatav3.WriteString();
1714         
1715         return TRUE;
1716         
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy