#
# Author: Kevin McCarthy
#         http://www.8t8.us/
#


###########################################
# Index settings
#

unset arrow_cursor         # highlight current line instead of using arrow
unset collapse_unread      # don't collapse threads with unread mails
set   uncollapse_jump      # jump to unread message when uncollapse
unset confirmappend        # don't confirm saving/copying messages
set   confirmcreate        # but confirm if saving creates a new mailbox
set   delete               # don't ask me to delete messages - just do it!
set   help                 # show help on first line of display
unset mark_old             # don't mark unread messages as Old
set   narrow_tree          # narrow threading trees
unset sort_re              # Use strict threading
set   strict_threads       # ^^^
unset mail_check_recent    # keep telling me a mailbox has new mail even if I
                           # visit it (added in 1.5.21)
set   move=no              # don't move messages to mbox and don't ask
set   print=ask-no         # double check when hitting 'p'
set   quit=ask-yes         # double check 'q' too
set   sleep_time=0         # Don't pause between mailbox changes
set   sort=threads
set   sort_aux=last-date-received      # secondary sorting (for threads)
# set sort_aux=date-sent

# set index_format="%4C %Z %{%b %d} %-15.15L %?M?>#%03M<&(%4l)? %s"
# set index_format="%4C %Z %{%b %d} %-15.15L (%?l?%4l&%4c?) %s"
# set index_format="%4C %Z  %[%a %b %d %Y %X]  %-15.15L (%?l?%4l&%4c?) %s"
# set index_format="%4C %Z  %[%a %x %X]  %-15.15L (%?l?%4l&%4c?) %s"
# set index_format="%4C %[%a %x %X]  %-15.15L %Z (%?l?%4l&%4c?) %s"
set index_format="%4C %[%a %x %X]  %-15.15F %Z (%4c) %s"


###########################################
# Message composition settings
#

set   abort_nosubject=ask-yes  # abort if no subject
set   abort_unmodified=ask-yes # abort if message wasn't edited
unset askbcc                   # don't prompt for bcc's
unset askcc                    # don't prompt for cc's
set   attribution="%n wrote:"
# set   autoedit               # compose emails without the prompts
set   edit_headers             # display the headers when I'm editing a message
set   editor="vim -X '+/^$' '++'"
set   fast_reply               # don't prompt for stuff when replying
set   followup_to              # add Mail-Followup-To header for lists
set   ispell="aspell -e -c"
unset metoo                    # remove my email from list of recipients
set   mime_forward=ask-no      # forward messages as rfc822 attachments
                               #   - useful for forwarding attachments too
set   postponed="=postponed"
set   reply_to=ask-yes         # ask to use from or reply-to
set   recall=no                # Don't ask about postponed when composing
                               # just use 'R' to recall postponed messages
set   realname="Kevin J. McCarthy"  # To keep consistency from machine to machine
                                    # otherwise will look in /etc/passwd


###########################################
# Message delivery settings
#

set   bounce_delivered     # unset: remove Delivered-To: when bouncing?
set   copy                 # save copies of sent messages


###########################################
# Pager settings
#

unset markers              # don't insert '+' character for wrapped lines
set   pager_stop           # don't go to next message at end of message
set   pager_context=1      # display one line on pgup/pgdown
set   pager_index_lines=8  # display 8 lines of the index while viewing messages

#
# Headers to display
#
ignore *
unignore From Message-ID Date User-Agent To Cc Bcc Subject
unignore Delivery-date
unignore x-mailer x-url
unignore X-Delivered-to Delivered-To
unignore x-spam-score authentication-results
unignore x-face
unignore openpgp

unhdr_order *
hdr_order date from to cc subject


###########################################
# Global settings
#

unset beep                 # don't beep on error
unset beep_new             # don't beep on new message
unset menu_scroll          # scroll menu a page on last line
unset wait_key             # don't prompt for a key after external commands

# These two settings control how new mail is checked for.
# See http://dev.mutt.org/trac/wiki/MuttFaq/Folder for more details.
#
# $mail_check controls the minimum amount of time to wait before
# scanning mail folders for new mail.  Keypresses or a $timeout event
# will ask for a new mail status update, but mutt will NOT actually scan
# the folders until at least $mail_check seconds has passed since the
# last scan.
#
# $timeout controls how long to wait for user input before timing out
# and updating the new mail status messages.  This will not trigger a
# folder scan unless $mail_check amount of time has passed since the
# last folder scan.
#
# Note that it is more useful if $mail_check < $timeout otherwise you
# may trigger a timeout but not actually scan folders for new mail.

set mail_check=10        # Default is 5 seconds
set timeout=60           # Default is 600 seconds

# set print_command="muttprint"
# set print_command="enscript -G2r"
set print_command="enscript -G"

# set query_command="/usr/local/scripts/mutt-ldap"
# set query_command="~/.mutt/bin/ldapsearch.sh '%s'"
# set query_command="abook --mutt-query '%s'"
set query_command="lbdbq '%s'"

# alias file
set alias_file=~/.mutt/aliases
source ~/.mutt/aliases


###########################################
# SSL settings
#

set   ssl_ca_certificates_file=/etc/ssl/certs/ca-certificates.crt
set   certificate_file=~/.mutt/certificates
set   ssl_force_tls        # make sure all connections are encrypted


###########################################
# MIME settings
#

#
# Says we prefer plain text to html in multiparts
#
alternative_order text/plain

#
# Says to consult mime.types for determining types of these attachments
#
mime_lookup application/octet-stream

