{ lib, pkgs, config, ... }: with lib; let mailAccountModule = types.submodule { isPrimary = mkOption { type = types.bool; default = false; }; mailAddress = mkOption { type = types.str; }; mailPasswdEval = mkOption { type = types.str; }; imapHost = mkOption { type = types.str; }; smtpHost = mkOption { type = types.str; }; }; defaultExtraMailboxes = [ "Archive" "Receipts" "Junk" "Drafts" "Sent" "Trash" ]; signature = { text = '' Victor Mignot ''; showSignature = "append"; }; hasNoAddress = config.my.communications.mail.accounts == null; in { options.my.communications.mail.accounts = mkOption { type = types.nullOr (types.attrsOf mailAccountModule); default = null; }; config = mkIf (!hasNoAddress) { accounts.email.accounts = builtins.mapAttrs (name: value: { primary = value.isPrimary; address = value.mailAddress; userName = value.mailAddress; realName = "Victor Mignot"; imap.host = value.imapHost; smtpHost = value.smtpHost; passwordCommand = value.mailPasswdEval; inherit signature; mbsync = { enable = true; create = "both"; expunge = "both"; patterns = [ "*" ]; subFolders = "Verbatim"; }; msmtp.enable = true; neomutt = { enable = true; mailboxName = "${name}/Inbox"; extraMailboxes = map (mb: { mailbox = mb; name = "${name}/${mb}"; }) defaultExtraMailboxes; }; }) config.my.communications.mail.accounts; services.mbsync.enable = true; programs.mbsync.enable = true; accounts.email.maildirBasePath = "Mail"; programs.neomutt = { enable = true; sidebar.enable = true; checkStatsInterval = 30; sort = "reverse-date"; extraConfig = '' set edit_headers = yes set use_from = yes set send_charset = "utf-8" color body brightwhite default ^[[:space:]].* color body yellow default ^(diff).* color body brightwhite default ^(\s).* color body cyan default ^(Signed-off-by).* color body cyan default ^(Docker-DCO-1.1-Signed-off-by).* color body brightwhite default ^(Cc) color body yellow default "^diff \-.*" color body brightwhite default "^index [a-f0-9].*" color body brightblue default "^---$" color body white default "^\-\-\- .*" color body white default "^[\+]{3} .*" color body green default "^[\+][^\+]+.*" color body red default "^\-[^\-]+.*" color body brightblue default "^@@ .*" color body green default "LGTM" color body brightmagenta default "-- Commit Summary --" color body brightmagenta default "-- File Changes --" color body brightmagenta default "-- Patch Links --" color body green default "^Merged #.*" color body red default "^Closed #.*" color body brightblue default "^Reply to this email.*" ''; }; }; }