You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2021/04/02 10:21:17 UTC

[GitHub] [james-project] Arsnael commented on a change in pull request #356: JAMES-3434 Fix EmailSubmission/set onSuccessUpdateEmail property

Arsnael commented on a change in pull request #356:
URL: https://github.com/apache/james-project/pull/356#discussion_r606172533



##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSubmissionSetMethod.scala
##########
@@ -126,6 +129,29 @@ class EmailSubmissionSetMethod @Inject()(serializer: EmailSubmissionSetSerialize
         case _ => None
       }
       .toMap
+
+    def resolveMessageId(creationId: EmailSubmissionCreationId): Either[IllegalArgumentException, MessageId] = {
+      if (creationId.startsWith("#")) {
+        val realId = creationId.substring(1)
+        val validatedId: Either[String, EmailSubmissionCreationId] = refineV[IdConstraint](realId)
+        validatedId
+          .left.map(s => new IllegalArgumentException(s))

Review comment:
       I don't understand why you need that line?

##########
File path: server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailSubmissionSetMethodContract.scala
##########
@@ -1165,6 +1165,135 @@ trait EmailSubmissionSetMethodContract {
                    |}""".stripMargin)
   }
 
+
+  @Test
+  def test(server: GuiceJamesServer): Unit = {

Review comment:
       test?

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailSubmissionSet.scala
##########
@@ -63,6 +64,33 @@ case class EmailSubmissionSetRequest(accountId: AccountId,
         create = None,
         update = None,
         destroy = onSuccessDestroyEmail)))
+
+  def validate: Either[IllegalArgumentException, EmailSubmissionSetRequest] = {
+    val supportedCreationIds: List[EmailSubmissionCreationId] = create.getOrElse(Map()).keys.toList
+
+    onSuccessUpdateEmail.getOrElse(Map())
+      .keys
+      .toList
+      .map(id => validate(id, supportedCreationIds))
+      .sequence
+      .map(_ => this)
+  }
+
+  private def validate(creationId: EmailSubmissionCreationId, supportedCreationIds: List[EmailSubmissionCreationId]): Either[IllegalArgumentException, EmailSubmissionCreationId] = {
+    if (creationId.startsWith("#")) {
+      val realId = creationId.substring(1)
+      val validatedId: Either[String, EmailSubmissionCreationId] = refineV[IdConstraint](realId)
+      validatedId
+        .left.map(s => new IllegalArgumentException(s))

Review comment:
       is this line necessary?

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSubmissionSetMethod.scala
##########
@@ -185,12 +215,14 @@ class EmailSubmissionSetMethod @Inject()(serializer: EmailSubmissionSetSerialize
                             processingContext: ProcessingContext): (CreationResult, ProcessingContext) =
     parseCreate(jsObject)
       .flatMap(emailSubmissionCreationRequest => sendEmail(mailboxSession, emailSubmissionCreationRequest))
-      .flatMap(creationResponse => recordCreationIdInProcessingContext(emailSubmissionCreationId, processingContext, creationResponse.id)
-        .map(context => (creationResponse, context)))
+      .flatMap {
+        case (creationResponse, messageId) =>
+          recordCreationIdInProcessingContext(emailSubmissionCreationId, processingContext, creationResponse.id)
+            .map(context => (creationResponse, messageId, context))
+      }
       .fold(e => (CreationFailure(emailSubmissionCreationId, e), processingContext),
-        creationResponseWithUpdatedContext => {
-          (CreationSuccess(emailSubmissionCreationId, creationResponseWithUpdatedContext._1), creationResponseWithUpdatedContext._2)
-        })
+        creation =>
+          (CreationSuccess(emailSubmissionCreationId, creation._1, creation._2), creation._3))

Review comment:
       extra useless parenthesis?

##########
File path: server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailSubmissionSetMethodContract.scala
##########
@@ -1165,6 +1165,135 @@ trait EmailSubmissionSetMethodContract {
                    |}""".stripMargin)
   }
 
+
+  @Test
+  def test(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", "urn:ietf:params:jmap:submission"],
+         |  "methodCalls": [
+         |     ["EmailSubmission/set", {
+         |       "accountId": "$ACCOUNT_ID",
+         |       "create": {
+         |         "k1490": {
+         |           "emailId": "${messageId.serialize}",
+         |           "envelope": {
+         |             "mailFrom": {"email": "${BOB.asString}"},
+         |             "rcptTo": [{"email": "${ANDRE.asString}"}]
+         |           }
+         |         }
+         |       },
+         |       "onSuccessDestroyEmail": ["notFound"]
+         |   }, "c1"]]
+         |}""".stripMargin
+
+    val response = `given`
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(requestBob)
+    .when
+      .post.prettyPeek()
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response)
+      .isEqualTo(s"""{
+                    |    "sessionState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
+                    |    "methodResponses": [
+                    |        [
+                    |            "error",
+                    |            {
+                    |                "type": "invalidArguments",
+                    |                "description": "notFound cannot be retrieved as storage for EmailSubmission is not yet implemented"
+                    |            },
+                    |            "c1"
+                    |        ]
+                    |    ]
+                    |}""".stripMargin)
+  }
+
+  @Test
+  def test2(server: GuiceJamesServer): Unit = {

Review comment:
       test2?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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