int TimeZoneCount = 0;
int AddressCount = 0;
int EmailCount = 0;
+ int IMCount = 0;
wxString ContactLine;
wxString PropertyLine;
wxString PropertySeg1;
ProcessEmail(PropertySeg1, PropertySeg2, &EmailCount);
EmailCount++;
+ } else if (Property == wxT("IMPP")){
+
+ // See frmContactEditor-LoadIM.cpp
+
+ ProcessIM(PropertySeg1, PropertySeg2, &IMCount);
+ IMCount++;
+
}
}
intPrevValue = 9;
- PropertyType PropType;
+ PropertyType PropType = PROPERTY_NONE;
// Look for type before continuing.
intPrevValue = 3;
- PropertyType PropType;
+ PropertyType PropType = PROPERTY_NONE;
// Look for type before continuing.
intPrevValue = 4;
- PropertyType PropType;
-
+ PropertyType PropType = PROPERTY_NONE;
+
// Look for type before continuing.
CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
intPrevValue = 6;
- PropertyType PropType;
-
+ PropertyType PropType = PROPERTY_NONE;
+
// Look for type before continuing.
CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
}
+void ContactDataObject::ProcessIM(wxString PropertySeg1, wxString PropertySeg2, int *IMCount){
+
+ std::map<int, int> SplitPoints;
+ std::map<int, int> SplitLength;
+
+ int intPrevValue = 6;
+ int intPref = 0;
+
+ SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
+
+ intPrevValue = 5;
+
+ PropertyType PropType = PROPERTY_NONE;
+
+ // Look for type before continuing.
+
+ CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
+
+ std::map<int, wxString> *IMList = NULL;
+ std::map<int, wxString> *IMListType = NULL;
+ std::map<int, wxString> *IMListAltID = NULL;
+ std::map<int, wxString> *IMListPID = NULL;
+ std::map<int, wxString> *IMListTokens = NULL;
+ std::map<int, wxString> *IMListMediatype = NULL;
+ std::map<int, int> *IMListPref = NULL;
+
+ switch(PropType){
+ case PROPERTY_NONE:
+ IMList = &GeneralIMList;
+ IMListType = &GeneralIMListType;
+ IMListAltID = &GeneralIMListAltID;
+ IMListPID = &GeneralIMListPID;
+ IMListTokens = &GeneralIMListTokens;
+ IMListMediatype = &GeneralIMListMediatype;
+ IMListPref = &GeneralIMListPref;
+ break;
+ case PROPERTY_HOME:
+ IMList = &HomeIMList;
+ IMListType = &HomeIMListType;
+ IMListAltID = &HomeIMListAltID;
+ IMListPID = &HomeIMListPID;
+ IMListTokens = &HomeIMListTokens;
+ IMListMediatype = &HomeIMListMediatype;
+ IMListPref = &HomeIMListPref;
+ break;
+ case PROPERTY_WORK:
+ IMList = &BusinessIMList;
+ IMListType = &BusinessIMListType;
+ IMListAltID = &BusinessIMListAltID;
+ IMListPID = &BusinessIMListPID;
+ IMListTokens = &BusinessIMListTokens;
+ IMListMediatype = &BusinessIMListMediatype;
+ IMListPref = &BusinessIMListPref;
+ break;
+ }
+
+ intPrevValue = 5;
+
+ 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")){
+
+ IMListAltID->erase(*IMCount);
+ IMListAltID->insert(std::make_pair(*IMCount, PropertyValue));
+
+ } else if (PropertyName == wxT("PID")){
+
+ IMListPID->erase(*IMCount);
+ IMListPID->insert(std::make_pair(*IMCount, PropertyValue));
+
+ } else if (PropertyName == wxT("MEDIATYPE")){
+
+ IMListMediatype->erase(*IMCount);
+ IMListMediatype->insert(std::make_pair(*IMCount, 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){
+
+ IMListPref->erase(*IMCount);
+ IMListPref->insert(std::make_pair(*IMCount, 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);
+
+ }
+
+ }
+
+ }
+
+ }
+
+ IMList->insert(std::make_pair(*IMCount, PropertySeg2));
+
+ // Add the name token data.
+
+ if (!PropertyTokens.IsEmpty()){
+
+ IMListTokens->insert(std::make_pair(*IMCount, PropertyTokens));
+
+ }
+
+}
+
void SplitValues(wxString *PropertyLine,
std::map<int,int> *SplitPoints,
std::map<int,int> *SplitLength,
void ProcessTimeZone(wxString PropertySeg1, wxString PropertySeg2, int *TimeZoneCount);
void ProcessAddress(wxString PropertySeg1, wxString PropertySeg2, int *AddressCount);
void ProcessEmail(wxString PropertySeg1, wxString PropertySeg2, int *EmailCount);
+ void ProcessIM(wxString PropertySeg1, wxString PropertySeg2, int *IMCount);
};
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
+IMPP;ALTID=10;PID=20;MEDIATYPE=text/plain;PREF=40;WONDERFUL=Colour:moo@examp
+ le.com
+IMPP;TYPE=home;ALTID=20;PID=40;PREF=80;MEDIATYPE=text/reallyplain;PEACE=quie
+ t:moo.home@example.com
+IMPP;TYPE=work;ALTID=98;PID=99;PREF=50;MEDIATYPE=text/superplain;BUSINESS=Mo
+ ney:moo.business@example.com
END:VCARD
ASSERT_NE(TestFile.BusinessEmailListTokens.end(), TestFileIter);
ASSERT_EQ("BUSINESS=Money", TestFileIter->second);
+}
+
+TEST(ContactLoad, IMTests){
+
+ 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 IM.
+
+ TestFileIter = TestFile.GeneralIMList.find(0);
+ ASSERT_NE(TestFile.GeneralIMList.end(), TestFileIter);
+ ASSERT_EQ("moo@example.com", TestFileIter->second);
+
+ // Check the ALTID section.
+
+ TestFileIter = TestFile.GeneralIMListAltID.find(0);
+ ASSERT_NE(TestFile.GeneralIMListAltID.end(), TestFileIter);
+ ASSERT_EQ("10", TestFileIter->second);
+
+ // Check the PID section.
+
+ TestFileIter = TestFile.GeneralIMListPID.find(0);
+ ASSERT_NE(TestFile.GeneralIMListPID.end(), TestFileIter);
+ ASSERT_EQ("20", TestFileIter->second);
+
+ // Check the MEDIATYPE section.
+
+ TestFileIter = TestFile.GeneralIMListMediatype.find(0);
+ ASSERT_NE(TestFile.GeneralIMListMediatype.end(), TestFileIter);
+ ASSERT_EQ("text/plain", TestFileIter->second);
+
+ // Check the PREF section.
+
+ TestFileIntIter = TestFile.GeneralIMListPref.find(0);
+ ASSERT_NE(TestFile.GeneralIMListPref.end(), TestFileIntIter);
+ ASSERT_EQ(40, TestFileIntIter->second);
+
+ // Check the extra tokens.
+
+ TestFileIter = TestFile.GeneralIMListTokens.find(0);
+ ASSERT_NE(TestFile.GeneralIMListTokens.end(), TestFileIter);
+ ASSERT_EQ("WONDERFUL=Colour", TestFileIter->second);
+
+ // Start with the home IM.
+
+ TestFileIter = TestFile.HomeIMList.find(1);
+ ASSERT_NE(TestFile.HomeIMList.end(), TestFileIter);
+ ASSERT_EQ("moo.home@example.com", TestFileIter->second);
+
+ // Check the ALTID section.
+
+ TestFileIter = TestFile.HomeIMListAltID.find(1);
+ ASSERT_NE(TestFile.HomeIMListAltID.end(), TestFileIter);
+ ASSERT_EQ("20", TestFileIter->second);
+
+ // Check the PID section.
+
+ TestFileIter = TestFile.HomeIMListPID.find(1);
+ ASSERT_NE(TestFile.HomeIMListPID.end(), TestFileIter);
+ ASSERT_EQ("40", TestFileIter->second);
+
+ // Check the MEDIATYPE section.
+
+ TestFileIter = TestFile.HomeIMListMediatype.find(1);
+ ASSERT_NE(TestFile.HomeIMListMediatype.end(), TestFileIter);
+ ASSERT_EQ("text/reallyplain", TestFileIter->second);
+
+ // Check the PREF section.
+
+ TestFileIntIter = TestFile.HomeIMListPref.find(1);
+ ASSERT_NE(TestFile.HomeIMListPref.end(), TestFileIntIter);
+ ASSERT_EQ(80, TestFileIntIter->second);
+
+ // Check the extra tokens.
+
+ TestFileIter = TestFile.HomeIMListTokens.find(1);
+ ASSERT_NE(TestFile.HomeIMListTokens.end(), TestFileIter);
+ ASSERT_EQ("PEACE=quiet", TestFileIter->second);
+
+ // Start with the business IM.
+
+ TestFileIter = TestFile.BusinessIMList.find(2);
+ ASSERT_NE(TestFile.BusinessIMList.end(), TestFileIter);
+ ASSERT_EQ("moo.business@example.com", TestFileIter->second);
+
+ // Check the ALTID section.
+
+ TestFileIter = TestFile.BusinessIMListAltID.find(2);
+ ASSERT_NE(TestFile.BusinessIMListAltID.end(), TestFileIter);
+ ASSERT_EQ("98", TestFileIter->second);
+
+ // Check the PID section.
+
+ TestFileIter = TestFile.BusinessIMListPID.find(2);
+ ASSERT_NE(TestFile.BusinessIMListPID.end(), TestFileIter);
+ ASSERT_EQ("99", TestFileIter->second);
+
+ // Check the MEDIATYPE section.
+
+ TestFileIter = TestFile.BusinessIMListMediatype.find(2);
+ ASSERT_NE(TestFile.BusinessIMListMediatype.end(), TestFileIter);
+ ASSERT_EQ("text/superplain", TestFileIter->second);
+
+ // Check the PREF section.
+
+ TestFileIntIter = TestFile.BusinessIMListPref.find(2);
+ ASSERT_NE(TestFile.BusinessIMListPref.end(), TestFileIntIter);
+ ASSERT_EQ(50, TestFileIntIter->second);
+
+ // Check the extra tokens.
+
+ TestFileIter = TestFile.BusinessIMListTokens.find(2);
+ ASSERT_NE(TestFile.BusinessIMListTokens.end(), TestFileIter);
+ ASSERT_EQ("BUSINESS=Money", TestFileIter->second);
}