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.

Document Links

maildrop mda
Maildrop is a powerful email filter/delivery agent. It supports mbox-style mailboxes and maildirs.
http://www.courier-mta.org/maildrop/
Procmail mda
The procmail and formail mail processing package can be used to create mail-servers, mailing lists, sort your incoming mail into separate folders/files, preprocess your mail, start any programs upon mail arrival or selectively forward certain incoming mail automatically to someone.
http://www.procmail.org/
Procmail quickstart
This article will quickly get you up and running withThis article will quickly get you up and running with Procmail
http://www.ii.com/internet/robots/procmail/qs/
mutt-users archive
web searchable mailing list archive
http://groups.yahoo.com/group/mutt-users/
IMAPFilter
Based on the user defined filters it checks messages residing on a remote IMAP mailbox and processes them in various ways.
https://github.com/lefcha/imapfilter
Mail::Audit
Perl library for creating easy mail filters
http://www.cpan.org/authors/id/S/SI/SIMON/
Mail::Procmail
Perl module that provides procmail-like tools
http://www.cpan.org/authors/id/JV/
sieve
A Mail Filtering Language for remote configuration
http://www.fastmail.fm/docs/sieve/
mailagent
A perl program for filtering incoming mail
http://www.cpan.org/authors/id/RAM/
Mutt and Procmail Guide
A mutt guide with procmail configuration hints
http://linux.ucla.edu/lugwiki/resources:linux:mutt-and-procmail
SpamAssassin
Uses a wide range of heuristic tests on mail headers and body text to identify spam
http://spamassassin.org/
IMAP Spam Begone
Makes it easy to scan an IMAP inbox for spam using SpamAssassin
http://redmine.ookook.fr/projects/isbg
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