This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new 8e11da76a fix(alert): keep the notification email subject on one line
(#6772)
8e11da76a is described below
commit 8e11da76a7b98fac72fc2d91e43eb5cc815b16c1
Author: Apulupie <[email protected]>
AuthorDate: Fri Nov 27 12:48:53 2026 +0800
fix(alert): keep the notification email subject on one line (#6772)
---
.../ops/alert/NotificationOutboxService.java | 12 ++++++-
.../ops/alert/NotificationOutboxServiceTest.java | 38 ++++++++++++++++++++++
2 files changed, 49 insertions(+), 1 deletion(-)
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/ops/alert/NotificationOutboxService.java
b/server/src/main/java/org/apache/rocketmq/studio/ops/alert/NotificationOutboxService.java
index 28f769342..937b5b9f7 100644
---
a/server/src/main/java/org/apache/rocketmq/studio/ops/alert/NotificationOutboxService.java
+++
b/server/src/main/java/org/apache/rocketmq/studio/ops/alert/NotificationOutboxService.java
@@ -526,11 +526,21 @@ public class NotificationOutboxService {
}
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(parseRecipients(settings.getEmailRecipients()));
- message.setSubject("[RocketMQ Studio] " + alert.getTitle());
+ message.setSubject("[RocketMQ Studio] " +
subjectLine(alert.getTitle()));
message.setText(content);
sender.send(message);
}
+ /**
+ * A mail subject is a single header line: the alert title is the rule's
name verbatim, and a
+ * name carrying a line break would otherwise fold the rest of the subject
into the header on
+ * the wire (its own line becomes a continuation). Collapse the breaks
into spaces, the same
+ * way {@code AlertService} keeps an exported rule comment on one line.
+ */
+ private static String subjectLine(String title) {
+ return title == null ? "" : title.replaceAll("[\\r\\n]+", " ");
+ }
+
private static String[] parseRecipients(String raw) throws
AddressException {
List<String> recipients = new ArrayList<>();
// Commas and legacy semicolons separate recipients only outside quoted
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/ops/alert/NotificationOutboxServiceTest.java
b/server/src/test/java/org/apache/rocketmq/studio/ops/alert/NotificationOutboxServiceTest.java
index c45fe1c64..d2e703a38 100644
---
a/server/src/test/java/org/apache/rocketmq/studio/ops/alert/NotificationOutboxServiceTest.java
+++
b/server/src/test/java/org/apache/rocketmq/studio/ops/alert/NotificationOutboxServiceTest.java
@@ -504,6 +504,44 @@ class NotificationOutboxServiceTest {
"alertId=9, channel=email", "SUCCESS", null);
}
+ @Test
+ void emailSubjectStaysOnOneLineForAMultiLineAlertTitleTest() {
+ RmqAlertNotificationOutboxMapper mapper =
mock(RmqAlertNotificationOutboxMapper.class);
+ SettingsRepository settings = mock(SettingsRepository.class);
+ AlertRepository alerts = mock(AlertRepository.class);
+ OperationAuditService audit = mock(OperationAuditService.class);
+ JavaMailSender mailSender = mock(JavaMailSender.class);
+ RmqAlertNotificationOutbox row = new RmqAlertNotificationOutbox();
+ row.setId(20L);
+ row.setAlertId(9L);
+ row.setChannel("email");
+ row.setStatus("PENDING");
+ row.setAttemptCount(0);
+ when(mapper.findDispatchable(any(LocalDateTime.class),
any(LocalDateTime.class), any(Integer.class)))
+ .thenReturn(List.of(row));
+ when(mapper.claimForDispatch(any(), any(LocalDateTime.class),
any(LocalDateTime.class),
+ any(LocalDateTime.class), anyString(),
anyInt())).thenReturn(1);
+ when(mapper.update(any(), any())).thenReturn(1);
+ // The alert title is the rule's name verbatim (NativeAlertProcessor),
and no rule-name
+ // constraint keeps it to one line, so a REST caller can store a name
with a line break.
+
when(alerts.findAlertById(9L)).thenReturn(Optional.of(SystemAlertVO.builder().id(9L)
+ .level(AlertLevel.warning).title("High lag\nBcc:
[email protected]")
+ .description("high").instanceId("local").build()));
+
when(settings.loadGeneralSettings()).thenReturn(GeneralSettingsVO.builder()
+ .emailRecipients("[email protected]").build());
+
+ new NotificationOutboxService(mapper, settings,
mock(AlertSilenceService.class), alerts, audit,
+ new RestTemplate(), () -> mailSender).dispatch();
+
+ // A message subject is one header line. Keeping the line break makes
MimeMessage write
+ // "Subject: [RocketMQ Studio] High lag\r\n Bcc:
[email protected]", so the rest of the
+ // rule name lands in the header as a folded continuation instead of
the subject text.
+ verify(mailSender).send(argThat((SimpleMailMessage message) ->
message.getSubject() != null
+ && !message.getSubject().contains("\n")
+ && !message.getSubject().contains("\r")
+ && message.getSubject().startsWith("[RocketMQ Studio] High
lag")));
+ }
+
@Test
void dispatchesEmailWithQuotedDisplayNameRecipientsTest() {
RmqAlertNotificationOutboxMapper mapper =
mock(RmqAlertNotificationOutboxMapper.class);