From 9fc7236977daf738f5a70645bff995f0460cc9b5 Mon Sep 17 00:00:00 2001 From: starkbamse <139136798+starkbamse@users.noreply.github.com> Date: Sun, 8 Sep 2024 12:28:16 +0200 Subject: [PATCH] Replace domain placeholder Reply with lib name or custom set env variable --- src/lib.rs | 1 + src/parser/ehlo.rs | 5 ++--- src/parser/helo.rs | 3 +-- src/parser/responses.rs | 12 ++++++++++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ad68939..04b4a20 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -86,4 +86,5 @@ mod tests { log::info!("Received mail: {:?}", mail); listening_server.stop().await.unwrap(); } + } diff --git a/src/parser/ehlo.rs b/src/parser/ehlo.rs index c96ae9b..73cc5ae 100644 --- a/src/parser/ehlo.rs +++ b/src/parser/ehlo.rs @@ -1,5 +1,4 @@ use std::str::SplitWhitespace; - use tokio::io; use crate::{ @@ -22,7 +21,7 @@ pub fn ehlo( } // Return based on the TLS configuration Ok(match connection.tls_config { - TlsConfig::Encrypted { .. } => EHLO_TLS_AVAILABLE, - _ => EHLO_TLS_UNAVAILABLE, + TlsConfig::Encrypted { .. } => &EHLO_TLS_AVAILABLE, + _ => &EHLO_TLS_UNAVAILABLE, }) } diff --git a/src/parser/helo.rs b/src/parser/helo.rs index eeb9fce..91a153c 100644 --- a/src/parser/helo.rs +++ b/src/parser/helo.rs @@ -1,5 +1,4 @@ use std::str::SplitWhitespace; - use tokio::io; use crate::{ @@ -21,5 +20,5 @@ pub fn helo( connection.state = State::Ehlo("".to_string()); } // We never support TLS on HELO - Ok(EHLO_TLS_UNAVAILABLE) + Ok(&EHLO_TLS_UNAVAILABLE) } diff --git a/src/parser/responses.rs b/src/parser/responses.rs index adc236c..0340c23 100644 --- a/src/parser/responses.rs +++ b/src/parser/responses.rs @@ -1,7 +1,15 @@ +use std::{env, sync::LazyLock}; + // Responses as per RFC 5321 // The following are the responses that the server can send to the client as per RFC 5321: -pub static EHLO_TLS_AVAILABLE: &[u8] = b"250-%DOMAIN%\r\n250 STARTTLS\r\n"; -pub static EHLO_TLS_UNAVAILABLE: &[u8] = b"250 %DOMAIN%\r\n"; +pub static EHLO_TLS_AVAILABLE:LazyLock> = LazyLock::new(|| { + let domain=env::var("MINISMTP_DOMAIN").unwrap_or_else(|_| "minismtp".to_string()); + format!("250-{}\r\n250 STARTTLS\r\n",domain).as_bytes().to_vec() +}); +pub static EHLO_TLS_UNAVAILABLE:LazyLock> = LazyLock::new(|| { + let domain=env::var("MINISMTP_DOMAIN").unwrap_or_else(|_| "minismtp".to_string()); + format!("250 {}\r\n",domain).as_bytes().to_vec() +}); pub static OK: &[u8] = b"250 OK\r\n"; pub static READY_FOR_TLS: &[u8] = b"220 Ready to start TLS\r\n"; pub static TLS_NOT_AVAILABLE: &[u8] = b"502 TLS not available\r\n";