-
Type:
Suggestion
-
Resolution: Won't Fix
-
Component/s: None
NOTE: This suggestion is for JIRA Cloud. Using JIRA Server? See the corresponding suggestion.
Problem Definition
Under some situations, decoding the message subject fails due to an encoding problem with the Mail Client. Given that there are many Mail clients that don't strictly confirm to encoding standards, it would be useful to try and mitigate some use-cases.
A specific example has been detailed below:
Sample Java Application
package com.mimeTest; import javax.mail.MessagingException; import javax.mail.internet.MimeUtility; import javax.mail.internet.ParseException; import java.io.UnsupportedEncodingException; public class Main { public static void main(String[] args) { System.setProperty("mail.mime.decodetext.strict", "false"); try { // Use method similar to JavaMail API (Fails) System.out.println("--- Decoding Using method similar to JavaMail API ---"); System.out.println(getSubject("=?ISO-8859-1?Q?ITSM - REASSIGNMENT: Incident mit Priorit=E4t 3 f=FCr ?=")); // We can test Encoding the text System.out.println("\n\n--- Encoding using JavaMail API ---"); System.out.println(MimeUtility.encodeText("ITSM - REASSIGNMENT: Incident IM1239906 mit Priorität 3 für", "ISO-8859-1","Q")); // Output is: "=?ISO-8859-1?Q?ITSM_-_REASSIGNMENT:_Incident?= =?ISO-8859-1?Q?_IM1239906_mit_Priorit=E4t_3_f=FCr?=" // if we try to decode the above string it passes: System.out.println("\n\n--- Decoding Using Encoded version of string with similar to JavaMail API method---"); System.out.println(getSubject("=?ISO-8859-1?Q?ITSM_-_REASSIGNMENT:_Incident?= =?ISO-8859-1?Q?_IM1239906_mit_Priorit=E4t_3_f=FCr?=")); // A coded workaround would be to use an alternative method to treat the text as a single word System.out.println("\n\n --- Decoding Using alternative method ---"); System.setProperty("mail.mime.decodetext.strict", "false"); System.out.println(MimeUtility.decodeWord("=?ISO-8859-1?Q?ITSM - REASSIGNMENT: Incident mit Priorit=E4t 3 f=FCr ?=")); } catch (Exception e) { throw new RuntimeException(e); } } public static String getSubject(String s) throws MessagingException { String rawvalue = s; if(rawvalue == null) { return null; } else { try { return MimeUtility.decodeText(MimeUtility.unfold(rawvalue)); } catch (UnsupportedEncodingException var3) { return rawvalue; } } } }
In the above Java application, we work through a few scenarios:
- Decoding Using a method similar to the JavaMail API (https://java.net/projects/javamail/pages/Home) which we use in JIRA.
- Encoding Using JavaMail's MIME utility.
- Decoding the String as encoded by the JavaMail API.
- Decoding using a different method in the API.
Output of sample app
--- Decoding Using method similar to JavaMail API --- =?ISO-8859-1?Q?ITSM - REASSIGNMENT: Incident mit Priorit=E4t 3 f=FCr ?= --- Encoding using JavaMail API --- =?ISO-8859-1?Q?ITSM_-_REASSIGNMENT:_Incident?= =?ISO-8859-1?Q?_IM1239906_mit_Priorit=E4t_3_f=FCr?= --- Decoding Using Encoded version of string with similar to JavaMail API method--- ITSM - REASSIGNMENT: Incident IM1239906 mit Priorität 3 für --- Decoding Using alternative method --- ITSM - REASSIGNMENT: Incident mit Priorität 3 für
Suggested Solution
If the Subject of an Incoming mail message includes encoding syntax, attempt to decode the subject as a 'word' instead of decoding 'text' using the JavaMail API.
Workaround
- Avoid using clients that don't adhere to the expected Mime Encoding syntax
- Replace malformed subject content manually.
- is related to
-
JRASERVER-61607 Attempt alternative methods of Decoding Mail Subject for incoming mail
- Closed