### vim:ft=muttrc
###
### mutt configuration
###
### Frank Terbeck <ft@bewatermyfriend.org>
### Last-Modified: Sun Sep  7 00:43:58 2008
###
####################################################

### desciption {{{
###
### I am using fdm <http://fdm.sf.net> to fetch my mails from various
### locations and sort them into local mailboxes (maildir format
### <http://cr.yp.to/proto/maildir.html>). This configuration is not
### limited to this setup, but it makes no effort to work with
### anything else either.
###
### Furthermore, this configuration does not do much magic. It is
### just mutt, tuned to fit my preference. The options I am setting
### are described below. Everything else is in the mutt manual.
###
### Here is a list of non-standard keybindings:
#{{{
###   + Function keys:
###       - F1  URLview
###       - F2  killfile author
###       - F3  ignore subthread, starting at current message
###       - F4  ignore whole thread, parse References for this.
###       - F5  prompt for MsgID to use as thread-to-ignore
###       - F6  edit scorefile
###       - F7  reread scorefile
###       - F8  fetch mails manually
###       - F9  reread muttrc
###       - F10 open manual.txt in pager
###
### The actions of keys F2..F5 rely on perl scripts available in:
### <http://ft.bewatermyfriend.org/comp/data/mutt/mutt-dotfiles.tar.bz2>
### The actual ignoring of mails selected with these scripts is done
### by fdm <http://ft.bewatermyfriend.org/comp/data/fdm/index.php>;
### This is doable with procmail and possibly maildrop as well.
###
###   + META-key combinations:
###       - M-1 toggle t-prot ON/OFF
###       - M-2 toggle a few semi-useful headers ON/OFF
###       - M-3 open archives folder
###       - M-4 open /var/mail/$USER
###       - M-5 =Sent
###       - M-6 =Drafts
###       - M-7 =Inbox
###       - M-8 =System
###       - M-9 =Spam-unsure
###       - M-0 =Spam
###       - M-b search in message bodies
###       - M-r toggle rot13 "decoding" ON/OFF
###       - M-y toggle quoted parts of mails ON/OFF
###       - M-x skip beyond quoted part of a mail
###
### t-prot <http://www.escape.de/~tolot/mutt/> used by the M-1 binding
### is a great script that filters those braindead top-posting mails
### in pager view, when used as a display filter.
###
###   + Other keys:
###       - 'J'     train message as spam
###       - 'H'     train message as ham
###       - ^O      filter out messages by myself
###       - <left>  open list of mailboxes
###       - <right> (un-)collapse thread
###       - '.'     (un-)collapse all threads
###       - '-'     show list of mailboxes with new mail
###       - 'S'     sync mailbox
###       - j/k     similar to <up>/<down>, but let's you move
###                 on mails that are markes for deletion
###
#}}} The rest of the keybindings are pretty much the default of mutt.
###
### External files sourced from this configuration:
#{{{
###   The names of these files are configured in $my_ variables:
###
###     + $my_aliases           list of mutt aliases
###     + $my_scorefile         mutt's scoring configuration
###     + $my_mailboxes_list    see mailboxes command in mutt's manual
###     + $my_subscription_list see subscribe command in mutt's manual.
###
### The reason I moved those parts of the configuration to external
### files, is that their content might change often and I do not want
### to touch the config for every little change in mailinglist
### subscriptions, etc.
#}}}
###
### I used to use mutt to move messages of certain age to archive
### folders. I've dropped that for quite time now. fdm does the job
### better and simpler.
###
### }}}
### user defined variables {{{
### this feature requires mutt >=1.5.14

    set my_main_address="Frank Terbeck <ft@bewatermyfriend.org>"
   #set my_main_address="Frank Terbeck <frank.terbeck@dialup.fh-aachen.de>"
    set my_name_expr="Frank.Terbeck"

    set my_user="hawk"
    set my_home="${HOME}"
    set my_m_hh="lines x-mailer x-seq user-agent Content-Type In-Reply-To message-id \
                 references X-JunkFilter"

    set my_sig              = "$my_home/etc/mailnews/signature.static.tech"
    set my_vimcfg           = "$my_home/etc/mailnews/mailnews.vim"
    set my_cfgdir           = "$my_home/etc/mutt"
    set my_include          = "$my_cfgdir/include"
    set my_scriptsdir       = "$my_cfgdir/scripts"
    set my_muttrc           = "$my_cfgdir/muttrc"
    set my_aliases          = "$my_include/alias.rc"
    set my_scorefile        = "$my_include/scorefile.rc"
    set my_mailboxes_list   = "$my_include/mailboxes.rc"
    set my_subscription_list= "$my_include/subscriptions.rc"
    set my_manual           = "/usr/share/doc/mutt/manual.txt.gz"
    set my_getmail_sh       = "$my_home/bin/getmail.sh"
    set my_rot13            = "/usr/games/rot13"
    set my_tprot            = "/usr/bin/t-prot \
                                -cemkltwS --ftr-ad --bigq=25,10 --pgp-move \
                                --pgp-short -Mmutt --max-lines=600 \
                                -L$my_home/etc/t-prot/footers -A$my_home/etc/t-prot/ads"

    set my_folder     = "Mail"
    set my_inbox      = "=Inbox"
    set my_drafts     = "=Drafts"
    set my_sent       = "=Sent"
    set my_spam       = "=Spam"
    set my_spam_unsure= "=Spam-unsure"
    set my_system     = "=System"

