JAMES-1833 Unknown content disposition should not be considered as attachment

A map in Optional was useless. I modified so that code reach its intent and 
added a failing test.


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/d44eeb13
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/d44eeb13
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/d44eeb13

Branch: refs/heads/master
Commit: d44eeb13ef005d27250953ca303745a7a373b83f
Parents: 0d685ea
Author: Benoit Tellier <btell...@linagora.com>
Authored: Thu Oct 13 10:40:18 2016 +0200
Committer: Benoit Tellier <btell...@linagora.com>
Committed: Fri Oct 14 08:59:05 2016 +0200

----------------------------------------------------------------------
 .../store/mail/model/impl/MessageParser.java    |  2 +-
 .../mail/model/impl/MessageParserTest.java      |  7 ++++++
 .../test/resources/eml/unknownDisposition.eml   | 24 ++++++++++++++++++++
 3 files changed, 32 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d44eeb13/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
index 6a80385..2be3e84 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
@@ -183,7 +183,7 @@ public class MessageParser {
                     public Boolean apply(String dispositionType) {
                         return 
ATTACHMENT_CONTENT_DISPOSITIONS.contains(dispositionType.toLowerCase());
                     }
-                }).isPresent();
+                }).or(false);
     }
 
     private boolean isTextPart(Entity part) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/d44eeb13/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
index 02aeaa1..a3a97b1 100644
--- 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
+++ 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
@@ -177,4 +177,11 @@ public class MessageParserTest {
         
         assertThat(attachments).hasSize(6);
     }
+
+    @Test
+    public void 
getAttachmentsShouldNotConsiderUnknownContentDispositionAsAttachments() throws 
Exception {
+        List<MessageAttachment> attachments = 
testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/unknownDisposition.eml"));
+
+        assertThat(attachments).hasSize(0);
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d44eeb13/mailbox/store/src/test/resources/eml/unknownDisposition.eml
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/resources/eml/unknownDisposition.eml 
b/mailbox/store/src/test/resources/eml/unknownDisposition.eml
new file mode 100644
index 0000000..4a0a724
--- /dev/null
+++ b/mailbox/store/src/test/resources/eml/unknownDisposition.eml
@@ -0,0 +1,24 @@
+To: m...@linagora.com
+From: Benoit Tellier <m...@linagora.com>
+Subject: Mail with text attachment
+Message-ID: <befd8cab-9c9c-5537-4e77-937f32326...@any.com>
+Date: Thu, 13 Oct 2016 10:26:20 +0200
+MIME-Version: 1.0
+Content-Type: multipart/mixed;
+ boundary="------------4FD2D252DB453546C22C25B2"
+
+This is a multi-part message in MIME format.
+--------------4FD2D252DB453546C22C25B2
+Content-Type: text/plain; charset=utf-8
+Content-Transfer-Encoding: 7bit
+
+I'm the body!
+
+--------------4FD2D252DB453546C22C25B2
+Content-Type: text/plain; charset=UTF-8;
+ name="attachment.txt"
+Content-Disposition: gabouzomeuh;
+ filename="attachment.txt"
+
+I'm a Schroedinger cat
+--------------4FD2D252DB453546C22C25B2--
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to