#! /usr/bin/env python # # Copyright (C) 2014 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. """Post all messages in some mbox file to a list. Usage: %(PROGRAM)s [options] filename listname Where: --verbose -v Print information about what's done. --help -h Print this help message and exit. 'filename' is the name of a *nix mbox file containing one or more messages to be posted to 'listname'. This script must run from Mailman's bin/ directory. """ import sys import getopt import paths from Mailman import mm_cfg from Mailman.i18n import _ from Mailman.Mailbox import Mailbox from Mailman.Queue.Switchboard import Switchboard 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:], 'hv', ['help', 'verbose']) except getopt.error, msg: usage(1, msg) verbose = False for opt, arg in opts: if opt in ('-h', '--help'): usage(0) elif opt in ('-v', '--verbose'): verbose = True if len(args) != 2: usage(1, 'Exactly two arguments required.') filename = args[0] listname = args[1] fp = open(filename) mb = Mailbox(fp) inq = Switchboard(mm_cfg.INQUEUE_DIR) for msg in mb: del msg['x-beenthere'] if verbose: print """Requeueing message Subject: %s Date: %s """ % (msg.get('subject', 'N/A'), msg.get('date', 'N/A')) inq.enqueue(msg, _plaintext = False, tolist = True, listname = listname) if __name__ == '__main__': main()