### }}}
### basic setup {{{

###
### settings handled in hooks:
###   $from, $sort, $sort_aux, $record
###
    set use_from="yes"
    set use_domain="no"
    alternates "ft@grml\.org" "frank\.terbeck\@dialup\.fh-aachen\.de"
    unset mbox                                        ### do not move read messages by default
    set move="no"
    set mbox_type="mbox"                              ### use 'mbox' to _create_ mailboxes
    set folder="$my_home/$my_folder"                  ### default mailbox location
    set spoolfile="$my_inbox"                         ### default inbox
    set postponed="$my_drafts"                        ### postponed mailboxes get here
    set sendmail="/usr/sbin/sendmail -oem -oi"        ### how to send mails
    set tmpdir="$my_home/tmp/"                        ### directory for temporary files
    set header_cache="$my_home/etc/cache/mutt"        ### location of the header cache

### }}}
### mutt settings {{{

    set timeout=10                                    ### check mailboxes for new mail all $timeout seconds
    set mail_check=5
    set query_command="abook --mutt-query '%s'"       ### use abook to find addresses
    set editor="vim +':source $my_vimcfg' %s"         ### use vim with additional configuration
    set edit_headers="yes"                            ### make header editable in $editor
    set include="yes"                                 ### include the message, that we reply to by default.
    set attribution="%n <%a>:"                        ### <http://www.guckes.net/faq/attribution.html>
    set indent_string="> "                            ### how to mark quotes?
    set to_chars='b mcol'                             ### chars for %T in $index_format. see manual.
    set autoedit='no'                                 ### when set, skip 1st send-menu
    set fast_reply='yes'                              ### I prefer this over $autoedit
    set pager_stop='yes'                              ### do not move to the next message, if end of message is reached
    set signature="$my_sig"                           ### include a signature
    set check_new="yes"                               ### check current mailbox for new mails
    set mark_old='no'                                 ### I don't like the 'O' flag feature
    set collapse_unread=yes
    set strict_threads="yes"
    set sort_re="no"
    set write_bcc="no"
    set tilde='yes'
    set history='10'
    set quit='ask-yes'
    set menu_move_off='no'
    set suspend='no'
    set charset="iso-8859-15"                         ### setup charsets
    set send_charset="iso-8859-1:iso-8859-15:koi8-r:utf-8"
    set locale=de_DE@euro
  unset wait_key
    set smart_wrap
   #set wrapmargin=20
  unset markers
### don't decode when piping messages to external programs
    set pipe_decode=no
    set display_filter='display_filter.sh'
    set status_on_top="yes"
    set pager_index_lines=9
    set smileys="(>From )|(:[-^]?[][)(><}{|/DP])"
    set sort_browser=unsorted

### autoviewing html mails
    auto_view           text/html
    alternative_order   text/plain text/html

