# Copyright (C) 2017 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. """Enable delivery for bouncing members. Save as bin/reset_bounce.py Run via bin/withlist -r reset_bounce [options] or bin/withlist -a -r reset_bounce -- [options] to do all lists. Options: -d domain --domain=domain Only reset those users with addresses in domain. -u address --user=address Reset the user with the given address. May be repeated and may be given in addition to domain. -v --verbose Print number of users reset. The default if neither domain nor a user address is given is to do all members with delivery disabled by bounce. """ import sys import getopt from Mailman import MemberAdaptor 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 reset_bounce(mlist, *args): try: opts, args = getopt.getopt(args, 'd:u:v', ['domain=', 'user=', 'verbose']) except getopt.error, msg: usage(1, msg) verbose = 0 domain = None users = [] for opt, arg in opts: if opt in ('-d', '--domain'): domain = arg.lower() elif opt in ('-u', '--user'): users.append(arg.lower()) elif opt in ('-v', '--verbose'): verbose = 1 if not mlist.Locked(): mlist.Lock() count = 0 for member in mlist.getMembers(): if not (domain or users) or (domain and member.endswith(domain)) or member in users: if mlist.getDeliveryStatus(member) == MemberAdaptor.BYBOUNCE: mlist.setDeliveryStatus(member, MemberAdaptor.ENABLED) count += 1 if count > 0: mlist.Save() mlist.Unlock() if verbose: print 'List %s: Reset %d bouncing members.' % (mlist.real_name, count)