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

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


The following commit(s) were added to refs/heads/master by this push:
     new 8e9dbd7  NIFI-7366 - ConsumeEWS Processor parse EML
8e9dbd7 is described below

commit 8e9dbd73350dce7e3aff1cf0734eeaa3b449d78e
Author: Jérémie <jerem...@gmail.com>
AuthorDate: Thu Apr 16 18:19:20 2020 -0400

    NIFI-7366 - ConsumeEWS Processor parse EML
    
    https://issues.apache.org/jira/browse/NIFI-7366
    
    This commit allows to retrieve ItemAttachement (such as EML) file when 
pulling mail.
    
    Signed-off-by: Pierre Villard <pierre.villard...@gmail.com>
    
    This closes #4215.
---
 .../apache/nifi/processors/email/ConsumeEWS.java   | 24 +++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git 
a/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/src/main/java/org/apache/nifi/processors/email/ConsumeEWS.java
 
b/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/src/main/java/org/apache/nifi/processors/email/ConsumeEWS.java
index aeeb5ee..00abff7 100644
--- 
a/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/src/main/java/org/apache/nifi/processors/email/ConsumeEWS.java
+++ 
b/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/src/main/java/org/apache/nifi/processors/email/ConsumeEWS.java
@@ -21,6 +21,7 @@ import 
microsoft.exchange.webservices.data.core.ExchangeService;
 import microsoft.exchange.webservices.data.core.PropertySet;
 import 
microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
 import microsoft.exchange.webservices.data.core.enumeration.property.BodyType;
+import 
microsoft.exchange.webservices.data.core.enumeration.property.BasePropertySet;
 import 
microsoft.exchange.webservices.data.core.enumeration.property.WellKnownFolderName;
 import 
microsoft.exchange.webservices.data.core.enumeration.search.FolderTraversal;
 import 
microsoft.exchange.webservices.data.core.enumeration.search.LogicalOperator;
@@ -36,6 +37,7 @@ import 
microsoft.exchange.webservices.data.core.service.schema.ItemSchema;
 import microsoft.exchange.webservices.data.credential.ExchangeCredentials;
 import microsoft.exchange.webservices.data.credential.WebCredentials;
 import microsoft.exchange.webservices.data.property.complex.FileAttachment;
+import microsoft.exchange.webservices.data.property.complex.ItemAttachment;
 import microsoft.exchange.webservices.data.search.FindFoldersResults;
 import microsoft.exchange.webservices.data.search.FindItemsResults;
 import microsoft.exchange.webservices.data.search.FolderView;
@@ -451,13 +453,25 @@ public class ConsumeEWS extends AbstractProcessor {
         if(ewsMessage.getHasAttachments()){
             ewsMessage.getAttachments().forEach(x->{
                 try {
-                    FileAttachment file = (FileAttachment)x;
-                    file.load();
+                    if(x instanceof FileAttachment) {
+                        FileAttachment file = (FileAttachment) x;
+                        file.load();
 
-                    String type = file.getContentType() == null ? "text/plain" 
: file.getContentType();
-                    ByteArrayDataSource bds = new 
ByteArrayDataSource(file.getContent(), type);
+                        String type = file.getContentType() == null ? 
"text/plain" : file.getContentType();
+                        ByteArrayDataSource bds = new 
ByteArrayDataSource(file.getContent(), type);
 
-                    mm.attach(bds,file.getName(), "", 
EmailAttachment.ATTACHMENT);
+                        mm.attach(bds, file.getName(), "", 
EmailAttachment.ATTACHMENT);
+                    } else { // x instanceof ItemAttachment
+                        ItemAttachment eml = (ItemAttachment) x;
+                        PropertySet oPropSetForBodyText = new 
PropertySet(BasePropertySet.FirstClassProperties);
+                        oPropSetForBodyText.add(ItemSchema.MimeContent);
+                        eml.load(oPropSetForBodyText);
+
+                        Item it = eml.getItem();
+                        ByteArrayDataSource bds = new 
ByteArrayDataSource(it.getMimeContent().getContent(), "text/plain");
+
+                        mm.attach(bds, eml.getName(), "", 
EmailAttachment.ATTACHMENT);
+                    }
                 } catch (MessagingException e) {
                     e.printStackTrace();
                 } catch (Exception e) {

Reply via email to