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