Skip to content

Generate rfc724_mid when creating Message #6676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(" ");
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -485,6 +486,7 @@ impl Message {
pub fn new(viewtype: Viewtype) -> Self {
Message {
viewtype,
rfc724_mid: create_outgoing_rfc724_mid(),
..Default::default()
}
}
Expand All @@ -494,6 +496,7 @@ impl Message {
Message {
viewtype: Viewtype::Text,
text,
rfc724_mid: create_outgoing_rfc724_mid(),
..Default::default()
}
}
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions src/message/message_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/mimefactory/mimefactory_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
1 change: 1 addition & 0 deletions src/receive_imf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/receive_imf/receive_imf_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading