diff options
| author | bwarsaw | 2003-06-17 16:11:39 +0000 |
|---|---|---|
| committer | bwarsaw | 2003-06-17 16:11:39 +0000 |
| commit | a18752d6faf37353151a2b2ef48ef45261b71a39 (patch) | |
| tree | 165a88f551e26b056d42c3dcc22d2c495ffd4c26 | |
| parent | 80c6ad3ee73bf41b597f81f72fb6675b586fadf4 (diff) | |
| download | mailman-a18752d6faf37353151a2b2ef48ef45261b71a39.tar.gz mailman-a18752d6faf37353151a2b2ef48ef45261b71a39.tar.zst mailman-a18752d6faf37353151a2b2ef48ef45261b71a39.zip | |
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.
| -rwxr-xr-x | bin/list_members | 66 |
1 files changed, 51 insertions, 15 deletions
diff --git a/bin/list_members b/bin/list_members index b4fdbb27e..cfb043f14 100755 --- a/bin/list_members +++ b/bin/list_members @@ -44,11 +44,14 @@ Where: --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 @@ from types import UnicodeType 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 @@ from email.Utils import formataddr 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 @@ def safe(s): 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 @@ def main(): 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 @@ def main(): 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 @@ def main(): 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 @@ def main(): 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 @@ def main(): 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 @@ def main(): # They're getting MIME digests if kind == 'plain': continue - print >> fp, formataddr((safe(name), addr)) + print >> fp, formataddr((safe(name), addr)), validmsg |
