Update of /cvsroot/tmda/tmda/TMDA
In directory sc8-pr-cvs1:/tmp/cvs-serv13359/TMDA

Modified Files:
        ChangeLog FilterParser.py 
Log Message:
New feature. Add an optional `-domains' argument to the
from-(file|cdb|dbm) and to-(file|cdb|dbm) sources.

-domains tells the parser that the target file or DB might also
contain domain names. The portion after the first `@' in the e-mail
address is considered the "domain". e.g,

[EMAIL PROTECTED] -> mastaler.com
[EMAIL PROTECTED] -> cs.yale.edu

Domains must be one per line, in the form:

wingnet.net
mastaler.com
tmda.net
cs.yale.edu

Then an attempt will be made to straight match the domain name in
addition to the e-mail address.

This isn't wildcarding, so with the above file, [EMAIL PROTECTED]'
WOULD match, but [EMAIL PROTECTED]' WOULD NOT match. You'd have
to add wopr.wingnet.net to the list first.

Some example filter file lines:

  from-file -domains -autocdb ~/.tmda/lists/domains_allow ok
  
  to-file -domains -autocdb ~/.tmda/lists/domains_allow bare

Where `domains_allow' would contain a list of e-mail addresses and/or
domain names. Wilcards would be treated the same as they are now;
ignored if using a DBM/CDB source or option.

This feature (suggested by Jesse Guardiani) was added for sites that
wish to check a large number of domain names, but don't want the
overhead of the wildcard code. This feature is less flexible
than wildcarding, but is much faster since you can store the list
of domains in a CDB or DBM.


Index: ChangeLog
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/ChangeLog,v
retrieving revision 1.257
retrieving revision 1.258
diff -u -r1.257 -r1.258
--- ChangeLog   4 Mar 2003 18:52:49 -0000       1.257
+++ ChangeLog   12 Mar 2003 20:56:50 -0000      1.258
@@ -1,3 +1,13 @@
+2003-03-12  Jason R. Mastaler  <[EMAIL PROTECTED]>
+
+       * FilterParser.py (_FilterFile.__init__): Add `-domains', a new
+       argument for from-(file|cdb|dbm) and to-(file|cdb|dbm).
+
+       (FilterParser.__add_domains): New method.
+
+       (FilterParser.firstmatch): Use __add_domains if the `-domains'
+       argument is specified.
+       
 2003-03-04  Jason R. Mastaler  <[EMAIL PROTECTED]>
 
        * FilterParser.py (_FilterFile.__init__): Add `pipe', a new filter

Index: FilterParser.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/FilterParser.py,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- FilterParser.py     4 Mar 2003 20:52:25 -0000       1.50
+++ FilterParser.py     12 Mar 2003 20:56:52 -0000      1.51
@@ -2,6 +2,9 @@
 #
 # Copyright (C) 2001,2002 Jason R. Mastaler <[EMAIL PROTECTED]>
 #
+# Authors: Tim Legant <[EMAIL PROTECTED]> and
+#          Jason R. Mastaler <[EMAIL PROTECTED]>
+#
 # This file is part of TMDA.
 #
 # TMDA is free software; you can redistribute it and/or modify it
@@ -69,7 +72,6 @@
 
 
 class Macro:
-
     """Macro definition as parsed by the filter parser."""
 
     macro_words = re.compile(r'([_a-zA-Z][_\w]*)')
@@ -206,7 +208,6 @@
 
 
 class _FilterFile:
-    
     """Storage for per-file data.  Used internally by FilterParser."""
 
     def __init__(self, filename):
@@ -261,12 +262,12 @@
     arguments = {
         'from'         : None,
         'to'           : None,
-        'from-file'    : ('autocdb', 'autodbm', 'optional'),
-        'to-file'      : ('autocdb', 'autodbm', 'optional'),
-        'from-cdb'     : ('optional',),
-        'to-cdb'       : ('optional',),
-        'from-dbm'     : ('optional',),
-        'to-dbm'       : ('optional',),
+        'from-file'    : ('autocdb', 'autodbm', 'domains', 'optional'),
+        'to-file'      : ('autocdb', 'autodbm', 'domains', 'optional'),
+        'from-cdb'     : ('domains', 'optional',),
+        'to-cdb'       : ('domains', 'optional',),
+        'from-dbm'     : ('domains', 'optional',),
+        'to-dbm'       : ('domains', 'optional',),
         'from-ezmlm'   : ('optional',),
         'to-ezmlm'     : ('optional',),
         'from-mailman' : ('attr', 'optional' ),
@@ -785,6 +786,20 @@
         return (dbname, search_func)
 
 
+    def __add_domains(self, keys):
+        """
+        Attempt to extract the domain names from each address in keys.
+        Add these to keys and return the combined list.
+        """
+        domains = []
+        for k in keys:
+            try:
+                domains.append(k.split('@', 1)[1])
+            except IndexError:
+                pass
+        return keys + domains
+     
+
     def firstmatch(self, recipient, senders=None,
                    msg_body=None, msg_headers=None, msg_size=None):
         """Iterate over each rule in the list looking for a match.  As
@@ -800,7 +815,6 @@
                 keys = senders
             elif source.startswith('to') and recipient:
                 keys = [recipient]
-            #
             # Here starts the matching against the various rules
             #
             # regular 'from' or 'to' addresses
@@ -812,6 +826,8 @@
             if source in ('from-file', 'to-file'):
                 dbname = os.path.expanduser(match)
                 search_func = self.__search_file
+                if args.has_key('domains'):
+                    keys = self.__add_domains(keys)
                 # If we have an 'auto*' argument, ensure that the database
                 # is up-to-date.  If the 'optional' argument is also given,
                 # don't die if the file doesn't exist.
@@ -839,6 +855,8 @@
             if source in ('from-dbm', 'to-dbm'):
                 import anydbm
                 match = os.path.expanduser(match)
+                if args.has_key('domains'):
+                    keys = self.__add_domains(keys)
                 try:
                     found_match = self.__search_dbm(match, keys,
                                                     actions, source)
@@ -851,6 +869,8 @@
             if source in ('from-cdb', 'to-cdb'):
                 import cdb
                 match = os.path.expanduser(match)
+                if args.has_key('domains'):
+                    keys = self.__add_domains(keys)
                 try:
                     found_match = self.__search_cdb(match, keys,
                                                     actions, source)

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

Reply via email to