If you have access to Outlook on Windows, you could import your mbox files there, and take the resulting .pst and import it in your Mac Outlook. Bit of a detour, but relatively easy and painless.
chmod +x [path to SetFile]
ln -s [path to SetFile] /usr/bin/SetFile
SetFile -t 'TEXT' mbox
sh mboxconv.sh "/Users/admin/mail export"
#!/bin/bash
find "$1" -name mbox -print0 | while read -d $'\0' file
do
# Get the name of the enclosing dir for any mbox file
# strip it of '.mbox' to arrive at the desired new name
# for the old mbox file. This helps because the name of
# the imported mbox becomes the label of the imported
# mails' folder in Outlook. Don't want 'mbox1' 'mbox2'...
encld=$(echo "$file" | awk -F '.mbox' '{print $1}')
mbname=$(echo "$encld" | awk -F '/' '{print $NF}')
# F#@KING mv command will not respect quotes in bash
# shells, and consistently misinterprets spaces
# so I'm constructing a raw file with commands and
# executing that.
tmp="${encld}.mbox/${mbname}"
newname="${tmp// /\ }"
mbpath="${file// /\ }"
echo "mv $mbpath $newname" >> /tmp/mboxlist
echo "SetFile -t 'TEXT' $newname" >> /tmp/mboxlist
done
sh /tmp/mboxlist
rm /tmp/mboxlist
global ArchiveFolderID
global TrimPath
on open files_
-- Make a new import destination with an unused name
set ArchiveFolderID to my setArchiveFolder()
-- Get the root folder of the export from Mail.app
set ExportPath to POSIX path of files_
-- Run script 'mboxconv.sh' which is in the script's Resources folder, converts the mboxes to
-- an Outlook readable format and returns a path to the files that it writes so we can use them
-- to direct the import.
set path_to_me to the POSIX path of (path to me)
set TmpRoot to do shell script "sh " & path_to_me & "Contents/Resources/mboxconv.sh " & "\"" & ExportPath & "\""
-- /tmp/whatever/hierarchyPath contains a hierarchically sorted list of the path to each Mail.app exported mbox file
set HierarchyPath to TmpRoot & "/hierarchyPath"
-- /tmp/whatever/TrimPath contains the overhead of the path to the export so we can trim the excess and use
-- it in Outlook to sort the imports and put them in the proper order
set TrimPath to (do shell script "cat " & TmpRoot & "/trimPath")
set NewTarget to paragraphs of (read HierarchyPath)
repeat with ImportPath in NewTarget
if length of ImportPath is greater than 0 then
set ImportedFolderID to my importMbox(ImportPath)
my placeInHierarchy(ImportPath, ImportedFolderID)
end if
end repeat
display dialog "Import finished"
end open
-- Chose an unused name and create a folder to host the archive import
on setArchiveFolder()
set ArchiveFolderName to ""
tell application "Finder"
display dialog ¬
"Enter a unique name for a new Archive folder under \"On My Computer\":" default answer ArchiveFolderName
set ArchiveFolderName to text returned of the result
repeat until my canIUseThis(ArchiveFolderName)
display dialog ¬
"Name already in use. Please try again. Enter a unique name for a new Archive folder under \"On My Computer\":" default answer ArchiveFolderName
set ArchiveFolderName to text returned of the result
end repeat
end tell
tell application "Microsoft Outlook"
make new mail folder in folder "On My Computer" with properties {name:ArchiveFolderName}
set ArchiveID to id of folder ArchiveFolderName in folder "On My Computer"
end tell
return ArchiveID
end setArchiveFolder
-- Microsoft has Applescript support for importing eml, ics, olm, pst, rge, and vcf but for some unimaginable
-- reason, nothing for importing mbox files... even though there is a mechanism for importing such files.
-- So we have to do this the ugly way - GUI scripting.
on importMbox(ImportPath)
set MboxFileName to do shell script "echo \"" & ImportPath & "\" | awk -F'/' '{print $NF}'"
set ImportedName to my getImportedName(MboxFileName)
tell application "Microsoft Outlook"
activate
tell application "System Events"
tell process "Microsoft Outlook"
click menu item "Import..." of menu 1 of menu bar item "File" of menu bar 1
delay 1
click radio button "Contacts or messages from a text file" of window "Import"
delay 1
click button 4 of window "Import"
delay 1
click radio button "Import messages from an MBOX-format text file" of window "Import"
delay 1
click button 4 of window "Import"
keystroke "g" using {shift down, command down}
keystroke ImportPath & ".mbox/" & MboxFileName
delay 1
keystroke return
keystroke return
-- test if import is finished before pressing return
my testImportCreated(ImportedName)
keystroke return
end tell
end tell
set ImportedFolderID to id of folder ImportedName of folder "On My Computer"
return ImportedFolderID
end tell
end importMbox
-- We've imported the mbox, now we have to move it in place and make sure it's named correctly
on placeInHierarchy(ImportPath, ImportedFolderID)
set OldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set OrigPath to every text item in (do shell script "echo " & quoted form of ImportPath & " | awk -F '" & TrimPath & "/' '{print $2}'")
set CurrentFolderID to ArchiveFolderID
repeat with MbName in OrigPath
tell application "Microsoft Outlook"
if exists folder named MbName in folder id CurrentFolderID then
set CurrentFolderID to (get id of folder named MbName in folder id CurrentFolderID)
else
move folder id ImportedFolderID to folder id CurrentFolderID
if name of folder id ImportedFolderID is not MbName then
set name of folder id ImportedFolderID to MbName
end if
end if
end tell
end repeat
set AppleScript's text item delimiters to OldDelims
end placeInHierarchy
-- Pick an unused name as a destination for importing mboxes
on getImportedName(MbName)
set Iteration to "1"
set TmpName to MbName
tell application "Microsoft Outlook"
repeat until my canIUseThis(TmpName) --evaluates true
set TmpName to MbName & " " & Iteration
set Iteration to (Iteration + 1)
end repeat
end tell
return TmpName
end getImportedName
-- Referenced a couple of times to make sure a name isn't already being used
on canIUseThis(MboxFileName)
tell application "Microsoft Outlook"
if exists folder MboxFileName of folder "On My Computer" then
return false
end if
end tell
end canIUseThis
-- Referenced on GUI scripted mbox import to pause GUI script until import is complete
-- otherwise we "keystroke return" at the wrong time if the mbox is large
on testImportCreated(ImportedName)
tell application "Microsoft Outlook"
repeat until exists folder ImportedName of folder "On My Computer"
delay 3
end repeat
end tell
end testImportCreated
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TMPFILES="/tmp/mail$(date "+%d%H%M%S")"
mkdir $TMPFILES
find "$1" -name mbox -print0 | while read -d $'\0' file
do
# Get the name of the enclosing dir for any mbox file
# strip it of '.mbox' to arrive at the desired new name
# for the old mbox file. This helps because the name of
# the imported mbox becomes the label of the imported
# mails' folder in Outlook. Don't want 'mbox1' 'mbox2'...
file=`echo "$file" | sed 's://:/:'`
encld=$(echo "$file" | awk -F '.mbox' '{print $1}')
mbname=$(echo "$encld" | awk -F '/' '{print $NF}')
# F#@KING mv command will not respect quotes in bash
# shells, and consistently misinterprets spaces
# so I'm constructing a raw file with commands and
# executing that.
parMbox="${encld}.mbox/${mbname}"
newname="${parMbox// /\ }"
mbpath="${file// /\ }"
echo "mv $mbpath $newname" >> $TMPFILES/cmdDoc
echo "$DIR/SetFile -t 'TEXT' $newname" >> $TMPFILES/cmdDoc
done
sh $TMPFILES/cmdDoc # execute each line in 'cmdDoc' to do renames and filetype setting
# create a list of parent directories to the newly renamed mbox files
# so that we may eventually come up with a folder hierarchy
# then sort them so we can create hierarchy in Outlook in proper order
sed '/^mv/d' $TMPFILES/cmdDoc | awk -F"'TEXT' " '{print $2}' | while read line;
do
mboxPath=$(dirname "$line")
echo "$mboxPath" >> $TMPFILES/mboxPath
done
sort $TMPFILES/mboxPath | awk -F'.mbox' '{print $1}' >> $TMPFILES/hierarchyPath
# isolate the redundant, useless file path of the list,
# so the AppleScript can use a pure hierarchy to instruct
# Outlook to sort imported folders.
echo "$(dirname `awk '((!L) || (length(L)>length($0))) { L=$0 } END { print L }' $TMPFILES/hierarchyPath`)" >$TMPFILES/trimPath
#excess=$(dirname `awk '((!L) || (length(L)>length($0))) { L=$0 } END { print L }' $TMPFILES/hierarchyPath`)
#cat $TMPFILES/hierarchyPath | awk -F"$excess" '{print $2}' > $TMPFILES/hierarchy
echo "$TMPFILES"