Free Support Forum - aspose.com

Cannot extract some emails from PST


#1

We cannot extract using Aspose.Email the 3 emails included in the following PST:

using (var currentPst = PersonalStorage.FromStream(inputStream))
{
foreach (var messageId in request.MessageIds)
{
using (var fileStream = File.OpenWrite(tempLocalEmail))
{
currentPst.SaveMessageToStream(messageId, fileStream);
}
}
}


#2

@PeteLee

You may use the code sample given at this link to read and extract messages from all folders using a recursive function:
https://docs.aspose.com/display/emailnet/Working+with+Messages+in+a+PST+File#WorkingwithMessagesinaPSTFile-ExtractingMessagesFormPSTFiles

Furthermore, please feel free to write back to us if additional information is required.


#3

running the following code on the PST, results in the exception below

  public static void ExtractPst(string pstfilename)
    {
        Program.InitializeAsposeMailLicense();
        string path = pstfilename;

        // Save message to MemoryStream
        using (PersonalStorage personalStorage = PersonalStorage.FromFile(path))
        {
            List<string> allMessageIds = GetAllMessageId(personalStorage.RootFolder);

            foreach (string entryIdString in allMessageIds)
            {
                using (MemoryStream memorystream = new MemoryStream())
                {
                    personalStorage.SaveMessageToStream(entryIdString, memorystream);
                }
            }
            
        }

    }

    static List<string> GetAllMessageId(FolderInfo folder)
    {
        List<string> messageIdList = new List<string>();

        var messageIds = folder.EnumerateMessagesEntryId();

        messageIdList.AddRange(messageIds.ToList());

        var subFolders = folder.EnumerateFolders();
        foreach (var subFolder in subFolders)
        {
            var someMessageIds = GetAllMessageId(subFolder);
            messageIdList.AddRange(someMessageIds);
        }

        return messageIdList;
    }

Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
at #=zI5JwC3ZCgW4HTj1bZpUcUucQt3p1cvC0LtaJ9wZGQw8o.#=zrDEU88dPSeXy(String #=zJmbxurc=, String #=ztxtvnsmJsYNI)
at #=zI5JwC3ZCgW4HTj1bZpUcUucQt3p1cvC0LtaJ9wZGQw8o.#=z8Hv5O7E=(String #=znLJBU9g=, StringBuilder #=z4M10kjc=)
at #=zI5JwC3ZCgW4HTj1bZpUcUucQt3p1cvC0LtaJ9wZGQw8o.#=z9YFcLOU=(String #=z_JfOGA_zhkbY)
at #=zWAWrInA$rr783lhXkXnK7OEeLwa1AOiWkA==.#=zSyV72edmzIdh(String #=z_JfOGA_zhkbY)
at #=zSqj10qCjZCEFV6a3UtavEhJU_ZhJl2RlVnKNeLc=.get_Data()
at #=z72k7a$mdzj3v_55eqYKXq2yV4hRs7EwypYnyW_s=.#=z5O6RE5nknLRF(UInt32 #=zA936i6zVftzP, Stream #=zVhu4sBU=)
at Aspose.Email.Storage.Pst.PersonalStorage.SaveMessageToStream(String entryId, Stream stream)
at PstTester.repro.ExtractPst(String pstfilename) in C:\Users\Administrator\Documents\GitHub\disco-batch\tools\PstTester\PstTester\repro.cs:line 25
at PstTester.Program.Main(String[] args) in C:\Users\Administrator\Documents\GitHub\disco-batch\tools\PstTester\PstTester\Program.cs:line 33


#4

@PeteLee

We were able to reproduce this issue and it has been logged with ID “EMAILNET-39264” for further investigation. We will update you here once we have more information to share.


#5

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