We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Value for the header 924057603(PR_ATTACH_FLAGS) is not properly populated

Few months ago we raised an issue with aspose: Special characters breaking in appointments
To which a solution was provided in 20.12 version.

When we made the upgrade of aspose version from 20.9 to 20.12, the intended issue was solved, but we observed another issue.
The code is not populating properly the value for the header id: 924057603 in MapiMessage for inline attachment.
For the previous version (Aspose 20.9) the value for this header was obtained as 4(in case of Inline attachments). But with the upgrade version the value for the same header is coming out to be 0(inline or not).

On gathering more knowledge about this header we found out for inline attachment the value for this header should be 4.

I am providing an end-to-end working code for your verification.
To run it:

  1. Download the zip,
  2. decompress it
  3. navigate inside the directory and run.
    mvn install
  4. The code will run at first build. Go to the pom and upgrade the version of aspose to 20.12 from 20.9
  5. Run the above maven command. The code should fail.

aspose-test.zip (99.7 KB)

Thank you for the issue description. To my regret, we cannot reproduce the problem because the next details are unknown to us:

  • javax.mail v1.4.2.gr17 artifact
  • ResettableSharedFileInputStream class

Could you share a standalone project with a simple code example for investigating the issue, please?

Sorry for that…
Please try the below zip.
aspose-test.zip (100.1 KB)

Thank you for the project example. I have reproduced the problem and got the same results with Aspose.Email 21.1 as well. I have logged the issue in our tracking system with ID EMAILJAVA-34792. Our development team will investigate it. You will be notified when it is fixed.

You should use LinkedResource class instead of Attachment class in the case of Inline Resource as below:

try (InputStream is = part.getInputStream()) {
    String[] contentId = part.getHeader("content-id");
    if (contentId != null && contentId.length > 0) {
        LinkedResource attachment = new LinkedResource(is);
        attachment.setContentType(new ContentType(part.getContentType()));

    } else {
        Attachment attachment = new Attachment(is, part.getFileName());
        attachment.setContentType(new ContentType(part.getContentType()));


API Reference: LinkedResource Class

Ok. We will try implying this and let you know

I did try the solution you proposed.
The PR_ATTACH_FLAG seem to be getting populated properly…
Is there a way I can set the fileName or display name of the linkedResource attachment…??(Like the normal attachment)

The file name is set in the next code line:

attachment.setContentType(new ContentType(part.getContentType()));

LinkedResource class does not have a file name field. ContentType object contains the file name. You can use it through getName and setName methods (API Reference: ContentType class).
You should also set content type data entirely instead of using “application/octet-stream” value.

Hello Andrey,
I did try setName for contentType.
But still the file name is not getting populated properly.

The issue seems to be related to this:

It seems the issue was resolved, but I am not sure why are we experiencing the same thing again…

Below is how we are populating. Please let us know if this is not the proper way:

     String contentId = getFirstHeader(part, CONTENT_ID);
        if(!StringUtils.isBlank(contentId)) {
            LinkedResource attachment = new LinkedResource(is);
            attachment.setContentType(new com.aspose.email.ContentType(part.getContentType()));
        }else {
            Attachment attachment = new Attachment(is, fileName, strType);

I verified the setName method and found no problems. To my regret, I cannot verify your code snippet that contains unknown symbols. Could you please share a simple standalone project that can be used to investigate the issue? Please also specify or describe what is wrong.

Please find my new project(aspose-test_2.zip)
To execute the test class, follow the same process as mentioned in the first message of this thread.

You will find the test case is failing because the expected fileName is b.png but the filename generated by MapiMessage.fromMailMessage is image001.png

The expected output is that MapiMessage.fromMailMessage should also generate the fileName to be b.png.
Let me know if we are missing something.

aspose-test_2.zip (17.7 KB)

I investigated the issue and got the same results. The additional information has been sent to our developers. I will let you know about any progress. Thank you for your patience.

Our developers are working on the issue. Also, you should handle “text/plain” and “text/html” parts properly:

String contentString = new String(IOUtils.toByteArray(part.getInputStream()),Charset.forName("UTF-8"));
if (part.getContentType().toLowerCase().startsWith("multipart/")) {
    parseMessage(part, mailMessage, fileName);
} else if (part.getContentType().toLowerCase().startsWith("text/plain")) {
    AlternateView view = AlternateView.createAlternateViewFromString(contentString,
            Charset.forName("UTF-8"), "text/plain");
} else if (part.getContentType().toLowerCase().startsWith("text/html")) {
    AlternateView view = AlternateView.createAlternateViewFromString(contentString,
            Charset.forName("UTF-8"), "text/html");
} else {

Thank you for that information.
But even with these changes, the code doesnt yield the expected fileName from MapiMessage.

The fix for the file name issue will be released with Aspose.Email 21.2 for Java.

Thank you for the update.
Any ETA of when can we expect the release??

Aspose.Email 21.2 for Java will be released next week (2021/W09).

I noticed the new release 21.2 for Java is done.
Even after using this version, I am facing the same problem.

Thank you for your remarks. I verified it and received the same results. I have sent your information to our development team. Thank you for your patience.

A LinkedResource.getContentDisposition method has been added to modify Content-Disposition header. It will be released with Aspose.Email 21.3, but you can use this method with Aspose.Email 21.2.1 now.
Code sample for your purposes:

LinkedResource attachment = new LinkedResource(is);
attachment.setContentType(new ContentType(part.getContentType()));