Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed commented out code from vcard/vcard34conv-v4conv.cpp
[xestiaab/.git] / source / vcard / vcard34conv-v4conv.cpp
1 // vcard34conv-v4conv.cpp - vCard34Conv Object vCard4 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::ConvertToV4(wxString *wxSData, vCard *vCardOut){
30         
31         // Convert a vCard 3.0 format into the vCard 4.0 format.
32         
33         std::map<int, wxString> ContactFileLines;
34         std::map<int, bool> ContactFileProcessed;
35         std::map<int, bool> ContactFileProcessedWorking;
36         std::map<int, wxString>::iterator striter;
37         std::map<int,bool>::iterator iterbool;
38         std::map<int,bool>::iterator iterboolsub;
39         wxString ContactLineRec;
41         // Process the received data.
42         
43         wxStringTokenizer wSTContactFileLines(*wxSData, wxT("\r\n"));
45         int ContactLineSeek = 0;
47         while (wSTContactFileLines.HasMoreTokens() == TRUE){
49                 ContactLineRec = wSTContactFileLines.GetNextToken();
50                 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLineRec));
51                 ContactFileProcessed.insert(std::make_pair(ContactLineSeek, FALSE));
52                 ContactLineSeek++;              
53         
54         }
55         
56         bool QuoteMode = FALSE;
57         bool PropertyFind = TRUE;
58         bool ExtraLineSeek = TRUE;
59         bool ExtraLineSeekSub = TRUE;
60         bool BirthdayProcessed = FALSE;
61         bool AnniversaryProcessed = FALSE;
62         bool FNProcessed = FALSE;
63         bool GenderProcessed = FALSE;
64         bool NameProcessed = FALSE;
65         bool FNFirst = FALSE;
66         bool NicknameFirst = FALSE;
67         bool TitleFirst = FALSE;
68         bool OrganisationFirst = FALSE;
69         bool NoteFirst = FALSE;
70         bool PhotoFirst = FALSE;
71         bool LogoFirst = FALSE;
72         bool NameFirst = FALSE;
73         bool FoundData = FALSE;
74         int intExtraNickname = 0;
75         wxString wxSProperty;
76         wxString wxSPropertyVCARD4;
77         wxString wxSPropertySeg1;
78         wxString wxSPropertySeg2;
79         wxString wxSPropertyNextLine;
80         wxString ContactLine;
81         wxString ContactLineSub;
82         wxString PropertyName;
83         wxString PropertyValue;
84         wxString PropertyDataStr;
85         size_t ContactLineLen = 0;
86         size_t ContactLineSubLen = 0;
87         int QuoteBreakPoint = 0;
88         size_t intPrevValueSub = 0;
90         std::map<wxString, wxString> PropertyData;
91         std::map<wxString, bool> PropertyLock;
92         std::map<wxString, wxString> TempPropertyData;
93         std::map<wxString, bool> TempPropertyLock;
94         std::map<int, int> TempSplitPoints;
95         std::map<int, int> TempSplitLength;
96         std::map<int, int>::iterator SLiter;
98         wxString PropertFindSub;
99         wxString wxSPropertySub;
100         wxString wxSPropertySeg1Sub;
101         wxString wxSPropertySeg2Sub;
102         wxString wxSPropertyValues;
103         wxString wxSPropertyData;
104         wxString wxSPropertyNameConv;
105         wxString wxSPropertyXVCard4Value;
106         wxString ItemProcString;
107         
108         bool XVCard4Value = FALSE;
109         bool VCard3Value = FALSE;
110         bool SeekItemData = FALSE;
111         
112         wxString strVer;
113     
114         // Setup the version string.
115         
116         strVer.Append(wxT("-//Xestia//Address Book Version "));
117         strVer.Append(wxT(XSDAB_VERSION));
118         strVer.Append(wxT("//KW"));
119         
120         vCardOut->AddRaw(wxT("BEGIN"), wxT("VCARD"));
121         vCardOut->AddRaw(wxT("VERSION"), wxT("4.0"));
122         vCardOut->AddRaw(wxT("PRODID"), strVer);
123         
124         // FN
125         // NICKNAME
126         // TITLE
127         // ORG
128         // NOTE
129         // PHOTO
130                 
131         // Process the properties which have X-FIRST.
132         
133         // Clone the ContactFileProcessed into ContactFileProcessedWorking.
135         ContactFileProcessedWorking.insert(ContactFileProcessed.begin(), ContactFileProcessed.end());
137         for (std::map<int,wxString>::iterator iter = ContactFileLines.begin(); 
138          iter != ContactFileLines.end(); ++iter){
139          
140                 ExtraLineSeek = TRUE;
142                 iterbool = ContactFileProcessed.find(iter->first);
143                 
144                 ContactLine = iter->second;
145                 
146                 // Ignore certain variables as they are not needed.
147                 
148                 if (ContactLine == wxT("BEGIN:VCARD") || 
149                 ContactLine == wxT("END:VCARD") || 
150                 ContactLine.Mid(0, 8) == wxT("VERSION:") || 
151                 ContactLine.Mid(0, 7) == wxT("PRODID:") || 
152                 ContactLine.Mid(0, 5) == wxT("X-AIM") || 
153                 ContactLine.Mid(0, 5) == wxT("X-MSN") || 
154                 ContactLine.Mid(0, 5) == wxT("X-ICQ") || 
155                 ContactLine.Mid(0, 10) == wxT("X-GADUGADU") || 
156                 ContactLine.Mid(0, 7) == wxT("X-YAHOO") || 
157                 ContactLine.Mid(0, 7) == wxT("X-SKYPE") || 
158                 ContactLine.Mid(0, 8) == wxT("X-JABBER") ||
159                 ContactLine.Mid(0, 4) == wxT("REV:")){
160                         
161                         iterbool->second = TRUE;
162                         continue;
163                         
164                 }
165                 
166                 if (iterbool->second == TRUE){
167                         
168                         continue;
169                         
170                 }
171                 
172                 if (ContactLine.Mid(0, 1) == wxT(" ") || ContactLine.Mid(0, 1) == wxT("\t")){
173                 
174                         continue;
175                 
176                 }
177         
178                 if (ContactLine.Mid(0, 4) == wxT("item")){
179                 
180                         // Line is a itemn... so ignore.
181                 
182                         continue;
183                 
184                 }
185                 
186                 std::map<int,int> DataLineProcess;
187                 std::map<int, bool>::iterator DLSLiter;
188                 std::map<int,int> DataLineProcessOriginal;
189                 int DataLineSeek = 0;
190                 int DataLineSeekOrig = 0;
192                 std::map<int,wxString>::iterator itersub = iter;
193                 DataLineProcessOriginal.insert(std::make_pair(DataLineSeekOrig, iterbool->first));
194                 DataLineSeekOrig++;
196                 while (ExtraLineSeek == TRUE){
197                 
198                         // Check if there is extra data on the next line 
199                         // (indicated by space or tab at the start) and add data.
200                 
201                         itersub++;
203                         if (itersub == ContactFileLines.end()){
205                                 break;
207                         }
209                         iterboolsub = ContactFileProcessed.find(itersub->first);
211                         if (iterboolsub == ContactFileProcessed.end()){
212                         
213                                 break;
214                         
215                         }
216                         
217                         if (iterboolsub->second == TRUE){
218                         
219                                 continue;
220                         
221                         }               
222                 
223                         wxSPropertyNextLine = itersub->second;
224                 
225                         if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
226                 
227                                 wxSPropertyNextLine.Remove(0, 1);
228                                 ContactLine.Append(wxSPropertyNextLine);
229                                 DataLineProcessOriginal.insert(std::make_pair(DataLineSeekOrig, iterboolsub->first));
230                                 DataLineSeekOrig++;
231                                 
232                         } else {
233                         
234                                 ExtraLineSeek = FALSE;
235                         
236                         }
237                 
238                 }
239                 
240                 ContactLineLen = ContactLine.Len();
241                 
242                 for (int i = 0; i <= ContactLineLen; i++){
243                 
244                         if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
245                         
246                                 PropertyFind = FALSE;
247                         
248                         } else if (PropertyFind == TRUE){
249                         
250                                 wxSProperty.Append(ContactLine.Mid(i, 1));
251                         
252                         }               
253                 
254                         if (ContactLine.Mid(i, 1) == wxT("\"")){
255                         
256                                 if (QuoteMode == TRUE){
257                                 
258                                         QuoteMode = FALSE;
259                                 
260                                 } else {
261                         
262                                         QuoteMode = TRUE;
263                                         
264                                 }
265                         
266                         }
267                         
268                         if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
269                         
270                                 QuoteBreakPoint = i;
271                                 break;
272                         
273                         }
274                 
275                 }
277                 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
278                 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
280                 wxStringTokenizer wxSPropertySegSplit(wxSPropertySeg1, wxT(";"));
281                 wxSProperty = wxSPropertySegSplit.GetNextToken();
282                         
283                 // Check what type of property it is.
284                 
285                 FoundData = FALSE;
286                 
287                 if ((wxSProperty == wxT("PHOTO") && PhotoFirst == FALSE) ||
288                 (wxSProperty == wxT("NICKNAME") && NicknameFirst == FALSE) || 
289                 (wxSProperty == wxT("TITLE") && TitleFirst == FALSE) || 
290                 (wxSProperty == wxT("FN") && FNFirst == FALSE) || 
291                 (wxSProperty == wxT("ORG") && OrganisationFirst == FALSE) ||
292                 (wxSProperty == wxT("NOTE") && NoteFirst == FALSE)){
293                         
294                         wxSPropertyVCARD4 = wxT("X-VCARD4-") + wxSProperty;
295                         intPrevValueSub = (wxSPropertyVCARD4.Len() + 2);
296                         
297                         for (std::map<int,wxString>::iterator itersub = ContactFileLines.begin(); 
298                         itersub != ContactFileLines.end(); ++itersub){
299                 
300                                 ContactLineSub = itersub->second;
301                 
302                                 ExtraLineSeekSub = TRUE;
304                                 iterboolsub = ContactFileProcessed.find(itersub->first);
305                 
306                                 // Ignore certain variables as they are not needed.
307                 
308                                 if (ContactLineSub == wxT("BEGIN:VCARD") || 
309                                 ContactLineSub == wxT("END:VCARD") || 
310                                 ContactLineSub.Mid(0, 8) == wxT("VERSION:") || 
311                                 ContactLineSub.Mid(0, 7) == wxT("PRODID:") || 
312                                 ContactLineSub.Mid(0, 5) == wxT("X-AIM") || 
313                                 ContactLineSub.Mid(0, 5) == wxT("X-MSN") || 
314                                 ContactLineSub.Mid(0, 5) == wxT("X-ICQ") || 
315                                 ContactLineSub.Mid(0, 10) == wxT("X-GADUGADU") || 
316                                 ContactLineSub.Mid(0, 7) == wxT("X-YAHOO") || 
317                                 ContactLineSub.Mid(0, 7) == wxT("X-SKYPE") || 
318                                 ContactLineSub.Mid(0, 8) == wxT("X-JABBER") ||
319                                 ContactLineSub.Mid(0, 4) == wxT("REV:")){
320                         
321                                         iterboolsub->second = TRUE;
322                                         continue;
323                         
324                                 }
325                 
326                                 if (iterboolsub->second == TRUE){
328                                         continue;
329                         
330                                 }
331                 
332                                 if (ContactLineSub.Mid(0, 1) == wxT(" ") || ContactLineSub.Mid(0, 1) == wxT("\t")){
333                 
334                                         continue;
335                 
336                                 }
337         
338                                 if (ContactLineSub.Mid(0, 4) == wxT("item")){
339                 
340                                         // Line is a itemn... so ignore.
341                 
342                                         continue;
343                 
344                                 }
345                                 
346                                 DataLineProcess.insert(std::make_pair(DataLineSeek, itersub->first));
347                                 DataLineSeek++;
349                                 while (ExtraLineSeekSub == TRUE){
351                                         if (itersub == ContactFileLines.end()){
352                                                 ExtraLineSeekSub = FALSE;
353                                                 continue;
354                                         } else {
355                                                 itersub++;
357                                         }
359                                         iterboolsub = ContactFileProcessedWorking.find(itersub->first);
361                                         wxSPropertyNextLine = itersub->second;
363                                         if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
365                                                 wxSPropertyNextLine.Remove(0, 1);
366                                                 ContactLineSub.Append(wxSPropertyNextLine);
367                                                 DataLineProcess.insert(std::make_pair(DataLineSeek, itersub->first));
368                                                 DataLineSeek++;
370                                         } else {
372                                                 itersub--;
373                                                 ExtraLineSeekSub = FALSE;
375                                         }
377                                 }
378                 
379                                 ContactLineSubLen = ContactLineSub.Len();
380                                 PropertyFind = TRUE;
381                                 wxSPropertySub.clear();
382                         
383                                 for (int i = 0; i <= ContactLineSubLen; i++){
384                 
385                                         if ((ContactLineSub.Mid(i, 1) == wxT(";") || ContactLineSub.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
386                         
387                                                 PropertyFind = FALSE;
388                         
389                                         } else if (PropertyFind == TRUE){
390                         
391                                                 wxSPropertySub.Append(ContactLineSub.Mid(i, 1));
392                         
393                                         }               
394                 
395                                         if (ContactLineSub.Mid(i, 1) == wxT("\"")){
396                         
397                                                 if (QuoteMode == TRUE){
398                                  
399                                                         QuoteMode = FALSE;
400                                 
401                                                 } else {
402                         
403                                                         QuoteMode = TRUE;
404                                         
405                                                 }
406                         
407                                         }
408                         
409                                         if (ContactLineSub.Mid(i, 1) == wxT(":") && ContactLineSub.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
410                         
411                                                 QuoteBreakPoint = i;
412                                                 break;
413                         
414                                         }
415                 
416                                 }
418                                 if (wxSPropertySub != wxSPropertyVCARD4){
419                         
420                                         wxSPropertySub.clear();
421                                         DataLineSeek = 0;
422                                         DataLineProcess.clear();
423                                         continue;
424                         
425                                 }
427                                 wxSPropertySeg1Sub = ContactLineSub.Mid(0, QuoteBreakPoint);
428                                 wxSPropertySeg2Sub = ContactLineSub.Mid((QuoteBreakPoint + 1));
430                                 // Split the property name data.
431                         
432                                 // Strip the X-VCARD4- from the variable.
433                                 
434                                 wxString wxSPropertyChopped =  wxSPropertySeg1Sub.Mid(9);
435                         
436                                 intPrevValueSub = (wxSProperty.Len() + 2);
437                                 
438                                 SplitValuesData(&wxSPropertyChopped, &TempSplitPoints, &TempSplitLength, (int)intPrevValueSub, &TempPropertyData);
439                                 
440                                 // Process the splitted data into temporary property data.
442                                 // Look for certain property names and the X-FIRST
443                                 // property name.
444                                         
445                                 bool ProcessData = FALSE;
446                         
447                                 // Check for X-FIRST.
448                         
449                                 for (std::map<wxString, wxString>::iterator xfiter = TempPropertyData.begin(); 
450                                 xfiter != TempPropertyData.end(); ++xfiter){
451                         
452                                         PropertyName = xfiter->first;
453                                         PropertyValue = xfiter->second;
454                                                 
455                                         if (PropertyName == wxT("X-FIRST") && PropertyValue == wxT("TRUE")){
456                                 
457                                                 ProcessData = TRUE;
458                                                 
459                                                 if (wxSProperty == wxT("PHOTO")){ PhotoFirst = TRUE; }
460                                                 else if (wxSProperty == wxT("NICKNAME")){ NicknameFirst = TRUE; }
461                                                 else if (wxSProperty == wxT("TITLE")){ TitleFirst = TRUE; }
462                                                 else if (wxSProperty == wxT("FN")){ FNFirst = TRUE; }
463                                                 else if (wxSProperty == wxT("ORG")){ OrganisationFirst = TRUE; }
464                                                 else if (wxSProperty == wxT("NOTE")){ NoteFirst = TRUE; }
465                                                 break;
466                                 
467                                         }
468                         
469                                 }
470                         
471                                 if (ProcessData == FALSE){
472                         
473                                         DataLineProcess.clear();
474                                         DataLineSeek = 0;
475                                         TempPropertyData.clear();
476                         
477                                 } else {
478                         
479                                         for (std::map<wxString, wxString>::iterator xfiter = TempPropertyData.begin(); 
480                                         xfiter != TempPropertyData.end(); ++xfiter){
481                         
482                                                 PropertyName = xfiter->first;
483                                                 PropertyValue = xfiter->second;
484                         
485                                                 if (PropertyName == wxT("X-FIRST")){
486                                 
487                                                         continue;
488                                 
489                                                 }
490                                 
491                                                 PropertyData.insert(std::make_pair(PropertyName, PropertyValue));
492                                                 PropertyLock.insert(std::make_pair(PropertyName, FALSE));
493                         
494                                         }
495                                 
496                                         // Mark all lines as processed.
497                                         
498                                         for (std::map<int,int>::iterator dpiter = DataLineProcess.begin(); 
499                                         dpiter != DataLineProcess.end(); ++dpiter){
500                                         
501                                                 DLSLiter = ContactFileProcessed.find(dpiter->second);
502                                                 DLSLiter->second = TRUE;
503                                         
504                                         }
505                                         
506                                         for (std::map<int,int>::iterator dpoiter = DataLineProcessOriginal.begin(); 
507                                         dpoiter != DataLineProcessOriginal.end(); ++dpoiter){
508                                         
509                                                 DLSLiter = ContactFileProcessed.find(dpoiter->second);
510                                                 DLSLiter->second = TRUE;
511                                         
512                                         }
513                                         
514                                         DataLineProcess.clear();
515                                         DataLineProcessOriginal.clear();
516                                         DataLineSeek = 0;
517                                         DataLineSeekOrig = 0;
518                                         TempSplitPoints.clear();
519                                         TempSplitLength.clear();
520                                         TempPropertyData.clear();
521                                         FoundData = TRUE;
522                                         
523                                         break;
524                         
525                                 }
526                                 
527                         }
528                 
529                 } else {
530                 
531                         wxSProperty.clear();
532                         wxSPropertySub.Clear();
533                         wxSPropertySeg1.Clear();
534                         wxSPropertySeg2.Clear();
535                         wxSPropertySeg1Sub.Clear();
536                         wxSPropertySeg2Sub.Clear();
537                         wxSPropertyValues.Clear();
538                         wxSPropertyData.Clear();
539                         wxSPropertyXVCard4Value.Clear();
540                         wxSPropertyNameConv.Clear();
541                         PropertyData.clear();
542                         PropertyLock.clear();
543                         ContactLine.clear();
544                         ContactLineSub.clear();
545                         DataLineProcess.clear();
546                         DataLineProcessOriginal.clear();
547                         TempSplitPoints.clear();
548                         TempSplitLength.clear();
549                         wxSPropertyVCARD4.clear();
550                         DataLineSeek = 0;
551                         DataLineSeekOrig = 0;
552                         XVCard4Value = FALSE;
553                         VCard3Value = FALSE;
554                 
555                 }
556                 
557                 if (FoundData == FALSE){
558                 
559                         wxSProperty.clear();
560                         wxSPropertySub.Clear();
561                         wxSPropertySeg1.Clear();
562                         wxSPropertySeg2.Clear();
563                         wxSPropertySeg1Sub.Clear();
564                         wxSPropertySeg2Sub.Clear();
565                         wxSPropertyValues.Clear();
566                         wxSPropertyData.Clear();
567                         wxSPropertyXVCard4Value.Clear();
568                         wxSPropertyNameConv.Clear();
569                         PropertyData.clear();
570                         PropertyLock.clear();
571                         ContactLine.clear();
572                         ContactLineSub.clear();
573                         DataLineProcess.clear();
574                         DataLineProcessOriginal.clear();
575                         TempSplitPoints.clear();
576                         TempSplitLength.clear();
577                         wxSPropertyVCARD4.clear();
578                         DataLineSeek = 0;
579                         DataLineSeekOrig = 0;
580                         XVCard4Value = FALSE;
581                         VCard3Value = FALSE;
582                 
583                 }
584                 
585                 ConvertV4PropertyProc(&wxSProperty, &wxSPropertySeg1, &wxSPropertySeg2, 
586                         &wxSPropertyValues, &wxSPropertyData, &wxSPropertyXVCard4Value, 
587                         &wxSPropertyNameConv, &PropertyData, &PropertyLock, FALSE, &VCard3Value, &XVCard4Value);
588                 
589                 wxString FinalPropertyData;
590         
591                 FinalPropertyData.Append(wxSPropertyNameConv);
592         
593                 for (std::map<wxString, wxString>::iterator striter = PropertyData.begin(); 
594                 striter != PropertyData.end(); ++striter){
596                         FinalPropertyData.Append(wxT(";"));             
597                         FinalPropertyData.Append(striter->first);
598                         FinalPropertyData.Append(wxT("="));
599                         FinalPropertyData.Append(striter->second);
600                 
601                 }
602                 
603                 wxString FinalPropValue;
604                 
605                 if (wxSPropertyXVCard4Value.IsEmpty()){
606                 
607                         FinalPropValue = wxSPropertyData;
608                 
609                 } else {
610                 
611                         if (wxSPropertyXVCard4Value != wxSPropertyData){
612                 
613                                 FinalPropValue = wxSPropertyXVCard4Value;
614                         
615                         }
616                 
617                 }
618                         
619                 if (FinalPropertyData.IsEmpty() && FinalPropValue.IsEmpty()){
620                 
621                         continue;
622                 
623                 }
624                 
625                 vCardOut->AddRaw(FinalPropertyData, FinalPropValue);
627                 wxSProperty.clear();
628                 wxSPropertySub.Clear();
629                 wxSPropertySeg1.Clear();
630                 wxSPropertySeg2.Clear();
631                 wxSPropertySeg1Sub.Clear();
632                 wxSPropertySeg2Sub.Clear();
633                 wxSPropertyValues.Clear();
634                 wxSPropertyData.Clear();
635                 wxSPropertyXVCard4Value.Clear();
636                 wxSPropertyNameConv.Clear();
637                 PropertyData.clear();
638                 PropertyLock.clear();
639                 ContactLine.clear();
640                 ContactLineSub.clear();
641                 DataLineProcess.clear();
642                 DataLineProcessOriginal.clear();
643                 wxSPropertyVCARD4.clear();
644                 DataLineSeek = 0;
645                 DataLineSeekOrig = 0;
646                 XVCard4Value = FALSE;
647                 VCard3Value = FALSE;
648         
649         }
650         
651         // Process the non-itemn values.
652         
653         for (std::map<int,wxString>::iterator iter = ContactFileLines.begin(); 
654          iter != ContactFileLines.end(); ++iter){
655         
656                 ExtraLineSeek = TRUE;
658                 iterbool = ContactFileProcessed.find(iter->first);
659                 
660                 ContactLine = iter->second;
661                 
662                 // Ignore certain variables as they are not needed.
663                 
664                 if (ContactLine == wxT("BEGIN:VCARD") || 
665                 ContactLine == wxT("END:VCARD") || 
666                 ContactLine.Mid(0, 8) == wxT("VERSION:") || 
667                 ContactLine.Mid(0, 7) == wxT("PRODID:") || 
668                 ContactLine.Mid(0, 5) == wxT("X-AIM") || 
669                 ContactLine.Mid(0, 5) == wxT("X-MSN") || 
670                 ContactLine.Mid(0, 5) == wxT("X-ICQ") || 
671                 ContactLine.Mid(0, 10) == wxT("X-GADUGADU") || 
672                 ContactLine.Mid(0, 7) == wxT("X-YAHOO") || 
673                 ContactLine.Mid(0, 7) == wxT("X-SKYPE") || 
674                 ContactLine.Mid(0, 8) == wxT("X-JABBER") ||
675                 ContactLine.Mid(0, 4) == wxT("REV:")){
676                         
677                         iterbool->second = TRUE;
678                         continue;
679                         
680                 }
681                 
682                 if (iterbool->second == TRUE){
683                         
684                         continue;
685                         
686                 }
687                 
688                 if (ContactLine.Mid(0, 1) == wxT(" ") || ContactLine.Mid(0, 1) == wxT("\t")){
689                 
690                         continue;
691                 
692                 }
693         
694                 if (ContactLine.Mid(0, 4) == wxT("item")){
695                 
696                         // Line is a itemn... so ignore.
697                 
698                         continue;
699                 
700                 }
701                 
702                 std::map<int,wxString>::iterator itersub = iter;
704                 while (ExtraLineSeek == TRUE){
705                 
706                         // Check if there is extra data on the next line 
707                         // (indicated by space or tab at the start) and add data.
709                         if (itersub == ContactFileLines.end()){
710                                 ExtraLineSeekSub = FALSE;
711                                 continue;
712                         }
713                         else {
714                                 itersub++;
716                         }
718                         iterboolsub = ContactFileProcessedWorking.find(itersub->first);
720                         if (iterboolsub == ContactFileProcessedWorking.end()){
721                         
722                                 break;
723                         
724                         }
725                         
726                         if (iterboolsub->second == TRUE){
727                         
728                                 continue;
729                         
730                         }
731                         
732                         if (itersub == ContactFileLines.end()){
733                         
734                                 break;
735                         
736                         }                       
737                 
738                         wxSPropertyNextLine = itersub->second;
739                 
740                         if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
741                 
742                                 wxSPropertyNextLine.Remove(0, 1);
743                                 ContactLine.Append(wxSPropertyNextLine);
744                                 iterboolsub->second = TRUE;
745                 
746                         } else {
747                         
748                                 ExtraLineSeek = FALSE;
749                         
750                         }
751                 
752                 }
753                 
754                 ContactLineLen = ContactLine.Len();
755                 
756                 for (int i = 0; i <= ContactLineLen; i++){
757                 
758                         if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
759                         
760                                 PropertyFind = FALSE;
761                         
762                         } else if (PropertyFind == TRUE){
763                         
764                                 wxSProperty.Append(ContactLine.Mid(i, 1));
765                         
766                         }               
767                 
768                         if (ContactLine.Mid(i, 1) == wxT("\"")){
769                         
770                                 if (QuoteMode == TRUE){
771                                 
772                                         QuoteMode = FALSE;
773                                 
774                                 } else {
775                         
776                                         QuoteMode = TRUE;
777                                         
778                                 }
779                         
780                         }
781                         
782                         if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
783                         
784                                 QuoteBreakPoint = i;
785                                 break;
786                         
787                         }
788                 
789                 }
791                 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
792                 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
794                 wxStringTokenizer wxSPropertySegSplit(wxSPropertySeg1, wxT(";"));
795                 wxSProperty = wxSPropertySegSplit.GetNextToken();
797                 std::map<int,int> DataLineProcess;
798                 std::map<int, bool>::iterator DLSLiter;
799                 
800                 // Look for the X-VCARD4-(variablename) equivilant.
801                 
802                 wxSPropertyVCARD4 = wxT("X-VCARD4-") + wxSProperty;
803                         
804                 // Sort out remainder of the types.
805                 
806                 ConvertV4PropertyProc(&wxSProperty, &wxSPropertySeg1, &wxSPropertySeg2, 
807                         &wxSPropertyValues, &wxSPropertyData, &wxSPropertyXVCard4Value, 
808                         &wxSPropertyNameConv, &PropertyData, &PropertyLock, FALSE, &VCard3Value, &XVCard4Value);
809                 
810                 wxString FinalPropertyData;
811         
812                 FinalPropertyData.Append(wxSPropertyNameConv);
813         
814                 for (std::map<wxString, wxString>::iterator striter = PropertyData.begin(); 
815                 striter != PropertyData.end(); ++striter){
817                         FinalPropertyData.Append(wxT(";"));             
818                         FinalPropertyData.Append(striter->first);
819                         FinalPropertyData.Append(wxT("="));
820                         FinalPropertyData.Append(striter->second);
821                 
822                 }
823                 
824                 wxString FinalPropValue;
825                 
826                 if (wxSPropertyXVCard4Value.IsEmpty()){
827                 
828                         FinalPropValue = wxSPropertyData;
829                 
830                 } else {
831                 
832                         if (wxSPropertyXVCard4Value != wxSPropertyData){
833                 
834                                 FinalPropValue = wxSPropertyXVCard4Value;
835                         
836                         }
837                 
838                 }
839                 
840                 vCardOut->AddRaw(FinalPropertyData, FinalPropValue);
842                 wxSProperty.clear();
843                 wxSPropertySub.Clear();
844                 wxSPropertySeg1.Clear();
845                 wxSPropertySeg2.Clear();
846                 wxSPropertyValues.Clear();
847                 wxSPropertyData.Clear();
848                 wxSPropertyXVCard4Value.Clear();
849                 wxSPropertyNameConv.Clear();
850                 PropertyData.clear();
851                 PropertyLock.clear();
852                 ContactLine.clear();
853                 XVCard4Value = FALSE;
854                 VCard3Value = FALSE;
855         
856         }
857         
858         int FNCount = 0;
859         int NameCount = 0;
860         int NicknameCount = 0;
861         int ADRCount = 0;
862         int EmailCount = 0;
863         int IMPPCount = 0;
864         int TelCount = 0;
865         int LangCount = 0;
866         int TZCount = 0;
867         int GeoCount = 0;
868         int URLCount = 0;
869         int RelatedCount = 0;
870         int TitleCount = 0;
871         int RoleCount = 0;
872         int OrgCount = 0;
873         int NoteCount = 0;
874         int CategoryCount = 0;
875         int PhotoCount = 0;
876         int LogoCount = 0;
877         int SoundCount = 0;
878         int CalAdrCount = 0;
879         int CalReqAdrCount = 0;
880         int FreeBusyCount = 0;
881         int KeyCount = 0;
882         int VendorCount = 0;
883         int XTokenCount = 0;
884         int ItemSeek = 1;
885         int MaxItemNumber = 0;
886         int ItemOrdered = 0;
887         int ItemUnordered = 0;
888         int ItemNumber = 0;
889         size_t ItemStringSeekLen = 0;
890         int ItemSeekSub = 0;
891         int ItemSeekSecSub = 0;
892         
893         std::map<int, wxString> NumberedName;
894         std::map<int, wxString> NumberedData;
895         std::map<int, wxString> NumberedPropValues;
896         std::map<int, wxString> NumberedPropOldValue;
897         
898         std::map<int, wxString> UnNumberedName;
899         std::map<int, wxString> UnNumberedData;
900         std::map<int, wxString> UnNumberedPropValues;
901         std::map<int, wxString> UnNumberedPropOldValue;
903         // Part 1: Get the itemn number.
904         
905         std::map<int,bool>::iterator iterboolsecsub;
906         std::map<int,wxString>::iterator itersub;
907         std::map<int, wxString> TempData;
908         PropertyData.clear();
909         PropertyLock.clear();
910         wxString ItemString;
911         wxString ItemStringSeek;
912         wxString ItemPropName;
913         ContactLineSeek = 0;
914         
915         ContactLineSub.clear();
916         ExtraLineSeekSub = 0;
917         wxString wxSPropertyNextLineSub;
918         ContactLineSubLen = 0;
919         int ItemIndex = 0;
920         PropertFindSub.clear();
921         wxSPropertySub.clear();
922         wxSPropertySeg1Sub.clear();
923         wxSPropertySeg2Sub.clear();
924         wxSPropertyValues.clear();
925         wxSPropertyData.clear();
926         wxSPropertyNameConv.clear();
927         wxSPropertyXVCard4Value.clear();
928         ItemProcString.clear();
929         
930         XVCard4Value = FALSE;
931         VCard3Value = FALSE;
932         SeekItemData = FALSE;
933         
934         std::map<wxString, void*> ItemMapIndex;
935         
936         // Look for item in the initial line, process into a proper line then
937         // look for other lines with the same item association.
938         
939         for (std::map<int,wxString>::iterator iter = ContactFileLines.begin();
940                 iter != ContactFileLines.end(); ++iter){
941         
942                 ExtraLineSeek = TRUE;
943                 
944                 iterbool = ContactFileProcessed.find(iter->first);
945                 
946                 if (iterbool->second == TRUE){
947                 
948                         continue;
949                 
950                 }
951                 
952                 ContactLine = iter->second;
953                 
954                 if (ContactLine.Mid(0, 1) == wxT(" ") || ContactLine.Mid(0, 1) == wxT("\t")){
955                 
956                         continue;
957                 
958                 }
959                 
960                 if (ContactLine.Mid(0, 4) != wxT("item")){
961                 
962                         continue;
963                 
964                 }
965                 
966                 // Get Item data.
968                 std::map<int,wxString>::iterator itersub = iter;
970                 while (ExtraLineSeek == TRUE){
971                 
972                         // Check if there is extra data on the next line 
973                         // (indicated by space or tab at the start) and add data.
974                 
975                         itersub++;
976                         iterboolsub = ContactFileProcessed.find(itersub->first);
978                         if (iterboolsub == ContactFileProcessed.end()){
979                         
980                                 break;
981                         
982                         }
983                         
984                         if (iterboolsub->second == TRUE){
985                         
986                                 continue;
987                         
988                         }
989                         
990                         if (itersub == ContactFileLines.end()){
991                         
992                                 break;
993                         
994                         }                       
995                 
996                         wxSPropertyNextLine = itersub->second;
997                 
998                         if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
999                 
1000                                 wxSPropertyNextLine.Remove(0, 1);
1001                                 ContactLine.Append(wxSPropertyNextLine);
1002                                 iterboolsub->second = TRUE;
1003                 
1004                         } else {
1005                         
1006                                 ExtraLineSeek = FALSE;
1007                         
1008                         }
1009                 
1010                 }
1011                 
1012                 ContactLineLen = ContactLine.Len();
1013                 
1014                 for (int i = 0; i <= ContactLineLen; i++){
1015                 
1016                         if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
1017                         
1018                                 PropertyFind = FALSE;
1019                         
1020                         } else if (PropertyFind == TRUE){
1021                         
1022                                 wxSProperty.Append(ContactLine.Mid(i, 1));
1023                         
1024                         }               
1025                 
1026                         if (ContactLine.Mid(i, 1) == wxT("\"")){
1027                         
1028                                 if (QuoteMode == TRUE){
1029                                 
1030                                         QuoteMode = FALSE;
1031                                 
1032                                 } else {
1033                         
1034                                         QuoteMode = TRUE;
1035                                         
1036                                 }
1037                         
1038                         }
1039                         
1040                         if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
1041                         
1042                                 QuoteBreakPoint = i;
1043                                 break;
1044                         
1045                         }
1046                 
1047                 }
1049                 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
1050                 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
1051                 
1052                 // Go through the lines and collect the lines like itemn.
1053                 
1054                 std::map<int,wxString> *ItemListData;
1055                 ItemListData = new std::map<int,wxString>;
1056                 
1057                 wxStringTokenizer ItemData(wxSPropertySeg1, wxT("."));
1058                 
1059                 ItemString = ItemData.GetNextToken();
1060                 ItemStringSeek = wxT("item") + ItemString.Mid(4);
1061                 
1062                 wxStringTokenizer ItemPropSplit(ItemData.GetNextToken(), wxT(";"));
1063                 
1064                 ItemPropName = ItemPropSplit.GetNextToken();
1065                 
1066                 ItemStringSeekLen = ItemStringSeek.Len();
1067                 
1068                 ItemIndex = 0;
1069                 
1070                 for (std::map<int,wxString>::iterator itersec = ContactFileLines.begin();
1071                 itersec != ContactFileLines.end(); ++itersec){
1072                 
1073                         ExtraLineSeek = TRUE;
1074                 
1075                         iterboolsub = ContactFileProcessed.find(itersec->first);
1076                 
1077                         if (iterboolsub->second == TRUE){
1078                         
1079                                 continue;
1080                         
1081                         }
1082                 
1083                         ContactLineSub = itersec->second;
1084                         
1085                         wxStringTokenizer ItemProcData(ContactLineSub, wxT("."));
1086                         ItemProcString = ItemData.GetNextToken();
1087                         
1088                         if (ItemStringSeek != ContactLineSub.Mid(0, ItemStringSeekLen)){
1089                         
1090                                 continue;
1091                         
1092                         }
1093                         
1094                         ItemIndex++;
1095                         
1096                         ItemListData->insert(std::make_pair(ItemIndex, ContactLineSub));
1097                         
1098                         iterboolsub->second = TRUE;
1099                 
1100                 }
1102                 ItemListData->insert(std::make_pair(ItemIndex, ContactLineSub));
1103                 ItemMapIndex.insert(std::make_pair(ItemStringSeek, ItemListData));
1104                 
1105         }
1106         
1107         // Process each itemn set.
1108         
1109         for (std::map<wxString, void*>::iterator iter = ItemMapIndex.begin();
1110                 iter != ItemMapIndex.end(); ++iter){
1111                         
1112                 std::map<int, wxString> *ItemDataPtr;
1114                 ItemDataPtr = (std::map<int,wxString>*)iter->second;
1115                 
1116                 for (std::map<int,wxString>::iterator itersub = ItemDataPtr->begin();
1117                         itersub != ItemDataPtr->end(); ++itersub){
1118                         
1119                         ContactLine = itersub->second;
1120                         
1121                         ContactLineLen = ContactLine.Len();
1122                 
1123                         for (int i = 0; i <= ContactLineLen; i++){
1124                 
1125                                 if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
1126                         
1127                                         PropertyFind = FALSE;
1128                         
1129                                 } else if (PropertyFind == TRUE){
1130                         
1131                                         wxSProperty.Append(ContactLine.Mid(i, 1));
1132                         
1133                                 }               
1134                 
1135                                 if (ContactLine.Mid(i, 1) == wxT("\"")){
1136                         
1137                                         if (QuoteMode == TRUE){
1138                                 
1139                                                 QuoteMode = FALSE;
1140                                 
1141                                         } else {
1142                         
1143                                                 QuoteMode = TRUE;
1144                                         
1145                                         }
1146                         
1147                                 }
1148                         
1149                                 if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
1150                         
1151                                         QuoteBreakPoint = i;
1152                                         break;
1153                         
1154                                 }
1155                 
1156                         }
1157                         
1158                         wxSPropertySeg1Sub = ContactLine.Mid(0, QuoteBreakPoint);
1159                         wxSPropertySeg2Sub = ContactLine.Mid((QuoteBreakPoint + 1));
1160                         
1161                         wxStringTokenizer wxSPropertySegSplit(wxSPropertySeg1Sub, wxT(";"));
1162                         wxSProperty = wxSPropertySegSplit.GetNextToken();
1163                         
1164                         // Sort out remainder of the types.
1165                         
1166                         // Skip certain X-* IM variables as they are processed via
1167                         // IMPP.
1168                         
1169                         if (wxSProperty == wxT("X-AIM") || wxSProperty == wxT("X-MSN") || 
1170                         wxSProperty == wxT("X-ICQ") || wxSProperty == wxT("X-GADUGADU") || 
1171                         wxSProperty == wxT("X-YAHOO") || wxSProperty == wxT("X-SKYPE") || 
1172                         wxSProperty == wxT("X-JABBER")){
1173                 
1174                                 wxSProperty.clear();
1175                                 wxSPropertySub.Clear();
1176                                 wxSPropertySeg1.Clear();
1177                                 wxSPropertySeg2.Clear();
1178                                 wxSPropertyValues.Clear();
1179                                 wxSPropertyData.Clear();
1180                                 wxSPropertyXVCard4Value.Clear();
1181                                 wxSPropertyNameConv.Clear();
1182                                 PropertyData.clear();
1183                                 PropertyLock.clear();
1184                                 ContactLine.clear();
1185                                 XVCard4Value = FALSE;
1186                                 VCard3Value = FALSE;
1187                                 continue;
1188                 
1189                         }
1190                         
1191                         ConvertV4PropertyProc(&wxSProperty, &wxSPropertySeg1Sub, &wxSPropertySeg2Sub, 
1192                         &wxSPropertyValues, &wxSPropertyData, &wxSPropertyXVCard4Value, 
1193                         &wxSPropertyNameConv, &PropertyData, &PropertyLock, TRUE, &VCard3Value, &XVCard4Value);
1194                         
1195                 }
1196                 
1197                 if (wxSPropertyNameConv.IsEmpty()){
1198                 
1199                         wxSProperty.clear();
1200                         wxSPropertySub.Clear();
1201                         wxSPropertySeg1.Clear();
1202                         wxSPropertySeg2.Clear();
1203                         wxSPropertyValues.Clear();
1204                         wxSPropertyData.Clear();
1205                         wxSPropertyXVCard4Value.Clear();
1206                         wxSPropertyNameConv.Clear();
1207                         PropertyData.clear();
1208                         PropertyLock.clear();
1209                         ContactLine.clear();
1210                         XVCard4Value = FALSE;
1211                         VCard3Value = FALSE;
1212                         continue;
1213                 
1214                 }
1215                 
1216                 wxString FinalPropertyData;
1217         
1218                 FinalPropertyData.Append(wxSPropertyNameConv);
1219         
1220                 for (std::map<wxString, wxString>::iterator striter = PropertyData.begin(); 
1221                 striter != PropertyData.end(); ++striter){
1223                         FinalPropertyData.Append(wxT(";"));             
1224                         FinalPropertyData.Append(striter->first);
1225                         FinalPropertyData.Append(wxT("="));
1226                         FinalPropertyData.Append(striter->second);
1227                 
1228                 }
1229                 
1230                 wxString FinalPropValue;
1231                 
1232                 if (wxSPropertyXVCard4Value.IsEmpty()){
1233                 
1234                         FinalPropValue = wxSPropertyData;
1235                 
1236                 } else {
1237                 
1238                         if (wxSPropertyXVCard4Value != wxSPropertyData){
1239                         
1240                                 FinalPropValue = wxSPropertyData;
1241                                 
1242                         } else {
1243                 
1244                                 FinalPropValue = wxSPropertyXVCard4Value;
1245                 
1246                         }
1247                 
1248                 }
1249                 
1250                 vCardOut->AddRaw(FinalPropertyData, FinalPropValue);
1251                 
1252                 wxSProperty.clear();
1253                 wxSPropertySub.Clear();
1254                 wxSPropertySeg1Sub.Clear();
1255                 wxSPropertySeg2Sub.Clear();
1256                 wxSPropertyValues.Clear();
1257                 wxSPropertyData.Clear();
1258                 wxSPropertyXVCard4Value.Clear();
1259                 wxSPropertyNameConv.Clear();
1260                 FinalPropertyData.clear();
1261                 FinalPropValue.clear();
1262                 PropertyData.clear();
1263                 PropertyLock.clear();
1264                 ContactLine.clear();
1265                 XVCard4Value = FALSE;
1266                 VCard3Value = FALSE;
1267         
1268                 TempData.clear();
1269                 
1270         }
1271         
1272         // Delete data.
1273         
1274         std::map<int, wxString> *ItemEraseData;
1275         
1276         for (std::map<wxString, void*>::iterator iter = ItemMapIndex.begin();
1277                 iter != ItemMapIndex.end(); ++iter){
1278                 
1279                 ItemEraseData = (std::map<int,wxString>*)iter->second;
1281                 delete ItemEraseData;
1282                 ItemEraseData = NULL;
1283                 
1284         }
1286         ItemMapIndex.clear();
1287         
1288         vCardOut->AddRaw(wxT("END"), wxT("VCARD"));
1290         return TRUE;
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