Determining last post sent from each Mailman list

We maintain a number of Mailman mailing lists. One of the reasons that I like Mailman for listserv-type functions is that it is easily scriptable from the command line. Here’s an example.

At the end of each academic year, we like to remind list owners of lists that are no longer being used, so that we can remove unnecessary lists and/or make arrangements to transfer ownership of lists to new groups. Here’s an easy way to generate a CSV file showing the name of the mailing list, the last time a message was sent via the mailing list and the owner(s) of the list.

In the mailman binary directory (on an older version of CentOS, it’s /usr/local/mailman/bin/; yours is probably different), create a file called Here’s what to put in the file:

#!/usr/bin/env python
Last time a message was posted to a list, along with list name

import os
import time
print "List,Last Post Date,Owner(s)"
def last_post(mlist):
    last = time.strftime('%m-%d-%Y',time.localtime(mlist.last_post_time))
    owner = ''
        if len(mlist.owner)>1:
            owner = ';'.join(mlist.owner)
            owner = mlist.owner[0]
    except IndexError:
        owner = ''
    print "%s,%s,%s" % ( mlist.real_name, last, owner)

Now that you have the file, you invoke it from the command line like this:

./withlist -a -r last_post.last_post >/tmp/last_posts.txt

This runs the withlist command (a utility bundled with mailman and located in the same directory) on all (“-a”) lists. The command tells it to run (“-r”) the function that you’ve created (“last_post”) located in the file that you’ve created (“last_post”), directing the output to /tmp/last_posts.txt. Note that you do not specify the file extension for the file. You should see some output fly by as the program is being executed. When you open up the /tmp/last_posts.txt file, you’ll see something like this:

List,Last Post Date,Owner

You can then use this csv file as the basis for sending out reminder messages, etc.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s