[Mailman-Users] Filter for exact domain names
Mark Sapiro
mark at msapiro.net
Sat Dec 13 18:42:13 CET 2008
Cyndi Norwitz wrote:
>I am getting a lot of spam post attempts from a domain tom.com. I
>would like to do an automatic discard in discard_these_nonmembers for
>this domain.
>
>I can add this line of code: ^[^@]+@(.*\.)?tom\.com$
>
>But I am concerned that this will discard all .com domain names that
>end with tom, which may be some legit ones.
It won't
>I do not understand the code as it's different from anything I've
>worked with and the above recipe (which I mucked up several times on
>my own despite some trips to the FAQ) came from Mark. My guess is I
>need to remove the question mark, but I'd like confirmation first.
It you remove the question mark, the regexp will match only sub-domains
of tom.com. I.e., it will match x at y.tom.com, but not x at tom.com. As it
is, it will match either of those, and it won't match x at tomtom.com
because the piece preceding tom.com doesn't end with a period.
Here's what it says:
^[^@]+ matches the beginning of the line and 1 or more non-@
characters, so ^[^@]+@ matches everything up to the first @ as long as
there is at least one character before the @.
Then (.*\.)? matches 0 or 1 occurrences of anything that ends with a
literal period - the ? says 0 or 1 of the preceding.
Then tom\.com$ matches if the remainder ends with 'tom.com'.
So the whole regexp matches
at least one non-@ followed by @ optionally followed by anything that
ends with a period followed by tom.com at the end.
See <http://docs.python.org/library/re.html>.
--
Mark Sapiro <mark at msapiro.net> The highway is for gamblers,
San Francisco Bay Area, California better use your sense - B. Dylan
More information about the Mailman-Users
mailing list