mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 17:06:35 +03:00
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:
@@ -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,34 +1662,51 @@ 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 {
|
||||||
if chat_type == Chattype::Group {
|
Ok((msg_id, chat_id, chat_type)) => {
|
||||||
if let Some(failed_recipient) = &failed.failed_recipient {
|
set_msg_failed(context, *msg_id, error.as_ref()).await;
|
||||||
let contact_id =
|
ndn_maybe_add_info_msg(context, failed, *chat_id, *chat_type).await;
|
||||||
Contact::lookup_id_by_addr(context, failed_recipient, Origin::Unknown).await;
|
|
||||||
if let Ok(contact) = Contact::load_from_db(context, contact_id).await {
|
|
||||||
// Tell the user which of the recipients failed if we know that (because in a group, this might otherwise be unclear)
|
|
||||||
chat::add_info_msg(
|
|
||||||
context,
|
|
||||||
chat_id,
|
|
||||||
context
|
|
||||||
.stock_string_repl_str(
|
|
||||||
StockMessage::FailedSendingTo,
|
|
||||||
contact.get_display_name(),
|
|
||||||
)
|
|
||||||
.await,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
context.emit_event(EventType::ChatModified(chat_id));
|
|
||||||
}
|
}
|
||||||
|
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 let Some(failed_recipient) = &failed.failed_recipient {
|
||||||
|
let contact_id =
|
||||||
|
Contact::lookup_id_by_addr(context, failed_recipient, Origin::Unknown).await;
|
||||||
|
if let Ok(contact) = Contact::load_from_db(context, contact_id).await {
|
||||||
|
// Tell the user which of the recipients failed if we know that (because in a group, this might otherwise be unclear)
|
||||||
|
chat::add_info_msg(
|
||||||
|
context,
|
||||||
|
chat_id,
|
||||||
|
context
|
||||||
|
.stock_string_repl_str(
|
||||||
|
StockMessage::FailedSendingTo,
|
||||||
|
contact.get_display_name(),
|
||||||
|
)
|
||||||
|
.await,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
context.emit_event(EventType::ChatModified(chat_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user