Perform an exact match on the email address in From: header using procmail

procmail

I have found a lot of examples for procmail to match on the From: header with wilcards, but I'd like to do an exact match, in order to prevent From:.*jgordon@example.com matching both jgordon@example.com and bjgordon@example.com

Is this possible, and if so, how?

Best Answer

The customary procedure is to add word boundary anchors on both sides of the target address.

:0
* ^From:(.*\<)?jgordon@example\.com\>
...

If you want to match exactly two email addresses and no others, craft a regular expression which will only match those two. In your specific example, b?jgordon@example\.com will match both bjgordon and jgordon. A common similar pattern is to want to match both firstname.lastname and flastnam; a pattern for that would be (firstname\.lastname|flastnam)@example\.com.