Skip to content
Permalink
Browse files

Fix JENKINS-33574

Set system property so that Javamail encodes the names of attachments if necessary
  • Loading branch information
slide committed Mar 16, 2016
1 parent 79d69e2 commit 4edc42b17f6af7392a8a218325e96a3e3d06c504
@@ -170,6 +170,13 @@
<version>3.18.1-GA</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-war</artifactId>
<type>war</type>
<version>${jenkins.version}</version>
<scope>test</scope>
</dependency>


<!-- static analysys -->
@@ -38,10 +38,7 @@
*/
public class EmailExtensionPlugin extends Plugin {
static {
// Fix JENKINS-9006
// When sending to multiple recipients, send to valid recipients even if some are
// invalid, unless we have explicitly said otherwise.
for (String property: Arrays.asList("mail.smtp.sendpartial", "mail.smtps.sendpartial")) {
for (String property: Arrays.asList("mail.smtp.sendpartial", "mail.smtps.sendpartial", "mail.mime.encodefilename")) {
if (System.getProperty(property) == null) {
System.setProperty(property, "true");
}
@@ -24,6 +24,8 @@
import javax.mail.Message;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeUtility;

import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
@@ -175,4 +177,48 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen

assertTrue("The file should have the \"text/html\" mimetype", attach.isMimeType("text/html"));
}

@Test
@Issue("JENKINS-33574")
public void testNonEnglishCharacter() throws Exception {
FreeStyleProject project = j.createFreeStyleProject("foo");

ExtendedEmailPublisher publisher = new ExtendedEmailPublisher();
publisher.attachmentsPattern = "**/*.txt";
publisher.recipientList = "mickey@disney.com";

SuccessTrigger trigger = new SuccessTrigger(Collections.<RecipientProvider>singletonList(new ListRecipientProvider()), "", "", "", "", "", 0, "project");

publisher.getConfiguredTriggers().add(trigger);

project.getPublishersList().add(publisher);

project.getBuildersList().add(new TestBuilder() {
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
build.getWorkspace().child("已使用红包.txt").write("test.property=success","UTF-8");
return true;
}
});

FreeStyleBuild b = project.scheduleBuild2(0).get();

j.assertBuildStatusSuccess(b);

Mailbox mbox = Mailbox.get("mickey@disney.com");
assertEquals("Should have an email from success", 1, mbox.size());

Message msg = mbox.get(0);
assertTrue("Message should be multipart", msg instanceof MimeMessage);
assertTrue("Content should be a MimeMultipart", msg.getContent() instanceof MimeMultipart);

MimeMultipart part = (MimeMultipart)msg.getContent();

assertEquals("Should have two body items (message + attachment)", 2, part.getCount());

BodyPart attach = part.getBodyPart(1);
assertTrue("There should be a txt file named \"已使用红包.txt\" attached", "已使用红包.txt".equalsIgnoreCase(MimeUtility.decodeText(attach.getFileName())));

assertTrue("The file should have the \"text/plain\" mimetype", attach.isMimeType("text/plain"));
}
}

0 comments on commit 4edc42b

Please sign in to comment.
You can’t perform that action at this time.