[
https://issues.apache.org/jira/browse/GERONIMO-6480?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14204093#comment-14204093
]
Hendrik Saly commented on GERONIMO-6480:
----------------------------------------
The unittests below are all green for geronimo javamail 1.8.4 (spec 1.7.1) and
Oracle/Sun javamail reference implementation 1.5.2.
I don't see here an issue.
{code}
public void testGERONIMO6480_0() throws Exception {
final BodyPart attachmentPart = new MimeBodyPart();
attachmentPart.setDataHandler(new DataHandler(new FileDataSource(
getAbsoluteFilePathFromClassPath("jmeter_distributed_testing_step_by_step.pdf"))));
attachmentPart.setFileName("test.pdf");
Assert.assertEquals("text/plain; name=test.pdf",
attachmentPart.getContentType());
}
public void testGERONIMO6480_1() throws Exception {
final MimeBodyPart attachmentPart = new MimeBodyPart();
attachmentPart.addHeader("Content-Type", "aplication/pdf");
attachmentPart.setDataHandler(new DataHandler(new FileDataSource(
getAbsoluteFilePathFromClassPath("jmeter_distributed_testing_step_by_step.pdf"))));
attachmentPart.setFileName("test.pdf");
Assert.assertEquals("text/plain; name=test.pdf",
attachmentPart.getContentType());
}
public void testGERONIMO6480_2() throws Exception {
final MimeBodyPart attachmentPart = new MimeBodyPart();
attachmentPart.setDataHandler(new DataHandler(new FileDataSource(
getAbsoluteFilePathFromClassPath("jmeter_distributed_testing_step_by_step.pdf"))));
attachmentPart.addHeader("Content-Type", "aplication/pdf");
attachmentPart.setFileName("test.pdf");
Assert.assertEquals("aplication/pdf; name=test.pdf",
attachmentPart.getContentType());
}
public void testGERONIMO6480_3() throws Exception {
final MimeBodyPart attachmentPart = new MimeBodyPart();
attachmentPart.setDataHandler(new DataHandler(new FileDataSource(
getAbsoluteFilePathFromClassPath("jmeter_distributed_testing_step_by_step.pdf"))));
attachmentPart.setFileName("test.pdf");
Assert.assertEquals("text/plain; name=test.pdf",
attachmentPart.getContentType());
}
public void testGERONIMO6480_4() throws Exception {
final MimeBodyPart attachmentPart = new MimeBodyPart();
attachmentPart.setFileName("test.pdf");
attachmentPart.setDataHandler(new DataHandler(new FileDataSource(
getAbsoluteFilePathFromClassPath("jmeter_distributed_testing_step_by_step.pdf"))));
Assert.assertEquals("text/plain", attachmentPart.getContentType());
}
{code}
> Wrong attachment 'Content-type' in some conditions
> --------------------------------------------------
>
> Key: GERONIMO-6480
> URL: https://issues.apache.org/jira/browse/GERONIMO-6480
> Project: Geronimo
> Issue Type: Bug
> Security Level: public(Regular issues)
> Components: mail
> Reporter: Alexandre Garnier
> Assignee: Hendrik Saly
>
> When you set an attachment filename before having a Content-type defined,
> then the Content-type is set to 'text/plain'.
> {code:language=java}
> BodyPart attachmentPart = new MimeBodyPart();
> attachmentPart.setDataHandler(dh);
> attachmentPart.setFileName("test.pdf");
> {code}
> ==> Content-type = 'text/plain'
> {code:language=java}
> BodyPart attachmentPart = new MimeBodyPart();
> attachmentPart.addHeader("Content-Type", "aplication/pdf");
> attachmentPart.setDataHandler(dh);
> attachmentPart.setFileName("test.pdf");
> {code}
> ==> Content-type = 'text/plain' (because setDataHandler reset Headers)
> {code:language=java}
> BodyPart attachmentPart = new MimeBodyPart();
> attachmentPart.setDataHandler(dh);
> attachmentPart.addHeader("Content-Type", "aplication/pdf");
> attachmentPart.setFileName("test.pdf");
> {code}
> ==> Right Content-Type
> {code:language=java}
> System.setProperty("mail.mime.setcontenttypefilename",
> Boolean.FALSE.toString());
> BodyPart attachmentPart = new MimeBodyPart();
> attachmentPart.setDataHandler(dh);
> attachmentPart.setFileName("test.pdf");
> {code}
> ==> Right Content-Type
> {code:language=java}
> BodyPart attachmentPart = new MimeBodyPart();
> attachmentPart.setFileName("test.pdf");
> attachmentPart.setDataHandler(dh);
> {code}
> ==> Right Content-Type
> It's because of solution of GERONIMO-2091 (SVN rev412720).
> The right solution is in [javamail
> MimeBodyPart.java|https://java.net/projects/javamail/sources/mercurial/content/mail/src/main/java/javax/mail/internet/MimeBodyPart.java?rev=569]
> : use direct access to Header (instead of method with default value) and do
> nothing if not yet defined. This solution could allow to remove the
> {{MIME_SETCONTENTTYPEFILENAME}} property.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)