api: Add Viewtype::Vcard (#5202)

Co-authored-by: Hocuri <hocuri@gmx.de>
This commit is contained in:
iequidoo
2024-05-06 03:35:45 -03:00
committed by iequidoo
parent 95238b6e17
commit 22f01a2699
10 changed files with 143 additions and 29 deletions

View File

@@ -4552,3 +4552,58 @@ async fn test_list_from() -> Result<()> {
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_receive_vcard() -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = tcm.alice().await;
let bob = tcm.bob().await;
for vcard_contains_address in [true, false] {
let mut msg = Message::new(Viewtype::Vcard);
msg.set_file_from_bytes(
&alice,
"claire.vcf",
format!(
"BEGIN:VCARD\n\
VERSION:4.0\n\
FN:Claire\n\
{}\
END:VCARD",
if vcard_contains_address {
"EMAIL;TYPE=work:claire@example.org\n"
} else {
""
}
)
.as_bytes(),
None,
)
.await
.unwrap();
let alice_bob_chat = alice.create_chat(&bob).await;
let sent = alice.send_msg(alice_bob_chat.id, &mut msg).await;
let rcvd = bob.recv_msg(&sent).await;
if vcard_contains_address {
assert_eq!(rcvd.viewtype, Viewtype::Vcard);
} else {
// VCards without an email address are not "deltachat contacts",
// so they are shown as files
assert_eq!(rcvd.viewtype, Viewtype::File);
}
let vcard = tokio::fs::read(rcvd.get_file(&bob).unwrap()).await?;
let vcard = std::str::from_utf8(&vcard)?;
let parsed = deltachat_contact_tools::parse_vcard(vcard);
assert_eq!(parsed.len(), 1);
if vcard_contains_address {
assert_eq!(&parsed[0].addr, "claire@example.org");
} else {
assert_eq!(&parsed[0].addr, "");
}
}
Ok(())
}