diff options
author | <> | 2003-09-22 02:07:49 +0000 |
---|---|---|
committer | <> | 2003-09-22 02:07:49 +0000 |
commit | 29de1e65e784b67e635616b2f4edf2a8a12e0a9e (patch) | |
tree | a62e374ceb5dad32cf92b11f84426345ec031586 /bin/discard | |
parent | a2a6085f338386ab1e4f34579a884e15b6639075 (diff) | |
download | mailman2-29de1e65e784b67e635616b2f4edf2a8a12e0a9e.tar.gz mailman2-29de1e65e784b67e635616b2f4edf2a8a12e0a9e.tar.xz mailman2-29de1e65e784b67e635616b2f4edf2a8a12e0a9e.zip |
This commit was manufactured by cvs2svn to create branch
'Release_2_1-maint'.
Diffstat (limited to 'bin/discard')
-rw-r--r-- | bin/discard | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/bin/discard b/bin/discard new file mode 100644 index 00000000..62325e5d --- /dev/null +++ b/bin/discard @@ -0,0 +1,120 @@ +#! @PYTHON@ +# +# Copyright (C) 2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +"""Discard held messages. + +Usage: + discard [options] file ... + +Options: + --help / -h + Print this help message and exit. + + --quiet / -q + Don't print status messages. +""" + +# TODO: add command line arguments for specifying other actions than DISCARD, +# and also for specifying other __handlepost() arguments, i.e. comment, +# preserve, forward, addr + +import os +import re +import sys +import getopt + +import paths +from Mailman import mm_cfg +from Mailman.MailList import MailList +from Mailman.i18n import _ + +try: + True, False +except NameError: + True = 1 + False = 0 + +cre = re.compile(r'heldmsg-(?P<listname>.*)-(?P<id>[0-9]+)\.(pck|txt)$') + + + +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:], 'hq', ['help', 'quiet']) + except getopt.error, msg: + usage(1, msg) + + quiet = False + for opt, arg in opts: + if opt in ('-h', '--help'): + usage(0) + elif opt in ('-q', '--quiet'): + quiet = True + + files = args + if not files: + print _('Nothing to do.') + + # Mapping from listnames to sequence of request ids + discards = {} + + # Cruise through all the named files, collating by mailing list. We'll + # lock the list once, process all holds for that list and move on. + for f in files: + basename = os.path.basename(f) + mo = cre.match(basename) + if not mo: + print >> sys.stderr, _('Ignoring non-held message: %(f)s') + continue + listname, id = mo.group('listname', 'id') + try: + id = int(id) + except (ValueError, TypeError): + print >> sys.stderr, _('Ignoring held msg w/bad id: %(f)s') + continue + discards.setdefault(listname, []).append(id) + + # Now do the discards + for listname, ids in discards.items(): + mlist = MailList(listname) + try: + for id in ids: + # No comment, no preserve, no forward, no forwarding address + mlist.HandleRequest(id, mm_cfg.DISCARD, '', False, False, '') + if not quiet: + print _('Discarded held msg #%(id)s for list %(listname)s') + mlist.Save() + finally: + mlist.Unlock() + + + +if __name__ == '__main__': + main() |