[Mailman-Users] Mailman Spam Filters
mark at msapiro.net
Mon Feb 13 17:09:23 EST 2017
On 02/13/2017 01:01 PM, Barco van Rhijn wrote:
> Thanks for pointing out the fact that a pipe means or. I'm still quite
> new to regex but I'm learning quickly.
The '|' symbol has many names and meanings
<https://en.wikipedia.org/wiki/Vertical_bar>. It is only a pipe in the
context of interprocess communication. It is not appropriate to refer to
it as 'pipe' in other contexts.
> I've reviewed the page you reference on custom handlers.
> I've looked into the custom handler file and notice 'discard_pattern'
> after comment suggesting regex here >>
> # the message if more than one matches, the precedence is DISCARD over
> # REJECT over HOLD.
> DISCARD = re.compile(r'discard_pattern', re.IGNORECASE)
> REJECT = re.compile(r'reject_pattern', re.IGNORECASE)
> HOLD = re.compile(r'hold_pattern', re.IGNORECASE)
> # And if the following regexp matches the Subject: header, the message will
> # be unconditionally accepted.
> ACCEPT = re.compile(r'accept_pattern', re.IGNORECASE)
> 1. Am I right in assuming that I can replace the text discard_pattern'
> with python formatted regex?
> 2. Can I have multiple Discard, Hold,
> Reject or Accept lines?
You really need to have an understanding of Python in order to turn that
example into a useful handler for your purpose. If I understand
correctly, you want to create regexp matches to be applied to the
message text and discard the message if the regexp matches.
To do that, you could replace lines 38 through 49 of that example with
D1 = re.compile(r'\bbadword\b', re.IGNORECASE)
D2 = re.compile(r'\ba\s+bad\s+phrase\b', re.IGNORECASE)
and more D3, D4, etc. if you like
Then delete lines 52 through 59 and replace lines 64 through the end with
for cre in (
and as many more Dn as you've defined
Note that indentation in Python is significant. The above lines are
indented 12 spaces, 16 spaces and 20 spaces for the first, second
through sixth and seventh respectively.
That said, you really need to be comfortable with the tutorial at
<https://docs.python.org/2/tutorial/index.html> before you try to do this.
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