diff --git a/src/main/java/io/kamax/mxisd/threepid/generator/PlaceholderNotificationGenerator.java b/src/main/java/io/kamax/mxisd/threepid/generator/PlaceholderNotificationGenerator.java index 2f0597a9..40ba9f59 100644 --- a/src/main/java/io/kamax/mxisd/threepid/generator/PlaceholderNotificationGenerator.java +++ b/src/main/java/io/kamax/mxisd/threepid/generator/PlaceholderNotificationGenerator.java @@ -27,8 +27,8 @@ import io.kamax.mxisd.invitation.IMatrixIdInvite; import io.kamax.mxisd.invitation.IThreePidInviteReply; import io.kamax.mxisd.threepid.session.IThreePidSession; -import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.WordUtils; +import org.apache.commons.lang3.StringUtils; import static io.kamax.mxisd.http.io.identity.StoreInviteRequest.Keys.RoomName; import static io.kamax.mxisd.http.io.identity.StoreInviteRequest.Keys.SenderDisplayName; @@ -46,6 +46,10 @@ public PlaceholderNotificationGenerator(MatrixConfig mxCfg, ServerConfig srvCfg) } protected String populateForCommon(ThreePid recipient, String input) { + if (StringUtils.isBlank(input)) { + return input; + } + String domainPretty = WordUtils.capitalizeFully(mxCfg.getDomain()); return input @@ -56,6 +60,10 @@ protected String populateForCommon(ThreePid recipient, String input) { } protected String populateForInvite(IMatrixIdInvite invite, String input) { + if (StringUtils.isBlank(input)) { + return input; + } + String senderName = invite.getProperties().getOrDefault(SenderDisplayName, ""); String senderNameOrId = StringUtils.defaultIfBlank(senderName, invite.getSender().getId()); String roomName = invite.getProperties().getOrDefault(RoomName, ""); @@ -72,6 +80,10 @@ protected String populateForInvite(IMatrixIdInvite invite, String input) { } protected String populateForReply(IThreePidInviteReply invite, String input) { + if (StringUtils.isBlank(input)) { + return input; + } + ThreePid tpid = new ThreePid(invite.getInvite().getMedium(), invite.getInvite().getAddress()); String senderName = invite.getInvite().getProperties().getOrDefault(SenderDisplayName, ""); @@ -93,6 +105,10 @@ protected String populateForReply(IThreePidInviteReply invite, String input) { } protected String populateForValidation(IThreePidSession session, String input) { + if (StringUtils.isBlank(input)) { + return input; + } + String validationLink = srvCfg.getPublicUrl() + IsAPIv1.getValidate( session.getThreePid().getMedium(), session.getId(), diff --git a/src/main/java/io/kamax/mxisd/threepid/notification/email/EmailSendGridNotificationHandler.java b/src/main/java/io/kamax/mxisd/threepid/notification/email/EmailSendGridNotificationHandler.java index ce8760cb..38dbbdfe 100644 --- a/src/main/java/io/kamax/mxisd/threepid/notification/email/EmailSendGridNotificationHandler.java +++ b/src/main/java/io/kamax/mxisd/threepid/notification/email/EmailSendGridNotificationHandler.java @@ -33,7 +33,7 @@ import io.kamax.mxisd.threepid.generator.PlaceholderNotificationGenerator; import io.kamax.mxisd.threepid.session.IThreePidSession; import io.kamax.mxisd.util.FileUtil; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -86,6 +86,9 @@ private String getFromFile(String path) { @Override public void sendForInvite(IMatrixIdInvite invite) { EmailTemplate template = cfg.getTemplates().getGeneric().get("matrixId"); + if (StringUtils.isAllBlank(template.getBody().getText(), template.getBody().getHtml())) { + throw new FeatureNotAvailable("No template has been configured for Matrix ID invite notifications"); + } Email email = getEmail(); email.setSubject(populateForInvite(invite, template.getSubject())); @@ -98,6 +101,10 @@ public void sendForInvite(IMatrixIdInvite invite) { @Override public void sendForReply(IThreePidInviteReply invite) { EmailTemplate template = cfg.getTemplates().getInvite(); + if (StringUtils.isAllBlank(template.getBody().getText(), template.getBody().getHtml())) { + throw new FeatureNotAvailable("No template has been configured for 3PID invite notifications"); + } + Email email = getEmail(); email.setSubject(populateForReply(invite, template.getSubject())); email.setText(populateForReply(invite, getFromFile(template.getBody().getText()))); @@ -109,6 +116,10 @@ public void sendForReply(IThreePidInviteReply invite) { @Override public void sendForValidation(IThreePidSession session) { EmailTemplate template = cfg.getTemplates().getSession().getValidation(); + if (StringUtils.isAllBlank(template.getBody().getText(), template.getBody().getHtml())) { + throw new FeatureNotAvailable("No template has been configured for validation notifications"); + } + Email email = getEmail(); email.setSubject(populateForValidation(session, template.getSubject())); email.setText(populateForValidation(session, getFromFile(template.getBody().getText()))); @@ -120,6 +131,10 @@ public void sendForValidation(IThreePidSession session) { @Override public void sendForFraudulentUnbind(ThreePid tpid) { EmailTemplate template = cfg.getTemplates().getSession().getUnbind().getFraudulent(); + if (StringUtils.isAllBlank(template.getBody().getText(), template.getBody().getHtml())) { + throw new FeatureNotAvailable("No template has been configured for fraudulent unbind notifications"); + } + Email email = getEmail(); email.setSubject(populateForCommon(tpid, template.getSubject())); email.setText(populateForCommon(tpid, getFromFile(template.getBody().getText())));