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