Navigation Menu

Skip to content

Commit

Permalink
JENKINS-33574 fix unicode attachments (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored and davidvanlaatum committed Sep 12, 2017
1 parent dacb2ca commit 3e74855
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 43 deletions.
10 changes: 9 additions & 1 deletion pom.xml
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
86 changes: 44 additions & 42 deletions src/test/java/hudson/plugins/emailext/AttachmentUtilsTest.java
Expand Up @@ -40,7 +40,7 @@
* @author acearl
*/
public class AttachmentUtilsTest {

@Rule
public final JenkinsRule j = new JenkinsRule() {
@Override
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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"));
}

Expand Down Expand Up @@ -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"));
}
Expand Down

0 comments on commit 3e74855

Please sign in to comment.