Skip to content

Commit fb4ff06

Browse files
committed
fix opensmtpd's sendmail, add relevant test
1 parent c340fd8 commit fb4ff06

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

nixos/modules/services/mail/opensmtpd.nix

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,11 @@ in
113113
source = "${cfg.package}/bin/smtpctl";
114114
};
115115

116-
services.mail.sendmailSetuidWrapper = lib.mkIf cfg.setSendmail (
117-
security.wrappers.smtpctl // { program = "sendmail"; }
118-
);
116+
services.mail.sendmailSetuidWrapper = lib.mkIf cfg.setSendmail
117+
(security.wrappers.smtpctl // {
118+
source = "${sendmail}/bin/sendmail";
119+
program = "sendmail";
120+
});
119121

120122
systemd.tmpfiles.rules = [
121123
"d /var/spool/smtpd 711 root - - -"

nixos/tests/opensmtpd.nix

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,24 @@ import ./make-test-python.nix {
1616
}
1717
];
1818
};
19-
environment.systemPackages = [ pkgs.opensmtpd ];
19+
environment.systemPackages = let
20+
testSendmail = pkgs.writeScriptBin "test-sendmail" ''
21+
#!/bin/sh
22+
set -euxo pipefail
23+
echo "========= SENDING" >&2
24+
${pkgs.system-sendmail}/bin/sendmail -v -f alice@smtp1 bob@smtp2 >&2 <<EOF
25+
From: alice@smtp1
26+
To: bob@smtp2
27+
Subject: Sendmail Test
28+
29+
Hello World
30+
EOF
31+
echo "=========== FINISHED SENDING" >&2
32+
'';
33+
in [
34+
pkgs.opensmtpd
35+
testSendmail
36+
];
2037
services.opensmtpd = {
2138
enable = true;
2239
extraServerArgs = [ "-v" ];
@@ -108,9 +125,12 @@ import ./make-test-python.nix {
108125
print("===> content:", content)
109126
split = content.split(b'\r\n')
110127
print("===> split:", split)
111-
lastline = split[-3]
128+
split.reverse()
129+
lastline = next(filter(lambda x: x != b"", map(bytes.strip, split)))
112130
print("===> lastline:", lastline)
113131
assert lastline.strip() == b'Hello World'
132+
imap.store(refs[0], '+FLAGS', '\\Deleted')
133+
imap.expunge()
114134
'';
115135
in
116136
[
@@ -139,6 +159,11 @@ import ./make-test-python.nix {
139159
smtp1.wait_until_fails("smtpctl show queue | egrep .")
140160
smtp2.wait_until_fails("smtpctl show queue | egrep .")
141161
client.succeed("check-mail-landed >&2")
162+
163+
smtp1.succeed("test-sendmail")
164+
smtp1.wait_until_fails("smtpctl show queue | egrep .")
165+
smtp2.wait_until_fails("smtpctl show queue | egrep .")
166+
client.succeed("check-mail-landed >&2")
142167
'';
143168

144169
meta.timeout = 1800;

0 commit comments

Comments
 (0)