On 03/31/2011 08:41 AM, Corey Quinn wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Mar 30, 2011, at 2:08 PM, Noel Jones wrote:
On 3/30/2011 3:53 PM, Ansgar Wiechers wrote:
On 2011-03-30 Corey Quinn wrote:
On Mar 30, 2011, at 12:46 PM, Noel Jones wrote:
# main.cf
smtp_generic_maps =
regexp:/etc/postfix/generic.regexp
# generic.regexp
IF /+.*@example\.com$/
/^(.*)+/ $1...@example.com
ENDIF
Threw this verbatim into my generic.regexp:
[root@mx1 postfix]# postmap -q "user+t...@example.com" regexp:generic.regexp
postmap: warning: regexp map generic.regexp, line 1: Invalid preceding regular
expression
postmap: warning: regexp map generic.regexp, line 4: ignoring ENDIF without
matching IF
user+t...@example.com@example.com
On the plus side, I figured out how to do something interesting by
reading through the regexp documentation-- this solved another
challenge I'd been facing.
'+' has a special meaning in regular expressions (one or more times the
preceding term), so you need to escape it to match a literal '+':
if /\+.*@example\.com$/
/^(.*)\+/ $1...@example.com
endif
Regards
Ansgar Wiechers
that's what I get for posting an untested example and then walking away for a
little while.
Escaping the "+" fixes the expression to what I intended.
Thanks everyone for cleaning up after me.
Thanks-- that sorted it, and now I'm able to say I learned two new things about
regular expressions today.
Only several thousand left to go.
I don't know if this is limited to PCRE or usable in regexp too, but the
above would match joe++++foo, and return joe+++ due to the greedy (.*).
To avoid such edge-cases:
/^([^+]+)\+[^+@]+@example.com/ $1...@example.com
That is, one or more of not a plus sign, followed by a plus sign,
followed by one or more of not a plus nor an @.
This would capture the first alpha-numeric sequence not including a
plus, and completely ignore non-delimited addresses (since they don't
contain a plus sign) and odd addresses that contain pluses but aren't
delimited by one.
--
J.