]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2779 Explicitly specify UTF-8 for outgoing emails
authorEvgeny Mandrikov <mandrikov@gmail.com>
Fri, 30 Sep 2011 12:00:22 +0000 (16:00 +0400)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Fri, 30 Sep 2011 12:00:44 +0000 (16:00 +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 df3f5ea77690cdbeae3eb059ac47279675a149f6..115191d9394f6d6b7afcfa9c1ca5cc317010eb8e 100644 (file)
@@ -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()) + " ", "")
index 1446e7d0b8fd18222bdcee1047796f4336a2b3a0..0dc4182d0b33af9df9f984cf49717a5d037c1cf4 100644 (file)
@@ -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());