[neomutt] Refactor to allow for alternative mail setups. Also add urlscan keybind

This commit is contained in:
lara 2020-06-18 22:01:14 -04:00
parent cc36d26f09
commit feccebb1c9
8 changed files with 142 additions and 108 deletions

View file

@ -1,10 +1,10 @@
set sendmail = "/usr/bin/msmtp -a $my_account" set sendmail = "/usr/bin/msmtp $my_msmtp_conf -a $my_account"
set spoolfile = "+$my_account/Inbox" set spoolfile = "+$my_account/Inbox"
set record = "+$my_account/Sent" set record = "+$my_account/Sent"
set postponed = "+$my_account/Draft" set postponed = "+$my_account/Draft"
set trash = "+$my_account/Trash" set trash = "+$my_account/Trash"
macro index,pager gs "<shell-escape>mbsync $my_account<enter>" "IMAP sync account" macro index,pager gs "<shell-escape>mbsync $my_mbsync_conf $my_account<enter>" "IMAP sync account"
macro index,pager gi "<shell-escape>mbsync $my_account:Inbox<enter>" "IMAP sync Inbox" macro index,pager gi "<shell-escape>mbsync $my_mbsync_conf $my_account:Inbox<enter>" "IMAP sync Inbox"
# vim: syntax=neomuttrc # vim: syntax=neomuttrc

93
config/neomutt/common.rc Normal file
View file

@ -0,0 +1,93 @@
set copy # See also $record
unmailboxes *
source "~/.config/neomutt/mailboxes.sh $folder|"
# Load external configs
source sidebar.rc
source colors.rc
source gpg.rc
source keys.rc
# Accounts
source "~/.config/neomutt/folder-hooks.sh $folder|"
# Basic options
unset wait_key # Only wait if command exited != 0
set delete # delete messages for real
unset confirmappend # don't ask when adding to a mailbox
set quit #default; <quit> exits neomutt
unset move #default; don't move read messages
unset mark_old # don't mark unread mail as old when exiting mailbox
set beep_new # Hope your term bell is set to something sensible :P
unset pipe_decode # decode and weed headers before <pipe-message>, urlscan seems to require it unset
set thorough_search #default; decode mail before searching ~b and ~h
set sleep_time = 0 # Speed up folder opening
set change_folder_next # Default to next folder in list
set mail_check = 5 #default; look for new mail every 'n' seconds
set mail_check_stats # Allow mail stats gathering
set mail_check_stats_interval = 10 # Mail stats calc interval
# Status bar
set status_chars = " *%A" # mailbox unchanged/changed/RO/attach-msg mode
set status_format = "───[ Folder: %f ]───[%r%m messages%?n? (%n new)?%?d? (%d to delete)?%?t? (%t tagged)? ]───%>─%?p?( %p postponed )?───"
#########
# Index #
#########
set date_format = "%d/%m/%y %H:%M"
set index_format = "[%Z] %D - %-20.20F %s"
set sort = threads
set sort_aux = last-date-received
set uncollapse_jump # Jump to unread when unfolding
set sort_re #default; useful for mailbox sort in sidebar
unset narrow_tree #default; compact thread tree arrows
#########
# Pager #
#########
set pager_index_lines = 10 # lines aboves the pager
set pager_context = 3 # lines of context around selected msg in index
set pager_stop # don't jump to next msg when scrolling past the end
set menu_scroll # don't skip to next page when reaching bottom
set tilde # pad blank lines with '~'
unset markers # remove '+' on wrapped lines
set smart_wrap #default; wrap at word boundaries
set quote_regex = "^( {0,4}[>|:#%]| {0,4}[a-z0-9]+[>|]+)+"
# Prefer plaintext and process html through mailcap
alternative_order text/plain text/enriched text/html
auto_view text/html
# Prune headers
ignore *
unignore From To Reply-To Cc Bcc Subject Date
unignore Organization X-Label X-Mailer User-Agent
###########
# Compose #
###########
# https://www.zigg.com/2018/natalie-nguyen.html
my_hdr X-Clacks-Overhead: GNU Natalie Nguyen, Terry Pratchett
set use_from # set a From: header
set use_envelope_from # which from?
set sig_dashes # dashes before sig
set edit_headers # show headers when composing
set fast_reply # skip to compose when replying
set askcc # ask for CC:
set fcc_attach # save attachments with the body
unset mime_forward # forward attachments as part of body
set forward_format = "Fwd: %s" # format of subject when forwarding
set forward_decode # decode when forwarding
set attribution = "On %d, %n wrote:" # format of quoting header
set reply_to # reply to Reply to: field
set reverse_name # reply as whomever it was to
set include # include message in replies
set forward_quote # include message in forwards
set send_charset = utf-8
set sendmail_wait = 0 # wait for msmtp to finish sending
set abort_noattach = ask-yes # warn for missing attachment
set abort_noattach_regex = "\\<(attach(|ed|ments?)|(attaché|attachés|attache|attachons|joint|jointe|joints|jointes|joins|joignons))\\>"
set editor = "vim -c 'set tw=70 et wrap' '+/^$' "
set mask = ".*" # Which files to match
# vim: syntax=neomuttrc

