james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [06/10] james-project git commit: JAMES-2370 Define fileName criterion in Search Query
Date Wed, 18 Apr 2018 00:36:58 GMT
JAMES-2370 Define fileName criterion in Search Query


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

Branch: refs/heads/master
Commit: 49b6e7668d33f954a76470c5e25c23dfd9a6d573
Parents: d33bf76
Author: benwa <btellier@linagora.com>
Authored: Mon Apr 9 13:19:22 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Wed Apr 18 07:35:38 2018 +0700

----------------------------------------------------------------------
 .../org/apache/james/mailbox/model/SearchQuery.java  | 10 +++++++++-
 .../apache/james/jmap/utils/FilterToSearchQuery.java | 15 +++------------
 .../james/jmap/utils/FilterToSearchQueryTest.java    | 15 +++++++++------
 3 files changed, 21 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/49b6e766/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
index fedab42..7925368 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
@@ -670,6 +670,10 @@ public class SearchQuery implements Serializable {
         }
     }
 
+    public static Criterion attachmentFileName(String fileName) {
+        return new TextCriterion(fileName, Scope.ATTACHMENT_FILE_NAME);
+    }
+
     public static Criterion hasAttachment() {
         return hasAttachment(true);
     }
@@ -1105,7 +1109,11 @@ public class SearchQuery implements Serializable {
         /** Full message content including headers and attachments */
         FULL,
         /** Attachment content */
-        ATTACHMENTS
+        ATTACHMENTS,
+
+        /** Attachment file name, specified on Content-Disposition
+         * header of mime body parts */
+        ATTACHMENT_FILE_NAME
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/49b6e766/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 9e47c86..5f14323 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
@@ -24,7 +24,6 @@ import java.util.Optional;
 
 import javax.mail.Flags.Flag;
 
-import org.apache.commons.lang3.NotImplementedException;
 import org.apache.james.jmap.model.Filter;
 import org.apache.james.jmap.model.FilterCondition;
 import org.apache.james.jmap.model.FilterOperator;
@@ -81,17 +80,9 @@ public class FilterToSearchQuery {
         filter.getMaxSize().ifPresent(maxSize -> searchQuery.andCriteria(SearchQuery.sizeLessThan(maxSize.asLong())));
         filter.getMinSize().ifPresent(minSize -> searchQuery.andCriteria(SearchQuery.sizeGreaterThan(minSize.asLong())));
         filter.getHasAttachment().ifPresent(hasAttachment -> searchQuery.andCriteria(SearchQuery.hasAttachment(hasAttachment)));
-        filter.getHasKeyword().ifPresent(hasKeyword -> {
-            keywordQuery(hasKeyword, true).ifPresent(hasKeywordCriterion
-                -> searchQuery.andCriteria(hasKeywordCriterion));
-        });
-        filter.getNotKeyword().ifPresent(notKeyword -> {
-            keywordQuery(notKeyword, false).ifPresent(notKeywordCriterion
-                -> searchQuery.andCriteria(notKeywordCriterion));
-        });
-        filter.getAttachmentFileName().ifPresent(attachmentFileName -> {
-            throw new NotImplementedException("`attachmentFileName` criterion is not yet
handled by `mailbox-api`");
-        });
+        filter.getHasKeyword().ifPresent(hasKeyword -> keywordQuery(hasKeyword, true).ifPresent(searchQuery::andCriteria));
+        filter.getNotKeyword().ifPresent(notKeyword -> keywordQuery(notKeyword, false).ifPresent(searchQuery::andCriteria));
+        filter.getAttachmentFileName().ifPresent(attachmentFileName -> searchQuery.andCriteria(SearchQuery.attachmentFileName(attachmentFileName)));
 
         return searchQuery;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/49b6e766/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 693e856..5ff9a2a 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
@@ -28,7 +28,6 @@ import java.util.Optional;
 
 import javax.mail.Flags.Flag;
 
-import org.apache.commons.lang3.NotImplementedException;
 import org.apache.james.jmap.model.Filter;
 import org.apache.james.jmap.model.FilterCondition;
 import org.apache.james.jmap.model.FilterOperator;
@@ -543,10 +542,14 @@ public class FilterToSearchQueryTest {
     }
 
     @Test
-    public void attachmentFileNameShouldNotBeImplemented() {
-        assertThatThrownBy(() -> new FilterToSearchQuery().convert(FilterCondition.builder()
-                .attachmentFileName(Optional.of("file.gz"))
-                .build()))
-            .isInstanceOf(NotImplementedException.class);
+    public void attachmentFileNameShouldMapWhenHasAttachmentFileName() {
+        String fileName = "file.gz";
+
+        SearchQuery expectedResult = new SearchQuery(SearchQuery.attachmentFileName(fileName));
+
+        assertThat(new FilterToSearchQuery().convert(FilterCondition.builder()
+            .attachmentFileName(Optional.of(fileName))
+            .build()))
+            .isEqualTo(expectedResult);
     }
 }


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