0 votes

I'm attempting to validate an opaque signed .msg file, described in https://msdn.microsoft.com/en-us/library/cc433474%28v=exchg.80%29.aspx

Here's my current code to load the file:
MailFactory mailFactory = new MailFactory();
var mail = mailFactory.CreateMail(buffer);

It seems that file does not get parsed correctly. Despite it beeing signed, IsSigned property is false and Text property contains invalid data, including headers of various parts.

Here's the file, I've been using for testing:
https://www.dropbox.com/s/ec9krjjgk14oy7z/RE%20mail%20d.o.o..msg?dl=0

by
retagged by

1 Answer

0 votes
 
Best answer

[Edit]

The latest version of Mail.dll fully supports Clear-Signed, Opaque-Signed and Encrypted S/MIME msg messages.

string fileName = @"Digitally signed_RE mail d.o.o..msg");

using (MsgConverter converter = new MsgConverter(fileName))
{
    Msg2IMailConfiguration configuration = new Msg2IMailConfiguration 
    {
        SMIMEConfiguration = {ExtractSignedAutomatically = false}
    };

    IMail email = converter.CreateMessage(configuration);
    Assert.AreEqual("RE: mail d.o.o.", email.Subject);

    Assert.AreEqual(null, email.HtmlData);
    Assert.AreEqual(null, email.TextData);

    Assert.AreEqual(true, email.IsSigned);
    Assert.AreEqual(true, email.NeedsSignedExtraction);

    IMail extracted = email.ExtractSigned();

    Assert.AreEqual(null, extracted.Subject);
    StringAssert.StartsWith("Uf. Možno.", extracted.Text);
    StringAssert.StartsWith("<html xmlns:", extracted.Html);

    extracted.CheckSignature(true);
}

At this point this is an expected behavior.

The problem is that msg file format destroys MIME structure completely. Parts that should be treated as document root are converted to .msg-file's attachments. Thus it is nearly impossible to rebuild the correct MIME structure.

Here's the code that shows how you can process this particular file:

string fileName = "Digitally signed_RE mail d.o.o..msg";

using (MsgConverter converter = new MsgConverter(fileName))
{
    IMail email = converter.CreateMessage();
    Assert.AreEqual("RE: mail d.o.o.", email.Subject);

    MimePkcs7Mime pkcs7Mime = (MimePkcs7Mime)email.Attachments
        .Find(x => x is MimePkcs7Mime);

    email = new MailFactory().CreateMail(pkcs7Mime);

    Assert.AreEqual(true, email.IsSigned);
    Assert.AreEqual(true, email.NeedsSignedExtraction);

    IMail extracted = email.ExtractSigned();
    StringAssert.StartsWith("Uf. Možno.", extracted.Text);
    StringAssert.StartsWith("<html xmlns:", extracted.Html);

    extracted.CheckSignature(true);
}

We'll try to improve Mail.dll to handle such files better.

by (298k points)
selected by
...