From c5a153386b3ef3d405347a4440e49bbf0220f490 Mon Sep 17 00:00:00 2001 From: Malte Brandy Date: Sat, 30 Jun 2018 04:23:53 +0200 Subject: [PATCH] Improve mutt setup --- home-manager/default.nix | 1 + home-manager/modules/home-options.nix | 3 ++ home-manager/modules/mail.nix | 76 ++++++++++++++++++++++----- hosts/apollo/home.nix | 2 + 4 files changed, 70 insertions(+), 12 deletions(-) diff --git a/home-manager/default.nix b/home-manager/default.nix index 0422e230..6159b0d6 100644 --- a/home-manager/default.nix +++ b/home-manager/default.nix @@ -114,6 +114,7 @@ home.sessionVariables = { BROWSER = "${pkgs.firefox}/bin/firefox"; EDITOR = "${pkgs.neovim}/bin/nvim"; TERMINAL = config.m-0.terminal; + EMAIL = me.mail; SUDO_ASKPASS = let print-pw = pkgs.writeShellScriptBin "print-pw" "pass eu/m-0/$HOST"; in diff --git a/home-manager/modules/home-options.nix b/home-manager/modules/home-options.nix index b33e7e2a..957f7ab9 100644 --- a/home-manager/modules/home-options.nix +++ b/home-manager/modules/home-options.nix @@ -4,6 +4,9 @@ with lib; options = { m-0 = { + hostName = mkOption { + type = types.str; + }; terminal = mkOption { default = "urxvt"; type = types.str; diff --git a/home-manager/modules/mail.nix b/home-manager/modules/mail.nix index 239c53c9..8ba9db01 100644 --- a/home-manager/modules/mail.nix +++ b/home-manager/modules/mail.nix @@ -2,7 +2,7 @@ with lib; let mail = config.m-0.mail; - me = config.m-0.private.me; + inherit (config.m-0.private) sendmail me; mkMailbox = {password, user, host, name}: '' IMAPAccount ${name} Host ${host} @@ -28,7 +28,8 @@ let Remove Both SyncState * ''; - mkSendconfig = {password, user, host, name, from ? null, default ? false , start_tls ? true }: '' + + mkSendconfig = {password, user, host, name, from ? null, default ? false , start_tls ? true , ... }: '' account ${name} host ${host} port ${if start_tls then "587" else "465"} @@ -48,6 +49,9 @@ options.m-0.mail.boxes = mkOption { options.m-0.mail.sendmail = mkOption { type = types.listOf types.attrs; }; +options.m-0.mail.default = mkOption { + type = types.attrs; +}; config = mkIf mail.enable { services.mbsync = { @@ -55,7 +59,14 @@ config = mkIf mail.enable { configFile = pkgs.writeText "mbsync-conf" (builtins.concatStringsSep "\n" (builtins.map mkMailbox mail.boxes)); frequency = "*:0/1"; verbose = false; - postExec = "${pkgs.notmuch}/bin/notmuch new"; + postExec = "${(pkgs.writeShellScriptBin "mail-filter" '' + ${pkgs.notmuch}/bin/notmuch new + ${pkgs.notmuch}/bin/notmuch tag -new -- tag:new + ${pkgs.notmuch}/bin/notmuch tag +deleted -- "folder:/Trash/ (not tag:deleted)" + ${pkgs.notmuch}/bin/notmuch tag -deleted -- "(not folder:/Trash/) tag:deleted" + ${pkgs.notmuch}/bin/notmuch tag +spam -- "folder:/Spam|SPAM/ (not tag:spam)" + ${pkgs.notmuch}/bin/notmuch tag -spam -- "(not folder:/Spam|SPAM/) tag:spam" + '')}/bin/mail-filter"; }; home = { packages = with pkgs; [ @@ -70,7 +81,7 @@ config = mkIf mail.enable { tls on tls_trust_file /etc/ssl/certs/ca-certificates.crt '' + (builtins.concatStringsSep "\n" (builtins.map mkSendconfig mail.sendmail))); - mutt_alternates = "@maralorn.de" + (builtins.concatStringsSep " " me.alternates); + mutt_alternates = "@maralorn.de " + (builtins.concatStringsSep " " me.alternates); notmuch_alternates = builtins.concatStringsSep ";" me.alternates; show-sidebar = pkgs.writeText "show-sidebar" '' set sidebar_visible=yes @@ -92,6 +103,20 @@ config = mkIf mail.enable { bind index display-message bind index display-message ''; + mkFccString = { from , name, sent }: '' + send2-hook '${from}' "macro compose y ${config.home.homeDirectory}/mail/${name}/${sent}" + ''; + mkFcc = { from ? null, name, sent ? null, ... }: + lib.optionalString + (from != null && sent != null) + (mkFccString { inherit name sent; from = "=f ${from}"; }); + mailcap = pkgs.writeText "mailcap" '' + text/html; ${pkgs.lynx}/bin/lynx -stdin -dump -force_html ; copiousoutput + application/*; ${pkgs.xdg_utils}/bin/xdg-open %s > /dev/null + image/*; ${pkgs.xdg_utils}/bin/xdg-open %s > /dev/null + video/*; ${pkgs.xdg_utils}/bin/xdg-open %s > /dev/null + audio/*; ${pkgs.xdg_utils}/bin/xdg-open %s > /dev/null + ''; in { ".notmuch-config".text = '' [database] @@ -113,6 +138,17 @@ config = mkIf mail.enable { synchronize_flags=true ''; ".neomuttrc".text = '' + alternative_order text/plain text/html + auto_view text/* + auto_view message/* + unset wait_key + + set query_format="%4c %t %-70.70a %-70.70n %?e?(%e)?" + set query_command = "${pkgs.notmuch}/bin/notmuch address --output=recipients --deduplicate=address '%s' | grep -i '%s'" + bind editor complete-query + bind editor ^T complete + + alternates ${mutt_alternates} set folder="${config.home.homeDirectory}/mail/" mailboxes `find ${config.home.homeDirectory}/mail -type d -name INBOX -printf '"%h" '` `find ~/mail -type d -name cur -printf '"%h" '` @@ -120,24 +156,40 @@ config = mkIf mail.enable { set sort=threads set sort_aux=date-sent set realname="${me.name}" + set from=fill-later + set use_from=yes + set fast_reply=yes + set mailcap_path=${mailcap}; + set include=yes set edit_headers=yes set mbox_type=Maildir - set spoolfile="${config.home.homeDirectory}/mail/m-0/INBOX" + set spoolfile="${config.home.homeDirectory}/mail/${mail.default.name}/INBOX" + set mail_check_stats=yes + bind index / vfolder-from-query + set header_cache = "~/.cache/neomutt" + set date_format="!%y-%m-%d %H:%M" + set mime_forward=yes + set mime_forward_rest=yes + + macro index "!systemctl --user start mbsync > /dev/null" + + source "${hide-sidebar}" + macro index "source ${hide-sidebar}" + macro index "source ${show-sidebar}" set sidebar_folder_indent=yes set sidebar_short_path=yes set sidebar_width=40 set sidebar_sort_method="alpha" set sidebar_indent_string=" " - set mail_check_stats=yes - bind index / vfolder-from-query color sidebar_indicator black white color sidebar_highlight white blue set sidebar_format = "%B%* %?N?%N/?%S" - set header_cache = "~/.cache/neomutt" - set date_format="!%y-%m-%d %H:%M" - source "${hide-sidebar}" - macro index "source ${hide-sidebar}" - macro index "source ${show-sidebar}" + + alias f__0 ${me.name} <${me.mail}> + ${builtins.concatStringsSep "\n" (lib.imap1 (n: x: "alias f__${toString n} ${me.name} <${x}>") me.alternates)} + send2-hook '~f fill-later' "push f__${me.mail}" + ${mkFccString { from = "~A"; inherit (mail.default) name sent; }} + ${builtins.concatStringsSep "\n" (builtins.map mkFcc mail.sendmail)} ''; }; }; diff --git a/hosts/apollo/home.nix b/hosts/apollo/home.nix index d3b0d90d..debc3555 100644 --- a/hosts/apollo/home.nix +++ b/hosts/apollo/home.nix @@ -5,6 +5,7 @@ imports = [ ../../home-manager ]; +m-0.hostName = "apollo"; m-0.laptop.enable = true; m-0.sleep-nag.enable = true; m-0.battery.enable = true; @@ -25,6 +26,7 @@ m-0.mail = { enable = true; boxes = with config.m-0.private.mail; [ private work work2 ]; sendmail = with config.m-0.private.sendmail; [ private work work2 club club2 ]; + default = config.m-0.private.sendmail.private; }; }