// frmContactEditor-LoadEmail.cpp - frmContactEditor load email subroutines. // // (c) 2012-2015 Xestia Software Development. // // This file is part of Xestia Address Book. // // Xestia Address Book is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by the // Free Software Foundation, version 3 of the license. // // Xestia Address Book is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with Xestia Address Book. If not, see #include "frmContactEditor.h" void frmContactEditor::LoadEmail(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *EmailCount){ size_t intPropertyLen = wxSPropertySeg1.Len(); std::map SplitPoints; std::map SplitLength; std::map::iterator SLiter; std::map::iterator SPoint; wxString PropertyData; wxString PropertyName; wxString PropertyValue; wxString PropertyTokens; wxString AddressLabel; wxString AddressLang; wxString AddressAltID; wxString AddressPID; wxString AddressTokens; wxString AddressGeo; wxString AddressTimezone; wxString AddressType; wxString AddressMediatype; wxString AddressPOBox; wxString AddressExtended; wxString AddressStreet; wxString AddressLocality; wxString AddressCity; wxString AddressRegion; wxString AddressPostalCode; wxString AddressCountry; bool FirstToken = TRUE; int intSplitsFound = 0; int intSplitSize = 0; int intPrevValue = 7; int intPref = 0; int intType = 0; long ListCtrlIndex; SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue); intPrevValue = 6; // Look for type before continuing. for (std::map::iterator intiter = SplitPoints.begin(); intiter != SplitPoints.end(); ++intiter){ SLiter = SplitLength.find(intiter->first); PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second)); wxStringTokenizer PropertyElement (PropertyData, wxT("=")); PropertyName = PropertyElement.GetNextToken(); PropertyValue = PropertyElement.GetNextToken(); intPrevValue = intiter->second; if (PropertyName == wxT("TYPE")){ if (PropertyValue == wxT("work")){ intType = 2; } else if (PropertyValue == wxT("home")){ intType = 1; } else { intType = 0; } } } // Setup blank lines for later on. if (intType == 0){ GeneralEmailList.insert(std::make_pair(intValueSeek, wxT(""))); GeneralEmailListAltID.insert(std::make_pair(intValueSeek, wxT(""))); GeneralEmailListPID.insert(std::make_pair(intValueSeek, wxT(""))); GeneralEmailListPref.insert(std::make_pair(intValueSeek, 0)); GeneralEmailListTokens.insert(std::make_pair(intValueSeek, wxT(""))); } else if (intType == 1){ HomeEmailList.insert(std::make_pair(intValueSeek, wxT(""))); HomeEmailListAltID.insert(std::make_pair(intValueSeek, wxT(""))); HomeEmailListPID.insert(std::make_pair(intValueSeek, wxT(""))); HomeEmailListPref.insert(std::make_pair(intValueSeek, 0)); HomeEmailListTokens.insert(std::make_pair(intValueSeek, wxT(""))); } else if (intType == 2){ BusinessEmailList.insert(std::make_pair(intValueSeek, wxT(""))); BusinessEmailListAltID.insert(std::make_pair(intValueSeek, wxT(""))); BusinessEmailListPID.insert(std::make_pair(intValueSeek, wxT(""))); BusinessEmailListPref.insert(std::make_pair(intValueSeek, 0)); BusinessEmailListTokens.insert(std::make_pair(intValueSeek, wxT(""))); } intPrevValue = 6; for (std::map::iterator intiter = SplitPoints.begin(); intiter != SplitPoints.end(); ++intiter){ SLiter = SplitLength.find(intiter->first); PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second)); wxStringTokenizer PropertyElement (PropertyData, wxT("=")); PropertyName = PropertyElement.GetNextToken(); PropertyValue = PropertyElement.GetNextToken(); intPrevValue = intiter->second; ProcessCaptureStrings(&PropertyValue); // Process properties. if (PropertyName == wxT("ALTID")){ if (intType == 0){ GeneralEmailListAltID.erase(intValueSeek); GeneralEmailListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeEmailListAltID.erase(intValueSeek); HomeEmailListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessEmailListAltID.erase(intValueSeek); BusinessEmailListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } } else if (PropertyName == wxT("PID")){ if (intType == 0){ GeneralEmailListPID.erase(intValueSeek); GeneralEmailListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeEmailListPID.erase(intValueSeek); HomeEmailListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessEmailListPID.erase(intValueSeek); BusinessEmailListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } } else if (PropertyName == wxT("PREF")){ intPref = wxAtoi(PropertyValue); if (intPref > 0 && intPref < 101){ if (intType == 0){ GeneralEmailListPref.erase(intValueSeek); GeneralEmailListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (intType == 1){ HomeEmailListPref.erase(intValueSeek); HomeEmailListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (intType == 2){ BusinessEmailListPref.erase(intValueSeek); BusinessEmailListPref.insert(std::make_pair(intValueSeek, intPref)); } } } else { // Something else we don't know about so append // to the tokens variable. 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); } } } } //std::map::iterator SLiter; intPropertyLen = wxSPropertySeg2.Len(); SplitPoints.clear(); SplitLength.clear(); intSplitsFound = 0; intSplitSize = 0; intPrevValue = 0; // Add the data to the General/Home/Work email variables. ProcessCaptureStrings(&wxSPropertySeg2); wxListItem coldata; coldata.SetId(intValueSeek); coldata.SetData(intValueSeek); coldata.SetText(wxSPropertySeg2); if (intType == 0){ ListCtrlIndex = lboEmails->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboEmails->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } GeneralEmailList.erase(intValueSeek); GeneralEmailListType.erase(intValueSeek); GeneralEmailListTokens.erase(intValueSeek); GeneralEmailList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); GeneralEmailListType.insert(std::make_pair(intValueSeek, wxT(""))); GeneralEmailListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); } else if (intType == 1){ ListCtrlIndex = lboHomeEmails->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboHomeEmails->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } HomeEmailList.erase(intValueSeek); HomeEmailListType.erase(intValueSeek); HomeEmailListTokens.erase(intValueSeek); HomeEmailList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); HomeEmailListType.insert(std::make_pair(intValueSeek, wxT("home"))); HomeEmailListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); } else if (intType == 2){ ListCtrlIndex = lboBusinessEmail->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboBusinessEmail->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } BusinessEmailList.erase(intValueSeek); BusinessEmailListType.erase(intValueSeek); BusinessEmailListTokens.erase(intValueSeek); BusinessEmailList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); BusinessEmailListType.insert(std::make_pair(intValueSeek, wxT("work"))); BusinessEmailListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); } EmailCount++; intValueSeek++; }