Solved

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

Posted on 2009-05-06
5
511 Views
Last Modified: 2013-12-26
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
Comment
Question by:TIgerV
  • 2
5 Comments
 

Author Comment

by:TIgerV
ID: 24320264
Delete or Purge.  This is an IMAP mailbox.
0
 
LVL 5

Accepted Solution

by:
AGoodKeenMan earned 500 total points
ID: 24334441
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
 

Author Comment

by:TIgerV
ID: 24334656
Thank you.  
I will try this one this afternoon.

Tony
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

New-MailboxSearch Powershell Command and step by step approach to Search and Extract Emails form Exchange 2013 Journaling server.
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
The purpose of this video is to demonstrate how to use PicMonkey software to customize images for a Mailchimp campaign. Picmonkey is free and simple online software which can be used by users who don’t have robust editing software such as Photoshop,…
This Micro Tutorial demonstrates  how Internet marketers work with competitive analysis data, and a common task in data preparation is creating separate column for domains. You will then extract from a list of URLs.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now