james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [5/6] james-project git commit: JAMES-2195 Flag sanitizing upon setInMailboxes
Date Thu, 26 Oct 2017 22:59:12 GMT
JAMES-2195 Flag sanitizing upon setInMailboxes


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

Branch: refs/heads/master
Commit: 4c0721456ef1fafb0065deefa22efc054305a950
Parents: 6b49e6c
Author: benwa <btellier@linagora.com>
Authored: Tue Oct 24 14:23:17 2017 +0700
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Fri Oct 27 00:56:22 2017 +0200

----------------------------------------------------------------------
 .../mailbox/hbase/mail/HBaseMailboxMessage.java |   4 +-
 .../jcr/mail/model/JCRMailboxMessage.java       |   4 +-
 .../openjpa/AbstractJPAMailboxMessage.java      |   4 +-
 .../mailbox/store/ImmutableMailboxMessage.java  |   4 +-
 .../mailbox/store/StoreMessageIdManager.java    |  18 ++-
 .../mail/model/DelegatingMailboxMessage.java    |   2 +-
 .../mailbox/store/mail/model/FlagsBuilder.java  |  55 --------
 .../mailbox/store/mail/model/FlagsFactory.java  | 130 +++++++++++++++++++
 .../mailbox/store/mail/model/FlagsFilter.java   |  87 +++++++++++++
 .../mail/model/impl/SimpleMailboxMessage.java   |  37 ++++--
 .../AbstractMessageIdManagerStorageTest.java    |  70 ++++++++--
 .../store/StoreMessageIdManagerTestSystem.java  |   3 +
 .../store/mail/model/FlagsFactoryTest.java      | 118 +++++++++++++++++
 .../store/mail/model/FlagsFilterTest.java       |  74 +++++++++++
 .../CassandraSetMessagesMethodCucumberTest.java |   3 +-
 .../test/resources/cucumber/SetMessages.feature |   1 -
 .../MemorySetMessagesMethodCucumberTest.java    |   3 +-
 17 files changed, 522 insertions(+), 95 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4c072145/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java
index 3fe7f48..0c16eef 100644
--- a/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java
+++ b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java
@@ -44,7 +44,7 @@ import org.apache.james.mailbox.model.ComposedMessageId;
 import org.apache.james.mailbox.model.ComposedMessageIdWithMetaData;
 import org.apache.james.mailbox.model.MessageAttachment;
 import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.store.mail.model.FlagsBuilder;
