mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 15:26:30 +03:00
Generate rfc724_mid when creating Message
This commit is contained in:
10
src/chat.rs
10
src/chat.rs
@@ -2027,8 +2027,6 @@ impl Chat {
|
|||||||
let mut to_id = 0;
|
let mut to_id = 0;
|
||||||
let mut location_id = 0;
|
let mut location_id = 0;
|
||||||
|
|
||||||
let new_rfc724_mid = create_outgoing_rfc724_mid();
|
|
||||||
|
|
||||||
if self.typ == Chattype::Single {
|
if self.typ == Chattype::Single {
|
||||||
if let Some(id) = context
|
if let Some(id) = context
|
||||||
.sql
|
.sql
|
||||||
@@ -2123,7 +2121,7 @@ impl Chat {
|
|||||||
if references_vec.is_empty() {
|
if references_vec.is_empty() {
|
||||||
// As a fallback, use our Message-ID,
|
// As a fallback, use our Message-ID,
|
||||||
// same as in the case of top-level message.
|
// same as in the case of top-level message.
|
||||||
new_references = new_rfc724_mid.clone();
|
new_references = msg.rfc724_mid.clone();
|
||||||
} else {
|
} else {
|
||||||
new_references = references_vec.join(" ");
|
new_references = references_vec.join(" ");
|
||||||
}
|
}
|
||||||
@@ -2133,8 +2131,9 @@ impl Chat {
|
|||||||
// This allows us to identify replies to our message even if
|
// This allows us to identify replies to our message even if
|
||||||
// email server such as Outlook changes `Message-ID:` header.
|
// email server such as Outlook changes `Message-ID:` header.
|
||||||
// MUAs usually keep the first Message-ID in `References:` header unchanged.
|
// 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
|
// add independent location to database
|
||||||
if msg.param.exists(Param::SetLatitude) {
|
if msg.param.exists(Param::SetLatitude) {
|
||||||
@@ -2201,7 +2200,6 @@ impl Chat {
|
|||||||
|
|
||||||
msg.chat_id = self.id;
|
msg.chat_id = self.id;
|
||||||
msg.from_id = ContactId::SELF;
|
msg.from_id = ContactId::SELF;
|
||||||
msg.rfc724_mid = new_rfc724_mid;
|
|
||||||
msg.timestamp_sort = timestamp;
|
msg.timestamp_sort = timestamp;
|
||||||
|
|
||||||
// add message to the database
|
// 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
|
let new_msg_id = chat
|
||||||
.prepare_msg_raw(context, &mut msg, None, curr_timestamp)
|
.prepare_msg_raw(context, &mut msg, None, curr_timestamp)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
msg.rfc724_mid = create_outgoing_rfc724_mid();
|
||||||
curr_timestamp += 1;
|
curr_timestamp += 1;
|
||||||
if !create_send_msg_jobs(context, &mut msg).await?.is_empty() {
|
if !create_send_msg_jobs(context, &mut msg).await?.is_empty() {
|
||||||
context.scheduler.interrupt_smtp().await;
|
context.scheduler.interrupt_smtp().await;
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ use crate::reaction::get_msg_reactions;
|
|||||||
use crate::sql;
|
use crate::sql;
|
||||||
use crate::summary::Summary;
|
use crate::summary::Summary;
|
||||||
use crate::sync::SyncData;
|
use crate::sync::SyncData;
|
||||||
|
use crate::tools::create_outgoing_rfc724_mid;
|
||||||
use crate::tools::{
|
use crate::tools::{
|
||||||
buf_compress, buf_decompress, get_filebytes, get_filemeta, gm2local_offset, read_file,
|
buf_compress, buf_decompress, get_filebytes, get_filemeta, gm2local_offset, read_file,
|
||||||
sanitize_filename, time, timestamp_to_str, truncate,
|
sanitize_filename, time, timestamp_to_str, truncate,
|
||||||
@@ -485,6 +486,7 @@ impl Message {
|
|||||||
pub fn new(viewtype: Viewtype) -> Self {
|
pub fn new(viewtype: Viewtype) -> Self {
|
||||||
Message {
|
Message {
|
||||||
viewtype,
|
viewtype,
|
||||||
|
rfc724_mid: create_outgoing_rfc724_mid(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -494,6 +496,7 @@ impl Message {
|
|||||||
Message {
|
Message {
|
||||||
viewtype: Viewtype::Text,
|
viewtype: Viewtype::Text,
|
||||||
text,
|
text,
|
||||||
|
rfc724_mid: create_outgoing_rfc724_mid(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2158,9 +2161,11 @@ pub(crate) async fn get_by_rfc724_mids(
|
|||||||
let mut latest = None;
|
let mut latest = None;
|
||||||
for id in mids.iter().rev() {
|
for id in mids.iter().rev() {
|
||||||
let Some((msg_id, _)) = rfc724_mid_exists(context, id).await? else {
|
let Some((msg_id, _)) = rfc724_mid_exists(context, id).await? else {
|
||||||
|
info!(context, "continue msgid");
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
let Some(msg) = Message::load_from_db_optional(context, msg_id).await? else {
|
let Some(msg) = Message::load_from_db_optional(context, msg_id).await? else {
|
||||||
|
info!(context, "continue msg");
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
if msg.download_state == DownloadState::Done {
|
if msg.download_state == DownloadState::Done {
|
||||||
|
|||||||
@@ -147,8 +147,6 @@ async fn test_quote() {
|
|||||||
|
|
||||||
let mut msg = Message::new_text("Quoted message".to_string());
|
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_id = chat::send_msg(ctx, chat.id, &mut msg).await.unwrap();
|
||||||
let msg = Message::load_from_db(ctx, msg_id).await.unwrap();
|
let msg = Message::load_from_db(ctx, msg_id).await.unwrap();
|
||||||
assert!(!msg.rfc724_mid.is_empty());
|
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 sent1 = alice.send_msg(alice_chat.id, &mut msg).await;
|
||||||
let msg1 = bob.recv_msg(&sent1).await;
|
let msg1 = bob.recv_msg(&sent1).await;
|
||||||
let bob_chat_id = msg1.chat_id;
|
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 sent2 = alice.send_msg(alice_chat.id, &mut msg).await;
|
||||||
let msg2 = bob.recv_msg(&sent2).await;
|
let msg2 = bob.recv_msg(&sent2).await;
|
||||||
assert_eq!(msg1.chat_id, msg2.chat_id);
|
assert_eq!(msg1.chat_id, msg2.chat_id);
|
||||||
@@ -380,9 +379,11 @@ async fn test_markseen_msgs() -> Result<()> {
|
|||||||
|
|
||||||
// bob sends to alice,
|
// bob sends to alice,
|
||||||
// alice knows bob and messages appear in normal chat
|
// alice knows bob and messages appear in normal chat
|
||||||
|
let mut msg = Message::new_text("this is the text!".to_string());
|
||||||
let msg1 = alice
|
let msg1 = alice
|
||||||
.recv_msg(&bob.send_msg(bob_chat_id, &mut msg).await)
|
.recv_msg(&bob.send_msg(bob_chat_id, &mut msg).await)
|
||||||
.await;
|
.await;
|
||||||
|
let mut msg = Message::new_text("this is the text!".to_string());
|
||||||
let msg2 = alice
|
let msg2 = alice
|
||||||
.recv_msg(&bob.send_msg(bob_chat_id, &mut msg).await)
|
.recv_msg(&bob.send_msg(bob_chat_id, &mut msg).await)
|
||||||
.await;
|
.await;
|
||||||
|
|||||||
@@ -727,6 +727,7 @@ async fn test_selfavatar_unencrypted_signed() {
|
|||||||
.is_some());
|
.is_some());
|
||||||
|
|
||||||
// if another message is sent, that one must not contain the avatar
|
// 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 sent_msg = t.send_msg(chat.id, &mut msg).await;
|
||||||
let mut payload = sent_msg.payload().splitn(4, "\r\n\r\n");
|
let mut payload = sent_msg.payload().splitn(4, "\r\n\r\n");
|
||||||
|
|
||||||
|
|||||||
@@ -3216,6 +3216,7 @@ async fn get_parent_message(
|
|||||||
if let Some(field) = references {
|
if let Some(field) = references {
|
||||||
mids.append(&mut parse_message_ids(field));
|
mids.append(&mut parse_message_ids(field));
|
||||||
}
|
}
|
||||||
|
info!(context, "mids: {mids:?}");
|
||||||
message::get_by_rfc724_mids(context, &mids).await
|
message::get_by_rfc724_mids(context, &mids).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5139,7 +5139,7 @@ async fn test_references() -> Result<()> {
|
|||||||
alice.set_config_bool(Config::BccSelf, true).await?;
|
alice.set_config_bool(Config::BccSelf, true).await?;
|
||||||
|
|
||||||
let alice_chat_id = create_group_chat(alice, ProtectionStatus::Unprotected, "Group").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.")
|
.send_text(alice_chat_id, "Hi! I created a group.")
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user