[Mailman-Users] Quick spam regex question

Mark Sapiro msapiro at value.net
Wed Jul 19 01:55:44 CEST 2006


Jason LaMar wrote:

>Thanks for helping me out with this. As a follow-up question, because
>(obviously) I'm a regexp newbie: If I wanted to use this statement as a
>basis ...
>
>\nfrom:[^@]*@(?!fubar.com[>\s])
>
>... BUT I also wanted to allow messages from any fubar.com sub-domain
>(mail.fubar.com, as an example), how should I modify this regexp to
>accommodate that? If it would make it any easier, the specific (additional)
>sub-domain I would need would be cc.fubar.com.


Actually, my original regexp is not quite right. In practice it
probably makes no difference, but fubar.com in the above will also
match and accept fubarxcom or fubarzcom, etc. since . matches
anything, but since without an actual ., it wouldn't be a valid
domain, it really doesn't matter. The strictly correct version of the
above is

\nfrom:[^@]*@(?!fubar\.com[>\s])

i.e, put a \ in front of the . to make it match literally a .

For fubar.com and cc.fubar.com, you could use

\nfrom:[^@]*@(?!(cc\.)?fubar\.com[>\s])

which will match 0 or 1 'cc.' followed by fubar.com or you could use

\nfrom:[^@]*@(?![^@>\s]*fubar\.com[>\s])

which will match 0 or more of any single character except @, > or white
space followed by fubar.com.

There are lots of other ways to do this too, but those should get what
you want.

A different approach which is more flexible for adding more domains is
to have a series of 'accept' rules each matching a simple pattern (or
one accept rule with multiple patterns) followed by a discard rule
that matches anything. E.g., in the accept rule put

\nfrom:[^@]*@fubar\.com[>\s]
\nfrom:[^@]*@cc\.fubar\.com[>\s]

and in the discard rule just put

^

(which will match at the beginning of the headers string and thus will
match any message at all and discard any message that wasn't matched
in the preceding rule(s)). Then you can easily add additional patterns
to the accept rule if it becomes necessary to accept additional
domains.

-- 
Mark Sapiro <msapiro at value.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