procmail

Procmail rule to change subject and forward a copy


I have an existing procmail recipe to forward a copy to my gmail account that is working well:

:0c
! myAddress@gmail.com

I have a second rule that is also working well (in limited testing) to prefix the subject with [OLD DOMAIN]:

:0fwh
* (To|Cc).*oldDomain.com
* ^Subject:\/.+
| formail -I"Subject: [OLD DOMAIN]$MATCH"  

The issue is in my local email account I get the modified subject as expected, but not in my gmail account. How can I combine these rules or modify the forward and copy rule to change the subject?


Solution

  • Just reverse their order; make sure the one which rewrites the subject runs before the one which forwards a copy to Gmail.

    Procmail simply processes your .procmailrc from top to bottom for each incoming message, and stops processing it once a (non-cloning) delivering action is successful. The c flag says to clone the message (so, even though the clone is successfully delivered, continue processing the original copy).

    As an aside, the regex for (To|Cc) should probably have a ^ anchor in front, unless you specifically want to match the text anywhere in a header line.