]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2740 Email notifications: add prefix to the sender's name
authorEvgeny Mandrikov <mandrikov@gmail.com>
Mon, 10 Oct 2011 09:54:09 +0000 (13:54 +0400)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Mon, 10 Oct 2011 09:55:23 +0000 (13:55 +0400)
plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java
plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationChannelTest.java

index 115191d9394f6d6b7afcfa9c1ca5cc317010eb8e..6079b20228e590fcab322cae7de2468c3aa1d51a 100644 (file)
@@ -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);
index 0dc4182d0b33af9df9f984cf49717a5d037c1cf4..b02fbf860012946dc90f99b447635ec29a72f6a7 100644 (file)
@@ -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."));