mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 15:26:30 +03:00
test: Add function to queue MDN into smtp
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;
|
||||||
@@ -590,44 +590,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.
|
||||||
|
|||||||
Reference in New Issue
Block a user