Aspose is detecting image attachments in a MSG that do not have any regular attachments

Hello,

If a MSG has any attachments my goal is to extract them and save them in a given location. But there is a problema with some MSG files that do not have any attachments but the Aspose.Email still detects several imagens as attachments and the ways to verify if those are inline attachments or embedded to not work.
I tried with IsEmbeddedMessage property but it returns false:

//Create an instance of MailMessage and load an email file
mailMsg = Aspose.Email.MailMessage.Load(fileStream);

//Get all the email file attachments
foreach (Aspose.Email.Attachment attachment in mailMsg.Attachments)
{
bool isEmbeddedAttachment = attachment.IsEmbeddedMessage;
if (isEmbeddedAttachment)
continue;

//Save the attachment file
attachment.Save(path);

}

Also tried with Aspose.Email.Mapi.MapiAttachment using the “IsInlineAttachment” example provided by you in your documentation:
https://docs.aspose.com/email/net/differentiating-between-inline-and-regular-attachments/
also with the same result unfortunately.

This problem can also be seen using your online converter (MSG to PDF), you will notice many imagens will show that are not present in the original MSG not even present as attachments:
https://products.aspose.app/email/conversion/msg-to-pdf

I provide this msg file that you will be able to reproduce the problem:
MSG without attachements.zip (133.9 KB)

This problem do not happen in older Aspose.Email versions, can you please fix it?

Thanks

@duvidasAspose

We have logged this problem in our issue tracking system as EMAILNET-40730. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@duvidasAspose

We have closed the issue EMAILNET-40730 as ‘Not a Bug’. Please use following code example to achieve your requirement.

var message = MapiMessage.Load("MSG without attachements.msg");
var attachments = message.Attachments;
var count = attachments.Count;
var type = message.BodyType;

for (int i = 0; i < attachments.Count; i++)
{
    var attachment = attachments[i];
    if (IsInlineAttachment(attachment, type))
    {
        count--;
    }
    else
    {

    }
}

Assert.AreEqual(0, count);
        internal static bool IsInlineAttachment(MapiAttachment att, BodyContentType messageBodyType)
        {
switch (messageBodyType)
{
    case BodyContentType.PlainText:
        return false;
    case BodyContentType.Html:
        // check the PidTagAttachFlags property
        if (!att.Properties.ContainsKey(MapiPropertyTag.PR_ATTACH_FLAGS))
        {
return att.GetPropertyString(0x3716001F) == "inline" ||
       att.GetPropertyString(0x3716001E) == "inline";
        }
        else
        {
long? attachFlagsValue = att.GetPropertyLong(MapiPropertyTag.PR_ATTACH_FLAGS);
if ((attachFlagsValue & 0x00000004) != 0x00000004) return false;

// check PidTagAttachContentId property
if (att.Properties.ContainsKey(MapiPropertyTag.PR_ATTACH_CONTENT_ID) ||
    att.Properties.ContainsKey(MapiPropertyTag.PR_ATTACH_CONTENT_ID_W))
{
    return true;
}

// check PidTagAttachContentLocation property
if (att.Properties.ContainsKey(0x3713001E) ||
    att.Properties.ContainsKey(0x3713001F))
{
    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
        return att.GetPropertyLong(MapiPropertyTag.PR_ATTACH_METHOD) == 0x00000006;
}

throw new ArgumentOutOfRangeException("messageBodyType");
        }

Thanks, was able to fix the problem with this work around you provided.
In the future would be great to have a easier way to detect the inline attachments.

@duvidasAspose

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Email, we will be happy to help you.

1 Like