From 14bce0a34670fed0c246e128cc6772cdfa72bedf Mon Sep 17 00:00:00 2001 From: mdecimus <11444311+mdecimus@users.noreply.github.com> Date: Sun, 2 Nov 2025 19:20:54 +0100 Subject: [PATCH] SMTP: MTA hook only runs if sieve script, milter or rewrite is configured (fixes #2317) --- crates/smtp/src/inbound/rcpt.rs | 44 ++++++++++----------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/crates/smtp/src/inbound/rcpt.rs b/crates/smtp/src/inbound/rcpt.rs index ab292e28..0c4f6ead 100644 --- a/crates/smtp/src/inbound/rcpt.rs +++ b/crates/smtp/src/inbound/rcpt.rs @@ -88,13 +88,10 @@ impl Session { self.data.rcpt_to.push(rcpt); // Address rewriting and Sieve filtering + let rcpt_config = &self.server.core.smtp.session.rcpt; let rcpt_script = self .server - .eval_if::( - &self.server.core.smtp.session.rcpt.script, - self, - self.data.session_id, - ) + .eval_if::(&rcpt_config.script, self, self.data.session_id) .await .and_then(|name| { self.server @@ -102,16 +99,17 @@ impl Session { .map(|s| (s.clone(), name)) }); + let session_config = &self.server.core.smtp.session; if rcpt_script.is_some() - || !self.server.core.smtp.session.rcpt.rewrite.is_empty() - || self - .server - .core - .smtp - .session + || !rcpt_config.rewrite.is_empty() + || session_config .milters .iter() .any(|m| m.run_on_stage.contains(&Stage::Rcpt)) + || session_config + .hooks + .iter() + .any(|h| h.run_on_stage.contains(&Stage::Rcpt)) { // Sieve filtering if let Some((script, script_id)) = rcpt_script { @@ -157,11 +155,7 @@ impl Session { // Address rewriting if let Some(new_address) = self .server - .eval_if::( - &self.server.core.smtp.session.rcpt.rewrite, - self, - self.data.session_id, - ) + .eval_if::(&rcpt_config.rewrite, self, self.data.session_id) .await { let rcpt = self.data.rcpt_to.last_mut().unwrap(); @@ -199,11 +193,7 @@ impl Session { let mut rcpt_members = None; if let Some(directory) = self .server - .eval_if::( - &self.server.core.smtp.session.rcpt.directory, - self, - self.data.session_id, - ) + .eval_if::(&rcpt_config.directory, self, self.data.session_id) .await .and_then(|name| self.server.get_directory(&name)) { @@ -247,11 +237,7 @@ impl Session { Ok(false) => { if !self .server - .eval_if( - &self.server.core.smtp.session.rcpt.relay, - self, - self.data.session_id, - ) + .eval_if(&rcpt_config.relay, self, self.data.session_id) .await .unwrap_or(false) { @@ -282,11 +268,7 @@ impl Session { } } else if !self .server - .eval_if( - &self.server.core.smtp.session.rcpt.relay, - self, - self.data.session_id, - ) + .eval_if(&rcpt_config.relay, self, self.data.session_id) .await .unwrap_or(false) {