From 4584f51bbf1f297d333383ca94cea222b487d228 Mon Sep 17 00:00:00 2001 From: Anwar khanfir Date: Mon, 5 Jun 2023 23:48:39 +0100 Subject: [PATCH] fix:[Process] Mail notification contains HTML tags -EXO-64330 Prior to this change, when create a request in process and user member in space mentioned in 'Who can manage the process' of the process and enabled 'For process manager - A new request has been created' notifs for mails, check received mail , this mail notification contains HTML tags. To fix this problem, remove the

tag that was created while typing a description. after this change, Mail notification escaped HTML tags. --- .../provider/MailTemplateProvider.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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); + } + } + } }