[Mailman-Users] Content filtering mail body

Mark Sapiro mark at msapiro.net
Sat Mar 31 19:53:20 CEST 2012


dhanushka ranasinghe wrote:
>
>is it possible  to  filter and reject any mails that have certain words in  them


Yes, it is but it requires a custom handler to examine the message body
and take appropriate action. See the FAQ at
<http://wiki.list.org/x/l4A9>

The handler you want is fairly simple. A basic outline is


import re
from Mailman import Errors
from Mailman import Utils

# Compile re to match words with flags like IGNORECASE, etc as desired.
CRE = re.compile('re_that_matches_your_words', re.IGNORCASE)
# Rejection message if we're rejecting.
MESSAGE = Utils.wrap("""Some nice message as to why
the message is being rejected.""")

def process(mlist, msg, msgdata):
    for part in msg.walk():
        if part.get_content_maintype() == 'text':
            if CRE.search(part.get_payload(decode=True)):
                raise Errors.RejectMessage , MESSAGE
                # or raise Errors.DiscardMessage if you want to
                # just discard it.


-- 
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