Skip to main content

This content has been archived and is no longer being updated. Links may not function; however, this content may be relevant to outdated versions of the product.

Support Article

Czech characters render incorrectly on the Email thread

SA-84634

Summary



When an email is sent to the Production Test Listener with Czech content, the case is created. However, the Czech characters are rendered incorrectly in the email thread of the case.


Error Messages



Not Applicable


Steps to Reproduce

  1. Send a message with the below content.

    Krásný den a celý víkend, paní Pecinková,
    .
    Těším se z naší spolupráce.

     
  2. Open the case from the Advanced case Search using the case ID. In the Email Reply window, email message is rendered incorrectly with all the Czech characters.


Root Cause



The setting in Outlook on Windows has the default encoding for outgoing messages as 'ISO_8859_1'. Therefore, the HTML source has the charset as ‘iso-8859-1’. Setting the correct content type is important for Email Accessibility.
The UTF-8 is a standard encoding which is widely used. It ensures that all the content is rendered correctly, especially when non-Latin characters are used.
While the ISO-8859-1 (default on Outlook) only includes Latin-based languages. On Pega side, since UTF-8 is used for decoding, the content should also have been encoded with UTF-8.



Resolution



Perform the following local-change:

Since it is not feasible to change the Outlook default encoding setting (from 'ISO_8859_1' to 'UTF-8') according to the user's requirement, include the below code change in the 'pyExtractHtmlFromAttachment' activity's Step 3.

The pyExtractHTMLFromAttachment (mainly Step 3) activity is responsible for creating HTML content from the base64 stream of the email attachment.
Instead of using UTF-8 as the default encoding, the actual content type is extracted from the HTML document and the encoding is performed based on the charset in the meta tag.

String inputStream = htmlBase64;

byte[] bytes = org.apache.commons.codec.binary.Base64.decodeBase64(inputStream);
java.io.InputStream is = new java.io.ByteArrayInputStream(bytes);
java.nio.charset.Charset charset = java.nio.charset.StandardCharsets.UTF_8;
StringBuilder stringBuilder = new StringBuilder();
String line = null;
java.io.InputStreamReader reader = new java.io.InputStreamReader(is, charset); try (java.io.BufferedReader bufferedReader = new java.io.BufferedReader(reader)) {        
  while ((line = bufferedReader.readLine()) != null) {
    stringBuilder.append(line);
  }
}catch(Exception ex){
  oLog.error("Error while reading file", ex);

FileString = stringBuilder.toString();
oLog.debug("Html string: " + FileString);
//-------------------------------------------
org.jsoup.nodes.Document doc = org.jsoup.Jsoup.parse(FileString);

//change all the anchor tags to have parameter as _blank
org.jsoup.select.Elements elements = doc.select("meta");
if(elements != null && !elements.isEmpty()){
  
  String charsetAttr = elements.get(0).attr("content");
  if(!charsetAttr.toUpperCase().contains("UTF-8")){
    stringBuilder = new StringBuilder();
    charset = java.nio.charset.StandardCharsets.ISO_8859_1;
    is = new java.io.ByteArrayInputStream(bytes);
    reader = new java.io.InputStreamReader(is, charset);

    try (java.io.BufferedReader bufferedReader = new java.io.BufferedReader(reader)) {    
      while ((line = bufferedReader.readLine()) != null) {
        stringBuilder.append(line);
      }
    }catch(Exception ex){
      oLog.error("Error while reading file", ex);
    } 
    FileString = stringBuilder.toString();
  }
}
Suggest Edit

Published December 2, 2021

Did you find this content helpful? Yes No

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.

We'd prefer it if you saw us at our best.

Pega Community has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice
Contact us