diff --git a/home/mail/bindings.neomuttrc b/home/mail/bindings.neomuttrc index bcffc0e..833af0d 100644 --- a/home/mail/bindings.neomuttrc +++ b/home/mail/bindings.neomuttrc @@ -1,52 +1,5 @@ -# Navigation -bind pager k previous-entry -bind pager j next-entry -bind index display-message -bind index collapse-thread -bind index,pager gf change-folder - -# Read HTML -bind index,pager V noop -macro index,pager V "html" "View as HTML" # compose -bind compose p postpone-message -bind compose P pgp-menu -macro compose I "\`tmpfile=$(mktemp -u --suffix .png -t XXXXXXXXXXXX -p ~/tmp) && wl-paste -t image/png > \"$tmpfile\" && echo \"$tmpfile\"\`" "attach image from clipboard" - -bind editor complete-query -bind editor ^T complete -bind index,pager a group-reply -bind index,pager m noop -macro index,pager mar "newn*" "Mark all read" - -# compose with signature management -macro index,pager c "set signature=$my_signature" "Compose new message" -macro index,pager r "unset signature" "Reply to message" -macro index,pager a "unset signature" "Reply all" -macro index,pager f "unset signature" "Forward message" -macro index,pager l "unset signature" "List reply" - -# moving messages -macro index,pager J ":set resolve=no\nn:set resolve=yes\n$my_junk" "Move to junk" -macro index,pager y ":set resolve=no\nn:set resolve=yes\n$mbox" "Move to archive" -macro index,pager I "$spoolfile" "Move to inbox" - -# switch folders -macro index,pager g! "$spoolfile" "Go to inbox" -macro index,pager gd "$postponed" "Go to drafts" -macro index,pager g< "$record" "Go to sent" -macro index,pager g> "$mbox" "Go to archive" -macro index,pager gt "$trash" "Go to trash" -macro index,pager gj "$my_junk" "Go to junk" - -# accounts -macro index,pager gu "~/.local/share/mail/gu/Inbox" "Go to gu" -macro index,pager gm "~/.local/share/mail/t9e/Inbox" "Go to t9e" -macro index,pager gk "~/.local/share/mail/ksh/Inbox" "Go to ksh" -macro index,pager gi "~/.local/share/mail/ktiu/Inbox" "Go to ktiu" - -macro index,pager L "all\n" "Show all messages (undo limit)" macro index,pager go "mbsync $my_account && notmuch new" "Sync this account" macro index,pager gO "mbsync -a && notmuch new" "Sync all accounts" @@ -61,8 +14,3 @@ macro index,pager /d "folder:+$my_account/$my_nm_po macro index,pager /t "folder:+$my_account/$my_nm_trash" "Find in trash" macro index,pager /j "folder:+$my_account/$my_nm_junk" "Find in junk" -macro index,pager A "khard add-email --vcard-version=4.0" "Add sender to khard" - -macro index,pager S " ripmime -i - -d ~/tmp && rm ~/tmp/textfile*" "Save all attachments" - -macro index,pager gb " urlscan" "Extract URLs" diff --git a/home/mail/config.neomuttrc b/home/mail/config.neomuttrc index a41cf1a..da13972 100644 --- a/home/mail/config.neomuttrc +++ b/home/mail/config.neomuttrc @@ -1,71 +1,26 @@ +# Alias + set alias_file = ~/.local/share/neomutt/aliases.neomuttrc source $alias_file -set mailcap_path = ~/.config/neomutt/mailcap +# External set my_download_folder = ~/tmp -set shell = /bin/sh - -# Caching and tmp -set header_cache = $XDG_CACHE_HOME/neomutt/headers -set message_cachedir = $XDG_CACHE_HOME/neomutt/bodies -set header_cache_backend = "lmdb" -set tmpdir = $XDG_CACHE_HOME/neomutt/tmp - -# Basic options -unset wait_key -set mbox_type = Maildir -set mail_check_stats -unset confirm_append -unset beep -unset mark_old -set sleep_time = 0 - -# Sending -set use_envelope_from -unset reverse_real_name - -# Searching -set nm_default_url = "notmuch:///home/till/.local/share/mail/" -set my_nm_spoolfile = 'Inbox' -set my_nm_postponed = 'Drafts' -set my_nm_record = 'Sent' -set my_nm_trash = 'Trash' - -folder-hook . source ~/.config/neomutt/bindings.neomuttrc - -# Compose -set editor = "nvim -c 'call woof#init#Init()'" -set edit_headers -set forward_format = "Fwd: %s" -set forward_attachments -set fast_reply -set include -set forward_quote -unset recall -set resume_draft_files -set abort_noattach_regex = "(attach|enclosed|anbei|anhängen|angehängt|anhang|anhänge|hängt an)" -set abort_noattach = ask-yes -set mime_type_query_command = "file -b --mime-type %s" -set query_command= "khard email --parsable '%s'" - # Status bar + set status_chars = "✔↻٪A" -set status_format = "— [ %r ] %f (%lB) %>— %m messages%?n? [ %n new ]?%?d? [ %d to delete ]?%?t? [ %t tagged ]? —" unset help # Index + set index_format = "%-25.25F %<[y?%<[7d?%<[d?%[ %H:%M]&%[%a %H:%M]>&%[%d.%m. %Hh]>&%[%d.%m.%Y]> %Z %?X?▼ &?%s" set strict_threads set send_charset = "utf-8:iso-8859-1:us-ascii" set charset = "utf-8" -# sorting -set sort = threads -set sort_aux = reverse-last-date-received - # Pager view + set pager_index_lines = 10 set pager_context = 3 set pager_stop @@ -81,31 +36,23 @@ alternative_order text/plain text/enriched text/html auto_view text/html # Attachments + set rfc2047_parameters set attach_save_dir = $my_download_folder -## Indicator -color indicator brightwhite brightblack +# Colors -## Index +color indicator brightwhite brightblack color index_flags brightmagenta default '.*' color index_date cyan default - -## New mail color index brightblack default '~N' - -## Header colors color header brightblack default ".*" color header brightgreen default "^(Subject)" color header yellow default "^(From|To|CC|BCC)" color header blue default "^Date" - -## Mutt color message cyan default color error red default color tilde black default - -## Pager color normal default default color attachment brightblack default color search black yellow @@ -117,8 +64,6 @@ color quoted4 red default color quoted5 brightred default color signature cyan default color underline black default - -## Email color body blue default "[\-\.+_a-zA-Z0-9]+@[\-\.a-zA-Z0-9]+" # Email addresses color body blue default "(https?|ftp)://[\-\.,/%~_:?&=\#a-zA-Z0-9]+" # URL color body red default "(BAD signature)" diff --git a/home/mail/default.nix b/home/mail/default.nix index b00c1b9..5133ecc 100644 --- a/home/mail/default.nix +++ b/home/mail/default.nix @@ -1,32 +1,63 @@ { config, pkgs, lib, ... }: -{ - programs.msmtp.enable = true; +let - programs.mbsync.enable = true; + makeConfig = accountName: + '' + unset reverse_name + unset crypt_auto_pgp + unset crypt_auto_smime + set my_account='${ accountName }' + macro index,pager / "tag:${ accountName } " + unalternates * + set nm_record_tags = "+sent -inbox -unread +${ accountName }"; + set my_signature = ${ pkgs.writeText "signature.txt" config.accounts.email.accounts.${accountName}.signature.text } + set status_format = "— [ %r ] $my_account %f (%lB) %>— %m messages%?n? [ %n new ]?%?d? [ %d to delete ]?%?t? [ %t tagged ]? —" + ''; - programs.notmuch.enable = true; + makeAccount = accountName: { + signature.showSignature = "append"; + smtp.tls.useStartTls = true; + msmtp.enable = true; - programs.neomutt = { - enable = true; - vimKeys = true; - extraConfig = builtins.readFile ./config.neomuttrc; + mbsync = { + enable = true; + create = "maildir"; + expunge = "both"; + }; + + neomutt = { + enable = true; + sendMailCommand = "${lib.getExe pkgs.msmtp} -a ${ accountName }"; + }; + + notmuch = { + enable = true; + neomutt = { + virtualMailboxes = [ + { name = "Inbox"; query = "tag:${ accountName } and tag:inbox"; } + { name = "Archive"; query = "tag:${ accountName } and not tag:sent and not tag:draft"; } + { name = "Sent"; query = "tag:${ accountName } and tag:sent"; } + { name = "Drafts"; query = "tag:${ accountName } and tag:draft"; } + { name = "Spam"; query = "tag:${ accountName } and tag:spam"; } + { name = "Trash"; query = "tag:${ accountName } and tag:trash"; } + ]; + }; + }; }; - xdg.configFile."neomutt/bindings.neomuttrc".source = ./bindings.neomuttrc; - xdg.configFile."neomutt/mailcap".source = ./neomutt_mailcap; +in +{ accounts.email = { maildirBasePath = "${config.xdg.dataHome}/mail"; accounts = { - - gu = { name, ... }: { + gu = { name, ... }: lib.attrsets.recursiveUpdate (makeAccount name) { primary = true; address = "straube@geo.uni-frankfurt.de"; realName = "Till Straube"; imap.host = "imap.server.uni-frankfurt.de"; smtp.host = "smtpauth.rz.uni-frankfurt.de"; - smtp.tls.useStartTls = true; userName = "tstraube"; passwordCommand = "pass uni/hrz"; signature = { @@ -35,149 +66,180 @@ Dept. of Human Geography Goethe University Frankfurt ''; - showSignature = "append"; }; - notmuch.enable = true; - mbsync = { - enable = true; - create = "maildir"; - expunge = "both"; - }; - msmtp.enable = true; neomutt = { - enable = true; - sendMailCommand = "${lib.getExe pkgs.msmtp} -a ${ name }"; - extraConfig = '' - set my_account='${ name }' - - set mbox='+Archive' - set my_nm_mbox='Archive' - - set my_junk='+Spamverdacht' - set my_nm_junk='Spamverdacht' - - set crypt_auto_smime - unset crypt_auto_pgp - - set crypt_autosign - set crypt_replyencrypt - set crypt_replysign - set crypt_replysignencrypted - set crypt_verify_sig - set smime_sign_as = "f1355556.0" - set pgp_default_key = "" - - unalternates * - alternates ^straube@em.uni-frankfurt.de$ \ - ^tstraube@em.uni-frankfurt.de$ \ - ^tstraube@rz.uni-frankfurt.de$ \ - ^tstraube@uni-frankfurt.de$ - unset reverse_name - - set my_signature = ${ pkgs.writeText "signature.txt" config.accounts.email.accounts.gu.signature.text } + extraConfig = makeConfig name + '' color status blue default + alternates ^tstraube@(em|rz)?.uni-frankfurt.de$ + set crypt_auto_smime ''; }; }; - t9e = { name, ... }: { + t9e = { name, ... }: lib.attrsets.recursiveUpdate (makeAccount name) { address = "till.straube@t9e.me"; realName = "Till Straube"; imap.host = "arielle.ktiu.net"; smtp.host = "arielle.ktiu.net"; - smtp.tls.useStartTls = true; userName = "till.straube@t9e.me"; signature.text = '' Till Straube (he/him) PGP key: https://keys.openpgp.org/search?q=till.straube@t9e.me ''; - gpg.signByDefault = true; - notmuch.enable = true; neomutt = { - enable = true; - sendMailCommand = "${lib.getExe pkgs.msmtp} -a ${ name }"; - extraConfig = '' - set my_mbsync_account='${ name }' - - set mbox='+Archive' - set my_nm_mbox='Archive' - - set my_junk='+Junk' - set my_nm_junk='Junk' - - set crypt_auto_pgp - unset crypt_auto_smime - - unalternates * - alternates @t9e.me$ @ktiu.net$ - set reverse_name - - set my_signature = ${ pkgs.writeText "signature.txt" config.accounts.email.accounts.t9e.signature.text } + extraConfig = makeConfig name + '' color status green default + alternates @t9e.me$ @ktiu.net$ ^(tillkowski|till.straube)@gmail.com$ + set reverse_name + set crypt_auto_pgp ''; }; - mbsync = { - enable = true; - create = "maildir"; - expunge = "both"; - }; - msmtp = { - enable = true; - extraConfig.port = "587"; - }; + msmtp.extraConfig.port = "587"; passwordCommand = "pass accounts/ktiu-imap"; }; - ksh = { name, ...}: { + ksh = { name, ... }: lib.attrsets.recursiveUpdate (makeAccount name) { address = "kein_schlussstrich_hessen@systemli.org"; realName = "Kein Schlussstrich Hessen"; imap.host = "mail.systemli.org"; smtp.host = "mail.systemli.org"; - smtp.tls.useStartTls = true; userName = "kein_schlussstrich_hessen@systemli.org"; signature.text = '' Kein Schlussstrich Hessen PGP Key: https://keys.openpgp.org/search?q=kein_schlussstrich_hessen@systemli.org ''; - signature.showSignature = "append"; - gpg.signByDefault = true; - notmuch.enable = true; neomutt = { - enable = true; - sendMailCommand = "${lib.getExe pkgs.msmtp} -a ${ name }"; - extraConfig = '' - set my_mbsync_account='${ name }' - - set mbox='+Erledigt' - set my_nm_mbox='Erledigt' - - set my_junk='+Junk' - set my_nm_junk='Junk' - + extraConfig = makeConfig name + '' + color status red default set crypt_auto_pgp - unset crypt_auto_smime - - unalternates * - set reverse_name - set my_signature = ${ - pkgs.writeText - "signature.txt" - config.accounts.email.accounts.ksh.signature.text - } - color status cyan default ''; }; - mbsync = { - enable = true; - create = "maildir"; - expunge = "both"; - }; - msmtp.enable = true; passwordCommand = "pass ksh/systemli"; }; }; }; + programs.msmtp.enable = true; + + programs.mbsync.enable = true; + + programs.notmuch = { + enable = true; + search.excludeTags = [ "trash" "spam" ]; + new.tags = [ "new" "unread" ]; + hooks = { + preNew = '' + notmuch tag +draft -- folder:/\/Drafts\// not tag:draft + mbsync --all + ''; + postNew = '' + notmuch tag +gu -- tag:new path:gu/** + notmuch tag +t9e -- tag:new path:t9e/** + notmuch tag +ksh -- tag:new path:ksh/** + notmuch tag +inbox -- tag:new 'folder:"/\/Inbox$/"' + notmuch tag +sent -unread -- tag:new 'folder:"/\/Sent$/"' + notmuch tag +trash -unread -- tag:new 'folder:"/\/Trash$/"' + notmuch tag +draft -unread -- tag:new 'folder:"/\/Drafts$/"' + notmuch tag +spam -- tag:new 'folder:"/\/Spam$/"' + notmuch tag +spam -- tag:new 'folder:"/\/Junk$/"' + notmuch tag -new -- tag:new + ''; + }; + }; + + programs.neomutt = { + enable = true; + + vimKeys = true; + changeFolderWhenSourcingAccount = true; + editor = "nvim -c 'call woof#init#Init()'"; + sort = "reverse-date-received"; + unmailboxes = true; + + settings = { + abort_noattach = "ask-yes"; + abort_noattach_regex = "\"(attach|enclosed|anbei|anhängen|angehängt|anhang|anhänge|hängt an)\""; + # auto_edit = "yes"; + beep = "no"; + confirm_append = "no"; + crypt_auto_sign = "yes"; + crypt_replyencrypt = "yes"; + crypt_replysign = "yes"; + crypt_replysignencrypted = "yes"; + crypt_verify_sig = "yes"; + edit_headers = "yes"; + forward_attachments = "yes"; + forward_format = "\"Fwd: %s\""; + forward_quote = "yes"; + include = "yes"; + mail_check_stats = "yes"; + mailcap_path = builtins.path { path = ./neomutt_mailcap; }; + mark_old = "no"; + mbox_type = "Maildir"; + mime_type_query_command = "\"file -b --mime-type %s\""; + nm_record = "yes"; + query_command= "\"khard email --parsable '%s'\""; + recall = "no"; + resume_draft_files = "yes"; + reverse_real_name = "no"; + shell = "/bin/sh"; + sleep_time = "0"; + use_envelope_from = "yes"; + virtual_spool_file = "yes"; + wait_key = "no"; + }; + + binds = [ + { key = "k"; map = "pager"; action = "previous-entry"; } + { key = "j"; map = "pager"; action = "next-entry"; } + { key = ""; map = "index"; action = "display-message"; } + { key = ""; map = "index"; action = "collapse-thread"; } + { key = "gf"; map = [ "index" "pager" ]; action = "change-folder"; } + { key = "P"; map = "compose"; action = "pgp-menu"; } + { key = ""; map = "editor"; action = "complete-query"; } + { key = "a"; map = [ "index" "pager" ]; action = "group-reply"; } + { key = "m"; map = [ "index" "pager" ]; action = "noop"; } + ]; + + macros = [ + { key = "gu"; map = [ "index" "pager" ]; action = "tag:dummy:source ${config.xdg.configHome}/neomutt/gug!"; } + { key = "gm"; map = [ "index" "pager" ]; action = "tag:dummy:source ${config.xdg.configHome}/neomutt/t9eg!"; } + { key = "gk"; map = [ "index" "pager" ]; action = "tag:dummy:source ${config.xdg.configHome}/neomutt/kshg!"; } + + { key = "Y"; map = [ "index" "pager" ]; action = ""; } + { key = "y"; map = [ "index" "pager" ]; action = "-inbox -unread -spam -trash"; } + { key = "J"; map = [ "index" "pager" ]; action = "+spam -inbox -unread -trash"; } + { key = "I"; map = [ "index" "pager" ]; action = "+inbox -old -spam -trash"; } + { key = "Y"; map = [ "index" "pager" ]; action = ""; } + { key = "dd"; map = [ "index" "pager" ]; action = "+trash -inbox -unread -spam"; } + + { key = "g!"; map = [ "index" "pager" ]; action = "Inbox"; } + { key = "g<"; map = [ "index" "pager" ]; action = "Sent"; } + { key = "g>"; map = [ "index" "pager" ]; action = "Archive"; } + { key = "gj"; map = [ "index" "pager" ]; action = "Spam"; } + { key = "gd"; map = [ "index" "pager" ]; action = "Drafts"; } + { key = "gt"; map = [ "index" "pager" ]; action = "Trash"; } + + { key = "go"; map = [ "index" "pager" ]; action = "notmuch new"; } + { key = "V"; map = ["index" "pager"]; action = "html"; } + { key = "mar"; map = [ "index" "pager" ]; action = "newn*"; } + { key = "A"; map = [ "index" "pager" ]; action = "khard add-email --vcard-version=4.0"; } + { key = "S"; map = [ "index" "pager" ]; action = "ripmime -i - -d ~/tmp && rm ~/tmp/textfile*"; } + { key = "gb"; map = [ "index" "pager" ]; action = "urlscan"; } + { key = "I"; map = [ "compose" ]; action = "`tmpfile=$(mktemp -u --suffix .png -t XXXXXXXXXXXX -p ~/tmp) && wl-paste -t image/png > \"$tmpfile\" && echo \"$tmpfile\"`"; } + + { key = "c"; map = [ "index" "pager" ]; action = "set signature=$my_signature"; } + { key = "r"; map = [ "index" "pager" ]; action = "unset signature"; } + { key = "a"; map = [ "index" "pager" ]; action = "unset signature"; } + { key = "f"; map = [ "index" "pager" ]; action = "unset signature"; } + { key = "l"; map = [ "index" "pager" ]; action = "unset signature"; } + ]; + + extraConfig = builtins.readFile ./config.neomuttrc; + }; + + xdg.configFile."neomutt/bindings.neomuttrc".source = ./bindings.neomuttrc; + programs.neovim.plugins = with pkgs.vimPlugins; [ { plugin = vim-pathogen;