fix: use CRLF newlines in vCards

This is a requirement from
<https://datatracker.ietf.org/doc/html/rfc6350#section-3.2>
This commit is contained in:
link2xt
2025-01-29 22:46:03 +00:00
committed by l
parent 0c0afead2c
commit e22d980845

View File

@@ -78,21 +78,21 @@ pub fn make_vcard(contacts: &[VcardContact]) -> String {
let addr = &c.addr; let addr = &c.addr;
let display_name = c.display_name(); let display_name = c.display_name();
res += &format!( res += &format!(
"BEGIN:VCARD\n\ "BEGIN:VCARD\r\n\
VERSION:4.0\n\ VERSION:4.0\r\n\
EMAIL:{addr}\n\ EMAIL:{addr}\r\n\
FN:{display_name}\n" FN:{display_name}\r\n"
); );
if let Some(key) = &c.key { if let Some(key) = &c.key {
res += &format!("KEY:data:application/pgp-keys;base64,{key}\n"); res += &format!("KEY:data:application/pgp-keys;base64,{key}\r\n");
} }
if let Some(profile_image) = &c.profile_image { if let Some(profile_image) = &c.profile_image {
res += &format!("PHOTO:data:image/jpeg;base64,{profile_image}\n"); res += &format!("PHOTO:data:image/jpeg;base64,{profile_image}\r\n");
} }
if let Some(timestamp) = format_timestamp(c) { if let Some(timestamp) = format_timestamp(c) {
res += &format!("REV:{timestamp}\n"); res += &format!("REV:{timestamp}\r\n");
} }
res += "END:VCARD\n"; res += "END:VCARD\r\n";
} }
res res
} }
@@ -559,20 +559,20 @@ END:VCARD",
}, },
]; ];
let items = [ let items = [
"BEGIN:VCARD\n\ "BEGIN:VCARD\r\n\
VERSION:4.0\n\ VERSION:4.0\r\n\
EMAIL:alice@example.org\n\ EMAIL:alice@example.org\r\n\
FN:Alice Wonderland\n\ FN:Alice Wonderland\r\n\
KEY:data:application/pgp-keys;base64,[base64-data]\n\ KEY:data:application/pgp-keys;base64,[base64-data]\r\n\
PHOTO:data:image/jpeg;base64,image in Base64\n\ PHOTO:data:image/jpeg;base64,image in Base64\r\n\
REV:20240418T184242Z\n\ REV:20240418T184242Z\r\n\
END:VCARD\n", END:VCARD\r\n",
"BEGIN:VCARD\n\ "BEGIN:VCARD\r\n\
VERSION:4.0\n\ VERSION:4.0\r\n\
EMAIL:bob@example.com\n\ EMAIL:bob@example.com\r\n\
FN:bob@example.com\n\ FN:bob@example.com\r\n\
REV:19700101T000000Z\n\ REV:19700101T000000Z\r\n\
END:VCARD\n", END:VCARD\r\n",
]; ];
let mut expected = "".to_string(); let mut expected = "".to_string();
for len in 0..=contacts.len() { for len in 0..=contacts.len() {