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