summaryrefslogtreecommitdiff
path: root/crates/smtp/src/inbound
diff options
context:
space:
mode:
Diffstat (limited to 'crates/smtp/src/inbound')
-rw-r--r--crates/smtp/src/inbound/auth.rs6
-rw-r--r--crates/smtp/src/inbound/data.rs109
-rw-r--r--crates/smtp/src/inbound/ehlo.rs52
-rw-r--r--crates/smtp/src/inbound/hooks/message.rs5
-rw-r--r--crates/smtp/src/inbound/mail.rs51
-rw-r--r--crates/smtp/src/inbound/milter/message.rs9
-rw-r--r--crates/smtp/src/inbound/rcpt.rs44
-rw-r--r--crates/smtp/src/inbound/session.rs5
-rw-r--r--crates/smtp/src/inbound/spawn.rs37
-rw-r--r--crates/smtp/src/inbound/vrfy.rs20
10 files changed, 135 insertions, 203 deletions
diff --git a/crates/smtp/src/inbound/auth.rs b/crates/smtp/src/inbound/auth.rs
index 419b4dab..d1ab3470 100644
--- a/crates/smtp/src/inbound/auth.rs
+++ b/crates/smtp/src/inbound/auth.rs
@@ -168,8 +168,7 @@ impl<T: SessionStream> Session<T> {
// Authenticate
let mut result = self
- .core
- .core
+ .server
.authenticate(
directory,
self.data.session_id,
@@ -182,8 +181,7 @@ impl<T: SessionStream> Session<T> {
// Validate permissions
if let Ok(principal) = &result {
match self
- .core
- .core
+ .server
.get_cached_access_token(principal.id())
.await
.caused_by(trc::location!())
diff --git a/crates/smtp/src/inbound/data.rs b/crates/smtp/src/inbound/data.rs
index 822fc734..80477eac 100644
--- a/crates/smtp/src/inbound/data.rs
+++ b/crates/smtp/src/inbound/data.rs
@@ -34,7 +34,8 @@ use utils::config::Rate;
use crate::{
core::{Session, SessionAddress, State},
inbound::milter::Modification,
- queue::{self, Message, MessageSource, QueueEnvelope, Schedule},
+ queue::{self, quota::HasQueueQuota, Message, MessageSource, QueueEnvelope, Schedule},
+ reporting::analysis::AnalyzeReport,
scripts::ScriptResult,
};
@@ -46,7 +47,7 @@ impl<T: SessionStream> Session<T> {
let raw_message = Arc::new(std::mem::take(&mut self.data.message));
let auth_message = if let Some(auth_message) = AuthenticatedMessage::parse_with_opts(
&raw_message,
- self.core.core.smtp.mail_auth.dkim.strict,
+ self.server.core.smtp.mail_auth.dkim.strict,
) {
auth_message
} else {
@@ -59,13 +60,12 @@ impl<T: SessionStream> Session<T> {
};
// Loop detection
- let dc = &self.core.core.smtp.session.data;
- let ac = &self.core.core.smtp.mail_auth;
- let rc = &self.core.core.smtp.report;
+ let dc = &self.server.core.smtp.session.data;
+ let ac = &self.server.core.smtp.mail_auth;
+ let rc = &self.server.core.smtp.report;
if auth_message.received_headers_count()
> self
- .core
- .core
+ .server
.eval_if(&dc.max_received_headers, self, self.data.session_id)
.await
.unwrap_or(50)
@@ -82,21 +82,19 @@ impl<T: SessionStream> Session<T> {
// Verify DKIM
let dkim = self
- .core
- .core
+ .server
.eval_if(&ac.dkim.verify, self, self.data.session_id)
.await
.unwrap_or(VerifyStrategy::Relaxed);
let dmarc = self
- .core
- .core
+ .server
.eval_if(&ac.dmarc.verify, self, self.data.session_id)
.await
.unwrap_or(VerifyStrategy::Relaxed);
let dkim_output = if dkim.verify() || dmarc.verify() {
let time = Instant::now();
let dkim_output = self
- .core
+ .server
.core
.smtp
.resolvers
@@ -111,8 +109,7 @@ impl<T: SessionStream> Session<T> {
// Send reports for failed signatures
if let Some(rate) = self
- .core
- .core
+ .server
.eval_if::<Rate, _>(&rc.dkim.send, self, self.data.session_id)
.await
{
@@ -155,21 +152,19 @@ impl<T: SessionStream> Session<T> {
// Verify ARC
let arc = self
- .core
- .core
+ .server
.eval_if(&ac.arc.verify, self, self.data.session_id)
.await
.unwrap_or(VerifyStrategy::Relaxed);
let arc_sealer = self
- .core
- .core
+ .server
.eval_if::<String, _>(&ac.arc.seal, self, self.data.session_id)
.await
- .and_then(|name| self.core.core.get_arc_sealer(&name, self.data.session_id));
+ .and_then(|name| self.server.get_arc_sealer(&name, self.data.session_id));
let arc_output = if arc.verify() || arc_sealer.is_some() {
let time = Instant::now();
let arc_output = self
- .core
+ .server
.core
.smtp
.resolvers
@@ -236,7 +231,7 @@ impl<T: SessionStream> Session<T> {
Some(spf_output) if dmarc.verify() => {
let time = Instant::now();
let dmarc_output = self
- .core
+ .server
.core
.smtp
.resolvers
@@ -317,7 +312,7 @@ impl<T: SessionStream> Session<T> {
// Analyze reports
if is_report {
- self.core
+ self.server
.analyze_report(raw_message.clone(), self.data.session_id);
if !rc.analysis.forward {
self.data.messages_sent += 1;
@@ -326,11 +321,16 @@ impl<T: SessionStream> Session<T> {
}
// Add Received header
- let message_id = self.core.inner.queue_id_gen.generate().unwrap_or_else(now);
+ let message_id = self
+ .server
+ .inner
+ .data
+ .queue_id_gen
+ .generate()
+ .unwrap_or_else(now);
let mut headers = Vec::with_capacity(64);
if self
- .core
- .core
+ .server
.eval_if(&dc.add_received, self, self.data.session_id)
.await
.unwrap_or(true)
@@ -340,8 +340,7 @@ impl<T: SessionStream> Session<T> {
// Add authentication results header
if self
- .core
- .core
+ .server
.eval_if(&dc.add_auth_results, self, self.data.session_id)
.await
.unwrap_or(true)
@@ -352,8 +351,7 @@ impl<T: SessionStream> Session<T> {
// Add Received-SPF header
if let Some(spf_output) = &self.data.spf_mail_from {
if self
- .core
- .core
+ .server
.eval_if(&dc.add_received_spf, self, self.data.session_id)
.await
.unwrap_or(true)
@@ -425,23 +423,20 @@ impl<T: SessionStream> Session<T> {
// Pipe message
for pipe in &dc.pipe_commands {
if let Some(command_) = self
- .core
- .core
+ .server
.eval_if::<String, _>(&pipe.command, self, self.data.session_id)
.await
{
let piped_message = edited_message.as_ref().unwrap_or(&raw_message).clone();
let timeout = self
- .core
- .core
+ .server
.eval_if(&pipe.timeout, self, self.data.session_id)
.await
.unwrap_or_else(|| Duration::from_secs(30));
let mut command = Command::new(&command_);
for argument in self
- .core
- .core
+ .server
.eval_if::<Vec<String>, _>(&pipe.arguments, self, self.data.session_id)
.await
.unwrap_or_default()
@@ -538,13 +533,11 @@ impl<T: SessionStream> Session<T> {
// Sieve filtering
if let Some((script, script_id)) = self
- .core
- .core
+ .server
.eval_if::<String, _>(&dc.script, self, self.data.session_id)
.await
.and_then(|name| {
- self.core
- .core
+ self.server
.get_trusted_sieve_script(&name, self.data.session_id)
.map(|s| (s, name))
})
@@ -642,8 +635,7 @@ impl<T: SessionStream> Session<T> {
// Add Return-Path
if self
- .core
- .core
+ .server
.eval_if(&dc.add_return_path, self, self.data.session_id)
.await
.unwrap_or(true)
@@ -656,8 +648,7 @@ impl<T: SessionStream> Session<T> {
// Add any missing headers
if !auth_message.has_date_header()
&& self
- .core
- .core
+ .server
.eval_if(&dc.add_date, self, self.data.session_id)
.await
.unwrap_or(true)
@@ -668,8 +659,7 @@ impl<T: SessionStream> Session<T> {
}
if !auth_message.has_message_id_header()
&& self
- .core
- .core
+ .server
.eval_if(&dc.add_message_id, self, self.data.session_id)
.await
.unwrap_or(true)
@@ -684,17 +674,12 @@ impl<T: SessionStream> Session<T> {
.as_deref()
.unwrap_or_else(|| raw_message.as_slice());
for signer in self
- .core
- .core
+ .server
.eval_if::<Vec<String>, _>(&ac.dkim.sign, self, self.data.session_id)
.await
.unwrap_or_default()
{
- if let Some(signer) = self
- .core
- .core
- .get_dkim_signer(&signer, self.data.session_id)
- {
+ if let Some(signer) = self.server.get_dkim_signer(&signer, self.data.session_id) {
match signer.sign_chained(&[headers.as_ref(), raw_message]) {
Ok(signature) => {
signature.write_header(&mut headers);
@@ -712,7 +697,7 @@ impl<T: SessionStream> Session<T> {
message.size = raw_message.len() + headers.len();
// Verify queue quota
- if self.core.has_quota(&mut message).await {
+ if self.server.has_quota(&mut message).await {
// Prepare webhook event
let queue_id = message.queue_id;
@@ -727,7 +712,7 @@ impl<T: SessionStream> Session<T> {
Some(&headers),
raw_message,
self.data.session_id,
- &self.core,
+ &self.server,
source,
)
.await
@@ -799,10 +784,9 @@ impl<T: SessionStream> Session<T> {
};
// Set expiration and notification times
- let config = &self.core.core.smtp.queue;
+ let config = &self.server.core.smtp.queue;
let (num_intervals, next_notify) = self
- .core
- .core
+ .server
.eval_if::<Vec<Duration>, _>(&config.notify, &envelope, self.data.session_id)
.await
.and_then(|v| (v.len(), v.into_iter().next()?).into())
@@ -813,8 +797,7 @@ impl<T: SessionStream> Session<T> {
now()
+ future_release.as_secs()
+ self
- .core
- .core
+ .server
.eval_if(&config.expire, &envelope, self.data.session_id)
.await
.unwrap_or_else(|| Duration::from_secs(5 * 86400))
@@ -827,8 +810,7 @@ impl<T: SessionStream> Session<T> {
)
} else {
let expire = self
- .core
- .core
+ .server
.eval_if(&config.expire, &envelope, self.data.session_id)
.await
.unwrap_or_else(|| Duration::from_secs(5 * 86400));
@@ -887,10 +869,9 @@ impl<T: SessionStream> Session<T> {
if !self.data.rcpt_to.is_empty() {
if self.data.messages_sent
< self
- .core
- .core
+ .server
.eval_if(
- &self.core.core.smtp.session.data.max_messages,
+ &self.server.core.smtp.session.data.max_messages,
self,
self.data.session_id,
)
diff --git a/crates/smtp/src/inbound/ehlo.rs b/crates/smtp/src/inbound/ehlo.rs
index 49580945..deeae3d1 100644
--- a/crates/smtp/src/inbound/ehlo.rs
+++ b/crates/smtp/src/inbound/ehlo.rs
@@ -42,7 +42,7 @@ impl<T: SessionStream> Session<T> {
if self.params.spf_ehlo.verify() {
let time = Instant::now();
let spf_output = self
- .core
+ .server
.core
.smtp
.resolvers
@@ -76,17 +76,15 @@ impl<T: SessionStream> Session<T> {
// Sieve filtering
if let Some((script, script_id)) = self
- .core
- .core
+ .server
.eval_if::<String, _>(
- &self.core.core.smtp.session.ehlo.script,
+ &self.server.core.smtp.session.ehlo.script,
self,
self.data.session_id,
)
.await
.and_then(|name| {
- self.core
- .core
+ self.server
.get_trusted_sieve_script(&name, self.data.session_id)
.map(|s| (s, name))
})
@@ -140,14 +138,13 @@ impl<T: SessionStream> Session<T> {
if !self.stream.is_tls() && self.instance.acceptor.is_tls() {
response.capabilities |= EXT_START_TLS;
}
- let ec = &self.core.core.smtp.session.extensions;
- let ac = &self.core.core.smtp.session.auth;
- let dc = &self.core.core.smtp.session.data;
+ let ec = &self.server.core.smtp.session.extensions;
+ let ac = &self.server.core.smtp.session.auth;
+ let dc = &self.server.core.smtp.session.data;
// Pipelining
if self
- .core
- .core
+ .server
.eval_if(&ec.pipelining, self, self.data.session_id)
.await
.unwrap_or(true)
@@ -157,8 +154,7 @@ impl<T: SessionStream> Session<T> {
// Chunking
if self
- .core
- .core
+ .server
.eval_if(&ec.chunking, self, self.data.session_id)
.await
.unwrap_or(true)
@@ -168,8 +164,7 @@ impl<T: SessionStream> Session<T> {
// Address Expansion
if self
- .core
- .core
+ .server
.eval_if(&ec.expn, self, self.data.session_id)
.await
.unwrap_or(false)
@@ -179,8 +174,7 @@ impl<T: SessionStream> Session<T> {
// Recipient Verification
if self
- .core
- .core
+ .server
.eval_if(&ec.vrfy, self, self.data.session_id)
.await
.unwrap_or(false)
@@ -190,8 +184,7 @@ impl<T: SessionStream> Session<T> {
// Require TLS
if self
- .core
- .core
+ .server
.eval_if(&ec.requiretls, self, self.data.session_id)
.await
.unwrap_or(true)
@@ -201,8 +194,7 @@ impl<T: SessionStream> Session<T> {
// DSN
if self
- .core
- .core
+ .server
.eval_if(&ec.dsn, self, self.data.session_id)
.await
.unwrap_or(false)
@@ -213,8 +205,7 @@ impl<T: SessionStream> Session<T> {
// Authentication
if self.data.authenticated_as.is_empty() {
response.auth_mechanisms = self
- .core
- .core
+ .server
.eval_if::<Mechanism, _>(&ac.mechanisms, self, self.data.session_id)
.await
.unwrap_or_default()
@@ -226,8 +217,7 @@ impl<T: SessionStream> Session<T> {
// Future release
if let Some(value) = self
- .core
- .core
+ .server
.eval_if::<Duration, _>(&ec.future_release, self, self.data.session_id)
.await
{
@@ -242,8 +232,7 @@ impl<T: SessionStream> Session<T> {
// Deliver By
if let Some(value) = self
- .core
- .core
+ .server
.eval_if::<Duration, _>(&ec.deliver_by, self, self.data.session_id)
.await
{
@@ -253,8 +242,7 @@ impl<T: SessionStream> Session<T> {
// Priority
if let Some(value) = self
- .core
- .core
+ .server
.eval_if::<MtPriority, _>(&ec.mt_priority, self, self.data.session_id)
.await
{
@@ -264,8 +252,7 @@ impl<T: SessionStream> Session<T> {
// Size
response.size = self
- .core
- .core
+ .server
.eval_if(&dc.max_message_size, self, self.data.session_id)
.await
.unwrap_or(25 * 1024 * 1024);
@@ -275,8 +262,7 @@ impl<T: SessionStream> Session<T> {
// No soliciting
if let Some(value) = self
- .core
- .core
+ .server
.eval_if::<String, _>(&ec.no_soliciting, self, self.data.session_id)
.await
{
diff --git a/crates/smtp/src/inbound/hooks/message.rs b/crates/smtp/src/inbound/hooks/message.rs
index 6ad3b44f..37720509 100644
--- a/crates/smtp/src/inbound/hooks/message.rs
+++ b/crates/smtp/src/inbound/hooks/message.rs
@@ -36,7 +36,7 @@ impl<T: SessionStream> Session<T> {
message: Option<&AuthenticatedMessage<'_>>,
queue_id: Option<QueueId>,
) -> Result<Vec<Modification>, FilterResponse> {
- let mta_hooks = &self.core.core.smtp.session.hooks;
+ let mta_hooks = &self.server.core.smtp.session.hooks;
if mta_hooks.is_empty() {
return Ok(Vec::new());
}
@@ -45,8 +45,7 @@ impl<T: SessionStream> Session<T> {
for mta_hook in mta_hooks {
if !mta_hook.run_on_stage.contains(&stage)
|| !self
- .core
- .core
+ .server
.eval_if(&mta_hook.enable, self, self.data.session_id)
.await
.unwrap_or(false)
diff --git a/crates/smtp/src/inbound/mail.rs b/crates/smtp/src/inbound/mail.rs
index 45428f9e..033b7d3d 100644
--- a/crates/smtp/src/inbound/mail.rs
+++ b/crates/smtp/src/inbound/mail.rs
@@ -54,7 +54,7 @@ impl<T: SessionStream> Session<T> {
} else if self.data.iprev.is_none() && self.params.iprev.verify() {
let time = Instant::now();
let iprev = self
- .core
+ .server
.core
.smtp
.resolvers
@@ -122,10 +122,9 @@ impl<T: SessionStream> Session<T> {
// Check whether the address is allowed
if !self
- .core
- .core
+ .server
.eval_if::<bool, _>(
- &self.core.core.smtp.session.mail.is_allowed,
+ &self.server.core.smtp.session.mail.is_allowed,
self,
self.data.session_id,
)
@@ -145,17 +144,15 @@ impl<T: SessionStream> Session<T> {
// Sieve filtering
if let Some((script, script_id)) = self
- .core
- .core
+ .server
.eval_if::<String, _>(
- &self.core.core.smtp.session.mail.script,
+ &self.server.core.smtp.session.mail.script,
self,
self.data.session_id,
)
.await
.and_then(|name| {
- self.core
- .core
+ self.server
.get_trusted_sieve_script(&name, self.data.session_id)
.map(|s| (s, name))
})
@@ -199,10 +196,9 @@ impl<T: SessionStream> Session<T> {
// Address rewriting
if let Some(new_address) = self
- .core
- .core
+ .server
.eval_if::<String, _>(
- &self.core.core.smtp.session.mail.rewrite,
+ &self.server.core.smtp.session.mail.rewrite,
self,
self.data.session_id,
)
@@ -258,12 +254,11 @@ impl<T: SessionStream> Session<T> {
}
// Validate parameters
- let config = &self.core.core.smtp.session.extensions;
- let config_data = &self.core.core.smtp.session.data;
+ let config = &self.server.core.smtp.session.extensions;
+ let config_data = &self.server.core.smtp.session.data;
if (from.flags & MAIL_REQUIRETLS) != 0
&& !self
- .core
- .core
+ .server
.eval_if(&config.requiretls, self, self.data.session_id)
.await
.unwrap_or(false)
@@ -279,8 +274,7 @@ impl<T: SessionStream> Session<T> {
}
if (from.flags & (MAIL_BY_NOTIFY | MAIL_BY_RETURN)) != 0 {
if let Some(duration) = self
- .core
- .core
+ .server
.eval_if::<Duration, _>(&config.deliver_by, self, self.data.session_id)
.await
{
@@ -320,8 +314,7 @@ impl<T: SessionStream> Session<T> {
}
if from.mt_priority != 0 {
if self
- .core
- .core
+ .server
.eval_if::<MtPriority, _>(&config.mt_priority, self, self.data.session_id)
.await
.is_some()
@@ -351,8 +344,7 @@ impl<T: SessionStream> Session<T> {
if from.size > 0
&& from.size
> self
- .core
- .core
+ .server
.eval_if(&config_data.max_message_size, self, self.data.session_id)
.await
.unwrap_or(25 * 1024 * 1024)
@@ -370,8 +362,7 @@ impl<T: SessionStream> Session<T> {
}
if from.hold_for != 0 || from.hold_until != 0 {
if let Some(max_hold) = self
- .core
- .core
+ .server
.eval_if::<Duration, _>(&config.future_release, self, self.data.session_id)
.await
{
@@ -419,8 +410,7 @@ impl<T: SessionStream> Session<T> {
}
if has_dsn
&& !self
- .core
- .core
+ .server
.eval_if(&config.dsn, self, self.data.session_id)
.await
.unwrap_or(false)
@@ -438,7 +428,7 @@ impl<T: SessionStream> Session<T> {
let time = Instant::now();
let mail_from = self.data.mail_from.as_ref().unwrap();
let spf_output = if !mail_from.address.is_empty() {
- self.core
+ self.server
.core
.smtp
.resolvers
@@ -452,7 +442,7 @@ impl<T: SessionStream> Session<T> {
)
.await
} else {
- self.core
+ self.server
.core
.smtp
.resolvers
@@ -542,10 +532,9 @@ impl<T: SessionStream> Session<T> {
// Send report
if let (Some(recipient), Some(rate)) = (
spf_output.report_address(),
- self.core
- .core
+ self.server
.eval_if::<Rate, _>(
- &self.core.core.smtp.report.spf.send,
+ &self.server.core.smtp.report.spf.send,
self,
self.data.session_id,
)
diff --git a/crates/smtp/src/inbound/milter/message.rs b/crates/smtp/src/inbound/milter/message.rs
index 1bcbde1b..0b369161 100644
--- a/crates/smtp/src/inbound/milter/message.rs
+++ b/crates/smtp/src/inbound/milter/message.rs
@@ -35,7 +35,7 @@ impl<T: SessionStream> Session<T> {
stage: Stage,
message: Option<&AuthenticatedMessage<'_>>,
) -> Result<Vec<Modification>, FilterResponse> {
- let milters = &self.core.core.smtp.session.milters;
+ let milters = &self.server.core.smtp.session.milters;
if milters.is_empty() {
return Ok(Vec::new());
}
@@ -44,8 +44,7 @@ impl<T: SessionStream> Session<T> {
for milter in milters {
if !milter.run_on_stage.contains(&stage)
|| !self
- .core
- .core
+ .server
.eval_if(&milter.enable, self, self.data.session_id)
.await
.unwrap_or(false)
@@ -170,9 +169,9 @@ impl<T: SessionStream> Session<T> {
client
.into_tls(
if !milter.tls_allow_invalid_certs {
- &self.core.inner.connectors.pki_verify
+ &self.server.inner.data.smtp_connectors.pki_verify
} else {
- &self.core.inner.connectors.dummy_verify
+ &self.server.inner.data.smtp_connectors.dummy_verify
},
&milter.hostname,
)
diff --git a/crates/smtp/src/inbound/rcpt.rs b/crates/smtp/src/inbound/rcpt.rs
index 89c7b8dc..aab0be1e 100644
--- a/crates/smtp/src/inbound/rcpt.rs
+++ b/crates/smtp/src/inbound/rcpt.rs
@@ -77,25 +77,23 @@ impl<T: SessionStream> Session<T> {
// Address rewriting and Sieve filtering
let rcpt_script = self
- .core
- .core
+ .server
.eval_if::<String, _>(
- &self.core.core.smtp.session.rcpt.script,
+ &self.server.core.smtp.session.rcpt.script,
self,
self.data.session_id,
)
.await
.and_then(|name| {
- self.core
- .core
+ self.server
.get_trusted_sieve_script(&name, self.data.session_id)
.map(|s| (s.clone(), name))
});
if rcpt_script.is_some()
- || !self.core.core.smtp.session.rcpt.rewrite.is_empty()
+ || !self.server.core.smtp.session.rcpt.rewrite.is_empty()
|| self
- .core
+ .server
.core
.smtp
.session
@@ -146,10 +144,9 @@ impl<T: SessionStream> Session<T> {
// Address rewriting
if let Some(new_address) = self
- .core
- .core
+ .server
.eval_if::<String, _>(
- &self.core.core.smtp.session.rcpt.rewrite,
+ &self.server.core.smtp.session.rcpt.rewrite,
self,
self.data.session_id,
)
@@ -187,22 +184,20 @@ impl<T: SessionStream> Session<T> {
// Verify address
let rcpt = self.data.rcpt_to.last().unwrap();
if let Some(directory) = self
- .core
- .core
+ .server
.eval_if::<String, _>(
- &self.core.core.smtp.session.rcpt.directory,
+ &self.server.core.smtp.session.rcpt.directory,
self,
self.data.session_id,
)
.await
- .and_then(|name| self.core.core.get_directory(&name))
+ .and_then(|name| self.server.get_directory(&name))
{
match directory.is_local_domain(&rcpt.domain).await {
Ok(is_local_domain) => {
if is_local_domain {
match self
- .core
- .core
+ .server
.rcpt(directory, &rcpt.address_lcase, self.data.session_id)
.await
{
@@ -233,10 +228,9 @@ impl<T: SessionStream> Session<T> {
}
}
} else if !self
- .core
- .core
+ .server
.eval_if(
- &self.core.core.smtp.session.rcpt.relay,
+ &self.server.core.smtp.session.rcpt.relay,
self,
self.data.session_id,
)
@@ -266,10 +260,9 @@ impl<T: SessionStream> Session<T> {
}
}
} else if !self
- .core
- .core
+ .server
.eval_if(
- &self.core.core.smtp.session.rcpt.relay,
+ &self.server.core.smtp.session.rcpt.relay,
self,
self.data.session_id,
)
@@ -315,12 +308,7 @@ impl<T: SessionStream> Session<T> {
if self.data.rcpt_errors < self.params.rcpt_errors_max {
Ok(())
} else {
- match self
- .core
- .core
- .is_rcpt_fail2banned(self.data.remote_ip)
- .await
- {
+ match self.server.is_rcpt_fail2banned(self.data.remote_ip).await {
Ok(true) => {
trc::event!(
Security(SecurityEvent::BruteForceBan),
diff --git a/crates/smtp/src/inbound/session.rs b/crates/smtp/src/inbound/session.rs
index b0c91672..02648b5f 100644
--- a/crates/smtp/src/inbound/session.rs
+++ b/crates/smtp/src/inbound/session.rs
@@ -84,10 +84,9 @@ impl<T: SessionStream> Session<T> {
initial_response,
} => {
let auth: u64 = self
- .core
- .core
+ .server
.eval_if::<Mechanism, _>(
- &self.core.core.smtp.session.auth.mechanisms,
+ &self.server.core.smtp.session.auth.mechanisms,
self,
self.data.session_id,
)
diff --git a/crates/smtp/src/inbound/spawn.rs b/crates/smtp/src/inbound/spawn.rs
index e6892fc1..d7e08f8b 100644
--- a/crates/smtp/src/inbound/spawn.rs
+++ b/crates/smtp/src/inbound/spawn.rs
@@ -8,6 +8,7 @@ use std::time::Instant;
use common::{
config::smtp::session::Stage,
+ core::BuildServer,
listener::{self, SessionManager, SessionStream},
};
use tokio_rustls::server::TlsStream;
@@ -15,7 +16,6 @@ use trc::{SecurityEvent, SmtpEvent};
use crate::{
core::{Session, SessionData, SessionParameters, SmtpSessionManager, State},
- queue, reporting,
scripts::ScriptResult,
};
@@ -27,7 +27,7 @@ impl SessionManager for SmtpSessionManager {
// Create session
let mut session = Session {
hostname: String::new(),
- core: self.inner.into(),
+ server: self.inner.build_server(),
instance: session.instance,
state: State::default(),
stream: session.stream,
@@ -59,19 +59,23 @@ impl SessionManager for SmtpSessionManager {
#[allow(clippy::manual_async_fn)]
fn shutdown(&self) -> impl std::future::Future<Output = ()> + Send {
async {
- let _ = self.inner.inner.queue_tx.send(queue::Event::Stop).await;
let _ = self
.inner
+ .ipc
+ .queue_tx
+ .send(common::ipc::QueueEvent::Stop)
+ .await;
+ let _ = self
.inner
+ .ipc
.report_tx
- .send(reporting::Event::Stop)
+ .send(common::ipc::ReportingEvent::Stop)
.await;
let _ = self
.inner
- .inner
.ipc
.delivery_tx
- .send(common::DeliveryEvent::Stop)
+ .send(common::ipc::DeliveryEvent::Stop)
.await;
}
}
@@ -81,17 +85,15 @@ impl<T: SessionStream> Session<T> {
pub async fn init_conn(&mut self) -> bool {
self.eval_session_params().await;
- let config = &self.core.core.smtp.session.connect;
+ let config = &self.server.core.smtp.session.connect;
// Sieve filtering
if let Some((script, script_id)) = self
- .core
- .core
+ .server
.eval_if::<String, _>(&config.script, self, self.data.session_id)
.await
.and_then(|name| {
- self.core
- .core
+ self.server
.get_trusted_sieve_script(&name, self.data.session_id)
.map(|s| (s, name))
})
@@ -123,8 +125,7 @@ impl<T: SessionStream> Session<T> {
// Obtain hostname
self.hostname = self
- .core
- .core
+ .server
.eval_if::<String, _>(&config.hostname, self, self.data.session_id)
.await
.unwrap_or_default();
@@ -138,8 +139,7 @@ impl<T: SessionStream> Session<T> {
// Obtain greeting
let greeting = self
- .core
- .core
+ .server
.eval_if::<String, _>(&config.greeting, self, self.data.session_id)
.await
.filter(|g| !g.is_empty())
@@ -194,10 +194,7 @@ impl<T: SessionStream> Session<T> {
.await
.ok();
- match self
- .core
- .core
- .is_loiter_fail2banned(self.data.remote_ip)
+ match self.server.is_loiter_fail2banned(self.data.remote_ip)
.await
{
Ok(true) => {
@@ -277,7 +274,7 @@ impl<T: SessionStream> Session<T> {
state: self.state,
data: self.data,
instance: self.instance,
- core: self.core,
+ server: self.server,
in_flight: self.in_flight,
params: self.params,
})
diff --git a/crates/smtp/src/inbound/vrfy.rs b/crates/smtp/src/inbound/vrfy.rs
index 0c23687d..a99823d0 100644
--- a/crates/smtp/src/inbound/vrfy.rs
+++ b/crates/smtp/src/inbound/vrfy.rs
@@ -13,20 +13,18 @@ use std::fmt::Write;
impl<T: SessionStream> Session<T> {
pub async fn handle_vrfy(&mut self, address: String) -> Result<(), ()> {
match self
- .core
- .core
+ .server
.eval_if::<String, _>(
- &self.core.core.smtp.session.rcpt.directory,
+ &self.server.core.smtp.session.rcpt.directory,
self,
self.data.session_id,
)
.await
- .and_then(|name| self.core.core.get_directory(&name))
+ .and_then(|name| self.server.get_directory(&name))
{
Some(directory) if self.params.can_vrfy => {
match self
- .core
- .core
+ .server
.vrfy(directory, &address.to_lowercase(), self.data.session_id)
.await
{
@@ -88,20 +86,18 @@ impl<T: SessionStream> Session<T> {
pub async fn handle_expn(&mut self, address: String) -> Result<(), ()> {
match self
- .core
- .core
+ .server
.eval_if::<String, _>(
- &self.core.core.smtp.session.rcpt.directory,
+ &self.server.core.smtp.session.rcpt.directory,
self,
self.data.session_id,
)
.await
- .and_then(|name| self.core.core.get_directory(&name))
+ .and_then(|name| self.server.get_directory(&name))
{
Some(directory) if self.params.can_expn => {
match self
- .core
- .core
+ .server
.expn(directory, &address.to_lowercase(), self.data.session_id)
.await
{