4 messages in net.sourceforge.lists.courier-users[courier-users] Integrating Spamassas...
FromSent OnAttachments
Jérôme BlionMay 13, 2007 7:38 pm 
Jérôme BlionMay 13, 2007 7:50 pm 
Gordon MessmerMay 14, 2007 9:34 am 
Jérôme BlionMay 14, 2007 10:00 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:[courier-users] Integrating Spamassassin in pythonfilterActions...
From:Jérôme Blion (jero@free.fr)
Date:May 13, 2007 7:38:39 pm
List:net.sourceforge.lists.courier-users

Hello,

I found no modules to integrate spamassassin into pythonfilter. I found no python "modules" that I could have imported. So, the way I use to scan mails are the less worst I found... using spamc...

For people who want to use it, be careful: mails are refused, not moved in a "junk" folder. So, take care about the score ;)

What do you think about this piece of code?

Now, pythonfilter is filtering spams and viruses... All that I need :)

HTH :)

#!/usr/bin/python # spamassassin -- Courier filter which scans messages with spamassassin # Copyright (C) 2004 Robert Penz <rob@penz.name> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

import sys import commands

# Record in the system log that this filter was initialized. sys.stderr.write('Initialized the "spamassasinfilter" python filter\n')

def doFilter(bodyFile, controlFileList): # check for viruses try: cmd = '/usr/bin/spamc -c < ' + bodyFile (status,output) = commands.getstatusoutput(cmd)

except Exception, e: return "554 " + str(e)

if status != 0: return '554 Mail rejected - spam detected: '+ output return '200 Spamassassin score: '+ output

if __name__ == '__main__': # we only work with 2 parameter if len(sys.argv) != 2: print "Usage: spamassassin.py <message_body_file> <controlFileList>" sys.exit(0) print doFilter(sys.argv[1], "")