#!/usr/bin/python

import email
import sys
import os
import string

scannerbin = "/usr/local/bin/clamscan --mbox -"
msg = email.message_from_file(sys.stdin)
childin, childout, childerr= os.popen3(scannerbin,"w")
childin.write(msg.as_string())
childin.close();
childout.readlines()
output = childerr.readlines()
Virus = None
for line in output:
	if line.find("FOUND") != -1 :
		Virus = line[line.find(":")+2:line.find("FOUND")-1]
		msg.add_header("X-Virus","yes",type=Virus)
		sys.stderr.write("VIRUS " + Virus);
	elif line.find("OK")!=-1:
		pass #no special action if we do not find a Virus

if not Virus :		
	msg.add_header("X-Virus","no")

print msg.as_string()
