Implement PUT method for addressbook import

This commit is contained in:
Lennart
2025-06-10 23:43:53 +02:00
parent 80cca7b7b2
commit a20e9800bd
8 changed files with 108 additions and 0 deletions

View File

@@ -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()));