#
# MIME autoviewing.  Requires appropriate .mailcap entry
# (with copiousoutput flag set)
#
auto_view text/html application/msword application/pdf
auto_view application/vnd.oasis.opendocument.text


###########################################
# Macros
#

# macro index ,a <save-message>=archive\n
# macro pager ,a <save-message>=archive\n

# ctrl-b
# macro index,pager \cb <pipe-message>urlview<enter>
macro index,pager \cb "<pipe-message>~/.mutt/bin/extract_url.pl<enter>" "extract urls"

# macro index,pager A "<pipe-message>abook --add-email<return>" "add the sender address to abook"
macro index,pager A "<pipe-message>lbdb-fetchaddr -a<return>" "add the sender address to lbdb"

# For notmuch-mutt
macro index ,ns \
"<enter-command>set my_old_pipe_decode=\$pipe_decode my_old_wait_key=\$wait_key nopipe_decode nowait_key<enter>\
<shell-escape>notmuch-mutt -r --prompt search<enter>\
<change-folder-readonly>`echo ${XDG_CACHE_HOME:-$HOME/.cache}/notmuch/mutt/results`<enter>\
<enter-command>set pipe_decode=\$my_old_pipe_decode wait_key=\$my_old_wait_key<enter>" \
      "notmuch: search mail"

macro index ,nt \
"<enter-command>set my_old_pipe_decode=\$pipe_decode my_old_wait_key=\$wait_key nopipe_decode nowait_key<enter>\
<pipe-message>notmuch-mutt -r thread<enter>\
<change-folder-readonly>`echo ${XDG_CACHE_HOME:-$HOME/.cache}/notmuch/mutt/results`<enter>\
<enter-command>set pipe_decode=\$my_old_pipe_decode wait_key=\$my_old_wait_key<enter>" \
      "notmuch: reconstruct thread"


###########################################
# msmtpq settings.
# I don't use this, but it looks interesting.
#

# set sendmail   = "$my_cfgdir/bin/msmtpQ"
# macro index "'q"   "<shell-escape>$my_cfgdir/bin/msmtpq -d  | less -r<enter>" "Show the local mail queuee"
# macro index "'f"   "<shell-escape>$my_cfgdir/bin/msmtpq -r 2>&1 | less -r<enter>" "Flush the local mail queue"


###########################################
# GPG
#

set pgp_autosign=no    # this is overridden in the local configs

# turn on agent support
set pgp_use_gpg_agent

# try using long key ids (after changing the keyid-format setting in gpg.conf)
set pgp_long_ids

ifdef postpone_encrypt set postpone_encrypt
ifdef postpone_encrypt_as set postpone_encrypt_as="0xB6B1CD9613699FB8"

# These are "standard settings" stolen from Debian's /etc/Muttrc.d/gpg.rc
set pgp_decode_command="gpg --status-fd=2 %?p?--passphrase-fd 0? --no-verbose --quiet --batch --output - %f"
set pgp_verify_command="gpg --status-fd=2 --no-verbose --quiet --batch --output - --verify %s %f"
set pgp_decrypt_command="gpg --status-fd=2 %?p?--passphrase-fd 0? --no-verbose --quiet --batch --output - %f"
set pgp_sign_command="gpg --no-verbose --batch --quiet --output - %?p?--passphrase-fd 0? --armor --detach-sign --textmode %?a?-u %a? %f"
set pgp_clearsign_command="gpg --no-verbose --batch --quiet --output - %?p?--passphrase-fd 0? --armor --textmode --clearsign %?a?-u %a? %f"
set pgp_encrypt_only_command="/usr/lib/mutt/pgpewrap gpg --batch --quiet --no-verbose --output - --encrypt --textmode --armor --always-trust -- -r %r -- %f"
set pgp_encrypt_sign_command="/usr/lib/mutt/pgpewrap gpg %?p?--passphrase-fd 0? --batch --quiet --no-verbose --textmode --output - --encrypt --sign %?a?-u %a? --armor --always-trust -- -r %r -- %f"
set pgp_import_command="gpg --no-verbose --import %f"
set pgp_export_command="gpg --no-verbose --export --armor %r"
set pgp_verify_key_command="gpg --verbose --batch --fingerprint --check-sigs %r"
set pgp_list_pubring_command="gpg --no-verbose --batch --quiet --with-colons --list-keys %r"
set pgp_list_secring_command="gpg --no-verbose --batch --quiet --with-colons --list-secret-keys %r"
set pgp_good_sign="^\\[GNUPG:\\] GOODSIG"


###########################################
# Headers
#

# Documented at http://josefsson.org/openpgp-header/
my_hdr OpenPGP: id=B6B1CD9613699FB8\; url=http://www.8t8.us/configs/13699FB8.asc.pubkey\; preference=signencrypt

# X-Face - todo
# https://en.wikipedia.org/wiki/X-Face
# http://dev.mutt.org/trac/wiki/MuttGuide/XFace
# http://www.emacswiki.org/emacs/GnusXFace
# my_hdr X-Face:


###########################################
# Colors
#

source ~/.mutt/colors.kjm


###########################################
# Tips
#

# Useful keys to remember:
#
# INDEX:
# &    - link broken threads
#        first tag the reply, then moving to the parent message and hit '&'
# #    - break thread
#        turns the subthread starting from the current message into a whole
#        different thread.
# =    - first message
# *    - last message
#
# PAGER:
# ^  jump to top of message
# -  previous-page


###########################################
# Local configs
#

# source ~/.mutt/muttrc.local
source ~/.mutt/muttrc.local.$LOCAL_CONFIG