fix: Treat and send images that can't be decoded as Viewtype::File

Otherwise unsupported and corrupted images are displayed in the "Images" tab in UIs and that looks
as a Delta Chat bug. This should be a rare case though, so log it as error and let the user know
that metadata isn't removed from the image at least.
This commit is contained in:
iequidoo
2025-06-06 16:24:54 -03:00
committed by iequidoo
parent cba9eb98d6
commit acba27a328
5 changed files with 84 additions and 48 deletions

View File

@@ -2722,25 +2722,27 @@ async fn prepare_msg_blob(context: &Context, msg: &mut Message) -> Result<()> {
if msg.viewtype == Viewtype::Vcard {
msg.try_set_vcard(context, &blob.to_abs_path()).await?;
}
let mut maybe_sticker = msg.viewtype == Viewtype::Sticker;
if !send_as_is
&& (msg.viewtype == Viewtype::Image
|| maybe_sticker && !msg.param.exists(Param::ForceSticker))
|| msg.viewtype == Viewtype::Sticker && !msg.param.exists(Param::ForceSticker))
{
let new_name = blob
.recode_to_image_size(context, msg.get_filename(), &mut maybe_sticker)
.recode_to_image_size(context, msg.get_filename(), &mut msg.viewtype)
.await?;
msg.param.set(Param::Filename, new_name);
msg.param.set(Param::File, blob.as_name());
if !maybe_sticker {
msg.viewtype = Viewtype::Image;
}
}
if !msg.param.exists(Param::MimeType) {
if let Some((_, mime)) = message::guess_msgtype_from_suffix(msg) {
if let Some((viewtype, mime)) = message::guess_msgtype_from_suffix(msg) {
// If we unexpectedly didn't recognize the file as image, don't send it as such,
// either the format is unsupported or the image is corrupted.
let mime = match viewtype != Viewtype::Image
|| matches!(msg.viewtype, Viewtype::Image | Viewtype::Sticker)
{
true => mime,
false => "application/octet-stream",
};
msg.param.set(Param::MimeType, mime);
}
}