### ignoring vcards by adding this to a mailcap file:
###     text/x-vcard; true; copiousoutput
### You still see a vcard attached to the mail, but you don't
### get bothered by its contents anymore.
    auto_view           text/x-vcard

### }}}
### keyboard setup (macros + bindings) {{{

    bind index        -             buffy-list
    bind index        <right>       collapse-thread
    bind index        .             collapse-all
    bind index,pager  <down>        next-undeleted
    bind index,pager  <up>          previous-undeleted
    bind index,pager  j             next-entry
    bind index,pager  k             previous-entry
    bind pager        \ey           toggle-quoted
    bind pager        \ex           skip-quoted
    bind pager        <backspace>   previous-line
    bind pager        \ch           previous-line
    bind pager        \c?           previous-line
    bind editor       <delete>      delete-char
    bind editor       <tab>         complete-query
    bind editor       \ea           complete
    bind index        S             sync-mailbox
    bind browser      q             exit

### shortcut to seach mail bodies
    macro index \eb '/~b ' 'search in message bodies'

### open mailbox folder
    macro index   <left>  "<change-folder>?<toggle-mailboxes>"        "show incoming mailboxes list"

### open folders
    macro index,pager \e0 "<change-folder>$my_spam<enter>"            "open Spam folder"
    macro index,pager \e9 "<change-folder>$my_spam_unsure<enter>"     "open Spam-unsure folder"
    macro index,pager \e8 "<change-folder>$my_system<enter>"          "open System folder"
    macro index,pager \e7 "<change-folder>$my_inbox<enter>"           "open Inbox folder"
    macro index,pager \e6 "<change-folder>$my_drafts<enter>"          "open Drafts folder"
    macro index,pager \e5 "<change-folder>$my_sent<enter>"            "open Sent folder"
    macro index,pager \e4 "<change-folder>/var/mail/$my_user<enter>"  "open mailspool folder"
    macro index,pager \e3 "<change-folder>?\
       <change-dir><kill-line>$my_home/$my_folder/archive<enter>"     "open archives folder"

    # (J)unk aka. spam
    macro index,pager J "<pipe-message>fdm -atrain-spam f<enter>d"    'train message as spam'
    # (H)am
    macro index,pager H "<pipe-message>fdm -atrain-good f<enter>d"    'train message as ham'

### urlview
    macro index,pager <f1> "<pipe-message>urlview<enter>"       'call urlview to extract URLs out of a message'

### one-key-plonk!
    macro index,pager <f2> "<pipe-message>\
      formail -xFrom:                     \
      | sed -e 's,.*<\\(.*\\)>,\\1,'      \
      | $my_scriptsdir/plonk.pl<enter>"                         'PLONK'

### one-key-thread-ignore
    macro index,pager <f3> "<pipe-message>  \
      formail -xMessage-id:                 \
      | sed -e 's,.*<\\(.*\\)>,\\1,'        \
      | $my_scriptsdir/tign.pl<enter>"                          'Thread-ignore'

### this ignores the the whole thread, that this message is part of (if References: isn't shortened)
    macro index,pager <f4> "<pipe-message>                   \
      formail -cxReferences:                                 \
      | sed -e 's/\\W\\(<[-_\\$\\@a-zA-Z0-9\\.]*>\\).*/\\1/' \
      | $my_scriptsdir/tign.pl<enter>"                          'Ignore whole thread'

### ignore thread by Message-Id: (explicitly name the ID)
    macro index,pager <f5> "<shell-escape>  \
      echo -n \"what thread to ignore? \" ; \
      read e ;                              \
      echo \$e                              \
      | $my_scriptsdir/tign.pl<enter>"                          'Ignore old thread'

### edit scorefile
    macro index,pager <f6> "<shell-escape>\
      vim $my_scorefile<enter>"                                 'edit scorefile'

### reread scorefile
    macro generic,index,pager,browser <f7> "<enter-command>\
      source $my_scorefile<enter>"                              'reread scorefile.rc'

### exec getmail by hand
    macro generic,index,pager,browser <f8> "<shell-escape>\
      $my_getmail_sh log mutt<enter>"                           'fetch new mails using $my_getmail_sh'

### reread scorefile
    macro generic,index,pager,browser <f9> "<enter-command>\
      source $my_muttrc<enter>"                                 'reread configuration file'

