# Copyright (C) 2019 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. """Clear Bounce info for all or selected members of a list Save as bin/clear_bounce_info.py Run via bin/withlist -r clear_bounce_info [options] or bin/withlist -a -r clear_bounce_info -- [options] to do all lists. Options: -d domain --domain=domain Only clear info for those users with addresses in domain. -u address --user=address Clear info for 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 bounce info. Note: this does not re-enable delivery for members with delivery disabled by bounce. See reset_bounce.py for that. """ import sys import getopt 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 clear_bounce_info(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.getBouncingMembers(): if not (domain or users) or (domain and member.endswith(domain)) or member in users: mlist.setBounceInfo(member, None) count += 1 if count > 0: mlist.Save() mlist.Unlock() if verbose: print 'List %s: Cleared bounce info for %d members.' % ( mlist.real_name, count)