Differentiating between Inline and Regular Attachments

We use your recommended method to detect inline attachments in HTML emails

We have noticed that Outlook does not use the property 0x3716001F with value ‘inline’

or the test
if ((att.Properties.ContainsKey(0x3716001F) && att.GetPropertyString(0x3716001F) == “inline”)
|| (att.Properties.ContainsKey(0x3716001E) && att.GetPropertyString(0x3716001E) == “inline”))
{
return true;
}

to determine if an email is an inline attachment, but rather displays emails with this property
as attachments.

Do you have any additional guidance on the best technique to differentiate between Inline and Regular Attachments and/or emulate Outlook’s behaviour.

Thanks!

@PeteLee,

Please provide a sample file so that we can reproduce the issue and assist you further.

Hello, this is a sample email that when loaded with Outlook shows 2 standard attachments
https://www.dropbox.com/s/wumq7walaf3f1bu/not-inline-image.msg?dl=0

The email has property 0x3716001F with value ‘inline’

So using your example, we classify the attachments as inline

@PeteLee,

An investigation has been logged in our issue tracking system as EMAILNET-39110 to look at your specific scenario. We will update you here as soon as we have additional information.

@PeteLee,

We have investigated this and found that there is no standard way to detect attachments in MSG file. It seems that in your case, the problem arises due to the empty email body. We can update our function to address this. The updated function is given below.

public static bool IsInlineAttachment(MapiAttachment att, MapiMessage msg)
{
    switch (msg.BodyType)
    {
        case BodyContentType.PlainText:
            // ignore indications for plain text messages
            return false;

        case BodyContentType.Html:

            // check the PidTagAttachFlags property
            if (att.Properties.ContainsKey(0x37140003))
            {
                long? attachFlagsValue = att.GetPropertyLong(0x37140003);
                if (attachFlagsValue != null && (attachFlagsValue & 0x00000004) == 0x00000004)
                {
                    // check PidTagAttachContentId property
                    if (att.Properties.ContainsKey(MapiPropertyTag.PR_ATTACH_CONTENT_ID) ||
                        att.Properties.ContainsKey(MapiPropertyTag.PR_ATTACH_CONTENT_ID_W))
                    {
                        string contentId = att.Properties.ContainsKey(MapiPropertyTag.PR_ATTACH_CONTENT_ID)
                            ? att.Properties[MapiPropertyTag.PR_ATTACH_CONTENT_ID].GetString()
                            : att.Properties[MapiPropertyTag.PR_ATTACH_CONTENT_ID_W].GetString();
                        if (msg.BodyHtml.Contains(contentId))
                        {
                            return true;
                        }
                    }
                    // check PidTagAttachContentLocation property
                    if (att.Properties.ContainsKey(0x3713001E) ||
                        att.Properties.ContainsKey(0x3713001F))
                    {
                        return true;
                    }
                }
                else if ((att.Properties.ContainsKey(0x3716001F) && att.GetPropertyString(0x3716001F) == "inline")
                    || (att.Properties.ContainsKey(0x3716001E) && att.GetPropertyString(0x3716001E) == "inline"))
                {
                    return true;
                }
            }

            return false;

        case BodyContentType.Rtf:

            // If the body is RTF, then all OLE attachments are inline attachments.
            // OLE attachments have 0x00000006 for the value of the PidTagAttachMethod property
            if (att.Properties.ContainsKey(MapiPropertyTag.PR_ATTACH_METHOD))
            {
                return att.GetPropertyLong(MapiPropertyTag.PR_ATTACH_METHOD) == 0x00000006;
            }
            return false;
        default:
            throw new ArgumentOutOfRangeException();
    }
}

We hope that this resolved the issue. Please do not hesitate to reach us if additional information is required.