Include queueId in MTA Hooks (fixes #708)
Some checks failed
trivy / Check (push) Failing after -8m10s

This commit is contained in:
mdecimus 2024-08-23 18:41:10 +02:00
parent 0186c215a5
commit 18a24f7220
8 changed files with 18 additions and 10 deletions

View file

@ -398,7 +398,7 @@ impl<T: SessionStream> Session<T> {
// Run MTA Hooks // Run MTA Hooks
match self match self
.run_mta_hooks(Stage::Data, (&auth_message).into()) .run_mta_hooks(Stage::Data, (&auth_message).into(), message_id.into())
.await .await
{ {
Ok(modifications_) => { Ok(modifications_) => {

View file

@ -115,7 +115,7 @@ impl<T: SessionStream> Session<T> {
} }
// MTAHook filtering // MTAHook filtering
if let Err(message) = self.run_mta_hooks(Stage::Ehlo, None).await { if let Err(message) = self.run_mta_hooks(Stage::Ehlo, None, None).await {
self.data.mail_from = None; self.data.mail_from = None;
self.data.helo_domain = prev_helo_domain; self.data.helo_domain = prev_helo_domain;
self.data.spf_ehlo = None; self.data.spf_ehlo = None;

View file

@ -24,15 +24,17 @@ use crate::{
milter::Modification, milter::Modification,
FilterResponse, FilterResponse,
}, },
queue::QueueId,
}; };
use super::{client::send_mta_hook_request, Action, Response}; use super::{client::send_mta_hook_request, Action, Queue, Response};
impl<T: SessionStream> Session<T> { impl<T: SessionStream> Session<T> {
pub async fn run_mta_hooks( pub async fn run_mta_hooks(
&self, &self,
stage: Stage, stage: Stage,
message: Option<&AuthenticatedMessage<'_>>, message: Option<&AuthenticatedMessage<'_>>,
queue_id: Option<QueueId>,
) -> Result<Vec<Modification>, FilterResponse> { ) -> Result<Vec<Modification>, FilterResponse> {
let mta_hooks = &self.core.core.smtp.session.hooks; let mta_hooks = &self.core.core.smtp.session.hooks;
if mta_hooks.is_empty() { if mta_hooks.is_empty() {
@ -53,7 +55,7 @@ impl<T: SessionStream> Session<T> {
} }
let time = Instant::now(); let time = Instant::now();
match self.run_mta_hook(stage, mta_hook, message).await { match self.run_mta_hook(stage, mta_hook, message, queue_id).await {
Ok(response) => { Ok(response) => {
trc::event!( trc::event!(
MtaHook(match response.action { MtaHook(match response.action {
@ -174,6 +176,7 @@ impl<T: SessionStream> Session<T> {
stage: Stage, stage: Stage,
mta_hook: &MTAHook, mta_hook: &MTAHook,
message: Option<&AuthenticatedMessage<'_>>, message: Option<&AuthenticatedMessage<'_>>,
queue_id: Option<QueueId>,
) -> Result<Response, String> { ) -> Result<Response, String> {
// Build request // Build request
let (tls_version, tls_cipher) = self.stream.tls_version_and_cipher(); let (tls_version, tls_cipher) = self.stream.tls_version_and_cipher();
@ -210,7 +213,9 @@ impl<T: SessionStream> Session<T> {
port: self.data.local_port, port: self.data.local_port,
ip: self.data.local_ip.to_string().into(), ip: self.data.local_ip.to_string().into(),
}, },
queue: None, queue: queue_id.map(|id| Queue {
id: format!("{:x}", id),
}),
protocol: Protocol { version: 1 }, protocol: Protocol { version: 1 },
}, },
envelope: self.data.mail_from.as_ref().map(|from| Envelope { envelope: self.data.mail_from.as_ref().map(|from| Envelope {

View file

@ -169,7 +169,7 @@ impl<T: SessionStream> Session<T> {
} }
// MTAHook filtering // MTAHook filtering
if let Err(message) = self.run_mta_hooks(Stage::Mail, None).await { if let Err(message) = self.run_mta_hooks(Stage::Mail, None, None).await {
self.data.mail_from = None; self.data.mail_from = None;
return self.write(message.message.as_bytes()).await; return self.write(message.message.as_bytes()).await;
} }

View file

@ -139,7 +139,7 @@ impl<T: SessionStream> Session<T> {
} }
// MTAHook filtering // MTAHook filtering
if let Err(message) = self.run_mta_hooks(Stage::Rcpt, None).await { if let Err(message) = self.run_mta_hooks(Stage::Rcpt, None, None).await {
self.data.rcpt_to.pop(); self.data.rcpt_to.pop();
return self.write(message.message.as_bytes()).await; return self.write(message.message.as_bytes()).await;
} }

View file

@ -116,7 +116,7 @@ impl<T: SessionStream> Session<T> {
} }
// MTAHook filtering // MTAHook filtering
if let Err(message) = self.run_mta_hooks(Stage::Connect, None).await { if let Err(message) = self.run_mta_hooks(Stage::Connect, None, None).await {
let _ = self.write(message.message.as_bytes()).await; let _ = self.write(message.message.as_bytes()).await;
return false; return false;
} }

View file

@ -409,7 +409,10 @@ async fn antispam() {
// Run script // Run script
let core_ = core.clone(); let core_ = core.clone();
let script = script.clone(); let script = script.clone();
match core_.run_script(script, params, 0).await { match core_
.run_script("test".to_string(), script, params, 0)
.await
{
ScriptResult::Accept { modifications } => { ScriptResult::Accept { modifications } => {
if modifications.len() != expected_headers.len() { if modifications.len() != expected_headers.len() {
panic!( panic!(

View file

@ -177,7 +177,7 @@ async fn sieve_scripts() {
.with_envelope(&core.core, &session, 0) .with_envelope(&core.core, &session, 0)
.await; .await;
let core_ = core.clone(); let core_ = core.clone();
match core_.run_script(script, params, 0).await { match core_.run_script(name.to_string(), script, params, 0).await {
ScriptResult::Accept { .. } => (), ScriptResult::Accept { .. } => (),
ScriptResult::Reject(message) => panic!("{}", message), ScriptResult::Reject(message) => panic!("{}", message),
err => { err => {