[plug] neato little mailman moderation script
Shayne O'Neill
shayne at guild.murdoch.edu.au
Sun Sep 19 19:28:42 WST 2004
Figure I'd share this one with you folks and google. It lets you load
mailman moderation data into mysql and then moderate acording to what
the moderation field in the table is set to. Handy for web interfaces/clients/whatever for
moderating lists;-
You save this sucker in in /var/lib/mailman/bin as moderate.py
and call it either by;
/var/lib/mailman/bin/withlist -l -r moderate.getmessages <listname>
or
/var/lib/mailman/bin/withlist -l -r moderate.moderatemessages <listname>
The first one loads up a mysql table with data about the messages in the
moderation queue in mysql
the second one moderates according to the values in the 'moderation' field
in that table
DEFER = 0
APPROVE = 1
REJECT = 2
DISCARD = 3
you need a table like this;-
CREATE TABLE modmessages (
list text NOT NULL,
idno int(11) NOT NULL default '0',
from text NOT NULL,
subject text NOT NULL,
reason text NOT NULL,
moderation tinyint(4) NOT NULL default '0'
) TYPE=MyISAM;
and heres the script;-
from Mailman import mm_cfg
import sys
import MySQLdb
def getmessages(list):
db=MySQLdb.connect(host="localhost",user="(username)",passwd="(password)",db="(db)")
cr =db.cursor()
listname = list.GetListEmail()
cr.execute (""" DELETE FROM modmessages WHERE list='""" + listname + """'""")
for messageid in list.GetHeldMessageIds():
message = list.GetRecord(messageid)
cr.execute ("""INSERT INTO modmessages ( `list` , `idno` , `from` , `subject` , `reason` , `moderation` ) VALUES ('"""+listname+"""','""" +str(messageid)+"""','"""+message[1]+"""','"""+message[2]+"""','"""+message[3]+"""',0)""")
def moderatemessages(list):
db=MySQLdb.connect(host="localhost",user="root",passwd="",db="activismo")
cr =db.cursor()
listname = list.GetListEmail()
cr.execute (""" SELECT * FROM modmessages WHERE list='""" + listname + """'""")
table = cr.fetchall()
for tuple in table:
list.HandleRequest(tuple[1],tuple[5])
list.Save()
--
"Well, I think if you say you're going to do something and don't do
it, that's trustworthiness."
-- George Bush on CNN online chat, Aug.30, 2000
More information about the plug
mailing list