### HELP!
    macro generic,index,pager,browser <f10> "<shell-escape>\
      zcat $my_manual | less -Mr\n"                             'Show Mutt documentation'

### t-prot is a display filter;
    set my_tprotmsg="Toggle TOFU protection"

    macro pager ,@tpoff "<enter-command>\
      unset display_filter;             \
      macro pager \\e1 ,@tpon  '$my_tprotmsg'<enter><exit><display-message>"

    macro pager ,@tpon "<enter-command>\
      set display_filter='$my_tprot' ; \
      macro pager \\e1 ,@tpoff '$my_tprotmsg'<enter><exit><display-message>"

    macro pager \e1 ,@tpoff '$my_tprotmsg'

### show more/less headers than default
    set my_m_hhmsg="Toggle more/less headers to be displayed"

    macro pager ,@headm "<enter-command>\
      unignore $my_m_hh ;               \
      macro pager \\e2 ,@headl '$my_m_hhmsg'<enter><exit><display-message>"

    macro pager ,@headl "<enter-command>\
      ignore $my_m_hh ;                 \
      macro pager \\e2 ,@headm '$my_m_hhmsg'<enter><exit><display-message>"

    macro pager \e2 ,@headm '$my_m_hhmsg'

### rot13 decode toggle
    set my_rot13msg="Toggle ROT13 decoding"

    macro pager ,@r13on  "<enter-command> \
      set display_filter=$my_rot13 ;      \
      macro pager \\er ,@r13off '$my_rot13msg'<enter><exit><display-message>"

    macro pager ,@r13off "<enter-command> \
      unset display_filter ;              \
      macro pager \\er ,@r13on  '$my_rot13msg'<enter><exit><display-message>"

    macro pager \er ,@r13on '$my_rot13msg'

### filter out my messages
    set my_fown_msg="Toggle display messages by myself"

    macro index ,@mymoff "<limit>!~f $my_name_expr<enter><enter-command>\
      macro index \cO ,@mymon '$my_fown_msg'<enter>"

    macro index ,@mymon "<limit>all<enter><enter-command> \
      macro index \cO ,@mymoff '$my_fown_msg'<enter>"

    macro index \cO ,@mymoff '$my_fown_msg'

### default binding for "m" in index,pager,
### because this might be changed via folder-hooks

### }}}
### header weeding {{{

### don't want these for sure
    ignore "from "        received    content-        mime-version    status
    ignore sender         references  return-path     resent-         list-
    ignore mail-followup  priority    old-return-path x-              Original-rec
    ignore envelop        importance  precedence      thread-         nntp distri
    ignore old-           face        complaints      injection       mailing-list
    ignore cancel         path        newsgroup       mail-copies-to  domainkey-
    ignore delivered-to   comment     keywords        errors-to
  unignore date

  unhdr_order *
    hdr_order From:         Reply-To:   To:       Cc:     Subject:    Date:             \
              Content-type: User-Agent: X-Mailer: X-Seq:  message-id: Delivery-date:    \
              In-Reply-To:  References:

### }}}
### colorization {{{

    color indicator       white         red
    color status          brightwhite   blue
    color error           white         red
    color hdrdefault      green         default
    color header          brightgreen   default     ^From:
    color header          cyan          default     ^To:
    color header          brightgreen   default     ^Reply-To:
    color header          cyan          default     ^Cc:
    color header          brightcyan    default     ^Subject:
    color header          yellow        default     ^Date:
    color header          yellow        default     ^Delivery-date:
    color header          yellow        default     ^X-Mailer:
    color header          yellow        default     ^User-Agent:
    color normal          white         default
    color body            brightred     default     [\-\.+_a-zA-Z0-9]+@[\-\.a-zA-Z0-9]+
    color body            cyan          default     (https?|ftp)://[\&\+\-\.\,/%=~_:?\#\;@a-zA-Z0-9]+
    color body            cyan          default     ^\\[sn[ia]p\\]
    color quoted          green         default
    color quoted1         yellow        default
    color quoted2         cyan          default
    color quoted3         red           default
    color quoted4         green         default
    color quoted5         yellow        default
    color quoted6         cyan          default
    color quoted7         red           default
    color attachment      brightyellow  default
    color signature       brightred     default
    color tree            red           default
    color tilde           blue          default
    color bold            yellow        default
    color underline       brightred     default
    color body            yellow        default     '(^| )\*[a-zA-Z0-9_-]+\*'
    color body            brightred     default     '(^| )_[a-zA-Z0-9_-]+_'
    color markers         brightred     default
    color search          yellow        blue
    color message         cyan          default
    color index           cyan          default     ~R
    color index           white         default     ~O
    color index           yellow        default     ~N
    color index           black         default     '~n 1-9'      ### badly readable
    color index           brightyellow  default     '~n 520-599'  ### friends
    color index           green         default     '~n 500-519'  ### family
    color index           red           default     '~n 600-899'  ### vips
    color index           magenta       default     '~n 150-199'  ### good
    color index           red           default     '~n 200-299'  ### excellent
    color index           black         yellow      ~F            ### flagged
    color body            brightmagenta default     "^\\[---.*"   ### t-prot
    color body            green         default     "^#v[-+]"     ### t-prot

