You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ad...@apache.org on 2017/11/15 12:33:32 UTC

[1/4] james-project git commit: JAMES-2215 Integration test about consistency of total and unread counts on a shared folder

Repository: james-project
Updated Branches:
  refs/heads/master 5df4371bc -> 2d22e0178


JAMES-2215 Integration test about consistency of total and unread counts on a shared folder


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

Branch: refs/heads/master
Commit: b73c53fea1807453612b0f928b0558056163daf2
Parents: b539779
Author: Antoine Duprat <ad...@linagora.com>
Authored: Mon Nov 13 15:35:09 2017 +0100
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Wed Nov 15 09:56:59 2017 +0100

----------------------------------------------------------------------
 .../CassandraGetMailboxesMethodTest.java        |  45 ++++
 .../cucumber/GetMailboxesMethodStepdefs.java    |  84 +++++++
 .../cucumber/GetMessagesMethodStepdefs.java     |   5 +
 .../resources/cucumber/GetMailboxes.feature     | 236 +++++++++++++++++++
 .../cucumber/MemoryGetMailboxesMethodTest.java  |  32 +++
 5 files changed, 402 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b73c53fe/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraGetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraGetMailboxesMethodTest.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraGetMailboxesMethodTest.java
new file mode 100644
index 0000000..edf671b
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraGetMailboxesMethodTest.java
@@ -0,0 +1,45 @@
+/****************************************************************
+ * 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.jmap.cassandra.cucumber;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.runner.RunWith;
+
+import cucumber.api.CucumberOptions;
+import cucumber.api.junit.Cucumber;
+
+@RunWith(Cucumber.class)
+@CucumberOptions(features="classpath:cucumber/GetMailboxes.feature",
+                glue={"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.cassandra.cucumber"},
+                strict = true)
+public class CassandraGetMailboxesMethodTest {
+
+    @BeforeClass
+    public static void init() {
+        CucumberCassandraSingleton.cassandraServer.start();
+    }
+
+    @AfterClass
+    public static void after() {
+        CucumberCassandraSingleton.cassandraServer.stop();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b73c53fe/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMailboxesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMailboxesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMailboxesMethodStepdefs.java
new file mode 100644
index 0000000..8b6514e
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMailboxesMethodStepdefs.java
@@ -0,0 +1,84 @@
+/****************************************************************
+ * 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.jmap.methods.integration.cucumber;
+
+import static com.jayway.jsonpath.Criteria.where;
+import static com.jayway.jsonpath.Filter.filter;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import cucumber.api.java.en.Then;
+import cucumber.api.java.en.When;
+import cucumber.runtime.java.guice.ScenarioScoped;
+
+@ScenarioScoped
+public class GetMailboxesMethodStepdefs {
+
+    private static final String NAME = "[0][0]";
+    private static final String ARGUMENTS = "[0][1]";
+
+    private final UserStepdefs userStepdefs;
+    private final HttpClient httpClient;
+
+    @Inject
+    private GetMailboxesMethodStepdefs(UserStepdefs userStepdefs, HttpClient httpClient) {
+        this.userStepdefs = userStepdefs;
+        this.httpClient = httpClient;
+    }
+
+    @When("^\"([^\"]*)\" ask for mailboxes$")
+    public void getMailboxes(String user) throws Throwable {
+        userStepdefs.execWithUser(user, 
+                () -> httpClient.post("[[\"getMailboxes\", {}, \"#0\"]]"));
+    }
+
+    @Then("^a mailboxes answer is returned without error$")
+    public void assertGetMailboxesOkStatus() throws Exception {
+        assertThat(httpClient.response.getStatusLine().getStatusCode()).isEqualTo(200);
+        assertThat(httpClient.jsonPath.<String>read(NAME)).isEqualTo("mailboxes");
+    }
+
+    @Then("^the list should contain (\\d+) (?:mailbox|mailboxes)$")
+    public void assertNumberOfMailboxes(int numberOfMailboxes) throws Exception {
+        assertThat(httpClient.jsonPath.<List<String>>read(ARGUMENTS + ".list")).hasSize(numberOfMailboxes);
+    }
+
+    @Then("^the mailbox \"([^\"]*)\" should be present$")
+    public void assertMailboxesNames(String mailboxName) throws Exception {
+        assertThat(httpClient.jsonPath.<List<String>>read(ARGUMENTS + ".list[*].name")).contains(mailboxName);
+    }
+
+    @Then("^the mailbox \"([^\"]*)\" has (\\d+) (?:messages|message)$")
+    public void assertNumberOfMessages(String mailboxName, int numberOfMessages) throws Exception {
+        assertThat(httpClient.jsonPath.<List<Integer>>read(ARGUMENTS + ".list[?].totalMessages",
+                filter(where("name").is(mailboxName))))
+            .containsOnly(numberOfMessages);
+    }
+
+    @Then("^the mailbox \"([^\"]*)\" has (\\d+) unseen (?:messages|message)$")
+    public void assertNumberOfUnseenMessages(String mailboxName, int numberOfUnseenMessages) throws Exception {
+        assertThat(httpClient.jsonPath.<List<Integer>>read(ARGUMENTS + ".list[?].unreadMessages",
+                filter(where("name").is(mailboxName))))
+            .containsOnly(numberOfUnseenMessages);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b73c53fe/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
index 9d353f6..4750950 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
@@ -358,6 +358,11 @@ public class GetMessagesMethodStepdefs {
         userStepdefs.execWithUser(username, () -> appendMessageWithFlags(messageName, mailbox, flagList));
     }
 
+    @Given("^\"([^\"]*)\" has a message \"([^\"]*)\" in \"([^\"]*)\" mailbox$")
+    public void appendSimpleMessage(String username, String messageName, String mailbox) throws Throwable {
+        userStepdefs.execWithUser(username, () -> appendMessageWithFlags(messageName, mailbox, ImmutableList.of()));
+    }
+
     @Given("^the user has a message \"([^\"]*)\" in the \"([^\"]*)\" mailbox with flags \"([^\"]*)\"$")
     public void appendMessageWithFlags(String messageName, String mailbox, List<String> flagList) throws Exception {
         appendMessage(messageName, StringListToFlags.fromFlagList(flagList));

http://git-wip-us.apache.org/repos/asf/james-project/blob/b73c53fe/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMailboxes.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMailboxes.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMailboxes.feature
new file mode 100644
index 0000000..45c545e
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMailboxes.feature
@@ -0,0 +1,236 @@
+#***************************************************************
+# 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.                                           *
+# **************************************************************/
+Feature: GetMailboxes method
+  As a James user
+  I want to be able to retrieve my mailboxes
+
+  Background:
+    Given a domain named "domain.tld"
+    And a user "alice@domain.tld"
+    And a user "bob@domain.tld"
+    And "alice@domain.tld" has a mailbox "INBOX"
+    And "bob@domain.tld" has a mailbox "bobMailbox"
+    And "alice@domain.tld" has a mailbox "shared"
+    And "alice@domain.tld" shares her mailbox "shared" with "bob@domain.tld" with "aeilrwt" rights
+
+  Scenario: Sharer can read the total and unread counts on a shared folder
+    Given "alice@domain.tld" has a message "m1" in "shared" mailbox
+    And "alice@domain.tld" has a message "m2" in "shared" mailbox with subject "my test subject 2", content "testmail 2"
+    When "alice@domain.tld" ask for mailboxes
+    Then the mailbox "shared" has 2 messages
+    And the mailbox "shared" has 2 unseen messages
+
+  Scenario: Sharee can read the total and unread counts on a shared folder
+    Given "alice@domain.tld" has a message "m1" in "shared" mailbox
+    And "alice@domain.tld" has a message "m2" in "shared" mailbox with subject "my test subject 2", content "testmail 2"
+    When "bob@domain.tld" ask for mailboxes
+    Then the mailbox "shared" has 2 messages
+    And the mailbox "shared" has 2 unseen messages
+
+  Scenario: Copy message should update the total and the unread counts when asked by sharer
+    Given "alice@domain.tld" has a message "m1" in "INBOX" mailbox
+    And "alice@domain.tld" copies "m1" from mailbox "INBOX" to mailbox "shared"
+    When "alice@domain.tld" ask for mailboxes
+    Then the mailbox "shared" has 1 message
+    And the mailbox "shared" has 1 unseen message
+
+  Scenario: Copy message should update the total and the unread counts when asked by sharer / sharee view
+    Given "alice@domain.tld" has a message "m1" in "INBOX" mailbox
+    And "alice@domain.tld" copies "m1" from mailbox "INBOX" to mailbox "shared"
+    When "bob@domain.tld" ask for mailboxes
+    Then the mailbox "shared" has 1 message
+    And the mailbox "shared" has 1 unseen message
+
+  Scenario: Copy message should update the total and the unread counts when asked by sharee
+    Given "bob@domain.tld" has a message "m1" in "bobMailbox" mailbox
+    And "bob@domain.tld" copies "m1" from mailbox "bobMailbox" of user "bob@domain.tld" to mailbox "shared" of user "alice@domain.tld"
+    When "alice@domain.tld" ask for mailboxes
+    Then the mailbox "shared" has 1 message
+    And the mailbox "shared" has 1 unseen message
+
+  Scenario: Copy message should update the total and the unread counts when asked by sharee / sharee view
+    Given "bob@domain.tld" has a message "m1" in "bobMailbox" mailbox
+    And "bob@domain.tld" copies "m1" from mailbox "bobMailbox" of user "bob@domain.tld" to mailbox "shared" of user "alice@domain.tld"
+    When "bob@domain.tld" ask for mailboxes
+    Then the mailbox "shared" has 1 message
+    And the mailbox "shared" has 1 unseen message
+
+  Scenario: Move message should update the total and the unread counts when asked by sharer
+    Given "alice@domain.tld" has a message "m1" in "INBOX" mailbox
+    And "alice@domain.tld" moves "m1" to mailbox "shared" of user "alice@domain.tld"
+    When "alice@domain.tld" ask for mailboxes
+    Then the mailbox "shared" has 1 message
+    And the mailbox "shared" has 1 unseen message
+
+  Scenario: Move message should update the total and the unread counts of origin mailbox when asked by sharer
+    Given "alice@domain.tld" has a message "m1" in "INBOX" mailbox
+    And "alice@domain.tld" moves "m1" to mailbox "shared" of user "alice@domain.tld"
+    When "alice@domain.tld" ask for mailboxes
+    Then the mailbox "INBOX" has 0 messages
+    And the mailbox "INBOX" has 0 unseen messages
+
+  Scenario: Move message should update the total and the unread counts when asked by sharer / sharee view
+    Given "alice@domain.tld" has a message "m1" in "INBOX" mailbox
+    And "alice@domain.tld" moves "m1" to mailbox "shared" of user "alice@domain.tld"
+    When "bob@domain.tld" ask for mailboxes
+    Then the mailbox "shared" has 1 message
+    And the mailbox "shared" has 1 unseen message
+
+  Scenario: Move message should update the total and the unread counts of origin mailbox when asked by sharer / sharee view
+    Given "alice@domain.tld" has a mailbox "sharedBis"
+    And "alice@domain.tld" has a message "m1" in "sharedBis" mailbox
+    And "alice@domain.tld" shares her mailbox "sharedBis" with "bob@domain.tld" with "aeilrwt" rights
+    And "alice@domain.tld" moves "m1" to mailbox "shared" of user "alice@domain.tld"
+    When "bob@domain.tld" ask for mailboxes
+    Then the mailbox "sharedBis" has 0 messages
+    And the mailbox "sharedBis" has 0 unseen messages
+
+  Scenario: Move message should update the total and the unread counts when asked by sharee
+    Given "bob@domain.tld" has a message "m1" in "bobMailbox" mailbox
+    And "bob@domain.tld" moves "m1" to mailbox "shared" of user "alice@domain.tld"
+    When "alice@domain.tld" ask for mailboxes
+    Then the mailbox "shared" has 1 message
+    And the mailbox "shared" has 1 unseen message
+
+  Scenario: Move message should update the total and the unread counts of origin mailbox when asked by sharee
+    Given "bob@domain.tld" has a mailbox "sharedBis"
+    And "bob@domain.tld" has a message "m1" in "sharedBis" mailbox
+    And "bob@domain.tld" shares her mailbox "sharedBis" with "alice@domain.tld" with "aeilrwt" rights
+    And "bob@domain.tld" moves "m1" to mailbox "shared" of user "alice@domain.tld"
+    When "alice@domain.tld" ask for mailboxes
+    Then the mailbox "sharedBis" has 0 messages
+    And the mailbox "sharedBis" has 0 unseen messages
+
+  Scenario: Move message should update the total and the unread counts when asked by sharee / sharee view
+    Given "bob@domain.tld" has a message "m1" in "bobMailbox" mailbox
+    And "bob@domain.tld" moves "m1" to mailbox "shared" of user "alice@domain.tld"
+    When "bob@domain.tld" ask for mailboxes
+    Then the mailbox "shared" has 1 message
+    And the mailbox "shared" has 1 unseen message
+
+  Scenario: Move message should update the total and the unread counts of origin mailbox when asked by sharee / sharee view
+    Given "bob@domain.tld" has a message "m1" in "bobMailbox" mailbox
+    And "bob@domain.tld" moves "m1" to mailbox "shared" of user "alice@domain.tld"
+    When "bob@domain.tld" ask for mailboxes
+    Then the mailbox "bobMailbox" has 0 messages
+    And the mailbox "bobMailbox" has 0 unseen messages
+
+  Scenario: Moving a message to a delegated mailbox without rights should not change the total and the unread counts
+    Given "alice@domain.tld" has a mailbox "shared2"
+    And "alice@domain.tld" shares her mailbox "shared2" with "bob@domain.tld" with "lr" rights
+    And "bob@domain.tld" has a message "m1" in "bobMailbox" mailbox
+    And "bob@domain.tld" moves "m1" to mailbox "shared2" of user "alice@domain.tld"
+    When "alice@domain.tld" ask for mailboxes
+    Then the mailbox "shared" has 0 messages
+    And the mailbox "shared" has 0 unseen messages
+
+  Scenario: Moving a message to a delegated mailbox without rights should not change the total and the unread counts / sharee view
+    Given "alice@domain.tld" has a mailbox "shared2"
+    And "alice@domain.tld" shares her mailbox "shared2" with "bob@domain.tld" with "lr" rights
+    And "bob@domain.tld" has a message "m1" in "bobMailbox" mailbox
+    And "bob@domain.tld" moves "m1" to mailbox "shared2" of user "alice@domain.tld"
+    When "bob@domain.tld" ask for mailboxes
+    Then the mailbox "shared" has 0 messages
+    And the mailbox "shared" has 0 unseen messages
+
+  Scenario: Move message should update the total and the unread counts when asked by sharee and seen message
+    Given "bob@domain.tld" has a message "m1" in the "bobMailbox" mailbox with flags "$Seen"
+    And "bob@domain.tld" moves "m1" to mailbox "shared" of user "alice@domain.tld"
+    When "alice@domain.tld" ask for mailboxes
+    Then the mailbox "shared" has 1 message
+    And the mailbox "shared" has 0 unseen message
+
+  Scenario: Move message should update the total and the unread counts when asked by sharee / sharee view and seen message
+    Given "bob@domain.tld" has a message "m1" in the "bobMailbox" mailbox with flags "$Seen"
+    And "bob@domain.tld" moves "m1" to mailbox "shared" of user "alice@domain.tld"
+    When "bob@domain.tld" ask for mailboxes
+    Then the mailbox "shared" has 1 message
+    And the mailbox "shared" has 0 unseen message
+
+  Scenario: Move message should update the total and the unread counts of origin mailbox when asked by sharer and seen message
+    Given "alice@domain.tld" has a message "m1" in the "INBOX" mailbox with flags "$Seen"
+    And "alice@domain.tld" moves "m1" to mailbox "shared" of user "alice@domain.tld"
+    When "alice@domain.tld" ask for mailboxes
+    Then the mailbox "INBOX" has 0 messages
+    And the mailbox "INBOX" has 0 unseen messages
+
+  Scenario: Moving a message to a delegated mailbox without rights should not change the total and the unread counts
+    Given "alice@domain.tld" has a mailbox "shared2"
+    And "alice@domain.tld" shares her mailbox "shared2" with "bob@domain.tld" with "lri" rights
+    And "bob@domain.tld" has a message "m1" in the "bobMailbox" mailbox with flags "$Seen"
+    And "bob@domain.tld" moves "m1" to mailbox "shared2" of user "alice@domain.tld"
+    When "alice@domain.tld" ask for mailboxes
+    Then the mailbox "shared" has 0 messages
+    And the mailbox "shared" has 0 unseen messages
+
+  Scenario: Moving a message to a delegated mailbox without rights should not change the total and the unread counts / sharee view
+    Given "alice@domain.tld" has a mailbox "shared2"
+    And "alice@domain.tld" shares her mailbox "shared2" with "bob@domain.tld" with "lri" rights
+    And "bob@domain.tld" has a message "m1" in the "bobMailbox" mailbox with flags "$Seen"
+    And "bob@domain.tld" moves "m1" to mailbox "shared2" of user "alice@domain.tld"
+    When "bob@domain.tld" ask for mailboxes
+    Then the mailbox "shared" has 0 messages
+    And the mailbox "shared" has 0 unseen messages
+
+  Scenario: Set flags by sharer should update unseen count when read by sharer
+    Given "alice@domain.tld" has a message "m1" in "shared" mailbox
+    When "alice@domain.tld" sets flags "$Seen" on message "m1"
+    When "alice@domain.tld" ask for mailboxes
+    Then the mailbox "shared" has 1 message
+    And the mailbox "shared" has 0 unseen messages
+
+  Scenario: Set flags by sharer should update unseen count when read by sharee
+    Given "alice@domain.tld" has a message "m1" in "shared" mailbox
+    When "alice@domain.tld" sets flags "$Seen" on message "m1"
+    When "bob@domain.tld" ask for mailboxes
+    Then the mailbox "shared" has 1 message
+    And the mailbox "shared" has 0 unseen messages
+
+  Scenario: Set flags by sharee should update unseen count when read by sharer
+    Given "alice@domain.tld" has a message "m1" in "shared" mailbox
+    When "bob@domain.tld" sets flags "$Seen" on message "m1"
+    When "alice@domain.tld" ask for mailboxes
+    Then the mailbox "shared" has 1 message
+    And the mailbox "shared" has 0 unseen messages
+
+  Scenario: Set flags by sharee should update unseen count when read by sharee
+    Given "alice@domain.tld" has a message "m1" in "shared" mailbox
+    When "bob@domain.tld" sets flags "$Seen" on message "m1"
+    When "bob@domain.tld" ask for mailboxes
+    Then the mailbox "shared" has 1 message
+    And the mailbox "shared" has 0 unseen messages
+
+  Scenario: Set flags by sharee should not update unseen count when no rights and read by sharer
+    Given "alice@domain.tld" has a mailbox "shared2"
+    And "alice@domain.tld" shares her mailbox "shared2" with "bob@domain.tld" with "lri" rights
+    And "alice@domain.tld" has a message "m1" in "shared2" mailbox
+    When "bob@domain.tld" sets flags "$Seen" on message "m1"
+    When "alice@domain.tld" ask for mailboxes
+    Then the mailbox "shared2" has 1 message
+    And the mailbox "shared2" has 1 unseen message
+
+  Scenario: As sharee read a message it should not update unseen count when no rights and read by sharee
+    Given "alice@domain.tld" has a mailbox "shared2"
+    And "alice@domain.tld" shares her mailbox "shared2" with "bob@domain.tld" with "lri" rights
+    And "alice@domain.tld" has a message "m1" in "shared2" mailbox
+    When "bob@domain.tld" sets flags "$Seen" on message "m1"
+    When "bob@domain.tld" ask for mailboxes
+    Then the mailbox "shared2" has 1 message
+    And the mailbox "shared2" has 1 unseen message
+

