Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!


Click here to return to the 'Automatically file email in Mail based on sender's domain' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Automatically file email in Mail based on sender's domain
Authored by: kaih on Wed, Jan 30 2008 at 1:06PM PST
There was a problem with the script as originally posted - as it is in the hint, then it works when invoked from the Script Editor, where I was doing my testing, however I was a little too hasty in posting it.

Here's an amended version that works when it's invoked as a rule in Mail.

using terms from application "Mail"
	on perform mail action with messages newMessages
		tell application "Mail"
			repeat with theMessage in newMessages
				-- first we find the sender of the message
				set theSender to sender of theMessage as string
				-- now we strip off the sender's domain (everything after the "@")
				set oldDelimiters to AppleScript's text item delimiters
				set AppleScript's text item delimiters to {"@"}
				try
					set theDomain to the second text item of theSender
					-- always set the text item delimiters back as soon as possible!
					set AppleScript's text item delimiters to ""
					-- and strip the last character off the domain, as it will be a ">"
					set theDomain to get characters 1 through ((theDomain's length) - 1) of theDomain
				on error
					set theDomain to "Undetermined"
					set AppleScript's text item delimiters to ""
				end try
				set targetMailbox to "Sorted/" & theDomain
				try
					move theMessage to mailbox targetMailbox of account "Emperor's Mind" of application "Mail"
				on error
					-- do nothing
				end try
			end repeat
		end tell
	end perform mail action with messages
end using terms from

This works well for me, as I also have one Smart Mailbox called Action Items that gathers all unread and all flagged emails - then all I need to do is monitor this one Smart Mailbox to see what emails need to have something done about them. Once I've read an email, if it needs a follow-up, I flag it. If not, it turns unread, and is automatically filed in the appropriate mailbox for future reference.

---
k:.

[ Reply to This | # ]