### }}}
### folder hooks {{{

### record postings to specific mailboxes
    fcc-hook lists.debian.org$ =debian-outbox

### default hook
    folder-hook . "set sort=threads"
    folder-hook . "set sort_aux=date"
    folder-hook . "set from='$my_main_address'"
   #folder-hook . "push '<collapse-all>'"
    folder-hook . "set record='$my_sent'"
    folder-hook . "macro index,pager m <mail>"
    folder-hook . "color index brightgreen default '~f $my_name_expr'"
    folder-hook . \
      "set index_format='%5C. [%Z/%4N/%3M] %-65.65s [ %-25.25F ]               -%{%d %b}-        (%7l)'"

    folder-hook . \
      "set status_format='--[[ %f ]]--[[ New:%n Old:%o Del:%d Post:%p ]]--(%s/%S)--[%V]--%>-(%P)---'"

    folder-hook . \
      "set pager_format='--[[ %C/%m ]]--( %-30.30n )--\> %s \<----%>-(%P)---'"

    folder-hook . \
      "set alias_format='[%3n] -%t- [ %65.65r ] alias:%-10a  | flags:%f'"

    folder-hook . \
      "set date_format='!%a, %B %d, %Y at %H:%M:%S'"

    folder-hook . "set maildir_header_cache_verify=no"

### common settings for mailinglists
    folder-hook =(.*-.*|schopppe|grml|fvwm) \
      "set index_format='%5C. [%Z/%4N/%3M] %-65.65s [ %-25.25n ]               -%{%d %b}-        (%7l)'"

### grml lists
    folder-hook =grml.* "set from='Frank Terbeck <ft@grml.org>'"

### schopppe
    folder-hook =schopppe 'macro index,pager m <mail>mail@schopppe.de<enter>'

### Sent-Folder
    folder-hook =(Sent|debian-outbox) "uncolor index '~f $my_name_expr'"
    folder-hook =(Sent|debian-outbox) "set sort=date"
    folder-hook =(Sent|debian-outbox) "set sort_aux=date"
    folder-hook =(Sent|debian-outbox) "set delete=ask-yes"
    folder-hook =(Sent|debian-outbox) \
      "set index_format='%5C. [%Z/%4N/%3M] %-65.65s [ %-25.25F ]               -%{%d %b}-        (%7l)'"

### main mailbox
    folder-hook =Inbox "set sort=threads"
    folder-hook =Inbox "set sort_aux=date"
    folder-hook =Inbox "set delete=ask-yes"
    folder-hook =Inbox "set record='=Inbox'"
    folder-hook =Inbox "push '<collapse-all>'"
    folder-hook =Inbox "color index white black '~f $my_name_expr'"
    folder-hook =Inbox "set maildir_header_cache_verify=yes"

