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