About Archive Tags RSS Feed

 

Delivering to a Maildir folder, but marking as read

25 October 2010 21:50

Email. We get a lot of it. We filter out the SPAM. Then if we're well-organized we file it away into folders as it arrives. (To be fair some people use priority settings such that all mail stays in their INBOX until they're "done" with it. I've never had the patience for that kind of behaviour.)

One problem which I often encounter is wanting to have email be delivered, archived, and stored, but I don't want to read it. Yet when I see a folder in my mail client which has unread mail in it I cannot unsee.

In my case I deliver mail to folders as it arrives via either Exim's filter language, or procmail. Procmail blows goats on the whole, but it is common and available everywhere - I just don't trust my own DSL enough to rely upon it (which is a dangerous sign).

So, how do you deliver a new mail to a Maildir folder, and mark it read at the same time? Well you can be naïve and do what I did which is to invoke formail to add "Status: ro" to the header. Unfortunately that's insufficient to mark a mail as read when viewed in mutt.

When an email is stored in a Maildir folder its status is encoded in part of its filename - which is why you'll have files like:

new/1288039894.28406_3.steve.org.uk
cur/1283711971.11157_3.skx.xen-hosting.net:2,S

The latter file has been Seen. So to mark a message as not-new you need to do two things:

  • Save it to ./cur/ not ./new/.
  • Append the appropriate flags to the filename (generally :2,S).

I've seen some horrific shell + procmail code to do the job, but the simpler version is:

:0
*^(To:|From:).*root@
*^X-added-header:.*debian-administration.org
| ~/bin/read-to-maildir .machines.debian-administration.org/

Similarly you can use Exim's filter language to do the same job:

# Exim filter
if $h_to: contains "hostmaster@" then
    pipe "/home/skx/bin/read-to-maildir /home/steve/Maildir/.hostmaster/"
finish

Cute. Obvious too? Maybe not to me.

ObSubject: Why did you murder someone, Raymond? - In Bruges

| 4 comments

 

Comments on this entry

icon Christoph Anton Mitterer at 22:32 on 25 October 2010

Would love to see a real solution for the same problem in maildrop's filtering language... something like a "to_read" command or so...

Asked upstream a year ago or so,... but probably nothing happens... :(

icon Glennie Vignarajah at 09:47 on 26 October 2010
http://www.glennie.fr

Hi,
Exim supports sieve filtering language. You can use sive to mark your mail as read. I use 'addflag "\\SEEN" ;' to mark mail as read (under cyrus imap ; perhaps, this sould be doable under exim too)
HTH

icon FooBar at 15:45 on 26 October 2010
http://www.sig-io.nl

And pray tell... where would I find (~/skx/bin/)read-to-maildir ... doesn't seem to be in any standard debian package.

icon Steve Kemp at 16:17 on 26 October 2010
http://www.steve.org.uk/

It's a shame that sieve doesn't support such a primitive. On my two main machines I mostly use either Dovecot or nothing - just raw access to ~/Maildir via mutt so cyrus is out.

As for the implementation mostly it's a matter of making a temporary file in the appropriate directory and renaming. Seems a little too trivial to post - but as I was writing this entry I did find this implementation: