[Mailman-Users] filtering based on message content
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:
from Mailman import Errors
from Mailman.Handlers.Hold import hold_for_approval
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():
hold_for_approval(mlist, msg, msgdata, BadWords)
new file lists/testlist/extend.py:
from Mailman import mm_cfg
mlist.pipeline = copy.copy(mm_cfg.GLOBAL_PIPELINE)
# The next line inserts MyHandler ahead of Moderate.
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
> >lists based on the message content. Specifically, the request is to hold
> >messages containing the third of George Carlin's seven words (and
> >by extension also the sixth), which a couple of our subscribers seem to
> >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():
> 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
> >to hold messages that have the spam flag set. But that seems like kind of
> Perhaps, but it is probably easier to manage.
> >Actually, I take that back. My first thought was to just ban the
> >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 at clemings.com>
National Association of Science Writers cybrarian:
<cybrarian at nasw.org>
More information about the Mailman-Users