pub mod config;
use async_trait::async_trait;
use log::info;
use std::sync::Arc;
use crate::{
account::config::AccountConfig,
backend::{
context::{BackendContext, BackendContextBuilder},
feature::BackendFeature,
},
message::send::{sendmail::SendSendmailMessage, SendMessage},
Result,
};
use self::config::SendmailConfig;
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct SendmailContext {
pub account_config: Arc<AccountConfig>,
pub sendmail_config: Arc<SendmailConfig>,
}
impl SendmailContext {
pub fn new(account_config: Arc<AccountConfig>, sendmail_config: Arc<SendmailConfig>) -> Self {
Self {
account_config,
sendmail_config,
}
}
}
pub type SendmailContextSync = SendmailContext;
impl BackendContext for SendmailContextSync {}
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct SendmailContextBuilder {
pub account_config: Arc<AccountConfig>,
pub sendmail_config: Arc<SendmailConfig>,
}
impl SendmailContextBuilder {
pub fn new(account_config: Arc<AccountConfig>, sendmail_config: Arc<SendmailConfig>) -> Self {
Self {
account_config,
sendmail_config,
}
}
}
#[async_trait]
impl BackendContextBuilder for SendmailContextBuilder {
type Context = SendmailContextSync;
fn send_message(&self) -> Option<BackendFeature<Self::Context, dyn SendMessage>> {
Some(Arc::new(SendSendmailMessage::some_new_boxed))
}
async fn build(self) -> Result<Self::Context> {
info!("building new sendmail context");
Ok(SendmailContextSync {
account_config: self.account_config,
sendmail_config: self.sendmail_config,
})
}
}