Skip to content

Provide control over synthetic HTML fallback when converting Outlook (.msg) plain-text emails #979

Closed

Description

@clepet

Thank you again for your hard work on this fantastic E-Mail library.

Context & Current Behavior

When converting an Outlook .msg file via EmailConverter.outlookMsgToEmail(...), SJM checks whether native HTML is available (outlookMessage.getBodyHTML()). If absent, it automatically falls back to converted RTF.

OutlookEmailConverter.java (line 109 in 9.3.9):

builder.withHTMLText(outlookMessage.getBodyHTML() != null ? outlookMessage.getBodyHTML() : outlookMessage.getConvertedBodyHTML());

In Outlook, even pure plain-text emails are internally wrapped in RTF (indicated by \fromtext in the RTF body). When outlookMessage.getConvertedBodyHTML() runs on such an email, it produces synthetic HTML.

While this opinionated fallback is very helpful for standard rendering, it causes issues in downstream processing pipelines (e.g. when HTML sanitizers or strict safety filters strip inline styles, turning plain-text emails into an unreadable single line of text).

Problem

Currently, callers cannot opt out of this synthetic HTML generation, nor can they determine whether the original message was originally plain text without parsing the entire .msg file a second time with OutlookMessageParser (which incurs significant memory and CPU overhead for large messages with attachments).

OutlookEmailConversionResult provides OutlookMessageData, but it does not expose the raw RTF body or an indicator of whether the source message was plain text.

Proposed Solutions / Discussion

Option 1: Expose isPlainText() or raw RTF in OutlookMessageData

Add a method boolean isPlainText() (e.g. checking if bodyRTF is absent or contains the "\fromtext" control word) to OutlookMessageData.

Benefit: Callers can inspect result.getOutlookMessageData().isPlainText() and call builder.clearHTMLText() if desired, keeping backward compatibility 100% intact.

Option 2: Configuration option via SimpleJavaMailConfig

Introduce a configuration property (e.g. simplejavamail.outlook.fallback_to_converted_html=true|false or a parameter in EmailConverter) to allow skipping the synthetic HTML conversion when no native HTML body exists.

Activity

  1. added this to the 9.3.10 milestone on Nov 9, 2026
  2. bbottema commented on Nov 9, 2026

    @bbottema
    Owner

    Thanks for explaining the use case. For 9.3.10, I plan to add getBodyHTML() and getBodyRTF() to OutlookMessageData, so you can inspect the native MSG bodies from the same conversion. The HTML value will exclude the RTF fallback; the RTF value will be the reader's decompressed/decoded text. The existing best-effort HTML fallback stays as it is.

    That gives your application the source information for its own policy, followed by result.getEmailBuilder().clearHTMLText() when plain-text output is appropriate. Missing native HTML alone won't mean the message was originally plain text: RTF can also contain original HTML or rich text. These values describe the native MSG, so they can differ from content selected later through S/MIME processing.

    For 10.0.0, a fuller inspection API is planned, along these lines:

    // Planned for 10.0.0; not an available 9.x API.
    email.getInspection().getHTMLText();

    The idea is to describe the origin, derivation and protection of the HTML actually returned by that Email, including content selected from protected or nested messages. Those result types are still under design.

  3. clepet commented on Nov 9, 2026

    @clepet
    Author

    Thanks a lot for the quick feedback and for including this in 9.3.10!

    Exposing getBodyHTML() and getBodyRTF() on OutlookMessageData solves our issue completely. It gives us all the info we need to apply our policy via result.getEmailBuilder().clearHTMLText() without having to parse the file twice.

    Also, thanks for the helpful clarification regarding rich-text RTF vs. plain-text RTF.

    Looking forward to the 9.3.10 release!

  4. bbottema commented on Nov 9, 2026

    @bbottema
    Owner
    OutlookEmailConversionResult result =
        EmailConverter.outlookMsgToEmailBuilderWithOutlookData(msgFile);
    
    OutlookMessageData source = result.getOutlookMessageData();
    String nativeHtml = source.getBodyHTML();
    String rtf = source.getBodyRTF();
    
    Email email = result.buildEmail();

    Available in 9.3.10. nativeHtml contains the native MSG HTML without the RTF fallback, and rtf contains the reader's decompressed and decoded RTF text. A missing or uncaptured value is null; an explicitly empty value stays empty. Existing HTML conversion and fallback behavior stay as they are.

    For an ordinary unprotected MSG, once your application has selected plain-text output, you can use result.getEmailBuilder().clearHTMLText().buildEmail().

    The source-body addition and usage guide describe the 9.x API.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions