Skip to content

Commit ff54cf2

Browse files
committed
fix: message::update_msg_state(): Reset error if message is delivered (#5119)
1 parent af0833e commit ff54cf2

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/message.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1663,10 +1663,14 @@ pub(crate) async fn update_msg_state(
16631663
msg_id: MsgId,
16641664
state: MessageState,
16651665
) -> Result<()> {
1666+
let error_subst = match state >= MessageState::OutDelivered {
1667+
true => ", error=''",
1668+
false => "",
1669+
};
16661670
context
16671671
.sql
16681672
.execute(
1669-
"UPDATE msgs SET state=?1 WHERE id=?2 AND (?1!=?3 OR state<?3)",
1673+
&format!("UPDATE msgs SET state=?1 {error_subst} WHERE id=?2 AND (?1!=?3 OR state<?3)"),
16701674
(state, msg_id, MessageState::OutDelivered),
16711675
)
16721676
.await?;

src/receive_imf/tests.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use tokio::fs;
22

33
use super::*;
44
use crate::aheader::EncryptPreference;
5+
use crate::chat::{self, get_chat_msgs, ChatItem, ChatVisibility};
56
use crate::chat::{
67
add_contact_to_chat, add_to_chat_contacts_table, create_group_chat, get_chat_contacts,
78
is_contact_in_chat, remove_contact_from_chat, send_text_msg,
89
};
9-
use crate::chat::{get_chat_msgs, ChatItem, ChatVisibility};
1010
use crate::chatlist::Chatlist;
1111
use crate::config::Config;
1212
use crate::constants::{DC_GCL_FOR_FORWARDING, DC_GCL_NO_SPECIALS};
@@ -628,7 +628,7 @@ async fn test_parse_ndn(
628628
rfc724_mid_outgoing: &str,
629629
raw_ndn: &[u8],
630630
error_msg: Option<&str>,
631-
) {
631+
) -> (TestContext, MsgId) {
632632
let t = TestContext::new().await;
633633
t.configure_addr(self_addr).await;
634634

@@ -675,6 +675,37 @@ async fn test_parse_ndn(
675675
);
676676

677677
assert_eq!(msg.error(), error_msg.map(|error| error.to_string()));
678+
(t, msg_id)
679+
}
680+
681+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
682+
async fn test_resend_after_ndn() -> Result<()> {
683+
let (t, msg_id) = test_parse_ndn(
684+
"alice@testrun.org",
685+
"hcksocnsofoejx@five.chat",
686+
"Mr.A7pTA5IgrUA.q4bP41vAJOp@testrun.org",
687+
include_bytes!("../../test-data/message/testrun_ndn.eml"),
688+
Some("Undelivered Mail Returned to Sender – This is the mail system at host hq5.merlinux.eu.\n\nI\'m sorry to have to inform you that your message could not\nbe delivered to one or more recipients. It\'s attached below.\n\nFor further assistance, please send mail to postmaster.\n\nIf you do so, please include this problem report. You can\ndelete your own text from the attached returned message.\n\n The mail system\n\n<hcksocnsofoejx@five.chat>: host mail.five.chat[195.62.125.103] said: 550 5.1.1\n <hcksocnsofoejx@five.chat>: Recipient address rejected: User unknown in\n virtual mailbox table (in reply to RCPT TO command)"),
689+
)
690+
.await;
691+
chat::resend_msgs(&t, &[msg_id]).await?;
692+
// Alice receives a BCC-self copy of their message.
693+
receive_imf(
694+
&t,
695+
"To: hcksocnsofoejx@five.chat\n\
696+
From: alice@testrun.org\n\
697+
Date: Today, 2 January 2024 00:00:00 -300\n\
698+
Message-ID: Mr.A7pTA5IgrUA.q4bP41vAJOp@testrun.org\n\
699+
\n\
700+
hi"
701+
.as_bytes(),
702+
false,
703+
)
704+
.await?;
705+
let msg = t.get_last_msg().await;
706+
assert_eq!(msg.state, MessageState::OutDelivered);
707+
assert_eq!(msg.error(), None);
708+
Ok(())
678709
}
679710

680711
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]

0 commit comments

Comments
 (0)