[Mailman-Users] filtering based on message content

Mark Sapiro mark at msapiro.net
Mon Jul 5 20:16:08 CEST 2010

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():
        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

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

More information about the Mailman-Users mailing list