mailbourne_core/config.rs
1//! # config — one schema, three sources
2//!
3//! Configuration resolves in precedence order: CLI flags, then
4//! `MAILBOURNE_*` environment variables, then `/var/mailbourne/
5//! mailbourne.toml`, then defaults. Every TOML key has an env twin so
6//! containers never need file templating. The generated TOML is heavily
7//! commented — the config file doubles as a guided tour.
8//!
9//! The schema lands here as the engine grows; it starts with the one value
10//! nothing can work without.
11
12/// Engine configuration.
13#[derive(Debug, Clone)]
14pub struct Config {
15 /// The mail domain this server is responsible for (`example.com`).
16 /// The only *required* setting — everything else is defaulted or
17 /// detected.
18 pub domain: String,
19 /// The server's own hostname, used in SMTP greetings and DNS records.
20 /// Defaults to `mail.<domain>`.
21 pub hostname: String,
22}
23
24impl Config {
25 /// Builds a config from the domain alone, deriving every default.
26 pub fn for_domain(domain: impl Into<String>) -> Self {
27 let domain = domain.into();
28 let hostname = format!("mail.{domain}");
29 Self { domain, hostname }
30 }
31}