Thank you for the help with this issue. Filtering is running smoothly.
Attached is the Jérôme version of clamav.py, with the mail warning I
added. Maybe can be of some use to somebody there. In case you have
suggestions or improvements I'll be very thankfull if you let me know.
Enrique.
Gordon Messmer escribió:
Enrique Verdes wrote:
---snip---
def mail(to='', who=''):
sender='[EMAIL PROTECTED]'
message = email.Message.Message()
message["To"] = to
message["From"] = sender
message["Date"] = email.Utils.formatdate(localtime=1)
message["Subject"] = 'Aviso de e-mail con virus'
text=who + "Le envio un mail que fue rechazado por el antivirus en
el servidor"
I'd use string formatting instead of concatenation:
text = "You received a message from '%s', which contained a virus." % who
message.set_payload(text)
mailServer = smtplib.SMTP('localhost:25')
mailServer.sendmail(sender, to, message.as_string())
mailServer.quit()
def doFilter(bodyFile, controlFileList):
# check for viruses
try:
pyclamd.init_unix_socket('/var/run/clamav/clamd.socket')
avresult = pyclamd.contscan_file(bodyFile)
except Exception, e:
return "554 " + str(e)
if avresult == None:
return ''
if avresult.has_key(bodyFile):
mail(courier.control.getRecipients(controlFileList),
courier.control.getSender(controlFileList))
return "554 %s was detected. Abort!" % avresult[bodyFile]
Right there, you want:
if avresult.has_key(bodyFile):
sender = courier.control.getSender(controlFileList)
for recipient in courier.control.getRecipients(controlFileList):
mail(recipient, sender)
return "554 %s was detected. Abort!" % avresult[bodyFile]
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
courier-users mailing list
[email protected]
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users
--
*/------------------------------------------------------------------------------------------------------------------
Enrique Verdes/**
UyGroup*/ /Consulting & Technology
*/_
www.uygroup.com.uy <http://www.uygroup.com.uy>_/*/
Av. Gral. Paz 1481 - CP 11400
Montevideo - Uruguay
Phone/Fax: (+598-2) 600-6200 - ext. 223
*/------------------------------------------------------------------------------------------------------------------/*
AVISO DE CONFIDENCIALIDAD:
LA INFORMACIÓN CONTENIDA EN ESTE CORREO ELECTRÓNICO ES PRIVILEGIADA Y
CONFIDENCIAL Y FUE ENVIADO PARA EL USO EXCLUSIVO DEL DESTINATARIO
DESIGNADO EN EL MISMO.
Si usted no es el destinatario, se prohibe estrictamente la
reproducción, distribución, y cualquier otra forma de difusión o uso de
esta comunicación.
Si usted ha recibido este correo electrónico por error, por favor
contéctese con nosotros inmediatamente al teléfono: (+598-2) 600-62-00 o
por el correo electrónico: [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
*/------------------------------------------------------------------------------------------------------------------/*
CONFIDENTIALITY NOTICE:
THE INFORMATION CONTAINED IN THIS E-MAIL IS PRIVILEGED AND CONFIDENTIAL
AND IS INTENDED FOR THE EXCLUSIVE USE OF THE ADDRESSEE DESIGNATED ABOVE.
If you are not the addressee, any disclosure, reproduction distribution,
or other dissemination or use of this communication is strictly prohibited.
If you have received this electronic mail by error please contact us
immediately by telephone: (+598-2) 600-62-00 or by e-mail:
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
*/------------------------------------------------------------------------------------------------------------------/*
/
#!/usr/bin/python
# clamav -- Courier filter which scans messages with ClamAV
# Copyright (C) 2007 Jerome Blion <[EMAIL PROTECTED]>
# Modifications made by Enrique Verdes <[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 pyclamd
import smtplib
import courier.control
import email.Message
import email.Utils
# Record in the system log that this filter was initialized.
sys.stderr.write('Initialized the "clamdfilter" python filter\n')
#EMV - Report mail recipient about infested mail
#Change the sender variable according to your configuration
def mail(to='', who=''):
sender='[EMAIL PROTECTED]'
message = email.Message.Message()
message["To"] = to
message["From"] = sender
message["Date"] = email.Utils.formatdate(localtime=1)
message["Subject"] = 'Aviso de e-mail con virus'
text= "You received a message from '%s', which contained a virus." %who
message.set_payload(text)
mailServer = smtplib.SMTP('localhost:25')
mailServer.sendmail(sender, to, message.as_string())
mailServer.quit()
def doFilter(bodyFile, controlFileList):
# check for viruses
try:
pyclamd.init_unix_socket('/var/run/clamav/clamd.socket')
avresult = pyclamd.contscan_file(bodyFile)
except Exception, e:
return "554 " + str(e)
if avresult == None:
return ''
#If mail has a virus we sent the alert to the recipients before rejecting it
if avresult.has_key(bodyFile):
for recipient in courier.control.getRecipients(controlFileList):
mail(recipient, courier.control.getSender(controlFileList))
return "554 %s was detected. Abort!" % avresult[bodyFile]
if __name__ == '__main__':
# we only work with 1 parameter
if len(sys.argv) != 2:
print "Usage: clamd.py <message_body_file>"
sys.exit(0)
print doFilter(sys.argv[1], "")
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
courier-users mailing list
[email protected]
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users