Extended Properties defined on decrypting EmailMessage

0 votes
asked Jan 15, 2014 by Naresh (150 points)
edited Jan 15, 2014

Hello all,

We are using Rebex utils for decryption.

Our scenario:

  1. Download the email message from Outlook EWS
  2. Decrypt the email
  3. Preserver extended properties (user properties) defined on original item.

Following code is performing the decryption.

// create an instance of MailMessage
var message = new Rebex.Mail.MailMessage { Silent = false };

// load the message
message.Load(ewsmessage.MimeContent.Content);

But I am loosing the user defined properties on the original email message.

Please help me.

Applies to: Rebex Secure Mail
commented Jan 15, 2014 by Lukas Pokorny (100,910 points)
edited Jan 15, 2014

I am currently looking into this. I assume that the message in message.MimeContent.Content is actually supposed to be an instance of an EWS message object (and not an instance of Rebex MailMessage object), is that correct?

commented Jan 15, 2014 by Naresh (150 points)
edited Jan 15, 2014

Thanks for your reply Lukas. Sorry it was a typo. It's an EmailMessage object from the EWS.

1 Answer

0 votes
answered Jan 15, 2014 by Lukas Pokorny (100,910 points)
edited Jan 15, 2014

It looks like the user defined properties are not actually present in EmailMessage .MimeContent.Content. They lack corresponding counterparts in the MIME standard and are possibly stored beside the MIME content in Exchange, not as a part of it.

To make sure this is indeed the case, try saving the MIME content into a file:

    System.IO.File.WriteAllBytes("message.eml", ewsmessage.MimeContent.Content);

And open it with Notepad or other simple text editor to see what's actually inside. Are there any of your extended properties?

If not, you will have to write a bit of custom code to convert them yourself. MailMessage doesn't have any extended properties (because MIME lacks support for them), but you might use custom message headers to store them, for example. A code similar to this might to the trick:

    // create an instance of MailMessage
    var message = new Rebex.Mail.MailMessage { Silent = false };

    // load the message
    message.Load(ewsmessage.MimeContent.Content);

    // convert extended headers
    foreach (var property in ewsmessage.ExtendedProperties)
    {
        string headerName = "X-Exchange-" + property.PropertyDefinition.Name;
        string headerValue = property.Value.ToString();

        message.Headers.Add(headerName, headerValue);
    }

(Please note that this assumes that property.PropertyDefinition.Name is always defined and has a MIME-friendly name, and that property.Value.ToString() returns a usable string. Some additional work might be needed to make it suitable for your scenario.)

commented Jan 15, 2014 by Naresh (150 points)
edited Jan 15, 2014

Thanks Lukas. I will try this and update you. Once again thanks for your quick response.

...