Hack and /

Mutt Tweaks for System Administrators

Kyle Rankin

Issue #168, April 2008

If digging through your server e-mail bogs you down, use these tips to organize and tweak your mutt configuration and cut through that mailbox like a letter opener through an envelope.

I am one of those people who stores everything in e-mail. Travel reservations, phone numbers—if it is in an e-mail message, I know one way or another I can find the information. That might be one of the reasons I have been using mutt as my main mail program both at home and work for years. It is difficult to beat when you need to read, search and navigate large mailboxes full of mail. That, and it has vi-style key bindings. I love vi-style key bindings.

If you are a sysadmin, there are even more reasons to love mutt. For one, you probably spend a good deal of your day in front of a terminal, so why not read your mail from there as well? A lot of administrators like to run stripped-down servers that don't include binaries for X or graphical tools, but mutt is small, and what's more, you can ssh to a server or your work desktop from another machine and check your mail.

At work, I like to segregate my e-mail into folders, based on whether a message is from a person or a server (and, of course, I segregate them further from there). If you manage a lot of servers, those mailboxes can start to get rather large. Almost nothing compares to mutt when you need to open a mailbox with a few thousand new messages. This brings me to my first almost-essential mutt tweak: header caching.

Header caching is a feature that has shown up in mutt only in the past few years. Essentially, it allows mutt to cache the headers from mailboxes, so that the next time you load the mailbox, it has to pull down only the new messages. This is particularly handy with IMAP servers or even large local mailboxes.

To enable header caching, create a directory called .muttheaders in your home directory, then add the following line to your ~/.muttrc, and restart mutt or reload your mutt config:

set header_cache="~/.muttheaders/"

Separate Mutt Configs

This tweak is, in some ways, more organizational, and it's handy not only for sysadmins but also for anyone who runs mutt on multiple machines. Many mutt guides will tell you to split .muttrc into multiple files for different types of configuration, so you can have one file that has all of your color options, another with your key bindings and so forth. Then, you simply can add a source line to your .muttrc file that points to the new file, and mutt will load those options as well.

What I like to do is take it a step further and create a .mutt directory in my home directory and place all of those files including my .muttrc in that directory. Then, I create a new file in my home directory called .muttrc.local. In this file, I store any options that are specific to just that particular machine (IMAP settings, local mailbox locations and so on) and keep the rest of the options organized in different files in the .mutt directory. Finally, I create a symlink from ~/.mutt/.muttrc to ~/.muttrc, so mutt still will be able to find it. In this .muttrc, you would find source lines like:

source ~/.muttrc.local
source ~/.mutt/colors
source ~/.mutt/aliases
source ~/.mutt/mailboxes

The advantage to this arrangement is that once I make a change to any of the files in .mutt, I simply can rsync that entire directory to any other machine on which I run mutt, and all of my changes will be there. If I didn't segregate these to a directory and separate .muttrc.local, I would have to worry that any local settings from one machine would clobber the rest.

Colorize Important Words

If you read through a lot of cron, Nagios or other e-mail your servers generate for you, it's easy to let your eyes glaze over and miss important content. What I like to do is tweak my mutt configuration so that certain words, like warning, are colored in bright yellow, and words like error and fail show up in bright red. This is surprisingly easy to do with mutt in only a few lines:

color body brightyellow default warning
color body brightred default error
color body white default 'no error'
color body brightred default "fail(ure|ed)?"

Notice the line that matches no error. I noticed that some messages said “no error” in them, and the error section still was being colored red. If this happens with your keywords, simply add a similar line in there to override the previous less-specific match. You don't have to limit yourself to just these keywords. For instance, you also could highlight certain server names with a particular color or assign different data-center locations distinct colors.

Read Important Messages First

Once I had colorized all my e-mail, it was great—I would browse through output and more critical e-mail would jump to my attention. As the number of messages started to grow though, I noticed I would spend a lot of time reading the less-important messages before I found the important ones. My solution was to use the limit feature in mutt. When you are in the index view in mutt (where mutt shows you only the From and the Subject lines), you can tell mutt to limit (the l key by default) the headers you currently can see based on a pattern.

For instance, if I wanted to see only all the headers that said Bob, I could type l and then Bob <Enter>. Then, to see all the headers again, I could type l and then all <Enter> to show all messages. You also can have mutt search within the body of messages, so I created a mutt macro that I bound to the F3 key, so that when I see the full list of headers and press F3, it limits the view only to new messages that contained error or fail in them. I could read those messages first and then change the limit back to all and tab through the rest. Here is the extra line in my .muttrc to create the macro:


macro index <F3> "l~N ~b \"([\^nN][\^oO].error|[Ff][Aa][Ii][Ll])\"<enter>"

I constantly am surprised with how far you can extend mutt. It is definitely one of those programs that gives your time back in gained productivity as you learn more about its configuration options. If you use your e-mail to remember things, or dig through a large stack of server e-mail every day (or even if you don't), mutt is an invaluable e-mail companion that always has new tricks.

Kyle Rankin is a Senior Systems Administrator in the San Francisco Bay Area and the author of a number of books, including Knoppix Hacks and Ubuntu Hacks for O'Reilly Media. He is currently the president of the North Bay Linux Users' Group.