[Mailman-Users] filtering based on message content

Russell Clemings rclemings at gmail.com
Sun Jul 11 18:25:08 CEST 2010


Thanks. For the archives, this appears to work on a list named "testlist"
...

new file Mailman/Handlers/MyHandler.py:

import re
from Mailman import Errors
from Mailman.Handlers.Hold import hold_for_approval

class BadWords(Errors.HoldMessage):
   reason = 'Message has bad words'
   rejection = 'Your message contains forbidden words.'

BADWORDS = re.compile(r'(\W|^)word3(\W|$)|(\W|^)word6(\W|$)', re.I)

def process(mlist, msg, msgdata):
   for part in msg.walk():
       if part.is_multipart():
           continue
       if BADWORDS.search(part.get_payload(decode=True)):
           hold_for_approval(mlist, msg, msgdata, BadWords)



new file lists/testlist/extend.py:

import copy
from Mailman import mm_cfg
def extend(mlist):
  mlist.pipeline = copy.copy(mm_cfg.GLOBAL_PIPELINE)
  # The next line inserts MyHandler ahead of Moderate.
  mlist.pipeline.insert(mlist.pipeline.index('Moderate'), 'MyHandler')

rac

On Mon, Jul 5, 2010 at 11:16 AM, Mark Sapiro <mark at msapiro.net> wrote:

> Russell Clemings wrote:
>
> >I've had a request from the boss to filter incoming messages to some of
> our
> >lists based on the message content. Specifically, the request is to hold
> all
> >messages containing the third of George Carlin's seven words (and
> presumably
> >by extension also the sixth), which a couple of our subscribers seem to
> find
> >suitable for use in any context.
> >
> >My first thought, not contradicted by a quick FAQ search, was that there's
> >no way Mailman can do this on its own, at least without hacking core,
> >because it's not scanning the whole message.
>
>
> Yes, and no depending on what you mean by "hacking core" (or is that
> "hacking code"?).
>
> The relevant FAQ is <http://wiki.list.org/x/l4A9>.
>
> The handler could be as simple as
>
> import re
> from Mailman import Errors
> from Mailman.Handlers.Hold import hold_for_approval
>
> class BadWords(Errors.HoldMessage):
>    reason = 'Message has bad words'
>    rejection = 'Your message has contains forbidden words.'
>
> BADWORDS = re.compile(r'(\W|^)word3(\W|$)|(\W|^)word6(\W|$)', re.I)
>
> def process(mlist, msg, msgdata):
>    for part in msg.walk():
>        if part.is_multipart():
>            continue
>        if BADWORDS.search(part.get_payload(decode=True)):
>            hold_for_approval(mlist, msg, msgdata, BadWords)
>
>
>
> >My second thought was that Spam
> >Assassin could be set to flag the offending messages; Mailman is already
> set
> >to hold messages that have the spam flag set. But that seems like kind of
> a
> >kludge.
>
>
> Perhaps, but it is probably easier to manage.
>
>
> >Actually, I take that back. My first thought was to just ban the
> offenders.
> >But that's not going to fly.
>
>
> Too bad.
>
> --
> Mark Sapiro <mark at msapiro.net>        The highway is for gamblers,
> San Francisco Bay Area, California    better use your sense - B. Dylan
>
>


-- 
============================================
Russell Clemings
<russell at clemings.com>
National Association of Science Writers cybrarian:
<cybrarian at nasw.org>
============================================


More information about the Mailman-Users mailing list