diff --git a/processes-services/src/main/java/org/exoplatform/processes/notification/provider/MailTemplateProvider.java b/processes-services/src/main/java/org/exoplatform/processes/notification/provider/MailTemplateProvider.java index ac20b3ad8..237e0d93a 100644 --- a/processes-services/src/main/java/org/exoplatform/processes/notification/provider/MailTemplateProvider.java +++ b/processes-services/src/main/java/org/exoplatform/processes/notification/provider/MailTemplateProvider.java @@ -24,10 +24,14 @@ import org.exoplatform.social.core.manager.IdentityManager; import org.exoplatform.social.notification.LinkProviderUtils; import org.exoplatform.webui.utils.TimeConvertUtils; +import org.jsoup.Jsoup; +import org.jsoup.nodes.*; import java.io.Writer; import java.util.Calendar; +import java.util.List; import java.util.Locale; +import java.util.stream.Collectors; @TemplateConfigs(templates = { @TemplateConfig(pluginId = CreateRequestPlugin.ID, template = "war:/notification/templates/mail/CreateRequestPlugin.gtmpl"), @@ -65,7 +69,7 @@ protected MessageInfo makeMessage(NotificationContext notificationContext) { String processTitle = notificationInfo.getValueOwnerParameter(NotificationArguments.REQUEST_PROCESS.getKey()); templateContext.put("PROCESS_TITLE", encoder.encode(processTitle)); templateContext.put("REQUEST_TITLE", encoder.encode(requestTitle)); - templateContext.put("REQUEST_DESCRIPTION", encoder.encode(requestDescription)); + templateContext.put("REQUEST_DESCRIPTION",encodeTextInsideHtmlTags(encoder, requestDescription)); } templateContext.put("PROCESS_URL", encoder.encode(processUrl)); templateContext.put("REQUEST_URL", encoder.encode(requestUrl)); @@ -146,4 +150,26 @@ private void buildCommonTemplateParams(TemplateContext templateContext, // Footer templateContext.put("FOOTER_LINK", LinkProviderUtils.getRedirectUrl("notification_settings", receiver.getRemoteId())); } + + private String encodeTextInsideHtmlTags(HTMLEntityEncoder encoder, String requestDescription) { + Document doc = Jsoup.parse(requestDescription); + encodeText(encoder ,doc); + List list = doc.body().children(); + return list.stream() + .map(Element::outerHtml) + .collect(Collectors.joining()); + } + + private void encodeText(HTMLEntityEncoder encoder, Document doc) { + for (int i = 0; i < doc.childNodes().size(); i++) { + Node child = doc.childNodes().get(i); + if (child instanceof TextNode) { + String encodedText = encoder.encode(((TextNode) child).text()); + TextNode newTextNode = new TextNode(encodedText); + doc.childNodes().set(i, newTextNode); + } else if (child instanceof Document) { + encodeText(encoder, (Document) child); + } + } + } }