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.
Where that filtering happens depends on where your mail lives. If it arrives on a server you control, filter it there as it is delivered. If it sits in somebody else’s IMAP account, filter it there, on their server, before it ever reaches you. Persuading mutt to sort mail that has already arrived is hard and is not going to be very satisfactory.
Filtering on the server: Sieve
For most people today, mail is delivered to a provider’s IMAP server and the right place to filter it is there. Sieve is the standard language for this - a small, deliberately unpowerful language that cannot loop or run programs, which is exactly what you want running unattended on a mailserver.
Most providers of any quality support it, either through a web interface or over the ManageSieve protocol. A rule looks like this:
require ["fileinto"];
if header :contains "List-Id" "mutt-users.mutt.org" {
fileinto "lists/mutt-users";
}
If you run your own server, Dovecot implements Sieve in its local delivery agent and is the usual choice.
Sieve has the considerable advantage that your mail is already sorted whichever machine or client you pick it up from, including your phone.
Filtering on delivery: a mail delivery agent
If mail is delivered to your own machine, filtering is done by a mail delivery agent (MDA), inserted into the incoming mail chain at the last stage before mail is written to mailboxes. Whatever software is transporting mail up until then (Postfix, Exim, fetchmail, getmail and so on) needs to be configured to pass it on to the MDA.
maildrop is the usual recommendation. It was developed for the Courier mailserver but is packaged separately, it understands both mbox and Maildir, and its filter language is considerably more readable than procmail’s:
if (/^List-Id:.*mutt-users\.mutt\.org/)
{
to "$HOME/Mail/lists/mutt-users"
}
fdm is a smaller alternative from the OpenBSD world that both fetches and delivers, so it can replace getmail and your MDA together.
A note on procmail
Procmail was the classic answer here for twenty years, and you will find it assumed by every piece of mail documentation written before about 2015, including earlier versions of this page. It is no longer a good place to start: it went unmaintained for roughly a decade, accumulated serious security problems in the process, and its own maintainer’s advice was to move to an alternative such as maildrop. The project website has since gone.
If you have working procmail recipes there is no emergency, but do not write new ones. maildrop is the closest replacement and recipes translate fairly directly.
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-dev
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-dev.
If you have a lot of these, turn on the sidebar so you can see them all at once - see the mutt overview.
Filtering an IMAP account you don’t control
If your provider has no Sieve support and gives you no shell access, you can filter the account remotely with a client tool. IMAPFilter logs in, applies rules written in Lua and moves messages about. Run it from cron and it behaves much like server-side filtering, just slower and only while your machine is awake.
Spam filtering
Most people’s spam is now filtered by their provider before they ever see it, and for a mailbox on Gmail or Microsoft 365 there is nothing useful for you to add.
If you run your own mail, rspamd is the current standard: fast, actively developed, and designed to be hooked into Postfix or Exim directly. Apache SpamAssassin is the venerable alternative and still works well alongside an MDA. bogofilter is a much smaller, purely statistical option if you want something you can train yourself and understand completely.
Whichever you use, have it add a header rather than delete anything, then let mutt act on that header. Mutt has a spam command for exactly this, which turns a filter’s score into something you can sort and limit on:
spam "X-Spam-Status: Yes, score=([0-9.]+)" "%1"
See the spam detection section of the manual.
Last updated 31 August 2026.