PST Processing via EntryID

Hello Team,

we are extracting EntryIds from PST file using some other Tools.
Now we want ASpose to use that EntryId and Extract Metadata and attachments.

Here from Reference document, I can see there is no direct way to get Message from PST using provided EntryId.

it has to write code as below,
private MailMessage FindMessageByEntryId(FolderInfo folder, string entryId)
{
foreach (MessageInfo messageInfo in folder.EnumerateMessages())
{
if (messageInfo.EntryIdString.Equals(entryId, StringComparison.OrdinalIgnoreCase))
{
return folder.GetMessage(messageInfo);
}
}

    // Recurse into subfolders
    foreach (FolderInfo subFolder in folder.GetSubFolders())
    {
        MailMessage msg = FindMessageByEntryId(subFolder, entryId);
        if (msg != null)
            return msg;
    }

    return null;
}

so is there any other suggestion or Method that we can use for fast navigation to access object using entryId.
Please advise.
Thanks

Hello @Viral84,

Hi,

You don’t need to manually traverse all folders and messages to find a message by EntryId.

Aspose.Email already provides a direct method for this:
PersonalStorage.ExtractMessage(string entryId)

This method allows you to extract the message directly from the PST using the EntryId, so there is no need to iterate through folders and messages recursively.

Example:

using (PersonalStorage pst = PersonalStorage.FromFile("sample.pst"))
{
    MapiMessage message = pst.ExtractMessage(entryId);
}

Thank you so much for this… @margarita.samodurova

You are welcome!