One big mutt inbox, filtered after-the-fact using procmail

This article shows how to configure mutt and procmail to drop all emails into one big inbox which is then filtered, after you’ve read the email, into a distinct mailbox. For example, emails from your friends, girlfriend(s), sysadmin, and bank all show up in your inbox; after reading each they are sent to =friends/, =romances/, =nightly/, and =finances/, respectively, automatically.

Rationale: each morning I read every email available to me, in order of a loose priority, no matter which mailbox it was in. As an email came in I’d immediately read it. It made little sense to open a new mailbox just to read yet another email; the mailboxes are more useful for saving the email to reference later.

In this setup you now need two procmailrcs: one that delivers stright to your inbox (you could probably get away without procmail for this role, even; I use procmail to handle the Maildir format and also to commit each email to git after delivering it), and one for the final filtering. I named these ~/.procmailrc and ~/.procmail/finalrc .

The ~/.procmailrc looks roughly like this:

DEFAULT=$HOME/Maildir/
MAILDIR=$HOME/Maildir/
:0:
$MAILDIR

(Mine also has a TRAP, as touched on above re git.)

Boring. It could probably be one line, even.

The other procmailrc, ~/.procmail/finalrc , is your real procmail rules. If you have an existing ~/.procmailrc, move it to this new place. Here’s an interesting snippet from mine:

DEFAULT=$HOME/Maildir/
MAILDIR=$HOME/Maildir/
LOGFILE=/dev/null

# Friends
:0:
* ? formail -x"From" -x"From:" -x"Sender:" \
    -x"Reply-To:" -x"Return-Path:" -x"To:" \
        | fgrep -is -f ~/.procmail/friends.list                                 
friends/

# Android
:0:
*^TO_droids@lists.bostonandroid.org                                             
droids/

# Catch-all
:0:
$MAILDIR

But great; so far emails are landing in your inbox and just staying there. Next you add this to your ~/.muttrc :

macro index y '<enter-command>unset wait_key<enter><tag-prefix><pipe-entry>/usr/local/bin/procmail /usr/home/mike/.procmail/finalrc<enter><tag-prefix><delete-message><enter-command>set wait_key<enter>'
macro pager y '<enter-command>unset wait_key<enter><pipe-entry>/usr/local/bin/procmail /usr/home/mike/.procmail/finalrc<enter><delete-message><enter-command>set wait_key<enter>'

When you’re done reading an email press y . This will pipe that email through the ~/.procmail/finalrc and delete it from your inbox, moving onto the next email.

Advertisements
%d bloggers like this: