Skip to content

Commit

Permalink
Merge pull request #3422 from LaVibeX/SubjectPrefix
Browse files Browse the repository at this point in the history
Subject prefix
  • Loading branch information
nscuro authored Feb 5, 2024
2 parents 113279c + 19b7e5b commit 11eb35f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public enum ConfigPropertyConstants {
GENERAL_BADGE_ENABLED("general", "badge.enabled", "false", PropertyType.BOOLEAN, "Flag to enable/disable SVG badge support from metrics"),
EMAIL_SMTP_ENABLED("email", "smtp.enabled", "false", PropertyType.BOOLEAN, "Flag to enable/disable SMTP"),
EMAIL_SMTP_FROM_ADDR("email", "smtp.from.address", null, PropertyType.STRING, "The from email address to use to send output SMTP mail"),
EMAIL_PREFIX("email", "subject.prefix", "[Dependency-Track]", PropertyType.STRING, "The Prefix Subject email to use"),
EMAIL_SMTP_SERVER_HOSTNAME("email", "smtp.server.hostname", null, PropertyType.STRING, "The hostname or IP address of the SMTP mail server"),
EMAIL_SMTP_SERVER_PORT("email", "smtp.server.port", null, PropertyType.INTEGER, "The port the SMTP server listens on"),
EMAIL_SMTP_USERNAME("email", "smtp.username", null, PropertyType.STRING, "The optional username to authenticate with when sending outbound SMTP mail"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

import static org.dependencytrack.model.ConfigPropertyConstants.EMAIL_SMTP_ENABLED;
import static org.dependencytrack.model.ConfigPropertyConstants.EMAIL_SMTP_FROM_ADDR;
import static org.dependencytrack.model.ConfigPropertyConstants.EMAIL_PREFIX;
import static org.dependencytrack.model.ConfigPropertyConstants.EMAIL_SMTP_PASSWORD;
import static org.dependencytrack.model.ConfigPropertyConstants.EMAIL_SMTP_SERVER_HOSTNAME;
import static org.dependencytrack.model.ConfigPropertyConstants.EMAIL_SMTP_SERVER_PORT;
Expand Down Expand Up @@ -103,6 +104,7 @@ private void sendNotification(final PublishContext ctx, Notification notificatio
final String encryptedSmtpPassword;
final boolean smtpSslTls;
final boolean smtpTrustCert;
String emailSubjectPrefix;

try (QueryManager qm = new QueryManager()) {
smtpEnabled = qm.isEnabled(EMAIL_SMTP_ENABLED);
Expand All @@ -112,6 +114,8 @@ private void sendNotification(final PublishContext ctx, Notification notificatio
}

smtpFrom = qm.getConfigProperty(EMAIL_SMTP_FROM_ADDR.getGroupName(), EMAIL_SMTP_FROM_ADDR.getPropertyName()).getPropertyValue();
emailSubjectPrefix = qm.getConfigProperty(EMAIL_PREFIX.getGroupName(), EMAIL_PREFIX.getPropertyName()).getPropertyValue();
emailSubjectPrefix = emailSubjectPrefix == null ? " " : emailSubjectPrefix;
smtpHostname = qm.getConfigProperty(EMAIL_SMTP_SERVER_HOSTNAME.getGroupName(), EMAIL_SMTP_SERVER_HOSTNAME.getPropertyName()).getPropertyValue();
smtpPort = Integer.parseInt(qm.getConfigProperty(EMAIL_SMTP_SERVER_PORT.getGroupName(), EMAIL_SMTP_SERVER_PORT.getPropertyName()).getPropertyValue());
smtpUser = qm.getConfigProperty(EMAIL_SMTP_USERNAME.getGroupName(), EMAIL_SMTP_USERNAME.getPropertyName()).getPropertyValue();
Expand All @@ -136,7 +140,7 @@ private void sendNotification(final PublishContext ctx, Notification notificatio
final SendMail sendMail = new SendMail()
.from(smtpFrom)
.to(destinations)
.subject("[Dependency-Track] " + notification.getTitle())
.subject(emailSubjectPrefix + " " + notification.getTitle())
.body(content)
.bodyMimeType(mimeType)
.host(smtpHostname)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.dependencytrack.model.ConfigPropertyConstants.EMAIL_SMTP_ENABLED;
import static org.dependencytrack.model.ConfigPropertyConstants.EMAIL_SMTP_FROM_ADDR;
import static org.dependencytrack.model.ConfigPropertyConstants.EMAIL_PREFIX;
import static org.dependencytrack.model.ConfigPropertyConstants.EMAIL_SMTP_PASSWORD;
import static org.dependencytrack.model.ConfigPropertyConstants.EMAIL_SMTP_SERVER_HOSTNAME;
import static org.dependencytrack.model.ConfigPropertyConstants.EMAIL_SMTP_SERVER_PORT;
Expand Down Expand Up @@ -86,6 +87,13 @@ public void setUp() throws Exception {
EMAIL_SMTP_FROM_ADDR.getPropertyType(),
EMAIL_SMTP_FROM_ADDR.getDescription()
);
qm.createConfigProperty(
EMAIL_PREFIX.getGroupName(),
EMAIL_PREFIX.getPropertyName(),
"[Dependency-Track]",
EMAIL_PREFIX.getPropertyType(),
EMAIL_PREFIX.getDescription()
);
qm.createConfigProperty(
EMAIL_SMTP_SSLTLS.getGroupName(),
EMAIL_SMTP_SSLTLS.getPropertyName(),
Expand Down

0 comments on commit 11eb35f

Please sign in to comment.