http://git-wip-us.apache.org/repos/asf/james-project/blob/b73c53fe/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryGetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryGetMailboxesMethodTest.java b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryGetMailboxesMethodTest.java
new file mode 100644
index 0000000..799b467
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryGetMailboxesMethodTest.java
@@ -0,0 +1,32 @@
+/****************************************************************
+ * 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.jmap.memory.cucumber;
+
+import org.junit.runner.RunWith;
+
+import cucumber.api.CucumberOptions;
+import cucumber.api.junit.Cucumber;
+
+@RunWith(Cucumber.class)
+@CucumberOptions(features="classpath:cucumber/GetMailboxes.feature",
+                glue={"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.memory.cucumber"},
+                strict = true)
+public class MemoryGetMailboxesMethodTest {
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[4/4] james-project git commit: Merge remote-tracking branch 'mine/JAMES-2215'

Posted by ad...@apache.org.
Merge remote-tracking branch 'mine/JAMES-2215'


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

Branch: refs/heads/master
Commit: 2d22e017824cbff13116bdc29d8cae8a1eadbc4f
Parents: 5df4371 ec485b5
Author: Antoine Duprat <ad...@linagora.com>
Authored: Wed Nov 15 13:22:38 2017 +0100
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Wed Nov 15 13:22:38 2017 +0100

----------------------------------------------------------------------
 .../james/mailbox/MailboxManagerTest.java       | 104 ++++++++
 .../james/mailbox/store/MailboxMetaData.java    |  24 ++
 .../mailbox/store/StoreMessageManager.java      |  31 ++-
 .../james/mailbox/copier/MailboxCopierTest.java |   7 +-
 .../CassandraGetMailboxesMethodTest.java        |  45 ++++
 .../cucumber/GetMailboxesMethodStepdefs.java    |  84 +++++++
 .../cucumber/GetMessagesMethodStepdefs.java     |  12 +-
 .../resources/cucumber/GetMailboxes.feature     | 244 +++++++++++++++++++
 .../test/resources/cucumber/GetMessages.feature |  12 +-
 .../cucumber/MemoryGetMailboxesMethodTest.java  |  32 +++
 10 files changed, 572 insertions(+), 23 deletions(-)
----------------------------------------------------------------------



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[2/4] james-project git commit: JAMES-2215 Mailbox argument should not be ignored in message stepDefs

Posted by ad...@apache.org.
JAMES-2215 Mailbox argument should not be ignored in message stepDefs


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

Branch: refs/heads/master
Commit: cda4eece0780063a40f690e52e2e5533ec6a36b6
Parents: b73c53f
Author: benwa <bt...@linagora.com>
Authored: Tue Nov 14 09:33:38 2017 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Wed Nov 15 09:57:30 2017 +0100

----------------------------------------------------------------------
 .../integration/cucumber/GetMessagesMethodStepdefs.java |  7 +++----
 .../src/test/resources/cucumber/GetMessages.feature     | 12 ++++++------
 2 files changed, 9 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/cda4eece/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
index 4750950..f594b30 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
@@ -38,7 +38,6 @@ import javax.mail.Flags;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.text.StringEscapeUtils;
-import org.apache.james.jmap.DefaultMailboxes;
 import org.apache.james.jmap.methods.integration.cucumber.util.TableRow;
 import org.apache.james.jmap.model.MessagePreviewGenerator;
 import org.apache.james.mailbox.model.MailboxConstants;
@@ -365,14 +364,14 @@ public class GetMessagesMethodStepdefs {
 
     @Given("^the user has a message \"([^\"]*)\" in the \"([^\"]*)\" mailbox with flags \"([^\"]*)\"$")
     public void appendMessageWithFlags(String messageName, String mailbox, List<String> flagList) throws Exception {
-        appendMessage(messageName, StringListToFlags.fromFlagList(flagList));
+        appendMessage(messageName, mailbox, StringListToFlags.fromFlagList(flagList));
     }
 
-    private void appendMessage(String messageName, Flags flags) throws Exception {
+    private void appendMessage(String messageName, String mailbox, Flags flags) throws Exception {
         ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z");
         boolean isRecent = flags.contains(Flags.Flag.RECENT);
         MessageId id = mainStepdefs.mailboxProbe.appendMessage(userStepdefs.getConnectedUser(),
-            MailboxPath.forUser(userStepdefs.getConnectedUser(), DefaultMailboxes.INBOX),
+            MailboxPath.forUser(userStepdefs.getConnectedUser(), mailbox),
             new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()),
             Date.from(dateTime.toInstant()), isRecent, flags)
             .getMessageId();

http://git-wip-us.apache.org/repos/asf/james-project/blob/cda4eece/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
index f0f8418..c003096 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
@@ -364,7 +364,7 @@ Feature: GetMessages method
             |"text/html; charset=iso-8859-1"                    |quoted-printable   |"Dans le cadre du stage effectu=E9 Mlle 2017, =E0 sign=E9e d=E8s que possible, =E0, tr=E8s, journ=E9e.."    |effectué, à, signée dès, très, journée                                                                        |
 
   Scenario Outline: Retrieving message should display keywords as jmap flag
-    Given "alice@domain.tld" has a message "m1" in the "inbox" mailbox with flags <flags>
+    Given "alice@domain.tld" has a message "m1" in the "INBOX" mailbox with flags <flags>
     When "alice@domain.tld" ask for messages "m1"
     Then no error is returned
     And the list should contain 1 message
@@ -375,7 +375,7 @@ Feature: GetMessages method
             |"$Flagged,$Answered,$Draft"    |$Flagged,$Answered,$Draft      |
 
   Scenario Outline: GetMessages should filter invalid keywords
-    Given "alice@domain.tld" has a message "m1" in the "inbox" mailbox with flags <flags>
+    Given "alice@domain.tld" has a message "m1" in the "INBOX" mailbox with flags <flags>
     When "alice@domain.tld" ask for messages "m1"
     Then no error is returned
     And the list should contain 1 message
@@ -386,7 +386,7 @@ Feature: GetMessages method
       |"$Draft,@ert,t^a,op§,$user_flag"    |$Draft,$user_flag      |
 
   Scenario Outline: Retrieving message should display keywords without unsupported jmap flag
-    Given "alice@domain.tld" has a message "m1" in the "inbox" mailbox with flags <flags>
+    Given "alice@domain.tld" has a message "m1" in the "INBOX" mailbox with flags <flags>
     When "alice@domain.tld" ask for messages "m1"
     Then no error is returned
     And the list should contain 1 message
@@ -397,7 +397,7 @@ Feature: GetMessages method
             |"$Flagged,$Answered,$Deleted,$Recent"  |$Flagged,$Answered      |
 
   Scenario Outline: Retrieving message should display keywords with custom user jmap flag
-    Given "alice@domain.tld" has a message "m1" in the "inbox" mailbox with flags <flags>
+    Given "alice@domain.tld" has a message "m1" in the "INBOX" mailbox with flags <flags>
     When "alice@domain.tld" ask for messages "m1"
     Then no error is returned
     And the list should contain 1 message
@@ -408,14 +408,14 @@ Feature: GetMessages method
             |"$Flagged,$Forwarded"    |$Forwarded,$Flagged     |
 
   Scenario: Retrieving message should include true isForwarded property when set
-    Given "alice@domain.tld" has a message "m1" in the "inbox" mailbox with flags "$Forwarded"
+    Given "alice@domain.tld" has a message "m1" in the "INBOX" mailbox with flags "$Forwarded"
     When "alice@domain.tld" ask for messages "m1"
     Then no error is returned
     And the list should contain 1 message
     And the isForwarded property of the message is "true"
 
   Scenario: Retrieving message should include false isForwarded property when not set
-    Given "alice@domain.tld" has a message "m1" in the "inbox" mailbox with flags "$Answered"
+    Given "alice@domain.tld" has a message "m1" in the "INBOX" mailbox with flags "$Answered"
     When "alice@domain.tld" ask for messages "m1"
     Then no error is returned
     And the list should contain 1 message


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[3/4] james-project git commit: JAMES-2215 Don't disclose mailbox metadata details when shared with only lookup right

Posted by ad...@apache.org.
JAMES-2215 Don't disclose mailbox metadata details when shared with only lookup right


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

Branch: refs/heads/master
Commit: ec485b53d6f39d19883041b60ba2e8a11e4cbf23
Parents: cda4eec
Author: benwa <bt...@linagora.com>
Authored: Tue Nov 14 10:24:49 2017 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Wed Nov 15 09:57:30 2017 +0100

----------------------------------------------------------------------
 .../james/mailbox/MailboxManagerTest.java       | 104 +++++++++++++++++++
 .../james/mailbox/store/MailboxMetaData.java    |  24 +++++
 .../mailbox/store/StoreMessageManager.java      |  31 ++++--
 .../james/mailbox/copier/MailboxCopierTest.java |   7 +-
 .../resources/cucumber/GetMailboxes.feature     |   8 ++
 5 files changed, 161 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/ec485b53/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
index be94d90..69298c7 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
@@ -22,6 +22,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.ByteArrayInputStream;
 import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
 import java.util.Date;
 import java.util.List;
 import java.util.Optional;
@@ -35,6 +36,7 @@ import org.apache.james.mailbox.mock.MockMailboxManager;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxAnnotation;
 import org.apache.james.mailbox.model.MailboxAnnotationKey;
+import org.apache.james.mailbox.model.MailboxCounters;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxPath;
@@ -42,6 +44,7 @@ import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
 import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.model.search.MailboxQuery;
+import org.assertj.core.api.JUnitSoftAssertions;
 import org.junit.Assume;
 import org.junit.Rule;
 import org.junit.Test;
@@ -81,6 +84,9 @@ public abstract class MailboxManagerTest {
     @Rule
     public ExpectedException expected = ExpectedException.none();
 
+    @Rule
+    public JUnitSoftAssertions softly = new JUnitSoftAssertions();
+
     private MailboxManager mailboxManager;
     private MailboxSession session;
 
@@ -859,4 +865,102 @@ public abstract class MailboxManagerTest {
         assertThat(mailboxManager.search(mailboxQuery, session2))
             .isEmpty();
     }
+
+    @Test
+    public void getMailboxCountersShouldReturnDefaultValueWhenNoReadRight() throws MailboxException {
+        Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
+        MailboxSession session1 = mailboxManager.createSystemSession(USER_1);
+        MailboxSession session2 = mailboxManager.createSystemSession(USER_2);
+        MailboxPath inbox1 = MailboxPath.inbox(session1);
+        mailboxManager.createMailbox(inbox1, session1);
+        mailboxManager.setRights(inbox1,
+            MailboxACL.EMPTY.apply(MailboxACL.command()
+                .forUser(USER_2)
+                .rights(MailboxACL.Right.Lookup)
+                .asAddition()),
+            session1);
+        ByteArrayInputStream message = new ByteArrayInputStream("Subject: any\n\nbdy".getBytes(StandardCharsets.UTF_8));
+        boolean isRecent = true;
+        mailboxManager.getMailbox(inbox1, session1)
+            .appendMessage(message, new Date(), session1, isRecent, new Flags());
+
+        MailboxCounters mailboxCounters = mailboxManager.getMailbox(inbox1, session2)
+            .getMailboxCounters(session2);
+
+        assertThat(mailboxCounters)
+            .isEqualTo(MailboxCounters.builder()
+                .count(0)
+                .unseen(0)
+                .build());
+    }
+
+    @Test
+    public void getMailboxCountersShouldReturnStoredValueWhenReadRight() throws MailboxException {
+        Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
+        MailboxSession session1 = mailboxManager.createSystemSession(USER_1);
+        MailboxSession session2 = mailboxManager.createSystemSession(USER_2);
+        MailboxPath inbox1 = MailboxPath.inbox(session1);
+        mailboxManager.createMailbox(inbox1, session1);
+        mailboxManager.setRights(inbox1,
+            MailboxACL.EMPTY.apply(MailboxACL.command()
+                .forUser(USER_2)
+                .rights(MailboxACL.Right.Lookup, MailboxACL.Right.Read)
+                .asAddition()),
+            session1);
+        ByteArrayInputStream message = new ByteArrayInputStream("Subject: any\n\nbdy".getBytes(StandardCharsets.UTF_8));
+        boolean isRecent = true;
+        mailboxManager.getMailbox(inbox1, session1)
+            .appendMessage(message, new Date(), session1, isRecent, new Flags());
+
+        MailboxCounters mailboxCounters = mailboxManager.getMailbox(inbox1, session2)
+            .getMailboxCounters(session2);
+
+        assertThat(mailboxCounters)
+            .isEqualTo(MailboxCounters.builder()
+                .count(1)
+                .unseen(1)
+                .build());
+    }
+
+    @Test
+    public void getMetaDataShouldReturnDefaultValueWhenNoReadRight() throws MailboxException {
+        Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
+        MailboxSession session1 = mailboxManager.createSystemSession(USER_1);
+        MailboxSession session2 = mailboxManager.createSystemSession(USER_2);
+        MailboxPath inbox1 = MailboxPath.inbox(session1);
+        mailboxManager.createMailbox(inbox1, session1);
+        mailboxManager.setRights(inbox1,
+            MailboxACL.EMPTY.apply(MailboxACL.command()
+                .forUser(USER_2)
+                .rights(MailboxACL.Right.Lookup)
+                .asAddition()),
+            session1);
+        ByteArrayInputStream message = new ByteArrayInputStream("Subject: any\n\nbdy".getBytes(StandardCharsets.UTF_8));
+        boolean isRecent = true;
+        mailboxManager.getMailbox(inbox1, session1)
+            .appendMessage(message, new Date(), session1, isRecent, new Flags());
+
+        boolean resetRecent = false;
+        MessageManager.MetaData metaData = mailboxManager.getMailbox(inbox1, session2)
+            .getMetaData(resetRecent, session2, MessageManager.MetaData.FetchGroup.UNSEEN_COUNT);
+
+        softly.assertThat(metaData)
+            .extracting(MessageManager.MetaData::getHighestModSeq)
+            .contains(0L);
+        softly.assertThat(metaData)
+            .extracting(MessageManager.MetaData::getUidNext)
+            .contains(MessageUid.MIN_VALUE);
+        softly.assertThat(metaData)
+            .extracting(MessageManager.MetaData::getMessageCount)
+            .contains(0L);
+        softly.assertThat(metaData)
+            .extracting(MessageManager.MetaData::getUnseenCount)
+            .contains(0L);
+        softly.assertThat(metaData)
+            .extracting(MessageManager.MetaData::getRecent)
+            .contains(ImmutableList.of());
+        softly.assertThat(metaData)
+            .extracting(MessageManager.MetaData::getPermanentFlags)
+            .contains(new Flags());
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/ec485b53/mailbox/store/src/main/java/org/apache/james/mailbox/store/MailboxMetaData.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/MailboxMetaData.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/MailboxMetaData.java
index 7dbfa1c..a9a4f26 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/MailboxMetaData.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/MailboxMetaData.java
@@ -27,13 +27,37 @@ import javax.mail.Flags;
 
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxACL;
 
+import com.google.common.collect.ImmutableList;
+
 /**
  * Describes the current state of a mailbox.
  */
 public class MailboxMetaData implements MessageManager.MetaData {
 
+    public static MailboxMetaData sensibleInformationFree(MailboxACL resolvedAcl, long uidValidity, boolean writeable, boolean modSeqPermanent) throws MailboxException {
+        ImmutableList<MessageUid> recents = ImmutableList.of();
+        MessageUid uidNext = MessageUid.MIN_VALUE;
+        long highestModSeq = 0L;
+        long messageCount = 0L;
+        long unseenCount = 0L;
+        MessageUid firstUnseen = null;
+        return new MailboxMetaData(
+            recents,
+            new Flags(),
+            uidValidity,
+            uidNext,
+            highestModSeq,
+            messageCount,
+            unseenCount,
+            firstUnseen,
+            writeable,
+            modSeqPermanent,
+            resolvedAcl);
+    }
+
     private final long recentCount;
     private final List<MessageUid> recent;
     private final Flags permanentFlags;

http://git-wip-us.apache.org/repos/asf/james-project/blob/ec485b53/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
index 173c247..03edb61 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
@@ -110,6 +110,11 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
         .setMaxLineLen(-1)
         .build();
 
+    private static final MailboxCounters ZERO_MAILBOX_COUNTERS = MailboxCounters.builder()
+        .count(0)
+        .unseen(0)
+        .build();
+
     /**
      * The minimal Permanent flags the {@link MessageManager} must support. <br>
      * 
@@ -232,7 +237,10 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
 
     @Override
     public MailboxCounters getMailboxCounters(MailboxSession mailboxSession) throws MailboxException {
-        return mapperFactory.createMessageMapper(mailboxSession).getMailboxCounters(mailbox);
+        if (storeRightManager.hasRight(mailbox, MailboxACL.Right.Read, mailboxSession)) {
+            return mapperFactory.createMessageMapper(mailboxSession).getMailboxCounters(mailbox);
+        }
+        return ZERO_MAILBOX_COUNTERS;
     }
 
     /**
@@ -463,17 +471,21 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
 
     @Override
     public MetaData getMetaData(boolean resetRecent, MailboxSession mailboxSession, MetaData.FetchGroup fetchGroup) throws MailboxException {
-
-        final List<MessageUid> recent;
-        final Flags permanentFlags = getPermanentFlags(mailboxSession);
-        final long uidValidity = getMailboxEntity().getUidValidity();
+        MailboxACL resolvedAcl = storeRightManager.getResolvedMailboxACL(mailbox, mailboxSession);
+        boolean hasReadRight = storeRightManager.hasRight(mailbox, MailboxACL.Right.Read, mailboxSession);
+        if (!hasReadRight) {
+            return MailboxMetaData.sensibleInformationFree(resolvedAcl, getMailboxEntity().getUidValidity(), isWriteable(mailboxSession), isModSeqPermanent(mailboxSession));
+        }
+        List<MessageUid> recent;
+        Flags permanentFlags = getPermanentFlags(mailboxSession);
+        long uidValidity = getMailboxEntity().getUidValidity();
         MessageUid uidNext = mapperFactory.getMessageMapper(mailboxSession).getLastUid(mailbox)
                 .map(MessageUid::next)
                 .orElse(MessageUid.MIN_VALUE);
-        final long highestModSeq = mapperFactory.getMessageMapper(mailboxSession).getHighestModSeq(mailbox);
-        final long messageCount;
-        final long unseenCount;
-        final MessageUid firstUnseen;
+        long highestModSeq = mapperFactory.getMessageMapper(mailboxSession).getHighestModSeq(mailbox);
+        long messageCount;
+        long unseenCount;
+        MessageUid firstUnseen;
         switch (fetchGroup) {
         case UNSEEN_COUNT:
             unseenCount = countUnseenMessagesInMailbox(mailboxSession);
@@ -507,7 +519,6 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
             recent = new ArrayList<>();
             break;
         }
-        MailboxACL resolvedAcl = storeRightManager.getResolvedMailboxACL(mailbox, mailboxSession);
         return new MailboxMetaData(recent, permanentFlags, uidValidity, uidNext, highestModSeq, messageCount, unseenCount, firstUnseen, isWriteable(mailboxSession), isModSeqPermanent(mailboxSession), resolvedAcl);
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/ec485b53/mailbox/tool/src/test/java/org/apache/james/mailbox/copier/MailboxCopierTest.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/test/java/org/apache/james/mailbox/copier/MailboxCopierTest.java b/mailbox/tool/src/test/java/org/apache/james/mailbox/copier/MailboxCopierTest.java
index 0bf9ec4..7e702c8 100644
--- a/mailbox/tool/src/test/java/org/apache/james/mailbox/copier/MailboxCopierTest.java
+++ b/mailbox/tool/src/test/java/org/apache/james/mailbox/copier/MailboxCopierTest.java
@@ -119,7 +119,6 @@ public class MailboxCopierTest {
      * @throws BadCredentialsException 
      */
     private void assertMailboxManagerSize(MailboxManager mailboxManager, int multiplicationFactor) throws BadCredentialsException, MailboxException {
-        
         MailboxSession mailboxSession = mailboxManager.createSystemSession("manager");
         mailboxManager.startProcessingRequest(mailboxSession);
 
@@ -128,8 +127,10 @@ public class MailboxCopierTest {
         assertThat(mailboxPathList).hasSize(MockMailboxManager.EXPECTED_MAILBOXES_COUNT);
         
         for (MailboxPath mailboxPath: mailboxPathList) {
-            MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, mailboxSession);
-            assertThat(messageManager.getMetaData(false, mailboxSession, FetchGroup.NO_UNSEEN).getMessageCount()).isEqualTo(MockMailboxManager.MESSAGE_PER_MAILBOX_COUNT * multiplicationFactor);
+            MailboxSession userSession = mailboxManager.createSystemSession(mailboxPath.getUser());
+            mailboxManager.startProcessingRequest(mailboxSession);
+            MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, userSession);
+            assertThat(messageManager.getMetaData(false, userSession, FetchGroup.NO_UNSEEN).getMessageCount()).isEqualTo(MockMailboxManager.MESSAGE_PER_MAILBOX_COUNT * multiplicationFactor);
         }
         
         mailboxManager.endProcessingRequest(mailboxSession);

http://git-wip-us.apache.org/repos/asf/james-project/blob/ec485b53/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMailboxes.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMailboxes.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMailboxes.feature
index 45c545e..9bbe9cc 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMailboxes.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMailboxes.feature
@@ -234,3 +234,11 @@ Feature: GetMailboxes method
     Then the mailbox "shared2" has 1 message
     And the mailbox "shared2" has 1 unseen message
 
+  Scenario: Lookup right should not be enough to read message and unseen counts
+    Given "alice@domain.tld" has a mailbox "shared2"
+    And "alice@domain.tld" shares her mailbox "shared2" with "bob@domain.tld" with "l" rights
+    And "alice@domain.tld" has a message "m1" in "shared2" mailbox
+    When "bob@domain.tld" ask for mailboxes
+    Then the mailbox "shared2" has 0 messages
+    And the mailbox "shared2" has 0 unseen messages
+


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org