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
};
let object = AddressObject::from_vcf(body)?;
assert_eq!(object.get_id(), object_id);
let object = AddressObject::from_vcf(object_id, body)?;
addr_store
.put_object(principal, addressbook_id, object, overwrite)
.await?;

View File

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

View File

@@ -20,17 +20,7 @@ impl TryFrom<AddressObjectRow> for AddressObject {
type Error = rustical_store::Error;
fn try_from(value: AddressObjectRow) -> Result<Self, Self::Error> {
let object = Self::from_vcf(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)
Ok(Self::from_vcf(value.id, value.vcf)?)
}
}