Author: Kevin Schoon [me@kevinschoon.com]
Hash: c3bc6f5f9fba755dfccaa96c2d19fb2bea989068
Timestamp: Sat, 07 Sep 2024 08:15:38 +0000 (1 month ago)

+34 -19 +/-3 browse
expand config options
1diff --git a/cmd/maitred-debug/src/config.rs b/cmd/maitred-debug/src/config.rs
2new file mode 100644
3index 0000000..af71bb7
4--- /dev/null
5+++ b/cmd/maitred-debug/src/config.rs
6 @@ -0,0 +1,23 @@
7+ #[derive(Clone, serde::Deserialize)]
8+ pub(crate) struct Account {
9+ pub address: String,
10+ }
11+
12+ #[derive(Clone, serde::Deserialize)]
13+ pub(crate) struct Spf {
14+ pub enabled: bool
15+ }
16+
17+
18+ #[derive(Clone, serde::Deserialize)]
19+ pub(crate) struct Dkim {
20+ pub enabled: bool
21+ }
22+
23+ #[derive(serde::Deserialize)]
24+ pub(crate) struct Config {
25+ pub maildir: String,
26+ pub spf: Spf,
27+ pub dkim: Dkim,
28+ pub accounts: Vec<Account>,
29+ }
30 diff --git a/cmd/maitred-debug/src/main.rs b/cmd/maitred-debug/src/main.rs
31index e8e4382..1429883 100644
32--- a/cmd/maitred-debug/src/main.rs
33+++ b/cmd/maitred-debug/src/main.rs
34 @@ -5,6 +5,8 @@ use clap::Parser;
35 use toml::from_str;
36 use tracing::Level;
37
38+ mod config;
39+
40 use maitred::{
41 mail_parser::Message, Delivery, DeliveryError, DeliveryFunc, Envelope, Maildir, MilterFunc,
42 PlainAuthFunc, Server, SessionOptions,
43 @@ -18,16 +20,6 @@ async fn print_message(envelope: &Envelope) -> Result<(), DeliveryError> {
44 Ok(())
45 }
46
47- #[derive(Clone, serde::Deserialize)]
48- struct Account {
49- pub address: String,
50- }
51-
52- #[derive(serde::Deserialize)]
53- struct Config {
54- pub maildir: String,
55- pub accounts: Vec<Account>,
56- }
57
58 const LONG_ABOUT: &str = r#"
59 Maitred SMTP Demo Server
60 @@ -40,12 +32,6 @@ considered stable or suitable for a production environment.
61 #[derive(Parser, Debug)]
62 #[clap(author, version, about, long_about = LONG_ABOUT)]
63 struct Args {
64- /// Enable DKIM verification of incoming e-mail.
65- #[clap(long, default_value_t = false)]
66- dkim: bool,
67- /// Enable SPF verification of incoming e-mail.
68- #[clap(long, default_value_t = false)]
69- spf: bool,
70 /// Addresses from which to accept e-mail for
71 #[clap(long, default_value = "maitred.toml")]
72 config: String,
73 @@ -55,7 +41,7 @@ struct Args {
74 async fn main() -> Result<(), Box<dyn std::error::Error>> {
75 let args = Args::parse();
76 let config_str = read_to_string(Path::new(&args.config))?;
77- let config: Config = from_str(&config_str)?;
78+ let config: config::Config = from_str(&config_str)?;
79 // Create a subscriber that logs events to the console
80 tracing_subscriber::fmt()
81 .compact()
82 @@ -87,8 +73,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
83 maildir.deliver(&cloned).await
84 }
85 }))
86- .dkim_verification(args.dkim)
87- .spf_verification(args.spf)
88+ .dkim_verification(config.dkim.enabled)
89+ .spf_verification(config.spf.enabled)
90 .with_session_opts(SessionOptions::default().plain_auth(PlainAuthFunc(
91 |authcid: &str, authzid: &str, passwd: &str| {
92 println!(
93 diff --git a/maitred.toml b/maitred.toml
94index 0fcf4e1..664e4ec 100644
95--- a/maitred.toml
96+++ b/maitred.toml
97 @@ -1,6 +1,12 @@
98 # Path of the directory to deliver mail in the "maildir" format to
99 maildir = "mail"
100
101+ [dkim]
102+ enabled = false
103+
104+ [spf]
105+ enabled = false
106+
107 # List of user accounts and their hard coded username / passwords
108 [[accounts]]
109 address = "demo-1@example.org"