diff --git a/lib/domain/libimagcontact/Cargo.toml b/lib/domain/libimagcontact/Cargo.toml index d295248a..c45979db 100644 --- a/lib/domain/libimagcontact/Cargo.toml +++ b/lib/domain/libimagcontact/Cargo.toml @@ -24,7 +24,7 @@ error-chain = "0.11" log = "0.3" toml = "0.4" toml-query = "0.6" -vobject = "0.4" +vobject = "0.5" uuid = "0.6" serde = "1" serde_derive = "1" diff --git a/lib/domain/libimagcontact/src/deser.rs b/lib/domain/libimagcontact/src/deser.rs index aa1dc806..44044142 100644 --- a/lib/domain/libimagcontact/src/deser.rs +++ b/lib/domain/libimagcontact/src/deser.rs @@ -17,8 +17,28 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // +use std::collections::BTreeMap; + use vobject::vcard::Vcard; +#[derive(Serialize, Deserialize, Debug)] +pub struct Email { + pub address: String, + + #[serde(skip_serializing_if = "BTreeMap::is_empty")] + #[serde(default)] + pub properties: BTreeMap, +} + +impl From<::vobject::vcard::Email> for Email { + fn from(voemail: ::vobject::vcard::Email) -> Self { + let address = voemail.raw().clone(); + let properties = voemail.params().clone(); + + Email { address, properties } + } +} + /// A type which can be build from a Vcard and be serialized. #[derive(Serialize, Deserialize, Debug)] pub struct DeserVcard { @@ -43,10 +63,6 @@ pub struct DeserVcard { #[serde(default)] clientpidmap : Option, - #[serde(skip_serializing_if = "Vec::is_empty")] - #[serde(default)] - email : Vec, - #[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default)] fullname : Vec, @@ -141,7 +157,11 @@ pub struct DeserVcard { #[serde(skip_serializing_if = "Option::is_none")] #[serde(default)] - version : Option + version : Option, + + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + email : Vec, } impl From for DeserVcard { @@ -163,7 +183,7 @@ impl From for DeserVcard { bday : optstr!(card.bday()), categories : arystr!(card.categories()), clientpidmap : optstr!(card.clientpidmap()), - email : arystr!(card.email()), + email : card.email().into_iter().map(Email::from).collect::>(), fullname : arystr!(card.fullname()), gender : optstr!(card.gender()), geo : arystr!(card.geo()), @@ -214,7 +234,7 @@ impl DeserVcard { self.clientpidmap.as_ref() } - pub fn email(&self) -> &Vec { + pub fn email(&self) -> &Vec { &self.email }