Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port: Configurable email subject prefix #1307

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ private void sendNotification(final PublishContext ctx, Notification notificatio
return;
}

String emailSubjectPrefix;
emailSubjectPrefix = publisherConfig.emailPrefix().orElse(" ");

final String fromAddress = publisherConfig.fromAddress().orElse(null);
if (fromAddress == null) {
LOGGER.warn("From address is not configured; Skipping notification (%s)".formatted(ctx));
Expand All @@ -132,7 +135,7 @@ private void sendNotification(final PublishContext ctx, Notification notificatio
final var message = new MailMessage();
message.setFrom(fromAddress);
message.setTo(destination);
message.setSubject("[Dependency-Track] " + notification.getTitle());
message.setSubject(emailSubjectPrefix + " " + notification.getTitle());
message.setText(content);

mailClient.sendMailAndAwait(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class SendMailPublisherConfig {
private final Provider<Optional<String>> passwordProvider;
private final Provider<Optional<Boolean>> tlsEnabledProvider;
private final Provider<Optional<Boolean>> trustCertificateProvider;
private final Provider<Optional<String>> emailPrefixProvider;

SendMailPublisherConfig(
@ConfigProperty(name = "dtrack.email.smtp.enabled") final Provider<Optional<Boolean>> smtpEnabledProvider,
Expand All @@ -53,7 +54,8 @@ class SendMailPublisherConfig {
@ConfigProperty(name = "dtrack.email.smtp.username") final Provider<Optional<String>> usernameProvider,
@ConfigProperty(name = "dtrack.email.smtp.password") final Provider<Optional<String>> passwordProvider,
@ConfigProperty(name = "dtrack.email.smtp.ssltls") final Provider<Optional<Boolean>> tlsEnabledProvider,
@ConfigProperty(name = "dtrack.email.smtp.trustcert") final Provider<Optional<Boolean>> trustCertificateProvider
@ConfigProperty(name = "dtrack.email.smtp.trustcert") final Provider<Optional<Boolean>> trustCertificateProvider,
@ConfigProperty(name = "dtrack.email.subject.prefix") final Provider<Optional<String>> emailPrefixProvider
) {
this.smtpEnabledProvider = smtpEnabledProvider;
this.fromAddressProvider = fromAddressProvider;
Expand All @@ -63,12 +65,17 @@ class SendMailPublisherConfig {
this.passwordProvider = passwordProvider;
this.tlsEnabledProvider = tlsEnabledProvider;
this.trustCertificateProvider = trustCertificateProvider;
this.emailPrefixProvider = emailPrefixProvider;
}

Optional<Boolean> isSmtpEnabled() {
return smtpEnabledProvider.get();
}

Optional<String> emailPrefix() {
return emailPrefixProvider.get();
}

Optional<String> fromAddress() {
return fromAddressProvider.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public Map<String, String> getConfigOverrides() {
Map.entry("dtrack.email.smtp.enabled", "true"),
Map.entry("dtrack.email.smtp.server.hostname", "localhost"),
Map.entry("dtrack.email.smtp.server.port", "${mailpit.smtp.port}"),
Map.entry("dtrack.email.smtp.from.address", "[email protected]")
Map.entry("dtrack.email.smtp.from.address", "[email protected]"),
Map.entry("dtrack.email.subject.prefix", "[Dependency-Track]")
);
}

Expand Down
Loading