GetContents(start, count) throws exception for some starting offsets (C# .NET)

When retrieving a portion of the contents of a folder using start offset and count, an exception is thrown when starting at certain offsets but not others. The failing offset is determined to be a valid offset, and the email in question can be accessed by starting at a different offset and iterating up to it. Other emails immediately after the failing offset also work correctly.

I’m not sure how to upload the sample PST in question but I am happy to do that if you can show me how. It is part of one of the Enron data sets.

Below is a sample program which demonstrates the issue:

class Program
{
    static void Main(string[] args)
    {
        InitLicense();
        string inputFile = @"C:\Temp\mary_fischer_000_1_1.pst";
        ReadChunks(inputFile);
    }

    public static void ReadChunks(string filePath)
    {
        // load the Outlook PST file
        PersonalStorage pst = PersonalStorage.FromFile(filePath);

        // Find the folder in question
        var folder = FindFolder(pst.RootFolder, "Notes inbox");
        if (folder == null)
            return;

        // Get a "chunk" of the folder contents
        ReadChunk(folder, 350, 408);   // This succeeds
        ReadChunk(folder, 388, 408);   // This succeeds
        ReadChunk(folder, 365, 408);   // This throws ArgumentOutOfRangeException: Non-negative number required. Parameter name: srcOffset
    }

    private static void ReadChunk(FolderInfo parentFolder, int startOffset, int endOffset)
    {
        int folderTotalCount = parentFolder.ContentCount;  // This shows 409 items in the folder
        int count = endOffset > folderTotalCount
                  ? folderTotalCount - startOffset
                  : endOffset - startOffset;
        MessageInfoCollection items = parentFolder.GetContents(startOffset, count);
    }

    private static FolderInfo FindFolder(FolderInfo parentFolder, string folderToFind)
    {
        if (parentFolder.DisplayName == folderToFind)
            return parentFolder;

        FolderInfoCollection subFolders = parentFolder.GetSubFolders();
        if (subFolders.Count == 0)
            return null;

        foreach (FolderInfo subFolder in subFolders)
        {
            var folder = FindFolder(subFolder, folderToFind);
            if (folder != null)
                return folder;
        }

        return null;
    }

    private static void InitLicense()
    {
        new Aspose.Email.License().SetLicense("Aspose.Total.lic");
    }
}

@wingswin1

I suggest you to please try using latest Aspose.Email for .NET 20.9 on your end. If there is still an issue then please share the source PST file with us along with working sample project. You can upload the PST on some file storage server and share download link with us.

Sorry I forgot to include version number. This is seen using Aspose.Email for .NET 20.9.

The sample program was provided in the original post. You can access the offending PST at this link:
[https://cloud9discovery-my.sharepoint.com/:u:/g/personal/mthompson_ediscovery_co/EWrwFaOcsndInNwCjd0f7ksBTEpqfJj8S2I6boAg7QAH0g ](https://cloud9discovery-my.sharepoint.com/:u:/g/personal/mthompson_ediscovery_co/EWrwFaOcsndInNwCjd0f7ksBTEpqfJj8S2I6boAg7QAH0g)

@wingswin1

I have tried to access the shared link. However, it is not allowing me to download the file and asking me to provide and email complying following:

To open this secure link, we’ll need you to enter the email that this item was shared to.

The sample data was shared with your email, support@aspose.com.

@wingswin1

Can you please be kind enough to share the file on some public server or on One drive without email authentication. You can zip the file with password and share the password with us privately using private message. For private message, you can click on my name icon in any of my posts and then select Message button to send private message.

@wingswin1

We have added an issue with ID EMAILNET-39969 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be addressed.

The issues you have found earlier (filed as EMAILNET-39969) have been fixed in this update.