From bcb439d3cf90af362c4151f29830de6adce137fe Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Wed, 29 Jun 2016 18:18:25 +0100 Subject: [PATCH] Added EMAIL to the SaveString function of ContactDataObject --- .../cdo/ContactDataObject-Save.cpp | 85 +++++++++++++++++++ source/contacteditor/cdo/ContactDataObject.h | 4 + source/tests/xestiaab_contactsave.h | 3 + 3 files changed, 92 insertions(+) diff --git a/source/contacteditor/cdo/ContactDataObject-Save.cpp b/source/contacteditor/cdo/ContactDataObject-Save.cpp index c8a394a..61acdc0 100644 --- a/source/contacteditor/cdo/ContactDataObject-Save.cpp +++ b/source/contacteditor/cdo/ContactDataObject-Save.cpp @@ -282,6 +282,21 @@ ContactSaveStatus ContactDataObject::SaveString(wxString *SaveData){ &BusinessAddressListMediatype, &BusinessAddressListPref, &BusinessAddressListTokens, SaveData, "work"); + // Process EMAIL. + + SaveEmail(&GeneralEmailList, &GeneralEmailListAltID, + &GeneralEmailListPID, &GeneralEmailListType, + &GeneralEmailListPref, &GeneralEmailListTokens, + SaveData, ""); + SaveEmail(&HomeEmailList, &HomeEmailListAltID, + &HomeEmailListPID, &HomeEmailListType, + &HomeEmailListPref, &HomeEmailListTokens, + SaveData, "home"); + SaveEmail(&BusinessEmailList, &BusinessEmailListAltID, + &BusinessEmailListPID, &BusinessEmailListType, + &BusinessEmailListPref, &BusinessEmailListTokens, + SaveData, "work"); + // Write the end part of the vCard data file. SaveData->Append("END:VCARD"); @@ -741,4 +756,74 @@ void ContactDataObject::SaveAddress(map *AddressList, map *EmailList, map *EmailListAltID, + map *EmailListPID, map *EmailListType, + map *EmailListPref, map *EmailListTokens, + wxString *SaveData, wxString DataType){ + + wxString ProcessData = ""; + + for (std::map::iterator EmailIter = EmailList->begin(); + EmailIter != EmailList->end(); EmailIter++){ + + ProcessData.Append("EMAIL"); + + // Check if there is a value for TYPE. + + if (DataType.size() > 0){ + + ProcessData.Append(";TYPE="); + ProcessData.Append(DataType); + + } + + // Check if there is a value for ALTID. + + if ((*EmailListAltID)[EmailIter->first].size() > 0){ + + ProcessData.Append(";ALTID="); + ProcessData.Append((*EmailListAltID)[EmailIter->first]); + + } + + // Check if there is a value for PID. + + if ((*EmailListPID)[EmailIter->first].size() > 0){ + + ProcessData.Append(";PID="); + ProcessData.Append((*EmailListPID)[EmailIter->first]); + + } + + // Check if there is a value for PREF. + + if ((*EmailListPref)[EmailIter->first] > 0){ + + ProcessData.Append(";PREF="); + ProcessData.Append(wxString::Format("%i", (*EmailListPref)[EmailIter->first])); + + } + + // Check if there is a value for tokens. + + if ((*EmailListTokens)[EmailIter->first].size() > 0){ + + ProcessData.Append(";"); + ProcessData.Append((*EmailListTokens)[EmailIter->first]); + + } + + ProcessData.Append(":"); + ProcessData.Append(EmailIter->second); + ProcessData.Append("\n"); + + ProcessData = OutputText(&ProcessData); + + SaveData->Append(ProcessData); + ProcessData.clear(); + + } + } \ No newline at end of file diff --git a/source/contacteditor/cdo/ContactDataObject.h b/source/contacteditor/cdo/ContactDataObject.h index f12c17a..99b8fc9 100644 --- a/source/contacteditor/cdo/ContactDataObject.h +++ b/source/contacteditor/cdo/ContactDataObject.h @@ -122,6 +122,10 @@ class ContactDataObject{ map *AddressListTimezone, map *AddressListType, map *AddressListMediatype, map *AddressListPref, map *AddressListTokens, wxString *SaveData, wxString DataType); + void SaveEmail(map *EmailList, map *EmailListAltID, + map *EmailListPID, map *EmailListType, + map *EmailListPref, map *EmailListTokens, + wxString *SaveData, wxString DataType); public: diff --git a/source/tests/xestiaab_contactsave.h b/source/tests/xestiaab_contactsave.h index 5afdb83..30d4960 100644 --- a/source/tests/xestiaab_contactsave.h +++ b/source/tests/xestiaab_contactsave.h @@ -107,6 +107,9 @@ TEST(ContactSave, ContactSaveTests){ " all\\nPL84 9YE\\nCornwall\\nUnited Kingdom\";LANGUAGE=en-GB;MEDIATYPE=text/plain\n" " ;PID=28;PREF=10;TZ=Europe/Newquay;JAM=Red:;;7 Flyby Drive;Elaine;Cornwall;PL\n" " 84 9YE;United Kingdom\n" + "EMAIL;ALTID=10;PID=20;PREF=40;WONDERFUL=Colour:moo@example.com\n" + "EMAIL;TYPE=home;ALTID=5;PID=10;PREF=20;PEACE=quiet:moo.home@example.com\n" + "EMAIL;TYPE=work;ALTID=1;PID=2;PREF=3;BUSINESS=Money:moo.business@example.com\n" "END:VCARD"; ASSERT_EQ(CONTACTLOAD_OK, TestFile3.LoadFile("LoadCheck-Load4.vcf")); -- 2.39.5