Incorrect rending when making use of MapiConversionOptions


#1

In issue https://forum.aspose.com/t/unable-to-manually-create-a-new-folder-via-outlook-for-a-pst-generated-by-aspose-email/190540/6

I had commented that an email is not rendered correctly when I make use of MapiConversionOptions. You had replied that I need to set MapiMessageFlags.MSGFLAG_HASATTACH to true.

Despite setting the flag does fix the rendering issue, I do not think that just because I am making use of the MapiConversionOptions factory overload I have to now take care of setting the MSGFLAG_HASATTACH. This is an inconsistency is your API and I consider the solution you gave me as a workaround. From a developer perspective I treat this a bug in your SDK. If for example I make use of the MapiConversionOptions.UnicodeFormat, there should be no reason why this should change the behavior of the MSGFLAG_HASATTACH.

What other differences do I need to take care of if I change my method from

var mapiItem = MapiMessage.FromMailMessage(mailMessage);

to

var mapiItem = MapiMessage.FromMailMessage(mailMessage, MapiConversionOptions.UnicodeFormat);

Additionally what is the correct way of handling MSGFLAG_HASATTACH. The below is my workaround

using (var memoryStream = new MemoryStream(mailboxItem.MimeContentBytes))
using (var mailMessage = MailMessage.Load(memoryStream))
using (var mapiItem = MapiMessage.FromMailMessage(mailMessage, MapiConversionOptions.UnicodeFormat))
{
var messageFlags = MapiMessageFlags.MSGFLAG_READ;

if (mailMessage.Attachments.Any() || mailMessage.LinkedResources.Any())
{
	messageFlags = messageFlags | MapiMessageFlags.MSGFLAG_HASATTACH;
}

}

Do you suggest something different?


#2

@BlitzKing,

I have observed your comment and have updated the information in our issue tracking system for issue EMAILNET-39263. I have linked this thread with issue as well so that we may get back to you with feedback as soon as it will be shared.


#3

@BlitzKing,

We have internally investigated the requirement. Actually, MessageFlags is a set of flags and setting MapiMessageFlags.MSGFLAG_READ clear all existing flags.

For example:

mapiMessage.Flags is (MSGFLAG_HASATTACH)
setting flags to MSGFLAG_READ

mapiMessage.SetMessageFlags(MapiMessageFlags.MSGFLAG_READ);

mapiMessage.Flags is (MSGFLAG_READ) but not is (MSGFLAG_HASATTACH | MSGFLAG_READ)

So, if we need to add flag MSGFLAG_READ but not reset we can use

mapiMessage.SetMessageFlags(mapiMessage.Flags | MapiMessageFlags.MSGFLAG_READ);

in this case mapiMessage.Flags is (MSGFLAG_HASATTACH | MSGFLAG_READ)
MSGFLAG_READ flag added and and previous state not reset

I have described all of this in my previous code example
In the last customer code we need to set Flags in a correct way

using (var memoryStream = new MemoryStream())
using (var mailMessage = MailMessage.Load(memoryStream))
using (var mapiItem = MapiMessage.FromMailMessage(mailMessage, MapiConversionOptions.UnicodeFormat))
{
    mapiItem.SetMessageFlags(mapiItem.Flags | MapiMessageFlags.MSGFLAG_READ);

    /*
    var messageFlags = MapiMessageFlags.MSGFLAG_READ;

    if (mailMessage.Attachments.Any() || mailMessage.LinkedResources.Any())
    {
        messageFlags = messageFlags | MapiMessageFlags.MSGFLAG_HASATTACH;
    }
    */
}

#4

Ok apologies then. I will test out.


#5

@BlitzKing,

Thank you for your feedback.