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
This commit is contained in:
parent
bfd536d3fb
commit
5f3b7b31e7
2 changed files with 28 additions and 8 deletions
|
@ -24,7 +24,7 @@ error-chain = "0.11"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
toml = "0.4"
|
toml = "0.4"
|
||||||
toml-query = "0.6"
|
toml-query = "0.6"
|
||||||
vobject = "0.4"
|
vobject = "0.5"
|
||||||
uuid = "0.6"
|
uuid = "0.6"
|
||||||
serde = "1"
|
serde = "1"
|
||||||
serde_derive = "1"
|
serde_derive = "1"
|
||||||
|
|
|
@ -17,8 +17,28 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use vobject::vcard::Vcard;
|
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<String, String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
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.
|
/// A type which can be build from a Vcard and be serialized.
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct DeserVcard {
|
pub struct DeserVcard {
|
||||||
|
@ -43,10 +63,6 @@ pub struct DeserVcard {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
clientpidmap : Option<String>,
|
clientpidmap : Option<String>,
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
|
||||||
#[serde(default)]
|
|
||||||
email : Vec<String>,
|
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
fullname : Vec<String>,
|
fullname : Vec<String>,
|
||||||
|
@ -141,7 +157,11 @@ pub struct DeserVcard {
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
version : Option<String>
|
version : Option<String>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||||
|
#[serde(default)]
|
||||||
|
email : Vec<Email>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Vcard> for DeserVcard {
|
impl From<Vcard> for DeserVcard {
|
||||||
|
@ -163,7 +183,7 @@ impl From<Vcard> for DeserVcard {
|
||||||
bday : optstr!(card.bday()),
|
bday : optstr!(card.bday()),
|
||||||
categories : arystr!(card.categories()),
|
categories : arystr!(card.categories()),
|
||||||
clientpidmap : optstr!(card.clientpidmap()),
|
clientpidmap : optstr!(card.clientpidmap()),
|
||||||
email : arystr!(card.email()),
|
email : card.email().into_iter().map(Email::from).collect::<Vec<Email>>(),
|
||||||
fullname : arystr!(card.fullname()),
|
fullname : arystr!(card.fullname()),
|
||||||
gender : optstr!(card.gender()),
|
gender : optstr!(card.gender()),
|
||||||
geo : arystr!(card.geo()),
|
geo : arystr!(card.geo()),
|
||||||
|
@ -214,7 +234,7 @@ impl DeserVcard {
|
||||||
self.clientpidmap.as_ref()
|
self.clientpidmap.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn email(&self) -> &Vec<String> {
|
pub fn email(&self) -> &Vec<Email> {
|
||||||
&self.email
|
&self.email
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue