Update of /cvsroot/tmda/tmda/TMDA
In directory sc8-pr-cvs1:/tmp/cvs-serv7516
Modified Files:
ChangeLog Deliver.py MTA.py Util.py
Log Message:
Added support for virtual domains in tmda-ofmipd. Removed references to
Defaults.py where necessary.
Index: ChangeLog
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/ChangeLog,v
retrieving revision 1.247
retrieving revision 1.248
diff -u -r1.247 -r1.248
--- ChangeLog 7 Jan 2003 00:03:02 -0000 1.247
+++ ChangeLog 21 Jan 2003 05:34:54 -0000 1.248
@@ -1,3 +1,27 @@
+2003-01-20 Tim Legant <[EMAIL PROTECTED]>
+
+ * MTA.py (MTA.getvdomainprepend): Added this method to abstract
+ ancestor. It raises NotImplementedError if called.
+
+ (Qmail.getvdomainprepend): Added method to return the prepend from
+ qmail's virtualdomains file if the passed address matches one of
+ the lines in virtualdomains.
+
+ (__init__): All classes now take a default delivery action in
+ their __init__ methods.
+
+ (init): The init() function now takes a the name of an MTA and the
+ default delivery action as parameters. This removes MTA.py's
+ dependence on Defaults.py
+
+ * Deliver.py (Deliver.__deliver_maildir): Changed Defaults.PID to
+ str(os.getpid()) in order to remove Deliver.py's dependency on
+ Defaults.py.
+
+ * Util.py (getvuserhomedir): Added function to run a script that
+ is expected to print the passed in virtual user's home directory.
+ That string is captured and returned.
+
2003-01-06 Jason R. Mastaler <[EMAIL PROTECTED]>
* AutoResponse.py (AutoResponse.create): Replace input characters
Index: Deliver.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/Deliver.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Deliver.py 29 Nov 2002 01:56:26 -0000 1.9
+++ Deliver.py 21 Jan 2003 05:34:56 -0000 1.10
@@ -30,7 +30,6 @@
import stat
import time
-import Defaults
import Errors
import Util
@@ -220,7 +219,7 @@
General Public License version 2.
"""
# e.g, 1014754642.51195.aguirre.la.mastaler.com
- filename = '%s.%s.%s' % (int(time.time()), Defaults.PID,
+ filename = '%s.%s.%s' % (int(time.time()), str(os.getpid()),
socket.gethostname())
# Set a 24-hour alarm for this delivery.
signal.signal(signal.SIGALRM, alarm_handler)
Index: MTA.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/MTA.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- MTA.py 30 Sep 2002 23:45:54 -0000 1.13
+++ MTA.py 21 Jan 2003 05:34:56 -0000 1.14
@@ -25,7 +25,6 @@
import os
import sys
-import Defaults
import Deliver
import Errors
import Util
@@ -33,12 +32,13 @@
class MTA:
"""Non-qmail methods and instance variables. """
- def __init__(self):
+ def __init__(self, default_delivery):
# Exit status codes; see /usr/include/sysexits.h
self.EX_HARD = 77 # permission denied; bounce message
self.EX_OK = 0 # successful termination; exit
self.EX_STOP = None # Non-qmail MTAs don't have such an exit code
self.EX_TEMPFAIL = 75 # temporary failure; defer delivery
+ self.default_delivery = default_delivery
# Define the four states of a message.
def bounce(self):
@@ -52,28 +52,31 @@
def deliver(self, msg, instruction=None):
if instruction is None:
- instruction = Defaults.DELIVERY
+ instruction = self.default_delivery
msg = Deliver.Deliver(msg, instruction)
msg.deliver()
self.stop()
-
+
+ def getvdomainprepend(self, address, vdomainsfile):
+ raise NotImplementedError
+
class Exim(MTA):
"""Exim-specific methods and instance variables."""
- def __init__(self):
- MTA.__init__(self)
+ def __init__(self, default_delivery):
+ MTA.__init__(self, default_delivery)
class Postfix(MTA):
"""Postfix-specific methods and instance variables."""
- def __init__(self):
- MTA.__init__(self)
+ def __init__(self, default_delivery):
+ MTA.__init__(self, default_delivery)
class Qmail(MTA):
"""qmail-specific methods and instance variables."""
- def __init__(self):
- MTA.__init__(self)
+ def __init__(self, default_delivery):
+ MTA.__init__(self, default_delivery)
# qmail exit status codes; see qmail-command(8)
self.EX_HARD = 100 # hard error; bounce message
self.EX_OK = 0 # success; process next instruction
@@ -92,7 +95,7 @@
def deliver(self, msg, instruction=None):
if instruction is None:
- instruction = Defaults.DELIVERY
+ instruction = self.default_delivery
if instruction == '_qok_':
sys.exit(self.EX_OK)
else:
@@ -100,24 +103,58 @@
msg.deliver()
self.stop()
+ def getvdomainprepend(self, address, vdomainsfile):
+ ret_prepend = ''
+ if os.path.exists(vdomainsfile):
+ fp = open(vdomainsfile, 'r')
+ # Parse the virtualdomains control file; see qmail-send(8) for
+ # syntax rules. All this because qmail doesn't store the original
+ # envelope recipient in the environment.
+ u, d = address.split('@', 1)
+ ousername = u.lower()
+ odomain = d.lower()
+ for line in fp.readlines():
+ vdomain_match = 0
+ line = line.strip().lower()
+ # Comment or blank line?
+ if line == '' or line[0] in '#':
+ continue
+ vdomain, prepend = line.split(':', 1)
+ # domain:prepend
+ if vdomain == odomain:
+ vdomain_match = 1
+ # .domain:prepend (wildcard)
+ elif vdomain[:1] == '.' and odomain.find(vdomain) != -1:
+ vdomain_match = 1
+ # user@domain:prepend
+ else:
+ try:
+ if vdomain.split('@', 1)[1] == odomain:
+ vdomain_match = 1
+ except IndexError:
+ pass
+ if vdomain_match:
+ ret_prepend = prepend
+ break
+ fp.close()
+ return ret_prepend
+
class Sendmail(MTA):
"""Sendmail-specific methods and instance variables."""
- def __init__(self):
- MTA.__init__(self)
+ def __init__(self, default_delivery):
+ MTA.__init__(self, default_delivery)
-def init():
- """Factory function which determine what MTA we are running and
- instantiates the corresponding MTA subclass."""
- mta = Defaults.MAIL_TRANSFER_AGENT
+def init(mta, default_delivery):
+ """Factory function which instantiates the corresponding MTA subclass."""
if mta == 'exim':
- return Exim()
+ return Exim(default_delivery)
elif mta == 'postfix':
- return Postfix()
+ return Postfix(default_delivery)
elif mta == 'qmail':
- return Qmail()
+ return Qmail(default_delivery)
elif mta == 'sendmail':
- return Sendmail()
+ return Sendmail(default_delivery)
else:
raise Errors.ConfigError, "Unsupported MAIL_TRANSFER_AGENT: " + mta
Index: Util.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/Util.py,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -r1.75 -r1.76
--- Util.py 13 Nov 2002 01:56:53 -0000 1.75
+++ Util.py 21 Jan 2003 05:34:56 -0000 1.76
@@ -117,6 +117,15 @@
return statinfo[stat.ST_UID]
+def getvuserhomedir(user, domain, script):
+ """Return the home directory of a qmail virtual domain user."""
+ cmd = "%s %s %s" % (script, user, domain)
+ fpin = os.popen(cmd)
+ vuserhomedir = fpin.read()
+ fpin.close()
+ return vuserhomedir.strip()
+
+
def seconds(timeout):
"""Translate the defined timeout interval into seconds."""
match = re.match("^([0-9]+)([YMwdhms])$", timeout)
_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs