Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Class

MhtmlDocument

OfficeIMO.Mhtml

Namespace
OfficeIMO.Mhtml
Assembly
OfficeIMO.Mhtml
Source revision
0eef6a5756b9 with working tree changes
Modifiers
sealed

Represents an MHTML web archive as an HTML document plus its decoded MIME related resources.

Inheritance

  • object
  • MhtmlDocument

Usage

Explore 2 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

Returned or exposed by 2

Constructors

public MhtmlDocument(string html, IEnumerable<MhtmlResource>? resources = null, string? contentLocation = null, string? rootContentId = null, string? subject = null, HtmlConversionDocumentOptions? htmlOptions = null) #

Creates an MHTML document from HTML and optional related resources.

Parameters

html string required
resources System.Collections.Generic.IEnumerable<OfficeIMO.Mhtml.MhtmlResource>? = null optional
contentLocation string? = null optional
rootContentId string? = null optional
subject string? = null optional
htmlOptions OfficeIMO.Html.HtmlConversionDocumentOptions? = null optional

Methods

ConfigureRenderOptions 2 overloads
public void ConfigureRenderOptions(HtmlRenderOptions options) #

Applies the archive base URI, resource-only URL policy, and embedded-resource resolver to render options. The hyperlink policy is left unchanged. Remote resources absent from the archive are fetched only through the policy's one-hop resolver so every redirect destination is approved before it is requested.

Parameters

options OfficeIMO.Html.HtmlRenderOptions required
public void ConfigureRenderOptions(HtmlRenderOptions options, MhtmlRemoteResourcePolicy? remoteResourcePolicy) #

Applies the archive base URI, resource-only URL policy, embedded-resource resolver, and explicit bounded remote-resource policy to render options.

Parameters

options OfficeIMO.Html.HtmlRenderOptions required
remoteResourcePolicy OfficeIMO.Mhtml.MhtmlRemoteResourcePolicy? required
public MhtmlImageEmbeddingResult CreateEmbeddedImageDocumentResult(HtmlRenderOptions? resourceLimits = null, CancellationToken cancellationToken = default) #

Creates an independent HTML conversion document whose direct image sources use the matching MIME parts from this archive. It never fetches resources outside the archive. The original MhtmlDocument.HtmlDocument and its render resolver remain unchanged.

Parameters

resourceLimits OfficeIMO.Html.HtmlRenderOptions? = null optional
Optional shared resource byte, count, and request limits. Other render settings are ignored.
cancellationToken System.Threading.CancellationToken = default optional
Stops preparation before the next image is processed.

Returns

MhtmlImageEmbeddingResult The editable document and diagnostics for image sources not embedded.
public HtmlRenderResourceResolver CreateResourceResolver() #

Creates a resolver that serves only resources embedded in this archive.

Returns

HtmlRenderResourceResolver
InspectContentSafety 2 overloads
public static OfficeContentSafetyReport InspectContentSafety(byte[] archiveBytes, OfficeContentSafetyOptions? options = null, EmailReaderOptions? mimeOptions = null, CancellationToken cancellationToken = default) #

Inspects concealed machine-readable HTML in a bounded MHTML archive.

Parameters

archiveBytes byte[] required
options OfficeIMO.ContentSafety.OfficeContentSafetyOptions? = null optional
mimeOptions OfficeIMO.Email.EmailReaderOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

OfficeContentSafetyReport
public static OfficeContentSafetyReport InspectContentSafety(string filePath, OfficeContentSafetyOptions? options = null, EmailReaderOptions? mimeOptions = null, CancellationToken cancellationToken = default) #

Inspects concealed machine-readable HTML in a bounded MHTML file.

Parameters

filePath string required
options OfficeIMO.ContentSafety.OfficeContentSafetyOptions? = null optional
mimeOptions OfficeIMO.Email.EmailReaderOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

OfficeContentSafetyReport
Load 2 overloads
public static MhtmlDocument Load(string path, EmailReaderOptions? mimeOptions = null, HtmlConversionDocumentOptions? htmlOptions = null, CancellationToken cancellationToken = default) #

Loads an MHTML archive from a file.

Parameters

path string required
mimeOptions OfficeIMO.Email.EmailReaderOptions? = null optional
htmlOptions OfficeIMO.Html.HtmlConversionDocumentOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional
public static MhtmlDocument Load(Stream stream, EmailReaderOptions? mimeOptions = null, HtmlConversionDocumentOptions? htmlOptions = null, CancellationToken cancellationToken = default) #

Loads an MHTML archive from a caller-owned stream.

