Mutt configuration

From wikinotes

TODO:

split this page into multiple pages

Documentation

http://www.mutt.org/doc/manual/ Official Mutt Manual
http://www.mutt.org/doc/manual/#functions Complete Function List (for macros/keybindings)
http://www.mutt.org/doc/manual/#bind Key Names
https://wiki.archlinux.org/index.php/Mutt Arch Wiki Mutt
http://www.mutt.org/doc/manual/manual-4.html index 4.2 has allof mutt's message matching shorthand (~N, ~V, ...)

Locations

~/.mutt/muttrc config
~/.mutt/mailboxes sidebar mailboxes

Introspection

:set ?<option_name>         # print value of config option
:set <option_name>=<value>  # override value of config option

Simple Example

A simple, self-contained gmail over imap config.

~/.mutt/muttrc


# ~/.mutt/muttrc

# ======
# config
# ======
set sort = threads
set text_flowed = yes
set sort_browser = "reverse-date"
set sort_aux = "last-date-received"
set arrow_cursor
set nohelp
set status_on_top
set sleep_time = 0
set realname = "Will Pittman"
set mail_check = 60
set use_from = yes
set envelope_from = yes
set mailcap_path = "~/.mutt/mailcap"
auto_view text/html image/*

# optional
source ~/.mutt/muttrc-bindings
source ~/.mutt/muttrc-colours

# ============
# email config
# ============
set folder=imaps://you@gmail.com@imap.gmail.com:993/
set from = "you@gmail.com"
set sendmail =
set spoolfile = "+INBOX"
set ssl_force_tls = yes

set smtp_url = "smtps:/you@gmail.com@smtp.gmail.com:465/"
set smtp_pass = "`<cli-cmd-for-password>`"
set imap_user = "you@gmail.com"
set imap_pass = "`<cli-cmd-for-password>`"

mailboxes "imaps://you@gmail.com@imap.gmail.com:993/"


~/.mutt/muttrc-bindings


# Editor (line-editor)
bind  editor <Esc>h backward-char
bind  editor <Esc>l forward-char
bind  editor <Esc>w forward-word
bind  editor <Esc>e backward-word
bind  editor <Esc>d kill-eow		# kill until end-of-line 
bind  editor <Esc>D kill-eow		# kill until end-of-line 
bind  editor <Esc>H bol     		# jump to beginning of line
bind  editor <Esc>L eol     		# jump to beginning of line
bind  editor <Esc>x delete-char

# Index (inbox)
bind  index J	 next-thread
bind  index K	 previous-thread
bind  index gg	 first-entry
bind  index G	 last-entry
bind  index R	 group-reply
bind  index zc   collapse-thread
bind  index zm   collapse-all
bind  index zO   collapse-all
macro index za   '<Esc>v'
macro index zo   '<Esc>v'
bind  index \cu  previous-page
bind  index \cd  next-page 
macro index,pager \co  'v;/text/html<Enter>;m;q'
bind index \cr imap-fetch-mail

# Pager (email)
bind pager k	previous-line
bind pager j	next-line
bind pager gg	top
bind pager G	bottom
bind pager R	group-reply
bind pager \cy previous-page
bind pager \cu previous-page
bind pager \cd next-page
bind pager \ce next-page

# Tab Completion of Addressbook names
bind  editor <Tab> complete-query
bind  editor ^T    complete

# Attachments
# force-use mutt mailcap when pressing enter, ignoring system prefs
bind attach <return> view-mailcap


~/.mutt/muttrc-colours


# vim: ft=muttrc
# =======
# General
# =======
color normal         color252       color236
color indicator      color235       color187
color status         color143       color237
color tree           color208       color236 
color signature      color102       color236 
color message        color252       color236 
color attachment     color117       color236 
color error          color30        color236 
color tilde          color130       color235 
color search         color100       color231 #
color markers        color138       color231 #


# ================================
# Message Contents (pager, quotes)
# ================================
color quoted        color107     color236 #
color quoted1       color66      color236 #
color quoted2       color32      color236 #
color quoted3       color30      color236 #
color quoted4       color99      color236 #
color quoted5       color36      color236 #
color quoted6       color114     color236 #
color quoted7       color109     color236 #
color quoted8       color41      color236 #
color quoted9       color138     color236 #


# ====================
# Message List (index)
# ====================
# Normal  (blue)
color index color068 color236  ~A            # All other Messages
color index color75  color236  "~v!~(~N|~U)" # Collapsed Threads
color index color12  color236  ~O            # Old messages

# New     (green)
color index color71  color236  "(~N|~U)"     # (green) New/Unread Mail
color index color112 color236  "~v~(~N|~U)"  # (bright green) Collapsed Threads with New/Unread

# Special (other)
color index             color202       color236  ~F             # Flagged
color index             color252       color22   ~T             # Tagged
color index             color240       color236  ~D             # Deleted


# ==============
# Message Header
# ==============
color header color106 color236 "^from:"
color header color106 color236 "^to:"
color header color106 color236 "^cc:"
color header color106 color236 "^date:"
color header yellow color236 "^newsgroups:"
color header yellow color236 "^reply-to:"
color header color112 color236 "^subject:"
color header red color236 "^x-spam-rule:"
color header color106 color236 "^x-mailer:"
color header yellow color236 "^message-id:"
color header yellow color236 "^Organization:"
color header yellow color236 "^Organisation:"
color header yellow color236 "^User-Agent:"
color header yellow color236 "^message-id: .*pine"
color header yellow color236 "^X-Fnord:"
color header yellow color236 "^X-WebTV-Stationery:"

color header red color236 "^x-spam-rule:"
color header color106 color236 "^x-mailer:"
color header yellow color236 "^message-id:"
color header yellow color236 "^Organization:"
color header yellow color236 "^Organisation:"
color header yellow color236 "^User-Agent:"
color header yellow color236 "^message-id: .*pine"
color header yellow color236 "^X-Fnord:"
color header yellow color236 "^X-WebTV-Stationery:"
color header yellow color236 "^X-Message-Flag:"
color header yellow color236 "^X-Spam-Status:"
color header yellow color236 "^X-SpamProbe:"
color header red color236 "^X-SpamProbe: SPAM"

~/.mutt/mailcap


application/pdf; /usr/bin/evince %s;
application/vnd.openxmlformats-officedocument.wordprocessingml.document; pandoc -f docx; needsterminal
text/html; qutebrowser '%s'; needsterminal; nametemplate=%s.html
text/html; w3m -o ext_image_viewer=FALSE auto_image=TRUE -I %{charset} -T text/html; copiousoutput;
#image/*; /usr/bin/feh -. %s;
#image/*; img2txt -W 70 %s; copiousoutput


Accounts

Receiving Emails

mutt offlineimap sync emails between maildir and imap
mutt imap read emails from imap server

Sending Emails

mutt smtp builtin
mutt msmtp external

Sidebar

mutt sidebar sidebar with list of accounts/folders

Contacts

mutt khard carddav contacts
mutt abook local-only contacts

Calendars

mutt khal caldav integration

Attachments/Media

The programs used to open attachments are determined by your ~/.mutt/mailcap.
If the program renders text, you can set it to auto_view and the attachment preview will be rendered in the pager.

You can also define a different program for auto_view and opening from the attachment list.
The auto_view command will use the mailcap entry that ends in copiousoutput.

# ~/.mutt/muttrc

auto_view text/html image/*
# ~/.mutt/mailcap

image/*; feh -. %s;                       # open from attachments view ('v' key)
image/*; img2txt -W 70 %s; copiousoutput  # in-pager preview (email body)

TODO:

The viu program is very good at rendering images in a terminal,
but does not render properly within w3m or mutt's builtin pager.

You could use set pager='less -Ri', but it removes the useful colourization of headers/separators.
I'm working on it.

Macros

Basics

Macros let you bind a sequence of keypresses (or optionally commands) to a keybinding.
Mutts functions can be invoked, and are defined between angle brackets (ex: <pipe-entry>).

Syntax:

macro <menu>[,<menu>...] <keybinding> <command> <description>

Menus:

index       # open-screen, displays emails
pager       # diplaying single email
browser     # displays files on filesystem, imap server, etc
sidebar     # 
help        # 
compose     # attachment-view when composing an email
alias       #
attach      # attachment list ('v')

Examples

Simple Examples

macro  pager  \cb "<pipe-entry>'urlview'<enter>" \
    "Follow links with urlview"

macro index,pager <Esc>r "!offlineimap -q -o\n " \
    "Sync all offlineimap accounts"


You can also define macros that consist of a sequence of keypresses.
The following example:

  • s saves a message
  • ? shows mailbox list
  • c changes folder (account)
  • <backspace> removes any text that has been entered
  • imaps://... types email into prompt
  • <Tab> triggers autocompletion
macro index \cs '\
s\
?\
c\
<backspace><backspace><backspace><backspace><backspace><backspace>\
<backspace><backspace><backspace><backspace><backspace><backspace>\
<backspace><backspace><backspace><backspace><backspace><backspace>\
<backspace><backspace><backspace><backspace><backspace><backspace>\
<backspace><backspace><backspace><backspace><backspace><backspace>\
<backspace><backspace><backspace><backspace><backspace><backspace>\
<backspace><backspace><backspace><backspace><backspace><backspace>\
<backspace><backspace><backspace><backspace><backspace><backspace>\
<backspace><backspace><backspace><backspace><backspace><backspace>\
<backspace><backspace><backspace><backspace><backspace><backspace>\
<backspace><backspace><backspace><backspace><backspace><backspace>\
imaps://your_email@imap.gmail.com:993\
<Tab>\
<backspace><backspace><backspace><backspace><backspace><backspace>\
<Tab>'\
    "Save message to +storage mailbox"

Format Strings

Read official docs - very good for this section.
This is just an overview.

Expandos

The available expandos are defined by each section.

index http://www.mutt.org/doc/manual/#index-format
pager http://www.mutt.org/doc/manual/#pager-format
status http://www.mutt.org/doc/manual/#status-format
sidebar http://www.mutt.org/doc/manual/#sidebar-format

Formatting

fill characters

zfill character

# %|{x} fills remainder of line with following character
# (ex: entire line of '-'s)
set status_format = "%|-"

rjust character

# %>{x}  right-justify  (priority to left-side info)
# (ex: fill with spaces so 'right info' will be right-justified)
# (    if not enough room, right-side will be clipped)
set status_format = "left info %> right info"

# %*{x}  soft-right-justify  (priority to right-side info)
# (ex: fill with spaces so 'right info' will be right-justified)
# (    if not enough room, left-side will be clipped)
set status_format = "left info %* right info"

CLI Filters

Format strings ending in | will be piped to a shell command.

# script.sh will be called to finalize format string
set status_format="script.sh '%r %f (%L)'|"

Conditionals

You can print text (or another format string) if an expando is non-zero.

# format
%?<sequence_char>?<optional_string>?

# if %n (number of new messages) is non-zero,
# print '%n new messages'
%?n?%n new messages.?