UCLALUG

Main - Linux? - Help & Docs - Software Downloads - About Us

Mutt and Procmail Guide

by terry chow

What is mutt and procmail?

mutt is a highly configurable text email client. Use it to for your email tasks, ie read and send mail. procmail is a highly configurable mail filtering utility. It can automatically put certain email in specified mailboxes. Both these programs run under Linux and probably other flavors of unix too.

What is this guide for? Why should I read it?

I spent way too much time configuring mutt and procmail to do what I wanted it to do. This guide is intended to assist the user to start using mutt and procmail as quickly as possible without going through all the crap I went through before everything finally worked. Do not read this guide if you want to learn about the internals of mutt or procmail. Do not read this guide if you want to learn how the programs work.

"All mail clients suck. This one just sucks less." -Michael Elkins, circa 1995

From my experience the above quote from Michael Elkins (the author of mutt) is totally true. Except for one minor note: most email clients suck ultimately because the final configured product (the email client) sucks. The configuration and setup might be easy, but the more you start using it the more it sucks. Mutt on the other hand is diametrically different. The configuration sucks horribly, but it gets better once everything is finally setup. Then the more you use it, the less it sucks.

Prerequisites

Here is my .muttrc. I recommend you open this in another window while reading this document. Its a text file because I'm too lazy to html'ize my .muttrc. However I will spit out parts of the config file for further discussion.

(Updated 10/22/2003) - A HTML version of the .mutt rc has been provided, thanks to Benji Fisher <benji_at_member_dot_AMS_dot_org>

For the extremely impatient

Save this other sample .muttrc. Rename it .muttrc and put it in your home directory. Edit the file and replace everything inside braces, that is {...}, with your corresponding info. Don't worry about procmail. Launch mutt. Continue reading if you have a little more patience and you want to learn what my .muttrc means. Continue reading if you want to learn some simple email filtering with procmail.

Basic mutt configuration

Let me emphasize that the following configuration is how I set mutt up. Mutt is highly configurable and if you don't like how I did something, you can probably change it. Open up your .muttrc or create one if you don't have one yet. Replace my name with yours and set where you want your mail directory to go. I have my mail in ~/muttmail but you can call the directory whatever you want. The postponed and mailboxes fields should be self-explanatory. We'll make procmail shove your mail into specified mailboxes later, so don't worry so soon about what belongs in the mailboxes fields. Again replace my stuff with your corresponding info. Pick your favorite text editor for editor.
set realname="tchow"
set folder="~/muttmail"			     # where my mailboxes are
set postponed="~/muttmail/postponed"	     # where postponed stuff goes
set mbox=+mbox				     # mail from spool gets copied in here
mailboxes /var/spool/mail/kodiak	     # my mailboxes filtered by procmail
mailboxes /home/kodiak/muttmail/lug
mailboxes /home/kodiak/muttmail/admin-lug
mailboxes /home/kodiak/muttmail/bruinlinux
mailboxes /home/kodiak/muttmail/bugtraq
#sent mail should not be defined as a mailbox
#mailboxes /home/kodiak/muttmail/sent
set editor=jmacs			     # yay! emacs key bindings

The following will copy all your sent mail to your mailbox sent. Call it whatever you want. "+" expands to what you specified in folder kind of like how "~" expands in shells. In this case it would be ~/muttmail/sent.

set copy=yes                    # + is a mailbox shortcut.
set record=+sent                # it expands to whatever you set in folder

Customizing how mutt looks

How mutt looks can be configured extensively. This specifies the order of the headers and ignores all the headers I don't want to see except the ones I explicitly state. "\" is used to split commands over more than one line.
hdr_order Date: From: Organization: User-Agent: X-Mailer To: Cc:\
    Reply-To: Subject:

ignore *
unignore Date: From: Organization: User-Agent: X-Mailer To: Cc:\
    Reply-To: Subject:

Syntax is kind of complicated here. Read the mutt manual if you're interested. Otherwise just copy the following junk and rest in peace. Format for folders, dates, indices, and forwards:

set date_format="!%a, %b %d, %Y at %I:%M:%S%p %Z
set folder_format="%N %-8.8u %8s %d  %N %f
set forward_format="Fwd: %s"
folder-hook . 'set index_format="%4C %Z %{%b %d} %-15.15F (%4l) %s"'

Useful aesthetic stuff.

