#! /usr/bin/env python # # Copyright (C) 2007 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. """List/Remove recipients from a Mailman outgoing message queue entry. Usage: %(PROGRAM)s [options] filename Where: --list / -l List the recipients of the message. --remove=
/ -r
Remove
from the recipient list. May be repeated for as many addresses as desired. --verbose / -v Print a message for each removed recipient address --help / -h Print this help message and exit. This script must run from Mailman's bin/ directory. """ import sys import getopt import cPickle import paths from Mailman.i18n import _ PROGRAM = sys.argv[0] 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 main(): try: opts, args = getopt.getopt( sys.argv[1:], 'hlr:v', ['help', 'list', 'remove=', 'verbose']) except getopt.error, msg: usage(1, msg) list = verbose = False removes = [] for opt, arg in opts: if opt in ('-h', '--help'): usage(0) elif opt in ('-l', '--list'): list = True elif opt in ('-r', '--remove'): removes.append(arg) elif opt in ('-v', '--verbose'): verbose = True if len(args) <> 1: usage(1) file = args[0] fp = open(file, 'r+') msg = cPickle.load(fp) msgdata = cPickle.load(fp) if not msgdata.get('recips', None): print >> sys.stderr, _('Message has no recipients') sys.exit(1) removed = False if list: print _('Recipients:') for recip in msgdata['recips']: print _(' %(recip)s') print if removes: for recip in removes: try: i = msgdata['recips'].index(recip) except ValueError: print _('%(recip)s is not a recipient') else: removed = True del msgdata['recips'][i] if verbose: print _('%(recip)s removed from recipient list') if removed: fp.seek(0) cPickle.dump(msg, fp, 1) cPickle.dump(msgdata, fp, 1) fp.close() if __name__ == '__main__': main()