Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bom-thirdparty/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ dependencies {
api("io.burt:jmespath-jackson:0.6.0")
api("jakarta.jms:jakarta.jms-api:3.1.0")
api("javax.activation:javax.activation-api:1.2.0")
api("javax.mail:mail:1.5.0-b01")
api("com.sun.mail:javax.mail:1.6.2")
api("jcharts:jcharts:0.7.5")
api("junit:junit:4.13.2") {
because("ApacheJMeter_junit depends on junit4")
Expand Down
2 changes: 1 addition & 1 deletion src/components/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies {
)
}

api("javax.mail:mail") {
api("com.sun.mail:javax.mail") {
exclude("javax.activation", "activation")
}
// There's no javax.activation:activation:1.2.0, so we use com.sun...
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/mail/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ plugins {
dependencies {
api(projects.src.core)

api("javax.mail:mail") {
api("com.sun.mail:javax.mail") {
exclude("javax.activation", "activation")
}
// There's no javax.activation:activation:1.2.0, so we use com.sun...
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.jmeter.protocol.smtp.sampler.protocol;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Collections;

import javax.mail.Message;
import javax.mail.internet.InternetAddress;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

class SendMailCommandTest {

private static final String NON_ASCII_FILE_NAME = "\u0442\u0435\u043a\u0441\u0442.txt"; // Russian for "text"

@TempDir
File tempDir;

@Test
void testNonAsciiAttachmentFileNameIsEncodedPerRfc2231() throws Exception {
SendMailCommand sendMailCommand = createSendMailCommandWithAttachment(NON_ASCII_FILE_NAME);
String rawMessage = writeMessageToString(sendMailCommand.prepareMessage());
// The file name must be encoded according to RFC 2231, so that the
// recipients see the original file name (see issue #6652)
assertTrue(
rawMessage.contains("filename*=UTF-8''%D1%82%D0%B5%D0%BA%D1%81%D1%82.txt"),
"filename* parameter with RFC 2231 encoded file name expected in:\n" + rawMessage);
// The mangled name must not appear anywhere
assertFalse(rawMessage.contains("B5:AB"), "mangled file name found in:\n" + rawMessage);
}

@Test
void testAsciiAttachmentFileNameIsNotEncoded() throws Exception {
SendMailCommand sendMailCommand = createSendMailCommandWithAttachment("attachment.txt");
String rawMessage = writeMessageToString(sendMailCommand.prepareMessage());
assertTrue(
rawMessage.contains("filename=attachment.txt"),
"plain ASCII file name expected in:\n" + rawMessage);
assertFalse(rawMessage.contains("filename*="), "unexpected RFC 2231 encoding in:\n" + rawMessage);
}

private SendMailCommand createSendMailCommandWithAttachment(String attachmentName) throws Exception {
File attachment = new File(tempDir, attachmentName);
Files.writeString(attachment.toPath(), "attachment content", StandardCharsets.UTF_8);

SendMailCommand sendMailCommand = new SendMailCommand();
sendMailCommand.setSmtpServer("localhost");
sendMailCommand.setSmtpPort("25");
sendMailCommand.setConnectionTimeOut("1000");
sendMailCommand.setTimeOut("1000");
sendMailCommand.setSender("from@example.com");
sendMailCommand.setReceiverTo(Collections.singletonList(new InternetAddress("to@example.com")));
sendMailCommand.setSubject("attachment file name test");
sendMailCommand.setMailBody("body");
sendMailCommand.addAttachment(attachment);
return sendMailCommand;
}

private static String writeMessageToString(Message message) throws Exception {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (outputStream) {
message.writeTo(outputStream);
}
return outputStream.toString(StandardCharsets.UTF_8);
}
}
2 changes: 2 additions & 0 deletions xdocs/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Summary
<li>Update json-path to 2.10.0 for JSON query expressions.</li>
<li>Update Neo4j Java driver to 6.x for Bolt-based database tests.</li>
<li>Update Rhino JavaScript engine to 1.8.0 for JSR-223 JavaScript execution.</li>
<li>Update <code>javax.mail</code> to 1.6.2 from 1.5.0-b01, so mail attachments with non-ASCII file names are encoded correctly.</li>
</ul>

<h3>UI</h3>
Expand All @@ -109,6 +110,7 @@ Summary
<ch_section>Bug fixes</ch_section>
<h3>General</h3>
<ul>
<li><issue>6652</issue>SMTP Sampler encoded non-ASCII attachment file names incorrectly. Attachment file names are now encoded according to RFC 2231 by upgrading <code>javax.mail</code> to 1.6.2.</li>
<li><pr>6654</pr><issue>6611</issue>Support JDK 25 and above for result collectors with empty file names</li>
<li>Trim whitespace when parsing numeric JMeter properties so accidental spaces do not silently change configuration values.</li>
<li><pr>6372</pr>Fix KeyManager logging when using CLI mode so keystore passwords are not incorrectly reported as missing. Contributed by Patrick Uiterwijk (patrick at puiterwijk.org)</li>
Expand Down