···
1
+
import ./make-test.nix {
4
+
machine = { pkgs, ... }: {
5
+
imports = [ common/user-account.nix ];
6
+
services.postfix.enable = true;
7
+
services.dovecot2.enable = true;
8
+
services.dovecot2.protocols = [ "imap" "pop3" ];
9
+
environment.systemPackages = let
10
+
sendTestMail = pkgs.writeScriptBin "send-testmail" ''
11
+
#!${pkgs.stdenv.shell}
12
+
exec sendmail -vt <<MAIL
13
+
From: root@localhost
15
+
Subject: Very important!
21
+
testImap = pkgs.writeScriptBin "test-imap" ''
22
+
#!${pkgs.python3.interpreter}
25
+
with imaplib.IMAP4('localhost') as imap:
26
+
imap.login('alice', 'foobar')
28
+
status, refs = imap.search(None, 'ALL')
29
+
assert status == 'OK'
30
+
assert len(refs) == 1
31
+
status, msg = imap.fetch(refs[0], 'BODY[TEXT]')
32
+
assert status == 'OK'
33
+
assert msg[0][1].strip() == b'Hello world!'
36
+
testPop = pkgs.writeScriptBin "test-pop" ''
37
+
#!${pkgs.python3.interpreter}
40
+
pop = poplib.POP3('localhost')
44
+
assert len(pop.list()[1]) == 1
45
+
status, fullmail, size = pop.retr(1)
46
+
assert status.startswith(b'+OK ')
47
+
body = b"".join(fullmail[fullmail.index(b""):]).strip()
48
+
assert body == b'Hello world!'
53
+
in [ sendTestMail testImap testPop ];
57
+
$machine->waitForUnit('postfix.service');
58
+
$machine->waitForUnit('dovecot2.service');
59
+
$machine->succeed('send-testmail');
60
+
$machine->waitUntilFails('[ "$(postqueue -p)" != "Mail queue is empty" ]');
61
+
$machine->succeed('test-imap');
62
+
$machine->succeed('test-pop');