# Copyright (C) 2012 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. """Discard all subscription requests older than a specified time Save as bin/discard_subs.py Run via bin/withlist -r discard_subs LISTNAME N or bin/withlist -a -r discard_subs -- N to do all lists. N is the number of days beyond which a request is "old". Discards will be logged to Mailman's vette log. """ import sys import time from Mailman import mm_cfg def discard_subs(mlist, days): try: old = time.time() - int(days) * 24 * 3600 except (TypeError, ValueError): print >> sys.stderr, 'discard_subs: argument must be a number' sys.exit(1) if not mlist.Locked(): mlist.Lock() pendingsubs = mlist.GetSubscriptionIds() changed = False for id in pendingsubs: if mlist.GetRecord(id)[0] > old: continue mlist.HandleRequest(id, mm_cfg.DISCARD, 'Discarded by script') changed = True if changed: mlist.Save() mlist.Unlock()