Parameters

stream System.IO.Stream required
mimeOptions OfficeIMO.Email.EmailReaderOptions? = null optional
htmlOptions OfficeIMO.Html.HtmlConversionDocumentOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional
LoadAsync 2 overloads
public static async Task<MhtmlDocument> LoadAsync(string path, EmailReaderOptions? mimeOptions = null, HtmlConversionDocumentOptions? htmlOptions = null, CancellationToken cancellationToken = default) #

Asynchronously loads an MHTML archive from a file.

Parameters

path string required
mimeOptions OfficeIMO.Email.EmailReaderOptions? = null optional
htmlOptions OfficeIMO.Html.HtmlConversionDocumentOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

Task<MhtmlDocument>
public static async Task<MhtmlDocument> LoadAsync(Stream stream, EmailReaderOptions? mimeOptions = null, HtmlConversionDocumentOptions? htmlOptions = null, CancellationToken cancellationToken = default) #

Asynchronously loads an MHTML archive from a caller-owned stream.

Parameters

stream System.IO.Stream required
mimeOptions OfficeIMO.Email.EmailReaderOptions? = null optional
htmlOptions OfficeIMO.Html.HtmlConversionDocumentOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

Task<MhtmlDocument>
RemoveSelectedContent 2 overloads
public static OfficeContentCleanupResult RemoveSelectedContent(byte[] archiveBytes, OfficeContentCleanupSelection selection, OfficeContentCleanupOptions? options = null, EmailReaderOptions? mimeOptions = null, CancellationToken cancellationToken = default) #

Removes exact selected concealed HTML findings, then reopens and reinspects the MHTML archive.

Parameters

archiveBytes byte[] required
selection OfficeIMO.ContentSafety.OfficeContentCleanupSelection required
options OfficeIMO.ContentSafety.OfficeContentCleanupOptions? = null optional
mimeOptions OfficeIMO.Email.EmailReaderOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

OfficeContentCleanupResult
public static OfficeContentCleanupResult RemoveSelectedContent(string inputPath, string outputPath, OfficeContentCleanupSelection selection, OfficeContentCleanupOptions? options = null, EmailReaderOptions? mimeOptions = null, CancellationToken cancellationToken = default) #

Atomically writes an explicitly cleaned MHTML artifact.

Parameters

inputPath string required
outputPath string required
selection OfficeIMO.ContentSafety.OfficeContentCleanupSelection required
options OfficeIMO.ContentSafety.OfficeContentCleanupOptions? = null optional
mimeOptions OfficeIMO.Email.EmailReaderOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

OfficeContentCleanupResult
Save 2 overloads
public void Save(string path, EmailWriterOptions? options = null) #

Saves the archive to a file.

Parameters

path string required
options OfficeIMO.Email.EmailWriterOptions? = null optional
public void Save(Stream stream, EmailWriterOptions? options = null) #

Saves the archive to a caller-owned stream.

Parameters

stream System.IO.Stream required
options OfficeIMO.Email.EmailWriterOptions? = null optional
SaveAsync 2 overloads
public Task<EmailWriteResult> SaveAsync(string path, EmailWriterOptions? options = null, CancellationToken cancellationToken = default) #

Asynchronously saves the archive to a file.

Parameters

path string required
options OfficeIMO.Email.EmailWriterOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

Task<EmailWriteResult>
public Task<EmailWriteResult> SaveAsync(Stream stream, EmailWriterOptions? options = null, CancellationToken cancellationToken = default) #

Asynchronously saves the archive to a caller-owned stream.

Parameters

stream System.IO.Stream required
options OfficeIMO.Email.EmailWriterOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

Task<EmailWriteResult>
public byte[] ToBytes(EmailWriterOptions? options = null) #

Serializes the archive to deterministic MHTML bytes.

Parameters

options OfficeIMO.Email.EmailWriterOptions? = null optional

Returns

byte[]

Properties

public HtmlConversionDocument HtmlDocument { get; } #

Parsed HTML root document.

public string Html { get; } #

Original HTML root source.

public IReadOnlyList<MhtmlResource> Resources { get; } #

Decoded related resources in archive order.

public string? ContentLocation { get; } #

Root content location, when declared.

public string? RootContentId { get; } #

Root Content-ID without angle brackets, when declared.

public string? Subject { get; } #

Optional archive subject.

public Uri BaseUri { get; } #

Base URI used for HTML and related-resource resolution.

public IReadOnlyList<EmailDiagnostic> MimeDiagnostics { get; } #

Diagnostics produced by the shared bounded MIME reader.