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


The following commit(s) were added to refs/heads/master by this push:
     new cb3355a  JAMES-3659 Modularize Namespace of mailbox share extension 
(#680)
cb3355a is described below

commit cb3355ae1fc5d0d81458f776f5d6a3733bd27ed6
Author: vttran <[email protected]>
AuthorDate: Tue Oct 5 10:37:11 2021 +0700

    JAMES-3659 Modularize Namespace of mailbox share extension (#680)
---
 .../james/jmap/rfc8621/RFC8621MethodsModule.java   |   3 +
 .../DistributedCustomNamespaceTest.java            |  56 +++++++
 .../rfc8621/contract/CustomNamespaceContract.scala | 183 +++++++++++++++++++++
 .../rfc8621/memory/MemoryCustomNamespaceTest.java  |  37 +++++
 .../apache/james/jmap/json/MailboxSerializer.scala |   8 +-
 .../scala/org/apache/james/jmap/mail/Mailbox.scala |  12 --
 .../apache/james/jmap/mail/MailboxFactory.scala    |   9 +-
 .../apache/james/jmap/mail/MailboxNamespace.scala  |  57 +++++++
 8 files changed, 342 insertions(+), 23 deletions(-)

diff --git 
a/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/rfc8621/RFC8621MethodsModule.java
 
b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/rfc8621/RFC8621MethodsModule.java
index 8210a95..e2ce681 100644
--- 
a/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/rfc8621/RFC8621MethodsModule.java
+++ 
b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/rfc8621/RFC8621MethodsModule.java
@@ -43,6 +43,8 @@ import org.apache.james.jmap.http.Authenticator;
 import org.apache.james.jmap.http.BasicAuthenticationStrategy;
 import org.apache.james.jmap.http.rfc8621.InjectionKeys;
 import org.apache.james.jmap.jwt.JWTAuthenticationStrategy;
+import org.apache.james.jmap.mail.DefaultNamespaceFactory;
+import org.apache.james.jmap.mail.NamespaceFactory;
 import org.apache.james.jmap.method.CoreEchoMethod;
 import org.apache.james.jmap.method.EmailChangesMethod;
 import org.apache.james.jmap.method.EmailGetMethod;
@@ -95,6 +97,7 @@ public class RFC8621MethodsModule extends AbstractModule {
 
     @Override
     protected void configure() {
+        bind(NamespaceFactory.class).to(DefaultNamespaceFactory.class);
         bind(ZoneIdProvider.class).to(SystemZoneIdProvider.class);
 
         bind(EmailSubmissionSetMethod.class).in(Scopes.SINGLETON);
diff --git 
a/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedCustomNamespaceTest.java
 
b/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedCustomNamespaceTest.java
new file mode 100644
index 0000000..435a2f5
--- /dev/null
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedCustomNamespaceTest.java
@@ -0,0 +1,56 @@
+/****************************************************************
+ * 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.rfc8621.distributed;
+
+import org.apache.james.CassandraExtension;
+import org.apache.james.CassandraRabbitMQJamesConfiguration;
+import org.apache.james.CassandraRabbitMQJamesServerMain;
+import org.apache.james.DockerElasticSearchExtension;
+import org.apache.james.JamesServerBuilder;
+import org.apache.james.JamesServerExtension;
+import org.apache.james.jmap.rfc8621.contract.CustomNamespaceContract;
+import org.apache.james.jmap.rfc8621.contract.CustomNamespaceModule;
+import org.apache.james.modules.AwsS3BlobStoreExtension;
+import org.apache.james.modules.RabbitMQExtension;
+import org.apache.james.modules.TestJMAPServerModule;
+import org.apache.james.modules.blobstore.BlobStoreConfiguration;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+public class DistributedCustomNamespaceTest implements CustomNamespaceContract 
{
+    @RegisterExtension
+    static JamesServerExtension testExtension = new 
JamesServerBuilder<CassandraRabbitMQJamesConfiguration>(tmpDir ->
+        CassandraRabbitMQJamesConfiguration.builder()
+            .workingDirectory(tmpDir)
+            .configurationFromClasspath()
+            .blobStore(BlobStoreConfiguration.builder()
+                .s3()
+                .disableCache()
+                .deduplication()
+                .noCryptoConfig())
+            .build())
+        .extension(new DockerElasticSearchExtension())
+        .extension(new CassandraExtension())
+        .extension(new RabbitMQExtension())
+        .extension(new AwsS3BlobStoreExtension())
+        .server(configuration -> 
CassandraRabbitMQJamesServerMain.createServer(configuration)
+            .overrideWith(new TestJMAPServerModule())
+            .overrideWith(new CustomNamespaceModule()))
+        .build();
+}
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/CustomNamespaceContract.scala
 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/CustomNamespaceContract.scala
new file mode 100644
index 0000000..5d3321c
--- /dev/null
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/CustomNamespaceContract.scala
@@ -0,0 +1,183 @@
+/****************************************************************
+ * 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.rfc8621.contract
+
+import com.google.inject.AbstractModule
+import io.netty.handler.codec.http.HttpHeaderNames.ACCEPT
+import io.restassured.RestAssured._
+import io.restassured.http.ContentType.JSON
+import org.apache.http.HttpStatus.SC_OK
+import org.apache.james.GuiceJamesServer
+import org.apache.james.jmap.http.UserCredential
+import org.apache.james.jmap.mail.{DelegatedNamespace, MailboxNamespace, 
NamespaceFactory, PersonalNamespace}
+import 
org.apache.james.jmap.rfc8621.contract.CustomNamespaceContract.{CUSTOM_NAMESPACE_MAILBOX_PATH,
 DELEGATED_NAMESPACE_MAILBOX_PATH, PERSONAL_NAMESPACE_MAILBOX_PATH}
+import 
org.apache.james.jmap.rfc8621.contract.Fixture.{ACCEPT_RFC8621_VERSION_HEADER, 
ACCOUNT_ID, BOB, BOB_PASSWORD, DOMAIN, authScheme, baseRequestSpecBuilder}
+import org.apache.james.mailbox.MailboxSession
+import org.apache.james.mailbox.model.MailboxPath
+import org.apache.james.modules.MailboxProbeImpl
+import org.apache.james.utils.DataProbeImpl
+import org.assertj.core.api.Assertions.assertThat
+import org.junit.jupiter.api.{BeforeEach, Test}
+
+import javax.inject.Inject
+
+case class CustomMailboxNamespace(value: String) extends MailboxNamespace {
+  override def serialize(): String = value
+}
+
+class CustomNamespaceModule extends AbstractModule {
+  override def configure(): Unit =
+    bind(classOf[NamespaceFactory]).to(classOf[CustomNamespaceFactory])
+}
+
+class CustomNamespaceFactory extends NamespaceFactory {
+
+  def from(mailboxPath: MailboxPath, mailboxSession: MailboxSession): 
MailboxNamespace = mailboxPath match {
+    case PERSONAL_NAMESPACE_MAILBOX_PATH => PersonalNamespace()
+    case DELEGATED_NAMESPACE_MAILBOX_PATH => 
DelegatedNamespace(mailboxSession.getUser)
+    case CUSTOM_NAMESPACE_MAILBOX_PATH => CustomMailboxNamespace("custom 123")
+  }
+}
+
+object CustomNamespaceContract {
+  val CUSTOM_NAMESPACE_MAILBOX_PATH: MailboxPath = MailboxPath.forUser(BOB, 
"custom")
+  val PERSONAL_NAMESPACE_MAILBOX_PATH: MailboxPath = MailboxPath.forUser(BOB, 
"personal")
+  val DELEGATED_NAMESPACE_MAILBOX_PATH: MailboxPath = MailboxPath.forUser(BOB, 
"delegated")
+}
+
+trait CustomNamespaceContract {
+
+  @BeforeEach
+  def setUp(server: GuiceJamesServer): Unit = {
+    server.getProbe(classOf[DataProbeImpl])
+      .fluent
+      .addDomain(DOMAIN.asString)
+      .addUser(BOB.asString, BOB_PASSWORD)
+
+    requestSpecification = baseRequestSpecBuilder(server)
+      .setAuth(authScheme(UserCredential(BOB, BOB_PASSWORD)))
+      .build
+  }
+
+  @Test
+  def getMailboxShouldIncludeCustomNamespaceWhenAssociated(server: 
GuiceJamesServer): Unit = {
+    val mailboxId: String = server.getProbe(classOf[MailboxProbeImpl])
+      .createMailbox(CUSTOM_NAMESPACE_MAILBOX_PATH)
+      .serialize
+
+    val namespace: String = `given`()
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(
+        s"""{
+           |  "using": [
+           |    "urn:ietf:params:jmap:core",
+           |    "urn:ietf:params:jmap:mail",
+           |    "urn:apache:james:params:jmap:mail:shares"],
+           |  "methodCalls": [[
+           |    "Mailbox/get",
+           |    {
+           |      "accountId": "$ACCOUNT_ID",
+           |      "ids": ["${mailboxId}"]
+           |    },
+           |    "c1"]]
+           |}""".stripMargin)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract()
+      .jsonPath()
+      .get("methodResponses[0][1].list[0].namespace")
+
+    assertThat(namespace)
+      .isEqualTo("custom 123")
+  }
+
+  @Test
+  def getMailboxShouldIncludePersonalNamespaceWhenAssociated(server: 
GuiceJamesServer): Unit = {
+    val mailboxId: String = server.getProbe(classOf[MailboxProbeImpl])
+      .createMailbox(PERSONAL_NAMESPACE_MAILBOX_PATH)
+      .serialize
+
+    val namespace: String = `given`()
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(
+        s"""{
+           |  "using": [
+           |    "urn:ietf:params:jmap:core",
+           |    "urn:ietf:params:jmap:mail",
+           |    "urn:apache:james:params:jmap:mail:shares"],
+           |  "methodCalls": [[
+           |    "Mailbox/get",
+           |    {
+           |      "accountId": "$ACCOUNT_ID",
+           |      "ids": ["${mailboxId}"]
+           |    },
+           |    "c1"]]
+           |}""".stripMargin)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract()
+      .jsonPath()
+      .get("methodResponses[0][1].list[0].namespace")
+
+    assertThat(namespace)
+      .isEqualTo("Personal")
+  }
+
+  @Test
+  def getMailboxShouldIncludeDelegatedNamespaceWhenAssociated(server: 
GuiceJamesServer): Unit = {
+    val mailboxId: String = server.getProbe(classOf[MailboxProbeImpl])
+      .createMailbox(DELEGATED_NAMESPACE_MAILBOX_PATH)
+      .serialize
+
+    val namespace: String = `given`()
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(
+        s"""{
+           |  "using": [
+           |    "urn:ietf:params:jmap:core",
+           |    "urn:ietf:params:jmap:mail",
+           |    "urn:apache:james:params:jmap:mail:shares"],
+           |  "methodCalls": [[
+           |    "Mailbox/get",
+           |    {
+           |      "accountId": "$ACCOUNT_ID",
+           |      "ids": ["${mailboxId}"]
+           |    },
+           |    "c1"]]
+           |}""".stripMargin)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract()
+      .jsonPath()
+      .get("methodResponses[0][1].list[0].namespace")
+
+    assertThat(namespace)
+      .isEqualTo("Delegated[[email protected]]")
+  }
+}
diff --git 
a/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryCustomNamespaceTest.java
 
b/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryCustomNamespaceTest.java
new file mode 100644
index 0000000..c8556bd
--- /dev/null
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryCustomNamespaceTest.java
@@ -0,0 +1,37 @@
+/****************************************************************
+ * 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.rfc8621.memory;
+
+import org.apache.james.JamesServerBuilder;
+import org.apache.james.JamesServerExtension;
+import org.apache.james.MemoryJamesServerMain;
+import org.apache.james.jmap.rfc8621.contract.CustomNamespaceContract;
+import org.apache.james.jmap.rfc8621.contract.CustomNamespaceModule;
+import org.apache.james.modules.TestJMAPServerModule;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+public class MemoryCustomNamespaceTest implements CustomNamespaceContract {
+    @RegisterExtension
+    static JamesServerExtension testExtension = new 
JamesServerBuilder<>(JamesServerBuilder.defaultConfigurationProvider())
+        .server(configuration -> 
MemoryJamesServerMain.createServer(configuration)
+            .overrideWith(new CustomNamespaceModule())
+            .overrideWith(new TestJMAPServerModule()))
+        .build();
+}
diff --git 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/MailboxSerializer.scala
 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/MailboxSerializer.scala
index cc4c94e..c5c4e51 100644
--- 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/MailboxSerializer.scala
+++ 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/MailboxSerializer.scala
@@ -26,7 +26,7 @@ import org.apache.james.core.{Domain, Username}
 import org.apache.james.jmap.core.CapabilityIdentifier.CapabilityIdentifier
 import org.apache.james.jmap.core.Id.IdConstraint
 import org.apache.james.jmap.core.{ClientId, Properties, SetError, UuidState}
-import org.apache.james.jmap.mail.{DelegatedNamespace, Ids, IsSubscribed, 
Mailbox, MailboxChangesRequest, MailboxChangesResponse, MailboxCreationId, 
MailboxCreationRequest, MailboxCreationResponse, MailboxGetRequest, 
MailboxGetResponse, MailboxNamespace, MailboxPatchObject, MailboxRights, 
MailboxSetRequest, MailboxSetResponse, MailboxUpdateResponse, MayAddItems, 
MayCreateChild, MayDelete, MayReadItems, MayRemoveItems, MayRename, 
MaySetKeywords, MaySetSeen, MaySubmit, NotFound, PersonalNa [...]
+import org.apache.james.jmap.mail.{Ids, IsSubscribed, Mailbox, 
MailboxChangesRequest, MailboxChangesResponse, MailboxCreationId, 
MailboxCreationRequest, MailboxCreationResponse, MailboxGetRequest, 
MailboxGetResponse, MailboxNamespace, MailboxPatchObject, MailboxRights, 
MailboxSetRequest, MailboxSetResponse, MailboxUpdateResponse, MayAddItems, 
MayCreateChild, MayDelete, MayReadItems, MayRemoveItems, MayRename, 
MaySetKeywords, MaySetSeen, MaySubmit, NotFound, PersonalNamespace, Quota, Quot 
[...]
 import org.apache.james.mailbox.Role
 import org.apache.james.mailbox.model.MailboxACL.{Right => JavaRight}
 import org.apache.james.mailbox.model.{MailboxACL, MailboxId}
@@ -70,10 +70,7 @@ class MailboxSerializer @Inject()(mailboxIdFactory: 
MailboxId.Factory) {
   private implicit val maySubmitWrites: Writes[MaySubmit] = 
Json.valueWrites[MaySubmit]
   private implicit val mailboxRightsWrites: Writes[MailboxRights] = 
Json.writes[MailboxRights]
 
-  private implicit val mailboxNamespaceWrites: Writes[MailboxNamespace] = {
-    case _: PersonalNamespace => JsString("Personal")
-    case delegated: DelegatedNamespace => 
JsString(s"Delegated[${delegated.owner.asString}]")
-  }
+  private implicit val mailboxNamespaceWrites: Writes[MailboxNamespace] = 
value => JsString(value.serialize())
 
   private implicit val mailboxACLWrites: Writes[MailboxACL.Right] = right => 
JsString(right.asCharacter.toString)
 
@@ -144,7 +141,6 @@ class MailboxSerializer @Inject()(mailboxIdFactory: 
MailboxId.Factory) {
   private implicit val stateWrites: Writes[UuidState] = 
Json.valueWrites[UuidState]
   private implicit val mailboxGetResponseWrites: Writes[MailboxGetResponse] = 
Json.writes[MailboxGetResponse]
 
-
   private implicit val mailboxSetUpdateResponseWrites: 
Writes[MailboxUpdateResponse] = Json.valueWrites[MailboxUpdateResponse]
 
   private implicit val mailboxMapSetErrorForCreationWrites: 
Writes[Map[MailboxCreationId, SetError]] =
diff --git 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Mailbox.scala
 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Mailbox.scala
index 0e503de..be3656b 100644
--- 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Mailbox.scala
+++ 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Mailbox.scala
@@ -66,18 +66,6 @@ case class MailboxRights(mayReadItems: MayReadItems,
                          mayDelete: MayDelete,
                          maySubmit: MaySubmit)
 
-object MailboxNamespace {
-  def delegated(owner: Username) = DelegatedNamespace(owner)
-
-  def personal = PersonalNamespace
-}
-
-sealed trait MailboxNamespace
-
-case class PersonalNamespace() extends MailboxNamespace
-
-case class DelegatedNamespace(owner: Username) extends MailboxNamespace
-
 object SortOrder {
   val defaultSortOrder: SortOrder = SortOrder(1000L)
 
diff --git 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxFactory.scala
 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxFactory.scala
index b235082..03bcfd0 100644
--- 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxFactory.scala
+++ 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxFactory.scala
@@ -75,7 +75,8 @@ case class Subscriptions(subscribedNames: Set[String]) {
   def isSubscribed(metaData: MailboxMetaData): IsSubscribed = 
isSubscribed(metaData.getPath.getName)
 }
 
-class MailboxFactory @Inject() (mailboxManager: MailboxManager) {
+class MailboxFactory @Inject() (mailboxManager: MailboxManager,
+                                namespaceFactory: NamespaceFactory) {
 
   private def getRole(mailboxPath: MailboxPath, mailboxSession: 
MailboxSession): Option[Role] = Role.from(mailboxPath.getName)
     .filter(_ => mailboxPath.belongsTo(mailboxSession)).toScala
@@ -84,10 +85,8 @@ class MailboxFactory @Inject() (mailboxManager: 
MailboxManager) {
 
   private def getRights(resolveMailboxACL: JavaMailboxACL): Rights = 
Rights.fromACL(MailboxACL.fromJava(resolveMailboxACL))
 
-  private def getNamespace(mailboxPath: MailboxPath, mailboxSession: 
MailboxSession): MailboxNamespace = mailboxPath.belongsTo(mailboxSession) match 
{
-    case true => PersonalNamespace()
-    case false => DelegatedNamespace(mailboxPath.getUser)
-  }
+  private def getNamespace(mailboxPath: MailboxPath, mailboxSession: 
MailboxSession): MailboxNamespace =
+    namespaceFactory.from(mailboxPath, mailboxSession)
 
   private def getParentPath(mailboxPath: MailboxPath, mailboxSession: 
MailboxSession): Option[MailboxPath] = mailboxPath
     .getHierarchyLevels(mailboxSession.getPathDelimiter)
diff --git 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxNamespace.scala
 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxNamespace.scala
new file mode 100644
index 0000000..d3df57b
--- /dev/null
+++ 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxNamespace.scala
@@ -0,0 +1,57 @@
+/** **************************************************************
+ * 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.mail
+
+import org.apache.james.core.Username
+import org.apache.james.mailbox.MailboxSession
+import org.apache.james.mailbox.model.MailboxPath
+
+import javax.inject.Inject
+
+trait NamespaceFactory {
+  def from(mailboxPath: MailboxPath, mailboxSession: MailboxSession): 
MailboxNamespace
+}
+
+class DefaultNamespaceFactory extends NamespaceFactory {
+
+  def from(mailboxPath: MailboxPath, mailboxSession: MailboxSession): 
MailboxNamespace =
+    mailboxPath.belongsTo(mailboxSession) match {
+      case true => PersonalNamespace()
+      case false => DelegatedNamespace(mailboxPath.getUser)
+    }
+}
+
+object MailboxNamespace {
+  def delegated(owner: Username): DelegatedNamespace = 
DelegatedNamespace(owner)
+
+  def personal(): PersonalNamespace = PersonalNamespace()
+}
+
+trait MailboxNamespace {
+  def serialize(): String
+}
+
+case class PersonalNamespace() extends MailboxNamespace {
+  override def serialize(): String = "Personal"
+}
+
+case class DelegatedNamespace(owner: Username) extends MailboxNamespace {
+  override def serialize(): String = s"Delegated[${owner.asString}]"
+}
\ No newline at end of file

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to