mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
Implement PUT method for addressbook import
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use crate::{CalDateTime, LOCAL_DATE};
|
||||
use crate::{CalendarObject, Error};
|
||||
use chrono::Datelike;
|
||||
use ical::generator::Emitter;
|
||||
use ical::parser::{
|
||||
Component,
|
||||
vcard::{self, component::VcardContact},
|
||||
@@ -15,6 +16,21 @@ pub struct AddressObject {
|
||||
vcard: VcardContact,
|
||||
}
|
||||
|
||||
impl TryFrom<VcardContact> for AddressObject {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(vcard: VcardContact) -> Result<Self, Self::Error> {
|
||||
let id = vcard
|
||||
.get_property("UID")
|
||||
.ok_or(Error::InvalidData("Missing UID".to_owned()))?
|
||||
.value
|
||||
.clone()
|
||||
.ok_or(Error::InvalidData("Missing UID".to_owned()))?;
|
||||
let vcf = vcard.generate();
|
||||
Ok(Self { id, vcf, vcard })
|
||||
}
|
||||
}
|
||||
|
||||
impl AddressObject {
|
||||
pub fn from_vcf(object_id: String, vcf: String) -> Result<Self, Error> {
|
||||
let mut parser = vcard::VcardParser::new(BufReader::new(vcf.as_bytes()));
|
||||
|
||||
Reference in New Issue
Block a user