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 bt...@apache.org on 2017/10/18 02:03:49 UTC
[01/12] james-project git commit: JAMES-2183 Add licence to all
feature files
Repository: james-project
Updated Branches:
refs/heads/master 4b211274a -> 6c6efcd12
JAMES-2183 Add licence to all feature files
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/3fabba9e
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/3fabba9e
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/3fabba9e
Branch: refs/heads/master
Commit: 3fabba9e097920037b6741bae2dc0987ff1d3ab0
Parents: 4b21127
Author: quynhn <qn...@linagora.com>
Authored: Fri Oct 13 14:26:04 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Oct 18 08:59:58 2017 +0700
----------------------------------------------------------------------
.../resources/cucumber/DownloadEndpoint.feature | 19 ++++
.../test/resources/cucumber/DownloadGet.feature | 19 ++++
.../resources/cucumber/DownloadPost.feature | 19 ++++
.../test/resources/cucumber/GetMessages.feature | 19 ++++
.../cucumber/ImapKeywordsConsistency.feature | 109 +++++++++++++++++++
...essagesMailboxesUpdatesCompatibility.feature | 19 ++++
.../cucumber/MailboxModification.feature | 19 ++++
.../resources/cucumber/UploadEndpoint.feature | 19 ++++
8 files changed, 242 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/3fabba9e/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadEndpoint.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadEndpoint.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadEndpoint.feature
index f4be86e..419ae98 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadEndpoint.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadEndpoint.feature
@@ -1,3 +1,22 @@
+#***************************************************************
+# 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: Download endpoint
As a James user
I want to access to the download endpoint
http://git-wip-us.apache.org/repos/asf/james-project/blob/3fabba9e/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature
index 2487487..586a321 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature
@@ -1,3 +1,22 @@
+#***************************************************************
+# 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: Download GET
As a James user
I want to retrieve my blobs (attachments and messages)
http://git-wip-us.apache.org/repos/asf/james-project/blob/3fabba9e/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadPost.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadPost.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadPost.feature
index 12d655d..571af47 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadPost.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadPost.feature
@@ -1,3 +1,22 @@
+#***************************************************************
+# 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: Alternative authentication mechanism for getting attachment via a POST request returning a specific authentication token
As a James user
I want to retrieve my attachments without an alternative authentication mechanim
http://git-wip-us.apache.org/repos/asf/james-project/blob/3fabba9e/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 06715f3..a74acb7 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
@@ -1,3 +1,22 @@
+#***************************************************************
+# 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: GetMessages method
As a James user
I want to be able to retrieve my messages
http://git-wip-us.apache.org/repos/asf/james-project/blob/3fabba9e/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/ImapKeywordsConsistency.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/ImapKeywordsConsistency.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/ImapKeywordsConsistency.feature
new file mode 100644
index 0000000..5a4ec8d
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/ImapKeywordsConsistency.feature
@@ -0,0 +1,109 @@
+#***************************************************************
+# 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: Impact of IMAP on JMAP keywords consistency
+
+ Background:
+ Given a domain named "domain.tld"
+ And a connected user "username@domain.tld"
+ And "username@domain.tld" has a mailbox "source"
+ And "username@domain.tld" has a mailbox "mailbox"
+ And "username@domain.tld" has a mailbox "trash"
+
+ Scenario Outline: GetMessages should union keywords when an inconsistency was created via IMAP
+ Given the user has a message "m1" in "source" mailbox with subject "My awesome subject", content "This is the content"
+ And the user copy "m1" from mailbox "source" to mailbox "mailbox"
+ And the user has an open IMAP connection with mailbox "<mailbox>" selected
+ And the user set flags via IMAP to "(\Flagged)" for all messages in mailbox "<mailbox>"
+ When the user ask for messages "m1"
+ Then no error is returned
+ And the list should contain 1 message
+ And the id of the message is "m1"
+ And the keywords of the message is <keyword>
+
+ Examples:
+ |keyword | mailbox |
+ |$Flagged | mailbox |
+ |$Flagged | source |
+
+ Scenario Outline: GetMessages should intersect Draft when an inconsistency was created via IMAP
+ Given the user has a message "m1" in "source" mailbox with subject "My awesome subject", content "This is the content"
+ And the user copy "m1" from mailbox "source" to mailbox "mailbox"
+ And the user has an open IMAP connection with mailbox "<mailbox>" selected
+ And the user set flags via IMAP to "(\Draft)" for all messages in mailbox "<mailbox>"
+ When the user ask for messages "m1"
+ Then no error is returned
+ And the list should contain 1 message
+ And the id of the message is "m1"
+ And the keywords of the message is <keyword>
+
+ Examples:
+ |keyword | mailbox |
+ | | mailbox |
+ | | source |
+
+ Scenario: GetMessageList should return matching messageId when matching in at least 1 mailbox
+ Given the user has a message "m1" in "source" mailbox with subject "My awesome subject", content "This is the content"
+ And the user copy "m1" from mailbox "source" to mailbox "mailbox"
+ And the user has an open IMAP connection with mailbox "mailbox" selected
+ And the user set flags via IMAP to "(\Flagged)" for all messages in mailbox "mailbox"
+ When the user asks for message list with flag "$Flagged"
+ Then the message list has size 1
+ And the message list contains "m1"
+
+ Scenario: GetMessageList in specific mailbox should return messageId when matching
+ Given the user has a message "m1" in "source" mailbox with subject "My awesome subject", content "This is the content"
+ And the user copy "m1" from mailbox "source" to mailbox "mailbox"
+ And the user has an open IMAP connection with mailbox "mailbox" selected
+ And the user set flags via IMAP to "(\Flagged)" for all messages in mailbox "mailbox"
+ When the user asks for message list in mailbox "mailbox" with flag "$Flagged"
+ Then the message list has size 1
+ And the message list contains "m1"
+
+ Scenario: GetMessageList in specific mailbox should skip messageId when not matching
+ Given the user has a message "m1" in "source" mailbox with subject "My awesome subject", content "This is the content"
+ And the user copy "m1" from mailbox "source" to mailbox "mailbox"
+ And the user has an open IMAP connection with mailbox "mailbox" selected
+ And the user set flags via IMAP to "(\Flagged)" for all messages in mailbox "mailbox"
+ When the user asks for message list in mailbox "source" with flag "$Flagged"
+ Then the message list is empty
+
+ Scenario: SetMessages should succeed to solve Keywords conflict introduced via IMAP upon flags addition
+ Given the user has a message "m1" in "source" mailbox with subject "My awesome subject", content "This is the content"
+ And the user copy "m1" from mailbox "source" to mailbox "mailbox"
+ And the user has an open IMAP connection with mailbox "mailbox" selected
+ And the user set flags via IMAP to "(\Flagged)" for all messages in mailbox "mailbox"
+ When the user set flags on "m1" to "$Flagged"
+ Then the user asks for message list in mailbox "mailbox" with flag "$Flagged"
+ And the message list has size 1
+ And the message list contains "m1"
+ And the user asks for message list in mailbox "source" with flag "$Flagged"
+ And the message list has size 1
+ And the message list contains "m1"
+
+ Scenario: SetMessages should ignore Keywords conflict introduced via IMAP upon flags deletion
+ Given the user has a message "m1" in "source" mailbox with subject "My awesome subject", content "This is the content"
+ And the user copy "m1" from mailbox "source" to mailbox "mailbox"
+ And the user has an open IMAP connection with mailbox "mailbox" selected
+ And the user set flags via IMAP to "(\Flagged)" for all messages in mailbox "mailbox"
+ When the user set flags on "m1" to "$Answered"
+ Then the user asks for message list in mailbox "mailbox" with flag "$Flagged"
+ And the message list is empty
+ And the user asks for message list in mailbox "source" with flag "$Flagged"
+ And the message list is empty
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/3fabba9e/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/ImapSetMessagesMailboxesUpdatesCompatibility.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/ImapSetMessagesMailboxesUpdatesCompatibility.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/ImapSetMessagesMailboxesUpdatesCompatibility.feature
index fdc12c9..33ae498 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/ImapSetMessagesMailboxesUpdatesCompatibility.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/ImapSetMessagesMailboxesUpdatesCompatibility.feature
@@ -1,3 +1,22 @@
+#***************************************************************
+# 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: IMAP compatibility of JMAP setMessages method used to update mailboxes
As a James user
I want to be able to access by IMAP messages moved and copied by JMAP
http://git-wip-us.apache.org/repos/asf/james-project/blob/3fabba9e/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/MailboxModification.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/MailboxModification.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/MailboxModification.feature
index 8ec100c..7b63c86 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/MailboxModification.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/MailboxModification.feature
@@ -1,3 +1,22 @@
+#***************************************************************
+# 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: Mailbox modification
As a James user
I want a mailbox to be modified when I modify it
http://git-wip-us.apache.org/repos/asf/james-project/blob/3fabba9e/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/UploadEndpoint.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/UploadEndpoint.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/UploadEndpoint.feature
index 6f82ada..2a33fd9 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/UploadEndpoint.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/UploadEndpoint.feature
@@ -1,3 +1,22 @@
+#***************************************************************
+# 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: An upload endpoint should be available to upload contents
As a James user
I want to upload my attachments
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[02/12] james-project git commit: JAMES-2183 Add CommutativityChecker
class
Posted by bt...@apache.org.
JAMES-2183 Add CommutativityChecker class
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/d1238fc2
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/d1238fc2
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/d1238fc2
Branch: refs/heads/master
Commit: d1238fc24ea0894634299ddd9b89531a0ae3c2c9
Parents: 747e3f1
Author: quynhn <qn...@linagora.com>
Authored: Fri Oct 13 11:45:36 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Oct 18 09:00:38 2017 +0700
----------------------------------------------------------------------
pom.xml | 5 +
server/container/util-java8/pom.xml | 5 +
.../apache/james/util/CommutativityChecker.java | 60 +++++++++++
.../james/util/CommutativityCheckerTest.java | 101 +++++++++++++++++++
server/protocols/jmap/pom.xml | 5 +
5 files changed, 176 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/d1238fc2/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 11d1d90..fa6b127 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1419,6 +1419,11 @@
<version>2.6.3</version>
</dependency>
<dependency>
+ <groupId>com.github.dpaukov</groupId>
+ <artifactId>combinatoricslib3</artifactId>
+ <version>3.2.0</version>
+ </dependency>
+ <dependency>
<groupId>com.github.fge</groupId>
<artifactId>throwing-lambdas</artifactId>
<version>0.5.0</version>
http://git-wip-us.apache.org/repos/asf/james-project/blob/d1238fc2/server/container/util-java8/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/util-java8/pom.xml b/server/container/util-java8/pom.xml
index 43bfcf3..c00ebe2 100644
--- a/server/container/util-java8/pom.xml
+++ b/server/container/util-java8/pom.xml
@@ -83,6 +83,11 @@
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.github.dpaukov</groupId>
+ <artifactId>combinatoricslib3</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
http://git-wip-us.apache.org/repos/asf/james-project/blob/d1238fc2/server/container/util-java8/src/test/java/org/apache/james/util/CommutativityChecker.java
----------------------------------------------------------------------
diff --git a/server/container/util-java8/src/test/java/org/apache/james/util/CommutativityChecker.java b/server/container/util-java8/src/test/java/org/apache/james/util/CommutativityChecker.java
new file mode 100644
index 0000000..5620af5
--- /dev/null
+++ b/server/container/util-java8/src/test/java/org/apache/james/util/CommutativityChecker.java
@@ -0,0 +1,60 @@
+/****************************************************************
+ * 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.util;
+
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.BinaryOperator;
+import java.util.stream.Stream;
+
+import org.apache.commons.lang3.tuple.Pair;
+import org.paukov.combinatorics3.Generator;
+
+import com.github.steveash.guavate.Guavate;
+import com.google.common.base.Preconditions;
+
+public class CommutativityChecker<T> {
+ private final Set<T> valuesToTest;
+ private final BinaryOperator<T> operationToTest;
+
+ public CommutativityChecker(Set<T> valuesToTest, BinaryOperator<T> operationToTest) {
+ Preconditions.checkNotNull(valuesToTest);
+ Preconditions.checkNotNull(operationToTest);
+ Preconditions.checkArgument(valuesToTest.size() > 1, "You must to pass more than one value to check commutativity");
+ this.valuesToTest = valuesToTest;
+ this.operationToTest = operationToTest;
+ }
+
+ public Set<Pair<T, T>> findNonCommutativeInput() {
+ return Generator.combination(valuesToTest)
+ .simple(2)
+ .stream()
+ .map(list -> Pair.of(list.get(0), list.get(1)))
+ .filter(this::isNotCommutative)
+ .collect(Guavate.toImmutableSet());
+ }
+
+ private boolean isNotCommutative(Pair<T, T> pair) {
+ T leftThenRight = operationToTest.apply(pair.getLeft(), pair.getRight());
+ T rightThenLeft = operationToTest.apply(pair.getRight(), pair.getLeft());
+ return !leftThenRight.equals(rightThenLeft);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/d1238fc2/server/container/util-java8/src/test/java/org/apache/james/util/CommutativityCheckerTest.java
----------------------------------------------------------------------
diff --git a/server/container/util-java8/src/test/java/org/apache/james/util/CommutativityCheckerTest.java b/server/container/util-java8/src/test/java/org/apache/james/util/CommutativityCheckerTest.java
new file mode 100644
index 0000000..a77b8e5
--- /dev/null
+++ b/server/container/util-java8/src/test/java/org/apache/james/util/CommutativityCheckerTest.java
@@ -0,0 +1,101 @@
+/****************************************************************
+ * 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.util;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.Set;
+import java.util.function.BinaryOperator;
+
+import org.apache.commons.lang3.tuple.Pair;
+import org.junit.Test;
+import org.testcontainers.shaded.com.google.common.collect.ImmutableSet;
+
+public class CommutativityCheckerTest {
+ @Test
+ public void constructorShouldThrowWhenNullValuesToTest() throws Exception {
+ BinaryOperator<Integer> binaryOperator = (a, b) -> a * a + b;
+
+ assertThatThrownBy(() -> new CommutativityChecker<>(null, binaryOperator))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ public void constructorShouldThrowWhenEmptyValuesToTest() throws Exception {
+ BinaryOperator<Integer> binaryOperator = (a, b) -> a * a + b;
+
+ assertThatThrownBy(() -> new CommutativityChecker<>(ImmutableSet.of(), binaryOperator))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void constructorShouldThrowWhenSingleValueToTest() throws Exception {
+ BinaryOperator<Integer> binaryOperator = (a, b) -> a * a + b;
+
+ assertThatThrownBy(() -> new CommutativityChecker<>(ImmutableSet.of(0), binaryOperator))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void constructorShouldThrowWhenNullOperation() throws Exception {
+ assertThatThrownBy(() -> new CommutativityChecker<>(ImmutableSet.of(0, 1), null))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ public void findNonCommutativeInputShouldReturnEmptyWhenCommutativeOperation() throws Exception {
+ Set<Integer> integers = ImmutableSet.of(5, 4, 3, 2, 1);
+ BinaryOperator<Integer> commutativeOperator = (a, b) -> a + b;
+ CommutativityChecker<Integer> commutativityChecker = new CommutativityChecker<>(integers, commutativeOperator);
+
+ assertThat(commutativityChecker.findNonCommutativeInput()).isEmpty();
+ }
+
+ @Test
+ public void findNonCommutativeInputShouldReturnDataWhenNonCommutativeOperation() throws Exception {
+ Set<Integer> integers = ImmutableSet.of(2, 1);
+ BinaryOperator<Integer> nonCommutativeOperator = (a, b) -> 2 * a + b;
+ CommutativityChecker<Integer> commutativityChecker = new CommutativityChecker<>(integers, nonCommutativeOperator);
+
+ assertThat(commutativityChecker.findNonCommutativeInput())
+ .containsOnly(Pair.of(2, 1));
+ }
+
+ @Test
+ public void findNonCommutativeInputShouldNotReturnStableValues() throws Exception {
+ Set<Integer> integers = ImmutableSet.of(0, 1, 2);
+ BinaryOperator<Integer> nonCommutativeOperatorWithStableValues = (a, b) -> a * a + b;
+ CommutativityChecker<Integer> commutativityChecker = new CommutativityChecker<>(integers, nonCommutativeOperatorWithStableValues);
+
+ assertThat(commutativityChecker.findNonCommutativeInput())
+ .containsOnly(Pair.of(1, 2),
+ Pair.of(0, 2));
+ }
+
+ @Test
+ public void findNonCommutativeInputShouldReturnEmptyWhenNonCommutativeOperationButOnlyStableValues() throws Exception {
+ Set<Integer> stableValues = ImmutableSet.of(0, 1);
+ BinaryOperator<Integer> nonCommutativeOperatorWithStableValues = (a, b) -> a * a + b;
+ CommutativityChecker<Integer> commutativityChecker = new CommutativityChecker<>(stableValues, nonCommutativeOperatorWithStableValues);
+
+ assertThat(commutativityChecker.findNonCommutativeInput()).isEmpty();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/d1238fc2/server/protocols/jmap/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/pom.xml b/server/protocols/jmap/pom.xml
index 52ea6f1..5cebbd0 100644
--- a/server/protocols/jmap/pom.xml
+++ b/server/protocols/jmap/pom.xml
@@ -143,6 +143,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>com.github.dpaukov</groupId>
+ <artifactId>combinatoricslib3</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[03/12] james-project git commit: JAMES-2183 Add util to build Flags
from list of String
Posted by bt...@apache.org.
JAMES-2183 Add util to build Flags from list of String
We need it to enable invalid keyword testing in JMAP integration tests.
Previously, cucumber generated flags relied on JMAP Keyword, thus we could not create invalid keyword.
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/747e3f19
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/747e3f19
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/747e3f19
Branch: refs/heads/master
Commit: 747e3f19dd03fba3e18c47d89507a743507b1132
Parents: 3fabba9
Author: quynhn <qn...@linagora.com>
Authored: Fri Oct 13 10:22:01 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Oct 18 09:00:38 2017 +0700
----------------------------------------------------------------------
.../cucumber/GetMessagesMethodStepdefs.java | 8 +-
.../integration/cucumber/StringListToFlags.java | 62 +++++++++++++++
.../cucumber/StringListToFlagsTest.java | 80 ++++++++++++++++++++
3 files changed, 144 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/747e3f19/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 05657a2..cc9f465 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
@@ -42,7 +42,6 @@ import org.apache.http.HttpResponse;
import org.apache.http.client.fluent.Request;
import org.apache.james.jmap.DefaultMailboxes;
import org.apache.james.jmap.methods.integration.cucumber.util.TableRow;
-import org.apache.james.jmap.model.Keywords;
import org.apache.james.jmap.model.MessagePreviewGenerator;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailbox.model.MailboxId;
@@ -248,11 +247,8 @@ public class GetMessagesMethodStepdefs {
}
@Given("^the user has a message \"([^\"]*)\" in the \"([^\"]*)\" mailbox with flags \"([^\"]*)\"$")
- public void appendMessageWithFlags(String messageName, String mailbox, List<String> keywords) throws Exception {
- Flags flags = Keywords.factory()
- .fromList(keywords)
- .asFlags();
- appendMessage(messageName, flags);
+ public void appendMessageWithFlags(String messageName, String mailbox, List<String> flagList) throws Exception {
+ appendMessage(messageName, FlagListToFlags.fromFlagList(flagList));
}
private void appendMessage(String messageName, Flags flags) throws Exception {
http://git-wip-us.apache.org/repos/asf/james-project/blob/747e3f19/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/StringListToFlags.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/StringListToFlags.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/StringListToFlags.java
new file mode 100644
index 0000000..36a273f
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/StringListToFlags.java
@@ -0,0 +1,62 @@
+/****************************************************************
+ * 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 java.util.List;
+
+import javax.mail.Flags;
+
+import org.apache.james.jmap.model.Keyword;
+import org.apache.james.mailbox.FlagsBuilder;
+
+import com.github.steveash.guavate.Guavate;
+import com.google.common.collect.ImmutableList;
+
+public class StringListToFlags {
+ public static Flags fromFlagList(List<String> flagList) {
+ ImmutableList<Flags> flags = flagList.stream()
+ .map(StringListToFlags::toFlags)
+ .collect(Guavate.toImmutableList());
+ return new FlagsBuilder().add(flags)
+ .build();
+ }
+
+ private static Flags toFlags(String flag) {
+ if (Keyword.ANSWERED.getFlagName().equals(flag)) {
+ return new Flags(Flags.Flag.ANSWERED);
+ }
+ if (Keyword.DELETED.getFlagName().equals(flag)) {
+ return new Flags(Flags.Flag.DELETED);
+ }
+ if (Keyword.DRAFT.getFlagName().equals(flag)) {
+ return new Flags(Flags.Flag.DRAFT);
+ }
+ if (Keyword.RECENT.getFlagName().equals(flag)) {
+ return new Flags(Flags.Flag.RECENT);
+ }
+ if (Keyword.FLAGGED.getFlagName().equals(flag)) {
+ return new Flags(Flags.Flag.FLAGGED);
+ }
+ if (Keyword.SEEN.getFlagName().equals(flag)) {
+ return new Flags(Flags.Flag.SEEN);
+ }
+ return new Flags(flag);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/747e3f19/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/StringListToFlagsTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/StringListToFlagsTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/StringListToFlagsTest.java
new file mode 100644
index 0000000..9ae5aa0
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/StringListToFlagsTest.java
@@ -0,0 +1,80 @@
+/****************************************************************
+ * 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 org.assertj.core.api.Assertions.assertThat;
+
+import javax.mail.Flags;
+import javax.mail.Flags.Flag;
+
+import org.apache.james.jmap.model.Keyword;
+import org.junit.Test;
+import org.testcontainers.shaded.com.google.common.collect.ImmutableList;
+
+public class StringListToFlagsTest {
+ @Test
+ public void fromFlagListShouldConvertAnwseredFlag() throws Exception {
+ assertThat(StringListToFlags.fromFlagList(ImmutableList.of(Keyword.ANSWERED.getFlagName())))
+ .isEqualTo(new Flags(Flag.ANSWERED));
+ }
+
+ @Test
+ public void fromFlagListShouldConvertSeenFlag() throws Exception {
+ assertThat(StringListToFlags.fromFlagList(ImmutableList.of(Keyword.SEEN.getFlagName())))
+ .isEqualTo(new Flags(Flag.SEEN));
+ }
+
+ @Test
+ public void fromFlagListShouldConvertDraftFlag() throws Exception {
+ assertThat(StringListToFlags.fromFlagList(ImmutableList.of(Keyword.DRAFT.getFlagName())))
+ .isEqualTo(new Flags(Flag.DRAFT));
+ }
+
+ @Test
+ public void fromFlagListShouldConvertRecentFlag() throws Exception {
+ assertThat(StringListToFlags.fromFlagList(ImmutableList.of(Keyword.RECENT.getFlagName())))
+ .isEqualTo(new Flags(Flag.RECENT));
+ }
+
+ @Test
+ public void fromFlagListShouldConvertDeletedFlag() throws Exception {
+ assertThat(StringListToFlags.fromFlagList(ImmutableList.of(Keyword.DELETED.getFlagName())))
+ .isEqualTo(new Flags(Flag.DELETED));
+ }
+
+ @Test
+ public void fromFlagListShouldConvertFlaggedFlag() throws Exception {
+ assertThat(StringListToFlags.fromFlagList(ImmutableList.of(Keyword.FLAGGED.getFlagName())))
+ .isEqualTo(new Flags(Flag.FLAGGED));
+ }
+
+ @Test
+ public void fromFlagListShouldConvertValidJMAPFlag() throws Exception {
+ assertThat(StringListToFlags.fromFlagList(ImmutableList.of("$Any")))
+ .isEqualTo(new Flags("$Any"));
+ }
+
+ @Test
+ public void fromFlagListShouldConvertInvalidJMAPFlag() throws Exception {
+ assertThat(StringListToFlags.fromFlagList(ImmutableList.of("op§")))
+ .isEqualTo(new Flags("op§"));
+ }
+
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[08/12] james-project git commit: JAMES-2188 A user can't set a
message in a mailbox from someone else.
Posted by bt...@apache.org.
JAMES-2188 A user can't set a message in a mailbox from someone else.
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/bb1eeec8
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/bb1eeec8
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/bb1eeec8
Branch: refs/heads/master
Commit: bb1eeec860dfadc0663939836c662f2f2865e598
Parents: 6ff67ca
Author: Antoine Duprat <ad...@linagora.com>
Authored: Mon Oct 16 14:46:40 2017 +0200
Committer: benwa <bt...@linagora.com>
Committed: Wed Oct 18 09:01:56 2017 +0700
----------------------------------------------------------------------
.../jmap/methods/MailboxRightsException.java | 29 +++++++
.../methods/SetMessagesCreationProcessor.java | 41 ++++++++-
.../SetMessagesCreationProcessorTest.java | 87 +++++++++++++++++++-
3 files changed, 151 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/bb1eeec8/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MailboxRightsException.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MailboxRightsException.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MailboxRightsException.java
new file mode 100644
index 0000000..f47e7d0
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MailboxRightsException.java
@@ -0,0 +1,29 @@
+/****************************************************************
+ * 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;
+
+import org.apache.james.mailbox.exception.MailboxException;
+
+public class MailboxRightsException extends MailboxException {
+
+ public MailboxRightsException() {
+ super();
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/bb1eeec8/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
index 3087e71..8c482e3 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
@@ -57,6 +57,7 @@ import org.apache.james.jmap.send.MailSpool;
import org.apache.james.jmap.utils.SystemMailboxesProvider;
import org.apache.james.lifecycle.api.LifecycleUtil;
import org.apache.james.mailbox.AttachmentManager;
+import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.MessageManager;
import org.apache.james.mailbox.exception.AttachmentNotFoundException;
@@ -65,6 +66,7 @@ import org.apache.james.mailbox.exception.MailboxNotFoundException;
import org.apache.james.mailbox.model.AttachmentId;
import org.apache.james.mailbox.model.Cid;
import org.apache.james.mailbox.model.ComposedMessageId;
+import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.metrics.api.TimeMetric;
@@ -93,6 +95,8 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
private final SystemMailboxesProvider systemMailboxesProvider;
private final AttachmentManager attachmentManager;
private final MetricFactory metricFactory;
+ private final MailboxManager mailboxManager;
+ private final MailboxId.Factory mailboxIdFactory;
@VisibleForTesting @Inject
SetMessagesCreationProcessor(MIMEMessageConverter mimeMessageConverter,
@@ -100,7 +104,10 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
MailFactory mailFactory,
MessageFactory messageFactory,
SystemMailboxesProvider systemMailboxesProvider,
- AttachmentManager attachmentManager, MetricFactory metricFactory) {
+ AttachmentManager attachmentManager,
+ MetricFactory metricFactory,
+ MailboxManager mailboxManager,
+ MailboxId.Factory mailboxIdFactory) {
this.mimeMessageConverter = mimeMessageConverter;
this.mailSpool = mailSpool;
this.mailFactory = mailFactory;
@@ -108,6 +115,8 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
this.systemMailboxesProvider = systemMailboxesProvider;
this.attachmentManager = attachmentManager;
this.metricFactory = metricFactory;
+ this.mailboxManager = mailboxManager;
+ this.mailboxIdFactory = mailboxIdFactory;
}
@Override
@@ -167,6 +176,14 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
.description(e.getMessage())
.build());
+ } catch (MailboxRightsException e) {
+ LOG.error("Appending message in an unknown mailbox", e);
+ responseBuilder.notCreated(create.getCreationId(),
+ SetError.builder()
+ .type("error")
+ .description("MailboxId invalid")
+ .build());
+
} catch (MailboxException | MessagingException e) {
LOG.error("Unexpected error while creating message", e);
responseBuilder.notCreated(create.getCreationId(),
@@ -223,7 +240,12 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
return AttachmentId.from(attachment.getBlobId().getRawValue());
}
- private void validateRights(CreationMessageEntry entry, MailboxSession session) throws MailboxSendingNotAllowedException {
+ private void validateRights(CreationMessageEntry entry, MailboxSession session) throws MailboxSendingNotAllowedException, MailboxRightsException {
+ validateUserIsInSenders(entry, session);
+ validateIsUserOwnerOfMailboxes(entry, session);
+ }
+
+ private void validateUserIsInSenders(CreationMessageEntry entry, MailboxSession session) throws MailboxSendingNotAllowedException {
List<String> allowedSenders = ImmutableList.of(session.getUser().getUserName());
if (!isAllowedFromAddress(entry.getValue(), allowedSenders)) {
throw new MailboxSendingNotAllowedException(allowedSenders);
@@ -238,7 +260,20 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
.orElse(false);
}
-
+ @VisibleForTesting void validateIsUserOwnerOfMailboxes(CreationMessageEntry entry, MailboxSession session) throws MailboxRightsException {
+ if (containsMailboxNotOwn(entry.getValue().getMailboxIds(), session)) {
+ throw new MailboxRightsException();
+ }
+ }
+
+ private boolean containsMailboxNotOwn(List<String> mailboxIds, MailboxSession session) {
+ return mailboxIds.stream()
+ .map(mailboxIdFactory::fromString)
+ .map(Throwing.function(mailboxId -> mailboxManager.getMailbox(mailboxId, session)))
+ .map(Throwing.function(MessageManager::getMailboxPath))
+ .anyMatch(path -> !session.getUser().isSameUser(path.getUser()));
+ }
+
private MessageWithId handleOutboxMessages(CreationMessageEntry entry, MailboxSession session) throws MailboxException, MessagingException {
MessageManager outbox = getMailboxWithRole(session, Role.OUTBOX).orElseThrow(() -> new MailboxNotFoundException(Role.OUTBOX.serialize()));
if (!isRequestForSending(entry.getValue(), session)) {
http://git-wip-us.apache.org/repos/asf/james-project/blob/bb1eeec8/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
index c1b9f00..8618b11 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
@@ -56,15 +56,19 @@ import org.apache.james.jmap.utils.HtmlTextExtractor;
import org.apache.james.jmap.utils.SystemMailboxesProvider;
import org.apache.james.mailbox.AttachmentManager;
import org.apache.james.mailbox.BlobManager;
+import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.MessageManager;
import org.apache.james.mailbox.MessageUid;
import org.apache.james.mailbox.exception.AttachmentNotFoundException;
import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.exception.MailboxNotFoundException;
import org.apache.james.mailbox.inmemory.InMemoryId;
import org.apache.james.mailbox.mock.MockMailboxSession;
import org.apache.james.mailbox.model.AttachmentId;
import org.apache.james.mailbox.model.ComposedMessageId;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxId.Factory;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.MessageId;
import org.apache.james.mailbox.model.TestMessageId;
@@ -113,6 +117,8 @@ public class SetMessagesCreationProcessorTest {
private MockMailboxSession session;
private MIMEMessageConverter mimeMessageConverter;
private AttachmentManager mockedAttachmentManager;
+ private MailboxManager mockedMailboxManager;
+ private Factory mockedMailboxIdFactory;
private SetMessagesCreationProcessor sut;
private MessageManager outbox;
private MessageManager drafts;
@@ -121,6 +127,7 @@ public class SetMessagesCreationProcessorTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
+
@Before
public void setUp() throws MailboxException {
HtmlTextExtractor htmlTextExtractor = mock(HtmlTextExtractor.class);
@@ -133,13 +140,20 @@ public class SetMessagesCreationProcessorTest {
mockedMailSpool = mock(MailSpool.class);
mockedMailFactory = mock(MailFactory.class);
mockedAttachmentManager = mock(AttachmentManager.class);
+ mockedMailboxManager = mock(MailboxManager.class);
+ mockedMailboxIdFactory = mock(MailboxId.Factory.class);
fakeSystemMailboxesProvider = new TestSystemMailboxesProvider(() -> optionalOutbox, () -> optionalDrafts);
session = new MockMailboxSession(USER);
mimeMessageConverter = new MIMEMessageConverter();
- sut = new SetMessagesCreationProcessor(mimeMessageConverter, mockedMailSpool, mockedMailFactory, messageFactory, fakeSystemMailboxesProvider, mockedAttachmentManager, new NoopMetricFactory());
+ sut = new SetMessagesCreationProcessor(mimeMessageConverter, mockedMailSpool, mockedMailFactory, messageFactory, fakeSystemMailboxesProvider, mockedAttachmentManager, new NoopMetricFactory(), mockedMailboxManager, mockedMailboxIdFactory);
outbox = mock(MessageManager.class);
+ when(mockedMailboxIdFactory.fromString(OUTBOX_ID.serialize()))
+ .thenReturn(OUTBOX_ID);
+ when(mockedMailboxManager.getMailbox(OUTBOX_ID, session))
+ .thenReturn(outbox);
+
when(outbox.getId()).thenReturn(OUTBOX_ID);
when(outbox.getMailboxPath()).thenReturn(MailboxPath.forUser(USER, OUTBOX));
@@ -216,7 +230,7 @@ public class SetMessagesCreationProcessorTest {
@Test
public void processShouldReturnNonEmptyCreatedWhenRequestHasNonEmptyCreate() throws MailboxException {
// Given
- sut = new SetMessagesCreationProcessor(mimeMessageConverter, mockedMailSpool, mockedMailFactory, messageFactory, fakeSystemMailboxesProvider, mockedAttachmentManager, new NoopMetricFactory());
+ sut = new SetMessagesCreationProcessor(mimeMessageConverter, mockedMailSpool, mockedMailFactory, messageFactory, fakeSystemMailboxesProvider, mockedAttachmentManager, new NoopMetricFactory(), mockedMailboxManager, mockedMailboxIdFactory);
// When
SetMessagesResponse result = sut.process(createMessageInOutbox, session);
@@ -231,7 +245,7 @@ public class SetMessagesCreationProcessorTest {
public void processShouldReturnErrorWhenOutboxNotFound() {
// Given
TestSystemMailboxesProvider doNotProvideOutbox = new TestSystemMailboxesProvider(Optional::empty, () -> optionalDrafts);
- SetMessagesCreationProcessor sut = new SetMessagesCreationProcessor(mimeMessageConverter, mockedMailSpool, mockedMailFactory, messageFactory, doNotProvideOutbox, mockedAttachmentManager, new NoopMetricFactory());
+ SetMessagesCreationProcessor sut = new SetMessagesCreationProcessor(mimeMessageConverter, mockedMailSpool, mockedMailFactory, messageFactory, doNotProvideOutbox, mockedAttachmentManager, new NoopMetricFactory(), mockedMailboxManager, mockedMailboxIdFactory);
// When
SetMessagesResponse actual = sut.process(createMessageInOutbox, session);
@@ -347,6 +361,73 @@ public class SetMessagesCreationProcessorTest {
.isInstanceOf(AttachmentsNotFoundException.class)
.matches(e -> ((AttachmentsNotFoundException)e).getAttachmentIds().containsAll(ImmutableSet.of(unknownBlobId1, unknownBlobId2)));
}
+
+ @Test
+ public void validateIsUserOwnerOfMailboxesShouldThrowWhenMailboxIdDoesntExist() throws Exception {
+ InMemoryId mailboxId = InMemoryId.of(6789);
+ when(mockedMailboxManager.getMailbox(mailboxId, session))
+ .thenThrow(new MailboxNotFoundException(mailboxId));
+ when(mockedMailboxIdFactory.fromString(mailboxId.serialize()))
+ .thenReturn(mailboxId);
+ CreationMessageId creationMessageId = CreationMessageId.of("anything-really");
+ CreationMessageEntry entry = new CreationMessageEntry(creationMessageId, creationMessageBuilder.mailboxId(mailboxId.serialize()).build());
+
+ assertThatThrownBy(() -> sut.validateIsUserOwnerOfMailboxes(entry, session));
+ }
+
+ @Test
+ public void validateIsUserOwnerOfMailboxesShouldThrowWhenRetrievingMailboxPathFails() throws Exception {
+ CreationMessageId creationMessageId = CreationMessageId.of("anything-really");
+ InMemoryId mailboxId = InMemoryId.of(6789);
+ MessageManager mailbox = mock(MessageManager.class);
+ when(mockedMailboxManager.getMailbox(mailboxId, session))
+ .thenReturn(mailbox);
+ when(mockedMailboxIdFactory.fromString(mailboxId.serialize()))
+ .thenReturn(mailboxId);
+ when(mailbox.getMailboxPath())
+ .thenThrow(new MailboxException());
+
+ CreationMessageEntry entry = new CreationMessageEntry(creationMessageId, creationMessageBuilder.mailboxId(mailboxId.serialize()).build());
+
+ assertThatThrownBy(() -> sut.validateIsUserOwnerOfMailboxes(entry, session));
+ }
+
+ @Test
+ public void validateIsUserOwnerOfMailboxesShouldThrowWhenUserIsNotTheOwnerOfTheMailbox() throws Exception {
+ CreationMessageId creationMessageId = CreationMessageId.of("anything-really");
+ InMemoryId mailboxId = InMemoryId.of(6789);
+ MessageManager mailbox = mock(MessageManager.class);
+ when(mockedMailboxManager.getMailbox(mailboxId, session))
+ .thenReturn(mailbox);
+ when(mockedMailboxIdFactory.fromString(mailboxId.serialize()))
+ .thenReturn(mailboxId);
+ when(mailbox.getMailboxPath())
+ .thenReturn(MailboxPath.forUser("otheruser@example.com", mailboxId.serialize()));
+
+
+ CreationMessageEntry entry = new CreationMessageEntry(creationMessageId, creationMessageBuilder.mailboxId(mailboxId.serialize()).build());
+
+ assertThatThrownBy(() -> sut.validateIsUserOwnerOfMailboxes(entry, session))
+ .isInstanceOf(MailboxRightsException.class);
+ }
+
+ @Test
+ public void validateIsUserOwnerOfMailboxesShouldNotThrowWhenUserIsTheOwnerOfTheMailbox() throws Exception {
+ CreationMessageId creationMessageId = CreationMessageId.of("anything-really");
+ InMemoryId mailboxId = InMemoryId.of(6789);
+ MessageManager mailbox = mock(MessageManager.class);
+ when(mockedMailboxManager.getMailbox(mailboxId, session))
+ .thenReturn(mailbox);
+ when(mockedMailboxIdFactory.fromString(mailboxId.serialize()))
+ .thenReturn(mailboxId);
+ when(mailbox.getMailboxPath())
+ .thenReturn(MailboxPath.forUser(USER, mailboxId.serialize()));
+
+
+ CreationMessageEntry entry = new CreationMessageEntry(creationMessageId, creationMessageBuilder.mailboxId(mailboxId.serialize()).build());
+
+ sut.validateIsUserOwnerOfMailboxes(entry, session);
+ }
public static class TestSystemMailboxesProvider implements SystemMailboxesProvider {
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[07/12] james-project git commit: JAMES-2183 IMAP Keywords
consistency integration test
Posted by bt...@apache.org.
JAMES-2183 IMAP Keywords consistency integration test
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/6ff67ca3
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/6ff67ca3
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/6ff67ca3
Branch: refs/heads/master
Commit: 6ff67ca3a579a27092dce8f6f93a8ff7b8db2d6b
Parents: c93ffe6
Author: benwa <bt...@linagora.com>
Authored: Fri Oct 13 09:56:07 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Oct 18 09:01:10 2017 +0700
----------------------------------------------------------------------
...assandraIMAPKeywordsInconsistenciesTest.java | 44 +++++++
.../cucumber/GetMessageListMethodStepdefs.java | 117 +++++++++++++++++++
.../cucumber/GetMessagesMethodStepdefs.java | 8 +-
.../integration/cucumber/ImapStepdefs.java | 12 +-
.../cucumber/SetMessagesMethodStepdefs.java | 38 +++++-
.../cucumber/ImapKeywordsConsistency.feature | 36 +++++-
.../MemoryIMAPKeywordsInconsistenciesTest.java | 32 +++++
.../apache/james/utils/IMAPMessageReader.java | 5 +
8 files changed, 285 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/6ff67ca3/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraIMAPKeywordsInconsistenciesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraIMAPKeywordsInconsistenciesTest.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraIMAPKeywordsInconsistenciesTest.java
new file mode 100644
index 0000000..c5dde12
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraIMAPKeywordsInconsistenciesTest.java
@@ -0,0 +1,44 @@
+/****************************************************************
+ * 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/ImapKeywordsConsistency.feature",
+ glue={"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.cassandra.cucumber"},
+ strict = true)
+public class CassandraIMAPKeywordsInconsistenciesTest {
+
+ @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/6ff67ca3/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessageListMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessageListMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessageListMethodStepdefs.java
new file mode 100644
index 0000000..c718803
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessageListMethodStepdefs.java
@@ -0,0 +1,117 @@
+/****************************************************************
+ * 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 org.assertj.core.api.Assertions.assertThat;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.fluent.Request;
+import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.modules.MailboxProbeImpl;
+
+import com.jayway.jsonpath.Configuration;
+import com.jayway.jsonpath.DocumentContext;
+import com.jayway.jsonpath.JsonPath;
+import com.jayway.jsonpath.Option;
+
+import cucumber.api.java.en.Then;
+import cucumber.api.java.en.When;
+import cucumber.runtime.java.guice.ScenarioScoped;
+
+@ScenarioScoped
+public class GetMessageListMethodStepdefs {
+
+ private static final String ARGUMENTS = "[0][1]";
+ private final MainStepdefs mainStepdefs;
+ private final UserStepdefs userStepdefs;
+ private final GetMessagesMethodStepdefs messagesMethodStepdefs;
+
+ private HttpResponse response;
+ private DocumentContext jsonPath;
+
+ @Inject
+ private GetMessageListMethodStepdefs(MainStepdefs mainStepdefs, UserStepdefs userStepdefs, GetMessagesMethodStepdefs messagesMethodStepdefs) {
+ this.mainStepdefs = mainStepdefs;
+ this.userStepdefs = userStepdefs;
+ this.messagesMethodStepdefs = messagesMethodStepdefs;
+ }
+
+ @When("^the user asks for message list in mailbox \"([^\"]*)\" with flag \"([^\"]*)\"$")
+ public void getMessageList(String mailbox, String flag) throws Exception {
+ MailboxId mailboxId = mainStepdefs.jmapServer
+ .getProbe(MailboxProbeImpl.class)
+ .getMailbox(MailboxConstants.USER_NAMESPACE, userStepdefs.lastConnectedUser, mailbox)
+ .getMailboxId();
+
+ post(String.format(
+ "[[\"getMessageList\", {\"filter\":{" +
+ " \"inMailboxes\":[\"%s\"]," +
+ " \"hasKeyword\":\"%s\"" +
+ "}}, \"#0\"]]",
+ mailboxId.serialize(),
+ flag));
+ }
+
+ @When("^the user asks for message list with flag \"([^\"]*)\"$")
+ public void getMessageList(String flag) throws Exception {
+ post(String.format(
+ "[[\"getMessageList\", {\"filter\":{" +
+ " \"hasKeyword\":\"%s\"" +
+ "}}, \"#0\"]]",
+ flag));
+ }
+
+ @Then("^the message list is empty$")
+ public void assertEmpty() throws Exception {
+ assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
+ assertThat(jsonPath.<List<String>>read(ARGUMENTS + ".messageIds")).isEmpty();
+ }
+
+ @Then("^the message list has size (\\d+)")
+ public void assertSize(int size) throws Exception {
+ assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
+ assertThat(jsonPath.<List<String>>read(ARGUMENTS + ".messageIds")).hasSize(size);
+ }
+
+ @Then("^the message list contains \"([^\"]*)\"")
+ public void assertContains(String messsage) throws Exception {
+ MessageId messageId = messagesMethodStepdefs.getMessageId(messsage);
+ assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
+ assertThat(jsonPath.<List<String>>read(ARGUMENTS + ".messageIds")).contains(messageId.serialize());
+ }
+
+ private void post(String requestBody) throws Exception {
+ response = Request.Post(mainStepdefs.baseUri().setPath("/jmap").build())
+ .addHeader("Authorization", userStepdefs.tokenByUser.get(userStepdefs.lastConnectedUser).serialize())
+ .addHeader("Accept", org.apache.http.entity.ContentType.APPLICATION_JSON.getMimeType())
+ .bodyString(requestBody, org.apache.http.entity.ContentType.APPLICATION_JSON)
+ .execute()
+ .returnResponse();
+ jsonPath = JsonPath.using(Configuration.defaultConfiguration()
+ .addOptions(Option.SUPPRESS_EXCEPTIONS))
+ .parse(response.getEntity().getContent());
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6ff67ca3/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 b477c2c..3c4d28f 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
@@ -108,6 +108,7 @@ public class GetMessagesMethodStepdefs {
mainStepdefs.jmapServer.getProbe(JmapGuiceProbe.class).setInMailboxes(id, userStepdefs.lastConnectedUser, mailboxId1, mailboxId2);
messageIdsByName.put(messageName, id);
+ mainStepdefs.awaitMethod.run();
}
@Given("^the user has a message \"([^\"]*)\" in \"([^\"]*)\" mailbox with subject \"([^\"]*)\", content \"([^\"]*)\"$")
@@ -143,14 +144,19 @@ public class GetMessagesMethodStepdefs {
Date.from(dateTime.toInstant()), false, new Flags())
.getMessageId();
messageIdsByName.put(messageName, id);
+ mainStepdefs.awaitMethod.run();
}
private MessageId appendMessage(String mailbox, ContentType contentType, String subject, String content, Optional<Map<String, String>> headers) throws Exception {
ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z");
- return mainStepdefs.mailboxProbe.appendMessage(userStepdefs.lastConnectedUser,
+ try {
+ return mainStepdefs.mailboxProbe.appendMessage(userStepdefs.lastConnectedUser,
MailboxPath.forUser(userStepdefs.lastConnectedUser, mailbox),
new ByteArrayInputStream(message(contentType, subject, content, headers).getBytes(Charsets.UTF_8)),
Date.from(dateTime.toInstant()), false, new Flags()).getMessageId();
+ } finally {
+ mainStepdefs.awaitMethod.run();
+ }
}
private String message(ContentType contentType, String subject, String content, Optional<Map<String,String>> headers) {
http://git-wip-us.apache.org/repos/asf/james-project/blob/6ff67ca3/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/ImapStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/ImapStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/ImapStepdefs.java
index 3eb3b0c..4f0f5f6 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/ImapStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/ImapStepdefs.java
@@ -41,11 +41,13 @@ public class ImapStepdefs {
private static final String LOCALHOST = "127.0.0.1";
private final UserStepdefs userStepdefs;
+ private final MainStepdefs mainStepdefs;
private final Map<String, IMAPMessageReader> imapConnections;
@Inject
- private ImapStepdefs(UserStepdefs userStepdefs) {
+ private ImapStepdefs(UserStepdefs userStepdefs, MainStepdefs mainStepdefs) {
this.userStepdefs = userStepdefs;
+ this.mainStepdefs = mainStepdefs;
this.imapConnections = Maps.newHashMap();
}
@@ -93,6 +95,13 @@ public class ImapStepdefs {
imapConnections.put(mailbox, imapMessageReader);
}
+ @Then("^the user set flags via IMAP to \"([^\"]*)\" for all messages in mailbox \"([^\"]*)\"$")
+ public void setFlagsViaIMAPInMailbox(String flags, String mailbox) throws Throwable {
+ IMAPMessageReader imapMessageReader = imapConnections.get(mailbox);
+ imapMessageReader.setFlagsForAllMessagesInMailbox(flags);
+ mainStepdefs.awaitMethod.run();
+ }
+
@Then("^the user has a IMAP RECENT and a notification about (\\d+) new messages on connection for mailbox \"([^\"]*)\"$")
public void checkNotificationForNewMessageOnActiveConnection(int numberOfMessages, String mailbox) throws Throwable {
IMAPMessageReader imapMessageReader = imapConnections.get(mailbox);
@@ -110,6 +119,7 @@ public class ImapStepdefs {
imapMessageReader.connectAndSelect(login, password, srcMailbox);
assertThat(imapMessageReader).isNotNull();
imapMessageReader.copyFirstMessage(destMailbox);
+ mainStepdefs.awaitMethod.run();
}
@Then("^the user has IMAP EXPUNGE and a notification for (\\d+) message sequence number on connection for mailbox \"([^\"]*)\"$")
http://git-wip-us.apache.org/repos/asf/james-project/blob/6ff67ca3/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMessagesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMessagesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMessagesMethodStepdefs.java
index 3d9f7bb..364c39e 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMessagesMethodStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMessagesMethodStepdefs.java
@@ -19,8 +19,12 @@
package org.apache.james.jmap.methods.integration.cucumber;
+import java.util.List;
+import java.util.stream.Collectors;
+
import javax.inject.Inject;
+import org.apache.http.entity.ContentType;
import org.apache.http.client.fluent.Request;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailbox.model.MailboxId;
@@ -66,9 +70,10 @@ public class SetMessagesMethodStepdefs {
"]";
Request.Post(mainStepdefs.baseUri().setPath("/jmap").build())
.addHeader("Authorization", userStepdefs.tokenByUser.get(username).serialize())
- .bodyString(requestBody, org.apache.http.entity.ContentType.APPLICATION_JSON)
+ .bodyString(requestBody, ContentType.APPLICATION_JSON)
.execute()
.discardContent();
+ mainStepdefs.awaitMethod.run();
}
@When("^the user copy \"([^\"]*)\" from mailbox \"([^\"]*)\" to mailbox \"([^\"]*)\"")
@@ -97,8 +102,37 @@ public class SetMessagesMethodStepdefs {
"]";
Request.Post(mainStepdefs.baseUri().setPath("/jmap").build())
.addHeader("Authorization", userStepdefs.tokenByUser.get(username).serialize())
- .bodyString(requestBody, org.apache.http.entity.ContentType.APPLICATION_JSON)
+ .bodyString(requestBody, ContentType.APPLICATION_JSON)
+ .execute()
+ .discardContent();
+ mainStepdefs.awaitMethod.run();
+ }
+
+ @When("^the user set flags on \"([^\"]*)\" to \"([^\"]*)\"")
+ public void setFlags(String message, List<String> keywords) throws Throwable {
+ String username = userStepdefs.lastConnectedUser;
+ MessageId messageId = getMessagesMethodStepdefs.getMessageId(message);
+ String keywordString = keywords
+ .stream()
+ .map(value -> "\"" + value + "\" : true")
+ .collect(Collectors.joining(","));
+
+ Request.Post(mainStepdefs.baseUri().setPath("/jmap").build())
+ .addHeader("Authorization", userStepdefs.tokenByUser.get(username).serialize())
+ .bodyString("[" +
+ " [" +
+ " \"setMessages\","+
+ " {" +
+ " \"update\": { \"" + messageId.serialize() + "\" : {" +
+ " \"keywords\": {" + keywordString + "}" +
+ " }}" +
+ " }," +
+ " \"#0\"" +
+ " ]" +
+ "]",
+ ContentType.APPLICATION_JSON)
.execute()
.discardContent();
+ mainStepdefs.awaitMethod.run();
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6ff67ca3/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/ImapKeywordsConsistency.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/ImapKeywordsConsistency.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/ImapKeywordsConsistency.feature
index 5a4ec8d..4650033 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/ImapKeywordsConsistency.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/ImapKeywordsConsistency.feature
@@ -84,7 +84,7 @@ Feature: Impact of IMAP on JMAP keywords consistency
When the user asks for message list in mailbox "source" with flag "$Flagged"
Then the message list is empty
- Scenario: SetMessages should succeed to solve Keywords conflict introduced via IMAP upon flags addition
+ Scenario: SetMessages should succeed to solve Keywords conflict introduced via IMAP upon flags addition (GetMessageList)
Given the user has a message "m1" in "source" mailbox with subject "My awesome subject", content "This is the content"
And the user copy "m1" from mailbox "source" to mailbox "mailbox"
And the user has an open IMAP connection with mailbox "mailbox" selected
@@ -97,7 +97,19 @@ Feature: Impact of IMAP on JMAP keywords consistency
And the message list has size 1
And the message list contains "m1"
- Scenario: SetMessages should ignore Keywords conflict introduced via IMAP upon flags deletion
+ Scenario: SetMessages should succeed to solve Keywords conflict introduced via IMAP upon flags addition with GetMessages
+ Given the user has a message "m1" in "source" mailbox with subject "My awesome subject", content "This is the content"
+ And the user copy "m1" from mailbox "source" to mailbox "mailbox"
+ And the user has an open IMAP connection with mailbox "mailbox" selected
+ And the user set flags via IMAP to "(\Flagged)" for all messages in mailbox "mailbox"
+ When the user set flags on "m1" to "$Flagged"
+ Then the user ask for messages "m1"
+ And no error is returned
+ And the list should contain 1 message
+ And the id of the message is "m1"
+ And the keywords of the message is $Flagged
+
+ Scenario: SetMessages should ignore Keywords conflict introduced via IMAP upon flags deletion with GetMessageList
Given the user has a message "m1" in "source" mailbox with subject "My awesome subject", content "This is the content"
And the user copy "m1" from mailbox "source" to mailbox "mailbox"
And the user has an open IMAP connection with mailbox "mailbox" selected
@@ -106,4 +118,22 @@ Feature: Impact of IMAP on JMAP keywords consistency
Then the user asks for message list in mailbox "mailbox" with flag "$Flagged"
And the message list is empty
And the user asks for message list in mailbox "source" with flag "$Flagged"
- And the message list is empty
\ No newline at end of file
+ And the message list is empty
+ Then the user asks for message list in mailbox "mailbox" with flag "$Answered"
+ And the message list has size 1
+ And the message list contains "m1"
+ And the user asks for message list in mailbox "source" with flag "$Answered"
+ And the message list has size 1
+ And the message list contains "m1"
+
+ Scenario: SetMessages should ignore Keywords conflict introduced via IMAP upon flags deletion with GetMessages
+ Given the user has a message "m1" in "source" mailbox with subject "My awesome subject", content "This is the content"
+ And the user copy "m1" from mailbox "source" to mailbox "mailbox"
+ And the user has an open IMAP connection with mailbox "mailbox" selected
+ And the user set flags via IMAP to "(\Flagged)" for all messages in mailbox "mailbox"
+ When the user set flags on "m1" to "$Answered"
+ Then the user ask for messages "m1"
+ And no error is returned
+ And the list should contain 1 message
+ And the id of the message is "m1"
+ And the keywords of the message is $Answered
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/6ff67ca3/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryIMAPKeywordsInconsistenciesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryIMAPKeywordsInconsistenciesTest.java b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryIMAPKeywordsInconsistenciesTest.java
new file mode 100644
index 0000000..30bbe9e
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryIMAPKeywordsInconsistenciesTest.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/ImapKeywordsConsistency.feature",
+ glue={"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.memory.cucumber"},
+ strict = true)
+public class MemoryIMAPKeywordsInconsistenciesTest {
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6ff67ca3/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java
----------------------------------------------------------------------
diff --git a/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java b/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java
index 8fb5d68..e2edb6f 100644
--- a/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java
+++ b/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java
@@ -95,6 +95,11 @@ public class IMAPMessageReader implements Closeable {
return readFirstMessageInMailbox(user, password, "(RFC822.HEADER)", INBOX);
}
+ public String setFlagsForAllMessagesInMailbox(String flag) throws IOException {
+ imapClient.store("1:*", "+FLAGS", flag);
+ return imapClient.getReplyString();
+ }
+
private String readFirstMessageInMailbox(String user, String password, String parameters, String mailboxName) throws IOException {
imapClient.login(user, password);
imapClient.select(mailboxName);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[12/12] james-project git commit: JAMES-2184 Show LIST do not return
shared mailboxes
Posted by bt...@apache.org.
JAMES-2184 Show LIST do not return shared mailboxes
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/6c6efcd1
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/6c6efcd1
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/6c6efcd1
Branch: refs/heads/master
Commit: 6c6efcd12b806ac448fa499af96728dbbc590242
Parents: 65d3ac3
Author: quynhn <qn...@linagora.com>
Authored: Wed Oct 11 16:17:37 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Oct 18 09:02:26 2017 +0700
----------------------------------------------------------------------
.../mpt/script/ImapScriptedTestProtocol.java | 30 +++++++--
.../CassandraListingWithSharingTest.java | 55 +++++++++++++++++
.../suite/ListingWithSharingTest.java | 64 ++++++++++++++++++++
.../imap/scripts/ListWithSharedMailbox.test | 32 ++++++++++
.../InMemoryListingWithSharingTest.java | 52 ++++++++++++++++
5 files changed, 229 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c6efcd1/mpt/core/src/main/java/org/apache/james/mpt/script/ImapScriptedTestProtocol.java
----------------------------------------------------------------------
diff --git a/mpt/core/src/main/java/org/apache/james/mpt/script/ImapScriptedTestProtocol.java b/mpt/core/src/main/java/org/apache/james/mpt/script/ImapScriptedTestProtocol.java
index cc11c0e..cc32d1b 100644
--- a/mpt/core/src/main/java/org/apache/james/mpt/script/ImapScriptedTestProtocol.java
+++ b/mpt/core/src/main/java/org/apache/james/mpt/script/ImapScriptedTestProtocol.java
@@ -19,12 +19,12 @@
package org.apache.james.mpt.script;
+import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mpt.api.ImapHostSystem;
public class ImapScriptedTestProtocol extends GenericSimpleScriptedTestProtocol<ImapHostSystem, ImapScriptedTestProtocol> {
-
private static class CreateMailbox implements PrepareCommand<ImapHostSystem> {
final MailboxPath mailboxPath;
@@ -32,18 +32,40 @@ public class ImapScriptedTestProtocol extends GenericSimpleScriptedTestProtocol<
CreateMailbox(MailboxPath mailboxPath) {
this.mailboxPath = mailboxPath;
}
-
+
+ @Override
public void prepare(ImapHostSystem system) throws Exception {
system.createMailbox(mailboxPath);
}
}
-
+
+ private static class CreateRights implements PrepareCommand<ImapHostSystem> {
+
+ final MailboxPath mailboxPath;
+ final String userName;
+ final MailboxACL.Rfc4314Rights rights;
+
+ public CreateRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) {
+ this.mailboxPath = mailboxPath;
+ this.userName = userName;
+ this.rights = rights;
+ }
+
+ public void prepare(ImapHostSystem system) throws Exception {
+ system.grantRights(mailboxPath, userName, rights);
+ }
+ }
+
+
public ImapScriptedTestProtocol(String scriptDirectory, ImapHostSystem hostSystem) throws Exception {
super(scriptDirectory, hostSystem);
}
-
+
public ImapScriptedTestProtocol withMailbox(MailboxPath mailboxPath) {
return withPreparedCommand(new CreateMailbox(mailboxPath));
}
+ public ImapScriptedTestProtocol withRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) {
+ return withPreparedCommand(new CreateRights(mailboxPath, userName, rights));
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c6efcd1/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraListingWithSharingTest.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraListingWithSharingTest.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraListingWithSharingTest.java
new file mode 100644
index 0000000..6d7fb6d
--- /dev/null
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraListingWithSharingTest.java
@@ -0,0 +1,55 @@
+/****************************************************************
+ * 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.mpt.imapmailbox.cassandra;
+
+import org.apache.james.backends.cassandra.DockerCassandraRule;
+import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.suite.ListingWithSharingTest;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+public class CassandraListingWithSharingTest extends ListingWithSharingTest {
+ @ClassRule
+ public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+
+ private ImapHostSystem system;
+
+ @Before
+ public void setUp() throws Exception {
+ Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
+ system = injector.getInstance(ImapHostSystem.class);
+ system.beforeTest();
+ super.setUp();
+ }
+
+ @Override
+ protected ImapHostSystem createImapHostSystem() {
+ return system;
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ system.afterTest();
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c6efcd1/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/ListingWithSharingTest.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/ListingWithSharingTest.java b/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/ListingWithSharingTest.java
new file mode 100644
index 0000000..64028dd
--- /dev/null
+++ b/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/ListingWithSharingTest.java
@@ -0,0 +1,64 @@
+/****************************************************************
+ * 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.mpt.imapmailbox.suite;
+
+import java.util.Locale;
+
+import org.apache.james.mailbox.model.MailboxACL;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.ImapTestConstants;
+import org.apache.james.mpt.imapmailbox.suite.base.BasicImapCommands;
+import org.apache.james.mpt.script.ImapScriptedTestProtocol;
+import org.junit.Before;
+import org.junit.Test;
+
+public abstract class ListingWithSharingTest implements ImapTestConstants {
+ public static final String OTHER_USER_NAME = "Boby";
+ public static final String OTHER_USER_PASSWORD = "password";
+ public static final MailboxPath OTHER_USER_SHARED_MAILBOX = MailboxPath.forUser( OTHER_USER_NAME, "sharedMailbox");
+ public static final MailboxPath OTHER_USER_SHARED_MAILBOX_CHILD = MailboxPath.forUser( OTHER_USER_NAME, "sharedMailbox.child");
+
+ protected abstract ImapHostSystem createImapHostSystem();
+
+ private ImapHostSystem system;
+ private ImapScriptedTestProtocol scriptedTestProtocol;
+
+ @Before
+ public void setUp() throws Exception {
+ system = createImapHostSystem();
+ scriptedTestProtocol = new ImapScriptedTestProtocol("/org/apache/james/imap/scripts/", system)
+ .withUser(USER, PASSWORD)
+ .withUser(OTHER_USER_NAME, OTHER_USER_PASSWORD);
+ BasicImapCommands.welcome(scriptedTestProtocol);
+ BasicImapCommands.authenticate(scriptedTestProtocol);
+ }
+
+ @Test
+ public void testListWithSharedMailboxUS() throws Exception {
+ scriptedTestProtocol
+ .withMailbox(OTHER_USER_SHARED_MAILBOX)
+ .withMailbox(OTHER_USER_SHARED_MAILBOX_CHILD)
+ .withRights(OTHER_USER_SHARED_MAILBOX, USER, MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights("r"))
+ .withRights(OTHER_USER_SHARED_MAILBOX_CHILD, USER, MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights("r"))
+ .withLocale(Locale.US)
+ .run("ListWithSharedMailbox");
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c6efcd1/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/ListWithSharedMailbox.test
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/ListWithSharedMailbox.test b/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/ListWithSharedMailbox.test
new file mode 100644
index 0000000..2d01957
--- /dev/null
+++ b/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/ListWithSharedMailbox.test
@@ -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. #
+################################################################
+
+# Shouw that #private.Boby.sharedMailbox and it's child are not displayed
+
+C: a0 LIST "" "*"
+S: \* LIST \(\\HasNoChildren\) \"\.\" \"INBOX\"
+S: a0 OK LIST completed.
+
+C: a1 LIST "#private" "%"
+S: \* LIST \(\\HasNoChildren\) \"\.\" \"#private.imapuser.INBOX\"
+S: a1 OK LIST completed.
+
+C: a3 LIST "#private" sharedMailbox*
+S: a3 OK LIST completed.
+
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c6efcd1/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/InMemoryListingWithSharingTest.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/InMemoryListingWithSharingTest.java b/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/InMemoryListingWithSharingTest.java
new file mode 100644
index 0000000..b5a54ee
--- /dev/null
+++ b/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/InMemoryListingWithSharingTest.java
@@ -0,0 +1,52 @@
+/****************************************************************
+ * 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.mpt.imapmailbox.inmemory;
+
+import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.suite.ListingWithSharingTest;
+import org.junit.After;
+import org.junit.Before;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+public class InMemoryListingWithSharingTest extends ListingWithSharingTest {
+
+ private ImapHostSystem system;
+
+ @Before
+ public void setUp() throws Exception {
+ Injector injector = Guice.createInjector(new InMemoryMailboxTestModule());
+ system = injector.getInstance(ImapHostSystem.class);
+ system.beforeTest();
+ super.setUp();
+ }
+
+ @Override
+ protected ImapHostSystem createImapHostSystem() {
+ return system;
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ system.afterTest();
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[06/12] james-project git commit: JAMES-2183 Adding KeywordsCombiner
Posted by bt...@apache.org.
JAMES-2183 Adding KeywordsCombiner
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f0b27714
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f0b27714
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f0b27714
Branch: refs/heads/master
Commit: f0b277144369e938fdd11eebc705e7f02c96ed9c
Parents: d1238fc
Author: benwa <bt...@linagora.com>
Authored: Thu Oct 12 10:04:33 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Oct 18 09:00:56 2017 +0700
----------------------------------------------------------------------
.../org/apache/james/jmap/model/Keywords.java | 6 +
.../james/jmap/utils/KeywordsCombiner.java | 65 +++++++++
.../james/jmap/utils/KeywordsCombinerTest.java | 132 +++++++++++++++++++
3 files changed, 203 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/f0b27714/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Keywords.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Keywords.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Keywords.java
index ed07982..c410cf9 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Keywords.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Keywords.java
@@ -19,6 +19,7 @@
package org.apache.james.jmap.model;
+import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -86,6 +87,11 @@ public class Keywords {
.collect(Guavate.toImmutableSet()));
}
+ public Keywords from(Keyword... keywords) {
+ return fromSet(Arrays.stream(keywords)
+ .collect(Guavate.toImmutableSet()));
+ }
+
public Keywords fromList(List<String> keywords) {
return fromSet(keywords.stream()
.map(Keyword::new)
http://git-wip-us.apache.org/repos/asf/james-project/blob/f0b27714/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/KeywordsCombiner.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/KeywordsCombiner.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/KeywordsCombiner.java
new file mode 100644
index 0000000..258f5df
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/KeywordsCombiner.java
@@ -0,0 +1,65 @@
+/****************************************************************
+ * 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.utils;
+
+import java.util.List;
+import java.util.Set;
+import java.util.function.BinaryOperator;
+
+import org.apache.james.jmap.model.Keyword;
+import org.apache.james.jmap.model.Keywords;
+
+import com.github.steveash.guavate.Guavate;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Sets;
+
+public class KeywordsCombiner implements BinaryOperator<Keywords> {
+ private static final ImmutableList<Keyword> KEYWORD_TO_INTERSECT = ImmutableList.of(Keyword.DRAFT);
+ private static final ImmutableList<Keyword> KEYWORD_NOT_TO_UNION = KEYWORD_TO_INTERSECT;
+
+ private Keywords.KeywordsFactory keywordsFactory;
+
+ public KeywordsCombiner() {
+ this.keywordsFactory = Keywords.factory()
+ .filterImapNonExposedKeywords();
+ }
+
+ @Override
+ public Keywords apply(Keywords keywords, Keywords keywords2) {
+ return keywordsFactory
+ .fromSet(Sets.union(
+ union(keywords.getKeywords(), keywords2.getKeywords(), KEYWORD_NOT_TO_UNION),
+ intersect(keywords.getKeywords(), keywords2.getKeywords(), KEYWORD_TO_INTERSECT)));
+ }
+
+ public Set<Keyword> union(Set<Keyword> set1, Set<Keyword> set2, List<Keyword> exceptKeywords) {
+ return Sets.union(set1, set2)
+ .stream()
+ .filter(keyword -> !exceptKeywords.contains(keyword))
+ .collect(Guavate.toImmutableSet());
+ }
+
+ public Set<Keyword> intersect(Set<Keyword> set1, Set<Keyword> set2, List<Keyword> forKeywords) {
+ return Sets.intersection(set1, set2)
+ .stream()
+ .filter(forKeywords::contains)
+ .collect(Guavate.toImmutableSet());
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f0b27714/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/KeywordsCombinerTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/KeywordsCombinerTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/KeywordsCombinerTest.java
new file mode 100644
index 0000000..df36ab4
--- /dev/null
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/KeywordsCombinerTest.java
@@ -0,0 +1,132 @@
+/****************************************************************
+ * 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.utils;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.jmap.model.Keyword;
+import org.apache.james.jmap.model.Keywords;
+import org.apache.james.util.CommutativityChecker;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+public class KeywordsCombinerTest {
+
+ public static final Keywords.KeywordsFactory FACTORY = Keywords.factory();
+
+ @Test
+ public void applyShouldUnionSeenKeyword() {
+ KeywordsCombiner keywordsCombiner = new KeywordsCombiner();
+
+ assertThat(keywordsCombiner.apply(
+ Keywords.DEFAULT_VALUE,
+ Keywords.factory().from(Keyword.SEEN)))
+ .isEqualTo(Keywords.factory().from(Keyword.SEEN));
+ }
+
+ @Test
+ public void applyShouldUnionAnsweredKeyword() {
+ KeywordsCombiner keywordsCombiner = new KeywordsCombiner();
+
+ assertThat(keywordsCombiner.apply(
+ Keywords.DEFAULT_VALUE,
+ Keywords.factory().from(Keyword.ANSWERED)))
+ .isEqualTo(Keywords.factory().from(Keyword.ANSWERED));
+ }
+
+ @Test
+ public void applyShouldUnionFlaggedKeyword() {
+ KeywordsCombiner keywordsCombiner = new KeywordsCombiner();
+
+ assertThat(keywordsCombiner.apply(
+ Keywords.DEFAULT_VALUE,
+ Keywords.factory().from(Keyword.FLAGGED)))
+ .isEqualTo(Keywords.factory().from(Keyword.FLAGGED));
+ }
+
+ @Test
+ public void applyShouldIntersectDraftKeyword() {
+ KeywordsCombiner keywordsCombiner = new KeywordsCombiner();
+
+ assertThat(keywordsCombiner.apply(
+ Keywords.DEFAULT_VALUE,
+ Keywords.factory().from(Keyword.DRAFT)))
+ .isEqualTo(Keywords.DEFAULT_VALUE);
+ }
+
+ @Test
+ public void applyShouldUnionCustomKeyword() {
+ KeywordsCombiner keywordsCombiner = new KeywordsCombiner();
+
+ Keyword customKeyword = new Keyword("$Any");
+ assertThat(keywordsCombiner.apply(
+ Keywords.DEFAULT_VALUE,
+ Keywords.factory().from(customKeyword)))
+ .isEqualTo(Keywords.factory().from(customKeyword));
+ }
+
+ @Test
+ public void applyShouldAcceptEmptyAsAZeroValue() {
+ KeywordsCombiner keywordsCombiner = new KeywordsCombiner();
+
+ assertThat(keywordsCombiner.apply(
+ Keywords.DEFAULT_VALUE,
+ Keywords.DEFAULT_VALUE))
+ .isEqualTo(Keywords.DEFAULT_VALUE);
+ }
+
+ @Test
+ public void applyShouldUnionDifferentFlags() {
+ KeywordsCombiner keywordsCombiner = new KeywordsCombiner();
+
+ assertThat(keywordsCombiner.apply(
+ Keywords.factory().from(Keyword.FLAGGED),
+ Keywords.factory().from(Keyword.ANSWERED)))
+ .isEqualTo(Keywords.factory().from(Keyword.FLAGGED, Keyword.ANSWERED));
+ }
+
+ @Test
+ public void keywordsCombinerShouldBeCommutative() {
+ Keywords allKeyword = FACTORY.from(Keyword.ANSWERED,
+ Keyword.DELETED,
+ Keyword.DRAFT,
+ Keyword.FLAGGED,
+ Keyword.SEEN,
+ new Keyword("$Forwarded"),
+ new Keyword("$Any"));
+
+ ImmutableSet<Keywords> values = ImmutableSet.of(
+ FACTORY.from(Keyword.ANSWERED),
+ FACTORY.from(Keyword.DELETED),
+ FACTORY.from(Keyword.DRAFT),
+ FACTORY.from(Keyword.FLAGGED),
+ FACTORY.from(Keyword.SEEN),
+ FACTORY.from(),
+ FACTORY.from(new Keyword("$Forwarded")),
+ FACTORY.from(new Keyword("$Any")),
+ allKeyword);
+
+ assertThat(
+ new CommutativityChecker<>(values, new KeywordsCombiner())
+ .findNonCommutativeInput())
+ .isEmpty();
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[11/12] james-project git commit: JAMES-2184 Simplify JamesHostSystem
hierarchy
Posted by bt...@apache.org.
JAMES-2184 Simplify JamesHostSystem hierarchy
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/65d3ac3a
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/65d3ac3a
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/65d3ac3a
Branch: refs/heads/master
Commit: 65d3ac3a97ad465243c1165330aaa6d6029e34b8
Parents: 10cd0d9
Author: benwa <bt...@linagora.com>
Authored: Fri Oct 13 17:26:31 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Oct 18 09:02:16 2017 +0700
----------------------------------------------------------------------
.../cassandra/host/CassandraHostSystem.java | 18 ++-------
.../james/mpt/host/JamesImapHostSystem.java | 27 ++++++++++++-
.../imapmailbox/MailboxCreationDelegate.java | 42 --------------------
.../host/ElasticSearchHostSystem.java | 18 ++-------
.../imapmailbox/hbase/host/HBaseHostSystem.java | 20 ++--------
.../inmemory/host/InMemoryHostSystem.java | 20 ++--------
.../mpt/imapmailbox/jcr/host/JCRHostSystem.java | 19 ++-------
.../mpt/imapmailbox/jpa/host/JPAHostSystem.java | 19 ++-------
.../host/LuceneSearchHostSystem.java | 17 ++------
.../maildir/host/MaildirHostSystem.java | 17 ++------
10 files changed, 53 insertions(+), 164 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/65d3ac3a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
index 0aaffcb..465a2f2 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
@@ -24,6 +24,7 @@ import org.apache.james.backends.cassandra.init.CassandraModuleComposite;
import org.apache.james.imap.encode.main.DefaultImapEncoderFactory;
import org.apache.james.imap.main.DefaultImapDecoderFactory;
import org.apache.james.imap.processor.main.DefaultImapProcessorFactory;
+import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.SubscriptionManager;
import org.apache.james.mailbox.cassandra.CassandraMailboxManager;
import org.apache.james.mailbox.cassandra.CassandraMailboxSessionMapperFactory;
@@ -47,8 +48,6 @@ import org.apache.james.mailbox.cassandra.modules.CassandraUidModule;
import org.apache.james.mailbox.cassandra.quota.CassandraCurrentQuotaManager;
import org.apache.james.mailbox.cassandra.quota.CassandraPerUserMaxQuotaManager;
import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.MailboxACL;
-import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.quota.QuotaRootResolver;
import org.apache.james.mailbox.store.JVMMailboxPathLocker;
import org.apache.james.mailbox.store.StoreSubscriptionManager;
@@ -60,7 +59,6 @@ import org.apache.james.metrics.logger.DefaultMetricFactory;
import org.apache.james.mpt.api.ImapFeatures;
import org.apache.james.mpt.api.ImapFeatures.Feature;
import org.apache.james.mpt.host.JamesImapHostSystem;
-import org.apache.james.mpt.imapmailbox.MailboxCreationDelegate;
public class CassandraHostSystem extends JamesImapHostSystem {
@@ -143,11 +141,6 @@ public class CassandraHostSystem extends JamesImapHostSystem {
protected void finalize() throws Throwable {
super.finalize();
}
-
- @Override
- public void createMailbox(MailboxPath mailboxPath) throws Exception{
- new MailboxCreationDelegate(mailboxManager).createMailbox(mailboxPath);
- }
@Override
public boolean supports(Feature... features) {
@@ -161,12 +154,7 @@ public class CassandraHostSystem extends JamesImapHostSystem {
}
@Override
- public void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception {
- mailboxManager.setRights(mailboxPath,
- MailboxACL.EMPTY.apply(MailboxACL.command()
- .forUser(userName)
- .rights(rights)
- .asAddition()),
- mailboxManager.createSystemSession(userName));
+ protected MailboxManager getMailboxManager() {
+ return mailboxManager;
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/65d3ac3a/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/host/JamesImapHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/host/JamesImapHostSystem.java b/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/host/JamesImapHostSystem.java
index bb8abdb..662002a 100644
--- a/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/host/JamesImapHostSystem.java
+++ b/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/host/JamesImapHostSystem.java
@@ -29,6 +29,8 @@ import org.apache.james.imap.api.process.ImapProcessor;
import org.apache.james.imap.decode.ImapDecoder;
import org.apache.james.imap.decode.main.ImapRequestStreamHandler;
import org.apache.james.imap.encode.ImapEncoder;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.store.Authenticator;
@@ -88,10 +90,31 @@ public abstract class JamesImapHostSystem implements ImapHostSystem, GrantRights
throws Exception {
return new Session(continuation);
}
+
+ protected abstract MailboxManager getMailboxManager();
- public abstract void createMailbox(MailboxPath mailboxPath) throws Exception;
+ public void createMailbox(MailboxPath mailboxPath) throws Exception {
+ MailboxManager mailboxManager = getMailboxManager();
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(mailboxPath.getUser());
+ mailboxManager.startProcessingRequest(mailboxSession);
+ mailboxManager.createMailbox(mailboxPath, mailboxSession);
+ mailboxManager.logout(mailboxSession, true);
+ mailboxManager.endProcessingRequest(mailboxSession);
+ }
- public abstract void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception;
+ public void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception {
+ MailboxManager mailboxManager = getMailboxManager();
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(mailboxPath.getUser());
+ mailboxManager.startProcessingRequest(mailboxSession);
+ mailboxManager.setRights(mailboxPath,
+ MailboxACL.EMPTY.apply(MailboxACL.command()
+ .forUser(userName)
+ .rights(rights)
+ .asAddition()),
+ mailboxManager.createSystemSession(userName));
+ mailboxManager.logout(mailboxSession, true);
+ mailboxManager.endProcessingRequest(mailboxSession);
+ }
class Session implements org.apache.james.mpt.api.Session {
ByteBufferOutputStream out;
http://git-wip-us.apache.org/repos/asf/james-project/blob/65d3ac3a/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/MailboxCreationDelegate.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/MailboxCreationDelegate.java b/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/MailboxCreationDelegate.java
deleted file mode 100644
index 75fdf4e..0000000
--- a/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/MailboxCreationDelegate.java
+++ /dev/null
@@ -1,42 +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.mpt.imapmailbox;
-
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.model.MailboxPath;
-
-public class MailboxCreationDelegate {
-
- private final MailboxManager mailboxManager;
-
- public MailboxCreationDelegate(MailboxManager mailboxManager) {
- this.mailboxManager = mailboxManager;
- }
-
- public void createMailbox(MailboxPath mailboxPath) throws Exception{
- MailboxSession mailboxSession = mailboxManager.createSystemSession("system");
- mailboxManager.startProcessingRequest(mailboxSession);
- mailboxManager.createMailbox(mailboxPath, mailboxSession);
- mailboxManager.logout(mailboxSession, true);
- mailboxManager.endProcessingRequest(mailboxSession);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/65d3ac3a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
index 3ae5818..dcdd8f4 100644
--- a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
@@ -36,6 +36,7 @@ import org.apache.james.imap.api.process.ImapProcessor;
import org.apache.james.imap.encode.main.DefaultImapEncoderFactory;
import org.apache.james.imap.main.DefaultImapDecoderFactory;
import org.apache.james.imap.processor.main.DefaultImapProcessorFactory;
+import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.acl.GroupMembershipResolver;
import org.apache.james.mailbox.acl.MailboxACLResolver;
import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
@@ -52,9 +53,7 @@ import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.inmemory.InMemoryId;
import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
import org.apache.james.mailbox.inmemory.InMemoryMessageId;
-import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxConstants;
-import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.store.StoreMailboxManager;
import org.apache.james.mailbox.store.StoreSubscriptionManager;
import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
@@ -65,7 +64,6 @@ import org.apache.james.metrics.logger.DefaultMetricFactory;
import org.apache.james.mpt.api.ImapFeatures;
import org.apache.james.mpt.api.ImapFeatures.Feature;
import org.apache.james.mpt.host.JamesImapHostSystem;
-import org.apache.james.mpt.imapmailbox.MailboxCreationDelegate;
import org.elasticsearch.client.Client;
import com.google.common.base.Throwables;
@@ -139,8 +137,8 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
}
@Override
- public void createMailbox(MailboxPath mailboxPath) throws Exception{
- new MailboxCreationDelegate(mailboxManager).createMailbox(mailboxPath);
+ protected MailboxManager getMailboxManager() {
+ return mailboxManager;
}
@Override
@@ -152,14 +150,4 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
public void setQuotaLimits(long maxMessageQuota, long maxStorageQuota) throws Exception {
throw new NotImplementedException();
}
-
- @Override
- public void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception {
- mailboxManager.setRights(mailboxPath,
- MailboxACL.EMPTY.apply(MailboxACL.command()
- .forUser(userName)
- .rights(rights)
- .asAddition()),
- mailboxManager.createSystemSession(userName));
- }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/65d3ac3a/mpt/impl/imap-mailbox/hbase/src/test/java/org/apache/james/mpt/imapmailbox/hbase/host/HBaseHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/hbase/src/test/java/org/apache/james/mpt/imapmailbox/hbase/host/HBaseHostSystem.java b/mpt/impl/imap-mailbox/hbase/src/test/java/org/apache/james/mpt/imapmailbox/hbase/host/HBaseHostSystem.java
index fae8500..bd26353 100644
--- a/mpt/impl/imap-mailbox/hbase/src/test/java/org/apache/james/mpt/imapmailbox/hbase/host/HBaseHostSystem.java
+++ b/mpt/impl/imap-mailbox/hbase/src/test/java/org/apache/james/mpt/imapmailbox/hbase/host/HBaseHostSystem.java
@@ -30,6 +30,7 @@ import org.apache.james.imap.api.process.ImapProcessor;
import org.apache.james.imap.encode.main.DefaultImapEncoderFactory;
import org.apache.james.imap.main.DefaultImapDecoderFactory;
import org.apache.james.imap.processor.main.DefaultImapProcessorFactory;
+import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.SubscriptionManager;
import org.apache.james.mailbox.acl.GroupMembershipResolver;
@@ -40,8 +41,6 @@ import org.apache.james.mailbox.hbase.HBaseMailboxManager;
import org.apache.james.mailbox.hbase.HBaseMailboxSessionMapperFactory;
import org.apache.james.mailbox.hbase.mail.HBaseModSeqProvider;
import org.apache.james.mailbox.hbase.mail.HBaseUidProvider;
-import org.apache.james.mailbox.model.MailboxACL;
-import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.store.StoreSubscriptionManager;
import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
@@ -51,7 +50,6 @@ import org.apache.james.metrics.api.NoopMetricFactory;
import org.apache.james.mpt.api.ImapFeatures;
import org.apache.james.mpt.api.ImapFeatures.Feature;
import org.apache.james.mpt.host.JamesImapHostSystem;
-import org.apache.james.mpt.imapmailbox.MailboxCreationDelegate;
public class HBaseHostSystem extends JamesImapHostSystem {
@@ -156,10 +154,10 @@ public class HBaseHostSystem extends JamesImapHostSystem {
}
@Override
- public void createMailbox(MailboxPath mailboxPath) throws Exception{
- new MailboxCreationDelegate(mailboxManager).createMailbox(mailboxPath);
+ protected MailboxManager getMailboxManager() {
+ return mailboxManager;
}
-
+
@Override
public boolean supports(Feature... features) {
return SUPPORTED_FEATURES.supports(features);
@@ -169,14 +167,4 @@ public class HBaseHostSystem extends JamesImapHostSystem {
public void setQuotaLimits(long maxMessageQuota, long maxStorageQuota) throws Exception {
throw new NotImplementedException();
}
-
- @Override
- public void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception {
- mailboxManager.setRights(mailboxPath,
- MailboxACL.EMPTY.apply(MailboxACL.command()
- .forUser(userName)
- .rights(rights)
- .asAddition()),
- mailboxManager.createSystemSession(userName));
- }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/65d3ac3a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java b/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
index 8a07469..4504737 100644
--- a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
+++ b/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
@@ -23,6 +23,7 @@ import org.apache.james.imap.api.process.ImapProcessor;
import org.apache.james.imap.encode.main.DefaultImapEncoderFactory;
import org.apache.james.imap.main.DefaultImapDecoderFactory;
import org.apache.james.imap.processor.main.DefaultImapProcessorFactory;
+import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.acl.GroupMembershipResolver;
import org.apache.james.mailbox.acl.MailboxACLResolver;
import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
@@ -33,8 +34,6 @@ import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
import org.apache.james.mailbox.inmemory.InMemoryMessageId;
import org.apache.james.mailbox.inmemory.quota.InMemoryCurrentQuotaManager;
import org.apache.james.mailbox.inmemory.quota.InMemoryPerUserMaxQuotaManager;
-import org.apache.james.mailbox.model.MailboxACL;
-import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.quota.QuotaRootResolver;
import org.apache.james.mailbox.store.JVMMailboxPathLocker;
import org.apache.james.mailbox.store.StoreSubscriptionManager;
@@ -47,7 +46,6 @@ import org.apache.james.metrics.logger.DefaultMetricFactory;
import org.apache.james.mpt.api.ImapFeatures;
import org.apache.james.mpt.api.ImapFeatures.Feature;
import org.apache.james.mpt.host.JamesImapHostSystem;
-import org.apache.james.mpt.imapmailbox.MailboxCreationDelegate;
public class InMemoryHostSystem extends JamesImapHostSystem {
@@ -99,10 +97,10 @@ public class InMemoryHostSystem extends JamesImapHostSystem {
}
@Override
- public void createMailbox(MailboxPath mailboxPath) throws Exception{
- new MailboxCreationDelegate(mailboxManager).createMailbox(mailboxPath);
+ protected MailboxManager getMailboxManager() {
+ return mailboxManager;
}
-
+
@Override
public boolean supports(Feature... features) {
return SUPPORTED_FEATURES.supports(features);
@@ -113,14 +111,4 @@ public class InMemoryHostSystem extends JamesImapHostSystem {
perUserMaxQuotaManager.setDefaultMaxMessage(maxMessageQuota);
perUserMaxQuotaManager.setDefaultMaxStorage(maxStorageQuota);
}
-
- @Override
- public void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception {
- mailboxManager.setRights(mailboxPath,
- MailboxACL.EMPTY.apply(MailboxACL.command()
- .forUser(userName)
- .rights(rights)
- .asAddition()),
- mailboxManager.createSystemSession(userName));
- }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/65d3ac3a/mpt/impl/imap-mailbox/jcr/src/test/java/org/apache/james/mpt/imapmailbox/jcr/host/JCRHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/jcr/src/test/java/org/apache/james/mpt/imapmailbox/jcr/host/JCRHostSystem.java b/mpt/impl/imap-mailbox/jcr/src/test/java/org/apache/james/mpt/imapmailbox/jcr/host/JCRHostSystem.java
index 8fb9322..cc4629f 100644
--- a/mpt/impl/imap-mailbox/jcr/src/test/java/org/apache/james/mpt/imapmailbox/jcr/host/JCRHostSystem.java
+++ b/mpt/impl/imap-mailbox/jcr/src/test/java/org/apache/james/mpt/imapmailbox/jcr/host/JCRHostSystem.java
@@ -28,6 +28,7 @@ import org.apache.james.imap.api.process.ImapProcessor;
import org.apache.james.imap.encode.main.DefaultImapEncoderFactory;
import org.apache.james.imap.main.DefaultImapDecoderFactory;
import org.apache.james.imap.processor.main.DefaultImapProcessorFactory;
+import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.acl.GroupMembershipResolver;
import org.apache.james.mailbox.acl.MailboxACLResolver;
@@ -40,8 +41,6 @@ import org.apache.james.mailbox.jcr.JCRSubscriptionManager;
import org.apache.james.mailbox.jcr.JCRUtils;
import org.apache.james.mailbox.jcr.mail.JCRModSeqProvider;
import org.apache.james.mailbox.jcr.mail.JCRUidProvider;
-import org.apache.james.mailbox.model.MailboxACL;
-import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.store.JVMMailboxPathLocker;
import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
@@ -51,7 +50,6 @@ import org.apache.james.metrics.logger.DefaultMetricFactory;
import org.apache.james.mpt.api.ImapFeatures;
import org.apache.james.mpt.api.ImapFeatures.Feature;
import org.apache.james.mpt.host.JamesImapHostSystem;
-import org.apache.james.mpt.imapmailbox.MailboxCreationDelegate;
import org.xml.sax.InputSource;
public class JCRHostSystem extends JamesImapHostSystem {
@@ -159,10 +157,10 @@ public class JCRHostSystem extends JamesImapHostSystem {
}
@Override
- public void createMailbox(MailboxPath mailboxPath) throws Exception {
- new MailboxCreationDelegate(mailboxManager).createMailbox(mailboxPath);
+ protected MailboxManager getMailboxManager() {
+ return mailboxManager;
}
-
+
@Override
public boolean supports(Feature... features) {
return SUPPORTED_FEATURES.supports(features);
@@ -173,13 +171,4 @@ public class JCRHostSystem extends JamesImapHostSystem {
throw new NotImplementedException();
}
- @Override
- public void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception {
- mailboxManager.setRights(mailboxPath,
- MailboxACL.EMPTY.apply(MailboxACL.command()
- .forUser(userName)
- .rights(rights)
- .asAddition()),
- mailboxManager.createSystemSession(userName));
- }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/65d3ac3a/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java b/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
index 763752f..cb43a65 100644
--- a/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
+++ b/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
@@ -29,6 +29,7 @@ import org.apache.james.imap.api.process.ImapProcessor;
import org.apache.james.imap.encode.main.DefaultImapEncoderFactory;
import org.apache.james.imap.main.DefaultImapDecoderFactory;
import org.apache.james.imap.processor.main.DefaultImapProcessorFactory;
+import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.SubscriptionManager;
import org.apache.james.mailbox.acl.GroupMembershipResolver;
@@ -44,9 +45,7 @@ import org.apache.james.mailbox.jpa.mail.JPAUidProvider;
import org.apache.james.mailbox.jpa.openjpa.OpenJPAMailboxManager;
import org.apache.james.mailbox.jpa.quota.JPAPerUserMaxQuotaManager;
import org.apache.james.mailbox.jpa.quota.JpaCurrentQuotaManager;
-import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxConstants;
-import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.store.JVMMailboxPathLocker;
import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
@@ -57,7 +56,6 @@ import org.apache.james.metrics.logger.DefaultMetricFactory;
import org.apache.james.mpt.api.ImapFeatures;
import org.apache.james.mpt.api.ImapFeatures.Feature;
import org.apache.james.mpt.host.JamesImapHostSystem;
-import org.apache.james.mpt.imapmailbox.MailboxCreationDelegate;
import com.google.common.collect.ImmutableList;
@@ -144,10 +142,10 @@ public class JPAHostSystem extends JamesImapHostSystem {
}
@Override
- public void createMailbox(MailboxPath mailboxPath) throws Exception {
- new MailboxCreationDelegate(mailboxManager).createMailbox(mailboxPath);
+ protected MailboxManager getMailboxManager() {
+ return mailboxManager;
}
-
+
@Override
public boolean supports(Feature... features) {
return SUPPORTED_FEATURES.supports(features);
@@ -159,13 +157,4 @@ public class JPAHostSystem extends JamesImapHostSystem {
maxQuotaManager.setDefaultMaxStorage(maxStorageQuota);
}
- @Override
- public void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception {
- mailboxManager.setRights(mailboxPath,
- MailboxACL.EMPTY.apply(MailboxACL.command()
- .forUser(userName)
- .rights(rights)
- .asAddition()),
- mailboxManager.createSystemSession(userName));
- }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/65d3ac3a/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java b/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
index ad8bbd2..cef5b5a 100644
--- a/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
@@ -31,6 +31,7 @@ import org.apache.james.imap.api.process.ImapProcessor;
import org.apache.james.imap.encode.main.DefaultImapEncoderFactory;
import org.apache.james.imap.main.DefaultImapDecoderFactory;
import org.apache.james.imap.processor.main.DefaultImapProcessorFactory;
+import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.SubscriptionManager;
import org.apache.james.mailbox.acl.GroupMembershipResolver;
@@ -47,9 +48,7 @@ import org.apache.james.mailbox.jpa.mail.JPAModSeqProvider;
import org.apache.james.mailbox.jpa.mail.JPAUidProvider;
import org.apache.james.mailbox.jpa.openjpa.OpenJPAMailboxManager;
import org.apache.james.mailbox.lucene.search.LuceneMessageSearchIndex;
-import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxConstants;
-import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.MessageId;
import org.apache.james.mailbox.store.JVMMailboxPathLocker;
import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
@@ -60,7 +59,6 @@ import org.apache.james.metrics.logger.DefaultMetricFactory;
import org.apache.james.mpt.api.ImapFeatures;
import org.apache.james.mpt.api.ImapFeatures.Feature;
import org.apache.james.mpt.host.JamesImapHostSystem;
-import org.apache.james.mpt.imapmailbox.MailboxCreationDelegate;
import org.apache.lucene.store.FSDirectory;
import com.google.common.base.Throwables;
@@ -146,8 +144,8 @@ public class LuceneSearchHostSystem extends JamesImapHostSystem {
}
@Override
- public void createMailbox(MailboxPath mailboxPath) throws Exception{
- new MailboxCreationDelegate(mailboxManager).createMailbox(mailboxPath);
+ protected MailboxManager getMailboxManager() {
+ return mailboxManager;
}
@Override
@@ -160,13 +158,4 @@ public class LuceneSearchHostSystem extends JamesImapHostSystem {
throw new NotImplementedException();
}
- @Override
- public void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception {
- mailboxManager.setRights(mailboxPath,
- MailboxACL.EMPTY.apply(MailboxACL.command()
- .forUser(userName)
- .rights(rights)
- .asAddition()),
- mailboxManager.createSystemSession(userName));
- }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/65d3ac3a/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java b/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
index 2316551..87375a3 100644
--- a/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
+++ b/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
@@ -26,14 +26,13 @@ import org.apache.james.imap.api.process.ImapProcessor;
import org.apache.james.imap.encode.main.DefaultImapEncoderFactory;
import org.apache.james.imap.main.DefaultImapDecoderFactory;
import org.apache.james.imap.processor.main.DefaultImapProcessorFactory;
+import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.acl.GroupMembershipResolver;
import org.apache.james.mailbox.acl.MailboxACLResolver;
import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
import org.apache.james.mailbox.maildir.MaildirMailboxSessionMapperFactory;
import org.apache.james.mailbox.maildir.MaildirStore;
-import org.apache.james.mailbox.model.MailboxACL;
-import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.store.JVMMailboxPathLocker;
import org.apache.james.mailbox.store.StoreMailboxManager;
import org.apache.james.mailbox.store.StoreSubscriptionManager;
@@ -45,7 +44,6 @@ import org.apache.james.metrics.logger.DefaultMetricFactory;
import org.apache.james.mpt.api.ImapFeatures;
import org.apache.james.mpt.api.ImapFeatures.Feature;
import org.apache.james.mpt.host.JamesImapHostSystem;
-import org.apache.james.mpt.imapmailbox.MailboxCreationDelegate;
public class MaildirHostSystem extends JamesImapHostSystem {
@@ -108,8 +106,8 @@ public class MaildirHostSystem extends JamesImapHostSystem {
}
@Override
- public void createMailbox(MailboxPath mailboxPath) throws Exception {
- new MailboxCreationDelegate(mailboxManager).createMailbox(mailboxPath);
+ protected MailboxManager getMailboxManager() {
+ return mailboxManager;
}
@Override
@@ -122,13 +120,4 @@ public class MaildirHostSystem extends JamesImapHostSystem {
throw new NotImplementedException();
}
- @Override
- public void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception {
- mailboxManager.setRights(mailboxPath,
- MailboxACL.EMPTY.apply(MailboxACL.command()
- .forUser(userName)
- .rights(rights)
- .asAddition()),
- mailboxManager.createSystemSession(userName));
- }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[05/12] james-project git commit: JAMES-2183 Refactoring:
MessageFactory should rely on JMAP Keywords
Posted by bt...@apache.org.
JAMES-2183 Refactoring: MessageFactory should rely on JMAP Keywords
We need to generate Keywords from a set of MessageResult. Thus, one MessageResult can not be enough anymore for generating a message's keyword.
In a first step, we decrease the spead of javax.Flags usage in JMAP code, and make keywords an explicit parameter of MessageFactory.
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/ce13804e
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/ce13804e
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/ce13804e
Branch: refs/heads/master
Commit: ce13804ed95ec755ed696b8ded7c2dea0680d5b8
Parents: f0b2771
Author: benwa <bt...@linagora.com>
Authored: Fri Oct 13 09:51:37 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Oct 18 09:00:56 2017 +0700
----------------------------------------------------------------------
.../cucumber/GetMessagesMethodStepdefs.java | 2 +-
.../test/resources/cucumber/GetMessages.feature | 11 ++
.../james/jmap/methods/GetMessagesMethod.java | 5 +
.../methods/SetMessagesCreationProcessor.java | 11 +-
.../org/apache/james/jmap/model/Message.java | 13 +-
.../apache/james/jmap/model/MessageFactory.java | 26 ++--
.../james/jmap/json/ParsingWritingObjects.java | 5 +-
.../james/jmap/model/MessageFactoryTest.java | 122 ++++++-------------
.../apache/james/jmap/model/MessageTest.java | 53 +-------
.../apache/james/jmap/send/MailFactoryTest.java | 6 +-
10 files changed, 85 insertions(+), 169 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/ce13804e/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 cc9f465..b477c2c 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
@@ -248,7 +248,7 @@ 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, FlagListToFlags.fromFlagList(flagList));
+ appendMessage(messageName, StringListToFlags.fromFlagList(flagList));
}
private void appendMessage(String messageName, Flags flags) throws Exception {
http://git-wip-us.apache.org/repos/asf/james-project/blob/ce13804e/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 a74acb7..10d0f56 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
@@ -349,6 +349,17 @@ Feature: GetMessages method
|flags |keyword |
|"$Flagged,$Answered,$Draft" |$Flagged,$Answered,$Draft |
+ Scenario Outline: GetMessages should filter invalid keywords
+ Given the user has a message "m1" in the "inbox" mailbox with flags <flags>
+ When the user ask for messages "m1"
+ Then no error is returned
+ And the list should contain 1 message
+ And the keywords of the message is <keyword>
+
+ Examples:
+ |flags |keyword |
+ |"$Draft,@ert,t^a,op§,$user_flag" |$Draft,$user_flag |
+
Scenario Outline: Retrieving message should display keywords without unsupported jmap flag
Given the user has a message "m1" in the "inbox" mailbox with flags <flags>
When the user ask for messages "m1"
http://git-wip-us.apache.org/repos/asf/james-project/blob/ce13804e/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
index 4b8470b..47a501a 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
@@ -32,6 +32,7 @@ import org.apache.james.jmap.json.FieldNamePropertyFilter;
import org.apache.james.jmap.model.ClientId;
import org.apache.james.jmap.model.GetMessagesRequest;
import org.apache.james.jmap.model.GetMessagesResponse;
+import org.apache.james.jmap.model.Keywords;
import org.apache.james.jmap.model.Message;
import org.apache.james.jmap.model.MessageFactory;
import org.apache.james.jmap.model.MessageFactory.MetaDataWithContent;
@@ -65,6 +66,7 @@ public class GetMessagesMethod implements Method {
private final MessageFactory messageFactory;
private final MessageIdManager messageIdManager;
private final MetricFactory metricFactory;
+ private final Keywords.KeywordsFactory keywordsFactory;
@Inject
@VisibleForTesting GetMessagesMethod(
@@ -74,6 +76,8 @@ public class GetMessagesMethod implements Method {
this.messageFactory = messageFactory;
this.messageIdManager = messageIdManager;
this.metricFactory = metricFactory;
+ this.keywordsFactory = Keywords.factory()
+ .filterImapNonExposedKeywords();
}
@Override
@@ -167,6 +171,7 @@ public class GetMessagesMethod implements Method {
MetaDataWithContent.builderFromMessageResult(firstMessageResult)
.messageId(firstMessageResult.getMessageId())
.mailboxIds(mailboxIds)
+ .keywords(keywordsFactory.fromFlags(firstMessageResult.getFlags()))
.build());
} catch (Exception e) {
LOGGER.error("Can not convert MessageResults to MetaData with content for messageId " + firstMessageResult.getMessageId() + " in " + mailboxIds, e);
http://git-wip-us.apache.org/repos/asf/james-project/blob/ce13804e/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
index 0b2ce96..3087e71 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
@@ -29,7 +29,6 @@ import java.util.Set;
import java.util.stream.Collectors;
import javax.inject.Inject;
-import javax.mail.Flags;
import javax.mail.MessagingException;
import javax.mail.util.SharedByteArrayInputStream;
@@ -293,16 +292,16 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
SharedByteArrayInputStream content = new SharedByteArrayInputStream(messageContent);
Date internalDate = Date.from(createdEntry.getValue().getDate().toInstant());
- Flags flags = createdEntry.getValue()
+ Keywords keywords = createdEntry.getValue()
.getKeywords()
- .map(Keywords::asFlags)
- .orElse(new Flags());
+ .orElse(Keywords.DEFAULT_VALUE);
+ boolean notRecent = false;
- ComposedMessageId message = outbox.appendMessage(content, internalDate, session, flags.contains(Flags.Flag.RECENT), flags);
+ ComposedMessageId message = outbox.appendMessage(content, internalDate, session, notRecent, keywords.asFlags());
return MetaDataWithContent.builder()
.uid(message.getUid())
- .flags(flags)
+ .keywords(keywords)
.internalDate(internalDate.toInstant())
.sharedContent(content)
.size(messageContent.length)
http://git-wip-us.apache.org/repos/asf/james-project/blob/ce13804e/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java
index 86762fe..797d191 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java
@@ -26,7 +26,6 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;
-import javax.mail.Flags;
import org.apache.james.jmap.methods.GetMessagesMethod;
import org.apache.james.jmap.methods.JmapResponseWriterImpl;
@@ -72,7 +71,7 @@ public class Message {
private Optional<String> htmlBody = Optional.empty();
private final ImmutableList.Builder<Attachment> attachments;
private final ImmutableMap.Builder<BlobId, SubMessage> attachedMessages;
- private Optional<Flags> flags = Optional.empty();
+ private Optional<Keywords> keywords = Optional.empty();
private Builder() {
to = ImmutableList.builder();
@@ -118,8 +117,8 @@ public class Message {
return this;
}
- public Builder flags(Flags flags) {
- this.flags = Optional.ofNullable(flags);
+ public Builder keywords(Keywords keywords) {
+ this.keywords = Optional.ofNullable(keywords);
return this;
}
@@ -206,15 +205,11 @@ public class Message {
ImmutableMap<BlobId, SubMessage> attachedMessages = this.attachedMessages.build();
Preconditions.checkState(areAttachedMessagesKeysInAttachments(attachments, attachedMessages), "'attachedMessages' keys must be in 'attachements'");
boolean hasAttachment = hasAttachment(attachments);
- Keywords keywords = flags.map(flag -> Keywords.factory()
- .filterImapNonExposedKeywords()
- .fromFlags(flag))
- .orElse(Keywords.DEFAULT_VALUE);
return new Message(id, blobId, threadId, mailboxIds, Optional.ofNullable(inReplyToMessageId),
hasAttachment, headers, Optional.ofNullable(from),
to.build(), cc.build(), bcc.build(), replyTo.build(), subject, date, size, preview, textBody, htmlBody, attachments, attachedMessages,
- keywords);
+ keywords.orElse(Keywords.DEFAULT_VALUE));
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/ce13804e/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
index 05f2589..f70db5c 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
@@ -32,7 +32,6 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import javax.inject.Inject;
-import javax.mail.Flags;
import javax.mail.internet.SharedInputStream;
import org.apache.james.jmap.utils.HtmlTextExtractor;
@@ -99,7 +98,7 @@ public class MessageFactory {
.threadId(message.getMessageId().serialize())
.mailboxIds(message.getMailboxIds())
.inReplyToMessageId(getHeader(mimeMessage, "in-reply-to"))
- .flags(message.getFlags())
+ .keywords(message.getKeywords())
.subject(Strings.nullToEmpty(mimeMessage.getSubject()).trim())
.headers(toMap(mimeMessage.getHeader().getFields()))
.from(firstFromMailboxList(mimeMessage.getFrom()))
@@ -240,7 +239,6 @@ public class MessageFactory {
Builder builder = builder()
.uid(messageResult.getUid())
.modSeq(messageResult.getModSeq())
- .flags(messageResult.getFlags())
.size(messageResult.getSize())
.internalDate(messageResult.getInternalDate().toInstant())
.attachments(messageResult.getAttachments())
@@ -255,7 +253,7 @@ public class MessageFactory {
public static class Builder {
private MessageUid uid;
private Long modSeq;
- private Flags flags;
+ private Keywords keywords;
private Long size;
private Instant internalDate;
private InputStream content;
@@ -274,11 +272,11 @@ public class MessageFactory {
return this;
}
- public Builder flags(Flags flags) {
- this.flags = flags;
+ public Builder keywords(Keywords keywords) {
+ this.keywords = keywords;
return this;
}
-
+
public Builder size(long size) {
this.size = size;
return this;
@@ -324,20 +322,20 @@ public class MessageFactory {
if (modSeq == null) {
modSeq = -1L;
}
- Preconditions.checkArgument(flags != null);
+ Preconditions.checkArgument(keywords != null);
Preconditions.checkArgument(size != null);
Preconditions.checkArgument(internalDate != null);
Preconditions.checkArgument(content != null ^ sharedContent != null);
Preconditions.checkArgument(attachments != null);
Preconditions.checkArgument(mailboxIds != null);
Preconditions.checkArgument(messageId != null);
- return new MetaDataWithContent(uid, modSeq, flags, size, internalDate, content, sharedContent, attachments, mailboxIds, messageId);
+ return new MetaDataWithContent(uid, modSeq, keywords, size, internalDate, content, sharedContent, attachments, mailboxIds, messageId);
}
}
private final MessageUid uid;
private final long modSeq;
- private final Flags flags;
+ private final Keywords keywords;
private final long size;
private final Instant internalDate;
private final InputStream content;
@@ -348,7 +346,7 @@ public class MessageFactory {
private MetaDataWithContent(MessageUid uid,
long modSeq,
- Flags flags,
+ Keywords keywords,
long size,
Instant internalDate,
InputStream content,
@@ -358,7 +356,7 @@ public class MessageFactory {
MessageId messageId) {
this.uid = uid;
this.modSeq = modSeq;
- this.flags = flags;
+ this.keywords = keywords;
this.size = size;
this.internalDate = internalDate;
this.content = content;
@@ -376,8 +374,8 @@ public class MessageFactory {
return modSeq;
}
- public Flags getFlags() {
- return flags;
+ public Keywords getKeywords() {
+ return keywords;
}
public long getSize() {
http://git-wip-us.apache.org/repos/asf/james-project/blob/ce13804e/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java
index f84b91e..7a7a04e 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java
@@ -27,6 +27,7 @@ import javax.mail.Flags;
import org.apache.james.jmap.model.BlobId;
import org.apache.james.jmap.model.Emailer;
import org.apache.james.jmap.model.Keyword;
+import org.apache.james.jmap.model.Keywords;
import org.apache.james.jmap.model.Message;
import org.apache.james.jmap.model.SubMessage;
import org.apache.james.mailbox.FlagsBuilder;
@@ -41,7 +42,7 @@ import com.google.common.collect.ImmutableSet;
public interface ParsingWritingObjects {
- public interface Common {
+ interface Common {
MessageId MESSAGE_ID = TestMessageId.of(1);
BlobId BLOB_ID = BlobId.of("myBlobId");
String THREAD_ID = "myThreadId";
@@ -76,7 +77,7 @@ public interface ParsingWritingObjects {
.threadId(Common.THREAD_ID)
.mailboxIds(Common.MAILBOX_IDS)
.inReplyToMessageId(Common.IN_REPLY_TO_MESSAGE_ID)
- .flags(Common.FLAGS)
+ .keywords(Keywords.factory().fromSet(Common.KEYWORDS))
.headers(Common.HEADERS)
.from(Common.FROM)
.to(Common.TO)
http://git-wip-us.apache.org/repos/asf/james-project/blob/ce13804e/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
index 24b0a1e..5637620 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
@@ -27,16 +27,12 @@ import java.io.ByteArrayInputStream;
import java.time.Instant;
import java.util.Optional;
-import javax.mail.Flags;
-import javax.mail.Flags.Flag;
-
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.james.jmap.model.MessageFactory.MetaDataWithContent;
import org.apache.james.jmap.utils.HtmlTextExtractor;
import org.apache.james.jmap.utils.JsoupHtmlTextExtractor;
import org.apache.james.mailbox.BlobManager;
-import org.apache.james.mailbox.FlagsBuilder;
import org.apache.james.mailbox.MessageUid;
import org.apache.james.mailbox.inmemory.InMemoryId;
import org.apache.james.mailbox.model.AttachmentId;
@@ -58,14 +54,12 @@ public class MessageFactoryTest {
private static final Instant INTERNAL_DATE = Instant.parse("2012-02-03T14:30:42Z");
private MessageFactory messageFactory;
- private MessagePreviewGenerator messagePreview ;
- private HtmlTextExtractor htmlTextExtractor;
-
+
@Before
public void setUp() {
- htmlTextExtractor = new JsoupHtmlTextExtractor();
+ HtmlTextExtractor htmlTextExtractor = new JsoupHtmlTextExtractor();
- messagePreview = new MessagePreviewGenerator();
+ MessagePreviewGenerator messagePreview = new MessagePreviewGenerator();
MessageContentExtractor messageContentExtractor = new MessageContentExtractor();
BlobManager blobManager = mock(BlobManager.class);
@@ -77,7 +71,7 @@ public class MessageFactoryTest {
public void emptyMailShouldBeLoadedIntoMessage() throws Exception {
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(new Flags(Flag.SEEN))
+ .keywords(Keywords.factory().from(Keyword.SEEN))
.size(0)
.internalDate(INTERNAL_DATE)
.content(new ByteArrayInputStream("".getBytes(Charsets.UTF_8)))
@@ -94,13 +88,9 @@ public class MessageFactoryTest {
@Test
public void flagsShouldBeSetIntoMessage() throws Exception {
- Flags flags = new Flags();
- flags.add(Flag.ANSWERED);
- flags.add(Flag.FLAGGED);
- flags.add(Flag.DRAFT);
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(flags)
+ .keywords(Keywords.factory().from(Keyword.ANSWERED, Keyword.FLAGGED, Keyword.DRAFT))
.size(0)
.internalDate(INTERNAL_DATE)
.content(new ByteArrayInputStream("".getBytes(Charsets.UTF_8)))
@@ -116,7 +106,7 @@ public class MessageFactoryTest {
@Test
public void headersShouldBeSetIntoMessage() throws Exception {
- Flags flags = new Flags(Flag.SEEN);
+ Keywords keywords = Keywords.factory().from(Keyword.SEEN);
String headers = "From: user <us...@domain>\n"
+ "Subject: test subject\n"
+ "To: user1 <us...@domain>, user2 <us...@domain>\n"
@@ -128,7 +118,7 @@ public class MessageFactoryTest {
+ "Other-header: other header value";
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(flags)
+ .keywords(keywords)
.size(headers.length())
.internalDate(INTERNAL_DATE)
.content(new ByteArrayInputStream(headers.getBytes(Charsets.UTF_8)))
@@ -175,14 +165,14 @@ public class MessageFactoryTest {
.preview("(Empty)")
.textBody(Optional.of(""))
.htmlBody(Optional.empty())
- .flags(flags)
+ .keywords(keywords)
.build();
assertThat(testee).isEqualToComparingFieldByField(expected);
}
@Test
public void headersShouldBeUnfoldedAndDecoded() throws Exception {
- Flags flags = new Flags(Flag.SEEN);
+ Keywords keywords = Keywords.factory().from(Keyword.SEEN);
String headers = "From: user <us...@domain>\n"
+ "Subject: test subject\n"
+ "To: user1 <us...@domain>,\r\n"
@@ -190,7 +180,7 @@ public class MessageFactoryTest {
+ "Cc: =?UTF-8?Q?Beno=c3=aet_TELLIER?= <te...@linagora.com>";
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(flags)
+ .keywords(keywords)
.size(headers.length())
.internalDate(INTERNAL_DATE)
.content(new ByteArrayInputStream(headers.getBytes(Charsets.UTF_8)))
@@ -226,7 +216,7 @@ public class MessageFactoryTest {
.preview("(Empty)")
.textBody(Optional.of(""))
.htmlBody(Optional.empty())
- .flags(flags)
+ .keywords(keywords)
.build();
assertThat(testee).isEqualToComparingFieldByField(expected);
@@ -234,7 +224,7 @@ public class MessageFactoryTest {
@Test
public void multivaluedHeadersShouldBeSeparatedByLineFeed() throws Exception {
- Flags flags = new Flags(Flag.SEEN);
+ Keywords keywords = Keywords.factory().from(Keyword.SEEN);
String headers = "From: user <us...@domain>\n"
+ "Subject: test subject\n"
+ "Multi-header: first value\n"
@@ -242,7 +232,7 @@ public class MessageFactoryTest {
+ "Multi-header: second value\n";
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(flags)
+ .keywords(keywords)
.size(headers.length())
.internalDate(INTERNAL_DATE)
.content(new ByteArrayInputStream(headers.getBytes(Charsets.UTF_8)))
@@ -275,7 +265,7 @@ public class MessageFactoryTest {
.preview("(Empty)")
.textBody(Optional.of(""))
.htmlBody(Optional.empty())
- .flags(flags)
+ .keywords(keywords)
.build();
assertThat(testee).isEqualToComparingFieldByField(expected);
@@ -283,12 +273,13 @@ public class MessageFactoryTest {
@Test
public void textBodyShouldBeSetIntoMessage() throws Exception {
+ Keywords keywords = Keywords.factory().from(Keyword.SEEN);
String headers = "Subject: test subject\n";
String body = "Mail body";
String mail = headers + "\n" + body;
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(new Flags(Flag.SEEN))
+ .keywords(keywords)
.size(mail.length())
.internalDate(INTERNAL_DATE)
.content(new ByteArrayInputStream(mail.getBytes(Charsets.UTF_8)))
@@ -321,7 +312,7 @@ public class MessageFactoryTest {
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(new Flags(Flag.SEEN))
+ .keywords(Keywords.factory().from(Keyword.SEEN))
.internalDate(INTERNAL_DATE)
.size(1000)
.content(messageContent)
@@ -350,7 +341,7 @@ public class MessageFactoryTest {
String mail = headers + "\n" + body300;
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(new Flags(Flag.SEEN))
+ .keywords(Keywords.factory().from(Keyword.SEEN))
.size(mail.length())
.internalDate(INTERNAL_DATE)
.content(new ByteArrayInputStream(mail.getBytes(Charsets.UTF_8)))
@@ -366,7 +357,7 @@ public class MessageFactoryTest {
public void attachmentsShouldBeEmptyWhenNone() throws Exception {
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(new Flags(Flag.SEEN))
+ .keywords(Keywords.factory().from(Keyword.SEEN))
.size(0)
.internalDate(INTERNAL_DATE)
.content(new ByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("spamMail.eml"))))
@@ -392,7 +383,7 @@ public class MessageFactoryTest {
.build();
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(new Flags(Flag.SEEN))
+ .keywords(Keywords.factory().from(Keyword.SEEN))
.size(0)
.internalDate(INTERNAL_DATE)
.content(new ByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("spamMail.eml"))))
@@ -424,7 +415,7 @@ public class MessageFactoryTest {
+ "Subject: test subject\n";
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(new Flags(Flag.SEEN))
+ .keywords(Keywords.factory().from(Keyword.SEEN))
.size(headers.length())
.internalDate(INTERNAL_DATE)
.content(new ByteArrayInputStream(headers.getBytes(Charsets.UTF_8)))
@@ -453,7 +444,7 @@ public class MessageFactoryTest {
+ "Subject: test subject\n";
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(new Flags(Flag.SEEN))
+ .keywords(Keywords.factory().from(Keyword.SEEN))
.size(headers.length())
.internalDate(INTERNAL_DATE)
.content(new ByteArrayInputStream(headers.getBytes(Charsets.UTF_8)))
@@ -478,7 +469,7 @@ public class MessageFactoryTest {
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(new Flags(Flag.SEEN))
+ .keywords(Keywords.factory().from(Keyword.SEEN))
.size(headers.length())
.internalDate(INTERNAL_DATE)
.content(new ByteArrayInputStream(headers.getBytes(Charsets.UTF_8)))
@@ -504,7 +495,7 @@ public class MessageFactoryTest {
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(new Flags(Flag.SEEN))
+ .keywords(Keywords.factory().from(Keyword.SEEN))
.size(headers.length())
.internalDate(INTERNAL_DATE)
.content(new ByteArrayInputStream(headers.getBytes(Charsets.UTF_8)))
@@ -529,7 +520,7 @@ public class MessageFactoryTest {
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(new Flags(Flag.SEEN))
+ .keywords(Keywords.factory().from(Keyword.SEEN))
.size(headers.length())
.internalDate(INTERNAL_DATE)
.content(new ByteArrayInputStream(headers.getBytes(Charsets.UTF_8)))
@@ -547,7 +538,7 @@ public class MessageFactoryTest {
public void mailWithBigLinesShouldBeLoadedIntoMessage() throws Exception {
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(new Flags(Flag.SEEN))
+ .keywords(Keywords.factory().from(Keyword.SEEN))
.size(1010)
.internalDate(INTERNAL_DATE)
.content(new ByteArrayInputStream((StringUtils.repeat("0123456789", 101).getBytes(Charsets.UTF_8))))
@@ -570,7 +561,7 @@ public class MessageFactoryTest {
+ "my <b>HTML</b> message").getBytes(Charsets.UTF_8));
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(new Flags(Flag.SEEN))
+ .keywords(Keywords.factory().from(Keyword.SEEN))
.size(messageContent.read())
.internalDate(INTERNAL_DATE)
.content(messageContent)
@@ -591,7 +582,7 @@ public class MessageFactoryTest {
+ "Subject: message 1 subject\r\n").getBytes(Charsets.UTF_8));
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(new Flags(Flag.SEEN))
+ .keywords(Keywords.factory().from(Keyword.SEEN))
.size(messageContent.read())
.internalDate(INTERNAL_DATE)
.content(messageContent)
@@ -623,7 +614,7 @@ public class MessageFactoryTest {
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(new Flags(Flag.SEEN))
+ .keywords(Keywords.factory().from(Keyword.SEEN))
.size(messageContent.read())
.internalDate(INTERNAL_DATE)
.content(messageContent)
@@ -645,7 +636,7 @@ public class MessageFactoryTest {
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(new Flags(Flag.SEEN))
+ .keywords(Keywords.factory().from(Keyword.SEEN))
.size(messageContent.read())
.internalDate(INTERNAL_DATE)
.content(messageContent)
@@ -664,7 +655,7 @@ public class MessageFactoryTest {
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(new Flags(Flag.SEEN))
+ .keywords(Keywords.factory().from(Keyword.SEEN))
.size(messageContent.read())
.internalDate(INTERNAL_DATE)
.content(messageContent)
@@ -688,7 +679,7 @@ public class MessageFactoryTest {
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(new Flags(Flag.SEEN))
+ .keywords(Keywords.factory().from(Keyword.SEEN))
.size(messageContent.read())
.internalDate(INTERNAL_DATE)
.content(messageContent)
@@ -724,7 +715,7 @@ public class MessageFactoryTest {
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(new Flags(Flag.SEEN))
+ .keywords(Keywords.factory().from(Keyword.SEEN))
.size(messageContent.read())
.internalDate(INTERNAL_DATE)
.content(messageContent)
@@ -741,16 +732,11 @@ public class MessageFactoryTest {
@Test
public void keywordShouldBeSetIntoMessage() throws Exception {
- Flags flags = FlagsBuilder.builder()
- .add(Flag.ANSWERED, Flag.DRAFT)
- .build();
- ImmutableMap<String, Boolean> keywords = Keywords.factory()
- .fromFlags(flags)
- .asMap();
+ Keywords keywords = Keywords.factory().from(Keyword.SEEN, Keyword.DRAFT);
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(flags)
+ .keywords(keywords)
.size(0)
.internalDate(INTERNAL_DATE)
.content(new ByteArrayInputStream("".getBytes(Charsets.UTF_8)))
@@ -759,46 +745,16 @@ public class MessageFactoryTest {
.messageId(TestMessageId.of(2))
.build();
Message testee = messageFactory.fromMetaDataWithContent(testMail);
- assertThat(testee.getKeywords()).containsAllEntriesOf(keywords);
+ assertThat(testee.getKeywords()).containsAllEntriesOf(keywords.asMap());
}
@Test
public void keywordWithUserFlagShouldBeSetIntoMessage() throws Exception {
- Flags flags = FlagsBuilder.builder()
- .add(Flag.ANSWERED)
- .add(FORWARDED)
- .build();
- ImmutableMap<String, Boolean> keywords = Keywords.factory()
- .fromFlags(flags)
- .asMap();
- MetaDataWithContent testMail = MetaDataWithContent.builder()
- .uid(MessageUid.of(2))
- .flags(flags)
- .size(0)
- .internalDate(INTERNAL_DATE)
- .content(new ByteArrayInputStream("".getBytes(Charsets.UTF_8)))
- .attachments(ImmutableList.of())
- .mailboxId(MAILBOX_ID)
- .messageId(TestMessageId.of(2))
- .build();
- Message testee = messageFactory.fromMetaDataWithContent(testMail);
- assertThat(testee.getKeywords()).containsAllEntriesOf(keywords);
- }
-
- @Test
- public void fromMetaDataWithContentShouldRemoveUnsupportedKeyword() throws Exception {
- Flags flags = FlagsBuilder.builder()
- .add(Flag.ANSWERED, Flag.DELETED, Flag.RECENT)
- .add(FORWARDED)
- .build();
- ImmutableMap<String, Boolean> keywords = Keywords.factory()
- .filterImapNonExposedKeywords()
- .fromFlags(flags)
- .asMap();
+ Keywords keywords = Keywords.factory().from(Keyword.ANSWERED, new Keyword(FORWARDED));
MetaDataWithContent testMail = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(flags)
+ .keywords(keywords)
.size(0)
.internalDate(INTERNAL_DATE)
.content(new ByteArrayInputStream("".getBytes(Charsets.UTF_8)))
@@ -807,6 +763,6 @@ public class MessageFactoryTest {
.messageId(TestMessageId.of(2))
.build();
Message testee = messageFactory.fromMetaDataWithContent(testMail);
- assertThat(testee.getKeywords()).containsAllEntriesOf(keywords);
+ assertThat(testee.getKeywords()).containsAllEntriesOf(keywords.asMap());
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/ce13804e/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
index 2e690ba..3a838fb 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
@@ -23,16 +23,12 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.time.Instant;
import java.util.Optional;
-import javax.mail.Flags;
-
-import org.apache.james.mailbox.FlagsBuilder;
import org.apache.james.mailbox.inmemory.InMemoryId;
import org.apache.james.mailbox.model.TestMessageId;
import org.junit.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
public class MessageTest {
@@ -163,12 +159,9 @@ public class MessageTest {
.date(currentDate)
.build();
ImmutableMap<BlobId, SubMessage> attachedMessages = ImmutableMap.of(BlobId.of("blobId"), simpleMessage);
- Flags flags = FlagsBuilder.builder()
- .add(Flags.Flag.DRAFT, Flags.Flag.ANSWERED, Flags.Flag.FLAGGED)
- .build();
Keywords keywords = Keywords.factory()
- .fromFlags(flags);
+ .from(Keyword.DRAFT, Keyword.ANSWERED, Keyword.FLAGGED);
Message expected = new Message(
TestMessageId.of(1),
@@ -198,7 +191,7 @@ public class MessageTest {
.threadId("threadId")
.mailboxId(InMemoryId.of(456))
.inReplyToMessageId("inReplyToMessageId")
- .flags(flags)
+ .keywords(keywords)
.headers(ImmutableMap.of("key", "value"))
.from(from)
.to(to)
@@ -263,48 +256,6 @@ public class MessageTest {
}
@Test
- public void buildShouldNotThrowWhenNonValidFlags() throws Exception {
- Message.builder()
- .id(TestMessageId.of(1))
- .blobId(BlobId.of("blobId"))
- .threadId("threadId")
- .mailboxId(InMemoryId.of(456))
- .headers(ImmutableMap.of("key", "value"))
- .subject("subject")
- .size(1)
- .date(Instant.now())
- .preview("preview")
- .attachments(ImmutableList.of())
- .flags(FlagsBuilder.builder()
- .add("@ert", "t^a", "op§")
- .build())
- .build();
- }
-
- @Test
- public void buildShouldIgnoreNonValidFlag() throws Exception {
- Message message = Message.builder()
- .id(TestMessageId.of(1))
- .blobId(BlobId.of("blobId"))
- .threadId("threadId")
- .mailboxId(InMemoryId.of(456))
- .headers(ImmutableMap.of("key", "value"))
- .subject("subject")
- .size(1)
- .date(Instant.now())
- .preview("preview")
- .attachments(ImmutableList.of())
- .flags(FlagsBuilder.builder()
- .add("$Draft", "@ert", "t^a", "op§", "$user_flag")
- .build())
- .build();
-
- assertThat(message.getKeywords()).containsOnly(
- Maps.immutableEntry("$Draft", true),
- Maps.immutableEntry("$user_flag", true));
- }
-
- @Test
public void hasAttachmentShouldReturnFalseWhenNoAttachment() throws Exception {
Message message = Message.builder()
.id(TestMessageId.of(1))
http://git-wip-us.apache.org/repos/asf/james-project/blob/ce13804e/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailFactoryTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailFactoryTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailFactoryTest.java
index dd5e0f7..501e9c1 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailFactoryTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailFactoryTest.java
@@ -26,17 +26,17 @@ import static org.mockito.Mockito.when;
import java.time.Instant;
import java.util.Collection;
-import javax.mail.Flags;
import javax.mail.util.SharedByteArrayInputStream;
import org.apache.james.core.MailAddress;
+import org.apache.james.jmap.model.Keyword;
+import org.apache.james.jmap.model.Keywords;
import org.apache.james.jmap.model.Message;
import org.apache.james.jmap.model.MessageFactory;
import org.apache.james.jmap.model.MessageFactory.MetaDataWithContent;
import org.apache.james.jmap.model.MessagePreviewGenerator;
import org.apache.james.jmap.utils.HtmlTextExtractor;
import org.apache.james.mailbox.BlobManager;
-import org.apache.james.mailbox.FlagsBuilder;
import org.apache.james.mailbox.MessageUid;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.inmemory.InMemoryId;
@@ -71,7 +71,7 @@ public class MailFactoryTest {
message = MetaDataWithContent.builder()
.uid(MessageUid.of(2))
- .flags(new FlagsBuilder().add(Flags.Flag.SEEN).build())
+ .keywords(Keywords.factory().from(Keyword.SEEN))
.size(content.length())
.internalDate(Instant.now())
.sharedContent(new SharedByteArrayInputStream(content.getBytes(Charsets.UTF_8)))
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[10/12] james-project git commit: JAMES-2182 JamesImapHostSystem
support function for setting right on mailbox
Posted by bt...@apache.org.
JAMES-2182 JamesImapHostSystem support function for setting right on mailbox
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/10cd0d9a
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/10cd0d9a
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/10cd0d9a
Branch: refs/heads/master
Commit: 10cd0d9a4a51ebef80f5c4584d9172b04e82fa65
Parents: d479320
Author: quynhn <qn...@linagora.com>
Authored: Wed Oct 11 16:14:32 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Oct 18 09:02:16 2017 +0700
----------------------------------------------------------------------
.../java/org/apache/james/mpt/api/ImapHostSystem.java | 3 +++
.../org/apache/james/mpt/host/ExternalHostSystem.java | 6 ++++++
.../imapmailbox/cassandra/host/CassandraHostSystem.java | 11 +++++++++++
.../org/apache/james/mpt/host/JamesImapHostSystem.java | 6 +++++-
.../elasticsearch/host/ElasticSearchHostSystem.java | 11 +++++++++++
.../mpt/imapmailbox/hbase/host/HBaseHostSystem.java | 11 +++++++++++
.../imapmailbox/inmemory/host/InMemoryHostSystem.java | 11 +++++++++++
.../james/mpt/imapmailbox/jcr/host/JCRHostSystem.java | 12 +++++++++++-
.../james/mpt/imapmailbox/jpa/host/JPAHostSystem.java | 11 +++++++++++
.../lucenesearch/host/LuceneSearchHostSystem.java | 10 ++++++++++
.../mpt/imapmailbox/maildir/host/MaildirHostSystem.java | 11 +++++++++++
11 files changed, 101 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/10cd0d9a/mpt/core/src/main/java/org/apache/james/mpt/api/ImapHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/core/src/main/java/org/apache/james/mpt/api/ImapHostSystem.java b/mpt/core/src/main/java/org/apache/james/mpt/api/ImapHostSystem.java
index 472b227..a9fe170 100644
--- a/mpt/core/src/main/java/org/apache/james/mpt/api/ImapHostSystem.java
+++ b/mpt/core/src/main/java/org/apache/james/mpt/api/ImapHostSystem.java
@@ -18,6 +18,7 @@
****************************************************************/
package org.apache.james.mpt.api;
+import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mpt.api.ImapFeatures.Feature;
@@ -28,4 +29,6 @@ public interface ImapHostSystem extends HostSystem {
void createMailbox(MailboxPath mailboxPath) throws Exception;
void setQuotaLimits(long maxMessageQuota, long maxStorageQuota) throws Exception;
+
+ void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception;
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/10cd0d9a/mpt/core/src/main/java/org/apache/james/mpt/host/ExternalHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/core/src/main/java/org/apache/james/mpt/host/ExternalHostSystem.java b/mpt/core/src/main/java/org/apache/james/mpt/host/ExternalHostSystem.java
index be59cb3..98f443b 100644
--- a/mpt/core/src/main/java/org/apache/james/mpt/host/ExternalHostSystem.java
+++ b/mpt/core/src/main/java/org/apache/james/mpt/host/ExternalHostSystem.java
@@ -20,6 +20,7 @@
package org.apache.james.mpt.host;
import org.apache.commons.lang.NotImplementedException;
+import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mpt.api.ImapFeatures;
import org.apache.james.mpt.api.ImapFeatures.Feature;
@@ -112,4 +113,9 @@ public class ExternalHostSystem extends ExternalSessionFactory implements ImapHo
public void setQuotaLimits(long maxMessageQuota, long maxStorageQuota) throws Exception {
throw new NotImplementedException();
}
+
+ @Override
+ public void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception {
+ throw new NotImplementedException();
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/10cd0d9a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
index 8f2b4c0..0aaffcb 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
@@ -47,6 +47,7 @@ import org.apache.james.mailbox.cassandra.modules.CassandraUidModule;
import org.apache.james.mailbox.cassandra.quota.CassandraCurrentQuotaManager;
import org.apache.james.mailbox.cassandra.quota.CassandraPerUserMaxQuotaManager;
import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.quota.QuotaRootResolver;
import org.apache.james.mailbox.store.JVMMailboxPathLocker;
@@ -158,4 +159,14 @@ public class CassandraHostSystem extends JamesImapHostSystem {
perUserMaxQuotaManager.setDefaultMaxMessage(maxMessageQuota);
perUserMaxQuotaManager.setDefaultMaxStorage(maxStorageQuota);
}
+
+ @Override
+ public void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception {
+ mailboxManager.setRights(mailboxPath,
+ MailboxACL.EMPTY.apply(MailboxACL.command()
+ .forUser(userName)
+ .rights(rights)
+ .asAddition()),
+ mailboxManager.createSystemSession(userName));
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/10cd0d9a/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/host/JamesImapHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/host/JamesImapHostSystem.java b/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/host/JamesImapHostSystem.java
index d1bc8af..bb8abdb 100644
--- a/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/host/JamesImapHostSystem.java
+++ b/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/host/JamesImapHostSystem.java
@@ -29,6 +29,7 @@ import org.apache.james.imap.api.process.ImapProcessor;
import org.apache.james.imap.decode.ImapDecoder;
import org.apache.james.imap.decode.main.ImapRequestStreamHandler;
import org.apache.james.imap.encode.ImapEncoder;
+import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.store.Authenticator;
import org.apache.james.mailbox.store.Authorizator;
@@ -36,12 +37,13 @@ import org.apache.james.mpt.api.Continuation;
import org.apache.james.mpt.api.ImapHostSystem;
import org.apache.james.mpt.helper.ByteBufferInputStream;
import org.apache.james.mpt.helper.ByteBufferOutputStream;
+import org.apache.james.mpt.imapmailbox.GrantRightsOnHost;
import org.apache.james.mpt.session.ImapSessionImpl;
import org.apache.james.user.memory.MemoryUsersRepository;
import com.google.common.base.Throwables;
-public abstract class JamesImapHostSystem implements ImapHostSystem {
+public abstract class JamesImapHostSystem implements ImapHostSystem, GrantRightsOnHost {
private MemoryUsersRepository memoryUsersRepository;
protected Authorizator authorizator;
@@ -89,6 +91,8 @@ public abstract class JamesImapHostSystem implements ImapHostSystem {
public abstract void createMailbox(MailboxPath mailboxPath) throws Exception;
+ public abstract void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception;
+
class Session implements org.apache.james.mpt.api.Session {
ByteBufferOutputStream out;
http://git-wip-us.apache.org/repos/asf/james-project/blob/10cd0d9a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
index 288ca22..3ae5818 100644
--- a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
@@ -52,6 +52,7 @@ import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.inmemory.InMemoryId;
import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
import org.apache.james.mailbox.inmemory.InMemoryMessageId;
+import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.store.StoreMailboxManager;
@@ -151,4 +152,14 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
public void setQuotaLimits(long maxMessageQuota, long maxStorageQuota) throws Exception {
throw new NotImplementedException();
}
+
+ @Override
+ public void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception {
+ mailboxManager.setRights(mailboxPath,
+ MailboxACL.EMPTY.apply(MailboxACL.command()
+ .forUser(userName)
+ .rights(rights)
+ .asAddition()),
+ mailboxManager.createSystemSession(userName));
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/10cd0d9a/mpt/impl/imap-mailbox/hbase/src/test/java/org/apache/james/mpt/imapmailbox/hbase/host/HBaseHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/hbase/src/test/java/org/apache/james/mpt/imapmailbox/hbase/host/HBaseHostSystem.java b/mpt/impl/imap-mailbox/hbase/src/test/java/org/apache/james/mpt/imapmailbox/hbase/host/HBaseHostSystem.java
index 557d609..fae8500 100644
--- a/mpt/impl/imap-mailbox/hbase/src/test/java/org/apache/james/mpt/imapmailbox/hbase/host/HBaseHostSystem.java
+++ b/mpt/impl/imap-mailbox/hbase/src/test/java/org/apache/james/mpt/imapmailbox/hbase/host/HBaseHostSystem.java
@@ -40,6 +40,7 @@ import org.apache.james.mailbox.hbase.HBaseMailboxManager;
import org.apache.james.mailbox.hbase.HBaseMailboxSessionMapperFactory;
import org.apache.james.mailbox.hbase.mail.HBaseModSeqProvider;
import org.apache.james.mailbox.hbase.mail.HBaseUidProvider;
+import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.store.StoreSubscriptionManager;
import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
@@ -168,4 +169,14 @@ public class HBaseHostSystem extends JamesImapHostSystem {
public void setQuotaLimits(long maxMessageQuota, long maxStorageQuota) throws Exception {
throw new NotImplementedException();
}
+
+ @Override
+ public void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception {
+ mailboxManager.setRights(mailboxPath,
+ MailboxACL.EMPTY.apply(MailboxACL.command()
+ .forUser(userName)
+ .rights(rights)
+ .asAddition()),
+ mailboxManager.createSystemSession(userName));
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/10cd0d9a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java b/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
index 8dc8eff..8a07469 100644
--- a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
+++ b/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
@@ -33,6 +33,7 @@ import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
import org.apache.james.mailbox.inmemory.InMemoryMessageId;
import org.apache.james.mailbox.inmemory.quota.InMemoryCurrentQuotaManager;
import org.apache.james.mailbox.inmemory.quota.InMemoryPerUserMaxQuotaManager;
+import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.quota.QuotaRootResolver;
import org.apache.james.mailbox.store.JVMMailboxPathLocker;
@@ -112,4 +113,14 @@ public class InMemoryHostSystem extends JamesImapHostSystem {
perUserMaxQuotaManager.setDefaultMaxMessage(maxMessageQuota);
perUserMaxQuotaManager.setDefaultMaxStorage(maxStorageQuota);
}
+
+ @Override
+ public void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception {
+ mailboxManager.setRights(mailboxPath,
+ MailboxACL.EMPTY.apply(MailboxACL.command()
+ .forUser(userName)
+ .rights(rights)
+ .asAddition()),
+ mailboxManager.createSystemSession(userName));
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/10cd0d9a/mpt/impl/imap-mailbox/jcr/src/test/java/org/apache/james/mpt/imapmailbox/jcr/host/JCRHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/jcr/src/test/java/org/apache/james/mpt/imapmailbox/jcr/host/JCRHostSystem.java b/mpt/impl/imap-mailbox/jcr/src/test/java/org/apache/james/mpt/imapmailbox/jcr/host/JCRHostSystem.java
index 12b6888..8fb9322 100644
--- a/mpt/impl/imap-mailbox/jcr/src/test/java/org/apache/james/mpt/imapmailbox/jcr/host/JCRHostSystem.java
+++ b/mpt/impl/imap-mailbox/jcr/src/test/java/org/apache/james/mpt/imapmailbox/jcr/host/JCRHostSystem.java
@@ -40,6 +40,7 @@ import org.apache.james.mailbox.jcr.JCRSubscriptionManager;
import org.apache.james.mailbox.jcr.JCRUtils;
import org.apache.james.mailbox.jcr.mail.JCRModSeqProvider;
import org.apache.james.mailbox.jcr.mail.JCRUidProvider;
+import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.store.JVMMailboxPathLocker;
import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
@@ -171,5 +172,14 @@ public class JCRHostSystem extends JamesImapHostSystem {
public void setQuotaLimits(long maxMessageQuota, long maxStorageQuota) throws Exception {
throw new NotImplementedException();
}
-
+
+ @Override
+ public void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception {
+ mailboxManager.setRights(mailboxPath,
+ MailboxACL.EMPTY.apply(MailboxACL.command()
+ .forUser(userName)
+ .rights(rights)
+ .asAddition()),
+ mailboxManager.createSystemSession(userName));
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/10cd0d9a/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java b/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
index d87e6a5..763752f 100644
--- a/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
+++ b/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
@@ -44,6 +44,7 @@ import org.apache.james.mailbox.jpa.mail.JPAUidProvider;
import org.apache.james.mailbox.jpa.openjpa.OpenJPAMailboxManager;
import org.apache.james.mailbox.jpa.quota.JPAPerUserMaxQuotaManager;
import org.apache.james.mailbox.jpa.quota.JpaCurrentQuotaManager;
+import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.store.JVMMailboxPathLocker;
@@ -157,4 +158,14 @@ public class JPAHostSystem extends JamesImapHostSystem {
maxQuotaManager.setDefaultMaxMessage(maxMessageQuota);
maxQuotaManager.setDefaultMaxStorage(maxStorageQuota);
}
+
+ @Override
+ public void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception {
+ mailboxManager.setRights(mailboxPath,
+ MailboxACL.EMPTY.apply(MailboxACL.command()
+ .forUser(userName)
+ .rights(rights)
+ .asAddition()),
+ mailboxManager.createSystemSession(userName));
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/10cd0d9a/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java b/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
index 5ca521f..ad8bbd2 100644
--- a/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
@@ -47,6 +47,7 @@ import org.apache.james.mailbox.jpa.mail.JPAModSeqProvider;
import org.apache.james.mailbox.jpa.mail.JPAUidProvider;
import org.apache.james.mailbox.jpa.openjpa.OpenJPAMailboxManager;
import org.apache.james.mailbox.lucene.search.LuceneMessageSearchIndex;
+import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.MessageId;
@@ -159,4 +160,13 @@ public class LuceneSearchHostSystem extends JamesImapHostSystem {
throw new NotImplementedException();
}
+ @Override
+ public void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception {
+ mailboxManager.setRights(mailboxPath,
+ MailboxACL.EMPTY.apply(MailboxACL.command()
+ .forUser(userName)
+ .rights(rights)
+ .asAddition()),
+ mailboxManager.createSystemSession(userName));
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/10cd0d9a/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java b/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
index f03ad97..2316551 100644
--- a/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
+++ b/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
@@ -32,6 +32,7 @@ import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
import org.apache.james.mailbox.maildir.MaildirMailboxSessionMapperFactory;
import org.apache.james.mailbox.maildir.MaildirStore;
+import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.store.JVMMailboxPathLocker;
import org.apache.james.mailbox.store.StoreMailboxManager;
@@ -120,4 +121,14 @@ public class MaildirHostSystem extends JamesImapHostSystem {
public void setQuotaLimits(long maxMessageQuota, long maxStorageQuota) throws Exception {
throw new NotImplementedException();
}
+
+ @Override
+ public void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception {
+ mailboxManager.setRights(mailboxPath,
+ MailboxACL.EMPTY.apply(MailboxACL.command()
+ .forUser(userName)
+ .rights(rights)
+ .asAddition()),
+ mailboxManager.createSystemSession(userName));
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[04/12] james-project git commit: JAMES-2183 GetMessages should
combine keywords
Posted by bt...@apache.org.
JAMES-2183 GetMessages should combine keywords
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c93ffe68
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c93ffe68
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c93ffe68
Branch: refs/heads/master
Commit: c93ffe68bf4b3dcdd07a5125cb04f9a0b4aa2c56
Parents: ce13804
Author: quynhn <qn...@linagora.com>
Authored: Fri Oct 13 10:41:48 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Oct 18 09:00:56 2017 +0700
----------------------------------------------------------------------
.../org/apache/james/jmap/methods/GetMessagesMethod.java | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/c93ffe68/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
index 47a501a..f0313ed 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
@@ -38,11 +38,13 @@ import org.apache.james.jmap.model.MessageFactory;
import org.apache.james.jmap.model.MessageFactory.MetaDataWithContent;
import org.apache.james.jmap.model.MessageProperties;
import org.apache.james.jmap.model.MessageProperties.HeaderProperty;
+import org.apache.james.jmap.utils.KeywordsCombiner;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.MessageIdManager;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.FetchGroupImpl;
import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.MessageResult;
import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.util.MDCBuilder;
@@ -63,6 +65,7 @@ public class GetMessagesMethod implements Method {
private static final Logger LOGGER = LoggerFactory.getLogger(GetMessagesMethod.class);
private static final Method.Request.Name METHOD_NAME = Method.Request.name("getMessages");
private static final Method.Response.Name RESPONSE_NAME = Method.Response.name("messages");
+ private static final KeywordsCombiner ACCUMULATOR = new KeywordsCombiner();
private final MessageFactory messageFactory;
private final MessageIdManager messageIdManager;
private final MetricFactory metricFactory;
@@ -167,11 +170,16 @@ public class GetMessagesMethod implements Method {
.distinct()
.collect(Guavate.toImmutableList());
try {
+ Keywords keywords = messageResults.stream()
+ .map(MessageMetaData::getFlags)
+ .map(keywordsFactory::fromFlags)
+ .reduce(ACCUMULATOR)
+ .get();
return Stream.of(
MetaDataWithContent.builderFromMessageResult(firstMessageResult)
.messageId(firstMessageResult.getMessageId())
.mailboxIds(mailboxIds)
- .keywords(keywordsFactory.fromFlags(firstMessageResult.getFlags()))
+ .keywords(keywords)
.build());
} catch (Exception e) {
LOGGER.error("Can not convert MessageResults to MetaData with content for messageId " + firstMessageResult.getMessageId() + " in " + mailboxIds, e);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[09/12] james-project git commit: JAMES-2188 Add integration test on
appending a message in a not own mailbox
Posted by bt...@apache.org.
JAMES-2188 Add integration test on appending a message in a not own mailbox
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/d479320f
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/d479320f
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/d479320f
Branch: refs/heads/master
Commit: d479320ff076cc07b9114ea85645933306e3daa5
Parents: bb1eeec
Author: Antoine Duprat <ad...@linagora.com>
Authored: Mon Oct 16 15:33:35 2017 +0200
Committer: benwa <bt...@linagora.com>
Committed: Wed Oct 18 09:01:57 2017 +0700
----------------------------------------------------------------------
.../integration/SetMessagesMethodTest.java | 45 ++++++++++++++++++++
1 file changed, 45 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/d479320f/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
index 1bc5731..23027ab 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
@@ -66,13 +66,16 @@ import org.apache.james.mailbox.MailboxListener;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.Attachment;
import org.apache.james.mailbox.model.ComposedMessageId;
+import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.MessageId;
import org.apache.james.mailbox.model.MessageResult;
import org.apache.james.mailbox.store.event.EventFactory;
+import org.apache.james.mailbox.store.probe.ACLProbe;
import org.apache.james.mailbox.store.probe.MailboxProbe;
+import org.apache.james.modules.ACLProbeImpl;
import org.apache.james.modules.MailboxProbeImpl;
import org.apache.james.probe.DataProbe;
import org.apache.james.util.ZeroedInputStream;
@@ -134,6 +137,7 @@ public abstract class SetMessagesMethodTest {
private MailboxProbe mailboxProbe;
private DataProbe dataProbe;
private MessageIdProbe messageProbe;
+ private ACLProbe aclProbe;
@Before
public void setup() throws Throwable {
@@ -142,6 +146,7 @@ public abstract class SetMessagesMethodTest {
mailboxProbe = jmapServer.getProbe(MailboxProbeImpl.class);
dataProbe = jmapServer.getProbe(DataProbeImpl.class);
messageProbe = jmapServer.getProbe(MessageIdProbe.class);
+ aclProbe = jmapServer.getProbe(ACLProbeImpl.class);
RestAssured.requestSpecification = new RequestSpecBuilder()
.setContentType(ContentType.JSON)
@@ -1165,6 +1170,46 @@ public abstract class SetMessagesMethodTest {
}
@Test
+ public void setMessagesShouldReturnErrorWhenUserIsNotTheOwnerOfOneOfTheMailboxes() throws Exception {
+ String alice = "alice@" + USERS_DOMAIN;
+ dataProbe.addUser(alice, "alicepassword");
+ MailboxId aliceOutbox = mailboxProbe.createMailbox("#private", alice, DefaultMailboxes.OUTBOX);
+
+ aclProbe.replaceRights(MailboxPath.forUser(alice, DefaultMailboxes.OUTBOX), USERNAME, MailboxACL.FULL_RIGHTS);
+
+ String messageCreationId = "creationId1337";
+ String fromAddress = USERNAME;
+ String requestBody = "[" +
+ " [" +
+ " \"setMessages\","+
+ " {" +
+ " \"create\": { \"" + messageCreationId + "\" : {" +
+ " \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
+ " \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
+ " \"subject\": \"\"," +
+ " \"mailboxIds\": [\"" + aliceOutbox.serialize() + "\", \"" + getOutboxId(accessToken) + "\"]" +
+ " }}" +
+ " }," +
+ " \"#0\"" +
+ " ]" +
+ "]";
+
+ given()
+ .header("Authorization", accessToken.serialize())
+ .body(requestBody)
+ .when()
+ .post("/jmap")
+ .then()
+ .log().ifValidationFails()
+ .statusCode(200)
+ .body(NAME, equalTo("messagesSet"))
+ .body(NAME, equalTo("messagesSet"))
+ .body(ARGUMENTS + ".notCreated", hasKey(messageCreationId))
+ .body(ARGUMENTS + ".notCreated[\""+messageCreationId+"\"].type", equalTo("error"))
+ .body(ARGUMENTS + ".notCreated[\""+messageCreationId+"\"].description", endsWith("MailboxId invalid"));
+ }
+
+ @Test
public void setMessageWithCreatedMessageShouldReturnAnErrorWhenBothIsFlagAndKeywordsPresent() {
String messageCreationId = "creationId1337";
String fromAddress = USERNAME;
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org