mirror of
https://github.com/apache/nifi.git
synced 2025-03-03 16:09:19 +00:00
NIFI-13827 Added Reply-To Property to PutEmail (#9332)
Co-authored-by: Vincenzo Abate <vincenzo.abate@teratecnologies.es> Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
parent
7188155d50
commit
0719a8113f
@ -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);
|
||||
}
|
||||
|
@ -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", "to@apache.org");
|
||||
attributes.put("bcc", "bcc@apache.org");
|
||||
attributes.put("cc", "cc@apache.org");
|
||||
attributes.put("reply-to", "replytome@apache.org");
|
||||
attributes.put("Precedence", "bulk");
|
||||
attributes.put("PrecedenceEncodeDecodeTest", "búlk");
|
||||
runner.enqueue("Some Text".getBytes(), attributes);
|
||||
@ -215,6 +217,8 @@ public class TestPutEmail {
|
||||
assertEquals("bcc@apache.org", message.getRecipients(RecipientType.BCC)[0].toString());
|
||||
assertEquals(1, message.getRecipients(RecipientType.CC).length);
|
||||
assertEquals("cc@apache.org", message.getRecipients(RecipientType.CC)[0].toString());
|
||||
assertEquals(1, message.getReplyTo().length);
|
||||
assertEquals("replytome@apache.org", 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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user