Mutt Maildir Caching

Header caching

 mkdir ~/.muttcache
 echo "set header_cache=~/.muttcache/" >> ~/.muttrc

As easy as that. Why didn't I do this earlier?

Well, I decided that it sucks and turned it off. The indexes take up an incredible amount of disk space and it actually seems to make mailbox accesses much slower as it seems to rebuild it from scratch whenever a change is made, and naturally this is slower than just loading the whole thing, especially after I moved mutt to a faster machine.

Since that was a let-down, here's a better tip:

 folder-hook SPAM 'set sort=reverse-date-received'

The date on spam is occasionally set way in the future, so my normal sort-by-date means that the same old spam always appears at the top of the list and I'm less inclined to actually look at new messages. This sorts my spam folder more sensibly and is, for now, the next best thing to a 'sort with unread first'.

Spam control

While I'm on the topic of spam, here's what I do to control mine.

I used sendmail with SpamAssassin and spamass-milter, the latter configured using Debian's instructions. I was using procmail to /dev/null very spammy (score 15+) messages and since I'm blissfully unaware of any false positives, I configured spamass-milter to reject these at SMTP time in /etc/default/spamass-milter. I even cranked down the threshold as well! Considering I don't bother looking at spam too closely anymore, I reckon it's safe to lower the threshold to anything reasonable when you're rejecting things rather than binning them, though it's hard to know whether you should just bin them and prevent back-scatter when an innocent relay is involved. Actually, binning them is probably better but there's something satisfying about rejecting mail and if someone does send a legitimate but spammy-sounding email, they'll hear about the rejection this way.

 OPTIONS="-r 12"

This also has the classy bonus that I no longer have to set per-user procmail spam dropping rules.

Spam macros

Since I mostly use mutt, it's easy to classify messages as soon as I find them. In .muttrc:

 macro pager S "<enter-command>unset wait_key\n<pipe-entry>sa-learn --single --spam \n<enter-command>set wait_key\n<save-message>=.SPAM\n"
 macro index S "<enter-command>unset wait_key\n<pipe-entry>sa-learn --single --spam \n<enter-command>set wait_key\n<save-message>=.SPAM\n"
 macro pager H "<enter-command>unset wait_key\n<pipe-entry>sa-learn --single --ham \n<enter-command>set wait_key\n"
 macro index H "<enter-command>unset wait_key\n<pipe-entry>sa-learn --single --ham \n<enter-command>set wait_key\n"

It would be nicer if the command would pipe all messages to one instance of sa-learn, which would make this a bit faster. It's probably quite easy, but I just stole this from elsewhere and haven't been too bothered about it.

I've since given up on this because it takes too long (a few seconds). Instead, I just mark the spam as not-new and move it to my spam folder using these commands:

 macro pager S "<clear-flag>N<save-message>=.SPAM\n"
 macro index S "<clear-flag>N<save-message>=.SPAM\n"

SpamAssassin learning

Learning takes place automatically using a set of cron jobs. To automatically train SpamAssassin with ham, I set up a cron job that looks in cur folders (ie, things I've seen)

 0 2 * * * find /home/joel/Maildir/.saved/cur/ /home/joel/Maildir/.uni/cur/ -type f -mtime -2 -print | xargs sa-learn --ham  > /dev/null

And another that classifies things as spam if I've seen them and didn't move them to non-spam. This is done because it won't auto-learn off messages it thinks are spammy but doesn't know for sure. I assume that I'll immediately move spammy messages upon seeing them.

 5 2 * * * find /home/joel/Maildir/.SPAM/cur/ -type f -mtime -2 -print | xargs sa-learn --spam > /dev/null

Automatic monthly spam folder

Because some folders (such as spam) eventually get enormous and mutt takes an increasingly longer time to open them, I've set up a simple script to store them by month.

In crontab:

 0 0 1 * * /home/wherever/update-spam-link.sh

The script:

DATE=`date +%y-%m`
rm /home/joel/Maildir/.SPAM > /dev/null
/usr/bin/maildirmake.dovecot /home/joel/Maildir/.SPAM-$DATE
ln -s /home/joel/Maildir/.SPAM-$DATE /home/joel/Maildir/.SPAM

This means that the SPAM folder is always a symbolic link to the current month's SPAM-xx-xx folder, which means that the mutt macros above don't need to change depending on the date.

Message searching

The other thing I like doing with mutt is using Mairix for full-text indexing. Dovecot can also do full-text indexing, but I don't use mutt with IMAP.