diff --git a/users/simon/modules/email.nix b/users/simon/modules/email.nix index cbabb91..4c138a3 100644 --- a/users/simon/modules/email.nix +++ b/users/simon/modules/email.nix @@ -1,6 +1,7 @@ { config, lib, pkgs, ... }: let virtualMailboxes = { + #"One Month" = "date:30days..today"; "FabLab" = "body:fablab"; "Git" = "from:{.*@github.com or .*@gitlab.com or no-reply+gitea@sbruder.de}'"; }; @@ -41,17 +42,6 @@ in tls.useStartTls = true; }; - signature = { - showSignature = "append"; - text = '' - Simon Bruder - - 🔑 (GPG): 47E7 559E 037A 3565 2DBB F8AA 8D3C 82F9 F309 F8EC - 📧 (E-Mail): simon@sbruder.de - 📱 (mobile): +49 152 56561414 - ''; - }; - gpg = { key = config.programs.gpg.settings.default-key; signByDefault = true; @@ -65,71 +55,155 @@ in create = "both"; expunge = "both"; }; - #mu.enable = true; - neomutt = { - enable = true; - extraConfig = let account = config.accounts.email.accounts.personal; in - '' - # revert home-manager setting - unmailboxes "${account.maildir.absPath}/${account.folders.inbox}" - unvirtual-mailboxes "My INBOX" - ''; - }; + neomutt.enable = true; notmuch.enable = true; }; }; }; - programs.neomutt = { - enable = true; + # I am not using the home-manger neomutt module, since it includes many + # opinionated, not-overridable defaults that I do not want + home.packages = with pkgs; [ neomutt ]; + xdg.configFile."neomutt/neomuttrc".text = + let + # adapted from home-manager + stringifyValue = value: + if lib.isBool value + then (if value then "yes" else "no") + else "'${toString value}'"; + stringifySetOption = option: value: + if value == null + then "unset ${option}" + else "set ${option}=${stringifyValue value}"; + stringifyOptions = options: lib.concatStringsSep + "\n" + (lib.mapAttrsToList stringifySetOption options); - sidebar = { - enable = true; - format = "%B%?F? [%F]?%* %?N?%N/?%S"; - }; + stringifyBinds = binds: lib.concatMapStringsSep + "\n" + (bind: + let map' = + if (lib.isList bind.map) + then (lib.concatStringsSep "," bind.map) + else bind.map; + in + ''bind ${map'} ${bind.key} "${bind.action}"'') + binds; - binds = [ - { map = "index"; key = "\\\\"; action = "vfolder-from-query"; } - ]; + stringifySources = files: lib.concatMapStringsSep + "\n" + (file: "source ${file}") + files; - extraConfig = '' - source ${mutt-solarized-dark} + neomuttAccounts = lib.filter (a: a.neomutt.enable) (lib.attrValues config.accounts.email.accounts); + + settings = { + # FIXME: comment all non-obvious + header_cache = "${config.xdg.cacheHome}/neomutt/headers/"; + message_cachedir = "${config.xdg.cacheHome}/neomutt/messages/"; + + # General + implicit_autoview = true; # automatically view with program from mailcap + delete = true; # do not ask before deleting + mail_check_stats = true; + + # Sidebar + sidebar_visible = true; + sidebar_folder_indent = true; + sidebar_format = "%D%?F? [%F]?%* %?N?%N/?%S"; + sidebar_short_path = true; + sidebar_width = 22; + sidebar_delim_chars = "/"; + + # Editor + edit_headers = true; + reverse_name = true; + include = true; + + # GPG + crypt_use_gpgme = true; + crypt_autosign = true; + pgp_use_gpg_agent = true; + mbox_type = "Maildir"; + sort = "threads"; + + sendmail = "msmtpq --read-envelope-from --read-recipients"; + + # Defaults for all accounts + folder = config.accounts.email.maildirBasePath; + spoolfile = "notmuch://?query=tag:inbox"; + #from = config.accounts.email.accounts.personal.address; + #postponed = "+Drafts"; + #realname = "Simon Bruder"; + #record = "+Sent"; + #trash = "+Trash"; + + signature = pkgs.writeText "signature" '' + Simon Bruder + + 🔑 (GPG): 47E7 559E 037A 3565 2DBB F8AA 8D3C 82F9 F309 F8EC + 📧 (E-Mail): simon@sbruder.de + 📱 (mobile): +49 152 56561414 + ''; + + # notmuch + nm_default_uri = "notmuch:///home/simon/.local/share/mail"; + + mailcap_path = pkgs.writeText "mutt-mailcap" '' + text/html; firefox %s + text/html; ${pkgs.w3m}/bin/w3m -I %{charset} -T text/html -dump; copiousoutput; + application/pdf; zathura %s + image/*; mpv %s + ''; + + pgp_default_key = config.programs.gpg.settings.default-key; + + nm_query_type = "threads"; + }; + + binds = [ + { map = "index"; key = "\\\\"; action = "vfolder-from-query"; } + { map = [ "index" "pager" ]; key = "J"; action = "sidebar-next"; } + { map = [ "index" "pager" ]; key = "K"; action = "sidebar-prev"; } + { map = [ "index" "pager" ]; key = "S"; action = "sidebar-open"; } + ]; + + sources = [ + mutt-solarized-dark + ]; + in + '' + alternative_order text/enriched text/plain text + + ${stringifyBinds binds} + + # Macros + #{macroSection} + #"source ${pkgs.neomutt}/share/doc/neomutt/vim-keys/vim-keys.rc" + + ${stringifyOptions settings} + + ${stringifySources sources} ${mkVirtualMailbox "Inbox" "tag:inbox"} ${lib.concatStringsSep "\n" - (lib.attrValues - (lib.mapAttrs mkVirtualMailbox virtualMailboxes))} - ''; - - # somehow makes not work (?) - #vimKeys = true; - settings = { - wait_key = "yes"; - timeout = "3"; - quit = "yes"; - mail_check_stats = "yes"; - - edit_headers = "yes"; - reverse_name = "yes"; - include = "yes"; - - mailcap_path = toString (pkgs.writeText "mutt-mailcap" '' - text/html; firefox %s - text/html; ${pkgs.w3m}/bin/w3m -I %{charset} -T text/html -dump; copiousoutput; - application/pdf; zathura %s - image/*; mpv %s - ''); - - pgp_default_key = config.programs.gpg.settings.default-key; - - nm_query_type = "threads"; - }; - }; + (lib.mapAttrsToList mkVirtualMailbox virtualMailboxes)} + #mailboxes ="===================" + '' + lib.concatMapStringsSep "\n" + (account: with account; '' + # Account ${name} + # FIXME + named-mailboxes "== ${name} ==" +${name}/${folders.inbox} + mailboxes =${name}/${folders.inbox} + mailboxes =${name}/${folders.sent} + mailboxes =${name}/${folders.drafts} + mailboxes =${name}/${folders.trash} + '') + neomuttAccounts; programs.mbsync.enable = true; programs.msmtp.enable = true; - #programs.mu.enable = true; programs.notmuch = { enable = true; hooks = {