mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 19:06:35 +03:00
fix!: Use Viewtype::File for messages with invalid images, images of unknown size, images > 50 Mpx (#6825)
BREAKING CHANGE: messages with invalid images, images of unknown size, huge images, will have Viewtype::File After changing the logic of Viewtype selection, I had to fix 3 old tests that used invalid Base64 image data. Co-authored-by: iequidoo <117991069+iequidoo@users.noreply.github.com>
This commit is contained in:
@@ -1393,6 +1393,20 @@ impl MimeMessage {
|
||||
} else {
|
||||
Viewtype::File
|
||||
}
|
||||
} else if msg_type == Viewtype::Image
|
||||
|| msg_type == Viewtype::Gif
|
||||
|| msg_type == Viewtype::Sticker
|
||||
{
|
||||
match get_filemeta(decoded_data) {
|
||||
// image size is known, not too big, keep msg_type:
|
||||
Ok((width, height)) if width * height <= constants::MAX_RCVD_IMAGE_PIXELS => {
|
||||
part.param.set_i64(Param::Width, width.into());
|
||||
part.param.set_i64(Param::Height, height.into());
|
||||
msg_type
|
||||
}
|
||||
// image is too big or size is unknown, display as file:
|
||||
_ => Viewtype::File,
|
||||
}
|
||||
} else {
|
||||
msg_type
|
||||
};
|
||||
@@ -1413,13 +1427,6 @@ impl MimeMessage {
|
||||
};
|
||||
info!(context, "added blobfile: {:?}", blob.as_name());
|
||||
|
||||
if mime_type.type_() == mime::IMAGE {
|
||||
if let Ok((width, height)) = get_filemeta(decoded_data) {
|
||||
part.param.set_int(Param::Width, width as i32);
|
||||
part.param.set_int(Param::Height, height as i32);
|
||||
}
|
||||
}
|
||||
|
||||
part.typ = msg_type;
|
||||
part.org_filename = Some(filename.to_string());
|
||||
part.mimetype = Some(mime_type);
|
||||
|
||||
Reference in New Issue
Block a user