v0.0.5
RustBox CI / rustbox (push) Waiting to run

This commit is contained in:
Mateusz Gruszczyński committed 2026-10-30 12:06:44 +01:00
1 parent 96a32ea8fb
commit a643e7e3ab
106 files changed
+2223 -4669

No files matched your search

-28
View File
@@ -1,46 +1,22 @@
//! SMTP client abstraction and real implementation.
use async_trait::async_trait;
// Import and re-export types for backward compatibility
pub use crate::smtp::error::SmtpError;
pub use crate::smtp::types::{AttachmentData, SendableMessage, SmtpCredentials, SmtpSendResult};
// ---------------------------------------------------------------------------
// Trait definition
// ---------------------------------------------------------------------------
/// Abstraction over SMTP operations.
///
/// Every method receives explicit connection parameters so that the trait
/// remains stateless — no persistent connections are held.
///
/// The `Send + Sync` bounds allow implementations to be shared across
/// Tokio tasks and stored in `Arc`.
#[allow(clippy::double_must_use)]
#[async_trait]
pub trait SmtpClient: Send + Sync {
/// Send an email message. Returns the generated Message-ID and exact RFC822 bytes.
async fn send_message(
&self,
creds: &SmtpCredentials,
message: &SendableMessage,
) -> Result<SmtpSendResult, SmtpError>;
/// Verify that the configured SMTP endpoint accepts an authenticated NOOP.
async fn check_connection(&self, _creds: &SmtpCredentials) -> Result<(), SmtpError> {
Ok(())
}
}
// ---------------------------------------------------------------------------
// Real implementation backed by lettre
// ---------------------------------------------------------------------------
/// Production SMTP client that uses `lettre`.
///
/// This is a stateless unit struct — every method creates a fresh connection,
/// performs the operation, and disconnects.
pub struct RealSmtpClient;
fn smtp_transport(
@@ -142,10 +118,6 @@ impl SmtpClient for RealSmtpClient {
}
}
// ---------------------------------------------------------------------------
// Mock implementation (test-only)
// ---------------------------------------------------------------------------
#[cfg(test)]
#[path = "mock.rs"]
pub mod mock;