james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [12/24] james-project git commit: JAMES-2142 Add Attachments search filter
Date Wed, 13 Sep 2017 10:57:38 GMT
JAMES-2142 Add Attachments search filter


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

Branch: refs/heads/master
Commit: 38db514f54cc902df15bfc1785f527f91861c43d
Parents: 33846e6
Author: Antoine Duprat <aduprat@linagora.com>
Authored: Fri Sep 8 10:45:39 2017 +0200
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Wed Sep 13 10:20:56 2017 +0200

----------------------------------------------------------------------
 .../james/jmap/model/FilterCondition.java       | 20 +++++++++++++++++---
 .../james/jmap/utils/FilterToSearchQuery.java   |  1 +
 .../james/jmap/model/FilterConditionTest.java   |  4 +++-
 .../jmap/utils/FilterToSearchQueryTest.java     | 13 +++++++++++++
 4 files changed, 34 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/38db514f/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 334667d..0dd14a1 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
@@ -60,6 +60,7 @@ public class FilterCondition implements Filter {
         private String bcc;
         private String subject;
         private String body;
+        private String attachments;
         private Header header;
         private Optional<String> hasKeyword;
         private Optional<String> notKeyword;
@@ -185,6 +186,11 @@ public class FilterCondition implements Filter {
             return this;
         }
 
+        public Builder attachments(String attachments) {
+            this.attachments = attachments;
+            return this;
+        }
+
         public Builder header(Header header) {
             this.header = header;
             return this;
@@ -196,7 +202,7 @@ public class FilterCondition implements Filter {
             return new FilterCondition(inMailboxes, notInMailboxes, Optional.ofNullable(before),
Optional.ofNullable(after), Optional.ofNullable(minSize), Optional.ofNullable(maxSize),
                     Optional.ofNullable(isFlagged), Optional.ofNullable(isUnread), Optional.ofNullable(isAnswered),
Optional.ofNullable(isDraft), 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(header), hasKeyword, notKeyword);
+                    Optional.ofNullable(body), Optional.ofNullable(attachments), Optional.ofNullable(header),
hasKeyword, notKeyword);
         }
     }
 
