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 "[EMAIL PROTECTED]", or
"[EMAIL PROTECTED]".  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 "[EMAIL PROTECTED]", 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                [EMAIL PROTECTED]
MEMS Exchange                            http://www.mems-exchange.org

------------------------------------------------------
Mailman-Users maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/mailman-users

Reply via email to