//! SMTP server configuration. use serde::{Deserialize, Serialize}; /// Configuration for an SMTP server instance. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct SmtpServerConfig { /// Server hostname for greeting and EHLO responses. pub hostname: String, /// Ports to listen on (e.g. [25, 587]). pub ports: Vec, /// Port for implicit TLS (e.g. 465). None = no implicit TLS port. pub secure_port: Option, /// TLS certificate chain in PEM format. pub tls_cert_pem: Option, /// TLS private key in PEM format. pub tls_key_pem: Option, /// Maximum message size in bytes. pub max_message_size: u64, /// Maximum number of concurrent connections. pub max_connections: u32, /// Maximum recipients per message. pub max_recipients: u32, /// Connection timeout in seconds. pub connection_timeout_secs: u64, /// Data phase timeout in seconds. pub data_timeout_secs: u64, /// Whether authentication is available. pub auth_enabled: bool, /// Maximum authentication failures before disconnect. pub max_auth_failures: u32, /// Socket timeout in seconds (idle timeout for the entire connection). pub socket_timeout_secs: u64, /// Timeout in seconds waiting for TS to respond to email processing. pub processing_timeout_secs: u64, } impl Default for SmtpServerConfig { fn default() -> Self { Self { hostname: "mail.example.com".to_string(), ports: vec![25], secure_port: None, tls_cert_pem: None, tls_key_pem: None, max_message_size: 10 * 1024 * 1024, // 10 MB max_connections: 100, max_recipients: 100, connection_timeout_secs: 30, data_timeout_secs: 60, auth_enabled: false, max_auth_failures: 3, socket_timeout_secs: 300, processing_timeout_secs: 30, } } } impl SmtpServerConfig { /// Check if TLS is configured. pub fn has_tls(&self) -> bool { self.tls_cert_pem.is_some() && self.tls_key_pem.is_some() } } #[cfg(test)] mod tests { use super::*; #[test] fn test_defaults() { let cfg = SmtpServerConfig::default(); assert_eq!(cfg.max_message_size, 10 * 1024 * 1024); assert_eq!(cfg.max_connections, 100); assert!(!cfg.has_tls()); } #[test] fn test_has_tls() { let mut cfg = SmtpServerConfig::default(); cfg.tls_cert_pem = Some("cert".into()); assert!(!cfg.has_tls()); // need both cfg.tls_key_pem = Some("key".into()); assert!(cfg.has_tls()); } }