This is an automated email from the ASF dual-hosted git repository.

exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new 0719a8113f NIFI-13827 Added Reply-To Property to PutEmail (#9332)
0719a8113f is described below

commit 0719a8113faca8b848aee496a30f13ed31c14378
Author: Vincenzo Abate <[email protected]>
AuthorDate: Tue Oct 8 17:56:51 2024 +0200

    NIFI-13827 Added Reply-To Property to PutEmail (#9332)
    
    Co-authored-by: Vincenzo Abate <[email protected]>
    Signed-off-by: David Handermann <[email protected]>
---
 .../org/apache/nifi/processors/standard/PutEmail.java  | 18 +++++++++++++++++-
 .../apache/nifi/processors/standard/TestPutEmail.java  |  7 +++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git 
a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutEmail.java
 
b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutEmail.java
index 2772dec176..a48aa8c5a8 100644
--- 
a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutEmail.java
+++ 
b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutEmail.java
@@ -237,6 +237,15 @@ public class PutEmail extends AbstractProcessor {
             
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
             .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
             .build();
+    public static final PropertyDescriptor REPLY_TO = new 
PropertyDescriptor.Builder()
+        .name("Reply-To")
+        .description("The recipients that will receive the reply instead of 
the from (see RFC2822 §3.6.2)."
+            + "This feature is useful, for example, when the email is sent by 
a no-reply account. This field is optional."
+            + "Comma separated sequence of addresses following RFC822 syntax.")
+        .required(false)
+        
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+        .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+        .build();
     public static final PropertyDescriptor SUBJECT = new 
PropertyDescriptor.Builder()
             .name("Subject")
             .description("The email subject")
@@ -304,6 +313,7 @@ public class PutEmail extends AbstractProcessor {
             TO,
             CC,
             BCC,
+            REPLY_TO,
             SUBJECT,
             MESSAGE,
             CONTENT_AS_MESSAGE,
@@ -422,6 +432,7 @@ public class PutEmail extends AbstractProcessor {
             message.setRecipients(RecipientType.TO, toInetAddresses(context, 
flowFile, TO));
             message.setRecipients(RecipientType.CC, toInetAddresses(context, 
flowFile, CC));
             message.setRecipients(RecipientType.BCC, toInetAddresses(context, 
flowFile, BCC));
+            message.setReplyTo(toInetAddresses(context, flowFile, REPLY_TO));
 
             if (attributeNamePattern != null) {
                 for (final Map.Entry<String, String> entry : 
flowFile.getAttributes().entrySet()) {
@@ -459,7 +470,12 @@ public class PutEmail extends AbstractProcessor {
                 final MimeBodyPart mimeFile = new MimeBodyPart();
                 session.read(flowFile, stream -> {
                     try {
-                        mimeFile.setDataHandler(new DataHandler(new 
ByteArrayDataSource(stream, "application/octet-stream")));
+                        final String mimeTypeAttribute = 
flowFile.getAttribute("mime.type");
+                        String mimeType = "application/octet-stream";
+                        if (mimeTypeAttribute != null && 
!mimeTypeAttribute.isEmpty()) {
+                            mimeType = mimeTypeAttribute;
+                        }
+                        mimeFile.setDataHandler(new DataHandler(new 
ByteArrayDataSource(stream, mimeType)));
                     } catch (final Exception e) {
                         throw new IOException(e);
                     }
diff --git 
a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutEmail.java
 
b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutEmail.java
index c45ee6a91d..405bc8f7eb 100644
--- 
a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutEmail.java
+++ 
b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutEmail.java
@@ -185,6 +185,7 @@ public class TestPutEmail {
         runner.setProperty(PutEmail.TO, "${to}");
         runner.setProperty(PutEmail.BCC, "${bcc}");
         runner.setProperty(PutEmail.CC, "${cc}");
+        runner.setProperty(PutEmail.REPLY_TO, "${reply-to}");
         runner.setProperty(PutEmail.ATTRIBUTE_NAME_REGEX, "Precedence.*");
         runner.setProperty(PutEmail.INPUT_CHARACTER_SET, 
StandardCharsets.UTF_8.name());
 
@@ -194,6 +195,7 @@ public class TestPutEmail {
         attributes.put("to", "[email protected]");
         attributes.put("bcc", "[email protected]");
         attributes.put("cc", "[email protected]");
+        attributes.put("reply-to", "[email protected]");
         attributes.put("Precedence", "bulk");
         attributes.put("PrecedenceEncodeDecodeTest", "búlk");
         runner.enqueue("Some Text".getBytes(), attributes);
@@ -215,6 +217,8 @@ public class TestPutEmail {
         assertEquals("[email protected]", 
message.getRecipients(RecipientType.BCC)[0].toString());
         assertEquals(1, message.getRecipients(RecipientType.CC).length);
         assertEquals("[email protected]", 
message.getRecipients(RecipientType.CC)[0].toString());
+        assertEquals(1, message.getReplyTo().length);
+        assertEquals("[email protected]", 
message.getReplyTo()[0].toString());
         assertEquals("bulk", 
MimeUtility.decodeText(message.getHeader("Precedence")[0]));
         assertEquals("búlk", 
MimeUtility.decodeText(message.getHeader("PrecedenceEncodeDecodeTest")[0]));
     }
@@ -267,6 +271,7 @@ public class TestPutEmail {
 
         Map<String, String> attributes = new HashMap<>();
         attributes.put(CoreAttributes.FILENAME.key(), "test한的ほу́.pdf");
+        attributes.put(CoreAttributes.MIME_TYPE.key(), "application/pdf");
         runner.enqueue("Some text".getBytes(), attributes);
 
         runner.run();
@@ -290,7 +295,9 @@ public class TestPutEmail {
         final BodyPart attachPart = multipart.getBodyPart(1);
         final InputStream attachIs = 
attachPart.getDataHandler().getInputStream();
         final String text = IOUtils.toString(attachIs, StandardCharsets.UTF_8);
+        final String mimeType = attachPart.getDataHandler().getContentType();
         assertEquals("test한的ほу́.pdf", 
MimeUtility.decodeText(attachPart.getFileName()));
+        assertEquals("application/pdf", mimeType);
         assertEquals("Some text", text);
 
         assertNull(message.getRecipients(RecipientType.BCC));

Reply via email to