int NicknameCount = 0;
int TimeZoneCount = 0;
int AddressCount = 0;
+ int EmailCount = 0;
wxString ContactLine;
wxString PropertyLine;
wxString PropertySeg1;
ProcessAddress(PropertySeg1, PropertySeg2, &AddressCount);
AddressCount++;
+ } else if (Property == wxT("EMAIL")){
+
+ // See frmContactEditor-LoadEmail.cpp
+
+ ProcessEmail(PropertySeg1, PropertySeg2, &EmailCount);
+ EmailCount++;
+
}
}
}
+void ContactDataObject::ProcessEmail(wxString PropertySeg1, wxString PropertySeg2, int *EmailCount){
+
+ std::map<int, int> SplitPoints;
+ std::map<int, int> SplitLength;
+
+ int intPrevValue = 7;
+ int intPref = 0;
+
+ SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
+
+ intPrevValue = 6;
+
+ PropertyType PropType;
+
+ // Look for type before continuing.
+
+ CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
+
+ std::map<int, wxString> *EmailList = NULL;
+ std::map<int, wxString> *EmailListType = NULL;
+ std::map<int, wxString> *EmailListAltID = NULL;
+ std::map<int, wxString> *EmailListPID = NULL;
+ std::map<int, wxString> *EmailListTokens = NULL;
+ std::map<int, int> *EmailListPref = NULL;
+
+ switch(PropType){
+ case PROPERTY_NONE:
+ EmailList = &GeneralEmailList;
+ EmailListType = &GeneralEmailListType;
+ EmailListAltID = &GeneralEmailListAltID;
+ EmailListPID = &GeneralEmailListPID;
+ EmailListTokens = &GeneralEmailListTokens;
+ EmailListPref = &GeneralEmailListPref;
+ break;
+ case PROPERTY_HOME:
+ EmailList = &HomeEmailList;
+ EmailListType = &HomeEmailListType;
+ EmailListAltID = &HomeEmailListAltID;
+ EmailListPID = &HomeEmailListPID;
+ EmailListTokens = &HomeEmailListTokens;
+ EmailListPref = &HomeEmailListPref;
+ break;
+ case PROPERTY_WORK:
+ EmailList = &BusinessEmailList;
+ EmailListType = &BusinessEmailListType;
+ EmailListAltID = &BusinessEmailListAltID;
+ EmailListPID = &BusinessEmailListPID;
+ EmailListTokens = &BusinessEmailListTokens;
+ EmailListPref = &BusinessEmailListPref;
+ break;
+ }
+
+ intPrevValue = 6;
+
+ std::map<int,int>::iterator SLiter;
+ wxString PropertyData;
+ wxString PropertyName;
+ wxString PropertyValue;
+ wxString PropertyTokens;
+ bool FirstToken = TRUE;
+
+ for (std::map<int, int>::iterator intiter = SplitPoints.begin();
+ intiter != SplitPoints.end(); ++intiter){
+
+ SLiter = SplitLength.find(intiter->first);
+
+ PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
+
+ wxStringTokenizer PropertyElement (PropertyData, wxT("="));
+ PropertyName = PropertyElement.GetNextToken();
+ PropertyValue = PropertyElement.GetNextToken();
+
+ intPrevValue = intiter->second;
+
+ CaptureString(&PropertyValue, FALSE);
+
+ // Process properties.
+
+ if (PropertyName == wxT("ALTID")){
+
+ EmailListAltID->erase(*EmailCount);
+ EmailListAltID->insert(std::make_pair(*EmailCount, PropertyValue));
+
+ } else if (PropertyName == wxT("PID")){
+
+ EmailListPID->erase(*EmailCount);
+ EmailListPID->insert(std::make_pair(*EmailCount, PropertyValue));
+
+ } else if (PropertyName == wxT("PREF")){
+
+ int PriorityNumber = 0;
+ bool ValidNumber = TRUE;
+
+ try{
+ PriorityNumber = std::stoi(PropertyValue.ToStdString());
+ }
+
+ catch(std::invalid_argument &e){
+ ValidNumber = FALSE;
+ }
+
+ if (ValidNumber == TRUE){
+
+ EmailListPref->erase(*EmailCount);
+ EmailListPref->insert(std::make_pair(*EmailCount, PriorityNumber));
+
+ }
+
+ } else {
+
+ if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
+
+ if (FirstToken == TRUE){
+
+ PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
+ FirstToken = FALSE;
+
+ } else {
+
+ PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
+
+ }
+
+ }
+
+ }
+
+ }
+
+ EmailList->insert(std::make_pair(*EmailCount, PropertySeg2));
+
+ // Add the name token data.
+
+ if (!PropertyTokens.IsEmpty()){
+
+ EmailListTokens->insert(std::make_pair(*EmailCount, PropertyTokens));
+
+ }
+
+
+}
+
void SplitValues(wxString *PropertyLine,
std::map<int,int> *SplitPoints,
std::map<int,int> *SplitLength,
void ProcessAnniversary(wxString PropertySeg1, wxString PropertySeg2);
void ProcessTimeZone(wxString PropertySeg1, wxString PropertySeg2, int *TimeZoneCount);
void ProcessAddress(wxString PropertySeg1, wxString PropertySeg2, int *AddressCount);
+ void ProcessEmail(wxString PropertySeg1, wxString PropertySeg2, int *EmailCount);
};
ited Kingdom";LANGUAGE=en-GB;ALTID=45;PREF=10;PID=28;GEO="geo:7.0, 7.0";TZ=
Europe/Newquay;MEDIATYPE=text/plain;JAM=Red:;;7 Flyby Drive;Elaine;Cornwall
;PL84 9YE;United Kingdom
+EMAIL;ALTID=10;PID=20;PREF=40;WONDERFUL=Colour:moo@example.com
+EMAIL;TYPE=home;ALTID=5;PID=10;PREF=20;PEACE=quiet:moo.home@example.com
+EMAIL;TYPE=work;ALTID=1;PID=2;PREF=3;BUSINESS=Money:moo.business@example.com
END:VCARD
}
+
+TEST(ContactLoad, EmailTests){
+
+ ContactDataObject TestFile;
+
+ // Check that the vCard 4.0 file loads OK.
+
+ ASSERT_EQ(CONTACTLOAD_OK, TestFile.LoadFile("LoadCheck-Load4.vcf"));
+
+ std::map<int,wxString>::iterator TestFileIter;
+ std::map<int,int>::iterator TestFileIntIter;
+
+ // Start with the general email.
+
+ TestFileIter = TestFile.GeneralEmailList.find(0);
+ ASSERT_NE(TestFile.GeneralEmailList.end(), TestFileIter);
+ ASSERT_EQ("moo@example.com", TestFileIter->second);
+
+ // Check the ALTID section.
+
+ TestFileIter = TestFile.GeneralEmailListAltID.find(0);
+ ASSERT_NE(TestFile.GeneralEmailListAltID.end(), TestFileIter);
+ ASSERT_EQ("10", TestFileIter->second);
+
+ // Check the PID section.
+
+ TestFileIter = TestFile.GeneralEmailListPID.find(0);
+ ASSERT_NE(TestFile.GeneralEmailListPID.end(), TestFileIter);
+ ASSERT_EQ("20", TestFileIter->second);
+
+ // Check the PREF section.
+
+ TestFileIntIter = TestFile.GeneralEmailListPref.find(0);
+ ASSERT_NE(TestFile.GeneralEmailListPref.end(), TestFileIntIter);
+ ASSERT_EQ(40, TestFileIntIter->second);
+
+ // Check the extra tokens.
+
+ TestFileIter = TestFile.GeneralEmailListTokens.find(0);
+ ASSERT_NE(TestFile.GeneralEmailListTokens.end(), TestFileIter);
+ ASSERT_EQ("WONDERFUL=Colour", TestFileIter->second);
+
+ // Start with the home email.
+
+ TestFileIter = TestFile.HomeEmailList.find(1);
+ ASSERT_NE(TestFile.HomeEmailList.end(), TestFileIter);
+ ASSERT_EQ("moo.home@example.com", TestFileIter->second);
+
+ // Check the ALTID section.
+
+ TestFileIter = TestFile.HomeEmailListAltID.find(1);
+ ASSERT_NE(TestFile.HomeEmailListAltID.end(), TestFileIter);
+ ASSERT_EQ("5", TestFileIter->second);
+
+ // Check the PID section.
+
+ TestFileIter = TestFile.HomeEmailListPID.find(1);
+ ASSERT_NE(TestFile.HomeEmailListPID.end(), TestFileIter);
+ ASSERT_EQ("10", TestFileIter->second);
+
+ // Check the PREF section.
+
+ TestFileIntIter = TestFile.HomeEmailListPref.find(1);
+ ASSERT_NE(TestFile.HomeEmailListPref.end(), TestFileIntIter);
+ ASSERT_EQ(20, TestFileIntIter->second);
+
+ // Check the extra tokens.
+
+ TestFileIter = TestFile.HomeEmailListTokens.find(1);
+ ASSERT_NE(TestFile.HomeEmailListTokens.end(), TestFileIter);
+ ASSERT_EQ("PEACE=quiet", TestFileIter->second);
+
+ // Start with the business email.
+
+ TestFileIter = TestFile.BusinessEmailList.find(2);
+ ASSERT_NE(TestFile.BusinessEmailList.end(), TestFileIter);
+ ASSERT_EQ("moo.business@example.com", TestFileIter->second);
+
+ // Check the ALTID section.
+
+ TestFileIter = TestFile.BusinessEmailListAltID.find(2);
+ ASSERT_NE(TestFile.BusinessEmailListAltID.end(), TestFileIter);
+ ASSERT_EQ("1", TestFileIter->second);
+
+ // Check the PID section.
+
+ TestFileIter = TestFile.BusinessEmailListPID.find(2);
+ ASSERT_NE(TestFile.BusinessEmailListPID.end(), TestFileIter);
+ ASSERT_EQ("2", TestFileIter->second);
+
+ // Check the PREF section.
+
+ TestFileIntIter = TestFile.BusinessEmailListPref.find(2);
+ ASSERT_NE(TestFile.BusinessEmailListPref.end(), TestFileIntIter);
+ ASSERT_EQ(3, TestFileIntIter->second);
+
+ // Check the extra tokens.
+
+ TestFileIter = TestFile.BusinessEmailListTokens.find(2);
+ ASSERT_NE(TestFile.BusinessEmailListTokens.end(), TestFileIter);
+ ASSERT_EQ("BUSINESS=Money", TestFileIter->second);
+
+
+}
+
// TODO: Add tests for the Contact Loading process.
\ No newline at end of file