"""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)