-- Update Message Flags after TB Import -- © Andreas Amann 2006 -- This script updates Entourage's message status flags of the selected mailbox to reflect -- the information stored in Thunderbird's "X-Mozilla-Status" header -- Tested on MacOS X 10.4.6 with Entourage 2004 (11.2.3) tell application "Microsoft Entourage" set noSelection to false try if class of displayed feature of front window is folder then set theMailbox to displayed feature of front window repeat with i from 1 to count of messages of theMailbox set eachMsg to message i of theMailbox try set MozHeader to headers of eachMsg set AppleScript's text item delimiters to "X-Mozilla-Status: " set MozHeader to characters 1 thru 4 of text item 2 of MozHeader set AppleScript's text item delimiters to "" set MozHeader to "0x" & MozHeader as text if my bAnd(MozHeader, "0x0008") then delete eachMsg else if my bAnd(MozHeader, "0x0001") then set read status of eachMsg to read else set read status of eachMsg to untouched end if set replied to of eachMsg to my bAnd(MozHeader, "0x0002") set flagged of eachMsg to my bAnd(MozHeader, "0x0004") set forwarded of eachMsg to my bAnd(MozHeader, "0x1000") end if on error em log em end try end repeat else set noSelection to true end if on error set noSelection to true end try if noSelection then display dialog "Please select a message folder before running this script" buttons "OK" default button 1 end if end tell -- A small handler for a bitwise "AND" operation - returns true of "mask" is set in value, false otherwise -- Uses bash which according to -- -- as of 10.2 is the shell used for "do shell script" regardless of the default shell on bAnd(value, mask) return ((do shell script "echo $(((" & value & " & " & mask & ") == " & mask & "))") = "1") end bAnd