Lloyd Zusman <[EMAIL PROTECTED]> writes:
> OK. In the absence of further suggestions, I am now getting started on
> this work. I'll make use of the five-variable methodology suggested
> here.
Well, most of this turns out to be ridiculously easy to implement. I
already have a first cut of a patch for tmda-1.1.11 that implements the
following hooks:
PENDING_RELEASE_ACTION_HOOK
PENDING_DELETE_ACTION_HOOK
PENDING_WHITELIST_ACTION_HOOK
PENDING_BLACKLIST_ACTION_HOOK
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?
This patch alters Defaults.py and Pending.py. The documentation within
Defaults.py explains how to use these four variables.
It would be very helpful of one or more of you would look this patch
over, critique it, test it, etc. Thank you very much in advance.
Here's the patch:
--- Defaults.py.orig 2007-04-01 12:51:53.000000000 -0400
+++ Defaults.py 2007-04-01 14:42:38.000000000 -0400
@@ -1213,4 +1213,80 @@
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_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 +1675,8 @@
'PENDING_RELEASE_APPEND': None,
'PENDING_WHITELIST_APPEND': None,
+ 'PENDING_RELEASE_ACTION_HOOK' : None,
+ 'PENDING_DELETE_ACTION_HOOK' : None,
+ 'PENDING_WHITELIST_ACTION_HOOK' : None,
+ 'PENDING_BLACKLIST_ACTION_HOOK' : None,
'RESPONSE_DIR': None,
'SENDMAIL_PROGRAM': None,
--- Pending.py.orig 2007-04-01 13:06:15.000000000 -0400
+++ Pending.py 2007-04-01 14:45:33.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.
_________________________________________________
tmda-workers mailing list ([email protected])
http://tmda.net/lists/listinfo/tmda-workers