james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [3/5] james-project git commit: JAMES-2213 OldKeyword will support isForwarded now and - Converting from Keyword to OldKeyword - Add needed unit testing
Date Tue, 14 Nov 2017 09:04:53 GMT
JAMES-2213 OldKeyword will support isForwarded now and
- Converting from Keyword to OldKeyword
- Add needed unit testing


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

Branch: refs/heads/master
Commit: b1e43fca9e419630ce2b9125618c1c52632c5db4
Parents: 3aa1732
Author: quynhn <qnguyen@linagora.com>
Authored: Mon Nov 13 10:53:14 2017 +0700
Committer: quynhn <qnguyen@linagora.com>
Committed: Tue Nov 14 10:27:40 2017 +0700

----------------------------------------------------------------------
 .../james/jmap/model/CreationMessage.java       | 11 ++++-
 .../org/apache/james/jmap/model/Keyword.java    |  1 +
 .../org/apache/james/jmap/model/Keywords.java   |  3 ++
 .../org/apache/james/jmap/model/OldKeyword.java | 18 ++++++--
 .../james/jmap/model/UpdateMessagePatch.java    | 11 ++++-
 .../apache/james/jmap/model/KeywordsTest.java   | 48 +++++++++++++++-----
 6 files changed, 72 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b1e43fca/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/CreationMessage.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/CreationMessage.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/CreationMessage.java
index f67185d..8bcbe4b 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/CreationMessage.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/CreationMessage.java
@@ -27,6 +27,7 @@ import java.util.Objects;
 import java.util.Optional;
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
+
 import javax.mail.internet.AddressException;
 import javax.mail.internet.InternetAddress;
 
