-- ---------------------------------------------------------------------------------------- -- This script takes the folder that is selected (or all folders) in Outlook Express 5 or -- Microsoft Entourage on the Mac and exports the messages and subfolders to the Finder. -- Each message is exported as an individual Outlook Express message file. This script -- was adapted from Steve Friesen's (steve@skyweyr.com) Archive Messages script called -- "Export as Indiv. Msg Archive". It was slightly modified by Bill Wright -- (bwright_us@mac.com) to export Outlook Express messages to a fixed filename of -- 'msgNNNN.eml'. It was also extended to work with Microsoft Entourage. This script -- is used in part to export email messages from Outlook Express 5 or MS Entourage on the -- Mac to Outlook Express 5.5 on Windows. (3/2001) -- ---------------------------------------------------------------------------------------- set log_ref_num to -1 global log_ref_num set logging to false global logging try set exportfolders to button returned of (display dialog ("What do you want to Export?") buttons {"All Entourage Folders", "Selected Entourage Folders"} default button {"Selected Entourage Folders"}) if exportfolders is equal to "All Entourage Folders" then set handledFolder to true tell application "Microsoft Entourage" set FolderReftoExport to "Microsoft Entourage" set thefolder to "Microsoft Entourage" end tell else tell application "Microsoft Entourage" try set thefolder to selection set FolderReftoExport to thefolder if the class of thefolder = folder then set handledFolder to true --make sure the selection in Entourage is a folder else set handledFolder to false end if on error set handledFolder to false end try end tell end if if handledFolder = false then display dialog "You need to select a folder in Entourage to export!" with icon stop buttons {"OK"} default button {"OK"} else set logginganswer to button returned of (display dialog ("Do you wish to turn on Logging?") buttons {"Logging", "No Logging"} default button {"No Logging"}) if logginganswer is equal to "Logging" then set logging to true if logging then tell application "Finder" set OE_path to file of process "Microsoft Entourage" as string set OE_folder to (container of file OE_path) as string end tell set log_filename to "OEexporter" & shortDate() & ".log" set log_ref_num to create_and_clear_file(OE_folder & log_filename) save_data_to_file("Log Created on " & (date string of (current date)) & " at " & (time string of (current date)) & return) end if if thefolder is equal to "Microsoft Entourage" then set foldertoimportpath to "every Entourage folder" set foldertoexport to "Every Entourage Folder" else tell application "Microsoft Entourage" set foldertoexport to name of thefolder set check to false set parentpath to "" repeat while check is false if name of parent of thefolder is not equal to "Microsoft Entourage" then set parentpath to (name of parent of thefolder) & ":" & parentpath set thefolder to parent of thefolder else set check to true end if end repeat set foldertoimportpath to "\"" & parentpath & foldertoexport & "\"" end tell end if set theanswr to button returned of (display dialog ("Are you sure you want to export folder " & foldertoimportpath & " and subfolders?") default button {"OK"}) if logging then my save_data_to_file("Attempting to export Entourage folder \"" & foldertoimportpath & "\" and subfolders." & return) if theanswr is equal to "Ok" then set theDestination to (choose folder with prompt "Choose the folder where the Entourage folder will be exported to.") as string tell application "Microsoft Entourage" activate end tell --Export the folder to the Finder ExporttheFolder({FolderReftoExport}, theDestination) if logging then save_data_to_file(return & "All folders exported!" & return) close_the_file() end if activate display dialog ("\"" & foldertoexport & "\" has been exported to Finder folder \"" & theDestination & "\"") buttons {"OK"} default button {"OK"} giving up after 30 if logging then display dialog ("The export log can be found at \"" & OE_folder & "\"") buttons {"OK"} default button {"OK"} giving up after 30 end if end if on error error_msg number error_num try if log_ref_num is not equal to -1 then my close_the_file() end try if error_num is not equal to -128 then error (error_msg as string) & (error_num as string) end if end try --This routine creates a unique folder in the parent path that is given. on Createafolder(foldername, parentpath) tell application "Finder" set check to false set counter to 0 set foldername to foldername repeat while check is equal to false set counter to counter + 1 set foldername to my ConvertToFileName(foldername) if (folder (parentpath & (foldername & ":")) exists) or (file (parentpath & foldername) exists) then set foldername to foldername & " " & (counter as string) else set check to true end if end repeat if logging then my save_data_to_file(return & "Creating Finder Folder \"" & (parentpath & foldername) & "\"" & return) make new folder at folder (parentpath) with properties {name:(foldername)} end tell return (parentpath & (foldername) & ":") end Createafolder --ConvertToFileName by David Cortright -- theString: a string to be changed into a valid filename -- returns string that is a valid file name (no colons and less than 32 -- characters long) on ConvertToFileName(theString) repeat set colonOffset to offset of ":" in theString if colonOffset = 0 then exit repeat else if colonOffset = 1 then set theString to (text 2 thru -1 of theString) else if colonOffset = (length of theString) then set theString to (text 1 thru -2 of theString) else set theString to (text 1 thru (colonOffset - 1) of theString) & (text (colonOffset + 1) thru -1 of theString) end if end repeat set stringLength to (number of items in theString) if stringLength > 31 then set theString to (text 1 thru 28 of theString) return theString end ConvertToFileName --This routine creates children folder if there are any --and exports their children. It is recursive so it --takes care of additional children folders. on ExporttheFolder(listofchildren, maindestinationpath) if listofchildren is equal to {"Microsoft Entourage"} then tell application "Microsoft Entourage" set listofchildren to every folder end tell set maindestinationpath to my Createafolder("Every Entourage Folder", maindestinationpath) end if repeat with i in listofchildren set childtoexport to name of i set destinationfolder to my Createafolder(childtoexport, maindestinationpath) Exportthemail(i, destinationfolder) tell application "Microsoft Entourage" set childcheck to folders in i end tell if childcheck is not equal to {} then ExporttheFolder(childcheck, destinationfolder) end repeat end ExporttheFolder --This routine saves the messages of the OE Folder to the folder in the Finder on Exportthemail(thefolder, destinationfolder) if logging then tell application "Microsoft Entourage" set foldername to name of thefolder end tell my save_data_to_file("Exporting message from Entourage folder \"" & foldername & "\" to Finder folder \"" & (destinationfolder) & "\"" & return) end if tell application "Microsoft Entourage" set numofmsgs to number of messages in thefolder if numofmsgs > 0 then repeat with i from 1 to numofmsgs -- Generate the right justified numbering for the msg files. -- It assumes less than 9999 files per folder. if i < 10 then set sfx to "000" & i else if i < 100 then set sfx to "00" & i else if i < 1000 then set sfx to "0" & i else set sfx to i end if end if end if -- Output file name follows Windows 8.3 naming convention. set outfile to destinationfolder & "msg" & sfx & ".eml" -- Actually save the message to the output file. save message i of thefolder in outfile end repeat end if end tell end Exportthemail --This handler creates and clears a file and gets the file ready for writing. --The argument "file_path" is the path to the file to be created and cleared. --This handler returns an integer that can be used to reference the file in subsequent commands. on create_and_clear_file(file_path) set file_ref_num to (open for access file file_path with write permission) set eof file_ref_num to 0 return file_ref_num end create_and_clear_file --This handler writes information to a file. --The argument "file_ref_num" is a reference to the file to be written to. --The argument "the_data" is the information that will be written to the file. --This handler does not return anything. on save_data_to_file(the_data) write the_data to log_ref_num end save_data_to_file --This handler closes a file. --The argument "file_ref_num" is a reference to the file to be closed. --This handler does not return anything. on close_the_file() close access log_ref_num end close_the_file --This handler converts the current date and time into a short --form with characters legal to use in a filename. on shortDate() set today to current date set thisDate to day of today -- Get the "day" set theDay to thisDate + 0 -- Get the "month" set theMonth to month of today as string set theMonth to characters 1 through 3 of theMonth -- Get the "year" set thisYear to year of today set theYear to thisYear + 0 set theYear to characters 3 through 4 of (theYear as string) as string -- Get the "hour" set timeStr to time string of today set Pos to offset of ":" in timeStr set theHour to characters 1 thru (Pos - 1) of timeStr as string set timeStr to characters (Pos + 1) through end of timeStr as string -- Get the "minute" set Pos to offset of ":" in timeStr set theMin to characters 1 thru (Pos - 1) of timeStr as string set timeStr to characters (Pos + 1) through end of timeStr as string --Get "AM or PM" set Pos to offset of " " in timeStr set theSfx to characters (Pos + 1) through end of timeStr as string return (theDay & theMonth & theYear & " _" & theHour & "." & theMin & theSfx) as string end shortDate