From 8fe036829d70df771ebaf194c9c973ed289aad55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Garc=C3=ADa?= Date: Wed, 13 Nov 2024 12:15:43 +0100 Subject: [PATCH] Metadata publication notifications / allow to configure the mail format: html / text --- .../util/MetadataPublicationMailNotifier.java | 17 ++++++++++++----- .../main/webResources/WEB-INF/config.properties | 3 ++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/services/src/main/java/org/fao/geonet/util/MetadataPublicationMailNotifier.java b/services/src/main/java/org/fao/geonet/util/MetadataPublicationMailNotifier.java index 02eab897564..64e65f71a8a 100644 --- a/services/src/main/java/org/fao/geonet/util/MetadataPublicationMailNotifier.java +++ b/services/src/main/java/org/fao/geonet/util/MetadataPublicationMailNotifier.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2001-2023 Food and Agriculture Organization of the + * Copyright (C) 2001-2024 Food and Agriculture Organization of the * United Nations (FAO-UN), United Nations World Food Programme (WFP) * and United Nations Environment Programme (UNEP) * @@ -34,6 +34,7 @@ import org.fao.geonet.repository.GroupRepository; import org.fao.geonet.utils.Log; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import java.util.*; @@ -48,6 +49,9 @@ @Component public class MetadataPublicationMailNotifier { + @Value("${metadata.publicationmail.format.html:true}") + private boolean sendHtmlMail; + @Autowired SettingManager settingManager; @@ -136,7 +140,6 @@ private void sendMailPublicationNotification(Locale[] feedbackLocales, LocalizedEmailComponent emailMessageComponent = new LocalizedEmailComponent(MESSAGE, "metadata_published_text", KeyType.MESSAGE_KEY, POSITIONAL_FORMAT); for (Locale feedbackLocale : feedbackLocales) { - emailSubjectComponent.addParameters( feedbackLocale, new LocalizedEmailParameter(ParameterType.RAW_VALUE, 1, settingManager.getSiteName()) @@ -175,15 +178,19 @@ private void sendMailPublicationNotification(Locale[] feedbackLocales, ); } - LocalizedEmail localizedEmail = new LocalizedEmail(true); + LocalizedEmail localizedEmail = new LocalizedEmail(sendHtmlMail); localizedEmail.addComponents(emailSubjectComponent, emailMessageComponent); String subject = localizedEmail.getParsedSubject(feedbackLocales); - String htmlMessage = localizedEmail.getParsedMessage(feedbackLocales); + String message = localizedEmail.getParsedMessage(feedbackLocales); // Send mail to notify about metadata publication / un-publication try { - MailUtil.sendHtmlMail(toAddress, subject, htmlMessage, settingManager); + if (sendHtmlMail) { + MailUtil.sendHtmlMail(toAddress, subject, message, settingManager); + } else { + MailUtil.sendMail(toAddress, subject, message, settingManager); + } } catch (IllegalArgumentException ex) { Log.warning(API.LOG_MODULE_NAME, ex.getMessage(), ex); } diff --git a/web/src/main/webResources/WEB-INF/config.properties b/web/src/main/webResources/WEB-INF/config.properties index 6a623b39a77..6704931e473 100644 --- a/web/src/main/webResources/WEB-INF/config.properties +++ b/web/src/main/webResources/WEB-INF/config.properties @@ -76,4 +76,5 @@ analytics.web.jscode= #analytics.web.service=matomo #analytics.web.jscode=var _paq = _paq || [];_paq.push(['trackPageView']);_paq.push(['enableLinkTracking']);(function() {var u="//localhost/";_paq.push(['setTrackerUrl', u+'piwik.php']);_paq.push(['setSiteId', '1']);var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);})();var currentUrl = location.href; window.addEventListener('hashchange', function() {_paq.push(['setReferrerUrl', currentUrl]);currentUrl = window.location.href;_paq.push(['setCustomUrl', currentUrl]);_paq.push(['setDocumentTitle', currentUrl]);_paq.push(['deleteCustomVariables', 'page']);_paq.push(['trackPageView']);var content = document.getElementsByTagName('body')[0];_paq.push(['MediaAnalytics::scanForMedia', content]);_paq.push(['FormAnalytics::scanForForms', content]);_paq.push(['trackContentImpressionsWithinNode', content]);_paq.push(['enableLinkTracking']);}); - +# Configure the metadata publication notification mails to be sent as HTML (true) or TEXT (false) +metadata.publicationmail.format.html=true