And now I see that the patch message fell victim my experiments.
Sigh. Do not look at laser with remaining eye.
Here it is again.
Here is a preliminary patch against TMDA 1.0 to add shell=
and python= as tag actions. The python= action uses eval.
I think the most significant change is that I have changed
the regexp for matching tag_action. I _have_ preserved the
(undocumented) behaviour of allowing string literals assigned to
headers.
Reading the output from the shell is not very elegant, to my perl
accustomed eyes. Oh well.
B.T.W., I found kodos, the python regex debugger to be very cool.
diff -ruN tmda-1.0/TMDA/FilterParser.py tmda-current/TMDA/FilterParser.py
--- tmda-1.0/TMDA/FilterParser.py Tue Sep 2 00:53:52 2003
+++ tmda-current/TMDA/FilterParser.py Mon Feb 2 12:27:47 2004
@@ -238,10 +238,13 @@
""", re.VERBOSE)
tag_action = re.compile(r"""
- ( [A-Za-z][-\w]+ )
- \s+
- (?: ([\'\"]) ( (?: \\\2 | . )+? ) \2
- | ( \S+ ) )
+ ( [A-Za-z][-\w]+ )
+ \s+
+ (\w+\s*=\s*)?
+ (?:
+ ([\'\"]) ( (?: \\\3 | . )+? ) \3
+ | ( \S+ )
+ )
""", re.VERBOSE)
in_action = re.compile(r"""
@@ -252,7 +255,7 @@
out_action = re.compile(r"""
( (?:(?:bare|sender|domain|dated)(?:=\S+)?)
- | (?:(?:exp(?:licit)?|as|ext(?:ension)?|kw|keyword)=\S+)
+ | (?:(?:exp(?:licit)?|as|ext(?:ension)?|kw|keyword|shell|python)=\S+)
| default )""", re.VERBOSE | re.IGNORECASE)
arg_option = re.compile(r'(\w+)(=?)')
@@ -649,7 +652,8 @@
errstr += 'malformed header field or missing <action>'
raise Error, errstr
header = string.lower(mo.group(1))
- action = mo.group(3) or mo.group(4)
+ action = mo.group(2) + (mo.group(4) or mo.group(5))
+
if action:
if not actions:
actions = {}
diff -ruN tmda-1.0/bin/tmda-inject tmda-current/bin/tmda-inject
--- tmda-1.0/bin/tmda-inject Tue Sep 2 00:53:52 2003
+++ tmda-current/bin/tmda-inject Sun Feb 1 14:14:52 2004
@@ -194,6 +194,7 @@
elif cookie_type in ('as','exp','explicit') and cookie_option:
# Send a message with an explicitly defined address.
field = cookie_option
+
elif cookie_type in ('ext','extension') and cookie_option:
# Send a message with a tagged (extension added) address.
(username, hostname) = string.split(from_address,'@')
@@ -202,6 +203,17 @@
elif cookie_type in ('kw','keyword') and cookie_option:
# Send a message with a tagged (keyword) address.
field = Cookie.make_keyword_address(from_address, cookie_option)
+ elif cookie_type == 'python':
+ field = str(eval(cookie_option))
+ elif cookie_type == 'shell':
+ # warning, this was written by a perl programmer.
+ field="";
+ fin, fout, ferr=os.popen3(cookie_option,"r")
+ for line in fout.readlines():
+ line=line.splitlines()[0]
+ if (len(field)>0):
+ field = field + " "
+ field+=line
elif not cookie_type:
# cookie_type == None means field is a text string
field = cookie_option
@@ -294,7 +306,7 @@
for header in custom_headers:
(cookie_type, cookie_option) = actions[header]
field = make_field(cookie_type, cookie_option, from_address, to_address)
- if cookie_type:
+ if not (cookie_type in ('python','shell', None)):
field = message_format(field, full_name,
Defaults.MESSAGE_TAG_HEADER_STYLE)
nice_header = string.capwords(header.replace('-', ' ')).replace(' ', '-')
_________________________________________________
tmda-workers mailing list ([EMAIL PROTECTED])
http://tmda.net/lists/listinfo/tmda-workers