From d258eeb3b86fc7a084e68428f3354789ef8e3b4c Mon Sep 17 00:00:00 2001 From: bwarsaw <> Date: Mon, 31 Mar 2003 20:07:57 +0000 Subject: Backporting various fixes and improvements from the trunk. --- bin/list_members | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'bin/list_members') diff --git a/bin/list_members b/bin/list_members index 3ad10f51..b4fdbb27 100755 --- a/bin/list_members +++ b/bin/list_members @@ -1,6 +1,6 @@ #! @PYTHON@ # -# Copyright (C) 1998,1999,2000,2001,2002 by the Free Software Foundation, Inc. +# Copyright (C) 1998-2003 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 @@ -61,6 +61,7 @@ status. """ import sys +from types import UnicodeType import paths from Mailman import mm_cfg @@ -72,6 +73,8 @@ from Mailman.i18n import _ from email.Utils import formataddr PROGRAM = sys.argv[0] +ENC = sys.getdefaultencoding() + WHYCHOICES = {'enabled' : MemberAdaptor.ENABLED, 'unknown' : MemberAdaptor.UNKNOWN, 'byuser' : MemberAdaptor.BYUSER, @@ -91,6 +94,15 @@ def usage(code, msg=''): sys.exit(code) + +def safe(s): + if not s: + return '' + if isinstance(s, UnicodeType): + return s.encode(ENC, 'replace') + return unicode(s, ENC, 'replace').encode(ENC, 'replace') + + def whymatches(mlist, addr, why): # Return true if the `why' matches the reason the address is enabled, or @@ -199,17 +211,15 @@ def main(): if regular: rmembers.sort() for addr in rmembers: - name = fullnames and mlist.getMemberName(addr) + name = fullnames and mlist.getMemberName(addr) or '' # Filter out nomails if nomail and not whymatches(mlist, addr, why): continue - enc = sys.getdefaultencoding() - s = formataddr((name, addr)).encode(enc, 'replace') - print >> fp, s + print >> fp, formataddr((safe(name), addr)) if digest: dmembers.sort() for addr in dmembers: - name = fullnames and mlist.getMemberName(addr) + name = fullnames and mlist.getMemberName(addr) or '' # Filter out nomails if nomail and not whymatches(mlist, addr, why): continue @@ -222,9 +232,7 @@ def main(): # They're getting MIME digests if kind == 'plain': continue - enc = sys.getdefaultencoding() - s = formataddr((name, addr)).encode(enc, 'replace') - print >> fp, s + print >> fp, formataddr((safe(name), addr)) -- cgit v1.2.3