Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sail.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ ListenAddress 127.0.0.1
Port 8000
Maildir maildir/{destination user:strip and lowercase}/{destination domain:uppercase}
Hostnames localhost
Relays nyble.dev
44 changes: 29 additions & 15 deletions saild/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct Config {
pub port: u16,
pub maildir: MaildirTemplate,
pub hostnames: Vec<Domain>,
pub relays: Vec<Domain>,
}

#[allow(clippy::or_fun_call)]
Expand Down Expand Up @@ -129,22 +130,16 @@ impl Config {
eprintln!("'Hostnames' not found in config. Who are we accepting mail for?");
return None;
}
Some(joined) => {
let splits = joined.split(',');
let mut names = vec![];
for split in splits {
let domain: Domain = match split.parse() {
Err(_e) => {
eprintln!("Failed to parse {split} as a domain");
return None;
}
Ok(d) => d,
};

names.push(domain);
}
Some(joined) => Self::parse_domains(&joined)?,
};

names
let relays = match config.child_owned("Relays") {
None => vec![],
Some(joined) => {
//possible future work: allow granular relays - which local-parts are acceptable to relay to?
//this complicates parsing a bit since roughly anything goes for a local-part
//i believe confindent has support for nested structures, though - could have this a multi-line structure?
Self::parse_domains(&joined)?
}
};

Expand All @@ -153,8 +148,27 @@ impl Config {
port,
maildir,
hostnames,
relays,
})
}

fn parse_domains(joined: &str) -> Option<Vec<Domain>> {
let splits = joined.split(',');
let mut names = vec![];
for split in splits {
let domain: Domain = match split.parse() {
Err(_e) => {
eprintln!("Failed to parse {split} as a domain");
return None;
}
Ok(d) => d,
};

names.push(domain);
}

Some(names)
}
}

#[derive(Clone, Debug, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion saild/test/integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from os import listdir

process: subprocess.Popen[bytes] | None = None
testfiles = [("happy_path.txt", ["snep", "coati"]), ("abortive.txt", [])]
testfiles = [("happy_path.txt", ["snep", "coati"]), ("abortive.txt", []), ("relay.txt", [])]
is_error: bool = True

@dataclass
Expand Down
15 changes: 15 additions & 0 deletions saild/test/relay.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
S: 220 localhost (Sail) ready
C: EHLO test.domain
S: 250-localhost (sail) greets test.domain
S: 250 Help
C: MAIL FROM:<[email protected]>
S: 250 Okay
C: RCPT TO:<[email protected]>
S: 250 Okay
C: DATA
S: 354 Start mail input
C: Autogenerated mail from a saild integration test :)
C: .
S: 250
C: QUIT
S: 221 localhost Goodbye
Loading