diff options
Diffstat (limited to 'Mailman/MTA/Postfix.py')
| -rw-r--r-- | Mailman/MTA/Postfix.py | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/Mailman/MTA/Postfix.py b/Mailman/MTA/Postfix.py index ebf934871..124c18999 100644 --- a/Mailman/MTA/Postfix.py +++ b/Mailman/MTA/Postfix.py @@ -35,6 +35,7 @@ from Mailman.i18n import _ LOCKFILE = os.path.join(config.LOCK_DIR, 'creator') ALIASFILE = os.path.join(config.DATA_DIR, 'aliases') VIRTFILE = os.path.join(config.DATA_DIR, 'virtual-mailman') +TRPTFILE = os.path.join(config.DATA_DIR, 'transport') log = logging.getLogger('mailman.error') @@ -42,6 +43,13 @@ log = logging.getLogger('mailman.error') def _update_maps(): msg = 'command failed: %s (status: %s, %s)' + if config.USE_LMTP: + tcmd = config.POSTFIX_MAP_CMD + ' ' + TRPTFILE + status = (os.system(tcmd) >> 8) & 0xff + if status: + errstr = os.strerror(status) + log.error(msg, tcmd, status, errstr) + raise RuntimeError(msg % (tcmd, status, errstr)) acmd = config.POSTFIX_ALIAS_CMD + ' ' + ALIASFILE status = (os.system(acmd) >> 8) & 0xff if status: @@ -73,6 +81,7 @@ def _zapfile(filename): def clear(): _zapfile(ALIASFILE) _zapfile(VIRTFILE) + _zapfile(TRPTFILE) @@ -202,6 +211,35 @@ def _check_for_virtual_loopaddr(mlist, filename): +def _addtransport(mlist, fp): + # create/add postfix transport file for mailman + fp.seek(0, 2) + if not fp.tell(): + print >> fp, """\ +# This file is generated by Mailman, and is kept in sync with the +# binary hash file transport.db. YOU SHOULD NOT MANUALLY EDIT THIS FILE +# unless you know what you're doing, and can keep the two files properly +# in sync. If you screw it up, you're on your own. +""" + if mlist is None: + return + listname = mlist.internal_name() + hostname = mlist.host_name + fieldsz = len(listname) + len(hostname) + len('-unsubscribe') + 1 + # The text file entries get a little extra info + print >> fp, '# STANZA START:', listname + '@' + hostname + print >> fp, '# CREATED:', time.ctime(time.time()) + # Now add transport entries + for k, v in makealiases(mlist): + l = len(k + hostname) + 1 + print >> fp, '%s@%s' % (k, hostname), ((fieldsz - l) * ' ')\ + + 'lmtp:%s:%s' % (config.LMTP_HOST, config.LMTP_PORT) + # + print >> fp, '# STANZA END:', '%s@%s' % (listname, hostname) + print >> fp + + + def _do_create(mlist, textfile, func): # Crack open the plain text file try: @@ -228,6 +266,14 @@ def create(mlist, cgi=False, nolock=False, quiet=False): if not nolock: lock = makelock() lock.lock() + # Create transport file if USE_LMTP + if config.USE_LMTP: + try: + _do_create(mlist, TRPTFILE, _addtransport) + _update_maps() + finally: + if lock: + lock.unlock(unconditionally=True) # Do the aliases file, which need to be done in any case try: _do_create(mlist, ALIASFILE, _addlist) @@ -292,6 +338,12 @@ def remove(mlist, cgi=False): # Acquire the global list database lock lock = makelock() lock.lock() + if config.USE_LMTP: + try: + _do_remove(mlist, TRPTFILE, False) + _update_maps() + finally: + lock.unlock(unconditionally=True) try: _do_remove(mlist, ALIASFILE, False) if mlist.host_name in config.POSTFIX_STYLE_VIRTUAL_DOMAINS: @@ -305,7 +357,7 @@ def remove(mlist, cgi=False): def checkperms(state): targetmode = S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP - for file in ALIASFILE, VIRTFILE: + for file in ALIASFILE, VIRTFILE, TRPTFILE: if state.VERBOSE: print _('checking permissions on %(file)s') stat = None |