View file

@ -1,8 +1,8 @@
#!/bin/sh #!/bin/sh
usage() { usage() {
echo "$0 <mutt \$folder>" >&2 echo "$0 <mutt \$folder>"
echo " Generate mutt folder hooks for every maildir account in \$folder" >&2 echo " Generate mutt folder hooks for every maildir account in \$folder"
exit 1 exit 1
} }
@ -14,14 +14,12 @@ acc_dir="$HOME/.config/neomutt/accounts/"
mail_dir="$1" mail_dir="$1"
# Select default account # Select default account
default="$(find "$acc_dir" -name "*.mail" -printf "source '%p'\n" -quit)" #default="$(find "$acc_dir" -name "*.mail" -printf "source '%p'\n" -quit)"
if [ -z "$default" ]; then #if [ -z "$default" ]; then
>&2 echo "No mail accounts found in $acc_dir" # >&2 echo "No mail accounts found in $acc_dir"
exit 1 # exit 1
fi #fi
printf '%s\n' "$default"
# Order of the keys to use for the account switch macro # Order of the keys to use for the account switch macro
chars="1234567890azertyuiopqsdfghjklmwxcvbn" chars="1234567890azertyuiopqsdfghjklmwxcvbn"
@ -30,6 +28,12 @@ i=1
# Setup folder hooks for all the accounts # Setup folder hooks for all the accounts
for f in "$acc_dir"*.mail; do for f in "$acc_dir"*.mail; do
account="$(basename -s '.mail' "$f")" account="$(basename -s '.mail' "$f")"
if [ ! -d "$mail_dir/$account" ]; then
continue
fi
if [ -z "$default" ]; then
default="source '$f'"
fi
inbox="$(find "$mail_dir/$account" -maxdepth 1 -iname "inbox" -type d -printf "%f" -quit)" inbox="$(find "$mail_dir/$account" -maxdepth 1 -iname "inbox" -type d -printf "%f" -quit)"
printf 'folder-hook =%s '\''source %s'\''\n' "$account" "$f" printf 'folder-hook =%s '\''source %s'\''\n' "$account" "$f"
key="$(printf '%s' "$chars" | cut -c "$i")" key="$(printf '%s' "$chars" | cut -c "$i")"
@ -37,3 +41,7 @@ for f in "$acc_dir"*.mail; do
"$key" "$account" "$inbox" "$account" "$key" "$account" "$inbox" "$account"
i=$((i+1)) i=$((i+1))
done done
if [ ! -z "$default" ]; then
printf '%s\n' "$default"
fi

View file

