Suppose there is a message in a PST and that message has an embedded message as an attachment.
I want to read the message bodies of the embedded message exactly as they are in the PST for archiving purposes. I do not want to have any message bodies synthesized for it.
I am able to do this on stand-alone messages (i.e. not embedded messages) by using PersonalStorage.ExtractProperty to read message body properties, rather than loading the messages as MapiMessage objects.
However, I can’t find a way to read the bodies of an embedded message in a way that avoids message bodies being synthesized.
Is there a way to know if a message body has been synthesized from Aspose or a way to avoid having message bodies synthesized for embedded messages?
I realize that message body synthesis is intentional behavior but I’m looking for a way to work around it so that I can archive the message bodies exactly as they are.
Below is an Xunit test demonstrating that PersonalStorage.ExtractProperty allows messages bodies to be read while avoiding synthesized bodies on regular messages. I’m looking for a way to do something similar with embedded messages.
[Fact]
public void Aspose_synthesizes_bodies_when_only_pr_html_is_set()
{
string html = "My PR_HTML message body!";
// create a message and only set the body with PR_HTML
MapiMessage before = new(OutlookMessageFormat.Unicode);
before.SetProperty(KnownPropertyList.TagHtml, Encoding.UTF8.GetBytes(html));
// save it to a PST
MemoryStream ms = new();
using (PersonalStorage pst = PersonalStorage.Create(ms, FileFormatVersion.Unicode, true))
{
pst.RootFolder.AddMessage(before);
}
ms.Position = 0;
// re-open the pst
MapiMessage after;
using (PersonalStorage pst = PersonalStorage.FromStream(ms, new PersonalStorageLoadOptions { LeaveStreamOpen = true }))
{
MessageInfo message = pst.RootFolder.EnumerateMessages().Single();
// use PersonalStorage.ExtractProperty bodies. this seems to avoid message body synthesis.
// PR_HTML is unchanged
var tagHtml = pst.ExtractProperty(message.EntryId, KnownPropertyList.TagHtml.Tag);
Assert.NotNull(tagHtml);
Assert.Equal(html, Encoding.UTF8.GetString(tagHtml.Data));
// **** NO SYNTHESIZED BODIES *****
Assert.Null(pst.ExtractProperty(message.EntryId, KnownPropertyList.BodyHtml.Tag));
Assert.Null(pst.ExtractProperty(message.EntryId, KnownPropertyList.Body.Tag));
Assert.Null(pst.ExtractProperty(message.EntryId, KnownPropertyList.RtfCompressed.Tag));
// extract the message as a MapiMessage instance
after = pst.ExtractMessage(message);
}
// check that PR_HTML is still set
var tagHtmlAfter = after.Properties[KnownPropertyList.TagHtml];
Assert.NotNull(tagHtmlAfter);
// PR_HTML is unchanged
Assert.Equal(html, Encoding.UTF8.GetString(tagHtmlAfter.Data));
Assert.Equal(BodyContentType.Html, after.BodyType);
// PR_BODY_HTML is still null
Assert.Null(after.Properties[KnownPropertyList.BodyHtml]);
// ***** MapiMessage has synthesized bodies *****
Assert.NotNull(after.Properties[KnownPropertyList.RtfCompressed]);
Assert.NotNull(after.Properties[KnownPropertyList.Body]);
}