james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [04/10] james-project git commit: JAMES-2370 JMAP layer should define `attachmentFileName` filter for GetMessageList
Date Wed, 18 Apr 2018 00:36:56 GMT
JAMES-2370 JMAP layer should define `attachmentFileName` filter for GetMessageList


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

Branch: refs/heads/master
Commit: d33bf76d10a9dfea460b705df1d7c47fe91740f5
Parents: 7f0b2f8
Author: benwa <btellier@linagora.com>
Authored: Mon Apr 9 13:10:46 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Wed Apr 18 07:35:07 2018 +0700

----------------------------------------------------------------------
 .../james/jmap/model/FilterCondition.java       | 23 ++++++++++++++++----
 .../james/jmap/utils/FilterToSearchQuery.java   |  4 ++++
 .../james/jmap/model/FilterConditionTest.java   |  4 +++-
 .../jmap/utils/FilterToSearchQueryTest.java     |  9 ++++++++
 4 files changed, 35 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d33bf76d/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterCondition.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterCondition.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterCondition.java
index f98cec0..f6b89aa 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterCondition.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterCondition.java
@@ -65,12 +65,14 @@ public class FilterCondition implements Filter {
         private Header header;
         private Optional<String> hasKeyword;
         private Optional<String> notKeyword;
+        private Optional<String> attachmentFileName;
 
         private Builder() {
             inMailboxes = Optional.empty();
             notInMailboxes = Optional.empty();
             hasKeyword = Optional.empty();
             notKeyword = Optional.empty();
+            attachmentFileName = Optional.empty();
         }
 
         public Builder inMailboxes(String... inMailboxes) {
@@ -204,6 +206,11 @@ public class FilterCondition implements Filter {
             return this;
         }
 
+        public Builder attachmentFileName(Optional<String> attachmentFileName) {
+            this.attachmentFileName = attachmentFileName;
+            return this;
+        }
+
         public FilterCondition build() {
             Preconditions.checkArgument(!hasKeyword.isPresent() || (new Keyword(hasKeyword.get())
!= null), "hasKeyword is not valid");
             Preconditions.checkArgument(!notKeyword.isPresent() || (new Keyword(notKeyword.get())
!= null), "notKeyword is not valid");
@@ -211,7 +218,7 @@ public class FilterCondition implements Filter {
                     Optional.ofNullable(isFlagged), Optional.ofNullable(isUnread), Optional.ofNullable(isAnswered),
Optional.ofNullable(isDraft), Optional.ofNullable(isForwarded),
                     Optional.ofNullable(hasAttachment),
                     Optional.ofNullable(text), Optional.ofNullable(from), Optional.ofNullable(to),
Optional.ofNullable(cc), Optional.ofNullable(bcc), Optional.ofNullable(subject),
-                    Optional.ofNullable(body), Optional.ofNullable(attachments), Optional.ofNullable(header),
hasKeyword, notKeyword);
+                    Optional.ofNullable(body), Optional.ofNullable(attachments), Optional.ofNullable(header),
hasKeyword, notKeyword, attachmentFileName);
         }
     }
 
