#!/usr/bin/env python # # mmvirtdlv -- MailMan Virtual Deliver # # Sean Reifschneider, tummy.com, ltd. # Copyright, tummy.com, ltd. All Rights Reserved # # The current version of this program is for QMail only. # # The idea behind mmvirtdel is to allow automatic detection of new # mailman mailing lists. It uses the "EXT" environment variables # as provided by QMail to determine the name of the list and the # function (request, owner, post). If it can't determine the name # of the list or there is an invalid function specified, the message # is run through "forwardCmd" (default, forward to mailman-owner). # # Setup: # Change "mailmanHome" to the home directory for mailman. # ("lists/" and "mail/wrapper" must exist under that directory) # Go to the mailman home directory and create ".qmail-default" containing: # |/path/to/mmvirtdel # Make sure that mail for "list" is now sent to "mailman-domain.com-list": # Add "lists.domain.com:mailman-lists.domain.com" to # "/var/qmail/control/virtualdomains" # Set up the appropriate alias files which forward the mail to # "mailman-domain.com-list" (though that's what we're trying to get # away from) mailmanHome = '/home/mailman' forwardCmd = '/var/qmail/forward mailman-owner' destList = { 'owner' : 'mailowner %s', 'request' : 'mailcmd %s', 'admin' : 'mailowner %s', 'list' : 'post %s' } import os import string ############## def getExts(): '''Return a list of the extensions. Doing a string.join(list, '-') should result in the full extension of the local address.''' def addExt(l, e): s = os.environ.get(e, None) if s: rstrip = string.join(l, '-') if len(s) >= len(rstrip) and s[-len(rstrip):] == rstrip: s = s[:-(len(rstrip) + 1)] l.insert(0, s) l = [] addExt(l, 'EXT4') addExt(l, 'EXT3') addExt(l, 'EXT2') addExt(l, 'EXT') return(l) ################################ # determine destination of list extList = getExts() destName = extList[1] destCmd = None # if len(extList) == 2: destType = destList.get('list', None) # if len(extList) == 3: destType = destList.get(extList[2], None) # if unknown destination, send to mailman-owner if not destType: destCmd = forwardCmd # check for list existance if not destCmd: destDir = os.path.join(mailmanHome, 'lists', destName) if not os.path.exists(destDir): destCmd = forwardCmd # otherwise, create "forward to list" command if not destCmd: destCmd = os.path.join(mailmanHome, 'mail', 'wrapper') destCmd = destCmd + ' ' + (destType % destName) ret = os.system(destCmd) os.exit(ret)