james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [10/10] james-project git commit: JAMES-2370 JMAP text search filter should include attachmentFileName
Date Wed, 18 Apr 2018 00:37:02 GMT
JAMES-2370 JMAP text search filter should include attachmentFileName


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

Branch: refs/heads/master
Commit: 3c379ddb4a601dbac88eaff51a228eca752addeb
Parents: c778ee1
Author: benwa <btellier@linagora.com>
Authored: Mon Apr 9 14:21:48 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Wed Apr 18 07:36:01 2018 +0700

----------------------------------------------------------------------
 .../integration/GetMessageListMethodTest.java   | 67 ++++++++++++++++++++
 .../james/jmap/utils/FilterToSearchQuery.java   |  3 +-
 .../jmap/utils/FilterToSearchQueryTest.java     |  3 +-
 3 files changed, 71 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/3c379ddb/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java
index 16f5805..0bf5c62 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java
@@ -2036,6 +2036,73 @@ public abstract class GetMessageListMethodTest {
             .body(ARGUMENTS + ".messageIds", contains(message2.getMessageId().serialize()));
     }
 
+    @Test
+    public void getMessageListFileNameFilterShouldNotReturnMessagesWithOnlyAttachmentContentMatching()
throws Exception {
+        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, ALICE, "mailbox");
+
+        mailboxProbe.appendMessage(ALICE, MailboxPath.forUser(ALICE, "mailbox"),
+            MessageManager.AppendCommand.builder()
+                .build(Message.Builder.of()
+                    .setBody(
+                        MultipartBuilder.create("alternative")
+                            .addBodyPart(BodyPartBuilder.create()
+                                .setContentDisposition("attachment", "nomatch.md")
+                                .setBody(SingleBodyBuilder.create()
+                                    .setText("matchme.txt ...")
+                                    .setCharset(StandardCharsets.UTF_8)
+                                    .build())
+                                .build())
+                            .build())));
+
+        await();
+
+        given()
+            .header("Authorization", aliceAccessToken.serialize())
+            .body("[[\"getMessageList\", {\"filter\":{\"attachmentFileName\":\"matchme.txt\"}},
\"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .body(NAME, equalTo("messageList"))
+            .body(ARGUMENTS + ".messageIds", hasSize(0));
+    }
+
+    @Test
+    public void getMessageListTextFilterShouldReturnOnlyMessagesWithMatchingAttachmentFileNames()
throws Exception {
+        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, ALICE, "mailbox");
+
+        ComposedMessageId message1 = mailboxProbe.appendMessage(ALICE, MailboxPath.forUser(ALICE,
"mailbox"),
+            MessageManager.AppendCommand.builder()
+                .build(Message.Builder.of()
+                    .setSubject("test")
+                    .setBody("content", StandardCharsets.UTF_8)));
+        ComposedMessageId message2 = mailboxProbe.appendMessage(ALICE, MailboxPath.forUser(ALICE,
"mailbox"),
+            MessageManager.AppendCommand.builder()
+                .build(Message.Builder.of()
+                    .setBody(
+                        MultipartBuilder.create("alternative")
+                            .addBodyPart(BodyPartBuilder.create()
+                                .setContentDisposition("attachment", "matchme.txt")
+                                .setBody(SingleBodyBuilder.create()
+                                    .setText("this is the file content...")
+                                    .setCharset(StandardCharsets.UTF_8)
+                                    .build())
+                                .build())
+                            .build())));
+
+        await();
+
+        given()
+            .header("Authorization", aliceAccessToken.serialize())
+            .body("[[\"getMessageList\", {\"filter\":{\"text\":\"matchme.txt\"}}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .body(NAME, equalTo("messageList"))
+            .body(ARGUMENTS + ".messageIds", contains(message2.getMessageId().serialize()));
+    }
+
     private Date convertToDate(LocalDate localDate) {
         return Date.from(localDate.atStartOfDay(ZONE_ID).toInstant());
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/3c379ddb/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/FilterToSearchQuery.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/FilterToSearchQuery.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/FilterToSearchQuery.java
index 5f14323..ac5b97e 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/FilterToSearchQuery.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/FilterToSearchQuery.java
@@ -60,7 +60,8 @@ public class FilterToSearchQuery {
                         SearchQuery.address(AddressType.Bcc, text),
                         SearchQuery.headerContains("Subject", text),
                         SearchQuery.attachmentContains(text),
-                        SearchQuery.bodyContains(text)))
+                        SearchQuery.bodyContains(text),
+                        SearchQuery.attachmentFileName(text)))
                 ));
         filter.getFrom().ifPresent(from -> searchQuery.andCriteria(SearchQuery.address(AddressType.From,
from)));
         filter.getTo().ifPresent(to -> searchQuery.andCriteria(SearchQuery.address(AddressType.To,
to)));

http://git-wip-us.apache.org/repos/asf/james-project/blob/3c379ddb/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/FilterToSearchQueryTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/FilterToSearchQueryTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/FilterToSearchQueryTest.java
index 5ff9a2a..0d54306 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/FilterToSearchQueryTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/FilterToSearchQueryTest.java
@@ -184,7 +184,8 @@ public class FilterToSearchQueryTest {
                 SearchQuery.address(AddressType.Bcc, text),
                 SearchQuery.headerContains("Subject", text),
                 SearchQuery.bodyContains(text),
-                SearchQuery.attachmentContains(text))));
+                SearchQuery.attachmentContains(text),
+                SearchQuery.attachmentFileName(text))));
 
         SearchQuery searchQuery = new FilterToSearchQuery().convert(FilterCondition.builder()
                 .text(text)


---------------------------------------------------------------------
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