#!/usr/bin/python ### ### Copyright (C) 1998-2010 by the Free Software Foundation, Inc. ### ### 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. http://www.fsf.org/licensing/licenses/gpl.html ### ### --------------------------- ### ### Given an option to set, a listname to set it on, a password (list ### password or site admin password), and either an email address or ### file that has one email address per line, set the option for the ### each address or each address in the file. ### ### Since this relies on set function of mailman_admin_cmd_handler, ### it supports the options that supports which are currently: ### delivery on/off (mail/nomail in Listserv terms), digest plain/ ### mime/off (digest/nodigest), and mod on/off (review/noreview) ### ### Author: Anthony R. Thompson ### Contact: put @ between art and sigilservices.com ### Created: Dec 2009 ### import os, sys, re from email.Utils import parseaddr MM_ROOT = '/usr/lib/mailman/' # INSTALL sys.path.append(MM_ROOT) import mailman_admin_cmd_handler, ListStream from Mailman import Errors from Mailman import MailList prog = sys.argv[0] if (len(sys.argv) < 4): print "Usage: %s option optionval listname password address/addressfile" % (prog) sys.exit(0) # We're not going to check if it's a valid option because the set # function in mailman_admin_cmd_handler checks, and we support # whatever it supports anyway, so we'll let that validate the option optname = sys.argv[1] optval = sys.argv[2] # Make sure if given an address file, that it exists addrfile = sys.argv[5] if ( (not re.search('@', addrfile)) and (not os.path.isfile(addrfile)) ): print "%s: address file %s not found" % (prog, addrfile) sys.exit(1) # Make sure the list name is valid too listname = sys.argv[3] try: mlist = MailList.MailList(listname, lock=0) except Errors.MMUnknownListError: print "%s: Unknown list: %s" % (prog, listname) sys.exit(1) # Check the password for the given list - list password or site admin passwd = sys.argv[4] if (not ( (mailman_admin_cmd_handler.valid_site_admin_pass(passwd)) or \ (mailman_admin_cmd_handler.valid_list_pass(mlist, passwd)) ) ): print "%s: Bad password: %s for list: %s" % (prog, passwd, listname) sys.exit(1) # Now open the input file (if any) and iterate over each line if (re.search('@', addrfile)): addresses = [addrfile] else: infile = open(addrfile, 'r') addresses = infile.readlines() infile.close() for addr in addresses: addr = re.sub('\n$', '', addr) # Parse the email address for the option from this addr email_name, email_addr = parseaddr(addr) if (not re.search('@', email_addr)): print "Unable to get address from: " + addr + " - continuing" continue # Now set up and then call mailman_admin_cmd_handler's set function args = [prog, listname, passwd, email_addr, optname, optval] retval = mailman_admin_cmd_handler.set(mlist, args) if (optname == 'mod'): retval = re.sub('\n$', '', retval) # hack print "%s/%s: %s" % (listname, email_addr, retval)