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

Click here to return to the 'Delete large numbers of duplicate emails from' 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
Authored by: mal0rd on Jan 29, '10 02:50:12AM
I also have such a large number of messages, mostly from work and mailing lists. At the end of the year I went to archive them and found that the "Mail Scripts" version was too slow.

Download my script or copy/paste this into Applescript Editor:

 Select Dups
 Devin Bayer ( - 2010
 To use:
 1. Select messages in
 2. Uncheck "Organize by Thread"
 3. Run this script
 4. Only duplicate message will be selected
 ---- Performance ----
 On my MacBook Pro 2.3Ghz, I can scan
 about 5000 messsages a minute.
 Only run this script using AppleScript Editor.
 When run standalone or in, the speed
 (and CPU usage) is drastically reduced
 ---- Notes ----
 If you want to use mail while this script is running,
 please create a second message viewer window to work in.
using terms from application "Mail"
	-- track the duplicate messages
	set dups to a reference to {}
	global dups
	set view to first message viewer of application "Mail"
	global view
	on progress(txt)
		display dialog txt 
			giving up after 1 with icon note
	end progress
	-- return a list of emails in msg
	to rcpt(msg)
		set emails to {}
		repeat with email in recipients in msg
			copy address of email to the end of emails
		end repeat
		return emails
	end rcpt
	-- compare two messages
	to compare(l, r)
		if r = none or l = none 
			or message size of l ≠ message size of r 
			or subject of l ≠ subject of r 
			or my rcpt(l) ≠ my rcpt(r) 
			then return false
		-- l and r are equal; mark one as a dup
		--set background color of r to red
		--set flagged status of r to true
		copy r to end of dups
	end compare
	-- set selected messages to dups 
	on finish()
		if (count of dups) < 1 then return true
			set selected messages of view to dups
		on error number -1712
			display alert "TIMEOUT"
			return false
		end try
		return true
	end finish
	my progress("retreiving list of selected messages")
	set sort column of view to size column
	set msgs to get selected messages of view
	set total to count of msgs
	-- initialize state
	set prev to none
	set pos to 0
	set failed to 0
	-- scan every message
	repeat with msg in msgs
			with timeout of 1 second
				compare(msg, prev)
			end timeout
		on error number -1712
			set failed to failed + 1
		end try
		set prev to msg
		-- progress dialog
		if pos mod 10000 = 0 then
			my progress("Processing message " & pos & " of " & total)
		end if
		set pos to pos + 1
	end repeat
	set ok to false
	repeat while not ok
		display dialog "Done scanning! total: " & total 
			& " timeouts: " & failed 
			& " dups: " & (count of dups) 
			" (click OK to select dups)" giving up after 60
		set ok to my finish()
	end repeat
	return true
end using terms from

[ Reply to This | # ]