Update of /cvsroot/mailman/mailman/bin
In directory sc8-pr-cvs1:/tmp/cvs-serv29408
Modified Files:
list_members
Log Message:
Added a --checkaddrs / -c option to do some limited sanity checking on
the addresses in the member databases. 1) it checks to make sure the
address part contains only ascii characters; 2) it checks to make sure
the address parts are not unicode objects.
Back port candidate.
Index: list_members
===================================================================
RCS file: /cvsroot/mailman/mailman/bin/list_members,v
retrieving revision 2.14
retrieving revision 2.15
diff -u -d -r2.14 -r2.15
--- list_members 13 Mar 2003 15:54:39 -0000 2.14
+++ list_members 17 Jun 2003 16:11:39 -0000 2.15
@@ -44,11 +44,14 @@
--fullnames / -f
Include the full names in the output.
- --preserve
- -p
+ --preserve / -p
Output member addresses case preserved the way they were added to the
list. Otherwise, addresses are printed in all lowercase.
+ --checkaddrs / -c
+ Check the email addresses in the resulting list and verify that they
+ are valid.
+
--help
-h
Print this help message and exit.
@@ -65,6 +68,7 @@
import paths
from Mailman import mm_cfg
+from Mailman import Utils
from Mailman import MailList
from Mailman import Errors
from Mailman import MemberAdaptor
@@ -74,6 +78,14 @@
PROGRAM = sys.argv[0]
ENC = sys.getdefaultencoding()
+COMMASPACE = ', '
+
+try:
+ True, False
+except NameError:
+ True = 1
+ False = 0
+
WHYCHOICES = {'enabled' : MemberAdaptor.ENABLED,
'unknown' : MemberAdaptor.UNKNOWN,
@@ -103,6 +115,19 @@
return unicode(s, ENC, 'replace').encode(ENC, 'replace')
+def isvalid(addr):
+ states = []
+ try:
+ Utils.ValidateEmail(addr)
+ except Errors.EmailAddressError:
+ states.append('INVALID')
+ if isinstance(addr, UnicodeType):
+ states.append('UNICODE')
+ if states:
+ return '(' + COMMASPACE.join(states) + ')'
+ return ''
+
+
def whymatches(mlist, addr, why):
# Return true if the `why' matches the reason the address is enabled, or
@@ -124,14 +149,15 @@
nomail = None
why = None
kind = None
- fullnames = 0
+ fullnames = False
+ checkaddrs = True
# Throw away the first (program) argument
args = sys.argv[1:]
if not args:
usage(0)
- while 1:
+ while True:
try:
opt = args.pop(0)
except IndexError:
@@ -139,38 +165,40 @@
if opt in ('-h', '--help'):
usage(0)
elif opt in ('-f', '--fullnames'):
- fullnames = 1
+ fullnames = True
elif opt in ('-p', '--preserve'):
- preserve = 1
+ preserve = True
elif opt in ('-r', '--regular'):
- regular = 1
+ regular = True
elif opt in ('-o', '--output'):
try:
outfile = args.pop(0)
except IndexError:
usage(1)
elif opt == '-n':
- nomail = 1
+ nomail = True
if args and args[0] in WHYCHOICES.keys():
why = args.pop(0)
elif opt.startswith('--nomail'):
- nomail = 1
+ nomail = True
i = opt.find('=')
if i >= 0:
why = opt[i+1:]
if why not in WHYCHOICES.keys():
usage(1, _('Bad --nomail option: %(why)s'))
elif opt == '-d':
- digest = 1
+ digest = True
if args and args[0] in ('mime', 'plain'):
kind = args.pop(0)
elif opt.startswith('--digest'):
- digest = 1
+ digest = True
i = opt.find('=')
if i >= 0:
kind = opt[i+1:]
if kind not in ('mime', 'plain'):
usage(1, _('Bad --digest option: %(kind)s'))
+ elif opt in ('-c', '--checkaddrs'):
+ checkaddrs = True
else:
# No more options left, push the last one back on the list
args.insert(0, opt)
@@ -182,7 +210,7 @@
listname = args[0].lower().strip()
if regular is None and digest is None:
- regular = digest = 1
+ regular = digest = True
if outfile:
try:
@@ -194,7 +222,7 @@
fp = sys.stdout
try:
- mlist = MailList.MailList(listname, lock=0)
+ mlist = MailList.MailList(listname, lock=False)
except Errors.MMListError, e:
print >> sys.stderr, _('No such list: %(listname)s')
sys.exit(1)
@@ -211,14 +239,22 @@
if regular:
rmembers.sort()
for addr in rmembers:
+ if checkaddrs:
+ validmsg = isvalid(addr)
+ else:
+ validmsg = ''
name = fullnames and mlist.getMemberName(addr) or ''
# Filter out nomails
if nomail and not whymatches(mlist, addr, why):
continue
- print >> fp, formataddr((safe(name), addr))
+ print >> fp, formataddr((safe(name), addr)), validmsg
if digest:
dmembers.sort()
for addr in dmembers:
+ if checkaddrs:
+ validmsg = isvalid(addr)
+ else:
+ validmsg = ''
name = fullnames and mlist.getMemberName(addr) or ''
# Filter out nomails
if nomail and not whymatches(mlist, addr, why):
@@ -232,7 +268,7 @@
# They're getting MIME digests
if kind == 'plain':
continue
- print >> fp, formataddr((safe(name), addr))
+ print >> fp, formataddr((safe(name), addr)), validmsg
_______________________________________________
Mailman-checkins mailing list
[EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/mailman-checkins