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


Click here to return to the 'A script to (somewhat) merge threads in Mail.app' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to (somewhat) merge threads in Mail.app
Authored by: macventure on Oct 22, '04 08:22:23PM

I was never fond of Thread Mode myself, primarily because of people who do not reply based on the tread. I always liked using the subject line to filter a thread - and it's easier on the eyes if you only see those messages in the thread. Here is a script that will work in any folder. Name the script the following name and Command-Shift-T can be used to view only those messages in the thread. It's a toggle based script so it will switch in and out of thread viewing mode.

Name: Filter Thread___cmd-shift-T

on realThread(theString)
	if characters 1 thru 4 of theString as string is equal to "Re: " then
		set theSubject to characters 5 through -1 of theString as string
	else
		theString
	end if
end realThread


tell application "Mail"
	tell message viewer 1 -- target the frontmost window
		set selectedMailboxes to selected mailboxes
		if (count of selectedMailboxes) = 1 then -- make sure only one mailbox is selected so you can get the subject line
			set selectedMailbox to item 1 of selectedMailboxes
			
			if (count of (visible messages)) < (count of (messages of selectedMailbox)) - 100 then
				set visible messages to {}
				return
			end if
		else
			display dialog ¬
				"This function only works within one mailbox!" & return & return & ¬
				"Please select just one mailbox" buttons {"OK"} default button "OK" with icon stop
			return
		end if
		-------------------------------------------
		set selectedMsgs to selected messages
		if (count of selectedMsgs) = 1 then -- make sure only one message is selected so you can get the subject line
			set keyMsg to item 1 of selectedMsgs
			set theSubject to my realThread(subject of item 1 of selectedMsgs)
		else
			display dialog "You must have a single message selected" buttons {"OK"} default button "OK" with icon note
			return
		end if
		-- Now capture all the messages with the same subject
		set mainMessage to every message of selectedMailbox whose subject is theSubject
		set theThread to every message of selectedMailbox whose subject is ("Re: " & theSubject)
		set theThread to mainMessage & theThread
		set visible messages to theThread
	end tell
end tell


[ Reply to This | # ]