From 5f3b7b31e7efe9757b834fe9c0e3df178031ab9a Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 27 Apr 2018 13:46:24 +0200 Subject: [PATCH 1/2] Add support for storing email properties We have to move the `Email` type at the bottom of the DeserVcard type because it contains a table and we must emit tables as last values when de/serializing. Maybe this will shoot us in the foot later, but only with TOML I guess. We'll see. For now, this is good. For that we need to update a dependency: vobject -> 0.5 --- lib/domain/libimagcontact/Cargo.toml | 2 +- lib/domain/libimagcontact/src/deser.rs | 34 ++++++++++++++++++++------ 2 files changed, 28 insertions(+), 8 deletions(-) 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 } From 713621337f7f71e583e5a3ab2dd3d5a83040486f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 27 Apr 2018 13:48:18 +0200 Subject: [PATCH 2/2] Adapt for new libimagcontact interface --- bin/domain/imag-contact/src/main.rs | 2 +- bin/domain/imag-contact/src/util.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/domain/imag-contact/src/main.rs b/bin/domain/imag-contact/src/main.rs index 86c98457..06488e75 100644 --- a/bin/domain/imag-contact/src/main.rs +++ b/bin/domain/imag-contact/src/main.rs @@ -277,7 +277,7 @@ fn find(rt: &Runtime) { }; let take = card.adr().iter().any(|a| str_contains_any(a, &grepstring)) - || card.email().iter().any(|a| str_contains_any(a, &grepstring)) + || card.email().iter().any(|a| str_contains_any(&a.address, &grepstring)) || card.fullname().iter().any(|a| str_contains_any(a, &grepstring)); if take { diff --git a/bin/domain/imag-contact/src/util.rs b/bin/domain/imag-contact/src/util.rs index 91e00783..61409941 100644 --- a/bin/domain/imag-contact/src/util.rs +++ b/bin/domain/imag-contact/src/util.rs @@ -45,7 +45,7 @@ pub fn build_data_object_for_handlebars<'a>(i: usize, vcard: &DeserVcard) -> BTr data.insert("BDAY" , process_opt(vcard.bday())); data.insert("CATEGORIES" , process_list(vcard.categories())); data.insert("CLIENTPIDMAP" , process_opt(vcard.clientpidmap())); - data.insert("EMAIL" , process_list(vcard.email())); + data.insert("EMAIL" , process_list(&vcard.email().iter().map(|a| a.address.clone()).collect())); data.insert("FN" , process_list(vcard.fullname())); data.insert("GENDER" , process_opt(vcard.gender())); data.insert("GEO" , process_list(vcard.geo()));