public class OlmStorage extends Object implements IDisposable, Closeable
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.
Example:
try (OlmStorage olm = OlmStorage.fromFile("storage.olm")) {
// Retrieve the total number of items in the OLM storage.
int totalItemsCount = olm.getTotalItemsCount();
System.out.println("Total items count: " + totalItemsCount);
// Iterate through each folder in the OLM storage.
for (OlmFolder olmFolder : olm.getFolders()) {
// Print the name of the currently iterated folder and the count of messages it contains.
System.out.println("Folder: " + olmFolder.getName());
System.out.println("Total items: " + olmFolder.getMessageCount());
// Iterate through each message in the current folder.
for (OlmMessageInfo messageInfo : olmFolder.enumerateMessages()) {
// Print the subject of the current message to the console.
System.out.println("Subject: " + messageInfo.getSubject());
// Extract the full message object from the OLM storage.
MapiMessage msg = olm.extractMapiMessage(messageInfo);
// Save the extracted message as a .msg file.
msg.save(msg.getSubject() + ".msg");
}
}
} catch (Exception e) {
e.printStackTrace();
}
| Constructor and Description |
|---|
OlmStorage(InputStream stream)
Initializes a new instance of the
OlmStorage class. |
OlmStorage(String fileName)
Initializes a new instance of the
OlmStorage class. |
OlmStorage(TraversalExceptionsCallback callback)
Initializes a new instance of the
OlmStorage class. |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
dispose()
Performs application-defined tasks associated with freeing,
releasing, or resetting unmanaged resources.
|
protected void |
dispose(boolean disposing)
Releases unmanaged and - optionally - managed resources.
|
IGenericEnumerable<MapiMessage> |
enumerateMessages(OlmFolder folder)
Exposes the enumerator, which supports an iteration of messages in folder.
|
MapiMessage |
extractMapiMessage(OlmMessageInfo messageInfo)
Get the message from OLM storage.
|
MapiMessage |
extractMapiMessage(String id)
Get the message from OLM.
|
static OlmStorage |
fromFile(String fileName)
Load OLM storage from file.
|
static OlmStorage |
fromStream(InputStream stream)
Load OLM from stream.
|
List<OlmItemCategory> |
getCategories()
Gets the supported item categories.
|
OlmFolder |
getFolder(String name,
boolean ignoreCase)
Gets the folder by name.
|
List<OlmFolder> |
getFolderHierarchy()
Gets the folder hierarchy.
|
List<OlmFolder> |
getFolders()
Gets collection of folders.
|
int |
getTotalItemsCount()
Gets the total items count.
|
boolean |
load(InputStream stream)
Load OLM storage from stream.
|
boolean |
load(String fileName)
Load OLM storage from file.
|
public OlmStorage(TraversalExceptionsCallback callback)
Initializes a new instance of the OlmStorage class.
Allows setting a callback method for handling exceptions that occur during OLM storage traversal.
callback - The exception callback.public OlmStorage(String fileName)
Initializes a new instance of the OlmStorage class.
fileName - OLM file name.ArgumentNullException - throws if file name is null or emptypublic OlmStorage(InputStream stream)
Initializes a new instance of the OlmStorage class.
stream - Source stream InputStream with OLM storage data.ArgumentNullException - throws if stream is nullpublic final List<OlmFolder> getFolderHierarchy()
Gets the folder hierarchy.
Value: The folder hierarchy.public final boolean load(InputStream stream)
Load OLM storage from stream. This method is used when a OlmStorage object is created using constructor with the TraversalExceptionsCallback parameter.
stream - The stream.public final boolean load(String fileName)
Load OLM storage from file. This method is used when a OlmStorage object is created using constructor with the TraversalExceptionsCallback parameter.
fileName - The file name.public static OlmStorage fromFile(String fileName)
Load OLM storage from file.
fileName - Name of .olm file.public static OlmStorage fromStream(InputStream stream)
Load OLM from stream.
stream - The System.IO.Stream.public final List<OlmFolder> getFolders()
Gets collection of folders.
public final OlmFolder getFolder(String name, boolean ignoreCase)
Gets the folder by name.
name - Name of folder.ignoreCase - A value that indicates whether the name to match is case insensitive.public final List<OlmItemCategory> getCategories()
Gets the supported item categories.
OlmItemCategory objects.public final MapiMessage extractMapiMessage(String id)
Get the message from OLM.
id - String representation of EntryId.MapiMessage object.public final MapiMessage extractMapiMessage(OlmMessageInfo messageInfo)
Get the message from OLM storage.
messageInfo - An OlmMessageInfo object that
represents information about message.public final int getTotalItemsCount()
Gets the total items count. Returns the total number of message items contained in the OLM.
public final IGenericEnumerable<MapiMessage> enumerateMessages(OlmFolder folder)
Exposes the enumerator, which supports an iteration of messages in folder.
folder - OlmFolder that represents information about folder in OLM storage.System.Collections.Generic.IEnumerableltTgt,
that represents an enumerator that iterates through a messages in folder.ArgumentNullException - throws if folder is nullpublic final void dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
dispose in interface IDisposablepublic void close()
close in interface Closeableclose in interface AutoCloseableprotected void dispose(boolean disposing)
Releases unmanaged and - optionally - managed resources.
disposing - true to release both managed
and unmanaged resources; false to release only unmanaged resources.Copyright (c) 2008-2024 Aspose Pty Ltd. All Rights Reserved.