Re: My first cut at the patch
Lloyd Zusman <[email protected]> Sun, 01 Apr 2007 18:14:23 -0400
| Newsgroups | gmane.mail.spam.tmda.devel |
|---|---|
| Message-ID | <[email protected]> |
--=-=-= Lloyd Zusman <[email protected]> writes: > [ ... ] > > I couldn't figure out how to distinguish between a "release" and a > "confirm", so I haven't yet written the "confirm" hook that was > suggested by Ole Wolf. Does anyone know how to make that distinction > within the tmda-1.1.11 code base? Well, I now think that I've figured it out. The confirmation logic is handled in tmda-rfilter, and I have now also patched that file. Therefore, I now have a patch for tmda-1.1.11 which adds all five variables: PENDING_RELEASE_ACTION_HOOK PENDING_CONFIRM_ACTION_HOOK PENDING_DELETE_ACTION_HOOK PENDING_WHITELIST_ACTION_HOOK PENDING_BLACKLIST_ACTION_HOOK All the documentation can be found in the patched version of Defaults.py. Once again, any help in testing this would be very much appreciated. The patch: --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=tmda-action-hook.patch Content-Description: Second attempt for the action hook patch --- bin/tmda-rfilter.orig 2007-04-01 17:59:00.000000000 -0400 +++ bin/tmda-rfilter 2007-04-01 18:00:45.000000000 -0400 @@ -474,4 +474,7 @@ def release_pending(timestamp, pid, msg): """Release a confirmed message from the pending queue.""" + # If there is a pending confirm hook, attempt to pipe + # the message through it. + msg.tryActionHook(Defaults.PENDING_CONFIRM_ACTION_HOOK) # Remove Return-Path: to avoid duplicates. return_path = return_path = parseaddr(msg.get('return-path'))[1] --- TMDA/Defaults.py.orig 2007-04-01 12:51:53.000000000 -0400 +++ TMDA/Defaults.py 2007-04-01 18:03:12.000000000 -0400 @@ -1213,4 +1213,99 @@ PENDING_WHITELIST_RELEASE = 1 +# PENDING_RELEASE_ACTION_HOOK +# Path of an optional executable that will be run when a message +# is being released from the pending queue, right before this +# release takes place. +# +# It will be run as follows: +# +# /path/to/executable /path/to/pending-message-file +# +# The message text will be available in this executable's stdin. +# +# When this executable is invoked, all TMDA configuration +# variables will be available in the environment in the +# form of strings. +# +# Default is None +if not vars().has_key('PENDING_RELEASE_ACTION_HOOK'): + PENDING_RELEASE_ACTION_HOOK = None + +# PENDING_CONFIRM_ACTION_HOOK +# Path of an optional executable that will be run when a message +# is being confirmed from the pending queue, right before this +# confirmation takes place. +# +# It will be run as follows: +# +# /path/to/executable /path/to/pending-message-file +# +# The message text will be available in this executable's stdin. +# +# When this executable is invoked, all TMDA configuration +# variables will be available in the environment in the +# form of strings. +# +# Default is None +if not vars().has_key('PENDING_CONFIRM_ACTION_HOOK'): + PENDING_CONFIRM_ACTION_HOOK = None + +# PENDING_DELETE_ACTION_HOOK +# Path of an optional executable that will be run when a message +# is being deleted from the pending queue, right before this +# deletion takes place. +# +# It will be run as follows: +# +# /path/to/executable /path/to/pending-message-file +# +# The message text will be available in this executable's stdin. +# +# When this executable is invoked, all TMDA configuration +# variables will be available in the environment in the +# form of strings. +# +# Default is None +if not vars().has_key('PENDING_DELETE_ACTION_HOOK'): + PENDING_DELETE_ACTION_HOOK = None + +# PENDING_WHITELIST_ACTION_HOOK +# Path of an optional executable that will be run when a message +# is being whitelisted from the pending queue, right before this +# whitelisting takes place. +# +# It will be run as follows: +# +# /path/to/executable /path/to/pending-message-file +# +# The message text will be available in this executable's stdin. +# +# When this executable is invoked, all TMDA configuration +# variables will be available in the environment in the +# form of strings. +# +# Default is None +if not vars().has_key('PENDING_WHITELIST_ACTION_HOOK'): + PENDING_WHITELIST_ACTION_HOOK = None + +# PENDING_BLACKLIST_ACTION_HOOK +# Path of an optional executable that will be run when a message +# is being blacklisted from the pending queue, right before this +# blacklisting takes place. +# +# It will be run as follows: +# +# /path/to/executable /path/to/pending-message-file +# +# The message text will be available in this executable's stdin. +# +# When this executable is invoked, all TMDA configuration +# variables will be available in the environment in the +# form of strings. +# +# Default is None +if not vars().has_key('PENDING_BLACKLIST_ACTION_HOOK'): + PENDING_BLACKLIST_ACTION_HOOK = None + # ADDED_HEADERS_CLIENT # A Python dictionary containing one or more header:value string pairs @@ -1599,4 +1694,9 @@ 'PENDING_RELEASE_APPEND': None, 'PENDING_WHITELIST_APPEND': None, + 'PENDING_RELEASE_ACTION_HOOK' : None, + 'PENDING_CONFIRM_ACTION_HOOK' : None, + 'PENDING_DELETE_ACTION_HOOK' : None, + 'PENDING_WHITELIST_ACTION_HOOK' : None, + 'PENDING_BLACKLIST_ACTION_HOOK' : None, 'RESPONSE_DIR': None, 'SENDMAIL_PROGRAM': None, --- TMDA/Pending.py.orig 2007-04-01 13:06:15.000000000 -0400 +++ TMDA/Pending.py 2007-04-01 18:00:06.000000000 -0400 @@ -28,6 +28,8 @@ import email import os +import re import sys import time +from types import * import Defaults @@ -40,4 +42,5 @@ Q = Q.init() +DefaultVarPat = re.compile('^[A-Z][A-Z0-9_]*$') class Queue: @@ -366,7 +369,29 @@ self.x_primary_address, self.return_path) + + def tryActionHook(self, hook): + """Attempt to run an action hook""" + if hook is None: + return + # Put all appropriate Defaults variables into the environment. + for (k, v) in vars(Defaults).items(): + if DefaultVarPat.search(k): + try: + if v is None: + del os.environ[k] + else: + os.environ[k] = str(v) + except: + pass + pendpath = os.path.join(Defaults.PENDING_DIR, self.msgid + '.msg') + # This will throw an exception upon failure. + Util.pipecmd('%s %s' % (hook, pendpath), self.show()) + def release(self): """Release a message from the pending queue.""" import Cookie + # If there is a pending release hook, attempt to pipe + # the message through it. + self.tryActionHook(Defaults.PENDING_RELEASE_ACTION_HOOK) if Defaults.PENDING_RELEASE_APPEND: Util.append_to_file(self.append_address, @@ -401,4 +426,7 @@ def delete(self): """Delete a message from the pending queue.""" + # If there is a pending delete hook, attempt to pipe + # the message through it. + self.tryActionHook(Defaults.PENDING_DELETE_ACTION_HOOK) if Defaults.PENDING_DELETE_APPEND: Util.append_to_file(self.append_address, @@ -408,4 +436,7 @@ def whitelist(self): """Whitelist the message sender.""" + # If there is a pending whitelist hook, attempt to pipe + # the message through it. + self.tryActionHook(Defaults.PENDING_WHITELIST_ACTION_HOOK) if Defaults.PENDING_WHITELIST_APPEND: Util.append_to_file(self.append_address, @@ -419,4 +450,7 @@ def blacklist(self): """Blacklist the message sender.""" + # If there is a pending blacklist hook, attempt to pipe + # the message through it. + self.tryActionHook(Defaults.PENDING_BLACKLIST_ACTION_HOOK) if Defaults.PENDING_BLACKLIST_APPEND: Util.append_to_file(self.append_address, --=-=-= -- Lloyd Zusman [email protected] God bless you. --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline