1 import ./make-test-python.nix {
4 nodes.machine = { pkgs, ... }: {
5 imports = [ common/user-account.nix ];
6 services.postfix.enable = true;
9 protocols = [ "imap" "pop3" ];
10 modules = [ pkgs.dovecot_pigeonhole ];
14 environment.systemPackages = let
15 sendTestMail = pkgs.writeScriptBin "send-testmail" ''
16 #!${pkgs.runtimeShell}
17 exec sendmail -vt <<MAIL
20 Subject: Very important!
26 sendTestMailViaDeliveryAgent = pkgs.writeScriptBin "send-lda" ''
27 #!${pkgs.runtimeShell}
29 exec ${pkgs.dovecot}/libexec/dovecot/deliver -d bob <<MAIL
32 Subject: Something else...
34 I'm running short of ideas!
38 testImap = pkgs.writeScriptBin "test-imap" ''
39 #!${pkgs.python3.interpreter}
42 with imaplib.IMAP4('localhost') as imap:
43 imap.login('alice', 'foobar')
45 status, refs = imap.search(None, 'ALL')
48 status, msg = imap.fetch(refs[0], 'BODY[TEXT]')
50 assert msg[0][1].strip() == b'Hello world!'
53 testPop = pkgs.writeScriptBin "test-pop" ''
54 #!${pkgs.python3.interpreter}
57 pop = poplib.POP3('localhost')
61 assert len(pop.list()[1]) == 1
62 status, fullmail, size = pop.retr(1)
63 assert status.startswith(b'+OK ')
64 body = b"".join(fullmail[fullmail.index(b""):]).strip()
65 assert body == b"I'm running short of ideas!"
70 in [ sendTestMail sendTestMailViaDeliveryAgent testImap testPop ];
74 machine.wait_for_unit("postfix.service")
75 machine.wait_for_unit("dovecot2.service")
76 machine.succeed("send-testmail")
77 machine.succeed("send-lda")
78 machine.wait_until_fails('[ "$(postqueue -p)" != "Mail queue is empty" ]')
79 machine.succeed("test-imap")
80 machine.succeed("test-pop")