@@ -62,6 +63,7 @@ public class CreationMessage {
         private Optional<Boolean> isFlagged = Optional.empty();
         private Optional<Boolean> isAnswered = Optional.empty();
         private Optional<Boolean> isDraft = Optional.empty();
+        private Optional<Boolean> isForwarded = Optional.empty();
         private final ImmutableMap.Builder<String, String> headers;
         private Optional<DraftEmailer> from = Optional.empty();
         private final ImmutableList.Builder<DraftEmailer> to;
@@ -121,6 +123,11 @@ public class CreationMessage {
             return this;
         }
 
+        public Builder isForwarded(Optional<Boolean> isForwarded) {
+            this.isForwarded = isForwarded;
+            return this;
+        }
+
         public Builder headers(ImmutableMap<String, String> headers) {
             this.headers.putAll(headers);
             return this;
@@ -225,8 +232,8 @@ public class CreationMessage {
         }
 
         private Optional<OldKeyword> getOldKeywords() {
-            if (isAnswered.isPresent() || isFlagged.isPresent() || isUnread.isPresent() ||
isDraft.isPresent()) {
-                return Optional.of(new OldKeyword(isUnread, isFlagged, isAnswered, isDraft));
+            if (isAnswered.isPresent() || isFlagged.isPresent() || isUnread.isPresent() ||
isDraft.isPresent() || isForwarded.isPresent()) {
+                return Optional.of(new OldKeyword(isUnread, isFlagged, isAnswered, isDraft,
isForwarded));
             }
             return Optional.empty();
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1e43fca/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Keyword.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Keyword.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Keyword.java
index 72918d0..ca18d2b 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Keyword.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Keyword.java
@@ -46,6 +46,7 @@ public class Keyword {
     public final static Keyword ANSWERED = new Keyword("$Answered");
     public final static Keyword DELETED = new Keyword("$Deleted");
     public final static Keyword RECENT = new Keyword("$Recent");
+    public final static Keyword FORWARDED = new Keyword("$Forwarded");
     public final static Boolean FLAG_VALUE = true;
 
     private final static ImmutableList<Keyword> NON_EXPOSED_IMAP_KEYWORDS = ImmutableList.of(Keyword.RECENT,
Keyword.DELETED);

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1e43fca/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Keywords.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Keywords.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Keywords.java
index c410cf9..286468f 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Keywords.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Keywords.java
@@ -126,6 +126,9 @@ public class Keywords {
             if (oldKeyword.isUnread().isPresent() && oldKeyword.isUnread().get()
== false) {
                 builder.add(Keyword.SEEN);
             }
+            if (oldKeyword.isForwarded().orElse(false)) {
+                builder.add(Keyword.FORWARDED);
+            }
             return fromSet(builder.build());
         }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1e43fca/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/OldKeyword.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/OldKeyword.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/OldKeyword.java
index e2cb2b3..207b275 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/OldKeyword.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/OldKeyword.java
@@ -30,20 +30,24 @@ public class OldKeyword {
     private final Optional<Boolean> isFlagged;
     private final Optional<Boolean> isAnswered;
     private final Optional<Boolean> isDraft;
+    private final Optional<Boolean> isForwarded;
 
     @VisibleForTesting
-    OldKeyword(boolean isUnread, boolean isFlagged, boolean isAnswered, boolean isDraft)
{
+    OldKeyword(boolean isUnread, boolean isFlagged, boolean isAnswered, boolean isDraft,
boolean isForwarded) {
         this.isUnread = Optional.of(isUnread);
         this.isFlagged = Optional.of(isFlagged);
         this.isAnswered = Optional.of(isAnswered);
         this.isDraft = Optional.of(isDraft);
+        this.isForwarded = Optional.of(isForwarded);
     }
 
-    public OldKeyword(Optional<Boolean> isUnread, Optional<Boolean> isFlagged,
Optional<Boolean> isAnswered, Optional<Boolean> isDraft) {
+    public OldKeyword(Optional<Boolean> isUnread, Optional<Boolean> isFlagged,
Optional<Boolean> isAnswered,
+                      Optional<Boolean> isDraft, Optional<Boolean> isForwarded)
{
         this.isUnread = isUnread;
         this.isFlagged = isFlagged;
         this.isAnswered = isAnswered;
         this.isDraft = isDraft;
+        this.isForwarded = isForwarded;
     }
 
     public Optional<Boolean> isUnread() {
@@ -62,6 +66,10 @@ public class OldKeyword {
         return isDraft;
     }
 
+    public Optional<Boolean> isForwarded() {
+        return isForwarded;
+    }
+
     @Override
     public final boolean equals(Object other) {
         if (other instanceof OldKeyword) {
@@ -69,14 +77,15 @@ public class OldKeyword {
             return Objects.equal(isUnread, oldKeyword.isUnread)
                 && Objects.equal(isFlagged, oldKeyword.isFlagged)
                 && Objects.equal(isAnswered, oldKeyword.isAnswered)
-                && Objects.equal(isDraft, oldKeyword.isDraft);
+                && Objects.equal(isDraft, oldKeyword.isDraft)
+                && Objects.equal(isForwarded, oldKeyword.isForwarded);
         }
         return false;
     }
 
     @Override
     public final int hashCode() {
-        return Objects.hashCode(isUnread, isFlagged, isAnswered, isDraft);
+        return Objects.hashCode(isUnread, isFlagged, isAnswered, isDraft, isForwarded);
     }
 
     @Override
@@ -86,6 +95,7 @@ public class OldKeyword {
                 .add("isFlagged", isFlagged)
                 .add("isAnswered", isAnswered)
                 .add("isDraft", isDraft)
+                .add("isForwarded", isForwarded)
                 .toString();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1e43fca/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UpdateMessagePatch.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UpdateMessagePatch.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UpdateMessagePatch.java
index 6a46bf8..49a2ac8 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UpdateMessagePatch.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UpdateMessagePatch.java
@@ -23,6 +23,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
+
 import javax.mail.Flags;
 
 import org.apache.james.jmap.methods.ValidationResult;
@@ -48,6 +49,7 @@ public class UpdateMessagePatch {
         private Optional<Boolean> isFlagged = Optional.empty();
         private Optional<Boolean> isUnread = Optional.empty();
         private Optional<Boolean> isAnswered = Optional.empty();
+        private Optional<Boolean> isForwarded = Optional.empty();
         private Optional<Map<String, Boolean>> keywords = Optional.empty();
         private Set<ValidationResult> validationResult = Sets.newHashSet();
 
@@ -76,6 +78,11 @@ public class UpdateMessagePatch {
             return this;
         }
 
+        public Builder isForwarded(Boolean isForwarded) {
+            this.isForwarded = Optional.of(isForwarded);
+            return this;
+        }
+
         public Builder validationResult(Set<ValidationResult> validationResult) {
             this.validationResult.addAll(validationResult);
             return this;
@@ -97,9 +104,9 @@ public class UpdateMessagePatch {
         }
 
         private Optional<OldKeyword> getOldKeywords() {
-            if (isAnswered.isPresent() || isFlagged.isPresent() || isUnread.isPresent())
{
+            if (isAnswered.isPresent() || isFlagged.isPresent() || isUnread.isPresent() ||
isForwarded.isPresent()) {
                 Optional<Boolean> isDraft = Optional.empty();
-                return Optional.of(new OldKeyword(isUnread, isFlagged, isAnswered, isDraft));
+                return Optional.of(new OldKeyword(isUnread, isFlagged, isAnswered, isDraft,
isForwarded));
             }
             return Optional.empty();
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1e43fca/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/KeywordsTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/KeywordsTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/KeywordsTest.java
index e992c59..5fa1d56 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/KeywordsTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/KeywordsTest.java
@@ -20,21 +20,23 @@
 package org.apache.james.jmap.model;
 
 import static org.assertj.core.api.Assertions.assertThat;
+
 import java.util.Map;
 import java.util.Optional;
+
 import javax.mail.Flags;
 import javax.mail.Flags.Flag;
 
 import org.apache.james.mailbox.FlagsBuilder;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 public class KeywordsTest {
     public static final String ANY_KEYWORD = "AnyKeyword";
@@ -87,21 +89,37 @@ public class KeywordsTest {
         Optional<Boolean> isUnread = Optional.empty();
         Optional<Boolean> isFlagged = Optional.empty();
         Optional<Boolean> isDraft = Optional.empty();
+        Optional<Boolean> isForwarded = Optional.empty();
         Keywords keywords = Keywords.factory()
-            .fromOldKeyword(new OldKeyword(isUnread, isFlagged, isAnswered, isDraft));
+            .fromOldKeyword(new OldKeyword(isUnread, isFlagged, isAnswered, isDraft, isForwarded));
 
         assertThat(keywords.getKeywords())
             .containsOnly(Keyword.ANSWERED);
     }
 
     @Test
+    public void fromOldKeywordsShouldReturnKeywordsFromIsForwarded() throws Exception {
+        Optional<Boolean> isAnswered = Optional.empty();
+        Optional<Boolean> isUnread = Optional.empty();
+        Optional<Boolean> isFlagged = Optional.empty();
+        Optional<Boolean> isDraft = Optional.empty();
+        Optional<Boolean> isForwarded = Optional.of(true);
+        Keywords keywords = Keywords.factory()
+            .fromOldKeyword(new OldKeyword(isUnread, isFlagged, isAnswered, isDraft, isForwarded));
+
+        assertThat(keywords.getKeywords())
+            .containsOnly(Keyword.FORWARDED);
+    }
+
+    @Test
     public void fromOldKeywordsShouldReturnKeywordsFromIsDraft() throws Exception {
         Optional<Boolean> isAnswered = Optional.empty();
         Optional<Boolean> isUnread = Optional.empty();
         Optional<Boolean> isFlagged = Optional.empty();
         Optional<Boolean> isDraft = Optional.of(true);
+        Optional<Boolean> isForwarded = Optional.empty();
         Keywords keywords = Keywords.factory()
-            .fromOldKeyword(new OldKeyword(isUnread, isFlagged, isAnswered, isDraft));
+            .fromOldKeyword(new OldKeyword(isUnread, isFlagged, isAnswered, isDraft, isForwarded));
 
         assertThat(keywords.getKeywords())
             .containsOnly(Keyword.DRAFT);
@@ -113,8 +131,9 @@ public class KeywordsTest {
         Optional<Boolean> isUnread = Optional.empty();
         Optional<Boolean> isFlagged = Optional.of(true);
         Optional<Boolean> isDraft = Optional.empty();
+        Optional<Boolean> isForwarded = Optional.empty();
         Keywords keywords = Keywords.factory()
-            .fromOldKeyword(new OldKeyword(isUnread, isFlagged, isAnswered, isDraft));
+            .fromOldKeyword(new OldKeyword(isUnread, isFlagged, isAnswered, isDraft, isForwarded));
 
         assertThat(keywords.getKeywords())
             .containsOnly(Keyword.FLAGGED);
@@ -126,8 +145,9 @@ public class KeywordsTest {
         Optional<Boolean> isUnread = Optional.of(false);
         Optional<Boolean> isFlagged = Optional.empty();
         Optional<Boolean> isDraft = Optional.empty();
+        Optional<Boolean> isForwarded = Optional.empty();
         Keywords keywords = Keywords.factory()
-            .fromOldKeyword(new OldKeyword(isUnread, isFlagged, isAnswered, isDraft));
+            .fromOldKeyword(new OldKeyword(isUnread, isFlagged, isAnswered, isDraft, isForwarded));
 
         assertThat(keywords.getKeywords())
             .containsOnly(Keyword.SEEN);
@@ -139,8 +159,9 @@ public class KeywordsTest {
         Optional<Boolean> isUnread = Optional.of(true);
         Optional<Boolean> isFlagged = Optional.of(true);
         Optional<Boolean> isDraft = Optional.of(true);
+        Optional<Boolean> isForwarded = Optional.empty();
         Keywords keywords = Keywords.factory()
-            .fromOldKeyword(new OldKeyword(isUnread, isFlagged, isAnswered, isDraft));
+            .fromOldKeyword(new OldKeyword(isUnread, isFlagged, isAnswered, isDraft, isForwarded));
 
         assertThat(keywords.getKeywords())
             .containsOnly(Keyword.ANSWERED, Keyword.DRAFT, Keyword.FLAGGED);
@@ -166,8 +187,9 @@ public class KeywordsTest {
         Optional<Boolean> isUnread = Optional.of(true);
         Optional<Boolean> isFlagged = Optional.of(true);
         Optional<Boolean> isDraft = Optional.of(true);
+        Optional<Boolean> isForwarded = Optional.of(true);
 
-        OldKeyword oldKeyword = new OldKeyword(isUnread, isFlagged, isAnswered, isDraft);
+        OldKeyword oldKeyword = new OldKeyword(isUnread, isFlagged, isAnswered, isDraft,
isForwarded);
 
         assertThat(Keywords.factory()
             .fromMapOrOldKeyword(Optional.empty(), Optional.of(oldKeyword)))
@@ -181,8 +203,9 @@ public class KeywordsTest {
         Optional<Boolean> isUnread = Optional.of(true);
         Optional<Boolean> isFlagged = Optional.of(true);
         Optional<Boolean> isDraft = Optional.of(true);
+        Optional<Boolean> isForwarded = Optional.of(true);
 
-        OldKeyword oldKeyword = new OldKeyword(isUnread, isFlagged, isAnswered, isDraft);
+        OldKeyword oldKeyword = new OldKeyword(isUnread, isFlagged, isAnswered, isDraft,
isForwarded);
 
         Keywords.factory()
             .fromMapOrOldKeyword(Optional.of(ImmutableMap.of()), Optional.of(oldKeyword));
@@ -205,14 +228,15 @@ public class KeywordsTest {
         Optional<Boolean> isUnread = Optional.of(true);
         Optional<Boolean> isFlagged = Optional.of(true);
         Optional<Boolean> isDraft = Optional.of(true);
+        Optional<Boolean> isForwarded = Optional.of(true);
 
-        OldKeyword oldKeyword = new OldKeyword(isUnread, isFlagged, isAnswered, isDraft);
+        OldKeyword oldKeyword = new OldKeyword(isUnread, isFlagged, isAnswered, isDraft,
isForwarded);
 
         Keywords keywords = Keywords.factory()
             .fromMapOrOldKeyword(Optional.empty(), Optional.of(oldKeyword))
             .get();
         assertThat(keywords.getKeywords())
-            .containsOnly(Keyword.ANSWERED, Keyword.DRAFT, Keyword.FLAGGED);
+            .containsOnly(Keyword.ANSWERED, Keyword.DRAFT, Keyword.FLAGGED, Keyword.FORWARDED);
     }
 
     @Test


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