aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-10-10 13:54:09 +0400
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-10-10 13:55:23 +0400
commit0646c52841a150dbc60810a38f9af5550c5ce109 (patch)
treed938872d13f87a0a923b775321acdff671a7a050 /plugins
parentd7b95d299268535ab96ba9224aecb9bbd6a244b2 (diff)
downloadsonarqube-0646c52841a150dbc60810a38f9af5550c5ce109.tar.gz
sonarqube-0646c52841a150dbc60810a38f9af5550c5ce109.zip
SONAR-2740 Email notifications: add prefix to the sender's name
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java9
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationChannelTest.java2
2 files changed, 6 insertions, 5 deletions
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java
index 115191d9394..6079b20228e 100644
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java
+++ b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java
@@ -19,6 +19,9 @@
*/
package org.sonar.plugins.emailnotifications;
+import java.net.MalformedURLException;
+import java.net.URL;
+
import org.apache.commons.lang.StringUtils;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
@@ -32,9 +35,6 @@ import org.sonar.api.utils.SonarException;
import org.sonar.plugins.emailnotifications.api.EmailMessage;
import org.sonar.plugins.emailnotifications.api.EmailTemplate;
-import java.net.MalformedURLException;
-import java.net.URL;
-
/**
* References:
* <ul>
@@ -163,7 +163,8 @@ public class EmailNotificationChannel extends NotificationChannel {
}
// Set general information
email.setCharset("UTF-8");
- email.setFrom(configuration.getFrom(), StringUtils.defaultIfBlank(emailMessage.getFrom(), FROM_NAME_DEFAULT));
+ String from = StringUtils.isBlank(emailMessage.getFrom()) ? FROM_NAME_DEFAULT : emailMessage.getFrom() + " (Sonar)";
+ email.setFrom(configuration.getFrom(), from);
email.addTo(emailMessage.getTo(), " ");
String subject = StringUtils.defaultIfBlank(StringUtils.trimToEmpty(configuration.getPrefix()) + " ", "")
+ StringUtils.defaultString(emailMessage.getSubject(), SUBJECT_DEFAULT);
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationChannelTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationChannelTest.java
index 0dc4182d0b3..b02fbf86001 100644
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationChannelTest.java
+++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationChannelTest.java
@@ -142,7 +142,7 @@ public class EmailNotificationChannelTest {
assertThat(email.getHeaderValue("List-ID"), is("Sonar <sonar.nemo.sonarsource.org>"));
assertThat(email.getHeaderValue("List-Archive"), is("http://nemo.sonarsource.org"));
- assertThat(email.getHeaderValue("From"), is("Full Username <server@nowhere>"));
+ assertThat(email.getHeaderValue("From"), is("\"Full Username (Sonar)\" <server@nowhere>"));
assertThat(email.getHeaderValue("To"), is("<user@nowhere>"));
assertThat(email.getHeaderValue("Subject"), is("[SONAR] Review #3"));
assertThat(email.getBody(), is("I'll take care of this violation."));