emailwebmailprocmailmaildir

How To Mark All Emails As Read In A Specific Folder Using Procmail Filter


Currently I have a filter in Procmail to place any emails with the subject WJZGGZ inside of a specific folder called Instantly Warmups.

This is how it looks like in the procmail configuration file:

:0
* ^Subject: .*WJZ4GGZ.*
"$HOME/.Maildir/.Instantly Warmup/"

But how do I add a filter in procmail to automatically mark all the emails inside this specific folder as read?

All emails in other folders should remain unchanged. In other words, if you provide a solution to my problem unread emails in my inbox folder should remain unread.


Solution

  • What works entirely depends on how your email client manages message status. Some legacy ones (vaguely IIRC Elm?) store the flags in the message headers, and then you can store the read status there; but other than that, it can't be done - Procmail only gives you access to the actual message at delivery time, not its metadata after delivery.

    There may be mechanisms outside of Procmail, and then of course, you could run them from within a Procmail recipe. For example, if you know where a message was delivered, and you have a command to separately mark it as read given its ID, you can run that as an external command from within Procmail.

    :0
    | msgstore --tell-me-the-uid --message-from-stdin --uid-to-stdout | \
      xargs msgflags --mark-as-read
    

    (These commands don't exist, but you might be able to find commands which perform the described actions for your particular type of mailbox store. The first one delivers a message and tells you where it was delivered, and the second marks the identified message as read.)

    For Maildir in particular, the message flags are stored as part of the file name. I'd be hesitant to recommend that you actually do this, but in brief, if you have delivered a message in .Maildir/.Folder/new/deadbeef, you could move it to .Maildir/.Folder/cur/deadbeef:2,S. Perhaps see also https://en.wikipedia.org/wiki/Maildir

    (This begs the question, why do you even care about the status of these messages? A much better solution would seem to be to ignore this folder so it's not displayed in your regular folder listing if you don't care about the messages there.)