1pub mod api;
2pub mod auth;
3pub mod models;
4pub mod smtp;
5pub mod storage;
6use once_cell::sync::OnceCell;
7use storage::Storage;
8use tokio::sync::broadcast::Sender;
9
10static APP: OnceCell<Mutex<Mailtutan>> = OnceCell::new();
11
12use std::{net::Ipv4Addr, sync::Mutex};
13
14pub struct Mailtutan {
15 pub ip: Ipv4Addr,
16 pub http_port: u16,
17 pub smtp_port: u16,
18 pub storage: Box<dyn Storage + 'static>,
19 pub ws_sender: Sender<String>,
20 pub http_auth: bool,
21 pub http_username: String,
22 pub http_password: String,
23 pub messages_limit: usize,
24 pub smtp_cert_path: Option<String>,
25 pub smtp_key_path: Option<String>,
26 pub smtp_auth_username: Option<String>,
27 pub smtp_auth_password: Option<String>,
28}
29
30impl Mailtutan {
31 pub fn get_api_uri(&self) -> String {
32 format!("{}:{}", self.ip, self.http_port)
33 }
34
35 pub fn get_smtp_uri(&self) -> String {
36 format!("{}:{}", self.ip, self.smtp_port)
37 }
38
39 pub fn init(self) {
40 APP.get_or_init(|| Mutex::new(self));
41 }
42
43 pub fn is_smtp_auth_enabled(&self) -> bool {
44 self.smtp_auth_username.is_some() && self.smtp_auth_password.is_some()
45 }
46}