From 83fda2e120ce19f7d4e64fb1a91229fcc5e67fbe Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Thu, 24 Jul 2008 18:27:34 -0400 Subject: [PATCH] Added opensync support for multiple contact email addresses --- ChangeLog | 1 + opensync-plugin/src/vcard.cc | 30 +++++++++++++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 29ceecd4..92dc091a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ Release: version 0.13 - 2008/07/?? - added g++ (>= 4.1) to Debian build dependency list - added support to base library and utilities for multiple email addresses in Contact records + - added opensync support for multiple contact email addresses 2008/07/16 - applied David Mansfield's opensync module password patch (ported manually to latest upcoming 0.13) diff --git a/opensync-plugin/src/vcard.cc b/opensync-plugin/src/vcard.cc index fc55c93f..db1c62d3 100644 --- a/opensync-plugin/src/vcard.cc +++ b/opensync-plugin/src/vcard.cc @@ -176,10 +176,20 @@ const std::string& vCard::ToVCard(const Barry::Contact &con) AddPhoneCond("cell", con.MobilePhone); AddPhoneCond("msg", con.Pager); - if( con.Email.size() ) { - vAttrPtr email = NewAttr("EMAIL", con.Email.c_str()); - AddParam(email, "TYPE", "internet"); - AddAttr(email); + // add all email addresses, marking first one as "pref" + Barry::Contact::EmailList::const_iterator eai = con.EmailAddresses.begin(); + for( unsigned int i = 0; eai != con.EmailAddresses.end(); ++eai, ++i ) { + const std::string& e = con.GetEmail(i); + if( e.size() ) { + vAttrPtr email = NewAttr("EMAIL", e.c_str()); + if( i == 0 ) { + AddParam(email, "TYPE", "internet,pref"); + } + else { + AddParam(email, "TYPE", "internet"); + } + AddAttr(email); + } } if( con.JobTitle.size() ) { @@ -286,10 +296,9 @@ const Barry::Contact& vCard::ToBarry(const char *vcard, uint32_t RecordId) con.Pager = tel.GetValue(); } - // scan for all email addresses... save the first one found - // by default, then overwrite it with any following email - // address if its type is set to "pref"... i.e. we want - // the preferred email address here. + // scan for all email addresses... append addresses to the + // list by default, but prepend if its type is set to "pref" + // i.e. we want the preferred email address first vAttr email = GetAttrObj("EMAIL"); for( int i = 0; email.Get(); email = GetAttrObj("EMAIL", ++i) ) { @@ -300,7 +309,10 @@ const Barry::Contact& vCard::ToBarry(const char *vcard, uint32_t RecordId) bool x400 = strstr(type.c_str(), "x400"); if( of_interest && !x400 ) { - con.Email = GetAttr("EMAIL"); + con.EmailAddresses.insert(con.EmailAddresses.begin(), email.GetValue()); + } + else { + con.EmailAddresses.push_back( email.GetValue() ); } } -- 2.11.4.GIT