CVS: tmda/TMDA Defaults.py,1.181,1.182 Util.py,1.96,1.97

Cory Wright <[email protected]>
Newsgroups gmane.mail.spam.tmda.cvs
Message-ID <[email protected]>
Update of /cvsroot/tmda/tmda/TMDA
In directory sc8-pr-cvs1:/tmp/cvs-serv31306/TMDA

Modified Files:
	Defaults.py Util.py 
Log Message:
Added the TEMPLATE_DIR_MATCH_RECIPIENT feature to allow customized
templates depending on the TMDA_RECIPIENT variable.


Index: Defaults.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/Defaults.py,v
retrieving revision 1.181
retrieving revision 1.182
diff -u -r1.181 -r1.182
--- Defaults.py	26 May 2003 00:43:05 -0000	1.181
+++ Defaults.py	5 Jun 2003 14:04:29 -0000	1.182
@@ -550,6 +550,40 @@
 if not vars().has_key('TEMPLATE_DIR'):
     TEMPLATE_DIR = None
 
+# TEMPLATE_DIR_MATCH_RECIPIENT
+# Set this variable to 1 if you want to use specific templates for
+# different recipient addresses.  Be sure to set TEMPLATE_DIR as well.
+#
+# The TEMPLATE_DIR_MATCH_RECIPIENT feature enables TMDA to search for
+# customized template files based on the recipient address.  To continue
+# with the example given for TEMPLATE_DIR_MATCH_SENDER, if a message
+# arrives for [email protected] then TMDA will search for
+# template files in the following directories:
+#
+#  [email protected]/
+#
+#  [email protected]/
+#
+#  [email protected]/
+#
+#  bar.baz.de/
+#
+#  baz.de/
+#
+#  de/
+#
+# This example assumes that RECIPIENT_DELIMITER is set to `-'.  This
+# feature also works for *-confirm-* addresses.
+#
+# When both TEMPLATE_DIR_MATCH_RECIPIENT and TEMPLATE_DIR_MATCH_SENDER
+# are enabled, the TEMPLATE_DIR_MATCH_RECIPIENT directories are searched
+# after the sender directories.
+#
+# Default is 0 (turned off)
+
+if not vars().has_key('TEMPLATE_DIR_MATCH_RECIPIENT'):
+    TEMPLATE_DIR_MATCH_RECIPIENT = 0
+
 # 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.

Index: Util.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/Util.py,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -r1.96 -r1.97
--- Util.py	5 Jun 2003 04:37:31 -0000	1.96
+++ Util.py	5 Jun 2003 14:04:30 -0000	1.97
@@ -850,9 +850,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_MATCH_SENDER (if true)
-     3. Defaults.TEMPLATE_DIR
-     4. ../templates/
-     5. The package/RPM template directories.
+     3. Defaults.TEMPLATE_DIR_MATCH_RECIPIENT (if true)
+     4. Defaults.TEMPLATE_DIR
+     5. ../templates/
+     6. 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
@@ -875,6 +876,25 @@
         searchdirs.append(os.path.join(Defaults.TEMPLATE_DIR, sender))
         try:
             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]
+        except IndexError:
+            pass
+    if Defaults.TEMPLATE_DIR_MATCH_RECIPIENT and Defaults.TEMPLATE_DIR:
+        recipient = os.environ.get('TMDA_RECIPIENT').lower()
+        searchdirs.append(os.path.join(Defaults.TEMPLATE_DIR, recipient))
+        try:
+            recippart, domainpart = recipient.split('@',1)
+            recipparts = recippart.split(Defaults.RECIPIENT_DELIMITER)
+            for i in range(len(recipparts)):
+                searchdirs.append(os.path.join
+                                  (Defaults.TEMPLATE_DIR,
+                                   Defaults.RECIPIENT_DELIMITER.join(recipparts) +
+                                   "@" + domainpart))
+                del recipparts[-1]
+            domainparts = domainpart.split('.')
             for i in range(len(domainparts)):
                 searchdirs.append(os.path.join
                                   (Defaults.TEMPLATE_DIR, '.'.join(domainparts)))

_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.