Mutt: unsubscribing from mailing-list threads

As a Free Software enthusiast, I take part in a lot of mailing-lists. To browse the messages (and to read my personal mail, too), I use mutt. This article describes a trick to make your mutt experience more enjoyable: a way to unsubscribe from specific mailing-list threads.

The problem

When downloading mailing-list messages, we are often confronted with threads we deem interesting and threads which are not. The immediate solution is to delete unwanted messages, like so:

1     May 05 To debian-user@ (0.7K) Interesting and useful thread
2  D  May 05 To debian-user@ (1.2K) Flame, boring thread

The issue is not solved, though. We deleted that particular message, but other people may have replied to it. The next time we are going to fetch e-mails, those replies will be there, forcing another deletion:

1     May 05 To debian-user@ (0.7K) Interesting and useful thread
2     May 05 Cc debian-user@ (0.8K) ├─>
3     May 05 To Debian User  (4.2K) └─>
4  D  May 05 To debian-user@ (4.1K) Re: Flame, boring thread
5  D  May 05 To debian-user@ (2.8K) └─>
6  D  May 05 To debian-user@ (0.7K)   └─>

And again, and again, and again. Heated discussions can lead to nested threads (visit the emacs-devel archives to check yourself). Alas, there is no way to “unsubscribe” from a specific mailing-list thread (like you would in a forum); you can unsubscribe to the list itself, but then you would be entirely cut off from the communication.

Soon you will get tired of pressing <C-d> to weed out those messages:

1      May 05 To debian-user@ (0.7K) Interesting and useful thread
2      May 05 Cc debian-user@ (0.8K) ├─>
3      May 05 To Debian User  (4.2K) └─>
4      May 06 To debian-user@ (3.4K)   └─>
5   D  May 06 Cc debian-user@ (1.7K) Re: Re: Re: the never-ending, obnoxious flame thread
2   D  May 06 Cc debian-user@ (1.1K) ├─>
6   D  May 06 To debian-user@ (2.8K) └─>
7   D  May 06 To debian-user@ (0.7K)   └─>
8   D  May 06 To debian-user@ (1.1K)     └─>
9   D  May 06 To debian-user@ (5.0K)       ├─>
10  D  May 06 To debian-user@ (7.6K)       └─>
11     May 06 To haskell-cafe (1.3K) [Haskell-cafe] Functional programming blues

The solution

Instead of setting up a complex scoring system (with procmail or other mail processors), we can take advantage of mutt pattern matching capabilities:

macro index <Esc>d "<delete-pattern>~l~N(!~(!~x.+))(!~(~F))<enter>"

Place this in your .muttrc. This is a <delete-pattern> macro, which means that it will bulk delete messages that will match the expression. Let us examine this bit by bit:

When you press <Esc>d, messages stemming from threads you were not interested in will be marked for deletion. The macro will leave new threads and old, undeleted threads untouched.

Grouping annoyances

Be careful on how how threads are grouped! With strict_threads=no, mutt will make use of In-Reply-To/References headers to group messages together and by default, messages with the same subject will be grouped together in the same “pseudo-thread”.

475     Aug 25 To help-gnu-ema (0.4K) Gist: get output of an external program on region
476     Aug 26 To help-gnu-ema (  15) └*>
477     Aug 25 To help-gnu-ema (1.2K)   └─>

Everything ok.

See the second messages? It lacked In-Reply-To (probably fell victim to some clobbering agent) but it is still correctly shown in the same thread (with an asterisk) because it shares the same Subject.

Now let’s see what happens with strict_threads=yes:

475     Aug 25 To help-gnu-ema (0.4K) Gist: get output of an external program on region
476  D  Aug 26 To help-gnu-ema (  15) Re: Gist: get output of an external program on region
477  D  Aug 25 To help-gnu-ema (1.2K) └─>

Woops!

Now the last two messages are considered a different, “head-less” thread and hence marked for deletion! This might lead to unwanted removal of interesting e-mails!

My suggestion to you is to turn strict_threads off; it will save you from the above mentioned problems and, if you want, you can fine-tune its behaviour by tweaking $sort_re setting.

Further reading

Coping with busy mailing lists is not an easy task; Debian Developer Joey Hess’ Thread patterns has more tongue-in-cheek tips on how to sever the wicked from among the just.