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.
#!/usr/bin/python
# clamav -- Courier filter which scans messages with ClamAV
# Copyright (C) 2004 Robert Penz <[EMAIL PROTECTED]>
# Copyright (C) 2007 Gordon Messmer <[EMAIL PROTECTED]>
# Copyright (C) 2008 Jerome Blion <[EMAIL PROTECTED]>
#
# 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], "")
#!/usr/bin/python
# spamassassin -- Courier filter which scans messages with spamassassin
# Copyright (C) 2007-2008 Jerome Blion <[EMAIL PROTECTED]>
#
# 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], "")
-------------------------------------------------------------------------
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/
_______________________________________________
courier-users mailing list
[email protected]
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users