{ config, lib, pkgs, ... }: with lib; let ms = config.mailserver; cfg = ms.autoconfig; # none of the available parameters are configurable in # simple-mailserver so these templates aren't configurable either incomingServer = enable: port: socketType: optionalString enable '' ${ms.fqdn} ${builtins.toString port} ${socketType} password-cleartext %EMAILADDRESS% ''; # we currently only support STARTTLS for outgoing servers outgoingServer = port: '' ${ms.fqdn} ${builtins.toString port} STARTTLS password-cleartext %EMAILADDRESS% ''; in { mailserver.autoconfig.webRoot = pkgs.substituteAll ({ name = "config-v1.1.xml"; dir = "mail"; src = if cfg.template == null then cfg.templateFile else pkgs.writeTextFile { name = "mailserver-autoconfig-template.xml"; text = cfg.template; }; } // { hostname = ms.fqdn; inherit (cfg) emailProviderId displayName displayShortName extraProviderConfig; imapSslServer = incomingServer ms.enableImapSsl 993 "SSL"; imapServer = incomingServer ms.enableImapSsl 143 "STARTTLS"; pop3SslServer = incomingServer ms.enablePop3Ssl 995 "SSL"; pop3Server = incomingServer ms.enablePop3 110 "STARTTLS"; smtpServer = outgoingServer 25; submissionServer = outgoingServer 587; domains = concatMapStringsSep "\n " (x: "${x}") cfg.domains; }); }