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/24 02:22:35 UTC
[james-project] 06/13: JAMES-3357 Mailbox/set creation should not
return isSubscribed when specified
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 f825b20e0890883fd2b6b966eb65214ac120582d
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Aug 20 09:15:03 2020 +0700
JAMES-3357 Mailbox/set creation should not return isSubscribed when specified
---
.../contract/MailboxSetMethodContract.scala | 75 ++++++++++++++++++++++
.../org/apache/james/jmap/mail/MailboxSet.scala | 4 +-
.../james/jmap/method/MailboxSetMethod.scala | 9 ++-
3 files changed, 84 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 b1d70b0..365cf35 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
@@ -311,6 +311,80 @@ trait MailboxSetMethodContract {
}
@Test
+ def createSHouldNotReturnSubscribeWhenSpecified(server: GuiceJamesServer): Unit = {
+ val request =
+ """
+ |{
+ | "using": [ "urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail" ],
+ | "methodCalls": [
+ | [
+ | "Mailbox/set",
+ | {
+ | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+ | "create": {
+ | "C42": {
+ | "name": "myMailbox",
+ | "isSubscribed": true
+ | }
+ | }
+ | },
+ | "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
+
+ val mailboxId: String = server.getProbe(classOf[MailboxProbeImpl])
+ .getMailboxId("#private", BOB.asString(), "myMailbox")
+ .serialize()
+
+ assertThatJson(response).isEqualTo(
+ s"""{
+ | "sessionState": "75128aab4b1b",
+ | "methodResponses": [
+ | ["Mailbox/set", {
+ | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+ | "newState": "000001",
+ | "created": {
+ | "C42": {
+ | "id": "${mailboxId}",
+ | "sortOrder":1000,
+ | "totalEmails": 0,
+ | "unreadEmails": 0,
+ | "totalThreads": 0,
+ | "unreadThreads": 0,
+ | "myRights": {
+ | "mayReadItems": true,
+ | "mayAddItems": true,
+ | "mayRemoveItems": true,
+ | "maySetSeen": true,
+ | "maySetKeywords": true,
+ | "mayCreateChild": true,
+ | "mayRename": true,
+ | "mayDelete": true,
+ | "maySubmit": true
+ | }
+ | }
+ | }
+ | }, "c1"]
+ | ]
+ |}""".stripMargin)
+ }
+
+ @Test
def mailboxSetShouldNotSubscribeMailboxWhenRequired(server: GuiceJamesServer): Unit = {
val request =
"""
@@ -961,6 +1035,7 @@ trait MailboxSetMethodContract {
| "created": {
| "C42": {
| "id": "$mailboxId",
+ | "sortOrder":1000,
| "isSubscribed":true,
| "myRights":{"mayAddItems":true,"mayCreateChild":true,"mayDelete":true,"mayReadItems":true,"mayRemoveItems":true,"mayRename":true,"maySetKeywords":true,"maySetSeen":true,"maySubmit":true},
| "totalEmails":0,
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala
index 4ae37ae..311182d 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala
@@ -112,7 +112,7 @@ case class MailboxSetError(`type`: SetErrorType, description: Option[SetErrorDes
object MailboxCreationResponse {
- def allProperties: Set[String] = Set("id", "role", "totalEmails", "unreadEmails",
+ def allProperties: Set[String] = Set("id", "sortOrder", "role", "totalEmails", "unreadEmails",
"totalThreads", "unreadThreads", "myRights", "isSubscribed", "quotas")
def propertiesFiltered(allowedCapabilities : Set[CapabilityIdentifier]) : Set[String] = {
@@ -136,7 +136,7 @@ case class MailboxCreationResponse(id: MailboxId,
unreadThreads: UnreadThreads,
myRights: MailboxRights,
quotas: Option[Quotas],
- isSubscribed: IsSubscribed)
+ isSubscribed: Option[IsSubscribed])
object MailboxSetResponse {
def empty: MailboxUpdateResponse = MailboxUpdateResponse(JsObject(Map[String, JsValue]()))
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 fd76d3d..90937ee 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
@@ -331,7 +331,8 @@ class MailboxSetMethod @Inject()(serializer: Serializer,
//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
val mailboxId = mailboxManager.createMailbox(path, mailboxSession).get()
- if (mailboxCreationRequest.isSubscribed.getOrElse(IsSubscribed(true)).value) {
+ val defaultSubscribed = IsSubscribed(true)
+ if (mailboxCreationRequest.isSubscribed.getOrElse(defaultSubscribed).value) {
subscriptionManager.subscribe(mailboxSession, path.getName)
}
@@ -352,7 +353,11 @@ class MailboxSetMethod @Inject()(serializer: Serializer,
unreadThreads = UnreadThreads(0L),
myRights = MailboxRights.FULL,
quotas = Some(quotas),
- isSubscribed = IsSubscribed(true)))
+ isSubscribed = if (mailboxCreationRequest.isSubscribed.isEmpty) {
+ Some(defaultSubscribed)
+ } else {
+ None
+ }))
} catch {
case error: Exception => Left(error)
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org