Jump to content
InsanelyMac Forum

Entourage: Delete mail with excessive non Alpha subjects

Recommended Posts

I wrote a script to fill a need I couldn't find anywhere else. Deleting emails who have a certain percentage of non Alpha characters in the subject line, so they can skate by keyword filters. So emails like "A+D;U)L`T+ V_I &D#E 0)S" in the subject would be deleted. It's written for Entourage, but the logic could be easily used for other email apps.


on run
tell application "Microsoft Entourage"

	-- delete messages that have <threshhold> percentage of characters
	-- outside the range of A..Z and a..z (and space) in the subject line.
	-- This is to zap emails that substitute special character for letters, to get
	-- past spam filters that drive off key words.  Threshhold can be
	-- adjusted as you see fit.  I arbitrarily chose .15.  Also, the characters
	-- included or excluded in either category can be easily changed.
	-- NOTE:  This permanently deletes, so if you don't want that, just
	-- remove the 2nd delete below.

	set CurrMessages to the current messages
	set alphaChar to 0 as integer -- number of Alpha characters and Space
	set otherChar to 0 as integer -- number of non Alpha characters
	set otherRatio to 0.0 as real -- otherChar / alphaChar
	set threshhold to 0.15 as real -- adjust this to whatever works

	repeat with theMsg in the CurrMessages
		set subj to the subject of theMsg

		repeat with thisCharacter in the characters of subj
			set thisCharacter to thisCharacter as text
			if (thisCharacter ≥ "A" and thisCharacter ≤ "Z") or (thisCharacter ≥ "a" and thisCharacter ≤ "z") or (thisCharacter = " ") then
				set alphaChar to alphaChar + 1
				set otherChar to otherChar + 1
			end if
		end repeat

		set otherRatio to otherChar / alphaChar
	end repeat

	if otherRatio > threshhold then
		delete theMsg -- put in Deleted Folder
		delete theMsg -- delete permanently
	end if
end tell
end run

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.