Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Delete large numbers of duplicate emails from Mail.app' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Delete large numbers of duplicate emails from Mail.app
Authored by: tedw on Jan 29, '10 07:31:48AM
It occurred to me that this would be best handled using a rule action. That way, messages could be tested as they arrived, automatically, as well as in bulk. the rule action script looks like this (untested):
using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		tell application "Mail"
			repeat with thisMessage in theMessages
				set theAccount to account of mailbox of thisMessage
				tell theAccount
					tell mailbox "INBOX"
						set theDupList to (every message whose 
							message size = message size of thisMessage 
							and subject = subject of thisMessage 
							and recipients = recipients of thisMessage)
						if (count of theDupList) > 1 and thisMessage ≠ last item of theDupList then
							set background color of thisMessage to purple
							-- delete thisMessage
						end if
					end tell
				end tell
			end repeat
		end tell
	end perform mail action with messages
end using terms from
because this is an untested version, I have it set to mark the emails in purple, and I've commented out the delete line (though ultimately you would want to uncomment that and delete emails automatically - test to make sure the script works as you want, first). This script will take the current email, check to see if there are any other emails that have the same message size, subject line, and to recipients in the INBOX of the same account, and mark/delete that email if there are duplicates (unless this email is the oldest email in the matching emails - oldest emails are preserved so that at least one copy of the email remains).

to use this, copy the script in the the applescript editor and save it as a script file. In Mail, set up a rule action that calls this script. the script will then run automatically on incoming emails, or you can run it on a given message or an entire mailbox using the Message -> Apply Rules menu item.

[ Reply to This | # ]