[Mailman-Users] Negative regular expression for deny list

Greg Ward gward at mems-exchange.org
Tue Oct 9 20:44:25 CEST 2001


On 08 October 2001, Jonathan Vafai said:
> I want to restrict one of my mailing lists to only messages coming from
> a single domain.  ( The reason for this is that my users are
> automatically subscribed, but have multiple email addresses within my
> domain that they'll be posting from.)

Oooh, fun regex problem!

> Therefore, what I want to do is only accept emails from ".*@.*nyu.edu".

Not quite.  You want to accept emails from addresses that match
  .*@(.+\.)?nyu.edu$
Your regex would accept messages from "foo at xynu.edu", or
"foo at nyu.edu.com".  Actually, to be even more strict, you only want to
accept messages from addresses that match
  [^@]+@([^@]+\.)?nyu.edu$
-- because there MUST be something before the "@" sign, and there may be
ONLY one "@" sign in an address.  (Actually, there's a specific
list of characters that are verboten in an email address, because they
are "special" characters in RFC 822.  So the localpart of the address
regex should probably be something like
  [\(\)\<\>\@\,\;\:\\\"\.\[\]]+
...but that's getting excessively anal-retentive.)

I will stick with the convenient fiction that ".+" is what your regex
should start with.

This should do the trick for you:
  .+@(?!(.+\.)?nyu\.edu$)

The ".+" matches any localpart.

"(?!...)" means, "match the preceding expression only if it's *not*
followed by the pattern in parentheses".  (*Python Essential Reference*,
2nd ed., p. 137.)

In this case, the "preceding expression" is ".+@", ie. any localpart
followed by "@".  The "negative match" part is for any nyu.edu domain,
as explained above.

Note that with the "$", this regex will match "foo at nyu.edu.com", meaning
you will deny senders from this domain.  Without the "$", that lame
attempt to fool your regex would work.

This double negative stuff makes my head hurt.  Maybe Mailman should
have a "sender accept" regex too.  ;-)

        Greg
-- 
Greg Ward - software developer                gward at mems-exchange.org
MEMS Exchange                            http://www.mems-exchange.org




More information about the Mailman-Users mailing list