Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 525
  • Last Modified:

Apple Script to delete mail based on a pattern found in the mail.

I can tell Apple Scripting is what i need to help process the mail that I need.  (Hundreds a day)

Can someone help me produce a script that looks for a pattern and if found, deletes the message?

The pattern is:
".



    Army " 

Yes, the hard returns and all.

A normal (keeper) message may contain the word Army, but if there is a period, then the hard coded returns, then the word Army, I want to delete the message.

Best way to do that is.......

Thanks!
0
TIgerV
Asked:
TIgerV
  • 2
1 Solution
 
TIgerVAuthor Commented:
Delete or Purge.  This is an IMAP mailbox.
0
 
AGoodKeenManCommented:
Ok, try this. Save the script into ~/Library/Scripts/Applications/Mail/. You will need to setup a rule that runs the script on all messages, preferably one that presorts the messages for the word "Army" and a period. Also I have found that the script would not work when I had Safari 4 beta installed.
-- 08/05/09 Script to sort incoming messages for the string ".\n\n\n\nArmy"
 
using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		tell application "Mail"
			set searchString to ".
 
 
 
Army"
			repeat with theMessage in theMessages
				set theAccount to the account of the mailbox of theMessage
				if content of theMessage contains searchString then
					set mailbox of theMessage to mailbox "Trash" of theAccount
					set read status of theMessage to yes
				end if
			end repeat
		end tell
	end perform mail action with messages
end using terms from

Open in new window

0
 
TIgerVAuthor Commented:
Thank you.  
I will try this one this afternoon.

Tony
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now