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 ma...@apache.org on 2016/04/25 16:15:45 UTC
[1/4] james-project git commit: JAMES-1721 Enhance readability of
SetMailboxesUpdateProcessor class by removing an abstraction level and using
existing Builder
Repository: james-project
Updated Branches:
refs/heads/master 1f3d5c8f2 -> b2f2e187c
JAMES-1721 Enhance readability of SetMailboxesUpdateProcessor class by removing an abstraction level and using existing Builder
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/80c60012
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/80c60012
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/80c60012
Branch: refs/heads/master
Commit: 80c60012529b0d2ad3b7605469bff26cb0926020
Parents: f476cba
Author: Laura Royet <lr...@linagora.com>
Authored: Tue Apr 19 15:55:47 2016 +0200
Committer: Laura Royet <lr...@linagora.com>
Committed: Mon Apr 25 14:50:28 2016 +0200
----------------------------------------------------------------------
.../methods/SetMailboxesUpdateProcessor.java | 48 ++++++++++++--------
1 file changed, 28 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/80c60012/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
index b079b64..0eee160 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
@@ -80,25 +80,40 @@ public class SetMailboxesUpdateProcessor<Id extends MailboxId> implements SetMai
responseBuilder.updated(mailboxId);
} catch (SystemMailboxNotUpdatableException e) {
- notUpdated(mailboxId, "invalidArguments", "Cannot update a system mailbox.", responseBuilder);
+ responseBuilder.notUpdated(mailboxId, SetError.builder()
+ .type("invalidArguments")
+ .description("Cannot update a system mailbox.")
+ .build());
} catch (MailboxNameException e) {
- notUpdated(mailboxId, "invalidArguments",
- e.getMessage(), responseBuilder);
+ responseBuilder.notUpdated(mailboxId, SetError.builder()
+ .type("invalidArguments")
+ .description(e.getMessage())
+ .build());
} catch (MailboxNotFoundException e) {
- notUpdated(mailboxId, "notFound",
- String.format("The mailbox '%s' was not found", mailboxId), responseBuilder);
+ responseBuilder.notUpdated(mailboxId, SetError.builder()
+ .type("notFound")
+ .description(String.format("The mailbox '%s' was not found", mailboxId))
+ .build());
} catch (MailboxParentNotFoundException e) {
- notUpdated(mailboxId, "notFound",
- String.format("The parent mailbox '%s' was not found.", e.getParentId()), responseBuilder);
+ responseBuilder.notUpdated(mailboxId, SetError.builder()
+ .type("notFound")
+ .description(String.format("The parent mailbox '%s' was not found.", e.getParentId()))
+ .build());
} catch (MailboxHasChildException e) {
- notUpdated(mailboxId, "invalidArguments",
- "Cannot update a parent mailbox.", responseBuilder);
+ responseBuilder.notUpdated(mailboxId, SetError.builder()
+ .type("invalidArguments")
+ .description("Cannot update a parent mailbox.")
+ .build());
} catch (MailboxExistsException e) {
- notUpdated(mailboxId, "invalidArguments",
- "Cannot rename a mailbox to an already existing mailbox.", responseBuilder);
+ responseBuilder.notUpdated(mailboxId, SetError.builder()
+ .type("invalidArguments")
+ .description("Cannot rename a mailbox to an already existing mailbox.")
+ .build());
} catch (MailboxException e) {
- notUpdated(mailboxId, "anErrorOccurred",
- "An error occurred when updating the mailbox", responseBuilder);
+ responseBuilder.notUpdated(mailboxId, SetError.builder()
+ .type( "anErrorOccurred")
+ .description("An error occurred when updating the mailbox")
+ .build());
}
}
@@ -108,13 +123,6 @@ public class SetMailboxesUpdateProcessor<Id extends MailboxId> implements SetMai
}
}
- private Builder notUpdated(String mailboxId, String type, String message, Builder responseBuilder) {
- return responseBuilder.notUpdated(mailboxId, SetError.builder()
- .type(type)
- .description(message)
- .build());
- }
-
private Mailbox getMailbox(String mailboxId, MailboxSession mailboxSession) throws MailboxNotFoundException {
return mailboxUtils.mailboxFromMailboxId(mailboxId, mailboxSession)
.orElseThrow(() -> new MailboxNotFoundException(mailboxId));
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[3/4] james-project git commit: JAMES-1721 Rename a mailbox to a
system Mailbox is not possible
Posted by ma...@apache.org.
JAMES-1721 Rename a mailbox to a system Mailbox is not possible
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/39928fdd
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/39928fdd
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/39928fdd
Branch: refs/heads/master
Commit: 39928fdd70afb77c26b3a353ad9cc1c6ce10da78
Parents: 80c6001
Author: Laura Royet <lr...@linagora.com>
Authored: Fri Apr 22 10:31:28 2016 +0200
Committer: Laura Royet <lr...@linagora.com>
Committed: Mon Apr 25 14:50:29 2016 +0200
----------------------------------------------------------------------
.../integration/SetMailboxesMethodTest.java | 36 ++++++++++++++++++++
.../methods/SetMailboxesUpdateProcessor.java | 21 ++++++++++--
2 files changed, 54 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/39928fdd/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
index 2c0316c..ede31d0 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
@@ -1476,4 +1476,40 @@ public abstract class SetMailboxesMethodTest {
hasEntry(equalTo("type"), equalTo("invalidArguments")),
hasEntry(equalTo("description"), equalTo("Cannot update a system mailbox.")))));
}
+
+ @Test
+ public void setMailboxesShouldReturnNotUpdatedWhenRenameToSystemMailboxName() {
+
+ jmapServer.serverProbe().createMailbox("#private", username, "myBox");
+ Mailbox<?> mailboxMyBox = jmapServer.serverProbe().getMailbox("#private", username, "myBox");
+ String mailboxIdMyBox = mailboxMyBox.getMailboxId().serialize();
+
+ String requestBody =
+ "[" +
+ " [ \"setMailboxes\"," +
+ " {" +
+ " \"update\": {" +
+ " \"" + mailboxIdMyBox + "\" : {" +
+ " \"name\" : \"outbox\"" +
+ " }" +
+ " }" +
+ " }," +
+ " \"#0\"" +
+ " ]" +
+ "]";
+
+ given()
+ .accept(ContentType.JSON)
+ .contentType(ContentType.JSON)
+ .header("Authorization", this.accessToken.serialize())
+ .body(requestBody)
+ .when()
+ .post("/jmap")
+ .then()
+ .statusCode(200)
+ .body(NAME, equalTo("mailboxesSet"))
+ .body(ARGUMENTS + ".notUpdated", hasEntry(equalTo(mailboxIdMyBox), Matchers.allOf(
+ hasEntry(equalTo("type"), equalTo("invalidArguments")),
+ hasEntry(equalTo("description"), equalTo("The mailbox 'outbox' is a system mailbox.")))));
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/39928fdd/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
index 0eee160..29efbe2 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
@@ -130,11 +130,26 @@ public class SetMailboxesUpdateProcessor<Id extends MailboxId> implements SetMai
private void validateMailboxName(MailboxUpdateRequest updateRequest, MailboxSession mailboxSession) throws MailboxNameException {
char pathDelimiter = mailboxSession.getPathDelimiter();
- if (updateRequest.getName()
- .filter(name -> name.contains(String.valueOf(pathDelimiter)))
- .isPresent()) {
+
+ if (nameContainsPathDelimiter(updateRequest, pathDelimiter)) {
throw new MailboxNameException(String.format("The mailbox '%s' contains an illegal character: '%c'", updateRequest.getName().get(), pathDelimiter));
}
+ if (nameMatchesSystemMailbox(updateRequest)) {
+ throw new MailboxNameException(String.format("The mailbox '%s' is a system mailbox.", updateRequest.getName().get()));
+ }
+ }
+
+ private boolean nameMatchesSystemMailbox(MailboxUpdateRequest updateRequest) {
+ return updateRequest.getName()
+ .flatMap(Role::from)
+ .filter(Role::isSystemRole)
+ .isPresent();
+ }
+
+ private boolean nameContainsPathDelimiter(MailboxUpdateRequest updateRequest, char pathDelimiter) {
+ return updateRequest.getName()
+ .filter(name -> name.contains(String.valueOf(pathDelimiter)))
+ .isPresent() ;
}
private void validateParent(Mailbox mailbox, MailboxUpdateRequest updateRequest, MailboxSession mailboxSession) throws MailboxException, MailboxHasChildException {
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[4/4] james-project git commit: Merge remote-tracking branch
'laura/JAMES-1721'
Posted by ma...@apache.org.
Merge remote-tracking branch 'laura/JAMES-1721'
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/b2f2e187
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b2f2e187
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b2f2e187
Branch: refs/heads/master
Commit: b2f2e187c18ce9fe592a75e86c2cecd536feb47f
Parents: 1f3d5c8 39928fd
Author: Matthieu Baechler <ma...@linagora.com>
Authored: Mon Apr 25 16:14:30 2016 +0200
Committer: Matthieu Baechler <ma...@linagora.com>
Committed: Mon Apr 25 16:14:30 2016 +0200
----------------------------------------------------------------------
.../integration/SetMailboxesMethodTest.java | 71 ++++++++++++++++++
.../jmap/exceptions/SystemMailboxException.java | 23 ------
.../SystemMailboxNotUpdatableException.java | 23 ++++++
.../SetMailboxesDestructionProcessor.java | 10 +--
.../methods/SetMailboxesUpdateProcessor.java | 77 ++++++++++++++------
.../SetMailboxesUpdateProcessorTest.java | 2 +-
6 files changed, 156 insertions(+), 50 deletions(-)
----------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[2/4] james-project git commit: JAMES-1721 SetMailboxes can't modify
system mailboxes
Posted by ma...@apache.org.
JAMES-1721 SetMailboxes can't modify system 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/f476cbaf
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f476cbaf
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f476cbaf
Branch: refs/heads/master
Commit: f476cbafaf86c6554be5bebf51b864e97ab4063d
Parents: 223dd81
Author: Laura Royet <lr...@linagora.com>
Authored: Thu Apr 14 16:15:14 2016 +0200
Committer: Laura Royet <lr...@linagora.com>
Committed: Mon Apr 25 14:50:28 2016 +0200
----------------------------------------------------------------------
.../integration/SetMailboxesMethodTest.java | 35 ++++++++++++++++++++
.../jmap/exceptions/SystemMailboxException.java | 23 -------------
.../SystemMailboxNotUpdatableException.java | 23 +++++++++++++
.../SetMailboxesDestructionProcessor.java | 10 +++---
.../methods/SetMailboxesUpdateProcessor.java | 12 +++++++
.../SetMailboxesUpdateProcessorTest.java | 2 +-
6 files changed, 76 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/f476cbaf/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
index 07718f8..2c0316c 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
@@ -1441,4 +1441,39 @@ public abstract class SetMailboxesMethodTest {
.body(ARGUMENTS + ".list", hasSize(1))
.body(ARGUMENTS + ".list[0].name", equalTo("mySecondBox"));
}
+
+ @Test
+ public void setMailboxesShouldReturnNotUpdatedWhenRenamingSystemMailbox() {
+
+ Mailbox<?> mailbox = jmapServer.serverProbe().getMailbox("#private", username, "inbox");
+ String mailboxId = mailbox.getMailboxId().serialize();
+
+ String requestBody =
+ "[" +
+ " [ \"setMailboxes\"," +
+ " {" +
+ " \"update\": {" +
+ " \"" + mailboxId + "\" : {" +
+ " \"name\" : \"renamed\"" +
+ " }" +
+ " }" +
+ " }," +
+ " \"#0\"" +
+ " ]" +
+ "]";
+
+ given()
+ .accept(ContentType.JSON)
+ .contentType(ContentType.JSON)
+ .header("Authorization", this.accessToken.serialize())
+ .body(requestBody)
+ .when()
+ .post("/jmap")
+ .then()
+ .statusCode(200)
+ .body(NAME, equalTo("mailboxesSet"))
+ .body(ARGUMENTS + ".notUpdated", hasEntry(equalTo(mailboxId), Matchers.allOf(
+ hasEntry(equalTo("type"), equalTo("invalidArguments")),
+ hasEntry(equalTo("description"), equalTo("Cannot update a system mailbox.")))));
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f476cbaf/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/SystemMailboxException.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/SystemMailboxException.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/SystemMailboxException.java
deleted file mode 100644
index f82cfa1..0000000
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/SystemMailboxException.java
+++ /dev/null
@@ -1,23 +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.jmap.exceptions;
-
-public class SystemMailboxException extends Exception {
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f476cbaf/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/SystemMailboxNotUpdatableException.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/SystemMailboxNotUpdatableException.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/SystemMailboxNotUpdatableException.java
new file mode 100644
index 0000000..6ecebf7
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/SystemMailboxNotUpdatableException.java
@@ -0,0 +1,23 @@
+/****************************************************************
+ * 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.exceptions;
+
+public class SystemMailboxNotUpdatableException extends RuntimeException {
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f476cbaf/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesDestructionProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesDestructionProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesDestructionProcessor.java
index 6076fb8..5fdc8d9 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesDestructionProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesDestructionProcessor.java
@@ -26,7 +26,7 @@ import java.util.Optional;
import javax.inject.Inject;
import org.apache.james.jmap.exceptions.MailboxHasChildException;
-import org.apache.james.jmap.exceptions.SystemMailboxException;
+import org.apache.james.jmap.exceptions.SystemMailboxNotUpdatableException;
import org.apache.james.jmap.model.SetError;
import org.apache.james.jmap.model.SetMailboxesRequest;
import org.apache.james.jmap.model.SetMailboxesResponse;
@@ -103,7 +103,7 @@ public class SetMailboxesDestructionProcessor<Id extends MailboxId> implements S
.type("mailboxHasChild")
.description(String.format("The mailbox '%s' has a child.", entry.getKey()))
.build());
- } catch (SystemMailboxException e) {
+ } catch (SystemMailboxNotUpdatableException e) {
builder.notDestroyed(entry.getKey(), SetError.builder()
.type("invalidArguments")
.description(String.format("The mailbox '%s' is a system mailbox.", entry.getKey()))
@@ -118,7 +118,7 @@ public class SetMailboxesDestructionProcessor<Id extends MailboxId> implements S
}
}
- private void preconditions(Mailbox mailbox, MailboxSession mailboxSession) throws MailboxHasChildException, SystemMailboxException, MailboxException {
+ private void preconditions(Mailbox mailbox, MailboxSession mailboxSession) throws MailboxHasChildException, SystemMailboxNotUpdatableException, MailboxException {
checkForChild(mailbox.getId(), mailboxSession);
checkRole(mailbox.getRole());
}
@@ -129,9 +129,9 @@ public class SetMailboxesDestructionProcessor<Id extends MailboxId> implements S
}
}
- private void checkRole(Optional<Role> role) throws SystemMailboxException {
+ private void checkRole(Optional<Role> role) throws SystemMailboxNotUpdatableException {
if (role.map(Role::isSystemRole).orElse(false)) {
- throw new SystemMailboxException();
+ throw new SystemMailboxNotUpdatableException();
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f476cbaf/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
index bf4d4ac..b079b64 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
@@ -26,12 +26,14 @@ import javax.inject.Inject;
import org.apache.james.jmap.exceptions.MailboxHasChildException;
import org.apache.james.jmap.exceptions.MailboxNameException;
import org.apache.james.jmap.exceptions.MailboxParentNotFoundException;
+import org.apache.james.jmap.exceptions.SystemMailboxNotUpdatableException;
import org.apache.james.jmap.model.SetError;
import org.apache.james.jmap.model.SetMailboxesRequest;
import org.apache.james.jmap.model.SetMailboxesResponse;
import org.apache.james.jmap.model.SetMailboxesResponse.Builder;
import org.apache.james.jmap.model.mailbox.Mailbox;
import org.apache.james.jmap.model.mailbox.MailboxUpdateRequest;
+import org.apache.james.jmap.model.mailbox.Role;
import org.apache.james.jmap.utils.MailboxUtils;
import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxSession;
@@ -71,10 +73,14 @@ public class SetMailboxesUpdateProcessor<Id extends MailboxId> implements SetMai
try {
validateMailboxName(updateRequest, mailboxSession);
Mailbox mailbox = getMailbox(mailboxId, mailboxSession);
+ checkRole(mailbox.getRole());
validateParent(mailbox, updateRequest, mailboxSession);
updateMailbox(mailbox, updateRequest, mailboxSession);
responseBuilder.updated(mailboxId);
+
+ } catch (SystemMailboxNotUpdatableException e) {
+ notUpdated(mailboxId, "invalidArguments", "Cannot update a system mailbox.", responseBuilder);
} catch (MailboxNameException e) {
notUpdated(mailboxId, "invalidArguments",
e.getMessage(), responseBuilder);
@@ -94,6 +100,12 @@ public class SetMailboxesUpdateProcessor<Id extends MailboxId> implements SetMai
notUpdated(mailboxId, "anErrorOccurred",
"An error occurred when updating the mailbox", responseBuilder);
}
+ }
+
+ private void checkRole(Optional<Role> role) throws SystemMailboxNotUpdatableException {
+ if (role.map(Role::isSystemRole).orElse(false)) {
+ throw new SystemMailboxNotUpdatableException();
+ }
}
private Builder notUpdated(String mailboxId, String type, String message, Builder responseBuilder) {
http://git-wip-us.apache.org/repos/asf/james-project/blob/f476cbaf/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
index 73e2146..6fc0f9e 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
@@ -64,7 +64,7 @@ public class SetMailboxesUpdateProcessorTest {
SetMailboxesRequest request = SetMailboxesRequest.builder()
.update(mailboxId, MailboxUpdateRequest.builder().parentId(newParentId).build())
.build();
- Mailbox mailbox = Mailbox.builder().id(mailboxId).name("name").build();
+ Mailbox mailbox = Mailbox.builder().id(mailboxId).name("name").role(Optional.empty()).build();
when(mockedMailboxUtils.mailboxFromMailboxId(mailboxId, mockedMailboxSession))
.thenReturn(Optional.of(mailbox));
when(mockedMailboxUtils.mailboxPathFromMailboxId(newParentId, mockedMailboxSession))
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org