[Mailman-Developers] updated patch: remove member from all the lists
Marc MERLIN
marc_news@vasoftware.com
Mon, 4 Mar 2002 23:10:25 -0800
This version of the patch add --fromall which lets you remove a specified
Email from all your lists
(replaces my _alllists_ special hack)
--- ../../src/mailman-cvs/bin/remove_members Fri Sep 7 16:18:47 2001
+++ remove_members Mon Mar 4 23:02:17 2002
@@ -19,7 +19,7 @@
"""Remove members from a list.
Usage:
- remove_members [options] listname [addr1 ...]
+ remove_members [options] ([-a] listname|--fromall) [addr1 ...]
Options:
@@ -31,6 +31,12 @@
--all
-a
Remove all members of the mailing list.
+ (mutually exclusive with --fromall)
+
+ --fromall
+ Removes the given addresses from all the lists on this system
+ regardless of virtual domains if you have any.
+ (mutually exclusive with -a/--all)
--help
-h
@@ -47,6 +53,7 @@
import paths
from Mailman import MailList
+from Mailman import Utils
from Mailman import Errors
from Mailman.i18n import _
@@ -77,17 +84,16 @@
def main():
try:
opts, args = getopt.getopt(
- sys.argv[1:], 'af:h', ['all', 'file=', 'help'])
+ sys.argv[1:], 'af:h', ['all', 'fromall', 'file=', 'help'])
except getopt.error, msg:
usage(1, msg)
if len(args) < 1:
usage(1)
- listname = args[0].lower().strip()
- addresses = args[1:]
filename = None
all = 0
+ alllists = 0
for opt, arg in opts:
if opt in ('-h', '--help'):
@@ -96,33 +102,55 @@
filename = arg
elif opt in ('-a', '--all'):
all = 1
-
+ elif opt == '--fromall':
+ alllists = 1
+
+ # You probably don't want to delete all the users of all the lists -- Marc
+ if all == 1 and alllists == 1:
+ usage(1)
+
+ if alllists:
+ addresses = args
+ else:
+ listname = args[0].lower().strip()
+ addresses = args[1:]
+
+ if alllists:
+ listnames = Utils.list_names()
+ else:
+ listnames = [ listname ]
+
if filename:
try:
addresses = addresses + ReadFile(filename)
except IOError:
print _('Could not open file for reading: %(filename)s.')
- try:
- # open locked
- mlist = MailList.MailList(listname)
- except Errors.MMListError, e:
- print _('No such list: %(listname)s')
- sys.exit(1)
-
- if all:
- addresses = mlist.getMembers()
-
- try:
- for addr in addresses:
- try:
- mlist.ApprovedDeleteMember(addr)
- except Errors.MMNoSuchUserError:
- print _("User `%(addr)s' not found.")
- finally:
- # Hmm, should it be all or nothing?
- mlist.Save()
- mlist.Unlock()
+ for listname in listnames:
+ try:
+ # open locked
+ mlist = MailList.MailList(listname)
+ except Errors.MMListError:
+ print _('Error opening list %(listname)s... skipping.')
+ continue
+
+ if all:
+ addresses = mlist.getMembers()
+
+ try:
+ for addr in addresses:
+ try:
+ mlist.ApprovedDeleteMember(addr)
+ except Errors.MMNoSuchUserError:
+ if not alllists:
+ print _("User `%(addr)s' not found.")
+ else:
+ if alllists:
+ print _("User `%(addr)s' removed from list '%(listname)s'.")
+ finally:
+ # Hmm, should it be all or nothing?
+ mlist.Save()
+ mlist.Unlock()
--
Microsoft is to operating systems & security ....
.... what McDonalds is to gourmet cooking
Home page: http://marc.merlins.org/ | Finger marc_f@merlins.org for PGP key