Skip to content

Commit

Permalink
Fix recognizing vcards as vcards in incoming emails
Browse files Browse the repository at this point in the history
  • Loading branch information
Hocuri committed May 8, 2024
1 parent 1234336 commit 62b17f8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/mimeparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1920,16 +1920,11 @@ fn get_mime_type(
let mimetype = mail.ctype.mimetype.parse::<Mime>()?;

let viewtype = match mimetype.type_() {
mime::TEXT => {
if !is_attachment_disposition(mail) {
match mimetype.subtype() {
mime::PLAIN | mime::HTML => Viewtype::Text,
_ => Viewtype::File,
}
} else {
Viewtype::File
}
}
mime::TEXT => match mimetype.subtype() {
mime::VCARD => Viewtype::Vcard,
mime::PLAIN | mime::HTML if !is_attachment_disposition(mail) => Viewtype::Text,
_ => Viewtype::File,
},
mime::IMAGE => match mimetype.subtype() {
mime::GIF => Viewtype::Gif,
mime::SVG => Viewtype::File,
Expand Down
28 changes: 28 additions & 0 deletions src/receive_imf/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4455,3 +4455,31 @@ 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;

let mut msg = Message::new(Viewtype::Vcard);
msg.set_file_from_bytes(
alice,
"fiona.vcf",
b"BEGIN:VCARD\n\
VERSION:4.0\n\
FN:Fiona\n\
EMAIL;TYPE=work:fiona@example.org\n\
END:VCARD",
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;
assert_eq!(rcvd.viewtype, Viewtype::Vcard);

Ok(())
}

0 comments on commit 62b17f8

Please sign in to comment.