#!/usr/bin/env python """ Automatically discard messages to be moderated on a Mailman form. This is useful for Mailman 2.0 installations that get a lot of spam. The config file should contain sections like: [example] url=http://example.com/mailman/admindb/mylist password=somepassword """ import sys, re, ConfigParser import mechanize cp = ConfigParser.ConfigParser() cp.read(sys.argv[1]) for section in cp.sections(): url = cp.get(section, "url") password = cp.get(section, "password") b = mechanize.Browser() b.set_handle_robots(False) # Log in b.open(url) assert b.viewing_html() b.select_form(nr=0) b["adminpw"] = password resp = b.submit() # Discard all messages assert b.viewing_html() try: b.select_form(nr=0) except mechanize.FormNotFoundError: # Nothing to moderate -- give up now. sys.exit(0) for control in b.form.controls: if not re.match(r'^[0-9]+$', control.name): continue items = control.possible_items() items.sort() if items != ["0", "1", "2", "3"]: continue control.toggle("3") resp = b.submit() # Done assert b.viewing_html()