# AutoApprove v 0.1 # by whatah # Automatically approve posts from certain addresses, then change those addresses. # Neither of the addresses given should even be subscribed to the list. # To use this you need to create /etc/mailman/approved.list as described below, # modify mm_cfg.py as described below, and you should set all subscribers posting # status to 'moderated'. # You'll need to add this to mm_cfg.py : GLOBAL_PIPELINE.insert(3, 'AutoApprove') import os """Automatically approve certain addresses and change the from field.""" APPROVED_LIST = "/etc/mailman/approved.list" # the approved list is in the format: # list.to.approve.for:address.it.is.coming@from:The Name # list.to.approve.for:address.it.is.coming@from:address.to.replace.it@with # lines beginning with a # or blank lines are comments def sepatcolon(message): split_index = message.find(':') ret = [] ret.append(message[:split_index]) ret.append(message[split_index+1:]) return ret # Returns a dictionary of approved addresses and their key values def getapproved(path_to_approved_file): if os.path.exists(path_to_approved_file): approved_file = open(path_to_approved_file, 'r') approved_lines = approved_file.readlines() a_dict = {} a_list = {} for line in approved_lines: line = line.strip() if line == '' or (len(line) > 0 and line[0] == '#'): continue split_line = sepatcolon(line) a_listname = split_line[0] split_line = sepatcolon(split_line[1]) a_address = split_line[0].lower() r_address = split_line[1] a_dict[a_address] = r_address if a_list.has_key(a_listname): tup_list = a_list[a_listname] tup_list = tup_list + (a_address, ) else: tup_list = (a_address, ) a_list[a_listname] = tup_list return a_dict, a_list else: # Log that the file doesn't exist pass return {}, {} def process(mlist, msg, msgdata): approved_addresses, approved_listnames = getapproved(APPROVED_LIST) # Not sure if i should be using msg['from'] or msg.get_sender() here sender = msgdata.get('sender', msg.get_sender()).lower() if approved_addresses.has_key(sender): listname = mlist.internal_name().lower() if not approved_listnames.has_key(listname): return if approved_listnames.has_key(listname): if not sender in approved_listnames[listname]: return _from = approved_addresses[sender].rstrip() msgdata['approved'] = 1 # Log that we approved the message here pass #Debugging statement # Now change the from header try: msg.replace_header('from', _from) except: pass #Debugging statement return # Log that we got an unapproved message pass # We let the mail go through, so it hits the moderation queue otherwise