NIFI-6834 Encoding attachment filename

Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com>

This closes #3865.
This commit is contained in:
Nicholas Zhan 2019-11-02 22:11:46 +08:00 committed by Pierre Villard
parent 0a26296276
commit af0777b2c9
No known key found for this signature in database
GPG Key ID: BEE1599F0726E9CD
2 changed files with 6 additions and 2 deletions

View File

@ -385,7 +385,7 @@ public class PutEmail extends AbstractProcessor {
}
});
mimeFile.setFileName(flowFile.getAttribute(CoreAttributes.FILENAME.key()));
mimeFile.setFileName(MimeUtility.encodeText(flowFile.getAttribute(CoreAttributes.FILENAME.key())));
MimeMultipart multipart = new MimeMultipart();
multipart.addBodyPart(mimeText);
multipart.addBodyPart(mimeFile);

View File

@ -36,6 +36,7 @@ import javax.mail.internet.MimeUtility;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.StringUtils;
import org.apache.commons.io.IOUtils;
import org.apache.nifi.flowfile.attributes.CoreAttributes;
import org.apache.nifi.util.LogMessage;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
@ -228,7 +229,9 @@ public class TestPutEmail {
runner.setProperty(PutEmail.CONTENT_TYPE, "text/html");
runner.setProperty(PutEmail.TO, "recipient@apache.org");
runner.enqueue("Some text".getBytes());
Map<String, String> attributes = new HashMap<>();
attributes.put(CoreAttributes.FILENAME.key(), "test한的ほу́.pdf");
runner.enqueue("Some text".getBytes(), attributes);
runner.run();
@ -253,6 +256,7 @@ public class TestPutEmail {
final BodyPart attachPart = multipart.getBodyPart(1);
final InputStream attachIs = attachPart.getDataHandler().getInputStream();
final String text = IOUtils.toString(attachIs, "UTF-8");
assertEquals("test한的ほу́.pdf", MimeUtility.decodeText(attachPart.getFileName()));
assertEquals("Some text", text);
assertNull(message.getRecipients(RecipientType.BCC));