Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:.* matching both and

Is this possible, and if so, how?

share|improve this question

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

* ^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.

share|improve this answer
Nope. I used that exact syntax, and email from that address skips that rule and goes right down to the next procmail rule. Why is it so hard to just match a single email address with a procmail rule ? – user227963 Jul 21 '14 at 22:40
@user227963 It's not actually hard at all, unless you have unchecked assumptions. Commin such assumptions are that the regex ^From: will somehow magically also match some other common sender headers, or that the email regex will somehow match an address in a different format which actually doesn't match the regex you used. But post a new question with the details of your problem and we can take a closer look. – tripleee Jul 22 '14 at 3:55
Incidentally, by commenting here, you will reach approximately two readers (me and the OP); a new question will reach a significantly larger number of eyeballs. – tripleee Jul 22 '14 at 3:57

The .* is what is matching the additional characters. You only need to match spaces after the header name, so you can change this to *.

* ^From: *

I suspect that it may also be possible to anchor the end of the header to avoid matching additional characters at the end, but I haven't tested this myself.

* ^From: *$
share|improve this answer
That will fail to match From: John Gordon <> or (in the latter case) From: (John Gordon) but this old format is no longer very widely used. – tripleee Jul 22 '12 at 19:54

I'm a bit confused. You should have a procmail for each user. If you folded them into the same one, that's the problem. Of course, Unix can handle it! Just tell it how to handle it. Keep in mind that it flows down. So you can squash things as they come in. Hook the bjgordon first.

* To:

* To:

If you want it to survive a rule use the carbon copy rule:

:0 c:
* From: root <>
root_foo_mail.`date +%y%m%d`
share|improve this answer
I'm trying to use the 'From:' header, that's probably where your confusion comes from? – datadevil Jul 2 '12 at 13:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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