Today I was dealing with an instance of GNU mailman without the web interface and there were some messages held for approval.

How to approve them from the command line? Turns out it is possible thanks to the withlist tool shipped with mailman and a bit of fiddling. Code below.

# installation:
# copy this file in the same dir as withlist and name it

# usage:
# bin/withlist -l -r approvemessage <list> <cookie>

# cookie is the digest in the Subject: after approve

import sys
from Mailman import mm_cfg
from Mailman import Pending

# ripped out from ProcessConfirmation
def approvemessage(ml, cookie=None):
  if cookie is None:
    print >> sys.stderr, "!!!! No cookie specified"

  rec = ml.pend_confirm(cookie)
  if not rec:
    print >> sys.stderr, "!!!! Cookie not found"

    op = rec[0]
    data = rec[1:]
  except ValueError:
    print >> sys.stderr, "!!!! No op found for cookie"

  if op != Pending.HELD_MESSAGE:
    print >> sys.stdout, "!!!! Message isn't held"

  ml.HandleRequest(data[0], mm_cfg.APPROVE)
  print >> sys.stdout, "!!!! Message approved"

# interactive version:
# bin/withlist -l admin
#Loading list admin (locked)
#The variable `m' is the admin MailList instance
#>>> from Mailman import mm_cfg
#>>> res = m.pend_confirm('862db35189d896667888114e67db8f41fa986c9f')
#>>> m.HandleRequest(res[1], mm_cfg.APPROVE)
#>>> m.Save()

blurb: public domain, no warranty whatsoever, use at your risk. Comments welcome though :)