Incorrect content type on reading embeeded message with cleared sign from PST and converting to EML (C# .NET)

Bug description:

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:

  1. Create a PST file with message that has an embedded message which is clear signed. (I attach a sample PST file)

  2. 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:

aspose-error-2503-1.png (8.6 KB)

It is expected to be like this:

aspose-error-2503-2.png (7.3 KB)

When opened in outlook, the message with the wrong content-type will not show as a signed message. Instead a smime.p7s attachment appears.

Sample Attached: sample.zip (25.0 KB)

@bahakh,

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.

Any Updates on this issue ? It has been too long without any fix.

@bahakh,

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.

@bahakh,

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)

@bahakh,

We are working on this issue. We will share good news with you soon.

@bahakh,

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.

@bahakh,

I have observed your comments and we have reopened this issue to further investigate so that we may help you out.

The issues you have found earlier (filed as EMAILNET-39424) have been fixed in this update.