james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [2/3] james-project git commit: JAMES-1926 hasAttachments should not take care of inline attachments
Date Thu, 09 Feb 2017 10:43:02 GMT
JAMES-1926 hasAttachments should not take care of inline attachments


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

Branch: refs/heads/master
Commit: 9d0fc97b5ca227c652f5d98816560c25009347a0
Parents: 11b9eee
Author: Antoine Duprat <aduprat@linagora.com>
Authored: Tue Feb 7 15:40:37 2017 +0100
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Thu Feb 9 09:45:07 2017 +0100

----------------------------------------------------------------------
 .../src/test/resources/eml/multipartRelated.eml |   2 +-
 .../org/apache/james/jmap/model/Message.java    |   9 +-
 .../apache/james/jmap/model/MessageTest.java    | 120 +++++++++++++++++++
 3 files changed, 129 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/9d0fc97b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/multipartRelated.eml
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/multipartRelated.eml
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/multipartRelated.eml
index b2e8232..df4e366 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/multipartRelated.eml
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/multipartRelated.eml
@@ -29,7 +29,7 @@ Content-Transfer-Encoding: 7bit
 ------=_Part_1787_1274970450.1471867607209
 Content-Type: image/png; name=gimp.png
 Content-Transfer-Encoding: base64
-Content-Disposition: inline; filename=gimp.png
+Content-Disposition: attachment; filename=gimp.png
 Content-ID: <image.part.1@linshare.org>
 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAALxklEQVR4Ae2Xe0xUZ97H5X4RiyAXEARURBSYCzNnLjMwwAx3huGOIBcUFJERAUVRq+KlwHABFdu+b9+0766x1W21ttnUtE3rul6aGNtm3XbdWncjaa3VXrZRK6IgfPd3Tp6wOGmyo0v/cOMknxwy5xzO7/P8LueZaWlpaU80TwWeCvy3CcRwXJlUqp39RApIOE4i5hQPxBz30hMpIJIrjktkseMimfzPUyoglilTf/XVl8u1Ik4xrOJEEMu4wSkVEMmVZ6VSTeivFXy0TDZfIlfc0qil0KpIQM59P6UCUk71lVShPD1t2jT7qQ4+Sq32prq/GhfHjSXFSxGvEfMCQ1MsoLzOadT3pArFwBQ3LSdRqK4mJyfcz0xRwaCLRVKcBDEybmxqBRTKH8uXpEOj0/1MD3wuMTHR8T9adY4LoOD3KuPj7xYVGlGYo0e6gUNKoowkpKBmHpXJZO5TKXCrpjwT5pWFSM1IvROrVH0hksujf+laAHYWi8XT+nsKyIlvVKlSeVSu0twtXpI/Yq4rR2lBKoxpamQmK5Gm55CcIAP1wxAvOWUCEk4xVLvchIaVedi8rgq1NSXjqnjdHcrGayK5yhStVPpbLLvE/Xt6Tnf3Wu529XSM9fZ13Wzbse2kJiGhK1ap/ETCqe5lGLNum+trxnZsbca6tcuwJM+AvKw4mNI1yEpVURYUSE2S8wJ3RSKN35QJUJPdM6/IQ8vaCmzdZMbObU2w7G7BhhbzeEFR4e2SsrIRChqnz5zE999/h9HREXz19SDefOt1dPW0Y8e2Frywtx0vDnRg57NrUVdTgJJ8PYpyEpBvjEdOhvahLIg55YOioiKHRxKgjwPBEaHEQzfz/3DH9mb07+nGsbeO4MjRw+jts8DS3or/GdiNnr4ufP6XC/jhh+9w587PuHdvGLdv38SNG9fwwYfvon9vN3Zvb0Td8
 lxUlqSirCgZpSRQnJuIgmwdcikL2elqZKU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kISXURCpR6enl1b1g0eLP+d8KsQrlqEqjGtHr48ezMmhMFmWiqsyEylIjivNSKPBEJBu0UKoVD0Qy+djC6Oir7h4eA/R/mvw87FdXK13PbsyPHOnt7aAtyQmBQ4dfHe3p7by187ntOXTdPCKDcLZVwIFwI7yIQGLepCxomUQ50Ui0UTD/5+Pr925waOifFi6OuiaKlQ1JOOUYMU6CozGx8uHIqJjr/kFBJ11cXJ6ne7YSZmIpkUJoWxqXv2fp2n133/49d44de1OQOHr0CAIC/Meio6MhkUhA110jNhL21gLWEvaTGtmbmM0kFk3KRCKRRZQR9cQGoo3oIHppJPfTsY/oJtqJbUQLUUeUshVNIJSExMvLK9rT03P+upbGVd09nZfo9/XPJlM2/P390dnZKRAWFsZL8JT+OwG7SRLuxEzCn5VTOBHFRJREPKEn0ggTUcRWtoJRyr4zscwlEXHsXinLbDgbn37sWW7bdm2L9/Pzu+nu7o6NGzeitbWVshEAlokvCPsJARskXFlPeDORYJaRCCYjZuWlYNnREFqGhlCxczJ27WJ279xJgXsRHmyAOLJnnyTAQxkVjvPnz4evry94eWuBX5RgOEwSmU54ErOYzGxiDhHGpMKJCCvC2bkwFvBsFrQ3m3bTWeBO7Fl2jPUErKFy44/p1gK2ijgSzkzGnfBgQcxkAfkwfBk+DG9iJrvWg93ryoJ2nBy41bMPWQvQ7pk/LrMSeCQRe8JhkpATk3JhQblZ4crOOVsFLGwTrAOfDLv3AAErWq0FHldm
 ktQEDlbYM+yseYTnLSOGCDD6H1/ARilrpuD/LyYuMoFDVgJPBqx3/p84YS3wpInonmQBxlOBpwJPBf4JszXhha5WvGwAAAAASUVORK5CYII=

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d0fc97b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java
index 5937560..4799b3f 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java
@@ -222,7 +222,7 @@ public class Message {
             ImmutableList<Attachment> attachments = this.attachments.build();
             ImmutableMap<BlobId, SubMessage> attachedMessages = this.attachedMessages.build();
             Preconditions.checkState(areAttachedMessagesKeysInAttachments(attachments, attachedMessages),
"'attachedMessages' keys must be in 'attachements'");
-            boolean hasAttachment = !attachments.isEmpty();
+            boolean hasAttachment = hasAttachment(attachments);
 
             return new Message(id, blobId, threadId, mailboxIds, Optional.ofNullable(inReplyToMessageId),
isUnread, isFlagged, isAnswered, isDraft, hasAttachment, headers, Optional.ofNullable(from),
                     to.build(), cc.build(), bcc.build(), replyTo.build(), subject, date,
size, preview, Optional.ofNullable(textBody), Optional.ofNullable(htmlBody), attachments,
attachedMessages);
@@ -242,6 +242,13 @@ public class Message {
         };
     }
 
