Mutt configuration

It's not difficult to guess, watching at the title, that this page is about Mutt. Mutt is a very well done, cross platform and feature rich MUA, that works under Linux, *BSD, OS X and even Windows. I'm using it on all my computers, because it's easy to use and very fast when it have to deal with a lot of emails. I use it primarly under OS X along with procmail as MDA, to filter emails in different folders.

Here you cand find some tips for a better use of mutt under OS X, in conjunction with general and cross-platform configuration.
The main site for mutt is www.mutt.org but there's a plethora of sites with many helpful informations. A small list is at the bottom of this page.

Install mutt with Macports

Macports, formerly called Darwinports, is a program to simplify installation of Open Source Software unders OS X. It needs Xcode tools from apple since it compiles all the software from source.
A quick guide to install macports is here. Mutt installtion is quite straightforward, as is the installation of every other program supported by macports. To have my configuration work correctly, mutt must be compiled with these variants (refer to the official wiki for further documentation):

sudo port -vc install mutt-devel +gnuregex +gpgme +headercache +imap +pop +sasl +smtp +ssl +tokyocabinet
The command above should install mutt and all required libraries and if you followed this instructions correctly mutt can be started simply invoking it from the terminal.

Configuration

Mutt's configuration starts from a file, called muttrc, that must be placed under user's home directory or in /etc for system wide settings.
My configuration works for mutt 1.5.20, it won't work for mutt 1.4.X and *maybe* for previous development releases as well. Every configuration specific to a local installation (alternates, programs location, crypto settings and so on) is sourced from external files, so i can mantain only one main configuration file across several different machines. My muttrc is available here, every option is well explained in the manual and also has a brief comment above.

Sender profiles

The main problem i faced switching from other mail clients to mutt was that, at least apparently, there isn't an easy way to use different mail profiles in mutt. Googling a bit i found this page, which suggests to use my_hdr to change the relevant headers. Under linux it was easy, because all the keys were correctly recognised, so i set a bunch of function keys to load my profiles and i got used to them. Every profile file was in the form

# Mutt sender profile: Ilgufo
# Signature file
set signature='~/.mutt/signatures/sig-gufo'
# Customized headers

my_hdr From: Gufo <ilgufo [at] notmail [dot] com>

# Include the profile name in the status line
set status_format="--%f [Msgs:%?M?%M/?%m%?n? New:%n?%?o? Old:%o?%?d? Del:%d?%?F? Flag:%F?%?t? Tag:%t?%?p? Post:%p?%?b? Inc:%b? %?l? %l?]---(%s/%S)--%>-(%P)--Ilgufo-"
And was bound to a key using a macro
macro index <F7> ":source ~/.mutt/profiles/ilgufo\n" "Load profile: ilgufo"
Under OS X, function keys aren't well recognized and it seems that the "apple key" isn't usable as well. That's to say that my usual bindings were lost, so it was time to solve the problem using different resources. I usually filter all my emails in several folders, at least one for every mailing list and one for every account i own, and i'm used to start mutt in browser mode (mutt -y). What helped me here were folder hooks and the help kindly provided by people at comp.mail.mutt (expecially Alain Bench). Every folder have a hook which loads the corresponding profile:
folder-hook =IlgufoNotmail\.com$ source ~/.mutt/profiles/ilgufo
folder-hook =Mailing\_Lists\/.*$ source ~/.mutt/profiles/mailing-list
...
And every profile uses the $from variable to change the from header, instead of my_hdr. Profiles now are as follow:
# Mutt sender profile: Ilgufo
# Signature file
set signature='~/.mutt/signatures/sig-gufo'
# Customized headers

set from = "Gufo <ilgufo [at] notmail [dot] com>"
# Include the profile name in the status line
set status_format="--%f [Msgs:%?M?%M/?%m%?n? New:%n?%?o? Old:%o?%?d? Del:%d?%?F? Flag:%F?%?t? Tag:%t?%?p? Post:%p?%?b? Inc:%b? %?l? %l?]---(%s/%S)--%>-(%P)--Ilgufo-"
Avoiding the use of my_hdr allows $reverse_name, and some other features, to work properly. I use my_hdr only for send_hooks, and properly unset it when done. Since I want to contact some people using always a specific account, I've set a send-hook that loads the right profile for each destination address:
send-hook . "source ~/.mutt/profiles/default"
send-hook "someone\@domain\.it" "source ~/.mutt/profiles/send/profileX"
Please note that profileX doesn't work as the other profiles, instead it uses my_hdr, as in the first solution previously described. The default hook simply unset my_hdr From:
#Default send hook:
unmy_hdr From:

Obviously this method implies to study how hooks work, but it's really worth the hassle :-)

To make mutt work well it's also important to specify all the mail addresses belonging to you, using the directive "alternates", which expects a list of regular expressions as argument:
alternates ^name@domain1\\.com$ ^name@domain2\\.com$ ^gufo@domain\\.it$ ....

Bindings and macros

I'm using lbdb to aggregate OS X's addressbook and mutt internal contacts, and urlview to start the browser when a mail contains an url. Here are my macros and keybindings.
A useful bind is the one that inhibits ctrl-d. When in hurry I used to delete messages when pressing "q" and then ctrl-d (to logout the shell) without actually quitting mutt:

bind pager,index \cd "noop"

Header caching

It costs just a little disk space, but header caching makes mutt significantly faster when a lot of emails in maildir format are in the same folder. This feature was available as a patch, but since mutt 1.5.7 is part of the main source tree. To enable it just point header_cache to a folder or a file (this feature must be enabled at compile time). There's a catch using this feature, when playing with the reply_regexp variable, caches must be deleted to see changes because the way threads are sorted gets cached too.

Colors

This is mine colors configuration, it's a modified version of ataualpa's one and it's good on a black background. A screenshot [~90K] is worth a million words ;^). It's also available an untested colors configuration for white background.

Mailcap

Under OS X my mailcap looks like this:

text/html; elinks -dump %s ; copiousoutput
document/pdf; view_attachment.sh %s -
application/octet-stream; view_attachment.sh %s -
mime_lookup application/octet-stream
video/*; view_attachment.sh %s -
image/*; view_attachment.sh %s -
application/*; view_attachment.sh %s -

Which is nothing special, by the way ;^).
The script called (view_attachment.sh) is very effective and is written by Eric Gebhart. I call it passing "-" as a parameter, so it doesn't try to recognise file extension (and fail every time a filename contains strange characters). You can download my local copy.

External programs

Mutt can seamlessy integrate with external programs, to expand its functions. One is urlview, which can open url listed on email body.

Urlview

Under OS X urlview is installable via fink or from macports, and its configuration is straightforward:

# Bind ulrview to crtl+b
macro index \cb "|urlview\n" "open url with urlview"
macro pager \cb "|urlview\n" "open url with urlview"
to configure urlview simply place a file named .urlview in your home directory, with this directive:
COMMAND open %s
and it'll use the default browser to open urls. In spite of what the man page states, urlview.sh isn't needed.

Mailtomutt

Mailtomutt must be set as the default mail application, obviously (!?!?!!!) Mail.app is used to configure this behaviour (see this page for a step by step guide). Mailtomutt will open mutt every time your programs want you to send mails to someone.

Links