Aspose::Email::Storage::Olm::OlmStorage Class Reference

Represents an Outlook for Mac (.OLM) storage file and provides functionality to access and manipulate the data within the file such as emails, contacts, calendars, tasks, and notes. More...

Inherits IDisposable.

Public Member Functions

System::SharedPtr< System::Collections::Generic::ListExt< System::SharedPtr< OlmFolder > > > get_FolderHierarchy () const
 Gets the folder hierarchy. More...
 
 OlmStorage (Exceptions::TraversalExceptionsCallback callback)
 Initializes a new instance of the OlmStorage class. Allows setting a callback method for handling exceptions that occur during OLM storage traversal. More...
 
 OlmStorage (System::String fileName)
 Initializes a new instance of the OlmStorage class. More...
 
 OlmStorage (System::SharedPtr< System::IO::Stream > stream)
 Initializes a new instance of the OlmStorage class. More...
 
bool Load (System::SharedPtr< System::IO::Stream > stream)
 Load OLM storage from stream. This method is used when a OlmStorage object is created using constructor with the TraversalExceptionsCallback parameter. More...
 
bool Load (System::String fileName)
 Load OLM storage from file. This method is used when a OlmStorage object is created using constructor with the TraversalExceptionsCallback parameter. More...
 
System::SharedPtr< System::Collections::Generic::ListExt< System::SharedPtr< OlmFolder > > > GetFolders ()
 Gets collection of folders. More...
 
System::SharedPtr< OlmFolderGetFolder (System::String name, bool ignoreCase)
 Gets the folder by name. More...
 
System::SharedPtr< System::Collections::Generic::IList< System::SharedPtr< OlmItemCategory > > > GetCategories ()
 Gets the supported item categories. More...
 
System::SharedPtr< Mapi::MapiMessageExtractMapiMessage (System::String id)
 Get the message from OLM. More...
 
System::SharedPtr< Mapi::MapiMessageExtractMapiMessage (System::SharedPtr< OlmMessageInfo > messageInfo)
 Get the message from OLM storage. More...
 
int32_t GetTotalItemsCount ()
 Gets the total items count. Returns the total number of message items contained in the OLM. More...
 
System::SharedPtr< System::Collections::Generic::IEnumerable< System::SharedPtr< Mapi::MapiMessage > > > EnumerateMessages (System::SharedPtr< OlmFolder > folder)
 Exposes the enumerator, which supports an iteration of messages in folder. More...
 
void Dispose () override
 Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. More...
 
void SetVentureLicense (System::SharedPtr< VentureLicense > ventureLicense)
 

Static Public Member Functions

static System::SharedPtr< OlmStorageFromFile (System::String fileName)
 Load OLM storage from file. More...
 
static System::SharedPtr< OlmStorageFromStream (System::SharedPtr< System::IO::Stream > stream)
 Load OLM from stream. More...
 

Protected Member Functions

virtual void Dispose (bool disposing)
 Releases unmanaged and - optionally - managed resources. More...
 

Detailed Description

Represents an Outlook for Mac (.OLM) storage file and provides functionality to access and manipulate the data within the file such as emails, contacts, calendars, tasks, and notes.

The OlmStorage class allows users to read from and interact with the contents of .OLM files typically used by Microsoft Outlook for Mac. This class handles the various data types stored within an .OLM file by providing methods to enumerate and extract information.

The following code shows how to access and retrieve information from an Outlook for Mac data file (.olm file).