set edit_headers		      # i like to see the headers when composing email
set pager_context=1		      # paging shows me one line leftover
set pager_stop			      # prevent pager from going to next message unlesss you say so
set nomarkers			      # no wrap around markers
For those of you who are familiar with hooks in Emacs, mutt has something similar. The term folder is quasi-synonymous with mailbox. The "." following folder_hook is a glob for all folders. (Its a regular expression) I've set it so that all mailboxes by default are sorted by threads and whenever I'm reading mail, 10 (yes, 10) messages are shown in a mini-index. Mutt defaults to not having a mini-index, but I like seeing some context of messages around the current message I'm reading. However, for my sent mailbox and spool, I like those to be sorted by date. The last lines override my default.
folder-hook . set sort=threads
folder-hook . set pager_index_lines=11

#these don't get sorted by threads
folder-hook /var/spool/mail/kodiak set sort=date-received
folder-hook +mbox set sort=date-received
folder-hook +sent set sort=date-sent

Some mutt behaviors

I think my comments are clear here.
unset mark_old			      # unread old messages are still unread after quitting
set auto_tag			      # when tagged, actions for messages are default for all tagged messages
set quit=ask-no			      # ask me to quit. default no
unset confirmappend		      # don't ask me about appending messages to other boxes

Aliases

Its sometimes easier to type an alias for somebody's email instead of trying to remember the whole email address. The next two commands set the file for aliases and then reads them in. You can call the file anything you like or you can even use .muttrc as your alias file.
set alias_file="~/.alias_mutt"
source ~/.alias_mutt
The syntax of the alias file is simple. You can have many more aliases and, you can alias several people to one alias. Here are is a short example:
alias tchow kodiak@linux.ucla.edu (Terry Chow)
alias lug linux@linux.ucla.edu (UCLALUG)
If this is set up correctly, then simply enter the alias whenever prompted for an email address and mutt will take care of the rest.

Keybindings

It is very easy to change the key bindings in mutt. You use the bind command, followed by where your key binding will apply, followed by which key, followed by a function. Not everything in mutt has a function so sometimes macros are defined to do something you would normally do with several keystrokes. I won't delve into macros here. These are the ones I have changed/added to the mutt default key bindings. They are derived from Emacs and slrn key bindings.
bind generic	"#"		tag-entry
bind generic	<left>		previous-entry
bind generic 	<right>		next-entry
bind index	"c"		copy-message
bind index	"\Cx\Cf"	change-folder
bind pager	"c"		copy-message
bind pager	"#"		tag-message
bind pager	<up>		previous-line
bind pager	<down>		next-line
bind pager	"<"		top
bind pager	">"		bottom
bind pager	<home>		top
bind pager	<end>		bottom
bind pager	"{"		previous-thread
bind pager	"}"		next-thread
bind pager	"\Cx\Cf"	change-folder
bind browser	"e"		check-new

macro index	"\Cx\Cb"	"<change-folder>?"	
macro index	"w"		"<change-folder>?"	
macro index	"\Cx\Cs"	"|cat > ~/"	
macro pager	"\Cx\Cb"	"<change-folder>?"	
macro pager	"w"		"<change-folder>?"
macro pager	"\Cx\Cs"	"|cat > ~/"	

What if I like vi key bindings?

There are some default key bindings that are similar to vi. When editing input fields like the email address, some vi favorites will work. For instance Ctrl-U, Ctrl-W, Ctrl-h will kill a line, kill a word, and delete a character respectively. For more vi like behavior look at Gabriel Zachmann's .muttrc. I'm sure you can implement other behaviors of favorite editors like pico in the same manner.

Colors

Colors for nearly every object inside mutt can be changed. The following colors are good for dark backgrounds. I use a pseudo-transparent terminal for mutt. If you also use a transparent terminal, put this in your .bashrc export COLORFGBG="default;default"

The first field is the command color. Second field is the object you want to alter in mutt. The third and fourth field specify the foreground and background color. If there is a fifth field, its the regular expression you want your colors to apply to. Change default to another color if you want another background color. Color values can be preceded by "bright" resulting in bold, bright text. Consult the mutt manual for more info.

color normal		default		default
color hdrdefault	brightcyan	default
color signature		green		default
color attachment	brightyellow	default
color indicator		brightblack	brightcyan
color quoted		green		default
color quoted1		white		default
color tilde		blue		default
This will catch email address and URLs and make them bold and a different color.
color body		brightcyan	default "[-a-z_0-9.%$]+@[-a-z_0-9.]+\\.[-a-z][-a-z]+"
color body		brightwhite	default "(http|ftp|news|telnet|finger)://[^ \">\t\r\n]*"
color body		brightwhite	default "mailto:[-a-z_0-9.]+@[-a-z_0-9.]+"
This will change the Date: and Subject: fields in headers to bold yellow or magenta.
color header		brightmagenta	default ^(Date):
color header		brightyellow	default ^Subject:
This will make smileys, :) , appear bold.
color body		brightred	default " [;:]-*[)>(<|]"	# :-) etc...