+import org.apache.james.mailbox.store.mail.model.FlagsFactory;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.Property;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
@@ -317,7 +317,7 @@ public class HBaseMailboxMessage implements MailboxMessage {
 
     @Override
     public Flags createFlags() {
-        return FlagsBuilder.createFlags(this, createUserFlags());
+        return FlagsFactory.createFlags(this, createUserFlags());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/4c072145/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java
index 606ef61..23673e3 100644
--- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java
+++ b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java
@@ -48,7 +48,7 @@ import org.apache.james.mailbox.model.ComposedMessageId;
 import org.apache.james.mailbox.model.ComposedMessageIdWithMetaData;
 import org.apache.james.mailbox.model.MessageAttachment;
 import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.store.mail.model.FlagsBuilder;
+import org.apache.james.mailbox.store.mail.model.FlagsFactory;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.Property;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
@@ -564,7 +564,7 @@ public class JCRMailboxMessage implements MailboxMessage, JCRImapConstants, Pers
 
     @Override
     public Flags createFlags() {
-        return FlagsBuilder.createFlags(this, userFlags);
+        return FlagsFactory.createFlags(this, userFlags);
     }
 
     public void unsetRecent() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/4c072145/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
index 800adb5..164a11e 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
@@ -55,7 +55,7 @@ import org.apache.james.mailbox.model.MessageAttachment;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
 import org.apache.james.mailbox.store.mail.model.DelegatingMailboxMessage;
-import org.apache.james.mailbox.store.mail.model.FlagsBuilder;
+import org.apache.james.mailbox.store.mail.model.FlagsFactory;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.Property;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
@@ -470,7 +470,7 @@ public abstract class AbstractJPAMailboxMessage implements MailboxMessage {
 
     @Override
     public Flags createFlags() {
-        return FlagsBuilder.createFlags(this, createUserFlags());
+        return FlagsFactory.createFlags(this, createUserFlags());
     }
 
     protected String[] createUserFlags() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/4c072145/mailbox/store/src/main/java/org/apache/james/mailbox/store/ImmutableMailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/ImmutableMailboxMessage.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/ImmutableMailboxMessage.java
index 19d7f11..7b1dc51 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/ImmutableMailboxMessage.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/ImmutableMailboxMessage.java
@@ -36,7 +36,7 @@ import org.apache.james.mailbox.model.ComposedMessageIdWithMetaData;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageAttachment;
 import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.store.mail.model.FlagsBuilder;
+import org.apache.james.mailbox.store.mail.model.FlagsFactory;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.Property;
 
@@ -266,7 +266,7 @@ public class ImmutableMailboxMessage implements MailboxMessage {
 
     @Override
     public Flags createFlags() {
-        return FlagsBuilder.createFlags(this, userFlags);
+        return FlagsFactory.createFlags(this, userFlags);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4c072145/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
index 4ae53af..dafd1a6 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
@@ -53,6 +53,8 @@ import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.MessageIdMapper;
 import org.apache.james.mailbox.store.mail.MessageMapper;
+import org.apache.james.mailbox.store.mail.model.FlagsFactory;
+import org.apache.james.mailbox.store.mail.model.FlagsFilter;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
@@ -295,7 +297,21 @@ public class StoreMessageIdManager implements MessageIdManager {
         MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession);
 
         for (MailboxId mailboxId : mailboxIds) {
-            SimpleMailboxMessage copy = SimpleMailboxMessage.copy(mailboxId, mailboxMessage);
+            boolean shouldPreserveFlags = mailboxManager.myRights(mailboxId, mailboxSession).contains(Right.Write);
+            SimpleMailboxMessage copy =
+                SimpleMailboxMessage.from(mailboxMessage)
+                    .mailboxId(mailboxId)
+                    .flags(
+                        FlagsFactory
+                            .builder()
+                            .flags(mailboxMessage.createFlags())
+                            .filteringFlags(
+                                FlagsFilter.builder()
+                                    .systemFlagFilter(f -> shouldPreserveFlags)
+                                    .userFlagFilter(f -> shouldPreserveFlags)
+                                    .build())
+                            .build())
+                    .build();
             save(mailboxSession, messageIdMapper, copy);
             dispatcher.added(mailboxSession, mailboxMapper.findMailboxById(mailboxId), copy);
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4c072145/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessage.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessage.java
index 515bdb7..fde3f82 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessage.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessage.java
@@ -43,7 +43,7 @@ public abstract class DelegatingMailboxMessage implements MailboxMessage {
 
     @Override
     public final Flags createFlags() {
-        return FlagsBuilder.createFlags(this, createUserFlags());
+        return FlagsFactory.createFlags(this, createUserFlags());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/4c072145/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/FlagsBuilder.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/FlagsBuilder.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/FlagsBuilder.java
deleted file mode 100644
index 0c8ce4d..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/FlagsBuilder.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-package org.apache.james.mailbox.store.mail.model;
-
-import javax.mail.Flags;
-
-public class FlagsBuilder {
-
-    public static Flags createFlags(MailboxMessage mailboxMessage, String[] userFlags) {
-        final Flags flags = new Flags();
-
-        if (mailboxMessage.isAnswered()) {
-            flags.add(Flags.Flag.ANSWERED);
-        }
-        if (mailboxMessage.isDeleted()) {
-            flags.add(Flags.Flag.DELETED);
-        }
-        if (mailboxMessage.isDraft()) {
-            flags.add(Flags.Flag.DRAFT);
-        }
-        if (mailboxMessage.isFlagged()) {
-            flags.add(Flags.Flag.FLAGGED);
-        }
-        if (mailboxMessage.isRecent()) {
-            flags.add(Flags.Flag.RECENT);
-        }
-        if (mailboxMessage.isSeen()) {
-            flags.add(Flags.Flag.SEEN);
-        }
-        if (userFlags != null && userFlags.length > 0) {
-            for (String userFlag : userFlags) {
-                flags.add(userFlag);
-            }
-        }
-        return flags;
-    }
-
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4c072145/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/FlagsFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/FlagsFactory.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/FlagsFactory.java
new file mode 100644
index 0000000..44a025f
--- /dev/null
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/FlagsFactory.java
@@ -0,0 +1,130 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.mailbox.store.mail.model;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Optional;
+import java.util.stream.Stream;
+
+import javax.mail.Flags;
+
+public class FlagsFactory {
+
+    private static Flags asFlags(MailboxMessage mailboxMessage, String[] userFlags) {
+        final Flags flags = new Flags();
+        if (mailboxMessage.isAnswered()) {
+            flags.add(Flags.Flag.ANSWERED);
+        }
+        if (mailboxMessage.isDeleted()) {
+            flags.add(Flags.Flag.DELETED);
+        }
+        if (mailboxMessage.isDraft()) {
+            flags.add(Flags.Flag.DRAFT);
+        }
+        if (mailboxMessage.isFlagged()) {
+            flags.add(Flags.Flag.FLAGGED);
+        }
+        if (mailboxMessage.isRecent()) {
+            flags.add(Flags.Flag.RECENT);
+        }
+        if (mailboxMessage.isSeen()) {
+            flags.add(Flags.Flag.SEEN);
+        }
+        if (userFlags != null && userFlags.length > 0) {
+            for (String userFlag : userFlags) {
+                flags.add(userFlag);
+            }
+        }
+        return flags;
+    }
+
+    public static Flags createFlags(MailboxMessage mailboxMessage, String[] userFlags) {
+        return builder()
+            .flags(asFlags(mailboxMessage, userFlags))
+            .addUserFlags(userFlags)
+            .build();
+    }
+
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    public static Flags empty() {
+        return builder().build();
+    }
+
+    public static class Builder {
+
+        private final ArrayList<String> userFlags;
+        private Optional<Flags> flags;
+        private Optional<FlagsFilter> flagsFilter;
+
+        private Builder() {
+            flagsFilter = Optional.empty();
+            userFlags = new ArrayList<>();
+            flags = Optional.empty();
+        }
+
+        public Builder flags(Flags flags) {
+            this.flags = Optional.of(flags);
+            return this;
+        }
+
+        public Builder filteringFlags(FlagsFilter filter) {
+            flagsFilter = Optional.of(filter);
+            return this;
+        }
+
+        public Builder addUserFlags(String... userFlags) {
+            this.userFlags.addAll(Arrays.asList(userFlags));
+            return this;
+        }
+
+        public Flags build() {
+            FlagsFilter flagsFilter = this.flagsFilter.orElse(FlagsFilter.noFilter());
+            Flags flagsOrEmpty = this.flags.orElse(new Flags());
+
+            Stream<Flags.Flag> flagStream =
+                toFlagStream(flagsOrEmpty)
+                    .filter(flagsFilter.getSystemFlagFilter());
+            Stream<String> userFlagsStream =
+                Stream
+                    .concat(
+                        toUserFlagStream(flagsOrEmpty),
+                        userFlags.stream())
+                    .distinct()
+                    .filter(flagsFilter.getUserFlagFilter());
+
+            final Flags result = new Flags();
+            flagStream.forEach(result::add);
+            userFlagsStream.forEach(result::add);
+            return result;
+        }
+
+        private Stream<Flags.Flag> toFlagStream(Flags flags) {
+            return Arrays.stream(flags.getSystemFlags());
+        }
+
+        private Stream<String> toUserFlagStream(Flags flags) {
+            return Arrays.stream(flags.getUserFlags());
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4c072145/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/FlagsFilter.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/FlagsFilter.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/FlagsFilter.java
new file mode 100644
index 0000000..a2ab2b0
--- /dev/null
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/FlagsFilter.java
@@ -0,0 +1,87 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.mailbox.store.mail.model;
+
+import java.util.Optional;
+import java.util.function.Predicate;
+
+import javax.mail.Flags;
+
+public class FlagsFilter {
+
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    public static FlagsFilter noFilter() {
+        return builder().build();
+    }
+
+    public static class Builder {
+        private Optional<SystemFlagFilter> systemFlagFilter;
+        private Optional<UserFlagFilter> userFlagFilter;
+
+        private Builder() {
+            systemFlagFilter = Optional.empty();
+            userFlagFilter = Optional.empty();
+        }
+
+        public Builder systemFlagFilter(SystemFlagFilter filter) {
+            this.systemFlagFilter = Optional.of(filter);
+            return this;
+        }
+
+        public Builder userFlagFilter(UserFlagFilter filter) {
+            this.userFlagFilter = Optional.of(filter);
+            return this;
+        }
+
+        public FlagsFilter build() {
+            return new FlagsFilter(
+                systemFlagFilter.orElse((Flags.Flag f) -> true),
+                userFlagFilter.orElse((String s) -> true)
+                );
+        }
+
+    }
+
+    @FunctionalInterface
+    public interface SystemFlagFilter extends Predicate<Flags.Flag> {
+    }
+
+    @FunctionalInterface
+    public interface UserFlagFilter extends Predicate<String> {
+    }
+
+    private final SystemFlagFilter systemFlagFilter;
+    private final UserFlagFilter userFlagFilter;
+
+    private FlagsFilter(SystemFlagFilter systemFlagFilter, UserFlagFilter userFlagFilter) {
+        this.systemFlagFilter = systemFlagFilter;
+        this.userFlagFilter = userFlagFilter;
+    }
+
+    public SystemFlagFilter getSystemFlagFilter() {
+        return systemFlagFilter;
+    }
+
+    public UserFlagFilter getUserFlagFilter() {
+        return userFlagFilter;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4c072145/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java
index 2431b43..e3af3f5 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java
@@ -36,6 +36,8 @@ import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageAttachment;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.store.mail.model.DelegatingMailboxMessage;
+import org.apache.james.mailbox.store.mail.model.FlagsFactory;
+import org.apache.james.mailbox.store.mail.model.FlagsFilter;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.commons.io.IOUtils;
 
@@ -146,19 +148,22 @@ public class SimpleMailboxMessage extends DelegatingMailboxMessage {
         }
     }
 
-    public static SimpleMailboxMessage copy(MailboxId mailboxId, MailboxMessage original) throws MailboxException {
-        return copy(mailboxId, original, original.getAttachments());
+    public static Builder from(MailboxMessage original) throws MailboxException {
+        PropertyBuilder propertyBuilder = new PropertyBuilder(original.getProperties());
+        propertyBuilder.setTextualLineCount(original.getTextualLineCount());
+        return builder()
+            .bodyStartOctet(Ints.checkedCast(original.getFullContentOctets() - original.getBodyOctets()))
+            .content(copyFullContent(original))
+            .messageId(original.getMessageId())
+            .internalDate(original.getInternalDate())
+            .size(original.getFullContentOctets())
+            .flags(original.createFlags())
+            .propertyBuilder(propertyBuilder)
+            .addAttachments(original.getAttachments());
     }
 
-    private static SimpleMailboxMessage copy(MailboxId mailboxId, MailboxMessage original, List<MessageAttachment> attachments) throws MailboxException {
-        Date internalDate = original.getInternalDate();
-        long size = original.getFullContentOctets();
-        Flags flags = original.createFlags();
-        SharedByteArrayInputStream content = copyFullContent(original);
-        int bodyStartOctet = Ints.checkedCast(original.getFullContentOctets() - original.getBodyOctets());
-        PropertyBuilder pBuilder = new PropertyBuilder(original.getProperties());
-        pBuilder.setTextualLineCount(original.getTextualLineCount());
-        return new SimpleMailboxMessage(original.getMessageId(), internalDate, size, bodyStartOctet, content, flags, pBuilder, mailboxId, attachments);
+    public static SimpleMailboxMessage copy(MailboxId mailboxId, MailboxMessage original) throws MailboxException {
+        return from(original).mailboxId(mailboxId).build();
     }
 
     private static SharedByteArrayInputStream copyFullContent(MailboxMessage original) throws MailboxException {
@@ -274,6 +279,16 @@ public class SimpleMailboxMessage extends DelegatingMailboxMessage {
         userFlags = flags.getUserFlags();
     }
 
+    public SimpleMailboxMessage filterFlags(FlagsFilter filter) throws MailboxException {
+        Flags flags = FlagsFactory
+            .builder()
+            .flags(createFlags())
+            .addUserFlags(createUserFlags())
+            .filteringFlags(filter)
+            .build();
+        return from(this).flags(flags).build();
+    }
+
     @Override
     public int hashCode() {
         return Objects.hashCode(uid);

http://git-wip-us.apache.org/repos/asf/james-project/blob/4c072145/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerStorageTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerStorageTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerStorageTest.java
index 772df77..4a8c069 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerStorageTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerStorageTest.java
@@ -39,6 +39,8 @@ import org.apache.james.mailbox.fixture.MailboxFixture;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.FetchGroupImpl;
 import org.apache.james.mailbox.model.MailboxACL;
+import org.apache.james.mailbox.model.MailboxACL.Rfc4314Rights;
+import org.apache.james.mailbox.model.MailboxACL.Right;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MessageResult;
@@ -543,7 +545,7 @@ public abstract class AbstractMessageIdManagerStorageTest {
             MailboxACL.EMPTY.apply(
                 MailboxACL.command()
                     .forUser(MailboxFixture.BOB)
-                    .rights(new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read))
+                    .rights(new Rfc4314Rights(Right.Read))
                     .asAddition()),
             aliceSession);
         MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession);
@@ -562,7 +564,7 @@ public abstract class AbstractMessageIdManagerStorageTest {
             MailboxACL.EMPTY.apply(
                 MailboxACL.command()
                     .forUser(MailboxFixture.BOB)
-                    .rights(MailboxACL.Rfc4314Rights.allExcept(MailboxACL.Right.Read))
+                    .rights(Rfc4314Rights.allExcept(Right.Read))
                     .asAddition()),
             aliceSession);
         MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession);
@@ -579,7 +581,7 @@ public abstract class AbstractMessageIdManagerStorageTest {
             MailboxACL.EMPTY.apply(
                 MailboxACL.command()
                     .forUser(MailboxFixture.BOB)
-                    .rights(new MailboxACL.Rfc4314Rights(MailboxACL.Right.Write))
+                    .rights(new Rfc4314Rights(Right.Write))
                     .asAddition()),
             aliceSession);
         MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession);
@@ -600,7 +602,7 @@ public abstract class AbstractMessageIdManagerStorageTest {
             MailboxACL.EMPTY.apply(
                 MailboxACL.command()
                     .forUser(MailboxFixture.BOB)
-                    .rights(MailboxACL.Rfc4314Rights.allExcept(MailboxACL.Right.Write))
+                    .rights(Rfc4314Rights.allExcept(Right.Write))
                     .asAddition()),
             aliceSession);
         MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession);
@@ -623,7 +625,7 @@ public abstract class AbstractMessageIdManagerStorageTest {
             MailboxACL.EMPTY.apply(
                 MailboxACL.command()
                     .forUser(MailboxFixture.BOB)
-                    .rights(new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read))
+                    .rights(new Rfc4314Rights(Right.Read))
                     .asAddition()),
             aliceSession);
         MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession);
@@ -648,7 +650,7 @@ public abstract class AbstractMessageIdManagerStorageTest {
             MailboxACL.EMPTY.apply(
                 MailboxACL.command()
                     .forUser(MailboxFixture.BOB)
-                    .rights(MailboxACL.Rfc4314Rights.allExcept(MailboxACL.Right.Read))
+                    .rights(Rfc4314Rights.allExcept(Right.Read))
                     .asAddition()),
             aliceSession);
         MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession);
@@ -676,7 +678,7 @@ public abstract class AbstractMessageIdManagerStorageTest {
             MailboxACL.EMPTY.apply(
                 MailboxACL.command()
                     .forUser(MailboxFixture.BOB)
-                    .rights(new MailboxACL.Rfc4314Rights(MailboxACL.Right.Insert, MailboxACL.Right.Read))
+                    .rights(new Rfc4314Rights(Right.Insert, Right.Read))
                     .asAddition()),
             aliceSession);
         MessageId messageId = testingData.persist(bobMailbox1.getMailboxId(), messageUid1, FLAGS, bobSession);
@@ -704,7 +706,7 @@ public abstract class AbstractMessageIdManagerStorageTest {
             MailboxACL.EMPTY.apply(
                 MailboxACL.command()
                     .forUser(MailboxFixture.BOB)
-                    .rights(MailboxACL.Rfc4314Rights.allExcept(MailboxACL.Right.Insert))
+                    .rights(Rfc4314Rights.allExcept(Right.Insert))
                     .asAddition()),
             aliceSession);
         MessageId messageId = testingData.persist(bobMailbox1.getMailboxId(), messageUid1, FLAGS, bobSession);
@@ -736,7 +738,7 @@ public abstract class AbstractMessageIdManagerStorageTest {
             MailboxACL.EMPTY.apply(
                 MailboxACL.command()
                     .forUser(MailboxFixture.BOB)
-                    .rights(new MailboxACL.Rfc4314Rights(MailboxACL.Right.Lookup, MailboxACL.Right.Read, MailboxACL.Right.DeleteMessages))
+                    .rights(new Rfc4314Rights(Right.Lookup, Right.Read, Right.DeleteMessages))
                     .asAddition()),
             aliceSession);
         MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession);
@@ -764,7 +766,7 @@ public abstract class AbstractMessageIdManagerStorageTest {
             MailboxACL.EMPTY.apply(
                 MailboxACL.command()
                     .forUser(MailboxFixture.BOB)
-                    .rights(MailboxACL.Rfc4314Rights.allExcept(MailboxACL.Right.DeleteMessages))
+                    .rights(Rfc4314Rights.allExcept(Right.DeleteMessages))
                     .asAddition()),
             aliceSession);
         MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession);
@@ -837,7 +839,7 @@ public abstract class AbstractMessageIdManagerStorageTest {
             MailboxACL.EMPTY.apply(
                 MailboxACL.command()
                     .forUser(MailboxFixture.BOB)
-                    .rights(new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read, MailboxACL.Right.Lookup, MailboxACL.Right.DeleteMessages))
+                    .rights(new Rfc4314Rights(Right.Read, Right.Lookup, Right.DeleteMessages))
                     .asAddition()),
             aliceSession);
         MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession);
@@ -855,7 +857,7 @@ public abstract class AbstractMessageIdManagerStorageTest {
             MailboxACL.EMPTY.apply(
                 MailboxACL.command()
                     .forUser(MailboxFixture.BOB)
-                    .rights(MailboxACL.Rfc4314Rights.allExcept(MailboxACL.Right.DeleteMessages))
+                    .rights(Rfc4314Rights.allExcept(Right.DeleteMessages))
                     .asAddition()),
             aliceSession);
         MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession);
@@ -876,7 +878,7 @@ public abstract class AbstractMessageIdManagerStorageTest {
             MailboxACL.EMPTY.apply(
                 MailboxACL.command()
                     .forUser(MailboxFixture.BOB)
-                    .rights(new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read, MailboxACL.Right.Lookup))
+                    .rights(new Rfc4314Rights(Right.Read, Right.Lookup))
                     .asAddition()),
             aliceSession);
         MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession);
@@ -893,7 +895,7 @@ public abstract class AbstractMessageIdManagerStorageTest {
             MailboxACL.EMPTY.apply(
                 MailboxACL.command()
                     .forUser(MailboxFixture.BOB)
-                    .rights(MailboxACL.Rfc4314Rights.allExcept(MailboxACL.Right.Read))
+                    .rights(Rfc4314Rights.allExcept(Right.Read))
                     .asAddition()),
             aliceSession);
         MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession);
@@ -903,4 +905,44 @@ public abstract class AbstractMessageIdManagerStorageTest {
         assertThat(messages)
             .isEmpty();
     }
+
+    @Test
+    public void setInMailboxesShouldSanitizeFlagsWhenNoWriteRight() throws Exception {
+        testingData.setACL(aliceMailbox1.getMailboxId(),
+            MailboxACL.EMPTY.apply(
+                MailboxACL.command()
+                    .forUser(MailboxFixture.BOB)
+                    .rights(new Rfc4314Rights(Right.Read, Right.Lookup, Right.Insert))
+                    .asAddition()),
+            aliceSession);
+        Flags flags = new Flags(Flags.Flag.FLAGGED);
+        MessageId messageId = testingData.persist(bobMailbox1.getMailboxId(), messageUid1, flags, bobSession);
+
+        messageIdManager.setInMailboxes(messageId, ImmutableList.of(aliceMailbox1.getMailboxId()), bobSession);
+
+        List<MessageResult> messages = messageIdManager.getMessages(ImmutableList.of(messageId), FetchGroupImpl.MINIMAL, aliceSession);
+        assertThat(messages)
+            .extracting(MessageResult::getFlags)
+            .containsOnly(new Flags());
+    }
+
+    @Test
+    public void setInMailboxesShouldPreserveFlagsWhenWriteRight() throws Exception {
+        testingData.setACL(aliceMailbox1.getMailboxId(),
+            MailboxACL.EMPTY.apply(
+                MailboxACL.command()
+                    .forUser(MailboxFixture.BOB)
+                    .rights(new Rfc4314Rights(Right.Read, Right.Lookup, Right.Insert, Right.Write))
+                    .asAddition()),
+            aliceSession);
+        Flags flags = new Flags(Flags.Flag.FLAGGED);
+        MessageId messageId = testingData.persist(bobMailbox1.getMailboxId(), messageUid1, flags, bobSession);
+
+        messageIdManager.setInMailboxes(messageId, ImmutableList.of(aliceMailbox1.getMailboxId()), bobSession);
+
+        List<MessageResult> messages = messageIdManager.getMessages(ImmutableList.of(messageId), FetchGroupImpl.MINIMAL, aliceSession);
+        assertThat(messages)
+            .extracting(MessageResult::getFlags)
+            .containsOnly(flags);
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4c072145/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMessageIdManagerTestSystem.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMessageIdManagerTestSystem.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMessageIdManagerTestSystem.java
index 2ed0e13..232ef04 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMessageIdManagerTestSystem.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMessageIdManagerTestSystem.java
@@ -24,6 +24,8 @@ import static org.mockito.Mockito.when;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.time.Instant;
+import java.util.Date;
 
 import javax.mail.Flags;
 
@@ -92,6 +94,7 @@ public class StoreMessageIdManagerTestSystem extends MessageIdManagerTestSystem
         when(mailboxMessage.getUid()).thenReturn(uid);
         when(mailboxMessage.getModSeq()).thenReturn(MOD_SEQ);
         when(mailboxMessage.getMailboxId()).thenReturn(mailboxId);
+        when(mailboxMessage.getInternalDate()).thenReturn(Date.from(Instant.parse("2007-12-03T10:15:30.00Z")));
         try {
             when(mailboxMessage.getFullContent()).thenReturn(ARRAY_INPUT_STREAM);
         } catch (IOException e) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/4c072145/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/FlagsFactoryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/FlagsFactoryTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/FlagsFactoryTest.java
new file mode 100644
index 0000000..0f99ca1
--- /dev/null
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/FlagsFactoryTest.java
@@ -0,0 +1,118 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.mailbox.store.mail.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import javax.mail.Flags;
+import javax.mail.Flags.Flag;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+public class FlagsFactoryTest {
+
+    private ImmutableList<Flag> listOfSystemFlags = ImmutableList.of(Flag.SEEN, Flag.RECENT, Flag.ANSWERED);
+    private ImmutableList<String> listOfUserFlags = ImmutableList.of("userFlag", "soCool");
+    private Flags emptyFlags;
+    private Flags someFlags;
+
+    @Before
+    public void setup() {
+        emptyFlags = new Flags();
+        someFlags = new Flags();
+        listOfSystemFlags.forEach(someFlags::add);
+        listOfUserFlags.forEach(someFlags::add);
+    }
+
+    @Test
+    public void builderShouldAllowEmptyFactory() {
+        assertThat(FlagsFactory.builder().build()).isEqualTo(emptyFlags);
+    }
+
+    @Test
+    public void builderShouldNotRequireFlagsInstanceWhenUserFlagsDefined() {
+        Flags actual = FlagsFactory.builder().addUserFlags("userFlag").build();
+        assertThat(actual.getUserFlags()).containsOnly("userFlag");
+    }
+
+    @Test
+    public void builderShouldNotRequireUserFlagsWhenFlagsInstanceDefined() {
+        assertThat(FlagsFactory.builder().flags(new Flags()).build()).isNotNull();
+    }
+
+    @Test
+    public void builderShouldFilterUserFlags() {
+        Flags actual = FlagsFactory.builder()
+            .flags(someFlags)
+            .filteringFlags(
+                FlagsFilter
+                    .builder()
+                    .userFlagFilter(f -> f.equals("soCool"))
+                    .build())
+            .build();
+        assertThat(actual.getUserFlags()).containsOnly("soCool");
+    }
+
+    @Test
+    public void builderShouldFilterSystemFlags() {
+        Flags actual = FlagsFactory.builder()
+            .flags(someFlags)
+            .filteringFlags(
+                FlagsFilter
+                    .builder()
+                    .systemFlagFilter(f -> f.equals(Flag.SEEN))
+                    .build())
+            .build();
+        assertThat(actual.getSystemFlags()).containsOnly(Flag.SEEN);
+    }
+
+    @Test
+    public void builderShouldAllowFilteringOnEmptyFlags() {
+        Flags actual = FlagsFactory.builder()
+            .flags(emptyFlags)
+            .filteringFlags(
+                FlagsFilter
+                    .builder()
+                    .systemFlagFilter(f -> f.equals(Flag.SEEN))
+                    .userFlagFilter(f -> f.equals("soCool"))
+                    .build())
+            .build();
+        assertThat(actual).isNotNull();
+    }
+
+    @Test
+    public void builderShouldFilterOnFlags() {
+        Flags actual = FlagsFactory.builder()
+            .flags(someFlags)
+            .filteringFlags(
+                FlagsFilter
+                    .builder()
+                    .systemFlagFilter(f -> f.equals(Flag.SEEN))
+                    .userFlagFilter(f -> f.equals("soCool"))
+                    .build())
+            .build();
+        assertThat(actual.getSystemFlags()).containsOnly(Flag.SEEN);
+        assertThat(actual.getUserFlags()).containsOnly("soCool");
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/4c072145/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/FlagsFilterTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/FlagsFilterTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/FlagsFilterTest.java
new file mode 100644
index 0000000..d9feb62
--- /dev/null
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/FlagsFilterTest.java
@@ -0,0 +1,74 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.mailbox.store.mail.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.List;
+
+import javax.mail.Flags;
+
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+public class FlagsFilterTest {
+
+    private List<Flags.Flag> listOfFlags = ImmutableList.of(Flags.Flag.SEEN, Flags.Flag.RECENT, Flags.Flag.FLAGGED);
+    private List<String> listOfUserFlags = ImmutableList.of("VeryImportant", "Bof");
+
+    @Test
+    public void buildShouldNotRequireAnyProperty() {
+        assertThat(FlagsFilter.builder().build()).isNotNull();
+    }
+
+    @Test
+    public void buildWithoutPropertyShouldReturnNoFilter() {
+        FlagsFilter filter = FlagsFilter.builder().build();
+        assertThat(listOfFlags.stream().filter(filter.getSystemFlagFilter())).isEqualTo(listOfFlags);
+        assertThat(listOfUserFlags.stream().filter(filter.getUserFlagFilter())).isEqualTo(listOfUserFlags);
+    }
+
+    @Test
+    public void buildWithSystemFlagFilterShouldNotFilterUserFlags() {
+        FlagsFilter filter = FlagsFilter.builder()
+            .systemFlagFilter(flag -> false)
+            .build();
+        assertThat(listOfUserFlags.stream().filter(filter.getUserFlagFilter())).isEqualTo(listOfUserFlags);
+    }
+
+    @Test
+    public void buildWithUSerFlagFilterShouldNotFilterSystemFlags() {
+        FlagsFilter filter = FlagsFilter.builder()
+            .userFlagFilter(flag -> false)
+            .build();
+        assertThat(listOfFlags.stream().filter(filter.getSystemFlagFilter())).isEqualTo(listOfFlags);
+    }
+
+
+    @Test
+    public void buildWithBothFiltersShouldApplyFilterOnBothFlagTypes() {
+        FlagsFilter filter = FlagsFilter.builder()
+            .userFlagFilter(flag -> false)
+            .systemFlagFilter(flag -> false)
+            .build();
+        assertThat(listOfFlags.stream().filter(filter.getSystemFlagFilter())).isEmpty();
+        assertThat(listOfUserFlags.stream().filter(filter.getUserFlagFilter())).isEmpty();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/4c072145/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraSetMessagesMethodCucumberTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraSetMessagesMethodCucumberTest.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraSetMessagesMethodCucumberTest.java
index eb81d00..d16ecd0 100644
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraSetMessagesMethodCucumberTest.java
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraSetMessagesMethodCucumberTest.java
@@ -29,8 +29,7 @@ import cucumber.api.junit.Cucumber;
 @RunWith(Cucumber.class)
 @CucumberOptions(features="classpath:cucumber/SetMessages.feature",
                 glue={"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.cassandra.cucumber"},
-                strict = true,
-                tags = {"~@Ignore"})
+                strict = true)
 public class CassandraSetMessagesMethodCucumberTest {
 
     @BeforeClass

http://git-wip-us.apache.org/repos/asf/james-project/blob/4c072145/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SetMessages.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SetMessages.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SetMessages.feature
index 12c4ac4..60abace 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SetMessages.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SetMessages.feature
@@ -57,7 +57,6 @@ Feature: SetMessages method on shared folders
     And "alice@domain.tld" moves "mAlice" to mailbox "shared" of user "bob@domain.tld"
     Then "alice@domain.tld" should see message "mAlice" with keywords $Flagged
 
-  @Ignore
   Scenario: A delegated user can add sanitized messages to a shared mailbox when missing "write" right
     Given "bob@domain.tld" shares his mailbox "shared" with "alice@domain.tld" with "lri" rights
     And "alice@domain.tld" sets flags "$Flagged" on message "mAlice"

http://git-wip-us.apache.org/repos/asf/james-project/blob/4c072145/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemorySetMessagesMethodCucumberTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemorySetMessagesMethodCucumberTest.java b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemorySetMessagesMethodCucumberTest.java
index 197c1d7..164e2fb 100644
--- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemorySetMessagesMethodCucumberTest.java
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemorySetMessagesMethodCucumberTest.java
@@ -27,7 +27,6 @@ import cucumber.api.junit.Cucumber;
 @RunWith(Cucumber.class)
 @CucumberOptions(features="classpath:cucumber/SetMessages.feature",
                 glue={"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.memory.cucumber"},
-                strict = true,
-                tags = {"~@Ignore"})
+                strict = true)
 public class MemorySetMessagesMethodCucumberTest {
 }


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