[C#]

using (var olm = OlmStorage.FromFile("storage.olm"))
{
// Retrieve the total number of items in the OLM storage.
var totalItemsCount = olm.GetTotalItemsCount();
Console.WriteLine($"Total items count: {totalItemsCount}");
// Iterate through each folder in the OLM storage.
foreach (var olmFolder in olm.GetFolders())
{
// Print the name of the currently iterated folder and the count of messages it contains.
Console.WriteLine($"Folder: {olmFolder.Name}");
Console.WriteLine($"Total items: {olmFolder.MessageCount}");
// Iterate through each message in the current folder.
foreach (var messageInfo in olmFolder.EnumerateMessages())
{
// Print the subject of the current message to the console.
Console.WriteLine($"Subject: {messageInfo.Subject}");
// Extract the full message object from the OLM storage.
var msg = olm.ExtractMapiMessage(messageInfo);
// Save the extracted message as a .msg file.
msg.Save($"{msg.Subject}.msg");
}
}
}

[Visual Basic]

Using olm As var = OlmStorage.FromFile("storage.olm")
' Retrieve the total number of items in the OLM storage and store the count in totalItemsCount.
Dim totalItemsCount As Integer = olm.GetTotalItemsCount()
' Print the total number of items in the OLM storage to the console.
Console.WriteLine($"Total items count: {totalItemsCount}")
' Iterate through each folder in the OLM storage.
For Each olmFolder In olm.GetFolders()
' Print the name of the currently iterated folder and the count of messages it contains.
Console.WriteLine($"Folder: {olmFolder.Name}")
Console.WriteLine($"Total items: {olmFolder.MessageCount}")
' Iterate through each message in the current folder.
For Each messageInfo In olmFolder.EnumerateMessages()
' Print the subject of the current message to the console.
Console.WriteLine($"Subject: {messageInfo.Subject}")
' Extract the full message object from the OLM storage using the information from messageInfo.
Dim msg As var = olm.ExtractMapiMessage(messageInfo)
' Save the extracted message as a .msg file on disk using its subject as the filename.
' Note: Message subject may need sanitization to be used as a valid filename.
msg.Save($"{msg.Subject}.msg")
Next
Next
End Using

Constructor & Destructor Documentation

◆ OlmStorage() [1/3]

Aspose::Email::Storage::Olm::OlmStorage::OlmStorage ( Exceptions::TraversalExceptionsCallback  callback)

Initializes a new instance of the OlmStorage class. Allows setting a callback method for handling exceptions that occur during OLM storage traversal.

Parameters
callbackThe exception callback.

◆ OlmStorage() [2/3]

Aspose::Email::Storage::Olm::OlmStorage::OlmStorage ( System::String  fileName)

Initializes a new instance of the OlmStorage class.

Parameters
fileNameOLM file name.
Returns
Returns an OlmStorage instance which is loaded from the specified file.
Exceptions
ArgumentNullExceptionthrows if file name is null or empty

◆ OlmStorage() [3/3]

Aspose::Email::Storage::Olm::OlmStorage::OlmStorage ( System::SharedPtr< System::IO::Stream >  stream)

Initializes a new instance of the OlmStorage class.

Parameters
streamSource stream System::IO::Stream with OLM storage data.
Returns
Returns an OlmStorage instance which is loaded from the specified stream.
Exceptions
ArgumentNullExceptionthrows if stream is null

Member Function Documentation

◆ Dispose() [1/2]

void Aspose::Email::Storage::Olm::OlmStorage::Dispose ( )
override

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

◆ Dispose() [2/2]

virtual void Aspose::Email::Storage::Olm::OlmStorage::Dispose ( bool  disposing)
protectedvirtual

Releases unmanaged and - optionally - managed resources.

Parameters
disposingtrue to release both managed and unmanaged resources; false to release only unmanaged resources.

◆ EnumerateMessages()

System::SharedPtr<System::Collections::Generic::IEnumerable<System::SharedPtr<Mapi::MapiMessage> > > Aspose::Email::Storage::Olm::OlmStorage::EnumerateMessages ( System::SharedPtr< OlmFolder folder)

Exposes the enumerator, which supports an iteration of messages in folder.

Parameters
folderOlmFolder that represents information about folder in OLM storage.
Returns
System::Collections::Generic::IEnumerable<T>, that represents an enumerator that iterates through a messages in folder.
Exceptions
ArgumentNullExceptionthrows if folder is null

◆ ExtractMapiMessage() [1/2]

System::SharedPtr<Mapi::MapiMessage> Aspose::Email::Storage::Olm::OlmStorage::ExtractMapiMessage ( System::SharedPtr< OlmMessageInfo messageInfo)

Get the message from OLM storage.

Parameters
messageInfoAn OlmMessageInfo object that represents information about message.
Returns
A MapiMessage object.

◆ ExtractMapiMessage() [2/2]

System::SharedPtr<Mapi::MapiMessage> Aspose::Email::Storage::Olm::OlmStorage::ExtractMapiMessage ( System::String  id)

Get the message from OLM.

Parameters
idString representation of EntryId.
Returns
A MapiMessage object.

◆ FromFile()

static System::SharedPtr<OlmStorage> Aspose::Email::Storage::Olm::OlmStorage::FromFile ( System::String  fileName)
static

Load OLM storage from file.

Parameters
fileNameName of .olm file.
Returns
An OlmStorage object that represents the current OLM file.

◆ FromStream()

static System::SharedPtr<OlmStorage> Aspose::Email::Storage::Olm::OlmStorage::FromStream ( System::SharedPtr< System::IO::Stream >  stream)
static

Load OLM from stream.

Parameters
streamThe System.IO.Stream.
Returns
An OlmStorage object that represents the current OLM storage.

◆ get_FolderHierarchy()

System::SharedPtr<System::Collections::Generic::ListExt<System::SharedPtr<OlmFolder> > > Aspose::Email::Storage::Olm::OlmStorage::get_FolderHierarchy ( ) const

Gets the folder hierarchy.

The folder hierarchy.

◆ GetCategories()

System::SharedPtr<System::Collections::Generic::IList<System::SharedPtr<OlmItemCategory> > > Aspose::Email::Storage::Olm::OlmStorage::GetCategories ( )

Gets the supported item categories.

Returns
A list of OlmItemCategory objects.

◆ GetFolder()

System::SharedPtr<OlmFolder> Aspose::Email::Storage::Olm::OlmStorage::GetFolder ( System::String  name,
bool  ignoreCase 
)

Gets the folder by name.

Parameters
nameName of folder.
ignoreCaseA value that indicates whether the name to match is case insensitive.
Returns
An OlmFolder object.

◆ GetFolders()

System::SharedPtr<System::Collections::Generic::ListExt<System::SharedPtr<OlmFolder> > > Aspose::Email::Storage::Olm::OlmStorage::GetFolders ( )

Gets collection of folders.

Returns
The collection of folders that belong to the storage, i.e. the sub-folders of the current OLMStorage object.

◆ GetTotalItemsCount()

int32_t Aspose::Email::Storage::Olm::OlmStorage::GetTotalItemsCount ( )

Gets the total items count. Returns the total number of message items contained in the OLM.

Returns
Total message items count.

◆ Load() [1/2]

bool Aspose::Email::Storage::Olm::OlmStorage::Load ( System::SharedPtr< System::IO::Stream >  stream)

Load OLM storage from stream. This method is used when a OlmStorage object is created using constructor with the TraversalExceptionsCallback parameter.

Parameters
streamThe stream.
Returns
'true' if the file has been loaded successfully and further traversal is possible; otherwise, false.

◆ Load() [2/2]

bool Aspose::Email::Storage::Olm::OlmStorage::Load ( System::String  fileName)

Load OLM storage from file. This method is used when a OlmStorage object is created using constructor with the TraversalExceptionsCallback parameter.

Parameters
fileNameThe file name.
Returns
'true' if the file has been loaded successfully and further traversal is possible; otherwise, false.

◆ SetVentureLicense()

void Aspose::Email::Storage::Olm::OlmStorage::SetVentureLicense ( System::SharedPtr< VentureLicense >  ventureLicense)
OlmStorage(Exceptions::TraversalExceptionsCallback callback)
Initializes a new instance of the OlmStorage class. Allows setting a callback method for handling exc...