+    private static boolean hasAttachment(List<Attachment> attachments) {
+        return attachments.stream()
+                .filter(attachment -> !attachment.isIsInline())
+                .findAny()
+                .isPresent();
+    }
+
     private final MessageId id;
     private final BlobId blobId;
     private final String threadId;

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d0fc97b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
index 0407c36..3ecac4a 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
@@ -255,4 +255,124 @@ public class MessageTest {
                     .build()))
             .build();
     }
+
+    @Test
+    public void hasAttachmentShouldReturnFalseWhenNoAttachment() throws Exception {
+        Message message = Message.builder()
+            .id(TestMessageId.of(1))
+            .blobId(BlobId.of("blobId"))
+            .threadId("threadId")
+            .mailboxId(InMemoryId.of(456))
+            .headers(ImmutableMap.of("key", "value"))
+            .subject("subject")
+            .size(1)
+            .date(ZonedDateTime.now())
+            .preview("preview")
+            .attachments(ImmutableList.of())
+            .build();
+
+        assertThat(message.isHasAttachment()).isFalse();
+    }
+
+    @Test
+    public void hasAttachmentShouldReturnFalseWhenAllAttachmentsAreInline() throws Exception
{
+        Message message = Message.builder()
+            .id(TestMessageId.of(1))
+            .blobId(BlobId.of("blobId"))
+            .threadId("threadId")
+            .mailboxId(InMemoryId.of(456))
+            .headers(ImmutableMap.of("key", "value"))
+            .subject("subject")
+            .size(1)
+            .date(ZonedDateTime.now())
+            .preview("preview")
+            .attachments(ImmutableList.of(
+                    Attachment.builder()
+                        .blobId(BlobId.of("key"))
+                        .size(1)
+                        .type("type")
+                        .isInline(true)
+                        .build(),
+                    Attachment.builder()
+                        .blobId(BlobId.of("key2"))
+                        .size(2)
+                        .type("type2")
+                        .isInline(true)
+                        .build()))
+            .build();
+
+        assertThat(message.isHasAttachment()).isFalse();
+    }
+
+    @Test
+    public void hasAttachmentShouldReturnTrueWhenOneAttachmentIsNotInline() throws Exception
{
+        Message message = Message.builder()
+            .id(TestMessageId.of(1))
+            .blobId(BlobId.of("blobId"))
+            .threadId("threadId")
+            .mailboxId(InMemoryId.of(456))
+            .headers(ImmutableMap.of("key", "value"))
+            .subject("subject")
+            .size(1)
+            .date(ZonedDateTime.now())
+            .preview("preview")
+            .attachments(ImmutableList.of(
+                    Attachment.builder()
+                        .blobId(BlobId.of("key"))
+                        .size(1)
+                        .type("type")
+                        .isInline(true)
+                        .build(),
+                    Attachment.builder()
+                        .blobId(BlobId.of("key2"))
+                        .size(2)
+                        .type("type2")
+                        .isInline(false)
+                        .build(),
+                    Attachment.builder()
+                        .blobId(BlobId.of("key3"))
+                        .size(3)
+                        .type("type3")
+                        .isInline(true)
+                        .build()))
+            .build();
+
+        assertThat(message.isHasAttachment()).isTrue();
+    }
+
+    @Test
+    public void hasAttachmentShouldReturnTrueWhenAllAttachmentsAreNotInline() throws Exception
{
+        Message message = Message.builder()
+            .id(TestMessageId.of(1))
+            .blobId(BlobId.of("blobId"))
+            .threadId("threadId")
+            .mailboxId(InMemoryId.of(456))
+            .headers(ImmutableMap.of("key", "value"))
+            .subject("subject")
+            .size(1)
+            .date(ZonedDateTime.now())
+            .preview("preview")
+            .attachments(ImmutableList.of(
+                    Attachment.builder()
+                        .blobId(BlobId.of("key"))
+                        .size(1)
+                        .type("type")
+                        .isInline(false)
+                        .build(),
+                    Attachment.builder()
+                        .blobId(BlobId.of("key2"))
+                        .size(2)
+                        .type("type2")
+                        .isInline(false)
+                        .build(),
+                    Attachment.builder()
+                        .blobId(BlobId.of("key3"))
+                        .size(3)
+                        .type("type3")
+                        .isInline(false)
+                        .build()))
+            .build();
+
+        assertThat(message.isHasAttachment()).isTrue();
+    }
 }


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


Mime
View raw message