Free Support Forum - aspose.com

EML inline attachment on forwarded email

aspose-ticket.zip (4.1 KB)
I have a forwarded email where the original email has an attachment. I can use the MapiMessage API to get the attachments. I can see the attachment in the AttachmentCollection of the email. However, when using the algorithm defined here – it’s returning true–indicating it’s an inline attachment. Outlook seems to “promote” this attachment to appear as if it’s an attachment of the received email. I’m attempting to mimic similar behaviour to Outlook in this case. I’m curious if there there is a Mapi property I should be checking in the isInlineAttachment function in addition to the current implementation. Any guidance or help would be appreciated. I’m included a condensed Java test to reproduce the example and expectation. I’ve also included an example email to reproduce the forwarded email with an attachment. I’m using Aspose Email 18.6 on JRE 1.8.0_181.

@tucker.barbour

We have tested your code using Aspose.Email for Java 18.9 and found that the attachment is a regular attachment not an inline attachment.
You may use the following code sample to check with this:

EmlLoadOptions loadOptions = new EmlLoadOptions();
try (InputStream stream = Files.newInputStream(Paths.get("D:\\forwarded-email.eml"))) {
     MapiMessage mapiMessage = MapiMessage.load(stream, loadOptions);
     for (MapiAttachment mapiAttachment : mapiMessage.getAttachments()) {
    	if (!isInlineAttachment(mapiAttachment, mapiMessage.getBodyType())) {
    	   System.out.println("Inline : " +mapiAttachment.getDisplayName());
        }
    	else
    	{
    	    	System.out.println("Regular : " + mapiAttachment.getDisplayName());
        }
    }
}

Thank you for the quick reply. I’ve upgraded to Aspose Email 18.9 for testing but I’m still seeing the same issues. The text attachment is actually and should be considered a regular attachment. However, isInlineAttachment still is returning true. I believe the logic provided in the previous response is backwards. We are printing “Inline” if the isInlineAttachment returns false since we are negating the results in the if statement. It should read

if (isInlineAttachment(mapiAttachment, mapiMessage.getBodyType()) { // Removed '!' operator
  System.out.println("Inline");
} else {
  System.out.println("regular");

}

With this change you should see “Inline” printed instead of “regular”.

After inspecting the MapiProperties of the MapiMessage, I can confirm the algorithm correctly returns true based on the MapiProperties of the MapiMessage. Walking through the isInlineAttachment algorithm:

The message has an HTML body.

} else if (messageBodyType == BodyContentType.Html) { 

The PR_ATTACH_FLAGS (0x37140003) returns 300000004 which has the attRenderedInBody (0x00000004) bit set.

    if (attachment.getProperties().containsKey(0x37140003)) {                                                                                                                          
      long attachFlagsValue = attachment.getPropertyLong(0x37140003);                                                                                                                  
      if ((attachFlagsValue & 0x00000004) == 0x00000004) {

The PR_ATTACH_CONTENT_ID is also set.

          if (attachment.getProperties().containsKey(MapiPropertyTag.PR_ATTACH_CONTENT_ID)                                                                                               
            || attachment.getProperties().containsKey(MapiPropertyTag.PR_ATTACH_CONTENT_ID_W)) { 

With all these true, the isInlineAttachment algorithm will return true.

        return true;                                                                                                                                                                 
      }

Is it possible that there’s some kind of conversion issue as we are converting an EML file into a MapiMessage prior to testing for attachments? I’m currently exploring additional MapiProperties that might be included in the algorithm to correctly identify the attachment as a regular attachment. Let me know if I should provide additional information. Any guidance would be appreciated.

@tucker.barbour

Thank you for your feedback.
Yes you were right in this regard. We have traced the issue and updated the code sample. Please use the IsInlineAttachment method code provided at this link:
https://docs.aspose.com/display/emailjava/Differentiate+between+Inline+and+Regular+Attachments

While calling this method, please use the code sample given below:

for (int i = 0; i < attachments.size(); i++)
{
	MapiAttachment attachment = (MapiAttachment)attachments.get(i);
	if (IsInlineAttachment(attachment,mapiMessage))
	{
		System.out.println(attachment.getLongFileName() + " is inline attachment");
    }
    else
    {
		System.out.println(attachment.getLongFileName() + " is regular attachment");
    }
}

Thank you for the reply. I have adjusted our implementation based on the feedback and I’m now seeing the expected results.

@tucker.barbour

We are glad to know that your issue is resolved. You are always welcome and please feel free to write us if you have any query in future.