Skip Navigation

Filtering mail

Mutt doesn't filter mail

You wouldn't want every single piece of incoming email dropped straight into your mailspool. There are things that you want to do with mail as it comes in: removing spam, sorting mailing lists into their respective folders and even altering the content - This is a job for a mail-filter.

Mail can arrive at your system in many ways, such as: POP3 retrieval, UUCP or SMTP - Since mutt doesn't really do any of these things, persuading it to filter mail that has already arrived is hard and is not going to be very satisfactory.

Procmail

The classic method of filtering mail is to use a mail-delivery agent (MDA) to do your filtering for you. This MDA is inserted into the incoming mail chain at the last stage before mail is written to mailboxes. Whatever software is transporting mail up until then (Sendmail, Postfix, Exim, Qmail, Fetchmail, Getmail etc..) needs to be configured to pass it on to the MDA.

Typically the mail-delivery agent is the Procmail mda. You probably already have procmail installed on your system - In that case configuring filtering rules is as simple as creating a ~/.procmailrc file in your home directory and reading the Procmail quickstart guide or some other mutt and Procmail guide.

Alternatives to Procmail

Aside from procmail, other mail filters you can investigate are the maildrop mda (developed for the courier mailserver but available separately) and mailagent as well as two perl modules Mail::Audit and Mail::Procmail.

Tell mutt about your mailboxes

Mutt isn't going to check every potential mailbox on your system on the off-chance that there is new mail in it - If you have set up delivery to multiple places, then you need to tell mutt about them with a mailboxes command in your ~/.muttrc file:

mailboxes \
$MAIL \
=inbox \
=lists/mutt-users \
=lists/mutt-newbie

The short example above will tell mutt to look for new mail; first in your system mailspool, then in ~/Mail/inbox, then in two other folders ~/Mail/lists/mutt-users and ~/Mail/lists/mutt-newbie.

Filtering mail on imap servers

Typically, an imap server will deliver all mail into the default INBOX. Ideally, you would have access to filtering software such as procmail or maildrop on the server-side - since sorting mail to the correct folders is hard to do using mutt.

If you don't have shell access to the server, one solution is to use a dedicated imap filtering client tool such as IMAPFilter. Alternatively, some IMAP servers support the sieve extension which allows you to create and manage filter rules remotely.

Spam filtering

Blocking junk mail, otherwise known as spam or UCE (Unsolicited Commercial Email), can be achieved with Procmail to a certain extent; simply trapping all HTML messages is very effective, though a dedicated spam-blocking tool like SpamAssassin is always going to be a better all-round solution.

SpamAssassin can be inserted into your incoming email toolchain alongside a mail delivery agent such as procmail. Alternatively, if all your mail is stored on an IMAP server, you can use a tool like IMAP Spam Begone to use it to filter UCE in place.

<< | Up | >>

This document was last modified on 2012-02-28 20:24:37.
Bruno Postle <bruno@postle.net>
Copyright © 2001 Bruno Postle and others. This guide is released under the Free Documentation License. http://www.gnu.org/licenses/fdl.txt