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 c979cfdd4248cc603f776c436f91a9f6370d35bf Author: duc91 <[email protected]> AuthorDate: Wed Aug 12 16:48:11 2020 +0700 JAMES-3354: handle MailboxExistsException --- .../contract/MailboxSetMethodContract.scala | 57 ++++++++++++++++++++++ .../james/jmap/method/MailboxSetMethod.scala | 3 +- 2 files changed, 59 insertions(+), 1 deletion(-) 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 8fe321b..e372cde 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 @@ -493,4 +493,61 @@ trait MailboxSetMethodContract { | "c1"]] |}""".stripMargin) } + + @Test + def mailboxSetShouldNotCreateMailboxWhenNameExists(server: GuiceJamesServer): Unit = { + server.getProbe(classOf[MailboxProbeImpl]).createMailbox(MailboxPath.forUser(BOB, "mailbox")) + val request= + s""" + |{ + | "using": [ "urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail" ], + | "methodCalls": [ + | [ + | "Mailbox/set", + | { + | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", + | "create": { + | "C42": { + | "name": "mailbox" + | } + | } + | }, + | "c1" + | ] + | ] + |} + |""".stripMargin + + val response = `given` + .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER) + .body(request) + .when + .post + .`then` + .log().ifValidationFails() + .statusCode(SC_OK) + .contentType(JSON) + .extract + .body + .asString + + assertThatJson(response).isEqualTo( + s"""{ + | "sessionState": "75128aab4b1b", + | "methodResponses": [[ + | "Mailbox/set", + | { + | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", + | "newState": "000001", + | "notCreated": { + | "C42": { + | "type": "invalidArguments", + | "description": "Mailbox with name=#private:[email protected]:mailbox already exists.", + | "properties":{"value":["name"]} + | } + | } + | }, + | "c1"]] + |}""".stripMargin) + } } 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 2f2ee59..91dfcf4 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 @@ -27,7 +27,7 @@ import org.apache.james.jmap.mail.{IsSubscribed, MailboxCreationRequest, Mailbox import org.apache.james.jmap.model.CapabilityIdentifier.CapabilityIdentifier import org.apache.james.jmap.model.Invocation.{Arguments, MethodName} import org.apache.james.jmap.model.{Invocation, State} -import org.apache.james.mailbox.exception.MailboxNotFoundException +import org.apache.james.mailbox.exception.{MailboxExistsException, MailboxNotFoundException} import org.apache.james.mailbox.model.{MailboxId, MailboxPath} import org.apache.james.mailbox.{MailboxManager, MailboxSession} import org.apache.james.metrics.api.MetricFactory @@ -46,6 +46,7 @@ case class CreationSuccess(mailboxCreationId: MailboxCreationId, mailboxId: Mail case class CreationFailure(mailboxCreationId: MailboxCreationId, exception: Exception) extends CreationResult { def asMailboxSetError: MailboxSetError = exception match { case e: MailboxNotFoundException => MailboxSetError.invalidArgument(Some(SetErrorDescription(e.getMessage)), Some(Properties(List("parentId")))) + case e: MailboxExistsException => MailboxSetError.invalidArgument(Some(SetErrorDescription(e.getMessage)), Some(Properties(List("name")))) case _ => MailboxSetError.serverFail(Some(SetErrorDescription(exception.getMessage)), None) } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
