Converting OLM to PST
Contents
[
Hide
]
OLM is a database file format used by Microsoft Outlook for Mac. OLM files store email messages, calendar data, contacts, and application settings, and they are not supported by Outlook for Windows. To migrate a mailbox from Outlook for Mac to Outlook for Windows, you need to convert the OLM file to the Outlook PST format. Aspose.Email for .NET lets you do this in code, without Microsoft Outlook installed.
How the Conversion Works
To convert an OLM file to PST, follow these steps:
- Create an instance of the OlmStorage class to open the source OLM file.
- Create a new PST file with the PersonalStorage.Create method.
- Implement a
GetContainerClassmethod that maps a message class to the corresponding folder (container) class, so each folder is created with the correct type in the PST. - Implement an
AddToPstmethod that recursively reads each folder and its messages from the OLM file - using EnumerateMapiMessages - and adds them to the PST in the same order, using theAddSubFolderandAddMessagemethods of FolderInfo.
Code Sample
The following code shows how to convert an OLM file to PST.
Main method:
// create an instance of OlmStorage class to open the source OLM
using (var olm = new OlmStorage("my.olm"))
// create a new PST file
using (var pst = PersonalStorage.Create("my.pst", FileFormatVersion.Unicode))
{
// recursively read each folder and its messages
// and add them to the PST in the same order
foreach (var olmFolder in olm.FolderHierarchy)
{
AddToPst(pst.RootFolder, olmFolder);
}
}
GetContainerClass method:
public string GetContainerClass(string messageClass)
{
if (messageClass.StartsWith("IPM.Contact") || messageClass.StartsWith("IPM.DistList"))
{
return "IPF.Contact";
}
if (messageClass.StartsWith("IPM.StickyNote"))
{
return "IPF.StickyNote";
}
if (messageClass.StartsWith("IPM.Activity"))
{
return "IPF.Journal";
}
if (messageClass.StartsWith("IPM.Task"))
{
return "IPF.Task";
}
if (messageClass.StartsWith("IPM.Appointment") || messageClass.StartsWith("IPM.Schedule.meeting"))
{
return "IPF.Appointment";
}
return "IPF.Note";
}
AddToPst method:
public void AddToPst(FolderInfo pstFolder, OlmFolder olmFolder)
{
FolderInfo pstSubFolder = pstFolder.GetSubFolder(olmFolder.Name);
foreach (var msg in olmFolder.EnumerateMapiMessages())
{
if (pstSubFolder == null)
{
pstSubFolder = pstFolder.AddSubFolder(olmFolder.Name, GetContainerClass(msg.MessageClass));
}
pstSubFolder.AddMessage(msg);
}
if (pstSubFolder == null)
{
pstSubFolder = pstFolder.AddSubFolder(olmFolder.Name);
}
foreach (var olmSubFolder in olmFolder.SubFolders)
{
AddToPst(pstSubFolder, olmSubFolder);
}
}
Conversion in the opposite direction (PST to OLM) is not supported, because an OLM file is always created by Outlook for Mac when an account is added and synchronized with the mail server.