The final output

Here's what my mutt configured with my .muttrc looks like. (fuzzy text is a product of jpeg compression)

Procmail

Procmail should deserve its own guide since it can be thoroughly complicated, but I'll give a quick run through so you can actually use it practically.

Step 1
Edit or create a .forward file. Put this in and replace "kodiak" with your user name. Include the quotes.

"|IFS=' ' && exec /usr/bin/procmail -f- || exit 75 #kodiak"
Step 2
Here is a simple .procmailrc:
LINEBUF=4096
VERBOSE=off
MAILDIR=$HOME/muttmail
FORMAIL=/usr/bin/formail
SENDMAIL=/usr/sbin/sendmail 
PMDIR=$HOME/.procmail
LOGFILE=$PMDIR/log
INCLUDERC=$PMDIR/rc.maillists
.procmailrc can be a whole lot more complicated, but the above will work for basic purposes. Do a whereis formail and whereis sendmail for the proper paths to them. Do not use ~ to expand to your home directory. The value for LOGFILE will be where procmail errors go. rc.maillists is the file that separates your mail into folders.

Step 3
Create or edit .procmail/rc.maillists. Here is a working example:

:0:
* ^TOlinux@linux.ucla.edu
lug

:0:
* ^TObruinlinux@linux.ucla.edu
bruinlinux

:0:
* ^FROMsaa@support.ucla.edu
/dev/null

:0:
* ^FROMchancellor@ucla.edu
/dev/null
Notice that "0" is a zero, not an "oh". Don't ask me about the strange syntax. I don't know why its like that, but I can tell you what the parts mean.

But what does all this garbage mean?

:0 means to start a recipe. You can have different recipes to do different things to certain emails. The following : means to lock the file. It might be disastrous if multiple processes are attempting to write to the same file.

The * means to start a condition. A recipe can have several conditions, but my examples only have one. Following the * is a regular expression which matches the mail that you want to filter somewhere. In the first recipe * ^TOlinux@linux.ucla.edu essentially means all mail with header "To: linux@linux.ucla.edu". The ^ is standard for regular expression to mean "beginning with". All of the email from the UCLALUG discussion mailing list are addressed "To: linux@linux.ucla.edu".

Note: Use ^TO and not "to:" or something else. ^TO is not a normal regular expression. It is built into procmail and actually stands for some crazy regular expression to match all cases of "to", like To:, to:, TO:, to, To, etc.

The last line in the first recipe, lug, is the mailbox that you want procmail to send your mail. It can be an absolute or relative path, but it is relative to $MAILDIR which you defined in .procmailrc. I throw my mail from the UCLALUG into mailbox lug.

A procmail recipe is very similar to a if statement for C, C++ or various other programming languages. For example, the first recipe is "if mail header is To: linux@linux.ucla.edu, then send it into the lug mailbox". The second recipe is similar to the first one except for a different mailing list.

The third and fourth recipes take mail with from chancellor@ucla.edu and SAA and sends them straight to the garbage. These two never have anything important to say and often spam me. The condition uses a procmail builtin shortcut, FROM which stands for a regular expression for many cases of "FROM:".

Step 4: Finishing up with procmail
By now you should have procmail filtering your email into the proper mailboxes. I've only touched briefly on the capabilities of procmail. It can be configured for all sorts of crazy stuff like automatically replying to some mail or automatically compressing it and forwarding it somewhere else. The possibilities are endless.

Quick start guide for mutt

Now that you have mutt and procmail configured, you can start using mutt. Why is the "getting started" with mutt section at the end of this article? Because using mutt sucks when its not properly configured.

The index
Use the arrow keys to move around and select the messages. Press ENTER to read a message.

The pager
Then use PgUp or PgDn ,the arrow keys or SPACE to scroll the message.

If you used my mutt configurations you should be able to see a mini-index of the messages. Use RIGHT and LEFT to go forward and backward in the index. If you didn't use my configuration, push i to go back to the index and use UP and DOWN for the next or previous message.

Composing new mail or replying
When you are viewing a message in the index or the pager you can press r to reply. Also in the index or pager, press m to compose a new message.

If you reply or start a new message, your editor should come up. After finishing your message, save and exit the editor and you will return back to the mutt composition screen. Press y to send the mail.

The help menu
Remember, press ? for a help menu, describing the default keybindings.

Where can I find more information

man procmail

man procmailrc

man procmailex

http://www.mutt.org/

This guide only scratches the surface for mutt and procmail. You can find many more advanced uses from the procmail man pages and the mutt webpage.

/guides/mailguide.php3 last updated on Wed Oct 22 2003