Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

throttlemeister

macrumors 6502a
Mar 31, 2009
550
63
Netherlands
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.
 

rickedmonds

macrumors newbie
Sep 2, 2012
2
0
Import apple mail into outlook 2011.

Are Apple that arrogant that they believe that people wouldn’t want to export from Apple Mail to another email program?
I set up a new IMAP account in Apple Mail to synch with my Gmail account, moved my emails into my inbox, they ‘uploaded’ go my Gmail account. I then set up the same account in Outlook and ‘downloaded’ the same emails with their original send dates intact.
 

signetmac

macrumors newbie
Oct 23, 2012
2
0
Solution

Hiya folks.

-----Edit-------
I just realized, in this script I use the utility 'SetFile' which is only available to you if you've installed Xcode
and the command line utilities. Now, you could download Xcode, if you have the time, or you could download SetFile from the 'transcoderredux' project at SourceForge, here:

SetFile

Likely, it will download without execute permissions set, and not in a location that the BASH script can find, but you can remedy that with the following:
Code:
chmod +x [path to SetFile]
ln -s [path to SetFile] /usr/bin/SetFile
However, you probably want to take the time to download Xcode anyhow, since downloading files at anyone's direction who you don't know and trust, and executing them can get you in trouble.

-----Edit-------

I'm still working out an Applescript to take care of nested archives for me automagically, but in the meantime, you might be pleased to know that you can import into Outlook any email that you have archived locally on your Mac Mail.app with the following instructions. To be clear, ~/Library/Mail/[whatever].mbox "files" associated with your Exchange account are folders containing a complex hierarchy of .emlx files for each individual email. The instructions below are not for that. They are for the [mailExportFolder]/[whatever].mbox "files" that are created when you right-click on a mailbox in Mail.app and choose "Export Mailbox...". This step creates perfectly valid mbox files wherever you save your export:

In Apple's Mail.app, right-click the folder you want to export and select "Export Mailbox..." Note that if you check the "Export all subfolders" option, you can export the entire hierarchy, but until I work out a script to accomplish it for you, you will have to import one subfolder at a time.

In the Finder, navigate to the exported folder, and keep drilling down into subfolders until you reach a directory named [name of folder].mbox which contains two files, {mbox, table_of_contents}

Either download a file type/creator change app like Quick Change and change the type resource on the mbox file to 'TEXT' or in Terminal app, cd to the parent folder of the mbox and type:
Code:
SetFile -t 'TEXT' mbox
It wouldn't hurt at this point to change the name of the file from 'mbox' to the name of whatever the originally exported folder was in Mail.app.

Now in Outlook, File>Import... Navigate to the changed mbox file, and you can import it.

OK, have a script for renaming all of the mboxes in a hierarchical export to proper names for import into Outlook. Any /bin/bash experts who see improvements, your input would be welcome. It takes as arguments the quoted path to the export destination, i.e.:
Code:
sh mboxconv.sh "/Users/admin/mail export"
Quotes obviated by simply not having any spaces in the path, but... whatever. Here's the bash script, to be followed soon by an AppleScript to replicate the hierarchy in Outlook. Name it however. I've named it mboxconv.sh:
Code:
#!/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
 
Last edited:

signetmac

macrumors newbie
Oct 23, 2012
2
0
Complete Solution: Import hierarchy of folders

OK so, disclaimers: First, I'm not much of an AppleScript programmer, and I'm sure this code isn't as clean as it could be, but it works. If you have ways to make it more efficient, I'd love to get feedback. Second, maybe it's the frustrated novelist in me, but I'm verbose in my comments. If it annoys you, sorry, but it's what I need so that when I return to this in a year to tweak it, I know what the heck I was thinking.

There are 3 components, the Apple provided utility, 'SetFile', a BASH script that initially cleans up the export from Mail.app, and lays out files under /tmp/ and an AppleScript that references those files later to import the archive and sort it.

I'll give the AppleScript first:
Code:
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
Open your AppleScript Editor, copy and paste the above code in and save it as an application, then save the BASH script that follows to a file named mboxconv.sh and move that file to the directory [path to AppleScript].app/Contents/Resources/ (for the less experienced: right-click on the AppleScript app you just created, and choose 'Show Package Contents')

The BASH script - mboxconv.sh:
Code:
#!/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"
Now get a copy of 'SetFile'. If you've already installed Xcode, you'll find it under /usr/bin/SetFile If not, you have two choices: you could download Xcode, if you have the time and hard drive space, or you could download SetFile from the 'transcoderredux' project at SourceForge, here:

SetFile

However, you probably want to take the time to download Xcode anyhow, since downloading files at anyone's direction who you don't know and trust, and executing them can get you in trouble. If you downloaded it from SourceForge, change the permissions to executable.

Once you get your hands on it, (again, Xcode will install it under /usr/bin/SetFile) copy it to the same place I have you save the BASH script to ([AppleScript Path].app/Contents/Resources) Then you will have a portable version of the AppleScript that you can use on other people's computers without needing to first install SetFile.

Instructions for use:
1. Go to Mail.app, and right click the parent directory of your email archive. Choose "Export Mailbox..."

2. In the drop down pane, choose "Export All Subfolders" and make a new Finder folder to export to, then click "Choose"

3. Drag the folder in the Finder that you exported to, and drop it on the AppleScript that you just created.

Notes: This uses GUI scripting for the import, since Outlook doesn't have an AppleScript command for that function. You need to let it execute undisturbed while it runs, and not go on to use other programs... so hands off. If you get impatient and start using other programs while it is running it will break. If it comes across a very large mbox file, it will pause until the import is done. Don't mistake this for the program having frozen, just let it sit and it will continue after the import finishes.

If anything fails, it is likely that the 'delay 1' commands in the GUI scripting function 'importMbox(ImportPath)' are too short. I wrote and tested this on a fast computer. On a slower computer, you may need to increase the delays.
 
Last edited:

Dal123

macrumors 6502a
Original poster
Oct 23, 2008
903
0
England
Thanks signet, I quickly looked at installing xcode and that looked like a chore itself and very risky if I did it wrong (which I'm sure to do :p).

The only old emails I have available to me are .emlx files, they do not contain attachments. Someone told me all I have to do is drag and drop the emails to a folder and that was how you back up.

This is not the case as they do not display in an email client; beware fellow email buddies :cool.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.