Linux.com

Feature

Training your Mutt

By Joe 'Zonker' Brockmeier on December 12, 2006 (8:00:00 AM)

Share    Print    Comments   

Mutt is a great mail client, in large part because it is extremely customizable. You can tweak Mutt's behavior and have it do tricks that are nearly impossible to do with other mail clients -- but it can be a bit daunting to get started with. Let's take Mutt on a short trip to mail client obedience school and see how easy it can be to make Mutt handle mail just the way you want it to.

To do that, we'll take a look configuring your Mutt configuration file. Mutt reads the system-wide configuration under /etc/Muttrc and looks for a file called .muttrc under your home directory for its configuration. We'll focus on modifying the .muttrc configuration here.

In the .muttrc file, you can tell Mutt where to look for mail, define or redefine Mutt's keybindings, set up macros to speed up actions that you perform frequently, and a lot more. Let's start by telling Mutt where your mail is.

Getting mail

You can get mail in a couple of ways with Mutt. Mutt supports POP3, IMAP(S), and reading the local mail spool. Mutt requires little, if any, configuration to read a local mail spool. By default, Mutt looks for the $MAIL environment variable and reads mail there. If your mail is in a non-standard place, or if you don't want Mutt to use $MAIL as your mail spool, you can set it manually:

set spoolfile=/path/to/spool

Remote mail is slightly trickier. You could combine Mutt with fetchmail, Getmail, or another program to retrieve mail from remote machines, but I'm going to assume most users would rather maintain one program than several.

Let's start by looking at a basic POP configuration. If you want to retrieve email from a POP server, you'll need to set the following in your .muttrc:

set pop_user = "username"
set pop_delete = no
set pop_pass = "password"
set pop_host = "pop.myserver.com"

The pop_user parameter is the name of the user that will be collecting mail.

The pop_delete directive is a quadoption; you can set this to yes, no, ask-yes, or ask-no. Setting the parameter to yes or no will tell Mutt to delete or leave mail on the POP server without prompting the user, while ask-yes and ask-no tell Mutt to provide a prompt each time it grabs mail via POP, but set to default action to yes or no.

The pop_pass parameter is optional, and it's not really advisable to include it in the .muttrc if you're on a multiuser system. If you leave this out, Mutt will prompt you for the password the first time that you retrieve mail in a session, so you don't need to keep entering the password to grab mail if you leave Mutt running.

The pop_host parameter tells Mutt the hostname of the system to poll for new mail. The default is to poll the server on port 110, without encryption. If you want to use encryption or a different port, you can set that by modifying the server URL a bit. For example, here's what you'd want to use for Gmail:

set pop_host = "pops://pop.gmail.com:995"

The pops prefix tells Mutt to use SSL, and you can append a port number. You can specify pop:// for regular unsecured POP3, but there's no need to do so -- if you don't specify pops:// or the port number, Mutt assumes POP3 on port 110.

The IMAP configuration isn't any more difficult. I use IMAPS, and have Mutt use the remote folder as my mail spool:

set spoolfile=imaps://imap.server.com/INBOX
set imap_user=username
set imap_pass=password

By setting the spoolfile to your IMAP inbox, Mutt will read the mailbox on the IMAP server. Note, again, that you may not want to save the password in your .muttrc file unless you're on a single-user system. If you omit the imap_pass parameter, Mutt will prompt you for your IMAP password.

Defining mailbox type

Mutt supports several mailbox types: mbox, MH, Maildir, and MMDF. By default, Mutt will use the mbox format, but you can override this with the mbox_type directive in the Mutt configuration file. For example, to set to MH, you'd use:

set mbox_type=MH

The mbox format is most widely used, but Maildir is often touted as a superior format. For example, if two programs try to manipulate the user's inbox at the same time, the mbox format has problems; because it's a single file, if two programs are successful at accessing the mbox file at the same time, you can wind up with a corrupted mailbox. Some programs use a locking mechanism to claim the mailbox, but that doesn't mean that another program will honor the lock.

Configuring keybindings

Switching to a new mail client, or new application of any sort, usually requires a retraining period. With Mutt, you can opt to retrain yourself or retrain Mutt. The first time I tried Mutt, I was migrating from Pine. Instead of adapting to Mutt, I decided to see if I could adapt Mutt to my way of doing things.

I could. A bit of searching, and I found this page, with a .muttrc contributed by Tobias v. Koch that configures Mutt to use most of Pine's keybindings, circa version 4.33. If you're using Ubuntu or Debian, you will have several sample Mutt config files under /usr/share/doc/mutt/examples that make for good references.

You can reconfigure Mutt's keybindings to suit your habits. The syntax for a custom keybinding is simple:

bind menu key function

The menu can be one of several menus of functions available within Mutt; the index menu where you view messages, the editor menu where messages are composed, the pager menu which is where you read messages, or any of several others. Mutt also has a generic menu that comprises functions that are available in most menus, except the pager and editor menus.

Let's look at a few examples. The default key for sorting messages in Mutt is o, which brings up the list of options to sort messages by. If you wanted to change that to $ instead, you could use the following directive:

bind index $ sort-mailbox

This tells Mutt to use $ for the sort-mailbox function when in the message index menu. I usually sort messages by the From header, so I've set up a macro to do that in one step rather than two:

macro index $ of

