[Mailman-Developers] How about Auto Discard

Tokio Kikuchi tkikuchi@is.kochi-u.ac.jp
Thu, 17 May 2001 12:03:50 +0900


Hi! Developers,

It is cumbersome to click 'Discard' on the admindb page each time a 
spam message come to the list address or at least every day basis. 
If we  have an automatic discard function which will be ivoked 
by cron, we can just check the admin notice and do nothing. 
The held message will disappear two or three days later. 
Following script will do the job (I hope). 

Please review it and comment! Would it be better to define the 
expiration period in mm_cfg.py ?

(I omitted the copyright/license notices)

Regards,
Tokio Kikuchi

#!/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()