@@ -218,6 +224,7 @@ public class FilterCondition implements Filter {
     private final Optional<String> bcc;
     private final Optional<String> subject;
     private final Optional<String> body;
+    private final Optional<String> attachments;
     private final Optional<Header> header;
     private final Optional<String> hasKeyword;
     private final Optional<String> notKeyword;
@@ -225,7 +232,7 @@ public class FilterCondition implements Filter {
     @VisibleForTesting FilterCondition(Optional<List<String>> inMailboxes, Optional<List<String>>
notInMailboxes, Optional<ZonedDateTime> before, Optional<ZonedDateTime> after,
Optional<Integer> minSize, Optional<Integer> maxSize,
                                        Optional<Boolean> isFlagged, Optional<Boolean>
isUnread, Optional<Boolean> isAnswered, Optional<Boolean> isDraft, 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<Header>
header, Optional<String> hasKeyword, Optional<String> notKeyword) {
+                                       Optional<String> body, Optional<String>
attachments, Optional<Header> header, Optional<String> hasKeyword, Optional<String>
notKeyword) {
 
         this.inMailboxes = inMailboxes;
         this.notInMailboxes = notInMailboxes;
@@ -245,6 +252,7 @@ public class FilterCondition implements Filter {
         this.bcc = bcc;
         this.subject = subject;
         this.body = body;
+        this.attachments = attachments;
         this.header = header;
         this.hasKeyword = hasKeyword;
         this.notKeyword = notKeyword;
@@ -322,6 +330,10 @@ public class FilterCondition implements Filter {
         return body;
     }
 
+    public Optional<String> getAttachments() {
+        return attachments;
+    }
+
     public Optional<Header> getHeader() {
         return header;
     }
@@ -356,6 +368,7 @@ public class FilterCondition implements Filter {
                 && Objects.equals(this.bcc, other.bcc)
                 && Objects.equals(this.subject, other.subject)
                 && Objects.equals(this.body, other.body)
+                && Objects.equals(this.attachments, other.attachments)
                 && Objects.equals(this.header, other.header)
                 && Objects.equals(this.hasKeyword, other.hasKeyword)
                 && Objects.equals(this.notKeyword, other.notKeyword);
@@ -366,7 +379,7 @@ public class FilterCondition implements Filter {
     @Override
     public final int hashCode() {
         return Objects.hash(inMailboxes, notInMailboxes, before, after, minSize, maxSize,
isFlagged, isUnread, isAnswered, isDraft, hasAttachment,
-                text, from, to, cc, bcc, subject, body, header, hasKeyword, notKeyword);
+                text, from, to, cc, bcc, subject, body, attachments, header, hasKeyword,
notKeyword);
     }
 
     @Override
@@ -390,6 +403,7 @@ public class FilterCondition implements Filter {
         bcc.ifPresent(x -> helper.add("bcc", x));
         subject.ifPresent(x -> helper.add("subject", x));
         body.ifPresent(x -> helper.add("body", x));
+        attachments.ifPresent(x -> helper.add("attachments", x));
         header.ifPresent(x -> helper.add("header", x));
         hasKeyword.ifPresent(x -> helper.add("hasKeyword", x));
         notKeyword.ifPresent(x -> helper.add("notKeyword", x));

http://git-wip-us.apache.org/repos/asf/james-project/blob/38db514f/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 f357628..d364b59 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
@@ -67,6 +67,7 @@ public class FilterToSearchQuery {
         filter.getCc().ifPresent(cc -> searchQuery.andCriteria(SearchQuery.address(AddressType.Cc,
cc)));
         filter.getBcc().ifPresent(bcc -> searchQuery.andCriteria(SearchQuery.address(AddressType.Bcc,
bcc)));
         filter.getSubject().ifPresent(subject -> searchQuery.andCriteria(SearchQuery.headerContains("Subject",
subject)));
+        filter.getAttachments().ifPresent(attachments ->  searchQuery.andCriteria(SearchQuery.attachmentContains(attachments)));
         filter.getBody().ifPresent(body ->  searchQuery.andCriteria(SearchQuery.bodyContains(body)));
         filter.getAfter().ifPresent(after -> searchQuery.andCriteria(SearchQuery.sentDateAfter(Date.from(after.toInstant()),
DateResolution.Second)));
         filter.getBefore().ifPresent(before -> searchQuery.andCriteria(SearchQuery.sentDateBefore(Date.from(before.toInstant()),
DateResolution.Second)));

http://git-wip-us.apache.org/repos/asf/james-project/blob/38db514f/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 79c232f..828c94a 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
@@ -93,13 +93,14 @@ public class FilterConditionTest {
         String bcc = "blindcopy@james.org";
         String subject = "subject";
         String body = "body";
+        String attachments = "attachments";
         Header header = Header.from(ImmutableList.of("name", "value"));
         Optional<String> hasKeyword = Optional.of("$Draft");
         Optional<String> notKeyword = Optional.of("$Flagged");
 
         FilterCondition expectedFilterCondition = new FilterCondition(Optional.of(ImmutableList.of("1")),
Optional.of(ImmutableList.of("2")), Optional.of(before), Optional.of(after), Optional.of(minSize),
Optional.of(maxSize),
                 Optional.of(isFlagged), Optional.of(isUnread), Optional.of(isAnswered), Optional.of(isDraft),
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(header),
+                Optional.of(to), Optional.of(cc), Optional.of(bcc), Optional.of(subject),
Optional.of(body), Optional.of(attachments), Optional.of(header),
                 hasKeyword, notKeyword);
 
         FilterCondition filterCondition = FilterCondition.builder()
@@ -121,6 +122,7 @@ public class FilterConditionTest {
                 .bcc(bcc)
                 .subject(subject)
                 .body(body)
+                .attachments(attachments)
                 .header(header)
                 .hasKeyword(hasKeyword)
                 .notKeyword(notKeyword)

http://git-wip-us.apache.org/repos/asf/james-project/blob/38db514f/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 0662003..857af1f 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
@@ -161,6 +161,19 @@ public class FilterToSearchQueryTest {
     }
 
     @Test
+    public void filterConditionShouldMapWhenAttachments() {
+        String attachments = "attachments";
+        SearchQuery expectedSearchQuery = new SearchQuery();
+        expectedSearchQuery.andCriteria(SearchQuery.attachmentContains(attachments));
+
+        SearchQuery searchQuery = new FilterToSearchQuery().convert(FilterCondition.builder()
+                .attachments(attachments)
+                .build());
+
+        assertThat(searchQuery).isEqualTo(expectedSearchQuery);
+    }
+
+    @Test
     public void filterConditionShouldMapWhenText() {
         String text = "text";
         SearchQuery expectedSearchQuery = new SearchQuery();


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