aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-09-30 16:00:22 +0400
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-09-30 16:00:44 +0400
commit28ae81e81f52fb4176ce091a8f6a0c2fd41b032b (patch)
treea2252f0ba869cd89f847522b963f22bbdd66bcf5
parentdc30e55e56000ad1b44ef6c387e1370885f68c4b (diff)
downloadsonarqube-28ae81e81f52fb4176ce091a8f6a0c2fd41b032b.tar.gz
sonarqube-28ae81e81f52fb4176ce091a8f6a0c2fd41b032b.zip
SONAR-2779 Explicitly specify UTF-8 for outgoing emails
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java1
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationChannelTest.java16
2 files changed, 15 insertions, 2 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 df3f5ea7769..115191d9394 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
@@ -162,6 +162,7 @@ public class EmailNotificationChannel extends NotificationChannel {
email.addHeader(LIST_ARCHIVE_HEADER, configuration.getServerBaseURL());
}
// Set general information
+ email.setCharset("UTF-8");
email.setFrom(configuration.getFrom(), StringUtils.defaultIfBlank(emailMessage.getFrom(), FROM_NAME_DEFAULT));
email.addTo(emailMessage.getTo(), " ");
String subject = StringUtils.defaultIfBlank(StringUtils.trimToEmpty(configuration.getPrefix()) + " ", "")
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 1446e7d0b8f..0dc4182d0b3 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
@@ -22,6 +22,7 @@ package org.sonar.plugins.emailnotifications;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
import static org.junit.Assume.assumeThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -88,18 +89,25 @@ public class EmailNotificationChannelTest {
assertThat(server.getReceivedEmailSize(), is(1));
SmtpMessage email = (SmtpMessage) server.getReceivedEmail().next();
+ assertThat(email.getHeaderValue("Content-Type"), is("text/plain; charset=UTF-8"));
+
assertThat(email.getHeaderValue("From"), is("Sonar <server@nowhere>"));
assertThat(email.getHeaderValue("To"), is("<user@nowhere>"));
assertThat(email.getHeaderValue("Subject"), is("[SONAR] Test Message from Sonar"));
assertThat(email.getBody(), is("This is a test message from Sonar."));
}
- @Test(expected = EmailException.class)
+ @Test
public void shouldThrowAnExceptionWhenUnableToSendTestEmail() throws Exception {
configure();
server.stop();
- channel.sendTestEmail("user@nowhere", "Test Message from Sonar", "This is a test message from Sonar.");
+ try {
+ channel.sendTestEmail("user@nowhere", "Test Message from Sonar", "This is a test message from Sonar.");
+ fail();
+ } catch (EmailException e) {
+ // expected
+ }
}
@Test
@@ -126,6 +134,8 @@ public class EmailNotificationChannelTest {
assertThat(server.getReceivedEmailSize(), is(1));
SmtpMessage email = (SmtpMessage) server.getReceivedEmail().next();
+ assertThat(email.getHeaderValue("Content-Type"), is("text/plain; charset=UTF-8"));
+
assertThat(email.getHeaderValue("In-Reply-To"), is("<reviews/view/1@nemo.sonarsource.org>"));
assertThat(email.getHeaderValue("References"), is("<reviews/view/1@nemo.sonarsource.org>"));
@@ -150,6 +160,8 @@ public class EmailNotificationChannelTest {
assertThat(server.getReceivedEmailSize(), is(1));
SmtpMessage email = (SmtpMessage) server.getReceivedEmail().next();
+ assertThat(email.getHeaderValue("Content-Type"), is("text/plain; charset=UTF-8"));
+
assertThat(email.getHeaderValue("In-Reply-To"), nullValue());
assertThat(email.getHeaderValue("References"), nullValue());