[Mailman-Users] Reject non-member postings.

Dan Mick Dan.Mick at west.sun.com
Thu Jan 18 02:48:00 CET 2001


OK, well, this seems to work.  I hacked up SpamDetect.py into
a new module, grabbed code from Hold.py to get the sender and
look for the member_posting_only option, and do a similar
rejection trick to SpamDetect for throwing the message away.
It also logs a message to ~mailman/logs/discard
every time it rejects a non-subscriber post, so you can see that it's
working.

Add the following file to ~mailman/Mailman/Handlers/ as 
RejectNonSub.py.

Then enable the feature by editing HandlerAPI.py (in the same directory)
and adding RejectNonSub to the beginning of LIST_PIPELINE, so it
looks like this:

LIST_PIPELINE = ['RejectNonSub',
                 'SpamDetect',
                 'Approve',
                 'Replybot',
		.
		.
		.

If you want to disable the feature, just remove the RejectNonSub from 
LIST_PIPELINE (or save a backup copy of HandlerAPI.py and just restore
it).

Here's RejectNonSub.py.  As always with Python, indentation is important.

# Copyright (C) 1998,1999,2000 by the Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software 
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

"""Do immediate rejection of non-subscriber posts for lists 
with member_posting_only set.

"""

import HandlerAPI
import string
from Mailman import Utils
from Mailman.Logging.Syslog import syslog

class NonMemberDetected(HandlerAPI.DiscardMessage):
    """The message was posted by a non-subscriber"""

def process(mlist, msg, msgdata):

    listname = mlist.internal_name()
    adminaddr = listname + '-admin'
    sender = msg.GetSender()
    # Special case an ugly sendmail feature: If there exists an alias of the
    # form "owner-foo: bar" and sendmail receives mail for address "foo",
    # sendmail will change the envelope sender of the message to "bar" before
    # delivering.  This feature does not appear to be configurable.  *Boggle*.
    if not sender or sender[:len(listname)+6] == adminaddr:
        sender = msg.GetSender(use_envelope=0)

    if msgdata.get('approved'):
        return

    if mlist.member_posting_only:
        posters = Utils.List2Dict(map(string.lower, mlist.posters))
        if not mlist.IsMember(sender) and \
           not Utils.FindMatchingAddresses(sender, posters):
            # the sender is neither a member of the list, nor in the list of
            # explicitly approved posters
            syslog('discard', 'mail to %s from non-subscriber %s discarded' \
               % (listname, sender))
            raise NonMemberDetected

> I would love to have this option (but can't help with the Python coding, not
> knowing Python).
> 
> Gary
> 
> ----- Original Message -----
> From: "Dan Mick" <Dan.Mick at west.sun.com>
> To: "Evilio del Rio" <edelrio at icm.csic.es>
> Cc: <mailman-users at python.org>
> Sent: Wednesday, January 17, 2001 5:05 PM
> Subject: Re: [Mailman-Users] Reject non-member postings.
> 
> 
> 
> 
> Evilio del Rio wrote:
> >
> > Hello,
> >
> > Is there any way to configure a list to ALWAYS reject ANY non-member
> > posting to a restricted list. I do not want them to be held for approval,
> > just reject, full stop.
> 
> Adding header patterns to SpamDetect.py is one way, although not trivial.
> Adding "check for list membership" wouldn't be that hard, but it would
> take some actual Python coding.  I could see if I could hack something
> like that up if there were sufficient interest.
> 
> Proposal: a modification to SpamDetect.py to auto-reject, with no
> reply message, mail from non-subscribers (on lists with "subscriber posting
> only" set).  Anyone besides Evilio dying for this?
> 
> ------------------------------------------------------
> Mailman-Users maillist  -  Mailman-Users at python.org
> http://mail.python.org/mailman/listinfo/mailman-users
> 
> 
> 
> ------------------------------------------------------
> Mailman-Users maillist  -  Mailman-Users at python.org
> http://mail.python.org/mailman/listinfo/mailman-users






More information about the Mailman-Users mailing list