Lloyd Zusman <[EMAIL PROTECTED]> writes:
> Thank you very much.
Don't thank me so fast. I woke up this morning and realized it won't
work for any MTA but qmail. :-(
> I will apply this patch, and I'll have feedback within a day or so.
Instead, try applying the new one I've attached.
The problem is that TMDA always returns 0 except in qmail's case. I
had discovered this fairly early, then completely forgotten it while
actually figuring out what code I needed. The exception to this is
when a Python exception occurs and TMDA defers the message. Then the
return code is 75.
I opted to use 99 as the "error" code (even though confirming,
dropping, etc. aren't really errors). This is the same return code
that qmail uses to mean "successful, but stop processing".
Because the other MTAs have no equivalent error code, you *don't* want
maildrop/procmail to pass this code back to the MTA. I have no idea
what Exim/Postfix/Sendmail will do with it. That means your maildrop
processing, for example, should look like this
EXITCODE=0
exception {
xfilter /usr/local/tmda/bin/tmda-filter -p
# DO FURTHER PROCESSING HERE
}
if ($RETURNCODE == 75)
{
EXITCODE=$RETURNCODE
exit
}
instead of always setting EXITCODE=$RETURNCODE. You don't want the 99
to get back to the MTA (this is for non-qmail/Courier MTAs).
> EXITCODE=0
>
> exception {
>
> xfilter "/usr/local/bin/runTmda"
>
> EXITCODE=$RETURNCODE
> if ( $EXITCODE == 0 )
> {
> # We will only be here if runTmda (and therefore, tmda-filter)
> # accepts the message and returns a zero exit code.
>
> # DO FURTHER PROCESSING HERE
> }
>
> }
I don't think you need to test $EXITCODE or $RETURNCODE inside the
exception block, since if xfilter returned non-zero, you will
immediately jump to the end of the exception block. Therefore, inside
the block you already know that the $RETURNCODE was 0.
Tim
Index: TMDA/Deliver.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/Deliver.py,v
retrieving revision 1.15
diff -u -r1.15 Deliver.py
--- TMDA/Deliver.py 25 May 2003 02:21:20 -0000 1.15
+++ TMDA/Deliver.py 27 May 2003 15:46:45 -0000
@@ -27,6 +27,7 @@
import signal
import socket
import stat
+import sys
import time
import Defaults
@@ -98,6 +99,9 @@
self.delivery_dest = self.option
if firstchar == '~':
self.delivery_dest = os.path.expanduser(self.delivery_dest)
+ elif self.option == '_filter_':
+ self.delivery_type = 'filter'
+ self.delivery_dest = 'stdout'
# Unknown delivery instruction.
else:
raise Errors.DeliveryError, \
@@ -138,6 +142,8 @@
else:
# don't wrap headers, don't escape From, don't add From_ line
self.__deliver_maildir(Util.msg_as_string(self.msg), dest)
+ elif type == 'filter':
+ sys.stdout.write(Util.msg_as_string(self.msg))
def __deliver_program(self, message, program):
"""Deliver message to /bin/sh -c program."""
Index: TMDA/MTA.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/MTA.py,v
retrieving revision 1.16
diff -u -r1.16 MTA.py
--- TMDA/MTA.py 25 May 2003 02:09:19 -0000 1.16
+++ TMDA/MTA.py 27 May 2003 15:46:46 -0000
@@ -51,11 +51,13 @@
sys.exit(self.EX_OK)
def deliver(self, msg, instruction=None):
- if instruction is None:
+ if instruction is None or self.default_delivery == '_filter_':
instruction = self.default_delivery
msg = Deliver.Deliver(msg, instruction)
msg.deliver()
- self.stop()
+ if self.default_delivery == '_filter_':
+ self.stop()
+ sys.exit(99)
class Exim(MTA):
@@ -91,13 +93,15 @@
sys.exit(self.EX_STOP)
def deliver(self, msg, instruction=None):
- if instruction is None:
+ if instruction is None or self.default_delivery == '_filter_':
instruction = self.default_delivery
if instruction == '_qok_':
sys.exit(self.EX_OK)
else:
msg = Deliver.Deliver(msg, instruction)
msg.deliver()
+ if instruction == '_filter_':
+ sys.exit(self.EX_OK)
self.stop()
Index: bin/tmda-rfilter
===================================================================
RCS file: /cvsroot/tmda/tmda/bin/tmda-rfilter,v
retrieving revision 1.94
diff -u -r1.94 tmda-rfilter
--- bin/tmda-rfilter 26 May 2003 15:32:52 -0000 1.94
+++ bin/tmda-rfilter 27 May 2003 15:46:48 -0000
@@ -74,6 +74,7 @@
filter_match = None
discard = None
+act_as_filter = 0
program = sys.argv[0]
def usage(code, msg=''):
@@ -84,13 +85,14 @@
try:
opts, args = getopt.getopt(sys.argv[1:],
- 'c:dt:I:M:Vh', ['config-file=',
- 'discard',
- 'template-dir=',
- 'filter-incoming-file=',
- 'filter-match=',
- 'version',
- 'help'])
+ 'c:dpt:I:M:Vh', ['config-file=',
+ 'discard',
+ 'print',
+ 'template-dir=',
+ 'filter-incoming-file=',
+ 'filter-match=',
+ 'version',
+ 'help'])
except getopt.error, msg:
usage(1, msg)
@@ -111,6 +113,8 @@
os.environ['TMDA_TEMPLATE_DIR'] = arg
elif opt in ('-d', '--discard'):
discard = 1
+ elif opt in ('-p', '--print'):
+ act_as_filter = 1
elif opt in ('-c', '--config-file'):
os.environ['TMDARC'] = arg
@@ -138,7 +142,10 @@
recip = sys.argv[-2]
Util.filter_match(Defaults.FILTER_INCOMING, recip, sender)
sys.exit()
-
+
+if act_as_filter:
+ Defaults.DELIVERY = '_filter_'
+
# We use this MTA instance to control the fate of the message.
mta = MTA.init(Defaults.MAIL_TRANSFER_AGENT, Defaults.DELIVERY)