Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
Expand All @@ -38,10 +39,12 @@
import javax.mail.internet.AddressException;
import javax.mail.internet.ContentType;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeUtility;

import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.CountingOutputStream;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.config.ConfigTestElement;
import org.apache.jmeter.protocol.smtp.sampler.gui.SecuritySettingsPanel;
import org.apache.jmeter.protocol.smtp.sampler.protocol.SendMailCommand;
Expand Down Expand Up @@ -272,7 +275,7 @@ private SendMailCommand createSendMailCommandFromProperties() throws AddressExce
sendMailCmd.setEnableDebug(getPropertyAsBoolean(ENABLE_DEBUG));

if (getPropertyAsString(MAIL_FROM).matches(".*@.*")) {
sendMailCmd.setSender(getPropertyAsString(MAIL_FROM));
sendMailCmd.setSender(encodeAddress(getPropertyAsString(MAIL_FROM)));
}

// Process address lists
Expand Down Expand Up @@ -368,14 +371,30 @@ private List<InternetAddress> getPropAsAddresses(String propKey) throws AddressE
if (!propValue.isEmpty()) { // we have at least one potential address
List<InternetAddress> addresses = new ArrayList<>();
for (String address : propValue.split(";")) {
addresses.add(new InternetAddress(address.trim()));
addresses.add(new InternetAddress(encodeAddress(address)));
}
return addresses;
} else {
return null;
}
}

private String encodeAddress(String address) throws AddressException {
String trimmedAddress = address.trim();
if (!StringUtils.isAsciiPrintable(trimmedAddress)) {
try {
final int startOfRealAddress = trimmedAddress.indexOf('<');
if (startOfRealAddress >= 0) {
String personalPart = trimmedAddress.substring(0, startOfRealAddress);
return MimeUtility.encodeWord(personalPart) + trimmedAddress.substring(startOfRealAddress);
}
} catch (UnsupportedEncodingException e) {
log.warn("Can't encode [{}] as quoted printable", trimmedAddress, e);
}
}
return trimmedAddress;
}

/**
* @see org.apache.jmeter.samplers.AbstractSampler#applies(org.apache.jmeter.config.ConfigTestElement)
*/
Expand Down