So if you've seen/used mailman , you'll know that it will add a [groupname] tag to the subject line of emails sent through it, if the tag doesn't already exist.

Can this be done with procmail?

I have my email machine at home running exim. I have a few email aliases that simply forward email to me, or sometimes to me and my wife.

It would be really nice if those emails has a subject tag that I can easily use to search/filter those emails. Something similar to mailman having [groupname] in the subject header, but I don't want/need all of the features of mailman.

Please note that my email client will not do this. I'd really want/need/like to do it in the email server.


You basically need shell access on the mail server in order to run Procmail there. If you do have the required privileges, doing what you are asking is simple, though your requirements are mildly unclear.

I'll assume that you want to add [groupname] to messages from groupname-list@example.net if it's not already present.

*   ^From: groupname-list@example\.net\>
* ! ^Subject:( Re:)? *\[groupname]
*   ^Subject:\/.+
| formail -I "Subject: [groupname]$MATCH"

The f flag says to modify the header by filtering through the pipeline in the action; the h means the action applies to the header only (to reduce the amount of data to copy unmodified back and forth); and the w says to check that the action is successful.

The \/ special regex token causes the match after it to be captured to the special variable MATCH.

Because dot and left square bracket are regex metacharacters, we need a backslash to match them literally. The \> word boundary ensures that net is not a partial match in a longer address (say ...@example.netcom.whatever) though it's not entirely foolproof (it would still match on ...@example.net.uk for example).

Anyway, you'll need to replace the first condition with something which matches exactly on a header in the messages you are targeting. For example, the one here doesn't match From: List Name <groupname-list@example.net> (because the regex doesn't contain an expression to skip the text up through the < character).

The rest should be trivial to understand, I hope.

  • I removed some speculative text about how to set up the pipe in Exim. I googled for a bit and my speculations seem to be way off. – tripleee Jul 16 '16 at 15:22
  • My request wasn't as clear as it could have been. But I think you gave me the pointer I need to figure out what I'm trying to do. The only real difference is I'm basing it on the To: address, not the From: address. Let me try it out ... – hymie Jul 17 '16 at 1:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.