#!/usr/bin/env python # import sys import paths import time from Mailman import mm_cfg from Mailman import MailList from Mailman import Utils expire = 2 * 24 * 60 * 60 # 2 days now = time.time() def auto_discard(mlist): if not mlist.NumRequestsPending(): return heldmsgs = mlist.GetHeldMessageIds() total = len(heldmsgs) if total: for id in heldmsgs: info = mlist.GetRecord(id) ptime,sender,subject,reason,filename,msgdata = info if now - ptime > expire: print 'DISCARD',id, ptime, sender, subject mlist.HandleRequest(id, mm_cfg.DISCARD) mlist.Save() def main(): confined_to = sys.argv[1:] for listname in Utils.list_names(): if confined_to and listname not in confined_to: continue mlist = MailList.MailList(listname, lock=0) mlist.Lock() auto_discard(mlist) mlist.Unlock() if __name__ == '__main__': main()