손상된 PST/OST 파일 읽기

손상된 저장소 파일 처리

때때로 일부 문제로 인해 PST/OST를 읽을 수 없을 수 있습니다. 예를 들어, 일부 데이터 블록이 손상될 수 있습니다. 이러한 경우에는 메서드를 호출할 때 예외가 발생하는 경우가 많습니다 the EnumerateFolders, EnumerateMessages, GetContents, GetSubfolders, 등 메서드. 그러나 개별 메시지나 폴더는 저장소에서 손상되지 않을 수 있습니다.

항목 식별자를 찾는 메서드

다음 메서드를 사용하면 계층적으로 항목 식별자를 찾을 수 있습니다.

메서드를 사용하여 얻은 식별자는 메시지와 폴더를 검색하는 데 사용할 수 있습니다.

NOTE: 장점에도 불구하고, 이러한 방법을 사용하더라도 읽을 수 없는 손상된 저장소가 있다는 점에 유의해야 합니다.

PST 파일 탐색

다음 코드 샘플은 PST 파일을 탐색하고 폴더와 메시지를 추출하는 방법을 보여줍니다. 식별자 목록을 얻으려면 FindMessages 및 FindSubfolders 메서드를 사용하십시오. 그런 다음 식별자는 the ExtractMessage 또는 GetFolderById 요소를 추출하는 메서드.

using (var pst = PersonalStorage.FromFile(fileName))
{
    ExploreCorruptedPst(pst, pst.RootFolder.EntryIdString);
}

public static void ExploreCorruptedPst(PersonalStorage pst, string rootFolderId)
{
    var messageIdList = pst.FindMessages(rootFolderId);

    foreach (var messageId in messageIdList)
    {
        try
        {
            var msg = pst.ExtractMessage(messageId);
            Console.WriteLine( "- " + msg.Subject);
        }
        catch
        {
            Console.WriteLine("Message reading error. Entry id: " + messageId);
        }
    }

    var folderIdList = pst.FindSubfolders(rootFolderId);

    foreach (var subFolderId in folderIdList)
    {
        if (subFolderId != rootFolderId)
        {
            try
            {
                FolderInfo subfolder = pst.GetFolderById(subFolderId);
                Console.WriteLine(subfolder.DisplayName);
            }
            catch
            {
                Console.WriteLine("Message reading error. Entry id: " + subFolderId);
            }

            ExplodeCorruptedPst(pst, subFolderId);
        }
    }
}