### }}}
### gnu privacy guard setup {{{
##########################################################################################
###
### %p    The empty string when no passphrase is needed,
###       the string "PGPPASSFD=0" if one is needed.
###
###       This is mostly used in conditional % sequences.
###
### %f    Most PGP commands operate on a single file or a file
###       containing a message.  %f expands to this file's name.
###
### %s    When verifying signatures, there is another temporary file
###       containing the detached signature.  %s expands to this
###       file's name.
###
### %a    In "signing" contexts, this expands to the value of the
###       configuration variable $pgp_sign_as.  You probably need to
###       use this within a conditional % sequence.
###
### %r    In many contexts, mutt passes key IDs to pgp.  %r expands to
###       a list of key IDs.
###
### Note that we explicitly set the comment armor header since GnuPG, when used
### in some localiaztion environments, generates 8bit data in that header, thereby
### breaking PGP/MIME.
##########################################################################################

    #set pgp_decode_command="/usr/bin/gpg \
    #  --status-fd=2 %?p?--passphrase-fd 0? --no-verbose --quiet --batch --output - %f"
    set pgp_decode_command="/usr/bin/gpg \
      --status-fd=2 --no-verbose --quiet --batch --output - %f"
    set pgp_verify_command="/usr/bin/gpg \
      --status-fd=2 --no-verbose --quiet --batch --output - --verify %s %f"
    #set pgp_decrypt_command="/usr/bin/gpg \
    #  --status-fd=2 --passphrase-fd 0 --no-verbose --quiet --batch --output - %f"
    set pgp_decrypt_command="/usr/bin/gpg \
      --status-fd=2 --no-verbose --quiet --batch --output - %f"
    #set pgp_sign_command="/usr/bin/gpg \
    #  --no-verbose --batch --quiet \
    #  --output - --passphrase-fd 0 --armor --detach-sign --textmode %?a?-u %a? %f"
    set pgp_sign_command="/usr/bin/gpg \
      --no-verbose --batch --quiet \
      --output - --armor --detach-sign --textmode %?a?-u %a? %f"
    #set pgp_clearsign_command="/usr/bin/gpg \
    #  --no-verbose --batch --quiet \
    #  --output - --passphrase-fd 0 --armor --textmode --clearsign %?a?-u %a? %f"
    set pgp_clearsign_command="/usr/bin/gpg \
      --no-verbose --batch --quiet \
      --output - --armor --textmode --clearsign %?a?-u %a? %f"
    set pgp_encrypt_only_command="/usr/lib/mutt/pgpewrap /usr/bin/gpg \
      --batch --quiet --no-verbose \
      --output - --encrypt --textmode --armor --always-trust -- -r %r -- %f"
    #set pgp_encrypt_sign_command="/usr/lib/mutt/pgpewrap /usr/bin/gpg \
    #  --passphrase-fd 0 --batch --quiet --no-verbose --textmode \
    #  --output - --encrypt --sign %?a?-u %a? --armor --always-trust -- -r %r -- %f"
    set pgp_encrypt_sign_command="/usr/lib/mutt/pgpewrap /usr/bin/gpg \
      --batch --quiet --no-verbose --textmode \
      --output - --encrypt --sign %?a?-u %a? --armor --always-trust -- -r %r -- %f"
    set pgp_import_command="/usr/bin/gpg --no-verbose --import -v %f"
    set pgp_export_command="/usr/bin/gpg --no-verbose --export --armor %r"
    set pgp_verify_key_command="/usr/bin/gpg --verbose --batch --fingerprint --check-sigs %r"
    set pgp_list_pubring_command="/usr/bin/gpg --no-verbose --batch --quiet --with-colons --list-keys %r"
    set pgp_list_secring_command="/usr/bin/gpg --no-verbose --batch --quiet --with-colons --list-secret-keys %r"
    set pgp_getkeys_command=""
    set pgp_good_sign="^gpg: Good signature from"
   #set pgp_good_sign="`gettext -d gnupg -s 'Good signature from "' | tr -d '"'`"
   #set pgp_good_sign="^\\[GNUPG:\\] GOODSIG"
    set pgp_timeout=18000
    set pgp_use_gpg_agent='yes'
    set crypt_replysignencrypted='yes'
    set crypt_replyencrypt='yes'
    set fcc_clear='yes'

### }}}
### sourcing external files {{{

    set alias_file="$my_aliases"
    source         "$my_aliases"
    source         "$my_scorefile"
    source         "$my_mailboxes_list"
    source         "$my_subscription_list"

### }}}