Skip to content

Commit

Permalink
fix:[Process] Mail notification contains HTML tags -EXO-64330
Browse files Browse the repository at this point in the history
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 <p> tag that was created while typing a description. after this change, Mail notification escaped HTML tags.
  • Loading branch information
akhanfir committed Aug 11, 2023
1 parent c6b0bf7 commit 4584f51
Showing 1 changed file with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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<Element> 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);
}
}
}
}

0 comments on commit 4584f51

Please sign in to comment.