carddav: Remove enforcement of UID matching filename (Apple Contacts doesn't play well)

This commit is contained in:
Lennart
2025-08-23 19:42:58 +02:00
parent 94ace71745
commit 1e90ff3d6c
3 changed files with 15 additions and 26 deletions

View File

@@ -86,8 +86,7 @@ pub async fn put_object<AS: AddressbookStore>(
true true
}; };
let object = AddressObject::from_vcf(body)?; let object = AddressObject::from_vcf(object_id, body)?;
assert_eq!(object.get_id(), object_id);
addr_store addr_store
.put_object(principal, addressbook_id, object, overwrite) .put_object(principal, addressbook_id, object, overwrite)
.await?; .await?;

View File

@@ -11,6 +11,7 @@ use std::{collections::HashMap, io::BufReader};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct AddressObject { pub struct AddressObject {
id: String,
vcf: String, vcf: String,
vcard: VcardContact, vcard: VcardContact,
} }
@@ -19,16 +20,21 @@ impl TryFrom<VcardContact> for AddressObject {
type Error = Error; type Error = Error;
fn try_from(vcard: VcardContact) -> Result<Self, Self::Error> { fn try_from(vcard: VcardContact) -> Result<Self, Self::Error> {
if vcard.get_uid().is_none() { let uid = vcard
return Err(Error::InvalidData("missing UID".to_owned())); .get_uid()
} .ok_or(Error::InvalidData("missing UID".to_owned()))?
.to_owned();
let vcf = vcard.generate(); let vcf = vcard.generate();
Ok(Self { vcf, vcard }) Ok(Self {
vcf,
vcard,
id: uid,
})
} }
} }
impl AddressObject { impl AddressObject {
pub fn from_vcf(vcf: String) -> Result<Self, Error> { pub fn from_vcf(id: String, vcf: String) -> Result<Self, Error> {
let mut parser = vcard::VcardParser::new(BufReader::new(vcf.as_bytes())); let mut parser = vcard::VcardParser::new(BufReader::new(vcf.as_bytes()));
let vcard = parser.next().ok_or(Error::MissingContact)??; let vcard = parser.next().ok_or(Error::MissingContact)??;
if parser.next().is_some() { if parser.next().is_some() {
@@ -36,17 +42,11 @@ impl AddressObject {
"multiple vcards, only one allowed".to_owned(), "multiple vcards, only one allowed".to_owned(),
)); ));
} }
Ok(Self { id, vcf, vcard })
if vcard.get_uid().is_none() {
return Err(Error::InvalidData("missing UID".to_owned()));
}
Ok(Self { vcf, vcard })
} }
pub fn get_id(&self) -> &str { pub fn get_id(&self) -> &str {
self.vcard &self.id
.get_uid()
.expect("We've validated before that UID exists")
} }
pub fn get_etag(&self) -> String { pub fn get_etag(&self) -> String {

View File

@@ -20,17 +20,7 @@ impl TryFrom<AddressObjectRow> for AddressObject {
type Error = rustical_store::Error; type Error = rustical_store::Error;
fn try_from(value: AddressObjectRow) -> Result<Self, Self::Error> { fn try_from(value: AddressObjectRow) -> Result<Self, Self::Error> {
let object = Self::from_vcf(value.vcf)?; Ok(Self::from_vcf(value.id, value.vcf)?)
if object.get_id() != value.id {
return Err(rustical_store::Error::IcalError(
rustical_ical::Error::InvalidData(format!(
"object_id={} and UID={} don't match",
object.get_id(),
value.id
)),
));
}
Ok(object)
} }
} }