@ -6,6 +6,7 @@ bind index,pager \Cu half-up
bind index,pager \Cd half-down bind index,pager \Cd half-down
bind index,pager g noop # required to define multikeys binds bind index,pager g noop # required to define multikeys binds
bind index,pager <tab> sync-mailbox bind index,pager <tab> sync-mailbox
macro index,pager ga "<shell-escape>mailsync<enter>" "Sync all IMAP mailboxes"
########### ###########
# SIDEBAR # # SIDEBAR #
@ -51,6 +52,8 @@ bind pager R group-reply
bind pager gh display-toggle-weed bind pager gh display-toggle-weed
bind pager ge extract-keys bind pager ge extract-keys
macro pager gu "<pipe-message> urlscan <enter>"
########## ##########
# ATTACH # # ATTACH #
########## ##########

View file

@ -1,8 +1,8 @@
#!/bin/sh #!/bin/sh
usage() { usage() {
echo "$0 <neomutt \$folder>" >&2 echo "$0 <neomutt \$folder>"
echo " Generate neomutt mailboxes & named-mailboxes for every maildir in \$folder" >&2 echo " Generate neomutt mailboxes & named-mailboxes for every maildir in \$folder"
exit 1 exit 1
} }

View file

@ -1,94 +1,13 @@
# Maildir setup # Default config
set mbox_type = Maildir set mbox_type = Maildir
set copy # See also $record (f*ckin recursion)
set folder = "~/mail" set folder = "~/mail"
unmailboxes * set my_msmtp_conf = "" # Leave empty for default
source "~/.config/neomutt/mailboxes.sh $folder|" set my_mbsync_conf = "" # Leave empty for default
source common.rc
# Load external configs # Override sidebar_new_mail_only
source sidebar.rc # Move back to sidebar.rc once the issue is resolved
source colors.rc # https://github.com/neomutt/neomutt/issues/2208
source gpg.rc sidebar_whitelist `find $folder -mindepth 1 -maxdepth 1 -type d ! -name cur ! -name tmp ! -name new ! -name .notmuch -printf '"%f"\0' | xargs -0`
source keys.rc sidebar_whitelist `find $folder -mindepth 1 -maxdepth 1 -type d ! -name cur ! -name tmp ! -name new ! -name .notmuch -printf '"%p"\0' | xargs -0`
sidebar_whitelist `find ~/mail -mindepth 1 -type d -iname inbox -printf '"%p"\0' | xargs -0`
# Accounts
source "~/.config/neomutt/folder-hooks.sh $folder|"
# Basic options
unset wait_key # Only wait if command exited != 0
set delete # delete messages for real
unset confirmappend # don't ask when adding to a mailbox
set quit #default; <quit> exits neomutt
unset move #default; don't move read messages
unset mark_old # don't mark unread mail as old when exiting mailbox
set beep_new # Hope your term bell is set to something sensible :P
set pipe_decode # decode and weed headers before <pipe-message>
set thorough_search #default; decode mail before searching ~b and ~h
set sleep_time = 0 # Speed up folder opening
set change_folder_next # Default to next folder in list
set mail_check = 5 #default; look for new mail every 'n' seconds
set mail_check_stats # Allow mail stats gathering
set mail_check_stats_interval = 10 # Mail stats calc interval
# Status bar
set status_chars = " *%A" # mailbox unchanged/changed/RO/attach-msg mode
set status_format = "───[ Folder: %f ]───[%r%m messages%?n? (%n new)?%?d? (%d to delete)?%?t? (%t tagged)? ]───%>─%?p?( %p postponed )?───"
#########
# Index #
#########
set date_format = "%d/%m/%y %H:%M"
set index_format = "[%Z] %D - %-20.20F %s"
set sort = threads
set sort_aux = last-date-received
set uncollapse_jump # Jump to unread when unfolding
set sort_re #default; useful for mailbox sort in sidebar
unset narrow_tree #default; compact thread tree arrows
#########
# Pager #
#########
set pager_index_lines = 10 # lines aboves the pager
set pager_context = 3 # lines of context around selected msg in index
set pager_stop # don't jump to next msg when scrolling past the end
set menu_scroll # don't skip to next page when reaching bottom
set tilde # pad blank lines with '~'
unset markers # remove '+' on wrapped lines
set smart_wrap #default; wrap at word boundaries
set quote_regex = "^( {0,4}[>|:#%]| {0,4}[a-z0-9]+[>|]+)+"
# Prefer plaintext and process html through mailcap
alternative_order text/plain text/enriched text/html
auto_view text/html
# Prune headers
ignore *
unignore From To Reply-To Cc Bcc Subject Date
unignore Organization X-Label X-Mailer User-Agent
###########
# Compose #
###########
# https://www.zigg.com/2018/natalie-nguyen.html
my_hdr X-Clacks-Overhead: GNU Natalie Nguyen, Terry Pratchett
set use_from # set a From: header
set use_envelope_from # which from?
set sig_dashes # dashes before sig
set edit_headers # show headers when composing
set fast_reply # skip to compose when replying
set askcc # ask for CC:
set fcc_attach # save attachments with the body
unset mime_forward # forward attachments as part of body
set forward_format = "Fwd: %s" # format of subject when forwarding
set forward_decode # decode when forwarding
set attribution = "On %d, %n wrote:" # format of quoting header
set reply_to # reply to Reply to: field
set reverse_name # reply as whomever it was to
set include # include message in replies
set forward_quote # include message in forwards
set send_charset = utf-8
set sendmail_wait = 0 # wait for msmtp to finish sending
set abort_noattach = ask-yes # warn for missing attachment
set abort_noattach_regex = "\\<(attach(|ed|ments?)|(attaché|attachés|attache|attachons|joint|jointe|joints|jointes|joins|joignons))\\>"
set editor = "vim -c 'set tw=70 et wrap' '+/^$' "
set mask = ".*" # Which files to match

