Reading large pst files (5+ GB) for calendar specific data

Hello,
I have a bunch of PST files that are 5+ GB in size. I am planning to read them using Aspose.Email.Storage.Pst.PersonalStorage.FromFile() to extract calendar data from the pst files. Any suggestions/recommendations on the best approaches to use so that I don’t run into memory issues or hangs? Below is the code snippet of what I do for each pst:

     // FolderInfo folderInfo, PersonalStorage personalStorage
    MessageInfoCollection messages = folderInfo.GetContents();
    foreach (MessageInfo messageInfo in messages)
    {
        // Extract message information
        MapiMessage message = personalStorage.ExtractMessage(messageInfo);      

        if (message.MessageClass == "IPM.Appointment")
        {            
            var calEvent = message.ToMapiMessageItem() as MapiCalendar;
            .......

Thanks,
Vijay

Hello @vijaykr,

Welcome to our support forum!

Consider using methods that return IEnumerable when traversing folders or messages in a PST file:

foreach (var messageInfo in folderInfo.EnumerateMessages())
{
    if (messageInfo.MessageClass == "IPM.Appointment")
    {
        var calEvent = pst.ExtractMessage(messageInfo).ToMapiMessageItem() as MapiCalendar;
    }
}

Alternatively, you can use search-based filtering to retrieve the messages you need:

var queryBuilder = new PersonalStorageQueryBuilder();
queryBuilder.MessageClass.Equals("IPM.Appointment");

foreach (var messageInfo in folder.EnumerateMessages(queryBuilder.GetQuery()))
{
    var calEvent = pst.ExtractMessage(messageInfo).ToMapiMessageItem() as MapiCalendar;
}

Thank you.