Update of /cvsroot/tmda/tmda/TMDA
In directory sc8-pr-cvs1:/tmp/cvs-serv22042
Modified Files:
Defaults.py FilterParser.py
Log Message:
Added MySQL variables and filter sources.
Index: Defaults.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/Defaults.py,v
retrieving revision 1.170
retrieving revision 1.171
diff -u -r1.170 -r1.171
--- Defaults.py 4 Mar 2003 22:16:32 -0000 1.170
+++ Defaults.py 23 Mar 2003 23:24:34 -0000 1.171
@@ -1097,6 +1097,62 @@
if not vars().has_key('AUTORESPONSE_INCLUDE_SENDER_COPY'):
AUTORESPONSE_INCLUDE_SENDER_COPY = 2
+# MYSQL_ENABLED
+# All defaults beginning with "MYSQL_" configure the use of a MySQL
+# database in the filtering process. To use a MySQL database, you
+# must have the _mysql library loaded. See:
+# http://sourceforge.net/projects/mysql-python/
+#
+# MYSQL_ENABLED must be set to 1 if you wish to use a MySQL database
+# in your filters.
+#
+# Example:
+# MYSQL_ENABLED = 1
+#
+# Default is 0 (disabled)
+if not vars().has_key('MYSQL_ENABLED'):
+ MYSQL_ENABLED = 0
+
+# MYSQL_HOST
+# MySQL host to connect to.
+#
+# Example:
+# MYSQL_HOST = "db.my.server"
+#
+# Default is "localhost".
+if MYSQL_ENABLED and not vars().has_key('MYSQL_HOST'):
+ MYSQL_HOST = "localhost"
+
+# MYSQL_DATABASE
+# MySQL database containing any lists used in filter.
+#
+# Example:
+# MYSQL_DATABASE = "JimsTMDA"
+#
+# Default is "TMDA".
+if MYSQL_ENABLED and not vars().has_key('MYSQL_DATABASE'):
+ MYSQL_DATABASE = "TMDA"
+
+# MYSQL_USER
+# MySQL user to use when connecting to database.
+#
+# Example:
+# MYSQL_USER = "Jim"
+#
+# Default is "TMDA".
+if MYSQL_ENABLED and not vars().has_key('MYSQL_USER'):
+ MYSQL_USER = "TMDA"
+
+# MYSQL_PASSWORD
+# MySQL password to use when connecting to database.
+#
+# Example:
+# MYSQL_USER = "[EMAIL PROTECTED]"
+#
+# Default is "".
+if MYSQL_ENABLED and not vars().has_key('MYSQL_PASSWORD'):
+ MYSQL_PASSWORD = ""
+
# PENDING_CACHE
# Path to the cache file used when tmda-pending is invoked with the
# --cache option.
Index: FilterParser.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/FilterParser.py,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- FilterParser.py 12 Mar 2003 20:56:52 -0000 1.51
+++ FilterParser.py 23 Mar 2003 23:24:34 -0000 1.52
@@ -221,7 +221,7 @@
bol_comment = re.compile(r'\s*#')
most_sources = re.compile(r"""
- ( (?:to|from)-(?:file|cdb|dbm|ezmlm|mailman)
+ ( (?:to|from)-(?:file|cdb|dbm|ezmlm|mailman|mysql)
| size | pipe
| (?:to|from) (?!-) )
""", re.VERBOSE | re.IGNORECASE)
@@ -272,6 +272,8 @@
'to-ezmlm' : ('optional',),
'from-mailman' : ('attr', 'optional' ),
'to-mailman' : ('attr', 'optional' ),
+ 'from-mysql' : ('like', 'rlike'),
+ 'to-mysql' : ('like', 'rlike'),
'body' : ('case',),
'headers' : ('case',),
'body-file' : ('case', 'optional'),
@@ -280,6 +282,9 @@
'pipe' : None
}
+ # MySQL connection
+ MySQL = None
+
def __init__(self):
self.macros = []
@@ -709,6 +714,44 @@
return found_match
+ def __search_mysql(self, Table, Args, Keys, Actions, Source):
+ "Search MySQL table."
+ if not self.MySQL:
+ # Connect to the database if we have not yet connected
+ import Defaults, _mysql
+ self.MySQL = _mysql.connect \
+ (
+ host = Defaults.MYSQL_HOST,
+ db = Defaults.MYSQL_DATABASE,
+ user = Defaults.MYSQL_USER,
+ passwd = Defaults.MYSQL_PASSWORD
+ )
+ # Searches can be for records that are "=", "like", or "rlike" the
+ # keys. "=" is the fastest and the default, but it does not allow any
+ # wildcarding. "like" allows "_" to mean any character and "%" to
+ # mean any string. "rlike" allows regular expressions.
+ Compare = "="
+ if Args.has_key('like'): Compare = "LIKE"
+ elif Args.has_key('rlike'): Compare = "RLIKE"
+ Test = ""
+ for Key in Keys:
+ if Test: Test += "OR "
+ Test += "('%s' %s ADDRESS) " % (Key, Compare)
+ # Perform the query
+ self.MySQL.query("SELECT * FROM %s WHERE %s LIMIT 1" % (Table, Test))
+ # Fetch the result
+ Result = self.MySQL.store_result().fetch_row(0, 1)
+ found_match = len(Result)
+
+ # If there is an entry for this key, we consider it an overriding
+ # action specification.
+ if found_match and Result[0]["ACTION"]:
+ Actions.clear()
+ Actions.update(self.__buildactions(Result[0]["ACTION"], Source))
+
+ return found_match
+
+
def __search_cdb(self, pathname, keys, actions, source):
"""
Search DJB's constant databases; see <http:/cr.yp.to/cdb.html>.
@@ -938,6 +981,14 @@
if addy and addy.lower() in mmdb_addylist:
found_match = 1
break
+ if found_match:
+ break
+ # MySQL-style databases.
+ if source in ('from-mysql', 'to-mysql'):
+ found_match = self.__search_mysql \
+ (
+ match, args, keys, actions, source
+ )
if found_match:
break
# A match is found if the command exits with a zero exit
_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs