(*
Copyright (c) 2006, Grayson Hansard

All rights reserved.

This software is provided “as is” without any expressed or implied warranties. Neither the original author nor any contributors are liable for any damage caused by the use of this program.

You are free to use, distribute, and create derivative works for commercial and noncommercial use.

Derivative works of this software must be made publicly available.
*)

using terms from application "Mail"
	perform mail action with messages theMessages for rule theRule
	set spamFound to 0
	repeat with eachMessage in theMessages
		try
			if source of eachMessage contains "html" then
				set allAttachments to mail attachments of eachMessage
				if (count of allAttachments) ≥ 1 then
					set test to first item of allAttachments
					if MIME type of test contains "image/" then
						set junk mail status of eachMessage to true
					end if
				end if
			end if
		end try
	end repeat
	if spamFound > 0 and appIsRunning("GrowlHelperApp") then
		tell application "GrowlHelperApp"
			set appName to "Can Image Spam script"
			set notificationName to "Spam Found"
			set notificationList to {notificationName}
			register as application appName all notifications notificationList default notifications notificationList icon of application "Mail"
			notify with name notificationName application name appName title "Image spam canned" description (spamFound & " messages suspected of spam.")
		end tell
	end if
end using terms from

on appIsRunning(appName)
	tell application "System Events"
		return (name of every process) contains appName
	end tell
end appIsRunning