Bill Lovett

Getting Procmail to Set Maildir Messages as Read

Posted on May 11th, 2006

Setting a newly arrived email message's status as Read can be a helpful way of dodging psychological baggage. As the volume of messages goes up, you're more likely to see a folder full of Unread messages as an obligation to get caught up-- even if the folder in question is the one you filter low-priority or no-priority messages into.

How much of an issue this is depends on the program you use to read your mail and the extent of filtering you do on your messages. I recently started using M2, the email program built into the Opera browser. I set up an IMAP account with it, and it gives me an unread count on all my messages. Including an unread count on my spam folder, and the folder I drop feed messages into (I use a service that turns feeds into email messages). Not helpful. Annoying, actually. To restore the cosmic balance of having no Unread messages as far as the eye can see, I was starting to hit the "Mark as as read" button on those messages a bit too manically.

Procmail can help out here. More than just funneling messages into folders, it can also flag those messages as Read. When you drop by with your email client of choice, it thinks those messages you've never technically laid eyes on before have already been seen. Taken from a thread on the procmail mailing list, here's how:



:0
* conditions
{
  foldername=whatever

  :0c
  .$foldername/ # stores in .$foldername/new/

  :0
  * LASTFOLDER ?? /\/[^/]+$
  { tail=$MATCH }

  TRAP="mv $LASTFOLDER .$foldername/cur/$tail:2,S"

  HOST
}

Earlier messages in the thread mention the equivalent (and simpler) approach for handling messages stored in mbox files.

Back to the index of all blog entries