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 2020/08/14 09:07:35 UTC
[james-project] 07/13: JAMES-3354: mailbox set: parentId handling
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit f26ba8ad750d3e6b67d4c1a32440f7ed8c43d846
Author: duc91 <vd...@linagora.com>
AuthorDate: Wed Aug 12 15:43:09 2020 +0700
JAMES-3354: mailbox set: parentId handling
---
.../contract/MailboxSetMethodContract.scala | 42 ++++++++++++++++++++++
.../james/jmap/method/MailboxSetMethod.scala | 18 +++++++---
2 files changed, 56 insertions(+), 4 deletions(-)
diff --git a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxSetMethodContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxSetMethodContract.scala
index 76a21ec..7e978bc 100644
--- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxSetMethodContract.scala
+++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxSetMethodContract.scala
@@ -393,4 +393,46 @@ trait MailboxSetMethodContract {
| "c1"]]
|}""".stripMargin)
}
+
+ @Test
+ def mailboxSetShouldCreateMailboxWhenNameAndParentId(server: GuiceJamesServer): Unit = {
+ val mailboxId: MailboxId = server.getProbe(classOf[MailboxProbeImpl]).createMailbox(MailboxPath.forUser(BOB, "parentMailbox"))
+ val request=
+ s"""
+ |{
+ | "using": [ "urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail" ],
+ | "methodCalls": [
+ | [
+ | "Mailbox/set",
+ | {
+ | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+ | "create": {
+ | "C42": {
+ | "name": "childMailbox",
+ | "parentId":"${mailboxId.serialize}"
+ | }
+ | }
+ | },
+ | "c1"
+ | ]
+ | ]
+ |}
+ |""".stripMargin
+
+ `given`
+ .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+ .body(request)
+ .when
+ .post
+ .`then`
+ .log().ifValidationFails()
+ .statusCode(SC_OK)
+ .contentType(JSON)
+ .extract
+ .body
+ .asString
+
+ Assertions.assertThatCode(() => server.getProbe(classOf[MailboxProbeImpl])
+ .getMailboxId("#private", BOB.asString(), "parentMailbox.childMailbox")).doesNotThrowAnyException()
+ }
}
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetMethod.scala
index 86479c0..ead1c2a 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetMethod.scala
@@ -31,7 +31,7 @@ import org.apache.james.mailbox.model.{MailboxId, MailboxPath}
import org.apache.james.mailbox.{MailboxManager, MailboxSession}
import org.apache.james.metrics.api.MetricFactory
import org.reactivestreams.Publisher
-import play.api.libs.json.{JsError, JsObject, JsPath, JsSuccess, Json, JsonValidationError}
+import play.api.libs.json._
import reactor.core.scala.publisher.{SFlux, SMono}
import reactor.core.scheduler.Schedulers
@@ -79,14 +79,24 @@ class MailboxSetMethod @Inject() (serializer: Serializer,
SFlux.fromIterable(createRequests).flatMap {
case (mailboxCreationId: MailboxCreationId, mailboxCreationRequest: MailboxCreationRequest) => {
SMono.fromCallable(() => {
- val path = MailboxPath.forUser(mailboxSession.getUser, mailboxCreationRequest.name)
- //can safely do a get as the Optional is empty only if the mailbox name is empty which is forbidden by the type constraint on MailboxName
- (mailboxCreationId, mailboxManager.createMailbox(path, mailboxSession).get())
+ createMailbox(mailboxSession, mailboxCreationId, mailboxCreationRequest)
}).subscribeOn(Schedulers.elastic())
}
}.collectMap(_._1, _._2)
}
+ private def createMailbox(mailboxSession: MailboxSession, mailboxCreationId: MailboxCreationId, mailboxCreationRequest: MailboxCreationRequest) = {
+ val path:MailboxPath = if (mailboxCreationRequest.parentId.isEmpty) {
+ MailboxPath.forUser(mailboxSession.getUser, mailboxCreationRequest.name)
+ } else {
+ val parentId: MailboxId = mailboxCreationRequest.parentId.get
+ val parentPath: MailboxPath = mailboxManager.getMailbox(parentId, mailboxSession).getMailboxPath
+ parentPath.child(mailboxCreationRequest.name, mailboxSession.getPathDelimiter)
+ }
+ //can safely do a get as the Optional is empty only if the mailbox name is empty which is forbidden by the type constraint on MailboxName
+ (mailboxCreationId, mailboxManager.createMailbox(path, mailboxSession).get())
+ }
+
private def createResponse(invocation: Invocation, mailboxSetRequest: MailboxSetRequest, createErrors: immutable.Iterable[(MailboxCreationId, MailboxSetError)], created: Map[MailboxCreationId, MailboxId]): Invocation = {
Invocation(methodName, Arguments(serializer.serialize(MailboxSetResponse(
mailboxSetRequest.accountId,
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org