# Copyright (C) 2008 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. """Find all list members with upper case in their non-case preserved member email addresses and convert to lower case or remove them if the lower case member exists. This script fixes a problem caused by a bug in OldStyleMemberships.py prior to Mailman 2.1.10. It does some direct manipulation of member data, so if you use a MemberAdaptor other than OldStyleMemberships, it will detect that and not run. Save as bin/fix_uc_address.py Run via bin/withlist -r fix_uc_address [options] or bin/withlist -a -r fix_uc_address [-- options] to do all lists. Options: -n --no-change Don't actually fix any members. Just report. """ import sys import getopt from Mailman import Utils from Mailman import Errors from Mailman import OldStyleMemberships try: True, False except NameError: True = 1 False = 0 def usage(code, msg=''): if code: fd = sys.stderr else: fd = sys.stdout print >> fd, __doc__ if msg: print >> fd, msg sys.exit(code) def fix_uc_address(mlist, *args): if not isinstance(mlist._memberadaptor, OldStyleMemberships.OldStyleMemberships): usage(1, 'MemberAdaptor is not OldStyleMemberships') try: opts, args = getopt.getopt(args, 'n', ['no-change']) except getopt.error, msg: usage(1, msg) change = True for opt, arg in opts: if opt in ('-n', '--no-change'): change = False if not mlist.Locked(): mlist.Lock() for member in mlist.getMembers(): if member.lower() == member: continue print 'List: %s, Non-lowercase address key: %s' % (mlist.real_name, member) if change: if mlist.isMember(member): # isMember() tests lower case address: remove(mlist, member) else: lowercase(mlist, member) mlist.Save() mlist.Unlock() def remove(mlist, member): # Based on OldStyleMemberships.removeMember() which we can't use because # it lower cases the member address. # Delete the appropriate entries from the various MailList attributes. # Remember that not all of them will have an entry (only those with # values different than the default). for attr in ('passwords', 'user_options', 'members', 'digest_members', 'language', 'topics_userinterest', 'usernames', 'bounce_info', 'delivery_status', ): dict = getattr(mlist, attr) if dict.has_key(member): del dict[member] def lowercase(mlist, member): # Change the key for the appropriate entries in the various MailList # attributes. # Remember that not all of them will have an entry (only those with # values different than the default). lcmember = member.lower() for attr in ('passwords', 'user_options', 'members', 'digest_members', 'language', 'topics_userinterest', 'usernames', 'bounce_info', 'delivery_status', ): dict = getattr(mlist, attr) if dict.has_key(member): dict[lcmember] = dict[member] del dict[member]