RtfEncapsulation Class
Extracts the HTML and plain text bodies that Outlook encapsulates in RTF bodies, and encapsulates bodies in RTF ([MS-OXRTFEX]). Outlook often stores the HTML body of a message only in its compressed RTF body.
public static class RtfEncapsulationExample
var rtf = RtfEncapsulation.EncapsulateHtml("<p>Hello {world}</p>\r\n");
Assert.Equal(RtfEncapsulationFormat.Html, RtfEncapsulation.GetFormat(rtf));
Assert.Equal("<p>Hello {world}</p>\r\n", RtfEncapsulation.Decapsulate(rtf));
// An RTF body that does not encapsulate another format
Assert.Equal(RtfEncapsulationFormat.None, RtfEncapsulation.GetFormat(@"{\rtf1\ansi Hello}"u8));
Assert.Null(RtfEncapsulation.Decapsulate(@"{\rtf1\ansi Hello}"u8));Methods
| Name | Description |
|---|---|
| Decapsulate(ReadOnlySpan<byte>) | Extracts the HTML or the plain text an RTF body encapsulates. |
| EncapsulateHtml(string) | Encapsulates an HTML body in RTF, which RtfEncapsulation.Decapsulate extracts unchanged. |
| EncapsulateText(string) | Encapsulates a plain text body in RTF, which RtfEncapsulation.Decapsulate extracts unchanged. |
| GetFormat(ReadOnlySpan<byte>) | Returns the format an RTF body encapsulates, from the control words of its header. |
Decapsulate(ReadOnlySpan<byte>)
RtfEncapsulation.csExtracts the HTML or the plain text an RTF body encapsulates.
public static string? Decapsulate(ReadOnlySpan<byte> rtf)Parameters
rtfReadOnlySpan<byte>- The RTF, decompressed (see
MapiMessage.GetRtfBody).
Returns
string? The HTML (RtfEncapsulationFormat.Html) or the plain text (RtfEncapsulationFormat.Text), or null when the RTF does not encapsulate another format.
EncapsulateHtml(string)
RtfEncapsulation.csEncapsulates an HTML body in RTF, which RtfEncapsulation.Decapsulate extracts unchanged.
Parameters
htmlstring- The HTML.
Returns
byte[] The RTF. It contains only the encapsulated HTML: a reader that does not support the encapsulation shows an empty document.
EncapsulateText(string)
RtfEncapsulation.csEncapsulates a plain text body in RTF, which RtfEncapsulation.Decapsulate extracts unchanged.
GetFormat(ReadOnlySpan<byte>)
RtfEncapsulation.csReturns the format an RTF body encapsulates, from the control words of its header.
public static RtfEncapsulationFormat GetFormat(ReadOnlySpan<byte> rtf)Parameters
rtfReadOnlySpan<byte>- The RTF, decompressed (see
MapiMessage.GetRtfBody).
Returns
RtfEncapsulationFormat The format of the encapsulated body, or RtfEncapsulationFormat.None for an RTF body.