mirror of
https://github.com/chatmail/core.git
synced 2026-05-06 06:46:35 +03:00
test: test_markseen_pre_msg: Check that MDN on pre-message changes message state to OutMdnRcvd (#8004)
This commit is contained in:
103
src/smtp.rs
103
src/smtp.rs
@@ -13,7 +13,7 @@ use crate::config::Config;
|
|||||||
use crate::contact::{Contact, ContactId};
|
use crate::contact::{Contact, ContactId};
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::events::EventType;
|
use crate::events::EventType;
|
||||||
use crate::log::{LogExt, warn};
|
use crate::log::warn;
|
||||||
use crate::message::Message;
|
use crate::message::Message;
|
||||||
use crate::message::{self, MsgId};
|
use crate::message::{self, MsgId};
|
||||||
use crate::mimefactory::MimeFactory;
|
use crate::mimefactory::MimeFactory;
|
||||||
@@ -584,44 +584,77 @@ async fn send_mdn_rfc724_mid(
|
|||||||
if context.get_config_bool(Config::BccSelf).await? {
|
if context.get_config_bool(Config::BccSelf).await? {
|
||||||
add_self_recipients(context, &mut recipients, encrypted).await?;
|
add_self_recipients(context, &mut recipients, encrypted).await?;
|
||||||
}
|
}
|
||||||
let recipients: Vec<_> = recipients
|
#[cfg(not(test))]
|
||||||
.into_iter()
|
{
|
||||||
.filter_map(|addr| {
|
use crate::log::LogExt;
|
||||||
async_smtp::EmailAddress::new(addr.clone())
|
|
||||||
.with_context(|| format!("Invalid recipient: {addr}"))
|
|
||||||
.log_err(context)
|
|
||||||
.ok()
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
match smtp_send(context, &recipients, &body, smtp, None).await {
|
let recipients: Vec<_> = recipients
|
||||||
SendResult::Success => {
|
.into_iter()
|
||||||
if !recipients.is_empty() {
|
.filter_map(|addr| {
|
||||||
info!(context, "Successfully sent MDN for {rfc724_mid}.");
|
async_smtp::EmailAddress::new(addr.clone())
|
||||||
|
.with_context(|| format!("Invalid recipient: {addr}"))
|
||||||
|
.log_err(context)
|
||||||
|
.ok()
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
match smtp_send(context, &recipients, &body, smtp, None).await {
|
||||||
|
SendResult::Success => {
|
||||||
|
if !recipients.is_empty() {
|
||||||
|
info!(context, "Successfully sent MDN for {rfc724_mid}.");
|
||||||
|
}
|
||||||
|
context
|
||||||
|
.sql
|
||||||
|
.transaction(|transaction| {
|
||||||
|
let mut stmt =
|
||||||
|
transaction.prepare("DELETE FROM smtp_mdns WHERE rfc724_mid = ?")?;
|
||||||
|
stmt.execute((rfc724_mid,))?;
|
||||||
|
for additional_rfc724_mid in additional_rfc724_mids {
|
||||||
|
stmt.execute((additional_rfc724_mid,))?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
Ok(true)
|
||||||
}
|
}
|
||||||
context
|
SendResult::Retry => {
|
||||||
.sql
|
info!(
|
||||||
.transaction(|transaction| {
|
context,
|
||||||
let mut stmt =
|
"Temporary SMTP failure while sending an MDN for {rfc724_mid}."
|
||||||
transaction.prepare("DELETE FROM smtp_mdns WHERE rfc724_mid = ?")?;
|
);
|
||||||
stmt.execute((rfc724_mid,))?;
|
Ok(false)
|
||||||
for additional_rfc724_mid in additional_rfc724_mids {
|
}
|
||||||
stmt.execute((additional_rfc724_mid,))?;
|
SendResult::Failure(err) => Err(err),
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
.await?;
|
|
||||||
Ok(true)
|
|
||||||
}
|
}
|
||||||
SendResult::Retry => {
|
|
||||||
info!(
|
|
||||||
context,
|
|
||||||
"Temporary SMTP failure while sending an MDN for {rfc724_mid}."
|
|
||||||
);
|
|
||||||
Ok(false)
|
|
||||||
}
|
|
||||||
SendResult::Failure(err) => Err(err),
|
|
||||||
}
|
}
|
||||||
|
#[cfg(test)]
|
||||||
|
{
|
||||||
|
let _ = smtp;
|
||||||
|
context
|
||||||
|
.sql
|
||||||
|
.transaction(|t| {
|
||||||
|
t.execute(
|
||||||
|
"INSERT INTO smtp (rfc724_mid, recipients, mime, msg_id)
|
||||||
|
VALUES (?, ?, ?, ?)",
|
||||||
|
(rfc724_mid, recipients.join(" "), body, u32::MAX),
|
||||||
|
)?;
|
||||||
|
let mut stmt = t.prepare("DELETE FROM smtp_mdns WHERE rfc724_mid = ?")?;
|
||||||
|
stmt.execute((rfc724_mid,))?;
|
||||||
|
for additional_rfc724_mid in additional_rfc724_mids {
|
||||||
|
stmt.execute((additional_rfc724_mid,))?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) async fn queue_mdn(context: &Context) -> Result<()> {
|
||||||
|
let queued = send_mdn(context, &mut Smtp::new()).await?;
|
||||||
|
assert!(queued);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tries to send a single MDN. Returns true if more MDNs should be sent.
|
/// Tries to send a single MDN. Returns true if more MDNs should be sent.
|
||||||
|
|||||||
@@ -716,7 +716,8 @@ impl TestContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_smtp_rows_for_msg<'a>(&'a self, msg_id: MsgId) -> Vec<SentMessage<'a>> {
|
pub async fn get_smtp_rows_for_msg<'a>(&'a self, msg_id: MsgId) -> Vec<SentMessage<'a>> {
|
||||||
self.ctx
|
let sent_msgs = self
|
||||||
|
.ctx
|
||||||
.sql
|
.sql
|
||||||
.query_map_vec(
|
.query_map_vec(
|
||||||
"SELECT id, msg_id, mime, recipients FROM smtp WHERE msg_id=?",
|
"SELECT id, msg_id, mime, recipients FROM smtp WHERE msg_id=?",
|
||||||
@@ -738,7 +739,23 @@ impl TestContext {
|
|||||||
sender_context: &self.ctx,
|
sender_context: &self.ctx,
|
||||||
recipients,
|
recipients,
|
||||||
})
|
})
|
||||||
.collect()
|
.collect();
|
||||||
|
self.ctx
|
||||||
|
.sql
|
||||||
|
.execute("DELETE FROM smtp WHERE msg_id=?", (msg_id,))
|
||||||
|
.await
|
||||||
|
.expect("Delete smtp jobs");
|
||||||
|
update_msg_state(&self.ctx, msg_id, MessageState::OutDelivered)
|
||||||
|
.await
|
||||||
|
.expect("Update message state");
|
||||||
|
self.sql
|
||||||
|
.execute(
|
||||||
|
"UPDATE msgs SET timestamp_sent=? WHERE id=?",
|
||||||
|
(time(), msg_id),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("Update timestamp_sent");
|
||||||
|
sent_msgs
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses a message.
|
/// Parses a message.
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use crate::message::{Message, MessageState, Viewtype, delete_msgs, markseen_msgs
|
|||||||
use crate::mimeparser::MimeMessage;
|
use crate::mimeparser::MimeMessage;
|
||||||
use crate::param::Param;
|
use crate::param::Param;
|
||||||
use crate::reaction::{get_msg_reactions, send_reaction};
|
use crate::reaction::{get_msg_reactions, send_reaction};
|
||||||
|
use crate::smtp;
|
||||||
use crate::summary::assert_summary_texts;
|
use crate::summary::assert_summary_texts;
|
||||||
use crate::test_utils::TestContextManager;
|
use crate::test_utils::TestContextManager;
|
||||||
use crate::tests::pre_messages::util::{
|
use crate::tests::pre_messages::util::{
|
||||||
@@ -523,7 +524,7 @@ async fn test_markseen_pre_msg() -> Result<()> {
|
|||||||
alice.create_chat(bob).await; // Make sure the chat is accepted.
|
alice.create_chat(bob).await; // Make sure the chat is accepted.
|
||||||
|
|
||||||
tcm.section("Bob sends a large message to Alice");
|
tcm.section("Bob sends a large message to Alice");
|
||||||
let (pre_message, post_message, _bob_msg_id) =
|
let (pre_message, post_message, bob_msg_id) =
|
||||||
send_large_file_message(bob, bob_chat_id, Viewtype::File, &vec![0u8; 1_000_000]).await?;
|
send_large_file_message(bob, bob_chat_id, Viewtype::File, &vec![0u8; 1_000_000]).await?;
|
||||||
|
|
||||||
tcm.section("Alice receives a pre-message message from Bob");
|
tcm.section("Alice receives a pre-message message from Bob");
|
||||||
@@ -542,6 +543,10 @@ async fn test_markseen_pre_msg() -> Result<()> {
|
|||||||
.await?,
|
.await?,
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
|
smtp::queue_mdn(alice).await?;
|
||||||
|
bob.recv_msg_trash(&alice.pop_sent_msg().await).await;
|
||||||
|
let bob_msg = Message::load_from_db(bob, bob_msg_id).await?;
|
||||||
|
assert_eq!(bob_msg.get_state(), MessageState::OutMdnRcvd);
|
||||||
|
|
||||||
tcm.section("Alice downloads message");
|
tcm.section("Alice downloads message");
|
||||||
alice.recv_msg_trash(&post_message).await;
|
alice.recv_msg_trash(&post_message).await;
|
||||||
|
|||||||
Reference in New Issue
Block a user