mockforge_smtp/
lib.rs

1//! SMTP server mocking for MockForge
2//!
3//! This crate provides SMTP server functionality for MockForge, allowing you to mock
4//! email servers for testing purposes.
5//!
6//! # Example
7//!
8//! ```no_run
9//! use mockforge_smtp::{SmtpConfig, SmtpServer, SmtpSpecRegistry};
10//! use std::sync::Arc;
11//!
12//! #[tokio::main]
13//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
14//!     let config = SmtpConfig::default();
15//!     let registry = Arc::new(SmtpSpecRegistry::new());
16//!
17//!     let server = SmtpServer::new(config, registry)?;
18//!     server.start().await?;
19//!
20//!     Ok(())
21//! }
22//! ```
23
24mod fixtures;
25mod server;
26mod spec_registry;
27
28pub use fixtures::*;
29pub use server::*;
30pub use spec_registry::*;
31
32use serde::{Deserialize, Serialize};
33use std::path::PathBuf;
34
35/// SMTP server configuration
36#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct SmtpConfig {
38    /// Server port (default: 1025)
39    pub port: u16,
40    /// Host address (default: 0.0.0.0)
41    pub host: String,
42    /// Server hostname for SMTP greeting
43    pub hostname: String,
44    /// Directory containing fixture files
45    pub fixtures_dir: Option<PathBuf>,
46    /// Connection timeout in seconds
47    pub timeout_secs: u64,
48    /// Maximum connections
49    pub max_connections: usize,
50    /// Enable mailbox storage
51    pub enable_mailbox: bool,
52    /// Maximum mailbox size
53    pub max_mailbox_messages: usize,
54    /// Enable STARTTLS support
55    pub enable_starttls: bool,
56    /// Path to TLS certificate file
57    pub tls_cert_path: Option<PathBuf>,
58    /// Path to TLS private key file
59    pub tls_key_path: Option<PathBuf>,
60}
61
62impl Default for SmtpConfig {
63    fn default() -> Self {
64        Self {
65            port: 1025,
66            host: "0.0.0.0".to_string(),
67            hostname: "mockforge-smtp".to_string(),
68            fixtures_dir: Some(PathBuf::from("./fixtures/smtp")),
69            timeout_secs: 300,
70            max_connections: 10,
71            enable_mailbox: true,
72            max_mailbox_messages: 1000,
73            enable_starttls: false,
74            tls_cert_path: None,
75            tls_key_path: None,
76        }
77    }
78}
79
80#[cfg(test)]
81mod tests {
82    use super::*;
83    use mockforge_core::protocol_abstraction::Protocol;
84
85    #[test]
86    fn test_default_config() {
87        let config = SmtpConfig::default();
88        assert_eq!(config.port, 1025);
89        assert_eq!(config.host, "0.0.0.0");
90        assert_eq!(config.hostname, "mockforge-smtp");
91    }
92
93    #[test]
94    fn test_protocol_display() {
95        assert_eq!(Protocol::Smtp.to_string(), "SMTP");
96    }
97}