mirror of
https://github.com/chatmail/core.git
synced 2026-04-20 23:16:30 +03:00
feat: Check images passed as File before making them Image
We don't want images having unsupported format or corrupted ones to be sent as `Image` and appear in the "Images" tab in UIs because they can't be displayed correctly.
This commit is contained in:
@@ -3727,18 +3727,26 @@ async fn test_nonimage_with_png_ext() -> Result<()> {
|
||||
|
||||
let bytes = include_bytes!("../../test-data/message/thunderbird_with_autocrypt.eml");
|
||||
let file = alice.get_blobdir().join("screenshot.png");
|
||||
tokio::fs::write(&file, bytes).await?;
|
||||
|
||||
let mut msg = Message::new(Viewtype::Image);
|
||||
msg.set_file_and_deduplicate(alice, &file, Some("screenshot.png"), None)?;
|
||||
let sent_msg = alice.send_msg(alice_chat.get_id(), &mut msg).await;
|
||||
assert_eq!(msg.viewtype, Viewtype::File);
|
||||
assert_eq!(msg.get_filemime().unwrap(), "application/octet-stream");
|
||||
assert!(!msg.get_filename().unwrap().contains("screenshot"));
|
||||
let msg_bob = bob.recv_msg(&sent_msg).await;
|
||||
assert_eq!(msg_bob.viewtype, Viewtype::File);
|
||||
assert_eq!(msg_bob.get_filemime().unwrap(), "application/octet-stream");
|
||||
assert!(!msg_bob.get_filename().unwrap().contains("screenshot"));
|
||||
for vt in [Viewtype::Image, Viewtype::File] {
|
||||
tokio::fs::write(&file, bytes).await?;
|
||||
let mut msg = Message::new(vt);
|
||||
msg.set_file_and_deduplicate(alice, &file, Some("screenshot.png"), None)?;
|
||||
let sent_msg = alice.send_msg(alice_chat.get_id(), &mut msg).await;
|
||||
assert_eq!(msg.viewtype, Viewtype::File);
|
||||
assert_eq!(msg.get_filemime().unwrap(), "application/octet-stream");
|
||||
assert_eq!(
|
||||
msg.get_filename().unwrap().contains("screenshot"),
|
||||
vt == Viewtype::File
|
||||
);
|
||||
let msg_bob = bob.recv_msg(&sent_msg).await;
|
||||
assert_eq!(msg_bob.viewtype, Viewtype::File);
|
||||
assert_eq!(msg_bob.get_filemime().unwrap(), "application/octet-stream");
|
||||
assert_eq!(
|
||||
msg_bob.get_filename().unwrap().contains("screenshot"),
|
||||
vt == Viewtype::File
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user