@@ -238,12 +245,13 @@ public class FilterCondition implements Filter {
     private final Optional<Header> header;
     private final Optional<String> hasKeyword;
     private final Optional<String> notKeyword;
+    private final Optional<String> attachmentFileName;
 
     @VisibleForTesting FilterCondition(Optional<List<String>> inMailboxes, Optional<List<String>>
notInMailboxes, Optional<ZonedDateTime> before, Optional<ZonedDateTime> after,
Optional<Number> minSize, Optional<Number> maxSize,
                                        Optional<Boolean> isFlagged, Optional<Boolean>
isUnread, Optional<Boolean> isAnswered, Optional<Boolean> isDraft, Optional<Boolean>
isForwarded,
                                        Optional<Boolean> hasAttachment,
                                        Optional<String> text, Optional<String>
from, Optional<String> to, Optional<String> cc, Optional<String> bcc, Optional<String>
subject,
-                                       Optional<String> body, Optional<String>
attachments, Optional<Header> header, Optional<String> hasKeyword, Optional<String>
notKeyword) {
+                                       Optional<String> body, Optional<String>
attachments, Optional<Header> header, Optional<String> hasKeyword, Optional<String>
notKeyword, Optional<String> attachmentFileName) {
 
         this.inMailboxes = inMailboxes;
         this.notInMailboxes = notInMailboxes;
@@ -268,6 +276,7 @@ public class FilterCondition implements Filter {
         this.header = header;
         this.hasKeyword = hasKeyword;
         this.notKeyword = notKeyword;
+        this.attachmentFileName = attachmentFileName;
     }
 
     public Optional<List<String>> getInMailboxes() {
@@ -362,6 +371,10 @@ public class FilterCondition implements Filter {
         return notKeyword;
     }
 
+    public Optional<String> getAttachmentFileName() {
+        return attachmentFileName;
+    }
+
     @Override
     public final boolean equals(Object obj) {
         if (obj instanceof FilterCondition) {
@@ -388,7 +401,8 @@ public class FilterCondition implements Filter {
                 && Objects.equals(this.attachments, other.attachments)
                 && Objects.equals(this.header, other.header)
                 && Objects.equals(this.hasKeyword, other.hasKeyword)
-                && Objects.equals(this.notKeyword, other.notKeyword);
+                && Objects.equals(this.notKeyword, other.notKeyword)
+                && Objects.equals(this.attachmentFileName, other.attachmentFileName);
         }
         return false;
     }
@@ -396,7 +410,7 @@ public class FilterCondition implements Filter {
     @Override
     public final int hashCode() {
         return Objects.hash(inMailboxes, notInMailboxes, before, after, minSize, maxSize,
isFlagged, isUnread, isAnswered, isDraft, isForwarded, hasAttachment,
-                text, from, to, cc, bcc, subject, body, attachments, header, hasKeyword,
notKeyword);
+                text, from, to, cc, bcc, subject, body, attachments, header, hasKeyword,
notKeyword, attachmentFileName);
     }
 
     @Override
@@ -425,6 +439,7 @@ public class FilterCondition implements Filter {
         header.ifPresent(x -> helper.add("header", x));
         hasKeyword.ifPresent(x -> helper.add("hasKeyword", x));
         notKeyword.ifPresent(x -> helper.add("notKeyword", x));
+        attachmentFileName.ifPresent(x -> helper.add("attachmentFileName", x));
         return helper.toString();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/d33bf76d/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 af1abf0..9e47c86 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,6 +24,7 @@ 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;
@@ -88,6 +89,9 @@ public class FilterToSearchQuery {
             keywordQuery(notKeyword, false).ifPresent(notKeywordCriterion
                 -> searchQuery.andCriteria(notKeywordCriterion));
         });
+        filter.getAttachmentFileName().ifPresent(attachmentFileName -> {
+            throw new NotImplementedException("`attachmentFileName` criterion is not yet
handled by `mailbox-api`");
+        });
 
         return searchQuery;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d33bf76d/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/FilterConditionTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/FilterConditionTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/FilterConditionTest.java
index 73bfcf7..246cf70 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/FilterConditionTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/FilterConditionTest.java
@@ -98,12 +98,13 @@ public class FilterConditionTest {
         Header header = Header.from(ImmutableList.of("name", "value"));
         Optional<String> hasKeyword = Optional.of("$Draft");
         Optional<String> notKeyword = Optional.of("$Flagged");
+        Optional<String> attachmentFileName = Optional.of("file.txt");
 
         FilterCondition expectedFilterCondition = new FilterCondition(Optional.of(ImmutableList.of("1")),
Optional.of(ImmutableList.of("2")), Optional.of(before), Optional.of(after),
                 Optional.of(Number.fromLong(minSize)), Optional.of(Number.fromLong(maxSize)),
                 Optional.of(isFlagged), Optional.of(isUnread), Optional.of(isAnswered), Optional.of(isDraft),
Optional.of(isForwarded), Optional.of(hasAttachment), Optional.of(text), Optional.of(from),
                 Optional.of(to), Optional.of(cc), Optional.of(bcc), Optional.of(subject),
Optional.of(body), Optional.of(attachments), Optional.of(header),
-                hasKeyword, notKeyword);
+                hasKeyword, notKeyword, attachmentFileName);
 
         FilterCondition filterCondition = FilterCondition.builder()
                 .inMailboxes(Optional.of(ImmutableList.of("1")))
@@ -129,6 +130,7 @@ public class FilterConditionTest {
                 .header(header)
                 .hasKeyword(hasKeyword)
                 .notKeyword(notKeyword)
+                .attachmentFileName(attachmentFileName)
                 .build();
 
         assertThat(filterCondition).isEqualToComparingFieldByField(expectedFilterCondition);

http://git-wip-us.apache.org/repos/asf/james-project/blob/d33bf76d/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 bb36e15..693e856 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,6 +28,7 @@ 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;
@@ -540,4 +541,12 @@ public class FilterToSearchQueryTest {
 
         assertThat(searchQuery).isEqualTo(expectedSearchQuery);
     }
+
+    @Test
+    public void attachmentFileNameShouldNotBeImplemented() {
+        assertThatThrownBy(() -> new FilterToSearchQuery().convert(FilterCondition.builder()
+                .attachmentFileName(Optional.of("file.gz"))
+                .build()))
+            .isInstanceOf(NotImplementedException.class);
+    }
 }


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