mirror of
https://github.com/rustmailer/bichon.git
synced 2026-08-03 07:48:34 +02:00
feat(config): add built-in IMAP server config with shared SMTP/IMAP TLS paths
This commit is contained in:
@@ -265,7 +265,7 @@ pub struct Settings {
|
|||||||
Ok(s.to_string())
|
Ok(s.to_string())
|
||||||
})
|
})
|
||||||
)]
|
)]
|
||||||
pub bichon_smtp_tls_key_path: Option<String>,
|
pub bichon_tls_key_path: Option<String>,
|
||||||
|
|
||||||
#[clap(
|
#[clap(
|
||||||
long,
|
long,
|
||||||
@@ -282,7 +282,7 @@ pub struct Settings {
|
|||||||
Ok(s.to_string())
|
Ok(s.to_string())
|
||||||
})
|
})
|
||||||
)]
|
)]
|
||||||
pub bichon_smtp_tls_cert_path: Option<String>,
|
pub bichon_tls_cert_path: Option<String>,
|
||||||
|
|
||||||
#[clap(
|
#[clap(
|
||||||
long,
|
long,
|
||||||
@@ -299,7 +299,7 @@ pub struct Settings {
|
|||||||
default_value = "starttls",
|
default_value = "starttls",
|
||||||
help = "Set the encryption mode for SMTP: 'none', 'starttls', or 'tls'"
|
help = "Set the encryption mode for SMTP: 'none', 'starttls', or 'tls'"
|
||||||
)]
|
)]
|
||||||
pub bichon_smtp_encryption: SmtpEncryptionMode,
|
pub bichon_smtp_encryption: EncryptionMode,
|
||||||
|
|
||||||
#[clap(
|
#[clap(
|
||||||
long,
|
long,
|
||||||
@@ -309,6 +309,42 @@ pub struct Settings {
|
|||||||
)]
|
)]
|
||||||
pub bichon_smtp_auth_required: bool,
|
pub bichon_smtp_auth_required: bool,
|
||||||
|
|
||||||
|
/// Enable the built-in IMAP server for read-only email access via standard
|
||||||
|
/// email clients (Thunderbird, Outlook, Apple Mail, etc.).
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
default_value = "false",
|
||||||
|
env,
|
||||||
|
help = "Enable the embedded IMAP server"
|
||||||
|
)]
|
||||||
|
pub bichon_enable_imap: bool,
|
||||||
|
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
default_value = "10143",
|
||||||
|
env,
|
||||||
|
help = "Set the IMAP port (STARTTLS or plaintext)",
|
||||||
|
value_parser = clap::value_parser!(u16).range(1..)
|
||||||
|
)]
|
||||||
|
pub bichon_imap_port: u16,
|
||||||
|
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
default_value = "10993",
|
||||||
|
env,
|
||||||
|
help = "Set the IMAPS port (implicit TLS)",
|
||||||
|
value_parser = clap::value_parser!(u16).range(1..)
|
||||||
|
)]
|
||||||
|
pub bichon_imaps_port: u16,
|
||||||
|
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
env,
|
||||||
|
default_value = "none",
|
||||||
|
help = "Set the encryption mode for IMAP: 'none', 'starttls', or 'tls'"
|
||||||
|
)]
|
||||||
|
pub bichon_imap_encryption: EncryptionMode,
|
||||||
|
|
||||||
/// Enable OIDC-based Single Sign-On (Pro/Enterprise feature).
|
/// Enable OIDC-based Single Sign-On (Pro/Enterprise feature).
|
||||||
#[clap(long, default_value = "false", env, help = "Enable OpenID Connect SSO")]
|
#[clap(long, default_value = "false", env, help = "Enable OpenID Connect SSO")]
|
||||||
pub bichon_oidc_enabled: bool,
|
pub bichon_oidc_enabled: bool,
|
||||||
@@ -417,7 +453,7 @@ impl fmt::Display for CompressionAlgorithm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, ValueEnum)]
|
#[derive(Clone, Copy, Debug, PartialEq, ValueEnum)]
|
||||||
pub enum SmtpEncryptionMode {
|
pub enum EncryptionMode {
|
||||||
#[clap(name = "none")]
|
#[clap(name = "none")]
|
||||||
None,
|
None,
|
||||||
#[clap(name = "starttls")]
|
#[clap(name = "starttls")]
|
||||||
@@ -426,12 +462,12 @@ pub enum SmtpEncryptionMode {
|
|||||||
Tls,
|
Tls,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for SmtpEncryptionMode {
|
impl fmt::Display for EncryptionMode {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
SmtpEncryptionMode::None => write!(f, "none"),
|
EncryptionMode::None => write!(f, "none"),
|
||||||
SmtpEncryptionMode::Starttls => write!(f, "starttls"),
|
EncryptionMode::Starttls => write!(f, "starttls"),
|
||||||
SmtpEncryptionMode::Tls => write!(f, "tls"),
|
EncryptionMode::Tls => write!(f, "tls"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,8 +103,8 @@ impl From<&Settings> for SystemConfigurations {
|
|||||||
bichon_smtp_port: s.bichon_smtp_port,
|
bichon_smtp_port: s.bichon_smtp_port,
|
||||||
bichon_smtp_encryption: s.bichon_smtp_encryption.to_string(),
|
bichon_smtp_encryption: s.bichon_smtp_encryption.to_string(),
|
||||||
bichon_smtp_auth_required: s.bichon_smtp_auth_required,
|
bichon_smtp_auth_required: s.bichon_smtp_auth_required,
|
||||||
bichon_smtp_tls_key_path: s.bichon_smtp_tls_key_path.clone(),
|
bichon_smtp_tls_key_path: s.bichon_tls_key_path.clone(),
|
||||||
bichon_smtp_tls_cert_path: s.bichon_smtp_tls_cert_path.clone(),
|
bichon_smtp_tls_cert_path: s.bichon_tls_cert_path.clone(),
|
||||||
bichon_oidc_enabled: s.bichon_oidc_enabled,
|
bichon_oidc_enabled: s.bichon_oidc_enabled,
|
||||||
bichon_oidc_issuer_url: s.bichon_oidc_issuer_url.clone(),
|
bichon_oidc_issuer_url: s.bichon_oidc_issuer_url.clone(),
|
||||||
bichon_oidc_client_id: s.bichon_oidc_client_id.clone(),
|
bichon_oidc_client_id: s.bichon_oidc_client_id.clone(),
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ use bichon_core::cache::imap::mailbox::{Attribute, AttributeEnum};
|
|||||||
use bichon_core::common::signal::SIGNAL_MANAGER;
|
use bichon_core::common::signal::SIGNAL_MANAGER;
|
||||||
use bichon_core::envelope::extractor::extract_envelope_from_smtp;
|
use bichon_core::envelope::extractor::extract_envelope_from_smtp;
|
||||||
use bichon_core::error::BichonResult;
|
use bichon_core::error::BichonResult;
|
||||||
use bichon_core::settings::cli::{SmtpEncryptionMode, SETTINGS};
|
use bichon_core::settings::cli::{EncryptionMode, SETTINGS};
|
||||||
use bichon_core::utils::create_hash;
|
use bichon_core::utils::create_hash;
|
||||||
use bichon_core::{
|
use bichon_core::{
|
||||||
account::migration::AccountModel,
|
account::migration::AccountModel,
|
||||||
@@ -698,8 +698,8 @@ pub async fn start_smtp_server() -> std::io::Result<SmtpServer> {
|
|||||||
let smtp_port = SETTINGS.bichon_smtp_port;
|
let smtp_port = SETTINGS.bichon_smtp_port;
|
||||||
|
|
||||||
let tls_acceptor: Option<TlsAcceptor> = match SETTINGS.bichon_smtp_encryption {
|
let tls_acceptor: Option<TlsAcceptor> = match SETTINGS.bichon_smtp_encryption {
|
||||||
SmtpEncryptionMode::None => None,
|
EncryptionMode::None => None,
|
||||||
SmtpEncryptionMode::Starttls | SmtpEncryptionMode::Tls => Some(create_acceptor().await?),
|
EncryptionMode::Starttls | EncryptionMode::Tls => Some(create_acceptor().await?),
|
||||||
};
|
};
|
||||||
|
|
||||||
let smtp_listener = TcpListener::bind((
|
let smtp_listener = TcpListener::bind((
|
||||||
@@ -721,15 +721,15 @@ pub async fn start_smtp_server() -> std::io::Result<SmtpServer> {
|
|||||||
let smtp_config = SmtpConfig {
|
let smtp_config = SmtpConfig {
|
||||||
whitelist: None,
|
whitelist: None,
|
||||||
tls_acceptor: match SETTINGS.bichon_smtp_encryption {
|
tls_acceptor: match SETTINGS.bichon_smtp_encryption {
|
||||||
SmtpEncryptionMode::None | SmtpEncryptionMode::Tls => None,
|
EncryptionMode::None | EncryptionMode::Tls => None,
|
||||||
SmtpEncryptionMode::Starttls => tls_acceptor.clone(),
|
EncryptionMode::Starttls => tls_acceptor.clone(),
|
||||||
},
|
},
|
||||||
auth_required: SETTINGS.bichon_smtp_auth_required,
|
auth_required: SETTINGS.bichon_smtp_auth_required,
|
||||||
};
|
};
|
||||||
|
|
||||||
let smtp_shutdown = SIGNAL_MANAGER.subscribe();
|
let smtp_shutdown = SIGNAL_MANAGER.subscribe();
|
||||||
|
|
||||||
let smtp_handle = if matches!(SETTINGS.bichon_smtp_encryption, SmtpEncryptionMode::Tls) {
|
let smtp_handle = if matches!(SETTINGS.bichon_smtp_encryption, EncryptionMode::Tls) {
|
||||||
let acceptor = tls_acceptor
|
let acceptor = tls_acceptor
|
||||||
.clone()
|
.clone()
|
||||||
.expect("TLS acceptor required when tls=true");
|
.expect("TLS acceptor required when tls=true");
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ use bichon_core::settings::cli::SETTINGS;
|
|||||||
|
|
||||||
pub async fn create_acceptor() -> io::Result<TlsAcceptor> {
|
pub async fn create_acceptor() -> io::Result<TlsAcceptor> {
|
||||||
let (certs, key) = if let (Some(key_path), Some(cert_path)) = (
|
let (certs, key) = if let (Some(key_path), Some(cert_path)) = (
|
||||||
&SETTINGS.bichon_smtp_tls_key_path,
|
&SETTINGS.bichon_tls_key_path,
|
||||||
&SETTINGS.bichon_smtp_tls_cert_path,
|
&SETTINGS.bichon_tls_cert_path,
|
||||||
) {
|
) {
|
||||||
load_certs_from_files(key_path, cert_path).await?
|
load_certs_from_files(key_path, cert_path).await?
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user