View file

@ -12,8 +12,5 @@ set sidebar_new_mail_only # Only display mailbox with new/flagged mail
unset sidebar_next_new_wrap # wrap <sidebar-{next,prev}-new> to beginning unset sidebar_next_new_wrap # wrap <sidebar-{next,prev}-new> to beginning
unset sidebar_on_right # keep bar on the left unset sidebar_on_right # keep bar on the left
set sidebar_sort_method = 'path' # sort by mailbox path alphabetically set sidebar_sort_method = 'path' # sort by mailbox path alphabetically
# Override sidebar_new_mail_only
sidebar_whitelist `find ~/mail -mindepth 1 -maxdepth 1 -type d ! -name cur ! -name tmp ! -name new ! -name .notmuch -printf '"%p"\0' | xargs -0`
sidebar_whitelist `find ~/mail -mindepth 1 -type d -iname inbox -printf '"%p"\0' | xargs -0`
# vim: syntax=neomuttrc # vim: syntax=neomuttrc

14
config/neomutt/work.rc Normal file
View file

@ -0,0 +1,14 @@
# Work config
set mbox_type = Maildir
set folder = "~/work/mail"
set my_msmtp_conf = "-C $folder/msmtprc" # Leave empty for default
set my_mbsync_conf = "-c $folder/mbsyncrc" # Leave empty for default
source common.rc
# Override sidebar_new_mail_only
# Move back to sidebar.rc once the issue is resolved
# https://github.com/neomutt/neomutt/issues/2208
sidebar_whitelist `find ~/work/mail -mindepth 1 -maxdepth 1 -type d ! -name cur ! -name tmp ! -name new ! -name .notmuch -printf '"%p"\0' | xargs -0`
sidebar_whitelist `find ~/work/mail -mindepth 1 -type d -iname inbox -printf '"%p"\0' | xargs -0`
# vim: syntax=neomuttrc