Tue, 31 May 2005

pyblosxomのcomments.pyにspamassassinを通してみる。

単にspamassassinをpipeしてるだけ。ベイジアン使うとこれがまた重いのだ。

パッチ:

--- comments.py     2005-05-31 07:26:18.000000000 +0900
+++ comments.py     2005-05-31 07:28:26.000000000 +0900
@@ -525,6 +525,22 @@

         body = form['body'].value

+        try:
+            indata, outdata = os.popen2('/usr/bin/spamassassin')
+            indata.write(body)
+            indata.close()
+            result = outdata.read()
+            outdata.close()
+            if re.search('\nX-Spam-Status: (Yes|No)', result).group(1) == 'Yes':
+                tools.log("Comment spam discovered.")
+                o = open(os.path.join(config['comment_dir'], 'spam.log'), 'a')
+                o.write(body)
+                o.write('-=' * 35)
+                return
+        except Exception, e:
+            tools.log("Couldn't check comment: " + str(e))
+            return
+
         body = sanitize(body)

         # Check if the form has a URL

どうやら、paypalとかでやってるような、 画像でconfirmするような仕組み もあるらしい。