(context: &Context, msg: &mut Message)
| 2457 | } |
| 2458 | |
| 2459 | async fn prepare_msg_blob(context: &Context, msg: &mut Message) -> Result<()> { |
| 2460 | if msg.viewtype == Viewtype::Text || msg.viewtype == Viewtype::Call { |
| 2461 | // the caller should check if the message text is empty |
| 2462 | } else if msg.viewtype.has_file() { |
| 2463 | let viewtype_orig = msg.viewtype; |
| 2464 | let mut blob = msg |
| 2465 | .param |
| 2466 | .get_file_blob(context)? |
| 2467 | .with_context(|| format!("attachment missing for message of type #{}", msg.viewtype))?; |
| 2468 | let mut maybe_image = false; |
| 2469 | |
| 2470 | if msg.viewtype == Viewtype::File || msg.viewtype == Viewtype::Image { |
| 2471 | // Correct the type, take care not to correct already very special |
| 2472 | // formats as GIF or VOICE. |
| 2473 | // |
| 2474 | // Typical conversions: |
| 2475 | // - from FILE to AUDIO/VIDEO/IMAGE |
| 2476 | // - from FILE/IMAGE to GIF */ |
| 2477 | if let Some((better_type, _)) = message::guess_msgtype_from_suffix(msg) { |
| 2478 | if better_type == Viewtype::Image { |
| 2479 | maybe_image = true; |
| 2480 | } else if better_type != Viewtype::Webxdc |
| 2481 | || context |
| 2482 | .ensure_sendable_webxdc_file(&blob.to_abs_path()) |
| 2483 | .await |
| 2484 | .is_ok() |
| 2485 | { |
| 2486 | msg.viewtype = better_type; |
| 2487 | } |
| 2488 | } |
| 2489 | } else if msg.viewtype == Viewtype::Webxdc { |
| 2490 | context |
| 2491 | .ensure_sendable_webxdc_file(&blob.to_abs_path()) |
| 2492 | .await?; |
| 2493 | } |
| 2494 | |
| 2495 | if msg.viewtype == Viewtype::Vcard { |
| 2496 | msg.try_set_vcard(context, &blob.to_abs_path()).await?; |
| 2497 | } |
| 2498 | if msg.viewtype == Viewtype::File && maybe_image || msg.viewtype == Viewtype::Image { |
| 2499 | let new_name = blob |
| 2500 | .check_or_recode_image(context, msg.get_filename(), &mut msg.viewtype) |
| 2501 | .await?; |
| 2502 | msg.param.set(Param::Filename, new_name); |
| 2503 | msg.param.set(Param::File, blob.as_name()); |
| 2504 | } |
| 2505 | |
| 2506 | if !msg.param.exists(Param::MimeType) |
| 2507 | && let Some((viewtype, mime)) = message::guess_msgtype_from_suffix(msg) |
| 2508 | { |
| 2509 | // If we unexpectedly didn't recognize the file as image, don't send it as such, |
| 2510 | // either the format is unsupported or the image is corrupted. |
| 2511 | let mime = match viewtype != Viewtype::Image |
| 2512 | || matches!(msg.viewtype, Viewtype::Image | Viewtype::Sticker) |
| 2513 | { |
| 2514 | true => mime, |
| 2515 | false => "application/octet-stream", |
| 2516 | }; |
no test coverage detected