Mailman list management: Flip nomail bit
Due to a server side misconfiguration, outgoing mails were bouncing for sometime. I identified the culprit to be:
/etc/hosts: ::1 localhost localhost.my.domain
After I fixed it, there was more collateral damage. A large number of subscribers were marked as “nomail” (i.e. delivery disabled due to excessive bounces). I didn’t see an easy way of mass enabling the delivery. So I wrote this little script.
#! /usr/local/bin/python2.6 # # Copyright (C) 2009 Arun Sharma# # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. """ Flip the nomail bit for all members of a list. """ import sys import paths from Mailman import MailList from Mailman import Errors from Mailman import MemberAdaptor def main(): listname = sys.argv[1].lower().strip() try: mlist = MailList.MailList(listname, lock=True) except Errors.MMListError, e: print >> sys.stderr, _('No such list: %(listname)s') sys.exit(1) # Get the lowercased member addresses rmembers = mlist.getRegularMemberKeys() for addr in rmembers: status = mlist.getDeliveryStatus(addr) if status <> MemberAdaptor.ENABLED: mlist.setDeliveryStatus(addr, MemberAdaptor.ENABLED) print >> sys.stderr, 'Enabled delivery for: %s' % (addr) mlist.Save() mlist.Unlock() if __name__ == '__main__': main()
Enjoy.
Categories: Open Source
I remember when I was working in India and we migrated our company’s MTA and mailing lists from the qmail based one to postfix+mailman. We ran into a problem very similar to this: incorrect bits set for subscribers.
Since I was running short on time and did not know mailman libraries existed, my solution was to ask mailman to dump the configuration for each mailing list into a file named $LISTNAME.setting. I then used vim to open the setting files. On the first file I enabled recording and searched for the setting and flipped its bit. I ended my recording and asked vim to play back this recorded macro on all the setting files. That was the first time I realized the full power of vim recording/playback.
My house mate used to argue that vi macros are powerful enough to solve any computer science problem by the virtue of being a turing machine. Me being a fervent emacs advocate back then dismissed the whole thing as propaganda created by lazy bastards who didn’t want to learn emacs lisp