0

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?

datadevil
  • 535
  • 1
  • 7
  • 22

3 Answers3

1

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.

tripleee
  • 1,416
  • 3
  • 15
  • 24
  • 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 03: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 03:57
0

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`
mgorven
  • 30,615
  • 7
  • 79
  • 122
0

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$
mgorven
  • 30,615
  • 7
  • 79
  • 122
  • That will fail to match `From: John Gordon ` 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