How to automatically mark stale threads for deletion.
I’ve moved back to mutt after being exiled to kmail, evolution, thunderbird and even gnus for the longest time. The only reason I left mutt in the first place was that I’d moved from POP to IMAP and mutt’s IMAP support was less than stellar at the time. That seems to have improved a lot since then and I’ve found out about some IMAP <-> maildir syncing programs. After some testing offlineimap came out as my winner. I haven’t bother to configure mutt to use IMAP. Using local maildirs instead I circumvent the entire IMAP-caching issue. Plus I have access to my mail when offline.
It turns out my favorite canine has learned some new tricks since I last saw her. Thread sorting is now more Gmail-ish, sorting threads not by the date of the oldest mail in the thread but by the most recent.
And I’ve learned about some new (new to me at least) cool matching functionality. It turns out you can match an entire thread by enclosing your pattern in a tilde and parenthesis. The pattern “~P” would normally match messages written by me, so the pattern “~(~P)” will match all messages in all threads where I’ve written at least one message.
Let me give you some…
… examples
Match threads I’ve participated in:
~(~P)
Match threads where I’ve flagged at least one message:
~(~F)
Match the opposite, ie threads where I haven’t flagged any messages:
!(~(~F))
You can logical AND conditions by separating them with a blank space, and logical OR conditions by separating them with a pipe.
Match all messages I’ve flagged OR written:
~F | ~P
Match all messages I’ve flagged AND written:
~F ~P
Match threads where I’ve flagged or written at least one message:
~(~F|~P)
Match the opposite, ie, threads I haven’t flagged or participated in
!(~(~F|~P))
The “~d” modifier will let you do date matching:
Match all messages that are more than 2 weeks old:
~d >2w
Match all threads where the at least one message is more than 2 weeks old:
~(~d >2w)
Now what do we get if we reverse that?
!(~(~d >2w))
Exactly what we’re asking for: All threads that contains no messages that are more than two weeks old. But what if we wanted to match threads not by their oldest message but by their most recent? Instead of using the lager than operator (>) we’ll use less than (<).
This will give us all messages written within the two last weeks:
~d <2w
And this will give us all threads with any activity within the last two weeks:
~(~d <2w)
And this will give us all threads that haven’t had any activity within the last two weeks:
!(~(~d <2w))
Now lets put all of that together and match all the threads that have been inactive for more than two weeks and contain no messages written or flagged by me:
!(~(~d <2w)) !(~(~P|~F))
The macro
That last pattern could make a pretty useful macro for my list folders. I’ve put this in my ~/.muttrc
macro index,pager
Now I just have to hit F7 and all stale threads that I’ve never showed any interest in will be marked for deletion.
0 Responses to “Cleaning out mail with mutt”
Leave a Reply