summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbwarsaw1999-08-09 15:49:57 +0000
committerbwarsaw1999-08-09 15:49:57 +0000
commitb9e11cd58382e55d7389ce0134316c2a976fe587 (patch)
tree7e97208fb83f0299099eccde029265ad48fa3ed4
parent6cd7b4e86bd6014b7730b0bc53aa4bd2df5d4456 (diff)
downloadmailman-b9e11cd58382e55d7389ce0134316c2a976fe587.tar.gz
mailman-b9e11cd58382e55d7389ce0134316c2a976fe587.tar.zst
mailman-b9e11cd58382e55d7389ce0134316c2a976fe587.zip
find_member: new script to search all lists (or a specified subset)
for an address matching a regular expression. Very handy when you have a bouncing address subscribed to many lists! Makefile.in: install find_member
-rw-r--r--bin/Makefile.in2
-rwxr-xr-xbin/find_member144
2 files changed, 145 insertions, 1 deletions
diff --git a/bin/Makefile.in b/bin/Makefile.in
index 79afcd639..0c86a2198 100644
--- a/bin/Makefile.in
+++ b/bin/Makefile.in
@@ -43,7 +43,7 @@ SHELL= /bin/sh
SCRIPTS= digest_arch mmsitepass newlist rmlist add_members \
list_members remove_members clone_member update arch \
- sync_members check_db withlist check_perms
+ sync_members check_db withlist check_perms find_member
# Modes for directories and executables created by the install
# process. Default to group-writable directories but
diff --git a/bin/find_member b/bin/find_member
new file mode 100755
index 000000000..f5a757e61
--- /dev/null
+++ b/bin/find_member
@@ -0,0 +1,144 @@
+#! /usr/bin/env python
+#
+# Copyright (C) 1998 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.
+
+"""Find all lists that a member's address is on.
+
+Usage:
+ find_member [-h] [-l listname] [-x listname] regex
+
+Where:
+ --list listname
+ -l listname
+ Include only the named list in the search
+
+ --exclude listname
+ -x listname
+ Exclude the named list from the search
+
+ --help
+ -h
+ Print this help message and exit.
+
+ regex
+ A Python regular expression to match against
+
+The interaction between -l and -x is as follows. If any -l option is given
+then only the named list will be included in the search. If any -x option is
+given but no -l option is given, then all lists will be search except those
+specifically excluded.
+
+Regular expression syntax is Perl5-like, using the Python re module. Complete
+specifications are at:
+
+http://www.python.org/doc/current/lib/module-re.html
+
+Address matches are case-insensitive, but case-preserved addresses are
+displayed.
+"""
+
+import sys
+import re
+import paths
+from Mailman import Utils
+from Mailman import MailList
+from Mailman import Errors
+
+
+def usage(code, msg=''):
+ print __doc__ % globals()
+ if msg:
+ print msg
+ sys.exit(code)
+
+
+
+def scanlists(listnames, cre):
+ matches = {}
+ for name in listnames:
+ try:
+ m = MailList.MailList(name)
+ except Errors.MMUnknownListError:
+ # XXX: Warn?
+ pass
+ allmembers = m.GetMembers() + m.GetDigestMembers()
+ for member in allmembers:
+ if cre.search(member):
+ addr = m.GetUserSubscribedAddress(member)
+ foundlists = matches.get(addr, {})
+ foundlists[name] = addr
+ matches[addr] = foundlists
+ return matches
+
+
+
+def main():
+ listnames = Utils.list_names()
+ loptseen = 0
+ searchre = None
+ # parse options and figure out the lists to search
+ try:
+ argvi = 1
+ while argvi < len(sys.argv):
+ argv = sys.argv[argvi]
+ if argv in ('-h', '--help'):
+ usage(0)
+ elif argv in ('-l', '--list'):
+ argvi = argvi + 1
+ name = sys.argv[argvi]
+ if not loptseen:
+ listnames = []
+ loptseen = 1
+ listnames.append(name)
+ elif argv in ('-x', '--exclude'):
+ argvi = argvi + 1
+ name = sys.argv[argvi]
+ try:
+ listnames.remove(name)
+ except ValueError:
+ pass
+ elif searchre:
+ usage(1, 'multiple search regexps not allowed')
+ else:
+ searchre = argv
+ argvi = argvi + 1
+ except IndexError:
+ usage(2)
+
+ if not listnames:
+ print 'No lists to search'
+ sys.exit(0)
+
+ if not searchre:
+ usage(3, 'no regexp provided')
+
+ matches = scanlists(listnames, re.compile(searchre, re.IGNORECASE))
+ addrs = matches.keys()
+ addrs.sort()
+ for k in addrs:
+ lists = matches[k].keys()
+ if len(lists) == 1:
+ print k, 'found in list', lists[0]
+ else:
+ print k, 'found in:'
+ for name in lists:
+ print ' ', name
+
+
+
+if __name__ == '__main__':
+ main()