jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject [jmeter] branch master updated: Encode the personal part of email addresses in SMTP Sampler
Date Sat, 27 Feb 2021 16:09:47 GMT
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git


The following commit(s) were added to refs/heads/master by this push:
     new d10b0e5  Encode the personal part of email addresses in SMTP Sampler
d10b0e5 is described below

commit d10b0e54bc2450a0ebd908c28380a91c08e795aa
Author: Felix Schumacher <felix.schumacher@internetallee.de>
AuthorDate: Sat Feb 20 11:03:02 2021 +0100

    Encode the personal part of email addresses in SMTP Sampler
    
    Often those personal parts contain umlauts. Try to find these
    and let MimeUtility encode those as quoted encodings.
    
    Bugzilla Id: 65149
    Closes #644 on github
---
 .../jmeter/protocol/smtp/sampler/SmtpSampler.java  | 23 ++++++++++++++++++++--
 xdocs/changes.xml                                  |  1 +
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java
b/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java
index 70697b5..a1fedc1 100644
--- a/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java
+++ b/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java
@@ -20,6 +20,7 @@ package org.apache.jmeter.protocol.smtp.sampler;
 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;
@@ -38,10 +39,12 @@ import javax.mail.Part;
 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;
@@ -272,7 +275,7 @@ public class SmtpSampler extends AbstractSampler {
         sendMailCmd.setEnableDebug(getPropertyAsBoolean(ENABLE_DEBUG));
 
         if (getPropertyAsString(MAIL_FROM).matches(".*@.*")) {
-            sendMailCmd.setSender(getPropertyAsString(MAIL_FROM));
+            sendMailCmd.setSender(encodeAddress(getPropertyAsString(MAIL_FROM)));
         }
 
         // Process address lists
@@ -368,7 +371,7 @@ public class SmtpSampler extends AbstractSampler {
         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 {
@@ -376,6 +379,22 @@ public class SmtpSampler extends AbstractSampler {
         }
     }
 
+    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)
      */
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index 4df2d5b..d4554c3 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -83,6 +83,7 @@ Summary
 
 <h3>Other samplers</h3>
 <ul>
+  <li><bug>65149</bug><pr>644</pr>Encode the personal part
of email addresses in SMTP Sampler</li>
 </ul>
 
 <h3>Controllers</h3>


Mime
View raw message