On Sun, 2008-12-21 at 13:25 -0800, Gordon Messmer wrote:
> Lindsay Haisley wrote:
> > It looks as if Gordon Messmer has written a very nice Python-based API
> > for courierfilter and I'm going to give it a shot at the job.  I'm going
> > to have to write a new module for it, but the documentation on it is
> > excellent and it shouldn't be too hard.  I'm quite fond of Python as a
> > programming language :-)
> 
> Glad to hear it.  Let me know if I can offer any advice.  There are 
> modules for clamav and spamassassin which you can use as a base for 
> local customizations.

Gordon, here's a suggested patch for the spamassassin.py filter for
pythonfilter.  This is perhaps just a demonstration of concept since you
would probably want to streamline the code.

Essentially, running SpamAssassin with configs in mysql (as opposed to
flat config files) adds a lot of flexibility to it and makes it more
attractive for use in the delivery phase.  To this end, it's slower, but
more flexible, to run SpamAssassin twice, once from the courierfilter
facility to put a ceiling on the SA spam score accepted by Courier and
yet again during delivery to add SA headers and to encapsulate spam
inside of SA wrappers.

This patch implements a checkOnly flag for the module which,when set,
causes it to do nothing to the message, but to provide input gating
based on a comparison of rejectScore with the SA-determined spam score.
If checkOnly == False (the default) spamassassin.py works just as it
does without the patch.

--- courier-pythonfilter-1.4/filters/spamassassin.py    2008-05-26 
22:04:39.000000000 -0500
+++ courier-pythonfilter-1.4.hold/filters/spamassassin.py       2008-12-21 
16:41:10.000000000 -0600
@@ -37,12 +37,17 @@
 # header will be used to determine whether or not to reject the message.
 # Otherwise, messages will be rejected if they are spam.
 rejectScore = None
-
+# Set checkOnly True to only determine whether or not the message
+# should be rejected.  Do not modify the message.
+checkOnly = False
 
 def initFilter():
     courier.config.applyModuleConfig('spamassassin.py', globals())
     # Record in the system log that this filter was initialized.
-    sys.stderr.write('Initialized the "spamassasinfilter" python filter\n')
+    if checkOnly:
+        sys.stderr.write('Initialized the "spamassasinfilter" python filter 
(check only mode)\n')
+    else:
+        sys.stderr.write('Initialized the "spamassasinfilter" python filter\n')
 
 
 def checkRejectCondition(status, resultHeader):
@@ -88,17 +93,21 @@
     if rejectMsg is not None:
         return rejectMsg
 
-    # If the message wasn't rejected, then replace the message with
-    # the output of spamc.
-    try:
-        mfilter = courier.xfilter.XFilter('spamassassin', bodyFile,
-                                          controlFileList)
-    except courier.xfilter.LoopError, e:
-        # LoopError indicates that we've already filtered this message.
+    if checkOnly:
+        # Don't modify the message
         return ''
-    mfilter.setMessage(result)
-    submitVal = mfilter.submit()
-    return submitVal
+    else:
+        # If the message wasn't rejected, then replace the message with
+        # the output of spamc.
+        try:
+            mfilter = courier.xfilter.XFilter('spamassassin', bodyFile,
+                                              controlFileList)
+        except courier.xfilter.LoopError, e:
+            # LoopError indicates that we've already filtered this message.
+            return ''
+        mfilter.setMessage(result)
+        submitVal = mfilter.submit()
+        return submitVal
 
 
 if __name__ == '__main__':

-- 
Lindsay Haisley       |  "The voice of dissent  |     PGP public key
FMP Computer Services | was arrested before the |      available at
512-259-1190          |  president cleared his  | http://pubkeys.fmp.com
http://www.fmp.com    |     throat to speak     |
                      |        of freedom"      |
                      |     (Chris Chandler)    |


------------------------------------------------------------------------------
_______________________________________________
courier-users mailing list
[email protected]
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users

Reply via email to