From b78fc8137408c0864936a983529c7a97c52cf989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Eug=C3=AAnio?= Date: Thu, 16 Feb 2023 12:07:46 -0300 Subject: [PATCH 1/2] WIP: add neomutt --- user/email.nix | 1 + user/home.nix | 1 + user/neomutt/default.nix | 107 ++++++++++++++++++++++++ user/neomutt/neomuttrc | 176 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 285 insertions(+) create mode 100644 user/neomutt/default.nix create mode 100644 user/neomutt/neomuttrc diff --git a/user/email.nix b/user/email.nix index 076d4ae..4620472 100644 --- a/user/email.nix +++ b/user/email.nix @@ -22,6 +22,7 @@ let }; msmtp.enable = true; notmuch.enable = true; + neomutt.enable = true; }; in { diff --git a/user/home.nix b/user/home.nix index 601e162..84b670f 100644 --- a/user/home.nix +++ b/user/home.nix @@ -19,6 +19,7 @@ ./mimeapps.nix ./chat.nix ./email.nix + ./neomutt ./syncthing.nix ./vdir.nix ./bmenu.nix diff --git a/user/neomutt/default.nix b/user/neomutt/default.nix new file mode 100644 index 0000000..6616f7b --- /dev/null +++ b/user/neomutt/default.nix @@ -0,0 +1,107 @@ +{ pkgs, lib, ... }: +let + inherit (pkgs.uservars) key; + inherit (lib) toUpper; +in +{ + programs.neomutt.enable = true; + programs.neomutt.binds = [ + { + map = [ "index" ]; + key = key.left; + action = "noop"; + } + { + map = [ "index" ]; + key = key.down; + action = "next-entry"; + } + { + map = [ "index" ]; + key = key.up; + action = "previous-entry"; + } + { + map = [ "index" ]; + key = key.right; + action = "display-message"; + } + + { + map = [ "attach" ]; + key = key.up; + action = "previous-entry"; + } + { + map = [ "attach" ]; + key = key.down; + action = "next-entry"; + } + { + map = [ "attach" ]; + key = key.left; + action = "exit"; + } + { + map = [ "attach" ]; + key = key.right; + action = "view-mailcap"; + } + { + map = [ "pager" ]; + key = key.left; + action = "exit"; + } + { + map = [ "pager" ]; + key = key.down; + action = "next-line"; + } + { + map = [ "pager" ]; + key = key.up; + action = "previous-line"; + } + { + map = [ "pager" ]; + key = key.right; + action = "view-attachments"; + } + { + map = [ "index" "pager" "browser" ]; + key = toUpper key.up; + action = "half-up"; + } + { + map = [ "index" "pager" "browser" ]; + key = toUpper key.down; + action = "half-down"; + } + { + map = [ "browser" ]; + key = key.left; + action = "goto-parent"; + } + { + map = [ "index" "pager" ]; + key = "\\C${ key.down }"; + action = "sidebar-next"; + } + { + map = [ "index" "pager" ]; + key = "\\C${ key.up }"; + action = "sidebar-prev"; + } + { + map = [ "index" "pager" ]; + key = "\\C${ key.right }"; + action = "sidebar-open"; + } + { + map = [ "index" "pager" ]; + key = "\\C${ key.left }"; + action = "sidebar-toggle-visible"; + } + ]; + programs.neomutt.extraConfig = lib.readFile ./neomuttrc; +} diff --git a/user/neomutt/neomuttrc b/user/neomutt/neomuttrc new file mode 100644 index 0000000..667225c --- /dev/null +++ b/user/neomutt/neomuttrc @@ -0,0 +1,176 @@ +# {{@@ header() @@}} +# _ _ _ _ +# | \ | | ___ ___ _ __ ___ _ _| |_| |_ +# | \| |/ _ \/ _ \| '_ ` _ \| | | | __| __| +# | |\ | __/ (_) | | | | | | |_| | |_| |_ +# |_| \_|\___|\___/|_| |_| |_|\__,_|\__|\__| + + +# Mailbox {{{ + + +# Set MailDir +# set mbox_type = Maildir +# set header_cache = ~/.cache/mutt/ +# set my_mailroot = ~/.local/share/mail + +set use_from = yes +# set ssl_force_tls = yes + +# {%@@ for name, info in mail.items() | reverse @@%} +# set my_source_command = "_mutt_get-mail '{{@@ name @@}}' |" +# folder-hook "$my_mailroot/{{@@ name @@}}/" source "\"$my_source_command\"" +# source "$my_source_command" +# {%@@ endfor @@%} + +# {%@@ for name, info in mail.items() @@%} +# set my_source_command = "_mutt_get-mail '{{@@ name @@}}' |" +# macro index,pager "source \"$my_source_command\"!" +# {%@@ endfor @@%} + +# }}} +# General {{{ + +set use_threads = threads +set sort = reverse-last-date +set sort_aux = last-date + +set mail_check_stats = yes +set mail_check_stats_interval = 10 + +set mark_old = no # Unread mail stay unread until read +set mailcap_path = ~/.config/neomutt/mailcap +auto_view text/html # automatically show html +auto_view application/pgp-encrypted +alternative_order text/plain text/enriched text/html + +set query_command= "khard email --parsable %s" + +# }}} +# General rebindings{{{ + +# index +# + +bind index noop +bind index next-entry +bind index previous-entry +bind index display-message + + +bind index g noop # needed to allow gg +bind index G last-entry +bind index gg first-entry + +bind index D delete-message +bind index U undelete-message + +bind index L limit +bind index tag-entry + + +# Attachment screen +bind attach view-mailcap + +bind editor noop + + +bind pager exit +bind pager next-line +bind pager previous-line +bind pager view-attachments + + +macro browser "{{@@ key.left @@}}" '..' "Go to parent folder" +bind index,pager H view-raw-message +bind browser l select-entry +bind pager,browser gg top-page +bind pager,browser G bottom-page +bind index,pager S sync-mailbox +bind index,pager R group-reply + +# Mouse wheel +bind index \031 previous-undeleted +bind index \005 next-undeleted +bind pager \031 previous-line +bind pager \005 next-line + +bind editor complete-query +set abort_key="" + +macro index,pager a \ + "khard add-email" \ + "add the sender email address to khard" + +# macro index,pager a "set my_pipe_decode=\$pipe_decode pipe_decodeabook --add-emailset pipe_decode=\$my_pipe_decode; unset my_pipe_decode" "add the sender address to abook" +macro index \Cr "T~UN." "mark all messages as read" +macro index O "mbsync -a" "run mbsync to sync all mail" +macro index \Cf "unset wait_keyread -p 'Enter a search term to find with notmuch: ' x; echo \$x >~/.cache/mutt_terms~i \"\`notmuch search --output=messages \$(cat ~/.cache/mutt_terms) | head -n 600 | perl -le '@a=<>;s/\^id:// for@a;$,=\"|\";print@a' | perl -le '@a=<>; chomp@a; s/\\+/\\\\+/ for@a;print@a' \`\"" "show only messages matching a notmuch pattern" +#macro index A "all\n" "show all messages (undo limit)" + +# }}} +# Sidebar mappings{{{ + +set sidebar_visible = yes +set sidebar_width = 20 +set sidebar_short_path = yes +set sidebar_next_new_wrap = yes +# set mail_check_stats +set sidebar_format = '%B%?F? [%F]?%* %?N?%N/? %?S?%S?' + + +# }}} +# Appearence{{{ + +# Don't show the menu bar at the top +set help = false + +# Disables the `+` displayed at line wraps +set markers = no + +set date_format="%m/%d %H:%M" +set index_format="%3C %zs %?X?A& ? %D %-15.15F %s" + +set display_filter = '_mutt_escape-html-chars' + +#}}} +# colors{{{ + +# # General +# color status black default +# color indicator brightwhite {{@@ accent_color_name @@}} + +# # Messages +# color index default default '.*' +# color index_number black default +# color index_author {{@@ accent_color_name @@}} default '.*' +# color index_subject green default '.*' + +# # New messages +# color index brightgreen default "~N|~O" +# color index_author brightred default "~N" +# color index_subject brightcyan default "~N" + +# # Sidebar +# color sidebar_new green default +# color sidebar_highlight default green +# color sidebar_indicator brightwhite {{@@ accent_color_name @@}} +# color sidebar_divider black default + +# # Header - information for any open email +# color header default default "^(Date)" +# color header {{@@ accent_color_name @@}} default "^(From)" +# color header green default "^(Subject)" +# color header brightwhite default "^(CC|BCC)" + +# # Content - Body of open email +# color body brightred default "[\-\.+_a-zA-Z0-9]+@[\-\.a-zA-Z0-9]+" # Email addresses +# color body brightblue default "(https?|ftp)://[\-\.,/%~_:?&=\#a-zA-Z0-9]+" # URL +# color attachment default black + +# # Comically large Regex{{{ +# color body red default "([a-z][a-z0-9+-]*://(((([a-z0-9_.!~*'();:&=+$,-]|%[0-9a-f][0-9a-f])*@)?((([a-z0-9]([a-z0-9-]*[a-z0-9])?)\\.)*([a-z]([a-z0-9-]*[a-z0-9])?)\\.?|[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)(:[0-9]+)?)|([a-z0-9_.!~*'()$,;:@&=+-]|%[0-9a-f][0-9a-f])+)(/([a-z0-9_.!~*'():@&=+$,-]|%[0-9a-f][0-9a-f])*(;([a-z0-9_.!~*'():@&=+$,-]|%[0-9a-f][0-9a-f])*)*(/([a-z0-9_.!~*'():@&=+$,-]|%[0-9a-f][0-9a-f])*(;([a-z0-9_.!~*'():@&=+$,-]|%[0-9a-f][0-9a-f])*)*)*)?(\\?([a-z0-9_.!~*'();/?:@&=+$,-]|%[0-9a-f][0-9a-f])*)?(#([a-z0-9_.!~*'();/?:@&=+$,-]|%[0-9a-f][0-9a-f])*)?|(www|ftp)\\.(([a-z0-9]([a-z0-9-]*[a-z0-9])?)\\.)*([a-z]([a-z0-9-]*[a-z0-9])?)\\.?(:[0-9]+)?(/([-a-z0-9_.!~*'():@&=+$,]|%[0-9a-f][0-9a-f])*(;([-a-z0-9_.!~*'():@&=+$,]|%[0-9a-f][0-9a-f])*)*(/([-a-z0-9_.!~*'():@&=+$,]|%[0-9a-f][0-9a-f])*(;([-a-z0-9_.!~*'():@&=+$,]|%[0-9a-f][0-9a-f])*)*)*)?(\\?([-a-z0-9_.!~*'();/?:@&=+$,]|%[0-9a-f][0-9a-f])*)?(#([-a-z0-9_.!~*'();/?:@&=+$,]|%[0-9a-f][0-9a-f])*)?)[^].,:;!)? \t\r\n<>\"]" +# }}} + +# }}} +# vim: ft=sh From b545641c6e80ddecc8db8f323e8ce6f702f7d067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Eug=C3=AAnio?= Date: Sat, 18 Feb 2023 16:16:01 -0300 Subject: [PATCH 2/2] WIP --- user/email.nix | 2 + user/neomutt/default.nix | 250 +++++++++++++++++++++++---------------- user/neomutt/neomuttrc | 48 +++++++- 3 files changed, 196 insertions(+), 104 deletions(-) diff --git a/user/email.nix b/user/email.nix index 4620472..3b6b4ca 100644 --- a/user/email.nix +++ b/user/email.nix @@ -23,6 +23,7 @@ let msmtp.enable = true; notmuch.enable = true; neomutt.enable = true; + neomutt.extraMailboxes = boxes; }; in { @@ -54,6 +55,7 @@ in passwordCommand = toString (pkgs.writeShellScript "get_pass" '' pass "Trabalho/wopus_email/leonardo@wopus.com.br" | head -n1 ''); + folders.inbox = "INBOX"; } // defaultAccountSettings { boxes = [ "INBOX" ]; }; }; diff --git a/user/neomutt/default.nix b/user/neomutt/default.nix index 6616f7b..fa1a4ff 100644 --- a/user/neomutt/default.nix +++ b/user/neomutt/default.nix @@ -1,107 +1,159 @@ -{ pkgs, lib, ... }: +{ pkgs, lib, config, ... }: let inherit (pkgs.uservars) key; inherit (lib) toUpper; + + mkControlBind = key: ''"^${ key }"''; + mkAltBind = key: ''"\e${ key }"''; + + mkDirectionBinds' = filter: modes: commands: map + (direction: lib.mkIf (lib.hasAttr direction commands) { + map = modes; + key = filter key.${direction}; + action = commands.${direction}; + }) [ "left" "down" "up" "right" ]; + + mkDirectionBinds = mkDirectionBinds' (x: x); + mkDirectionBindsControl = mkDirectionBinds' mkControlBind; + in { programs.neomutt.enable = true; - programs.neomutt.binds = [ - { - map = [ "index" ]; - key = key.left; - action = "noop"; - } - { - map = [ "index" ]; - key = key.down; - action = "next-entry"; - } - { - map = [ "index" ]; - key = key.up; - action = "previous-entry"; - } - { - map = [ "index" ]; - key = key.right; - action = "display-message"; - } + programs.neomutt.sidebar.enable = false; + programs.neomutt.sort = "reverse-date"; + programs.neomutt.binds = + (mkDirectionBindsControl [ "index" "pager" ] { + up = "half-up"; + down = "half-down"; + }) ++ + (mkDirectionBindsControl [ "index" "pager" ] { + left = "sidebar-toggle-visible"; + down = "sidebar-next"; + up = "sidebar-prev"; + right = "sidebar-open"; + }) ++ + (mkDirectionBinds [ "index" ] { + left = "noop"; + down = "next-entry"; + up = "previous-entry"; + right = "display-message"; + }) ++ + (mkDirectionBinds [ "pager" ] { + left = "exit"; + down = "next-line"; + up = "previous-line"; + right = "view-attachments"; + }) ++ + (mkDirectionBinds [ "attach" ] { + left = "exit"; + down = "next-entry"; + up = "previous-entry"; + right = "view-mailcap"; + }) ++ [ + # { + # map = [ "index" ]; + # key = key.left; + # action = "noop"; + # } + # { + # map = [ "index" ]; + # key = key.down; + # action = "next-entry"; + # } + # { + # map = [ "index" ]; + # key = key.up; + # action = "previous-entry"; + # } + # { + # map = [ "index" ]; + # key = key.right; + # action = "display-message"; + # } - { - map = [ "attach" ]; - key = key.up; - action = "previous-entry"; - } - { - map = [ "attach" ]; - key = key.down; - action = "next-entry"; - } - { - map = [ "attach" ]; - key = key.left; - action = "exit"; - } - { - map = [ "attach" ]; - key = key.right; - action = "view-mailcap"; - } - { - map = [ "pager" ]; - key = key.left; - action = "exit"; - } - { - map = [ "pager" ]; - key = key.down; - action = "next-line"; - } - { - map = [ "pager" ]; - key = key.up; - action = "previous-line"; - } - { - map = [ "pager" ]; - key = key.right; - action = "view-attachments"; - } - { - map = [ "index" "pager" "browser" ]; - key = toUpper key.up; - action = "half-up"; - } - { - map = [ "index" "pager" "browser" ]; - key = toUpper key.down; - action = "half-down"; - } - { - map = [ "browser" ]; - key = key.left; - action = "goto-parent"; - } - { - map = [ "index" "pager" ]; - key = "\\C${ key.down }"; - action = "sidebar-next"; - } - { - map = [ "index" "pager" ]; - key = "\\C${ key.up }"; - action = "sidebar-prev"; - } - { - map = [ "index" "pager" ]; - key = "\\C${ key.right }"; - action = "sidebar-open"; - } - { - map = [ "index" "pager" ]; - key = "\\C${ key.left }"; - action = "sidebar-toggle-visible"; - } - ]; - programs.neomutt.extraConfig = lib.readFile ./neomuttrc; + # { + # map = [ "attach" ]; + # key = key.left; + # action = "exit"; + # } + # { + # map = [ "attach" ]; + # key = key.down; + # action = "next-entry"; + # } + # { + # map = [ "attach" ]; + # key = key.up; + # action = "previous-entry"; + # } + # { + # map = [ "attach" ]; + # key = key.right; + # action = "view-mailcap"; + # } + + # { + # map = [ "pager" ]; + # key = key.left; + # action = "exit"; + # } + # { + # map = [ "pager" ]; + # key = key.down; + # action = "next-line"; + # } + # { + # map = [ "pager" ]; + # key = key.up; + # action = "previous-line"; + # } + # { + # map = [ "pager" ]; + # key = key.right; + # action = "view-attachments"; + # } + + # { + # map = [ "index" "pager" "browser" ]; + # key = toUpper key.up; + # action = "half-up"; + # } + # { + # map = [ "index" "pager" "browser" ]; + # key = toUpper key.down; + # action = "half-down"; + # } + + { + map = [ "browser" ]; + key = key.left; + action = "goto-parent"; + } + + # { + # map = [ "index" "pager" ]; + # key = mkControlBind key.down; + # action = "sidebar-next"; + # } + # { + # map = [ "index" "pager" ]; + # key = mkControlBind key.up; + # action = "sidebar-prev"; + # } + # { + # map = [ "index" "pager" ]; + # key = mkControlBind key.right; + # action = "sidebar-open"; + # } + # { + # map = [ "index" "pager" ]; + # key = mkControlBind key.left; + # action = "sidebar-toggle-visible"; + # } + + ]; + programs.neomutt.extraConfig = '' + source extra + ''; + xdg.configFile."neomutt/extra".source = config.lib.file.mkOutOfStoreSymlink "/home/lelgenio/projects/nixos-config/user/neomutt/neomuttrc"; } diff --git a/user/neomutt/neomuttrc b/user/neomutt/neomuttrc index 667225c..9c236ed 100644 --- a/user/neomutt/neomuttrc +++ b/user/neomutt/neomuttrc @@ -31,21 +31,27 @@ set use_from = yes # }}} # General {{{ -set use_threads = threads -set sort = reverse-last-date -set sort_aux = last-date +# set use_threads = threads +set sort = threads +set sort_aux = reverse-last-date set mail_check_stats = yes set mail_check_stats_interval = 10 set mark_old = no # Unread mail stay unread until read + set mailcap_path = ~/.config/neomutt/mailcap + auto_view text/html # automatically show html auto_view application/pgp-encrypted alternative_order text/plain text/enriched text/html set query_command= "khard email --parsable %s" +# unmailboxes * +mailboxes 'notmuch://?query=tag:inbox' +set spoolfile = 'notmuch://?query=tag:inbox' + # }}} # General rebindings{{{ @@ -115,7 +121,7 @@ set sidebar_visible = yes set sidebar_width = 20 set sidebar_short_path = yes set sidebar_next_new_wrap = yes -# set mail_check_stats +set mail_check_stats set sidebar_format = '%B%?F? [%F]?%* %?N?%N/? %?S?%S?' @@ -131,11 +137,43 @@ set markers = no set date_format="%m/%d %H:%M" set index_format="%3C %zs %?X?A& ? %D %-15.15F %s" -set display_filter = '_mutt_escape-html-chars' +# set display_filter = '_mutt_escape-html-chars' #}}} # colors{{{ +# General +color status black default +color indicator brightwhite red + +# Messages +color index default default '.*' +color index_number black default +color index_author red default '.*' +color index_subject green default '.*' + +# New messages +color index brightgreen default "~N|~O" +color index_author brightred default "~N" +color index_subject brightcyan default "~N" + +# Sidebar +color sidebar_new green default +color sidebar_highlight default green +color sidebar_indicator brightwhite red +color sidebar_divider black default + +# Header - information for any open email +color header default default "^(Date)" +color header red default "^(From)" +color header green default "^(Subject)" +color header brightwhite default "^(CC|BCC)" + +# Content - Body of open email +color body brightred default "[\-\.+_a-zA-Z0-9]+@[\-\.a-zA-Z0-9]+" # Email addresses +color body brightblue default "(https?|ftp)://[\-\.,/%~_:?&=\#a-zA-Z0-9]+" # URL +color attachment default black + # # General # color status black default # color indicator brightwhite {{@@ accent_color_name @@}}