diff --git a/src/chat.rs b/src/chat.rs index 6db3b465a3..25a2885702 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -2027,8 +2027,6 @@ impl Chat { let mut to_id = 0; let mut location_id = 0; - let new_rfc724_mid = create_outgoing_rfc724_mid(); - if self.typ == Chattype::Single { if let Some(id) = context .sql @@ -2123,7 +2121,7 @@ impl Chat { if references_vec.is_empty() { // As a fallback, use our Message-ID, // same as in the case of top-level message. - new_references = new_rfc724_mid.clone(); + new_references = msg.rfc724_mid.clone(); } else { new_references = references_vec.join(" "); } @@ -2133,8 +2131,9 @@ impl Chat { // This allows us to identify replies to our message even if // email server such as Outlook changes `Message-ID:` header. // MUAs usually keep the first Message-ID in `References:` header unchanged. - new_references = new_rfc724_mid.clone(); + new_references = msg.rfc724_mid.clone(); } + info!(context, "new references: {new_references:?}"); // add independent location to database if msg.param.exists(Param::SetLatitude) { @@ -2201,7 +2200,6 @@ impl Chat { msg.chat_id = self.id; msg.from_id = ContactId::SELF; - msg.rfc724_mid = new_rfc724_mid; msg.timestamp_sort = timestamp; // add message to the database @@ -4369,6 +4367,8 @@ pub async fn forward_msgs(context: &Context, msg_ids: &[MsgId], chat_id: ChatId) let new_msg_id = chat .prepare_msg_raw(context, &mut msg, None, curr_timestamp) .await?; + + msg.rfc724_mid = create_outgoing_rfc724_mid(); curr_timestamp += 1; if !create_send_msg_jobs(context, &mut msg).await?.is_empty() { context.scheduler.interrupt_smtp().await; diff --git a/src/message.rs b/src/message.rs index db61dcf6f2..c4cca7b37f 100644 --- a/src/message.rs +++ b/src/message.rs @@ -33,6 +33,7 @@ use crate::reaction::get_msg_reactions; use crate::sql; use crate::summary::Summary; use crate::sync::SyncData; +use crate::tools::create_outgoing_rfc724_mid; use crate::tools::{ buf_compress, buf_decompress, get_filebytes, get_filemeta, gm2local_offset, read_file, sanitize_filename, time, timestamp_to_str, truncate, @@ -485,6 +486,7 @@ impl Message { pub fn new(viewtype: Viewtype) -> Self { Message { viewtype, + rfc724_mid: create_outgoing_rfc724_mid(), ..Default::default() } } @@ -494,6 +496,7 @@ impl Message { Message { viewtype: Viewtype::Text, text, + rfc724_mid: create_outgoing_rfc724_mid(), ..Default::default() } } @@ -2158,9 +2161,11 @@ pub(crate) async fn get_by_rfc724_mids( let mut latest = None; for id in mids.iter().rev() { let Some((msg_id, _)) = rfc724_mid_exists(context, id).await? else { + info!(context, "continue msgid"); continue; }; let Some(msg) = Message::load_from_db_optional(context, msg_id).await? else { + info!(context, "continue msg"); continue; }; if msg.download_state == DownloadState::Done { diff --git a/src/message/message_tests.rs b/src/message/message_tests.rs index 708cac5279..84aabde962 100644 --- a/src/message/message_tests.rs +++ b/src/message/message_tests.rs @@ -147,8 +147,6 @@ async fn test_quote() { let mut msg = Message::new_text("Quoted message".to_string()); - // Send message, so it gets a Message-Id. - assert!(msg.rfc724_mid.is_empty()); let msg_id = chat::send_msg(ctx, chat.id, &mut msg).await.unwrap(); let msg = Message::load_from_db(ctx, msg_id).await.unwrap(); assert!(!msg.rfc724_mid.is_empty()); @@ -358,6 +356,7 @@ async fn test_markseen_msgs() -> Result<()> { let sent1 = alice.send_msg(alice_chat.id, &mut msg).await; let msg1 = bob.recv_msg(&sent1).await; let bob_chat_id = msg1.chat_id; + let mut msg = Message::new_text("this is the text!".to_string()); let sent2 = alice.send_msg(alice_chat.id, &mut msg).await; let msg2 = bob.recv_msg(&sent2).await; assert_eq!(msg1.chat_id, msg2.chat_id); @@ -380,9 +379,11 @@ async fn test_markseen_msgs() -> Result<()> { // bob sends to alice, // alice knows bob and messages appear in normal chat + let mut msg = Message::new_text("this is the text!".to_string()); let msg1 = alice .recv_msg(&bob.send_msg(bob_chat_id, &mut msg).await) .await; + let mut msg = Message::new_text("this is the text!".to_string()); let msg2 = alice .recv_msg(&bob.send_msg(bob_chat_id, &mut msg).await) .await; diff --git a/src/mimefactory/mimefactory_tests.rs b/src/mimefactory/mimefactory_tests.rs index b8cc6af006..3127b19a66 100644 --- a/src/mimefactory/mimefactory_tests.rs +++ b/src/mimefactory/mimefactory_tests.rs @@ -727,6 +727,7 @@ async fn test_selfavatar_unencrypted_signed() { .is_some()); // if another message is sent, that one must not contain the avatar + let mut msg = Message::new_text("this is the text!".to_string()); let sent_msg = t.send_msg(chat.id, &mut msg).await; let mut payload = sent_msg.payload().splitn(4, "\r\n\r\n"); diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 945d440cc8..b5f83b433d 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -3216,6 +3216,7 @@ async fn get_parent_message( if let Some(field) = references { mids.append(&mut parse_message_ids(field)); } + info!(context, "mids: {mids:?}"); message::get_by_rfc724_mids(context, &mids).await } diff --git a/src/receive_imf/receive_imf_tests.rs b/src/receive_imf/receive_imf_tests.rs index 4df492c679..45878e2004 100644 --- a/src/receive_imf/receive_imf_tests.rs +++ b/src/receive_imf/receive_imf_tests.rs @@ -5139,7 +5139,7 @@ async fn test_references() -> Result<()> { alice.set_config_bool(Config::BccSelf, true).await?; let alice_chat_id = create_group_chat(alice, ProtectionStatus::Unprotected, "Group").await?; - let _sent = alice + alice .send_text(alice_chat_id, "Hi! I created a group.") .await;