2019-05-01 11:32:37 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
accounts =
|
|
|
|
filter (a: a.getmail.enable) (attrValues config.accounts.email.accounts);
|
2019-05-01 11:32:37 +00:00
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
renderAccountConfig = account:
|
|
|
|
with account;
|
2019-05-01 11:32:37 +00:00
|
|
|
let
|
|
|
|
passCmd = concatMapStringsSep ", " (x: "'${x}'") passwordCommand;
|
2021-03-01 22:58:18 +00:00
|
|
|
renderedMailboxes = concatMapStrings (x: "'${x}', ") getmail.mailboxes;
|
2020-02-01 23:39:17 +00:00
|
|
|
retrieverType = if imap.tls.enable then
|
|
|
|
"SimpleIMAPSSLRetriever"
|
|
|
|
else
|
|
|
|
"SimpleIMAPRetriever";
|
|
|
|
destination = if getmail.destinationCommand != null then {
|
|
|
|
destinationType = "MDA_external";
|
|
|
|
destinationPath = getmail.destinationCommand;
|
|
|
|
} else {
|
|
|
|
destinationType = "Maildir";
|
|
|
|
destinationPath = "${maildir.absPath}/";
|
|
|
|
};
|
2019-05-01 11:32:37 +00:00
|
|
|
renderGetmailBoolean = v: if v then "true" else "false";
|
|
|
|
in ''
|
|
|
|
# Generated by Home-Manager.
|
|
|
|
[retriever]
|
|
|
|
type = ${retrieverType}
|
|
|
|
server = ${imap.host}
|
2019-10-24 05:40:37 +00:00
|
|
|
${optionalString (imap.port != null) "port = ${toString imap.port}"}
|
2019-05-01 11:32:37 +00:00
|
|
|
username = ${userName}
|
|
|
|
password_command = (${passCmd})
|
|
|
|
mailboxes = ( ${renderedMailboxes} )
|
|
|
|
|
|
|
|
[destination]
|
|
|
|
type = ${destination.destinationType}
|
|
|
|
path = ${destination.destinationPath}
|
|
|
|
|
|
|
|
[options]
|
|
|
|
delete = ${renderGetmailBoolean getmail.delete}
|
|
|
|
read_all = ${renderGetmailBoolean getmail.readAll}
|
|
|
|
'';
|
|
|
|
getmailEnabled = length (filter (a: a.getmail.enable) accounts) > 0;
|
|
|
|
# Watch out! This is used by the getmail.service too!
|
2020-02-01 23:39:17 +00:00
|
|
|
renderConfigFilepath = a:
|
|
|
|
".getmail/getmail${if a.primary then "rc" else a.name}";
|
2019-05-01 11:32:37 +00:00
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
in {
|
2020-06-15 22:45:20 +00:00
|
|
|
options = {
|
|
|
|
accounts.email.accounts = mkOption {
|
|
|
|
type = with types; attrsOf (submodule (import ./getmail-accounts.nix));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-01-11 18:49:24 +00:00
|
|
|
config = mkIf getmailEnabled {
|
2021-07-07 21:24:27 +00:00
|
|
|
assertions = [
|
|
|
|
(hm.assertions.assertPlatform "programs.getmail" pkgs platforms.linux)
|
|
|
|
];
|
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
home.file = foldl' (a: b: a // b) { }
|
2020-01-11 18:49:24 +00:00
|
|
|
(map (a: { "${renderConfigFilepath a}".text = renderAccountConfig a; })
|
2020-02-01 23:39:17 +00:00
|
|
|
accounts);
|
2020-01-11 18:49:24 +00:00
|
|
|
};
|
|
|
|
}
|