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