Skip to content

Inline images not detected for MSG files generated by New Outlook / Outlook Online #668

Closed

Description

@rogersteblerbsi

Summary

Inline images are not detected when parsing .msg files generated by New Outlook (and possibly Outlook Online).

After investigating the issue, it appears that the exported MSG:

  1. Does not contain an RTF body.
  2. Contains attachment Content-ID properties with trailing NUL (\u0000) characters.
  3. Relies on HTML cid: references for inline image detection.
  4. Fails to match attachments to the HTML because the Content-ID value contains the trailing NUL while the HTML reference does not.

As a result, inline images are treated as normal attachments instead of embedded images.


Environment

  • Simple Java Mail: 9.1.0
  • Source message: .msg exported/downloaded from New Outlook / Outlook Online

Potential fixes

Based on my investigation of the attached test.msg, I believe the following changes would resolve the issue.

1. Sanitize string values in OutlookMessageProperty

It appears that some string-based properties contain a trailing NUL character (\u0000).

For example, attachment Content-ID values may be exposed as:

177438a0-381f-49ff-a81f-57404ccdb560\u0000

while the HTML contains:

cid:177438a0-381f-49ff-a81f-57404ccdb560

As a result, fetchCIDMap() is unable to match the attachment to the corresponding HTML cid: reference.

It may be beneficial to normalize string values when creating or reading the properties, for example by trimming trailing NUL characters.

2. Use the full HTML body for CID matching

fetchCIDMap() currently performs CID matching against:

final String html = getConvertedBodyHTML();

For the attached MSG generated by New Outlook, there is no RTF body and inline image detection appears to depend entirely on HTML-based CID resolution.

It may therefore be more reliable to also inspect the full getBodyHTML() when resolving inline images rather than relying solely on getConvertedBodyHTML().

This would provide a fallback for MSG files generated by New Outlook / Outlook Online that rely exclusively on HTML content.

Why I think these changes would help

The attached test.msg was created using New Outlook and contains:

  • Subject: test
  • Body: the text Hello World followed by an inline image
  • Attachment: test.pdf

When parsed, the PDF attachment is correctly detected, but the inline image is not recognized as an embedded image and instead appears as a regular attachment.

My suspicion is that this is caused by a combination of:

  1. Missing RTF content.
  2. CID matching based only on getConvertedBodyHTML().
  3. Content-ID values containing trailing NUL characters.

Activity

  1. bbottema commented on Aug 4, 2026

    @bbottema
    Owner

    Fixed upstream in bbottema/outlook-message-parser#90 and released in org.simplejavamail:outlook-message-parser:1.16.2.

    The parser now:

    • uses native HTML for CID matching when present, with RTF-converted HTML as the fallback;
    • removes trailing U+0000 terminators from string-valued MAPI properties without trimming meaningful whitespace or changing binary values;
    • includes the exact reported MSG as a regression fixture, verifying the PNG is embedded and only test.pdf remains a true attachment.

    The existing suite missed this because its CID-positive fixtures were all RTF-backed and had clean metadata; it had neither a native-HTML-only New Outlook fixture nor a unit contract for MAPI string terminators.

    Simple Java Mail users can override the parser dependency to 1.16.2 immediately; the next Simple Java Mail dependency update can consume this patch normally. Closing as resolved upstream.

  2. bbottema commented on Aug 4, 2026

    @bbottema
    Owner

    Thanks for reporting! Will release soon.

  3. rogersteblerbsi commented on Aug 4, 2026

    @rogersteblerbsi
    Author

    Wow, that was fast 😄 Thanks for the fix! I've tested it and can confirm it's working correctly now.

  4. added this to the 9.1.3 milestone on Aug 4, 2026
  5. bbottema commented on Aug 4, 2026

    @bbottema
    Owner

    Available now in Simple Java Mail 9.1.3 and on Maven Central. This release consumes outlook-message-parser 1.16.2, including the reported New Outlook .msg regression fixture and fix.

  6. bbottema commented on Aug 4, 2026

    @bbottema
    Owner

    Wow, that was fast 😄 Thanks for the fix! I've tested it and can confirm it's working correctly now.

    By the power of Greysk.... no wait. By our powers combined, Captain Pl... no also not. Hold on. By the powers of my coding agents combined, I have the pow.... meh

    Anyway, yep. Codex with Remote is pretty awesome as a fast response service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions