mirror of
https://github.com/chatmail/core.git
synced 2026-04-23 08:26:30 +03:00
force a reason when calling set_msg_failed() (#3410)
* force a reason when calling `set_msg_failed()` the string is displayed to the user, so even _some_ context as "NDN without further details" is better than an empty string. * make clippy happy * add CHANGELOG entry
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
### Changes
|
||||
|
||||
### Fixes
|
||||
- set a default error if NDN does not provide an error
|
||||
|
||||
|
||||
## 1.86.0
|
||||
|
||||
@@ -2068,7 +2068,7 @@ async fn create_send_msg_job(context: &Context, msg_id: MsgId) -> Result<Option<
|
||||
let rendered_msg = match mimefactory.render(context).await {
|
||||
Ok(res) => Ok(res),
|
||||
Err(err) => {
|
||||
message::set_msg_failed(context, msg_id, Some(err.to_string())).await;
|
||||
message::set_msg_failed(context, msg_id, &err.to_string()).await;
|
||||
Err(err)
|
||||
}
|
||||
}?;
|
||||
@@ -2078,7 +2078,7 @@ async fn create_send_msg_job(context: &Context, msg_id: MsgId) -> Result<Option<
|
||||
message::set_msg_failed(
|
||||
context,
|
||||
msg_id,
|
||||
Some("End-to-end-encryption unavailable unexpectedly."),
|
||||
"End-to-end-encryption unavailable unexpectedly.",
|
||||
)
|
||||
.await;
|
||||
bail!(
|
||||
|
||||
@@ -2650,7 +2650,7 @@ mod tests {
|
||||
"shenauithz@testrun.org",
|
||||
"Mr.un2NYERi1RM.lbQ5F9q-QyJ@tiscali.it",
|
||||
include_bytes!("../test-data/message/tiscali_ndn.eml"),
|
||||
None,
|
||||
Some("Non-Delivery-Notification without further details."),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
@@ -1424,9 +1424,8 @@ pub async fn exists(context: &Context, msg_id: MsgId) -> Result<bool> {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn set_msg_failed(context: &Context, msg_id: MsgId, error: Option<impl AsRef<str>>) {
|
||||
pub async fn set_msg_failed(context: &Context, msg_id: MsgId, error: &str) {
|
||||
if let Ok(mut msg) = Message::load_from_db(context, msg_id).await {
|
||||
let error = error.map(|e| e.as_ref().to_string()).unwrap_or_default();
|
||||
if msg.state.can_fail() {
|
||||
msg.state = MessageState::OutFailed;
|
||||
warn!(context, "{} failed: {}", msg_id, error);
|
||||
@@ -1541,7 +1540,7 @@ pub async fn handle_mdn(
|
||||
pub(crate) async fn handle_ndn(
|
||||
context: &Context,
|
||||
failed: &FailureReport,
|
||||
error: Option<impl AsRef<str>>,
|
||||
error: &str,
|
||||
) -> Result<()> {
|
||||
if failed.rfc724_mid.is_empty() {
|
||||
return Ok(());
|
||||
@@ -1575,7 +1574,7 @@ pub(crate) async fn handle_ndn(
|
||||
let mut first = true;
|
||||
for msg in msgs.into_iter() {
|
||||
let (msg_id, chat_id, chat_type) = msg?;
|
||||
set_msg_failed(context, msg_id, error.as_ref()).await;
|
||||
set_msg_failed(context, msg_id, error).await;
|
||||
if first {
|
||||
// Add only one info msg for all failed messages
|
||||
ndn_maybe_add_info_msg(context, failed, chat_id, chat_type).await?;
|
||||
@@ -2218,7 +2217,7 @@ mod tests {
|
||||
update_msg_state(&alice, alice_msg.id, MessageState::OutMdnRcvd).await?;
|
||||
assert_state(&alice, alice_msg.id, MessageState::OutMdnRcvd).await;
|
||||
|
||||
set_msg_failed(&alice, alice_msg.id, Some("badly failed")).await;
|
||||
set_msg_failed(&alice, alice_msg.id, "badly failed").await;
|
||||
assert_state(&alice, alice_msg.id, MessageState::OutFailed).await;
|
||||
|
||||
// check incoming message states on receiver side
|
||||
|
||||
@@ -1398,11 +1398,11 @@ impl MimeMessage {
|
||||
}
|
||||
|
||||
if let Some(failure_report) = &self.failure_report {
|
||||
let error = parts
|
||||
.iter()
|
||||
.find(|p| p.typ == Viewtype::Text)
|
||||
.map(|p| p.msg.clone());
|
||||
if let Err(e) = message::handle_ndn(context, failure_report, error).await {
|
||||
let error = parts.iter().find(|p| p.typ == Viewtype::Text).map_or_else(
|
||||
|| "Non-Delivery-Notification without further details.".to_string(),
|
||||
|p| p.msg.clone(),
|
||||
);
|
||||
if let Err(e) = message::handle_ndn(context, failure_report, &error).await {
|
||||
warn!(context, "Could not handle ndn: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,7 +360,7 @@ pub(crate) async fn smtp_send(
|
||||
|
||||
if let SendResult::Failure(err) = &status {
|
||||
// We couldn't send the message, so mark it as failed
|
||||
message::set_msg_failed(context, msg_id, Some(err.to_string())).await;
|
||||
message::set_msg_failed(context, msg_id, &err.to_string()).await;
|
||||
}
|
||||
status
|
||||
}
|
||||
@@ -410,12 +410,7 @@ pub(crate) async fn send_msg_to_smtp(
|
||||
)
|
||||
.await?;
|
||||
if retries > 6 {
|
||||
message::set_msg_failed(
|
||||
context,
|
||||
msg_id,
|
||||
Some("Number of retries exceeded the limit."),
|
||||
)
|
||||
.await;
|
||||
message::set_msg_failed(context, msg_id, "Number of retries exceeded the limit.").await;
|
||||
context
|
||||
.sql
|
||||
.execute("DELETE FROM smtp WHERE id=?", paramsv![rowid])
|
||||
|
||||
Reference in New Issue
Block a user