Mark all failed messages as failed when receiving an NDN

There may be multiple messages with the same `Message-Id`-header alias
rfc724_mid because an email with multiple attachments was split up.
This commit is contained in:
Hocuri
2020-10-14 10:52:25 +02:00
committed by holger krekel
parent c005f756d6
commit 0b1288fc17

View File

@@ -1643,9 +1643,9 @@ pub(crate) async fn handle_ndn(
return; return;
} }
let res = context let res: Result<Vec<_>, _> = context
.sql .sql
.query_row( .query_map(
concat!( concat!(
"SELECT", "SELECT",
" m.id AS msg_id,", " m.id AS msg_id,",
@@ -1662,15 +1662,33 @@ pub(crate) async fn handle_ndn(
row.get::<_, Chattype>("type")?, row.get::<_, Chattype>("type")?,
)) ))
}, },
|rows| Ok(rows.collect::<Vec<_>>()),
) )
.await; .await;
if let Err(ref err) = res { if let Err(ref err) = res {
info!(context, "Failed to select NDN {:?}", err); info!(context, "Failed to select NDN {:?}", err);
} }
if let Ok((msg_id, chat_id, chat_type)) = res { if let Ok(msgs) = res {
set_msg_failed(context, msg_id, error).await; for msg in msgs.iter() {
match msg {
Ok((msg_id, chat_id, chat_type)) => {
set_msg_failed(context, *msg_id, error.as_ref()).await;
ndn_maybe_add_info_msg(context, failed, *chat_id, *chat_type).await;
}
Err(e) => warn!(context, "ndn error: {}", e),
}
}
}
}
async fn ndn_maybe_add_info_msg(
context: &Context,
failed: &FailureReport,
chat_id: ChatId,
chat_type: Chattype,
) {
if chat_type == Chattype::Group { if chat_type == Chattype::Group {
if let Some(failed_recipient) = &failed.failed_recipient { if let Some(failed_recipient) = &failed.failed_recipient {
let contact_id = let contact_id =
@@ -1693,7 +1711,6 @@ pub(crate) async fn handle_ndn(
} }
} }
} }
}
/// The number of messages assigned to real chat (!=deaddrop, !=trash) /// The number of messages assigned to real chat (!=deaddrop, !=trash)
pub async fn get_real_msg_cnt(context: &Context) -> i32 { pub async fn get_real_msg_cnt(context: &Context) -> i32 {