[Mailman-Users] Analog to remove_members for nomail?

Bret Mogilefsky mogul-mailman at gelatinous.com
Fri Oct 26 02:17:04 CEST 2001


On Thu, Oct 25, 2001 at 07:56:58PM -0400, Jon Carnes wrote:
> This is actually quite easy to do, but you will have to write your own
> scripts for it (or hire someone to do it for you), as this is not a function
> of Mailman.
> 
> Check out the command line scripts in ~mailman/bin/...
> 
> Run an hourly list of your active users out of /etc/passwd.  Compare the new
> list with last hours list.  If any folks are missing (or commented out),
> then use the Mailman command line scripts to look for what lists they belong
> to, and then remove them from those lists.
> 
> Easy to do.  Should take you two hours.

Actually, it only took me about fifteen minutes.  =) nomail_members is
attached.  I now use this in my SourceForge-based developer support site for
PlayStation2... When users' website access is suspended or deleted, I mark
them such on the website, and the PHP code sets them to nomail on all the
lists they belong to using find_member and nomail_members.  Similarly if
they're reactivated I run a nomail -r.  When suspended, they also lose
access to the mailman interface, and I catch admin requests... Works rather
nicely.  =)

Bret
-- 
Bret Mogilefsky * Mgr. SCEA Developer Support * mogul at gelatinous.com
-------------- next part --------------
#! /usr/bin/env python
#
# 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.
#
"""Turn off mail delivery for members in a list.

Usage:
    nomail_members [options] listname [addr1 ...]

Options:

    --file=file
    -f file
        Stop delivery to member addresses found in the given file.  If file is
        `-', read stdin.

    --all
    -a
        Stop delivery to all members of the mailing list.

    --reverse
    -r
        Reverse the effect of this command, i.e. ENABLE mail to the specified
        addresses.

    --help
    -h
        Print this help message and exit.

    listname is the name of the mailing list to use.

    addr1 ... are additional addresses to stop mailing.

"""

import sys
import string
import getopt

import paths
from Mailman import MailList
from Mailman import Errors
from Mailman import mm_cfg



def usage(status, msg=''):
    print __doc__ % globals()
    if msg:
        print msg
    sys.exit(status)


def ReadFile(filename):
    lines = []
    if filename == "-":
        fp = sys.stdin
    else:
        fp = open(filename)
    lines = filter(None, map(string.strip, fp.readlines()))
    fp.close()
    return lines



def main():
    try:
        opts, args = getopt.getopt(
            sys.argv[1:], 'raf:h', ['reverse', 'all', 'file=', 'help'])
    except getopt.error, msg:
        usage(1, msg)

    if not len(args) >= 1:
        usage(1)

    listname = string.lower(args[0])
    addresses = args[1:]
    filename = None
    all = 0
    disable = 1

    for opt, arg in opts:
        if opt in ('-h', '--help'):
            usage(0)
        elif opt in ('-f', '--file'):
            filename = arg
        elif opt in ('-a', '--all'):
            all = 1
        elif opt in ('-r', '--reverse'):
            disable = 0
                
    if filename:
        try:
            addresses = addresses + ReadFile(filename)
        except IOError:
            print 'Could not open file for reading: %s.  Ignoring...' % \
                  `filename`

    try:
        # open locked
        mlist = MailList.MailList(listname)
    except Errors.MMListError, e:
        print 'No such list "%s"\n%s' % (listname, e)
        sys.exit(1)

    if all:
        addresses = mlist.GetMembers() + mlist.GetDigestMembers()

    try:
        for addr in addresses:
            try:
                mlist.SetUserOption(addr, mm_cfg.DisableDelivery, disable)
            except Errors.MMNoSuchUserError:
                print "User `%s' not found." % addr
    finally:
        # Hmm, should it be all or nothing?
        mlist.Save()
        mlist.Unlock()



if __name__ == '__main__':
    main()


More information about the Mailman-Users mailing list