fix: add device message instead of partial message when receive_imf fails

This commit is contained in:
link2xt
2025-11-04 23:32:45 +00:00
committed by l
parent f04c881b8c
commit 81ba2d20d6
5 changed files with 33 additions and 77 deletions

View File

@@ -221,21 +221,14 @@ impl MimeMessage {
/// To create the placeholder, only the outermost header can be used,
/// the mime-structure itself is not available.
///
/// The placeholder part currently contains a text with size and availability of the message;
/// `error` is set as the part error;
/// in the future, we may do more advanced things as previews here.
/// The placeholder part currently contains a text with size and availability of the message.
pub(crate) async fn create_stub_from_partial_download(
&mut self,
context: &Context,
org_bytes: u32,
error: Option<String>,
) -> Result<()> {
let prefix = match error {
None => "",
Some(_) => "[❗] ",
};
let mut text = format!(
"{prefix}[{}]",
"[{}]",
stock_str::partial_download_msg_body(context, org_bytes).await
);
if let Some(delete_server_after) = context.get_config_delete_server_after().await? {
@@ -252,7 +245,6 @@ impl MimeMessage {
self.do_add_single_part(Part {
typ: Viewtype::Text,
msg: text,
error,
..Default::default()
});

View File

@@ -24,7 +24,7 @@ use ratelimit::Ratelimit;
use url::Url;
use crate::calls::{create_fallback_ice_servers, create_ice_servers_from_metadata};
use crate::chat::{self, ChatId, ChatIdBlocked};
use crate::chat::{self, ChatId, ChatIdBlocked, add_device_msg};
use crate::chatlist_events;
use crate::config::Config;
use crate::constants::{self, Blocked, Chattype, ShowEmails};
@@ -1468,29 +1468,19 @@ impl Session {
context,
"Passing message UID {} to receive_imf().", request_uid
);
let res = receive_imf_inner(
context,
rfc724_mid,
body,
is_seen,
partial.map(|msg_size| (msg_size, None)),
)
.await;
let received_msg = if let Err(err) = res {
warn!(context, "receive_imf error: {:#}.", err);
if partial.is_some() {
return Err(err);
let res = receive_imf_inner(context, rfc724_mid, body, is_seen, partial).await;
let received_msg = match res {
Err(err) => {
warn!(context, "receive_imf error: {err:#}.");
let text = format!(
"❌ Failed to receive a message: {err:#}. Please report this bug to delta@merlinux.eu or https://support.delta.chat/."
);
let mut msg = Message::new_text(text);
add_device_msg(context, None, Some(&mut msg)).await?;
None
}
receive_imf_inner(
context,
rfc724_mid,
body,
is_seen,
Some((body.len().try_into()?, Some(format!("{err:#}")))),
)
.await?
} else {
res?
Ok(msg) => msg,
};
received_msgs_channel
.send((request_uid, received_msg))

View File

@@ -240,12 +240,11 @@ const MIME_AC_SETUP_FILE: &str = "application/autocrypt-setup";
impl MimeMessage {
/// Parse a mime message.
///
/// If `partial` is set, it contains the full message size in bytes and an optional error text
/// for the partially downloaded message, and `body` contains the HEADER only.
/// If `partial` is set, it contains the full message size in bytes.
pub(crate) async fn from_bytes(
context: &Context,
body: &[u8],
partial: Option<(u32, Option<String>)>,
partial: Option<u32>,
) -> Result<Self> {
let mail = mailparse::parse_mail(body)?;
@@ -619,9 +618,9 @@ impl MimeMessage {
};
match partial {
Some((org_bytes, err)) => {
Some(org_bytes) => {
parser
.create_stub_from_partial_download(context, org_bytes, err)
.create_stub_from_partial_download(context, org_bytes)
.await?;
}
None => match mail {

View File

@@ -186,14 +186,7 @@ pub(crate) async fn receive_imf_from_inbox(
seen: bool,
is_partial_download: Option<u32>,
) -> Result<Option<ReceivedMsg>> {
receive_imf_inner(
context,
rfc724_mid,
imf_raw,
seen,
is_partial_download.map(|msg_size| (msg_size, None)),
)
.await
receive_imf_inner(context, rfc724_mid, imf_raw, seen, is_partial_download).await
}
/// Inserts a tombstone into `msgs` table
@@ -490,14 +483,13 @@ async fn get_to_and_past_contact_ids(
/// If the message is so wrong that we didn't even create a database entry,
/// returns `Ok(None)`.
///
/// If `partial` is set, it contains the full message size in bytes and an optional error text for
/// the partially downloaded message.
/// If `is_partial_download` is set, it contains the full message size in bytes.
pub(crate) async fn receive_imf_inner(
context: &Context,
rfc724_mid: &str,
imf_raw: &[u8],
seen: bool,
partial: Option<(u32, Option<String>)>,
is_partial_download: Option<u32>,
) -> Result<Option<ReceivedMsg>> {
if std::env::var(crate::DCC_MIME_DEBUG).is_ok() {
info!(
@@ -506,7 +498,7 @@ pub(crate) async fn receive_imf_inner(
String::from_utf8_lossy(imf_raw),
);
}
if partial.is_none() {
if is_partial_download.is_none() {
ensure!(
!context
.get_config_bool(Config::FailOnReceivingFullMsg)
@@ -514,8 +506,8 @@ pub(crate) async fn receive_imf_inner(
);
}
let is_partial_download = partial.as_ref().map(|(msg_size, _err)| *msg_size);
let mut mime_parser = match MimeMessage::from_bytes(context, imf_raw, partial).await {
let mut mime_parser = match MimeMessage::from_bytes(context, imf_raw, is_partial_download).await
{
Err(err) => {
warn!(context, "receive_imf: can't parse MIME: {err:#}.");
if rfc724_mid.starts_with(GENERATED_PREFIX) {