# 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. """Set a member or members to no mail by admin or by bounce. Optionally, also set password reminders off. Save as bin/set_nomail.py Run via bin/withlist -r set_nomail [options] [ ...] Options: -a --allmembers Process all members -b --bybounce Set reason by bounce, set bounce info for subsequent processing by cron/disabled and log and send first notice. Default is to set reason by admin. -r --noreminder Also set password reminders off -h --help Print this message. """ import sys import time import getopt from Mailman import mm_cfg from Mailman import Bouncer 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 set_nomail(mlist, *args): try: opts, args = getopt.getopt(args, 'arbh', ['allmembers', 'noreminder', 'bybounce', 'help']) except getopt.error, msg: usage(1, msg) bybounce = noreminder = allmembers = False for opt, arg in opts: if opt in ('-r', '--noreminder'): noreminder = True if opt in ('-a', '--allmembers'): allmembers = True if opt in ('-b', '--bybounce'): bybounce = True if opt in ('-h', '--help'): usage(0) if not args and not allmembers: usage(1, 'Member address is required') if args and allmembers: usage(1, 'Specify --allmembers or member address(es), not both') # Sanity check. if allmembers and bybounce: usage(1, "Can't set all members by bounce") if allmembers: args = mlist.getMembers() if not mlist.Locked(): mlist.Lock() for member in args: if bybounce: bi = Bouncer._BounceInfo(member, mlist.bounce_score_threshold, time.localtime()[:3], mlist.bounce_you_are_disabled_warnings) mlist.setBounceInfo(member, bi) mlist.disableBouncingMember(member, bi, 'Disabled member by bounce from withlist set_nomail') else: mlist.setDeliveryStatus(member, MemberAdaptor.BYADMIN) if noreminder: mlist.setMemberOption(member, mm_cfg.SuppressPasswordReminder, 1) mlist.Save() mlist.Unlock()