Hey, everyone!
Can anyone suggest how I could speed up / improve this script?
–
I needed to solve a problem for a client.
They use the colored flags on Mail.app extensively for their business workflow. Different colors mean different things.
However, Mail.app colored flags aren’t visible in any environment other than a Mac. If anyone wants to use a PC or look at their emails in Webmail, the workflow is totally broken.
So I wrote a script that takes all flagged items and sorts them into corresponding folders on the server (Red, Green, Blue, etc). It then looks at those same folders, and removes anything that’s no longer flagged).
With this, the Mail.app colored flags are always synced up with a corresponding folder on the server.
However, they have a ton of emails, often with large attachments.
When the script runs, it can often slow down Mail.app, which I would like to avoid.
Any suggestions?
-- These are the account and folder names we need
set _account to "Jimthehandyman"
set _mailboxlistUNSET to {"INBOX/Red", "INBOX/Orange", "INBOX/Yellow", "INBOX/Green", "INBOX/Blue", "INBOX/Purple", "INBOX/Gray"}
set _mailboxlist to {"INBOX", "Sent Items"}
-- These are the color and index pairs so we can just iterate thru all of these with the same function
set _FlagRecord to {{index:"0", color:"Red"}, {index:"1", color:"Orange"}, {index:"2", color:"Yellow"}, {index:"3", color:"Green"}, {index:"4", color:"Blue"}, {index:"5", color:"Purple"}, {index:"6", color:"Gray"}}
-- Search thru each flag-folder, find any message without a flag, and move it into the inbox.
tell application "Mail"
repeat with _m in _mailboxlistUNSET
set allMessage to (every message of mailbox _m of account _account whose flag index is -1)
repeat with MyMessage in allMessage
move MyMessage to mailbox "INBOX" of account _account
end repeat
end repeat
end tell
-- Search through each color/flag pair and move flagged items into the flag-folder
tell application "Mail"
repeat with i in _FlagRecord
repeat with box in _mailboxlist
-- here for testing
-- display dialog (index of i) & (color of i)
-- set _mailbox to box
-- display dialog box
set allMessage to (every message of mailbox _mailbox of account _account whose flag index is index of i)
try
repeat with MyMessage in allMessage
move MyMessage to (first mailbox whose name is color of i) of account _account
end repeat
end try
end repeat
end repeat
end tell