PST Bloating and Corruption (C# .NET)

Hi,
I know this message has been posted a couple of times previously by other people; however, those posts relate to the Java library and don’t appear to have been fixed in the .NET library. I’m using version 19.4 which is the latest at the time of writing.

I’m attempting to import MSG files into a PST. The MSG files total around 1.5GB but the resulting PST is 12GB. Some size differences are to be expected, but this is quite significant. Furthermore, the PST can’t be opened in Outlook (“Failed to create all properties in this location”) and instead I need to run it through ScanPST first which identifies 3,000 issues in a file containing 20,000 items. Once ScanPST is run I can open the PST and everything appears fine (although the file is still extremely large).

I am unable to provide copies of the MSG/PST files, but I’ve included the part of the code relating to importing the MSG files into the PST below.

private Int32 Import(String inputPath, String outputPath)
{
    using (PersonalStorage outputStorage = PersonalStorage.Create(outputPath, FileFormatVersion.Unicode))
    {
        return Import(inputPath, outputStorage.RootFolder);
    }
}

private Int32 Import(String inputPath, FolderInfo outputFolder)
{
    Int32 errors = 0;

    foreach (String file in Directory.GetFiles(inputPath, "*.msg", SearchOption.TopDirectoryOnly))
    {
        try
        {
            outputFolder.AddMessage(MapiMessage.FromFile(file));
        }
        catch
        {
            ++errors;
        }
    }

    foreach (String directory in Directory.GetDirectories(inputPath, "*", SearchOption.TopDirectoryOnly))
    {
        String name = new DirectoryInfo(directory).Name;
        FolderInfo outputSubFolder = outputFolder.GetSubFolder(name);

        if (outputSubFolder == null)
            outputSubFolder = outputFolder.AddSubFolder(name);

        errors += Import(directory, outputSubFolder);
    }

    return errors;
}

There are only 6 errors out of the 20,000 MSG files, which are occurring due to the filenames being too long, so they are unrelated to Aspose.Email. Apart from those six, the rest of the messages appear fine in the resulting PST (once run through ScanPST).

Any advice would be greatly appreciated.

Thanks.

@MiHadzic,

I have observed the issue shared by you and request you please share working sample project reproducing the issue on your end. My request to you would be sharing a subset of data reproducing the issue rather than complete 1.5 GB data and resulting 12 GB PST. We may need to investigate the requirements on our end to investigate this further on our end.

For anyone else having this issue, I have found that if you load the MSG files into a temporary PST, then merge the temporary PST with a new PST, the file will shrink back to an appropriate size and you no longer need to run ScanPST.

The downside is – using my above example – it took 15 minutes to load the MSG files then another 15 minutes to copy the temporary PST to the new PST, so you’re doubling the amount of time it takes but at least it works. The final file was 1.2GB which was smaller than the original MSG files combined.

Example code to be added to the code from the previous post:

private void CopyOutput(String temporaryFilePath, String finalFilePath)
{
    using (PersonalStorage storage = PersonalStorage.Create(finalFilePath, FileFormatVersion.Unicode))
    {
        storage.MergeWith(new String[] { temporaryFilePath });
    }

    File.Delete(temporaryFilePath);
}

I would still like to raise this as an issue for the developers - size is one thing, but the corruption issue is an important bug that needs fixing.

Thanks.

@MiHadzic,

It’s good to hear that workaround approach has worked on your end. I have created an issue with ID EMAILNET-39478 as investigation to further investigate this behavior on our end. This thread has been linked with the issue so that you may be notified once the issue will be fixed.