Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

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.

:0
* To: bjgordon@example.com
bjgordon_file


:0
* To: jgordon@example.com
jgordon_file

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

:0 c:
* From: root <root@foo.bar.com>
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

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: *jgordon@example.com

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

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.

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 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 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 at 3:57

Your Answer

 
discard

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.