#! /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 the pending requests for a mailing list. Usage: %(PROGRAM)s [options] listname Where: --bounce / -b List bounce processing related requests in addition to the defaults. --expired / -e List requests which have expired but have not yet been removed from the pending.pck file --message / -m List held message requests in addition to the defaults. --verbose / -v List more information about each request --help / -h Print this help message and exit. listname is the name of the mailing list to use. The various pending request types are defined as follows: SUBSCRIPTION = 'S' UNSUBSCRIPTION = 'U' CHANGE_OF_ADDRESS = 'C' HELD_MESSAGE = 'H' RE_ENABLE = 'E' PROBE_BOUNCE = 'P' By default, this script lists only SUBSCRIPTION, UNSUBSCRIPTION and CHANGE_OF_ADDRESS requests. The -m option adds HELD_MESSAGE requests and the -b option adds RE_ENABLE and PROBE_BOUNCE requests. Currently, the default output is the confirmation cookie, the type and the data for each listed request. The type is one of the above letters and the data depends on the type. The -v option adds the expiration time to the output. This script must run from Mailman's bin/ directory. """ import os import sys import time import errno import getopt import cPickle import paths from Mailman import mm_cfg from Mailman import Errors from Mailman import Pending from Mailman import MailList 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:], 'hbemv', ['help', 'bounce', 'expired', 'message', 'verbose']) except getopt.error, msg: usage(1, msg) bounce = expired = message = verbose = False for opt, arg in opts: if opt in ('-h', '--help'): usage(0) elif opt in ('-b', '--bounce'): bounce = True elif opt in ('-e', '--expired'): expired = True elif opt in ('-m', '--message'): message = True elif opt in ('-v', '--verbose'): verbose = True if len(args) <> 1: usage(1) listname = args[0].lower().strip() try: mlist = MailList.MailList(listname, lock=False) except Errors.MMListError, e: print >> sys.stderr, _('No such list: %(listname)s') sys.exit(1) now = time.time() pendfile = os.path.join(mlist.fullpath(), 'pending.pck') try: fp = open(pendfile) except IOError, e: if e.errno <> errno.ENOENT: raise return try: pending = cPickle.load(fp) finally: fp.close() evictions = pending['evictions'] if pending['version'] <> 2: print >> sys.stderr, _('Incompatible pending database version.') sys.exit(1) for cookie in pending.keys(): if cookie in ['evictions', 'version']: continue if not message and pending[cookie][0] == Pending.HELD_MESSAGE: continue if not bounce and pending[cookie][0] in [Pending.RE_ENABLE, Pending.PROBE_BOUNCE]: continue if not expired and evictions[cookie] < now: continue print 'cookie: %s' % cookie print ' type: %s' % pending[cookie][0] print ' data: %s' % pending[cookie][1] if len(pending[cookie]) > 2: for i in range(2, len(pending[cookie])): print ' %s' % pending[cookie][i] if verbose: print ' expiration: %s' % time.ctime(evictions[cookie]) if __name__ == '__main__': main()