When extracting messages from the PST
https://www.dropbox.com/s/z3cc90hs14qq9to/JAN-5174.pst?dl=0
With the code below.
I get the following exception:
Saving AAAAAJMxOHZCV4pMuQ4tEgo2fkeEYyAA at 5/29/2019 5:12:39 PM
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 27
filePath = "JAN-5174.pst";
repro.ExtractPst(filePath);
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Aspose.Email.Storage.Pst;
namespace PstTester
{
class repro
{
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())
{
Console.WriteLine("Saving {0} at {1}", entryIdString, DateTime.Now);
personalStorage.SaveMessageToStream(entryIdString, memorystream);
Console.WriteLine("Saved {0} at {1}", entryIdString, DateTime.Now);
}
}
}
}
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;
}
}
}