Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2009-05-06
5
519 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Granting full access permission allows users to access mailboxes present in their database. By giving full access permission one can open and read the content of any mailbox but cannot send emails from that mailbox.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
This Micro Tutorial will demonstrate the easy use of Gmail embedding images in your email so the recipient of your email can view them in context.

790 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