This is a discussion on [courier-users] Spamassassin and clamav modules within the Courier-Imap forums, part of the Mail Servers and Related category; This is a multi-part message in MIME format. --------------050501030400080606090100 Content-Type: text/plain; charset=ISO-8859-1; format=flowed ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
This is a multi-part message in MIME format.
--------------050501030400080606090100 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi :) I rewrote some parts of these two modules. Local socket or paths can be different... With these modules, the admin is able to set up correct paths to make these filters working. So, we have to modify pythonfilter-modules.conf. Here is how I modified it: [clamav.py] LocalSocket = '/tmp/clamd' [...] [spamassassin.py] spamc_path = '/usr/local/bin/spamc' LocalSocket is the name of the parameter in clamav.conf. Please find attached both modules. HTH. Jerome Blion. --------------050501030400080606090100 Content-Type: text/plain; name="clamav.py" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="clamav.py" #!/usr/bin/python # clamav -- Courier filter which scans messages with ClamAV # Copyright (C) 2004 Robert Penz <robert@penz.name> # Copyright (C) 2007 Gordon Messmer <gordon@dragonsdawn.net> # Copyright (C) 2008 Jerome Blion <jerome@hebergement-pro.org> # # 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 courier.config LocalSocket = '' try: import pyclamav def scanMessage(bodyFile): try: avresult = pyclamav.scanfile(bodyFile) except Exception, e: return "554 " + str(e) if avresult[0]: return "554 Virus found - Signature is %s" % avresult[1] return '' except ImportError: import pyclamd def scanMessage(bodyFile): try: pyclamd.init_unix_socket(LocalSocket) avresult = pyclamd.scan_file(bodyFile) except Exception, e: return "554 " + str(e) if avresult != None and avresult.has_key(bodyFile): return "554 Virus found - Signature is %s" % avresult[bodyFile] return '' def initFilter(): courier.config.applyModuleConfig('clamav.py', globals()) # Record in the system log that this filter was initialized. sys.stderr.write('Initialized the "clamav" python filter\n') def doFilter(bodyFile, controlFileList): return scanMessage(bodyFile) if __name__ == '__main__': # we only work with 1 parameter if len(sys.argv) != 2: print "Usage: clamav.py <message_body_file>" sys.exit(0) initFilter() print doFilter(sys.argv[1], "") --------------050501030400080606090100 Content-Type: text/plain; name="spamassassin.py" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="spamassassin.py" #!/usr/bin/python # spamassassin -- Courier filter which scans messages with spamassassin # Copyright (C) 2007-2008 Jerome Blion <jerome@hebergement-pro.org> # # 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 import courier.config spamc_path = '/usr/bin/spamc' 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') def doFilter(bodyFile, controlFileList): try: cmd = spamc_path + ' -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 '' if __name__ == '__main__': # For debugging, you can create a file that contains just one # line, beginning with an 's' character, followed by an email # address. Run this script with the name of that file as an # argument, and it'll validate that email address. if not sys.argv[1:]: print "Usage: spamassassin.py <message body file>" sys.exit(0) initFilter() print doFilter(sys.argv[1], "") --------------050501030400080606090100 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ --------------050501030400080606090100 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ courier-users mailing list courier-users@lists.sourceforge.net Unsubscribe: https://lists.sourceforge.net/lists/.../courier-users --------------050501030400080606090100-- |