Export Mailman Subscriber Address Lists Without SSH/Shell Access

mailman-members

I recently had a need to export the contents of a GNU Mailman-based mailing list for WordCamp Philly, so I poked around the web-based Mailman admin interface, hoping to find an easy way to export a .CSV or at least a list of names, to no avail. The only supported, native way is to use a couple of Mailman shell scripts from the command line. Alas, since this particular list is hosted on a shared hosting account, I lacked the proper access to pursue this route.

There are a few ways to get around this, but they involve

  1. overly-complicated internal Mailman commands emailed directly to the listserv WITH THE ADMIN PASSWORD CONTAINED IN THE EMAIL ITSELF or
  2. use of third-party Python scripts with external dependencies or
  3. cutting-and-pasting by hand.

Perhaps you heard that laughter from where you sit? That was me. Laughing maniacally at those “solutions”.

I needed simple, I needed quick, so after a bit of Google scouting, I came across the following (ever-so-slightly modified/generalized):

wget -O - --post-data 'adminpw=${admin password}'  http://${listserv domain name}/admin.cgi/${list name}/members | egrep "_realname" | sed 's/^.*value="\([^"]*\)".*value="\([^"]*\)".*$/\1,\2/' | sed 's/%40/@/' > maillist.csv

This single-liner should work on any Linux/Mac/BSD/etc. box with a decently up-to-date version of wget installed on it and it should dump a nice comma-separated list into a file, maillist.csv. Let’s break it down a bit so that you can see how it’s working its magic.

wget -O - --post-data 'adminpw=${admin password}'  http://${listserv domain name}/admin.cgi/${list name}/members

Here, ${admin password} is the actual Mailman list admin password, ${listserv domain name} is your actual Mailman server’s DNS name (in my case, it was lists.phillywp.org, but yours will obviously differ) and ${list name} is the actual list slug.

NOTE: Some Mailman setups have pretty URLs turned on, in which case you may need to use admin/ instead of admin.cgi. The fastest way to determine the proper URL is to simply visit your Mailman list admin page and take note of the full URL.

This portion of the code retrieves the contents of the ${list name}‘s membership list by essentially screen-scraping the entire page. This is a step in the right direction, but obviously not very human-readable. The output is littered with HTML output that makes picking the subscribers’ needles out of that particular haystack a bit of a chore. The next two bits help on that count.

| egrep "_realname"

This bit strips all lines except those containing the subscribers’ real names. Again, useful, but still a bit too much info for our purposes.

| sed 's/^.*value="\([^"]*\)".*value="\([^"]*\)".*$/\1,\2/'

Here we look for two values contained in the line, specifically the subscriber’s real name and email address. We then output those two values as essentially Real Name, email Address.

| sed 's/%40/@/'

There’s one small problem with the comma-separated values we exported in the step above — the @ symbol is actually encoded as an HTML entity, namely %40. By running that sed, you’re changing %40 into the universally-understood @

So, when all is said and done, you should have a nice, concise, comma-delimited text file containing a complete list of your Mailman subscribers, one per line. I hope someone else finds this to be as time-saving a proposition as I did.

Literal Barrage is Stephen Fry proof thanks to caching by WP Super Cache