Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/OldXstReader/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ private void treeFolders_SelectedItemChanged(object sender, RoutedPropertyChange
{
try
{
//Clear contents of prev selected folder
view.SelectedFolder?.Folder?.ClearContents();


FolderView fv = (FolderView)e.NewValue;
view.SelectedFolder = fv;

Expand Down
2 changes: 1 addition & 1 deletion src/OldXstReader/MessageView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public bool IsSelected

public void ClearContents()
{
Message.ClearContents();

Attachments.Clear();
}

Expand Down
4 changes: 2 additions & 2 deletions src/OldXstReader/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ public void PopMessage()

public void Clear()
{
SelectedFolder?.Folder?.ClearContents();

SelectedFolder = null;
CurrentMessage?.Message?.ClearContents();

CurrentMessage = null;
RootFolderViews.Clear();
stackMessage.Clear();
Expand Down
2 changes: 1 addition & 1 deletion src/XstExporter.Portable/XstExporter.Portable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AssemblyVersion>2.0.1</AssemblyVersion>
<FileVersion>2.0.1</FileVersion>
<Version>2.0.1</Version>
Expand Down
1 change: 1 addition & 0 deletions src/XstReader.Api.Tests/MSTestSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
88 changes: 88 additions & 0 deletions src/XstReader.Api.Tests/ReadingStreamTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Diagnostics;
using System.Security.Cryptography.X509Certificates;
using XstReader.Api;


namespace XstReader.Api.Tests
{
[TestClass]
public sealed class ReadingStreamTests
{
private string _pstFilepath = "<PSTFILEPATH HERE>";

[TestMethod]
public void OpenFileWithXstReader()
{
// Arrange



using var xstFile = new XstFile(_pstFilepath);


// Assert
Assert.IsNotNull(xstFile);
Assert.IsNotNull(xstFile.RootFolder);
}


[TestMethod]
public void OpenFileAndPassStreamToXstReader()
{
// Arrange

using FileStream fileStream = new FileStream(_pstFilepath, FileMode.Open, FileAccess.Read);
// Act
using var xstFile = new XstFile(fileStream);


// Assert
Assert.IsNotNull(xstFile);
Assert.IsNotNull(xstFile.RootFolder);
}

[TestMethod]
public void ReadInboxFromStream()
{

using FileStream fileStream = new FileStream(_pstFilepath, FileMode.Open, FileAccess.Read);
// Act
using var xstFile = new XstFile(fileStream);


// Assert
Assert.IsNotNull(xstFile);
Assert.IsNotNull(xstFile.RootFolder);


FindInboxMessages(xstFile.RootFolder);
}

public bool FindInboxMessages(XstFolder folder)
{
if (folder.DisplayName == "Inbox")
{
foreach (var m in folder.Messages)
{
Debug.WriteLine($"{m.InternetMessageId} - {m.Subject} - {m.Date} - has attachments:{m.HasAttachments}");
foreach (var a in m.Attachments)
{
Debug.WriteLine($"Attachment: {a.DisplayName} - {a.Size} bytes");
}
}

return true;
}

foreach(var f in folder.Folders)
{
if (FindInboxMessages(f))
break;
}

return false;
}

}
}
33 changes: 33 additions & 0 deletions src/XstReader.Api.Tests/XstReader.Api.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnableMSTestRunner>true</EnableMSTestRunner>
<OutputType>Exe</OutputType>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
<!--
Displays error on console in addition to the log file. Note that this feature comes with a performance impact.
For more information, visit https://learn.microsoft.com/dotnet/core/testing/unit-testing-platform-integration-dotnet-test#show-failure-per-test
-->
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.14.2" />
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="1.6.3" />
<PackageReference Include="MSTest" Version="3.8.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\XstReader.Api\XstReader.Api.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/XstReader.Api/Common/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace XstReader.Common
internal static class Map
{
// Read enough bytes from the file stream at the current position to populate specified type T
public static T ReadType<T>(FileStream fs)
public static T ReadType<T>(Stream fs)
{
byte[] buffer = new byte[Marshal.SizeOf(typeof(T))];
fs.Read(buffer, 0, Marshal.SizeOf(typeof(T)));
Expand Down
11 changes: 10 additions & 1 deletion src/XstReader.Api/LTP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,16 @@ public IEnumerable<T> ReadTable<T>(BTree<Node> subNodeTree,

// Test for the presence of an optional table in the supplied sub node tree
public bool IsTablePresent(BTree<Node> subNodeTree, NID nid)
=> (subNodeTree != null && NDB.LookupSubNode(subNodeTree, nid) != null);
{
if(subNodeTree != null)
{
var subNode = NDB.LookupSubNode(subNodeTree, nid);
return subNode != null;
}

return false;
}


#endregion

Expand Down
6 changes: 3 additions & 3 deletions src/XstReader.Api/NDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private void ReadDeferredIndex(TreeIntermediate inter)
inter.fileOffset = null;
}
// Read a page containing part of a node or data block B-tree, and build the corresponding data structure
private void ReadBTPageUnicode(FileStream fs, ulong fileOffset, TreeIntermediate parent)
private void ReadBTPageUnicode(Stream fs, ulong fileOffset, TreeIntermediate parent)
{
fs.Seek((long)fileOffset, SeekOrigin.Begin);
var p = Map.ReadType<BTPAGEUnicode>(fs);
Expand Down Expand Up @@ -286,7 +286,7 @@ private void ReadBTPageUnicode(FileStream fs, ulong fileOffset, TreeIntermediate
}

// Read a page containing part of a node or data block B-tree, and build the corresponding data structure
private void ReadBTPageUnicode4K(FileStream fs, ulong fileOffset, TreeIntermediate parent)
private void ReadBTPageUnicode4K(Stream fs, ulong fileOffset, TreeIntermediate parent)
{
fs.Seek((long)fileOffset, SeekOrigin.Begin);
var p = Map.ReadType<BTPAGEUnicode4K>(fs);
Expand Down Expand Up @@ -338,7 +338,7 @@ private void ReadBTPageUnicode4K(FileStream fs, ulong fileOffset, TreeIntermedia
}
}

private void ReadBTPageANSI(FileStream fs, ulong fileOffset, TreeIntermediate parent)
private void ReadBTPageANSI(Stream fs, ulong fileOffset, TreeIntermediate parent)
{
fs.Seek((long)fileOffset, SeekOrigin.Begin);
var p = Map.ReadType<BTPAGEANSI>(fs);
Expand Down
10 changes: 2 additions & 8 deletions src/XstReader.Api/XstAttachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ private XstMessage GetAttachedEmailMessage()
SubNodeTreeParentAttachment = subNodeTreeAttachment,
};

// Read the basic and contents properties
_AttachedEmailMessage.BodyLoader = () => Ltp.ReadProperties(subNodeTreeAttachment, _AttachedEmailMessage.Nid, _AttachedEmailMessage.Properties, true);

}
else
throw new XstException("Unexpected data type for attached message");
Expand Down Expand Up @@ -444,12 +443,7 @@ private void ClearAttachmentContent()
_Content = null;
}

internal override void ClearContentsInternal()
{
base.ClearContentsInternal();
ClearAttachedEmailMessage();
ClearAttachmentContent();
}


/// <summary>
/// Gets the String representation of the object
Expand Down
26 changes: 7 additions & 19 deletions src/XstReader.Api/XstElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace XstReader
/// <summary>
/// Base class for an element inside a pst or ost file
/// </summary>
public abstract class XstElement
public abstract class XstElement : IDisposable
{
/// <summary>
/// The Type of the element
Expand Down Expand Up @@ -129,30 +129,18 @@ protected XstElement(XstElementType elementType)
}
#endregion Ctor

private protected void ClearProperties()
{
Properties.ClearContents();
//_Properties = null;
}

/// <summary>
/// Clear all Contents
/// </summary>
public virtual void ClearContents()
{
new Thread(() => { ClearContentsInternal(); GC.Collect(); }).Start();
}

internal virtual void ClearContentsInternal()
{
ClearProperties();
}


/// <summary>
/// Gets the String representation of the object
/// </summary>
/// <returns></returns>
public override string ToString()
=> DisplayName;

public void Dispose()
{

}
}
}
59 changes: 18 additions & 41 deletions src/XstReader.Api/XstFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ public class XstFile : XstElement, IDisposable
private void SetFileName(string fileName)
{
_FileName = fileName;
ClearContents();

}

private FileStream _ReadStream = null;
internal FileStream ReadStream
private Stream _ReadStream = null;
internal Stream ReadStream
{
get => _ReadStream ?? (_ReadStream = new FileStream(FileName, FileMode.Open, FileAccess.Read));
private set
{
_ReadStream = value;
}
}
internal object StreamLock { get; } = new object();

Expand Down Expand Up @@ -81,6 +85,15 @@ public XstFile(string fileName) : base(XstElementType.File)
{
FileName = fileName;
}

/// <summary>
/// Ctor
/// </summary>
/// <param name="stream">A stream that could be any stream file, memory, network</param>
public XstFile(Stream stream) : base(XstElementType.File)
{
ReadStream = stream;
}
#endregion Ctor

private void ClearStream()
Expand All @@ -93,46 +106,10 @@ private void ClearStream()
}
}

/// <summary>
/// Clears information and memory used in RootFolder
/// </summary>
private void ClearRootFolder()
{
if (_RootFolder != null)
{
_RootFolder.ClearContents();
_RootFolder = null;
}
}

/// <summary>
/// Clears all information and memory used by the object
/// </summary>
public override void ClearContents()
{
ClearStream();
ClearRootFolder();

_Ndb = null;
_Ltp = null;
}

/// <summary>
/// Disposes memory used by the object
/// </summary>
public void Dispose()
{
ClearContents();
}

/// <summary>
/// Gets the String representation of the object
/// </summary>
/// <returns></returns>
public override string ToString()
{
return System.IO.Path.GetFileName(FileName ?? "");
}



private protected override IEnumerable<XstProperty> LoadProperties()
{
Expand Down
Loading