Script Not Working (Note: You Need Clamscan To Test)

The problems are…

Script should be prefixing subject wit INFECTED which is not
also script should be allowing Mail to delete message off server. It
is leaving the message on server resulting in downloading the same
file while getting new mail.

I might be wrong with needing clamscan to test, I’m sure
you can modify it to work without clamscan.

(* 
Infected mail:
- subject is prefixed with "***INFECTED***"
- is tagged as "Junk"
- is moved to mailbox "Junk"

Setup:
- place clamAVscan.scpt in a known location, e.g. ~/Library/Scripts/
- create Rule
Mail -> Preferences->Rules -> Add Rule
Description: virus-scan
If any of the following conditions are met:
Every Message
Perform the following actions:
Run AppleScript: ~/Library/Scripts/clamAVscan.scpt

Test Virus
http://www.eicar.org/download/eicar.com

*)

using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		tell application "Mail"
			repeat with thisMessage in theMessages
				set msgSource to source of thisMessage
				try
					do shell script "echo " & quoted form of msgSource & "| /usr/local/clamXav/bin/clamscan --quiet --stdout -"
				on error errMsg number exitCode
					if (exitCode = 1) then
						set currentSubject to subject of thisMessage
						set subject of thisMessage to "***INFECTED*** " & currentSubject
						set junk mail status of thisMessage to true
						set accountName to name of account of mailbox of thisMessage
						set mailbox of thisMessage to mailbox "Junk" of account accountName
					else
						display dialog "Something unexpected has happened to clamAV scan: Exit Code = " & exitCode
						display dialog "Error Message:" & errMsg
					end if
				end try
			end repeat
		end tell
	end perform mail action with messages
end using terms from

Ok I solved the problem of messages not being removed from remote server by removing code

set currentSubject to subject of thisMessage
						set subject of thisMessage to "***INFECTED*** " & currentSubject
						set junk mail status of thisMessage to true
						set accountName to name of account of mailbox of thisMessage
						set mailbox of thisMessage to mailbox "Junk" of account accountName

and replacing it with

move thisMessage to mailbox "INFECTED"

So now instead of knowing each file is infected by seeing INFECTED in subject line, I just look at mailbox INFECTED to know:)

I still don’t understand why first script didn’t set subject to INFECTED.

Hi virustrapp,

it’s not possible to change the subject of a received mail