When reading from a PST file a MapiMessage that has an embedded message that is clear signed, and then converting the message to EML, the resulting embedded message will have an incorrect content-type.
To reproduce:
Create a PST file with message that has an embedded message which is clear signed. (I attach a sample PST file)
Use this code:
using (var store = PersonalStorage.FromFile("c:\\sample.pst", writable: false))
{
var msg = store.RootFolder.EnumerateMapiMessages().Single();
var mailMessage = msg.ToMailMessage(
new MailConversionOptions
{
ConvertAsTnef = false
});
var tempMemoryStream = new MemoryStream();
mailMessage.Save(
tempMemoryStream,
new EmlSaveOptions(MailMessageSaveType.EmlFormat)
{
MailMessageSaveType = MailMessageSaveType.EmlFormat,
PreserveSignedContent = true
});
File.WriteAllBytes("c:\\result_mime.eml", tempMemoryStream.ToArray());
}
The resulting embedded message content-type looks like this:
I have worked with the sample file shared by you and have been able to observe the issue specified. An issue with ID EMAILNET-39424 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.
We suggest you to please use PreserveEmbeddedMessageFormat = true flag in your application. Please try using following sample code on your end and share with us if there is still an issue.
using (var store = PersonalStorage.FromFile(file.Name, writable: false))
{
var msg = store.RootFolder.EnumerateMapiMessages().Single();
var mailMessage = msg.ToMailMessage(
new MailConversionOptions
{
//this setting ensures correct result for a signed embedded messages
PreserveEmbeddedMessageFormat = true,
ConvertAsTnef = false
});
var tempMemoryStream = new MemoryStream();
mailMessage.Save(
tempMemoryStream,
new EmlSaveOptions(MailMessageSaveType.EmlFormat)
{
MailMessageSaveType = MailMessageSaveType.EmlFormat,
PreserveSignedContent = true
});
File.WriteAllBytes(file.OutName, tempMemoryStream.ToArray());
}
It seems that the issue was partially fixed when using Aspose.Email 19.4, the embedded message looks signed. However, another problem appears, which is that the signature is no longer valid.
Note that the workaround you sent doesn’t make any difference, so basically with or without the workaround you get the same results.
I have observed the comments shared by you and request you to please share the source and generated output having issue that you have generated using workaround method. We will investigate the issue further on our end on provision of requested information.
The source pst and the source code are already attached in the original issue.
I attach the generated output messages. There are two messages, one with the suggested workaround and the other is without the workaround. result_mime_5June2019.zip (9.4 KB)
Can you please use following sample code on your end and share details with us. I also shared my generated result with you for your kind reference. output.zip (16.4 KB)
TestFile file = new TestFile(“sample.pst”, “output.eml”, true);
using (var store = PersonalStorage.FromFile(file.Name, writable: false))
{
var msg = store.RootFolder.EnumerateMapiMessages().Single();
var mailMessage = msg.ToMailMessage(
new MailConversionOptions
{
PreserveEmbeddedMessageFormat = true,
ConvertAsTnef = false
});
var tempMemoryStream = new MemoryStream();
mailMessage.Save(
tempMemoryStream,
new EmlSaveOptions(MailMessageSaveType.EmlFormat)
{
MailMessageSaveType = MailMessageSaveType.EmlFormat,
PreserveSignedContent = true
});
File.WriteAllBytes(file.OutName, tempMemoryStream.ToArray());
}
The problem with this workaround is that the embedded message is no longer an embedded message. The embedded message becomes an attachment that contains an MSG file. This is not considered an embedded message.
Also, If I take the resulting MSG file and convert it to MIME, I get a correctly signed message. This means that this should be easy to fix.