Skip to content
Permalink
Browse files

JENKINS-33574 fix unicode attachments (#159)

  • Loading branch information
ssbarnea authored and davidvanlaatum committed Sep 12, 2017
1 parent dacb2ca commit 3e74855770efaf70afad14518ffdfe1db8dcb07e
Showing with 53 additions and 43 deletions.
  1. +9 −1 pom.xml
  2. +44 −42 src/test/java/hudson/plugins/emailext/AttachmentUtilsTest.java
10 pom.xml
@@ -279,6 +279,14 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>clirr-maven-plugin</artifactId>
@@ -328,7 +336,7 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Djava.awt.headless=true -XX:MaxPermSize=512m @{argLine}</argLine>
<argLine>-Djava.awt.headless=true -XX:MaxPermSize=512m -Dfile.encoding=UTF-8 @{argLine}</argLine>
</configuration>
</plugin>
</plugins>
@@ -40,7 +40,7 @@
* @author acearl
*/
public class AttachmentUtilsTest {

@Rule
public final JenkinsRule j = new JenkinsRule() {
@Override
@@ -49,64 +49,64 @@ public void before() throws Throwable {
super.before();
}
};

@Test
public void testAttachmentFromWorkspace() throws Exception {
URL url = this.getClass().getResource("/test.pdf");
final File attachment = new File(url.getFile());

FreeStyleProject project = j.createFreeStyleProject("foo");
ExtendedEmailPublisher publisher = new ExtendedEmailPublisher();
publisher.attachmentsPattern = "*.pdf";
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("test.pdf").copyFrom(new FilePath(attachment));
return true;
}
});
FreeStyleBuild b = project.scheduleBuild2(0).get();
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 PDF named \"test.pdf\" attached", "test.pdf".equalsIgnoreCase(attach.getFileName()));
assertTrue("There should be a PDF named \"test.pdf\" attached", "test.pdf".equalsIgnoreCase(attach.getFileName()));
}

@Test
public void testAttachmentFromWorkspaceSubdir() throws Exception {
URL url = this.getClass().getResource("/test.pdf");
final File attachment = new File(url.getFile());

FreeStyleProject project = j.createFreeStyleProject("foo");
ExtendedEmailPublisher publisher = new ExtendedEmailPublisher();
publisher.attachmentsPattern = "**/*.pdf";
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 {
@@ -115,41 +115,41 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
return true;
}
});
FreeStyleBuild b = project.scheduleBuild2(0).get();
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 PDF named \"test.pdf\" attached", "test.pdf".equalsIgnoreCase(attach.getFileName()));
assertTrue("There should be a PDF named \"test.pdf\" attached", "test.pdf".equalsIgnoreCase(attach.getFileName()));
}

@Test
@Issue("JENKINS-27062")
public void testHtmlMimeType() throws Exception {
URL url = this.getClass().getResource("/test.html");
final File attachment = new File(url.getFile());

FreeStyleProject project = j.createFreeStyleProject("foo");
ExtendedEmailPublisher publisher = new ExtendedEmailPublisher();
publisher.attachmentsPattern = "**/*.html";
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 {
@@ -158,23 +158,23 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
return true;
}
});
FreeStyleBuild b = project.scheduleBuild2(0).get();
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 HTML file named \"test.html\" attached", "test.html".equalsIgnoreCase(attach.getFileName()));
assertTrue("There should be a HTML file named \"test.html\" attached", "test.html".equalsIgnoreCase(attach.getFileName()));

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

@@ -217,7 +217,9 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
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())));
String attachment_filename = MimeUtility.decodeText(attach.getFileName());
assertTrue(String.format("There should be a txt file named \"已使用红包.txt\" attached but found %s", attachment_filename),
"已使用红包.txt".equalsIgnoreCase(attachment_filename));

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

0 comments on commit 3e74855

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