{ pkgs, lib, config, user, home-dir, ... }: { imports = [ ./davmail.nix ./neomutt ./mailcap.nix ]; options.custom.email = with lib; { enable = mkEnableOption "Enable email"; davmail = mkEnableOption "Enable DavMail"; mbsync = mkEnableOption "Enable Mbsync"; }; config = lib.mkIf config.custom.email.enable { services.davmail = { enable = config.custom.email.davmail; url = "https://outlook.office365.com/EWS/Exchange.asmx"; config = { davmail.mode = "O365Manual"; # davmail.mode = "O365Modern"; davmail.keepDelay = 30; # log4j.logger.davmail = "DEBUG"; }; }; programs = { neomutt = { macros = [ { map = [ "index" "pager" ]; key = ""; action = "source ~/.config/neomutt/uchicago!"; } { map = [ "index" "pager" ]; key = ""; action = "source ~/.config/neomutt/personal!"; } ]; }; mbsync.enable = true; msmtp = { enable = true; }; }; services = { mbsync = { enable = config.custom.email.mbsync; frequency = "*:0/1"; }; }; accounts.email = let cat = lib.getExe' pkgs.coreutils "cat"; in rec { maildirBasePath = "${home-dir}/mail"; accounts = lib.mkMerge ([ { "personal" = { userName = "raydreww@gmail.com"; address = "raydreww@gmail.com"; realName = "Ray Andrew"; primary = !config.custom.email.davmail; signature = { text = '' -- Ray Andrew ''; showSignature = "append"; }; passwordCommand = "${cat} ${config.sops.secrets."personal".path}"; gpg = { key = "1913ECC8FD7076BC8330E11607AA5254804C009F"; signByDefault = true; }; smtp = { host = "smtp.gmail.com"; }; imap = { host = "imap.gmail.com"; }; mbsync = { enable = true; create = "both"; expunge = "both"; patterns = [ "*" "!\"[Airmail]/Done\"" "!\"[Airmail]/Snooze\"" "!\"[Airmail]/To Do\"" "!\"[Airmail]/Send Later\"" "!\"[Gmail]/All Mail\"" "!\"[Gmail]/Important\"" "!\"[Gmail]/Starred\"" "!\"[Gmail]/Bin\"" ]; }; msmtp = { enable = true; }; neomutt = rec { enable = true; mailboxName = "p"; extraConfig = '' set use_from = yes set pgp_verify_sig = yes set pgp_sign_as = 0x07AA5254804C009F set pgp_timeout = 3600 named-mailboxes "${mailboxName}/inbox" =Inbox named-mailboxes "${mailboxName}/drafts" =Drafts named-mailboxes "${mailboxName}/sent" =Sent named-mailboxes "${mailboxName}/important" =Important named-mailboxes "${mailboxName}/trash" =Trash named-mailboxes "${mailboxName}/archive" =Archive ''; }; }; } (lib.mkIf config.custom.email.davmail { "uchicago" = { userName = "rayandrew@uchicago.edu"; address = "rayandrew@uchicago.edu"; realName = "Ray Andrew"; primary = true; signature = { text = '' -- Ray Andrew ''; showSignature = "append"; }; passwordCommand = "${cat} ${config.sops.secrets."uchicago".path}"; gpg = { key = "0BADFAD0FB93296C84956F9CEEF04CFFE9DFE5FC"; signByDefault = false; }; smtp = { host = "127.0.0.1"; port = 1025; tls = { enable = false; certificatesFile = null; }; }; imap = { host = "127.0.0.1"; port = 1143; tls.enable = false; }; mbsync = { enable = true; create = "both"; expunge = "both"; patterns = [ "*" "!\"[Airmail]/Done\"" "!\"[Airmail]/Snooze\"" "!\"[Airmail]/To Do\"" "!\"[Airmail]/Send Later\"" ]; extraConfig.account = { TLSType = "None"; AuthMechs = "LOGIN"; Timeout = 0; }; }; msmtp = { enable = true; extraConfig = { auth = "plain"; }; }; neomutt = rec { enable = true; mailboxName = "u"; extraConfig = '' set use_from = yes set pgp_sign_as = 0xEEF04CFFE9DFE5FC set pgp_verify_sig = yes set pgp_timeout = 3600 named-mailboxes "${mailboxName}/inbox" =Inbox named-mailboxes "${mailboxName}/drafts" =Drafts named-mailboxes "${mailboxName}/sent" =Sent named-mailboxes "${mailboxName}/important" =Important named-mailboxes "${mailboxName}/trash" =Trash named-mailboxes "${mailboxName}/archive" =Archive named-mailboxes "${mailboxName}/teaching" =Teaching ''; }; }; }) ]); }; sops = { age.keyFile = "${home-dir}/.config/sops/age/keys.txt"; age.generateKey = true; defaultSopsFile = ./secrets.yaml; secrets = { "personal" = { }; "uchicago" = { }; }; }; }; }