Now, instead of pressing o to bring up the sort menu, and then f to sort by the From header, typing $ does it all in one shot.

Saving messages

If you subscribe to mailing lists, you may want to set up one or more save-hook directives in your .muttrc file. A save-hook provides a default folder for Mutt to save messages in if a message matches a simple pattern. Here's a good example:

save-hook "~C devel-list@" +devel-list

This tells Mutt if a message has the string "devel-list@" in the To or CC field of a message to default to saving it in the devel-list folder. If you wanted to match the user the message was sent from instead, you'd use "~f user . A full list of patterns can be found in the Mutt manual.

If you want to save messages going out to a list to the same folder, you could use the fcc-save-hook directive instead:

fcc-save-hook "~C devel-list@" +devel-list

That would save outgoing and incoming messages with devel-list@ in the To or CC field to the devel-list folder.

The save-hook method doesn't work so well if you have to sort a lot of messages that have almost no common characteristics. For example, I get tons of press releases to my work email address. Setting a save-hook triggered by mail email address wouldn't help, so I use a macro instead:

macro index \co s+OSTG
macro index \cp s+Work/PR

Let's walk through the syntax of the first line to make sure it's clear. The macro directive declares a macro, and index tells Mutt that it's to be used in Mutt's index view. The shortcut for the operation will be Ctrl-o, and when you press that key combination, Mutt will then execute the save command s with the parameter +OSTG, which tells Mutt to save the file in the OSTG folder under my mail directory.

This way, when I get a press release to my work address, I can press Ctrl-p to save it in the PR subfolder. If I get a work email that I want to save to the OSTG folder, I hit Ctrl-o.

Sane header display

Mutt likes to display headers, probably more than you'd care to see. Since I usually care about only a few message headers, I tell Mutt to "ignore" all headers except the From, To, Subject, Date, and CC headers in a message, like so:

ignore headers *
unignore headers from to subject date cc

The headers are still there, of course, but they're hidden from view when you're reading your messages. Since it's not unusual for a message to have more than 20 or more header fields, this saves some valuable screen real estate. If you need to see headers, you can toggle the full view with h, or whatever you have display-toggle-weed set to in your .muttrc file.

To specify what order headers should appear in, use the hdr_order directive:

set hdr_order to from subject date

Look at the pretty colors!

You can customize Mutt's color scheme to whatever makes your eyes happy. I tend to stick to minimal color modifications, but you can go crazy if you want to and customize almost every aspect of Mutt's interface and message displays. The syntax is simple:

color object foreground background expression

The object name, foreground, and background are required fields, while the expression is optional. If you add an expression, then the colorization will take effect only when an object matches the expression. You can find a list of objects and color usage in the Mutt manual.

Mutt has a special object called index that allows you to set colors for messages by pattern in the index. For instance, if you want to highlight any message that is sent by your boss:

color index brightred black boss

Any message in the index that matches the pattern "boss" will have a bright red foreground and a black background.

Here's a short example, with some of my colorization options:

color header brightred black subject
color hdrdefault brightwhite black
color quoted brightgreen black
color status black cyan
color indicator default green

This is mostly self-explanatory, but I'll break the first one down to be sure it's clear. The first item in the configuration tells Mutt to check the header object for a pattern that matches "subject." If it does match, it should set the foreground color to bright red, and the background color to black.

Next: More useful settings

 

Share    Print    Comments   

Comments

on Training your Mutt

Note: Comments are owned by the poster. We are not responsible for their content.

Training your Mutt

Posted by: Anonymous Coward on December 12, 2006 06:38 PM
I am Swedish, and I find that quite funny...<nobr> <wbr></nobr>:D

#

Re:Training your Mutt

Posted by: Anonymous Coward on December 12, 2006 07:43 PM
So, what does "mutt" mean in Swedish? If it's inappropriate, I'm satisfied with the Norwegian word for it (if you know)<nobr> <wbr></nobr>:)

#

Re:Training your Mutt

Posted by: Anonymous Coward on December 13, 2006 05:06 AM
I am using mutt for 7-8 months. I am now very comfortable with it and very happy with it. Imap account is pretty decent. It should have support of builtin MTA client.

I have few issues with it :
1. For pop account, it tries to download all the mails (atleast headers) every time when I login into which is a different behaviour than thunderbird. I feel thunderbird way is lot natural. I guess that there may be some way to mimic what thunderbird does. Also I want to know if there is way so that it will save the mail in local file from pop account. It should delete mail when I delete it from local mbox.
2. Multiple mbox is very painful to setup in mutt.

#

imap?

Posted by: Anonymous Coward on December 13, 2006 12:37 AM
How do I switch between multiple IMAP accounts? How do I switch between different IMAP folders?
How do I cache IMAP messages, so mutt doesn't download them all every time?
P.S. Crap, and now I have to use IMAP in lowercase in the subject, because linux.com thinks I am yelling!!!

#

Re:imap?

Posted by: Anonymous Coward on December 13, 2006 02:25 PM
> How do I switch between multiple IMAP accounts?
press c to change address, start address with "imaps://" or "imap://" if no SSL.

> How do I switch between different IMAP folders?
press c then cycle list with tab key (may have to start tabbing after typing in "imap".

> How do I cache IMAP messages, so mutt doesn't download them all every time?
set message_cachedir in<nobr> <wbr></nobr>.muttrc to an existing directory.

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya