(* clamAVscan-1.0.scpt modified 27/9/2005 Herman Lim - to run with fink installed clamav Applescript by Joseph E. Sacco, Ph.D., released under GPL, May 11, 2005 Not responsible for any loss of data or any inaccuracies in processing e-mails. This is FREEWARE, review and understand the source, use at your own risk!!! Filter MacOSX email through Clam AntiVirus scanner Infected mail: - subject is prefixed with "***INFECTED***" - is tagged as "Junk" - is moved to mailbox "Junk" Assumptions: - clamav has been installed via fink 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 Note: This script filters email using the command line utility, clamscan, which does not communicate with the ClamAV daemon. The tradeoff is speed verus complexity. For faster scans: - configure and run the clamAV daemon - edit this script, replacing "clamscan" with "clamdscan" in the "do shell script" command *) 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 & "| /sw/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