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