Update of /cvsroot/tmda/tmda/TMDA
In directory usw-pr-cvs1:/tmp/cvs-serv22628/TMDA

Modified Files:
        ChangeLog Defaults.py Util.py 
Log Message:
New feature.

TEMPLATE_DIR_MATCH_SENDER provides a way to further specialize the
template selection process.

When enabled, TMDA looks for a subdirectory of TEMPLATE_DIR that
matches the sender address, and then increasingly general portions of
the domain part of the address.

For example, if mail arrives from [EMAIL PROTECTED], we'd look for
templates in these subdirectories under TEMPLATE_DIR, in this order:

  [EMAIL PROTECTED]/
  bar.baz.de/
  baz.de/
  de/

If no sender based templates are found, TEMPLATE_DIR and then the
default template locations are tried.


Index: ChangeLog
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/ChangeLog,v
retrieving revision 1.235
retrieving revision 1.236
diff -u -r1.235 -r1.236
--- ChangeLog   24 Oct 2002 17:52:11 -0000      1.235
+++ ChangeLog   1 Nov 2002 22:53:07 -0000       1.236
@@ -1,3 +1,9 @@
+2002-11-01  Jason R. Mastaler  <[EMAIL PROTECTED]>
+
+       * Util.py (maketext): Recognize TEMPLATE_DIR_MATCH_SENDER.
+       
+       * Defaults.py (TEMPLATE_DIR_MATCH_SENDER): New variable.
+
 2002-10-18  Jason R. Mastaler  <[EMAIL PROTECTED]>
 
        * Util.py (normalize_sender): New fuction, moved from

Index: Defaults.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/Defaults.py,v
retrieving revision 1.149
retrieving revision 1.150
diff -u -r1.149 -r1.150
--- Defaults.py 24 Oct 2002 20:36:16 -0000      1.149
+++ Defaults.py 1 Nov 2002 22:53:07 -0000       1.150
@@ -545,6 +545,32 @@
 if not vars().has_key('TEMPLATE_DIR'):
     TEMPLATE_DIR = None
 
+# TEMPLATE_DIR_MATCH_SENDER
+# Set this variable to 1 if you want to use sender specific template
+# directory matching. Make sure you also have TEMPLATE_DIR set.
+#
+# With this feature enabled, TMDA will look for templates in a
+# subdirectory of TEMPLATE_DIR that matches the sender address, and
+# then increasingly general portions of the domain part of the address.
+#
+# For example, if mail arrives from [EMAIL PROTECTED], TMDA will look for
+# templates in these subdirectories of TEMPLATE_DIR, in this order:
+#
+#  [EMAIL PROTECTED]/
+#
+#  bar.baz.de/
+#
+#  baz.de/
+#
+#  de/
+#
+# If no sender based templates can be found, TEMPLATE_DIR itself and
+# then the default locations will be tried.
+#
+# Default is 0 (turned off)
+if not vars().has_key('TEMPLATE_DIR_MATCH_SENDER'):
+    TEMPLATE_DIR_MATCH_SENDER = 0
+
 # TEMPLATE_EMAIL_HEADERS
 # A list containing the names of headers in your templates that
 # contain an e-mail address.  This is necessary so that the e-mail

Index: Util.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/Util.py,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -r1.71 -r1.72
--- Util.py     18 Oct 2002 22:36:16 -0000      1.71
+++ Util.py     1 Nov 2002 22:53:08 -0000       1.72
@@ -635,9 +635,10 @@
 
      Several locations are scanned for templatefile, in the following order:
      1. The directory specified by tmda-filter's `-t' option.
-     2. Defaults.TEMPLATE_DIR
-     3. ../templates/
-     4. The package/RPM template directory.
+     2. Defaults.TEMPLATE_DIR_MATCH_SENDER (if true)
+     3. Defaults.TEMPLATE_DIR
+     4. ../templates/
+     5. The package/RPM template directories.
 
     The first match found stops the search.  In this way, you can
     specialize templates at the desired level, or, if you use only the
@@ -655,9 +656,17 @@
     # Calculate the locations to scan.
     searchdirs = []
     searchdirs.append(os.environ.get('TMDA_TEMPLATE_DIR'))
+    if Defaults.TEMPLATE_DIR_MATCH_SENDER and Defaults.TEMPLATE_DIR:
+        sender = os.environ.get('SENDER').lower()
+        searchdirs.append(os.path.join(Defaults.TEMPLATE_DIR, sender))
+        domainparts = sender.split('@', 1)[1].split('.')
+        for i in range(len(domainparts)):
+            searchdirs.append(os.path.join
+                              (Defaults.TEMPLATE_DIR, '.'.join(domainparts)))
+            del domainparts[0]
     searchdirs.append(Defaults.TEMPLATE_DIR)
-    searchdirs.append(Defaults.PARENTDIR + '/templates/')
-    searchdirs.append(sys.prefix + '/share/tmda/')
+    searchdirs.append(os.path.join(Defaults.PARENTDIR, 'templates'))
+    searchdirs.append(os.path.join(sys.prefix, 'share/tmda'))
     searchdirs.append('/etc/tmda/')
     # Start scanning.
     foundit = None

_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs

Reply via email to