2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.davmail;
|
|
|
|
|
|
|
|
configType = with types;
|
|
|
|
oneOf [ (attrsOf configType) str int bool ] // {
|
|
|
|
description = "davmail config type (str, int, bool or attribute set thereof)";
|
|
|
|
};
|
|
|
|
|
|
|
|
toStr = val: if isBool val then boolToString val else toString val;
|
|
|
|
|
|
|
|
linesForAttrs = attrs: concatMap (name: let value = attrs.${name}; in
|
|
|
|
if isAttrs value
|
|
|
|
then map (line: name + "." + line) (linesForAttrs value)
|
|
|
|
else [ "${name}=${toStr value}" ]
|
|
|
|
) (attrNames attrs);
|
|
|
|
|
|
|
|
configFile = pkgs.writeText "davmail.properties" (concatStringsSep "\n" (linesForAttrs cfg.config));
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options.services.davmail = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "davmail, an MS Exchange gateway");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
url = mkOption {
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Outlook Web Access URL to access the exchange server, i.e. the base webmail URL.";
|
2020-04-24 23:36:52 +00:00
|
|
|
example = "https://outlook.office365.com/EWS/Exchange.asmx";
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkOption {
|
|
|
|
type = configType;
|
|
|
|
default = {};
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Davmail configuration. Refer to
|
2022-08-12 12:06:08 +00:00
|
|
|
<http://davmail.sourceforge.net/serversetup.html>
|
|
|
|
and <http://davmail.sourceforge.net/advanced.html>
|
2020-04-24 23:36:52 +00:00
|
|
|
for details on supported values.
|
|
|
|
'';
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''
|
2020-04-24 23:36:52 +00:00
|
|
|
{
|
|
|
|
davmail.allowRemote = true;
|
|
|
|
davmail.imapPort = 55555;
|
|
|
|
davmail.bindAddress = "10.0.1.2";
|
|
|
|
davmail.smtpSaveInSent = true;
|
|
|
|
davmail.folderSizeLimit = 10;
|
|
|
|
davmail.caldavAutoSchedule = false;
|
|
|
|
log4j.logger.rootLogger = "DEBUG";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
services.davmail.config = {
|
|
|
|
davmail = mapAttrs (name: mkDefault) {
|
|
|
|
server = true;
|
|
|
|
disableUpdateCheck = true;
|
|
|
|
logFilePath = "/var/log/davmail/davmail.log";
|
|
|
|
logFileSize = "1MB";
|
|
|
|
mode = "auto";
|
|
|
|
url = cfg.url;
|
|
|
|
caldavPort = 1080;
|
|
|
|
imapPort = 1143;
|
|
|
|
ldapPort = 1389;
|
|
|
|
popPort = 1110;
|
|
|
|
smtpPort = 1025;
|
|
|
|
};
|
|
|
|
log4j = {
|
|
|
|
logger.davmail = mkDefault "WARN";
|
|
|
|
logger.httpclient.wire = mkDefault "WARN";
|
|
|
|
logger.org.apache.commons.httpclient = mkDefault "WARN";
|
|
|
|
rootLogger = mkDefault "WARN";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.davmail = {
|
|
|
|
description = "DavMail POP/IMAP/SMTP Exchange Gateway";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
ExecStart = "${pkgs.davmail}/bin/davmail ${configFile}";
|
|
|
|
Restart = "on-failure";
|
|
|
|
DynamicUser = "yes";
|
|
|
|
LogsDirectory = "davmail";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.davmail ];
|
|
|
|
};
|
|
|
|
}
|