CVS: tmda/TMDA ChangeLog,1.276,1.277 FilterParser.py,1.56,1.57 Util.py,1.97,1.98

"Jason R. Mastaler" <[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-serv26285/TMDA

Modified Files:
	ChangeLog FilterParser.py Util.py 
Log Message:
New feature.  The bounce,reject FILTER_INCOMING action now takes an
optional 'template' argument to bounce using a specific template
rather than the default template (bounce.txt).

The argument can either be an absolute pathname (including tilde
expansion) or a relative (to TEMPLATE_DIR) pathname.  Assuming
TEMPLATE_DIR is set to ~/.tmda/templates, each of the following
instructions are equivalent:

 from johndoe* bounce = /users/jasonrm/.tmda/templates/bounce_freemail.txt
 from johndoe* bounce = ~/.tmda/templates/bounce_freemail.txt
 from johndoe* bounce = ~jasonrm/.tmda/templates/bounce_freemail.txt
 from johndoe* bounce = bounce_freemail.txt


Index: ChangeLog
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/ChangeLog,v
retrieving revision 1.276
retrieving revision 1.277
diff -u -r1.276 -r1.277
--- ChangeLog	5 Jun 2003 14:30:41 -0000	1.276
+++ ChangeLog	9 Jun 2003 02:20:51 -0000	1.277
@@ -1,3 +1,13 @@
+2003-06-08  Jason R. Mastaler  <[email protected]>
+
+	* Util.py (maketext): Now accepts an absolute pathname to a
+	template file which short-circuits the searching process.
+
+2003-06-08  Jason R. Mastaler  <[email protected]>
+
+	* FilterParser.py (_FilterFile.__init__): bounce,reject now can
+	take an option, which is the path to a specific template.
+
 2003-06-05  Cory Wright <[email protected]>
 
 	* Util.py (maketext): Recognize TEMPLATE_DIR_MATCH_RECIPIENT.

Index: FilterParser.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/FilterParser.py,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -r1.56 -r1.57
--- FilterParser.py	10 May 2003 21:23:38 -0000	1.56
+++ FilterParser.py	9 Jun 2003 02:20:51 -0000	1.57
@@ -244,10 +244,9 @@
     """, re.VERBOSE)
 
     in_action = re.compile(r"""
-    ( bounce | reject
-    | drop | exit | stop
+    ( drop | exit | stop
     | confirm | hold
-    | (?: deliver | ok | accept)(?:\s*=.*$)? )
+    | (?: bounce | reject | deliver | ok | accept)(?:\s*=.*$)? )
     """, re.VERBOSE | re.IGNORECASE)
     
     out_action = re.compile(r"""

Index: Util.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/Util.py,v
retrieving revision 1.97
retrieving revision 1.98
diff -u -r1.97 -r1.98
--- Util.py	5 Jun 2003 14:04:30 -0000	1.97
+++ Util.py	9 Jun 2003 02:20:51 -0000	1.98
@@ -847,13 +847,19 @@
 def maketext(templatefile, vardict):
     """Make some text from a template file.
 
-     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_MATCH_RECIPIENT (if true)
-     4. Defaults.TEMPLATE_DIR
-     5. ../templates/
-     6. The package/RPM template directories.
+    templatefile can either be an absolute pathname starting with an /
+    or ~ (e.g, /usr/local/packages/tmda/templates/bounce.txt) or a
+    relative pathname (e.g, bounce.txt).
+
+    Given a relative pathname, 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_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
@@ -868,51 +874,57 @@
     and licensed under the GNU General Public License version 2.
     """
     import Defaults
-    # 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))
-        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)))
-                del domainparts[0]
-        except IndexError:
-            pass
-    searchdirs.append(Defaults.TEMPLATE_DIR)
-    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
-    for dir in searchdirs:
-        if dir:
-            filename = os.path.join(dir, templatefile)
-            if os.path.exists(filename):
-                foundit = filename
-                break
+    if (templatefile[0] == '/' or templatefile[0] == '~'):
+        if templatefile[0] == '~':
+            templatefile = os.path.expanduser(templatefile)
+        if os.path.exists(templatefile):
+            foundit = templatefile
+    else:
+        # 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))
+            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)))
+                    del domainparts[0]
+            except IndexError:
+                pass
+        searchdirs.append(Defaults.TEMPLATE_DIR)
+        searchdirs.append(os.path.join(Defaults.PARENTDIR, 'templates'))
+        searchdirs.append(os.path.join(sys.prefix, 'share/tmda'))
+        searchdirs.append('/etc/tmda/')
+        # Start scanning.
+        for dir in searchdirs:
+            if dir:
+                filename = os.path.join(dir, templatefile)
+                if os.path.exists(filename):
+                    foundit = filename
+                    break
     if foundit is None:
         raise IOError, "Can't find " + templatefile
     else:

_______________________________________
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.