Emails with attached emails with special characters get renamed and are saved without eml extension

XMLWordPrintable

    • 1
    • Severity 3 - Minor

      Issue Summary

      When an inbound email processed by a JSM mail handler contains an attached .eml file whose filename includes special characters (e.g., :, ü, ö, !, ?), Jira's replaceInvalidChars method renames the file to strip invalid characters but drops the .eml file extension in the process. The attachment is then stored without an extension, causing it to be unrecognizable as an email message file when downloaded.

      This is a recurrence of previously closed https://jira.atlassian.com/browse/JRACLOUD-81538 and https://jira.atlassian.com/browse/JRACLOUD-34220, now reproducible on a customer site with German-language email subjects.

      Affected site: mediengruppe-chbeck.atlassian.net
      Support ticket: PCS-3798828

      Steps to Reproduce

      Configure a JSM project with an email channel (mail handler) that creates/comments on tickets from inbound emails.

      Send an email to the mail handler address with a .eml file attached. The .eml file's subject (used as filename) must contain special/invalid characters — e.g., {}EXTERN{} AW: EILT -Kündigung für zwei Zugänge zu Plog/Wiedow Bundesbeamtengesetz !.eml

      The mail handler processes the email and creates a comment with the attachment.

      Jira logs a message: "Renamed attached file: '...' to '...' because it contained invalid character(s)."

      Download the renamed attachment from the Jira ticket.

      Expected Results

      Jira renames the file by replacing invalid characters with _ while preserving the .eml extension:

      {}EXTERN{} AW_ EILT -Kündigung für zwei Zugänge zu Plog_Wiedow Bundesbeamtengesetz !.eml

      → becomes: {}EXTERN{} AW_ EILT -Kündigung für zwei Zugänge zu Plog_Wiedow Bundesbeamtengesetz _.eml

      The file retains its .eml extension and is recognized by the OS/email client upon download.

      Actual Results

      Jira renames the file and strips the .eml extension entirely:

      {}EXTERN{} AW_ EILT -Kündigung für zwei Zugänge zu Plog_Wiedow Bundesbeamtengesetz !.eml

      → becomes: {}EXTERN{} AW_ EILT -Kündigung für zwei Zugänge zu Plog_Wiedow Bundesbeamtengesetz _

      The downloaded file has no extension. Windows identifies it as a generic "Datei" (file) instead of "Microsoft Outlook Email Message (.eml)." The file cannot be opened by an email client without manual intervention.

      Root cause hypothesis: The replaceInvalidChars(String filename, char replacementChar) method replaces characters in INVALID_CHARS =

      {'\\', '/', '"', ':', '?', '*', '<', '|', '>'}

      with _. When the filename ends with a special character immediately before .eml (e.g., ! .eml or the dot itself is affected by adjacent processing), the extension is lost. The method does not appear to protect the file extension portion of the filename during replacement.

      // No exception/stack trace available — this is a logic bug in the rename method.
      // The method replaceInvalidChars strips the extension when the filename
      // contains certain character combinations near the end of the string.
      // Relevant method: replaceInvalidChars(String filename, char replacementChar)
      // INVALID_CHARS =

      {'\\', '/', '"', ':', '?', '*', '<', '|', '>'}

      ;
      // INVALID_CHAR_REPLACEMENT = '_';

      Workaround

      Download the affected attachment from the Jira ticket (it will save without an extension)

      Manually rename the file and append .eml to the filename

      Open the renamed file with your preferred email client (Outlook, Thunderbird, etc.)

      The file content is intact — only the extension/file association is lost.

              Assignee:
              Unassigned
              Reporter:
              Adithyan A
              Votes:
              5 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated: