You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2020/11/23 08:20:14 UTC

[james-project] 15/19: JAMES-3434 EmailSubmission/set should mandate urn:ietf:params:jmap:submission capability

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 1447aa8d6203410cdc492468d94604f39d0f801c
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Sun Nov 22 14:26:29 2020 +0700

    JAMES-3434 EmailSubmission/set should mandate urn:ietf:params:jmap:submission capability
---
 .../EmailSubmissionSetMethodContract.scala         | 107 ++++++++++++++++-----
 .../jmap/method/EmailSubmissionSetMethod.scala     |   4 +-
 2 files changed, 85 insertions(+), 26 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/EmailSubmissionSetMethodContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailSubmissionSetMethodContract.scala
index ae20bef..8c7fd45 100644
--- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailSubmissionSetMethodContract.scala
+++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailSubmissionSetMethodContract.scala
@@ -87,7 +87,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestBob =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [
          |     ["EmailSubmission/set", {
          |       "accountId": "$ACCOUNT_ID",
@@ -113,7 +113,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestAndre =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core","urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core","urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [[
          |    "Email/query",
          |    {
@@ -165,7 +165,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestBob =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [
          |     ["EmailSubmission/set", {
          |       "accountId": "$ACCOUNT_ID",
@@ -191,7 +191,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestReadMail =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core","urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core","urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [[
          |    "Email/query",
          |    {
@@ -243,7 +243,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestBob =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [
          |     ["EmailSubmission/set", {
          |       "accountId": "$ACCOUNT_ID",
@@ -269,7 +269,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestReadMail =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core","urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core","urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [[
          |    "Email/query",
          |    {
@@ -321,7 +321,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestBob =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [
          |     ["EmailSubmission/set", {
          |       "accountId": "$ACCOUNT_ID",
@@ -347,7 +347,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestReadMail =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core","urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core","urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [[
          |    "Email/query",
          |    {
@@ -399,7 +399,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestBob =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [
          |     ["EmailSubmission/set", {
          |       "accountId": "$ACCOUNT_ID",
@@ -425,7 +425,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestReadMail =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core","urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core","urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [[
          |    "Email/query",
          |    {
@@ -478,7 +478,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestBob =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [
          |     ["EmailSubmission/set", {
          |       "accountId": "$ACCOUNT_ID",
@@ -571,7 +571,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestBob =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [
          |    ["Email/set", {
          |      "accountId": "$ACCOUNT_ID",
@@ -656,7 +656,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestBob =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [
          |     ["EmailSubmission/set", {
          |       "accountId": "$ACCOUNT_ID",
@@ -710,7 +710,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestBob =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [
          |     ["EmailSubmission/set", {
          |       "accountId": "$ACCOUNT_ID",
@@ -816,7 +816,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestBob =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [
          |     ["EmailSubmission/set", {
          |       "accountId": "$ACCOUNT_ID",
@@ -911,7 +911,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestBob =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [
          |     ["EmailSubmission/set", {
          |       "accountId": "$ANDRE_ACCOUNT_ID",
@@ -949,7 +949,22 @@ trait EmailSubmissionSetMethodContract {
   }
 
   @Test
-  def setShouldRejectMessageNotFound(): Unit = {
+  def setShouldRejectMissingCapability(server: GuiceJamesServer): Unit = {
+    val message: Message = Message.Builder
+      .of
+      .setSubject("test")
+      .setSender(BOB.asString)
+      .setFrom(BOB.asString)
+      .setTo(ANDRE.asString)
+      .setBody("testmail", StandardCharsets.UTF_8)
+      .build
+
+    val bobDraftsPath = MailboxPath.forUser(BOB, DefaultMailboxes.DRAFTS)
+    server.getProbe(classOf[MailboxProbeImpl]).createMailbox(bobDraftsPath)
+    val messageId: MessageId = server.getProbe(classOf[MailboxProbeImpl]).appendMessage(BOB.asString(), bobDraftsPath, AppendCommand.builder()
+      .build(message))
+      .getMessageId
+
     val requestBob =
       s"""{
          |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
@@ -958,6 +973,50 @@ trait EmailSubmissionSetMethodContract {
          |       "accountId": "$ACCOUNT_ID",
          |       "create": {
          |         "k1490": {
+         |           "emailId": "${messageId.serialize}",
+         |           "envelope": {
+         |             "mailFrom": {"email": "${BOB.asString}"},
+         |             "rcptTo": [{"email": "${ANDRE.asString}"}]
+         |           }
+         |         }
+         |    }
+         |  }, "c1"]]
+         |}""".stripMargin
+
+    val response = `given`
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(requestBob)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response)
+      .inPath("methodResponses[0]")
+      .isEqualTo("""[
+                   |  "error",
+                   |  {
+                   |    "type": "unknownMethod",
+                   |    "description": "Missing capability(ies): urn:ietf:params:jmap:submission"
+                   |  },
+                   |  "c1"
+                   |]""".stripMargin)
+  }
+
+  @Test
+  def setShouldRejectMessageNotFound(): Unit = {
+    val requestBob =
+      s"""{
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
+         |  "methodCalls": [
+         |     ["EmailSubmission/set", {
+         |       "accountId": "$ACCOUNT_ID",
+         |       "create": {
+         |         "k1490": {
          |           "emailId": "${randomMessageId.serialize}",
          |           "envelope": {
          |             "mailFrom": {"email": "${BOB.asString}"},
@@ -995,7 +1054,7 @@ trait EmailSubmissionSetMethodContract {
   def setShouldRejectExtraProperties(): Unit = {
     val requestBob =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [
          |     ["EmailSubmission/set", {
          |       "accountId": "$ACCOUNT_ID",
@@ -1054,7 +1113,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestBob =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [
          |     ["EmailSubmission/set", {
          |       "accountId": "$ACCOUNT_ID",
@@ -1115,7 +1174,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestBob =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [
          |     ["EmailSubmission/set", {
          |       "accountId": "$ACCOUNT_ID",
@@ -1190,7 +1249,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestBob =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [
          |     ["EmailSubmission/set", {
          |       "accountId": "$ACCOUNT_ID",
@@ -1247,7 +1306,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestBob =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [
          |     ["EmailSubmission/set", {
          |       "accountId": "$ACCOUNT_ID",
@@ -1304,7 +1363,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestBob =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [
          |     ["EmailSubmission/set", {
          |       "accountId": "$ACCOUNT_ID",
@@ -1362,7 +1421,7 @@ trait EmailSubmissionSetMethodContract {
 
     val requestBob =
       s"""{
-         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
          |  "methodCalls": [
          |     ["EmailSubmission/set", {
          |       "accountId": "$ACCOUNT_ID",
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSubmissionSetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSubmissionSetMethod.scala
index 905d1c9..a2bd639 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSubmissionSetMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSubmissionSetMethod.scala
@@ -26,7 +26,7 @@ import javax.annotation.PreDestroy
 import javax.inject.Inject
 import javax.mail.internet.{InternetAddress, MimeMessage}
 import org.apache.james.core.{MailAddress, Username}
-import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JMAP_CORE, JMAP_MAIL}
+import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, EMAIL_SUBMISSION, JMAP_CORE, JMAP_MAIL}
 import org.apache.james.jmap.core.Invocation.{Arguments, MethodName}
 import org.apache.james.jmap.core.SetError.{SetErrorDescription, SetErrorType}
 import org.apache.james.jmap.core.{ClientId, Id, Invocation, Properties, ServerId, SetError, State}
@@ -74,7 +74,7 @@ class EmailSubmissionSetMethod @Inject()(serializer: EmailSubmissionSetSerialize
                                          val metricFactory: MetricFactory,
                                          val sessionSupplier: SessionSupplier) extends MethodRequiringAccountId[EmailSubmissionSetRequest] with Startable {
   override val methodName: MethodName = MethodName("EmailSubmission/set")
-  override val requiredCapabilities: Set[CapabilityIdentifier] = Set(JMAP_CORE, JMAP_MAIL)
+  override val requiredCapabilities: Set[CapabilityIdentifier] = Set(JMAP_CORE, JMAP_MAIL, EMAIL_SUBMISSION)
   var queue: MailQueue = _
 
   sealed trait CreationResult {


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org