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 05:03:26 UTC

[GitHub] [james-project] chibenwa opened a new pull request #356: JAMES-3434 Fix EmailSubmission/set onSuccessUpdateEmail property

chibenwa opened a new pull request #356:
URL: https://github.com/apache/james-project/pull/356


   Re-reading https://jmap.io/spec-mail.html#emailsubmissionset
   
   ```
   onSuccessUpdateEmail: Id[PatchObject]|null A map of EmailSubmission id
   to an object containing properties to update on the Email object
   referenced by the EmailSubmission if the create/update/destroy
   succeeds. (For references to EmailSubmissions created in the same
   “/set” invocation, this is equivalent to a creation-reference, so the
   id will be the creation id prefixed with a #.)
   ```
   
   We are currently using a message id, not an EmailSubmission id...
   
   CF a bug report opened on the Linagora fork: https://github.com/linagora/james-project/issues/4310 


-- 
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


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

Posted by GitBox <gi...@apache.org>.
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


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

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #356:
URL: https://github.com/apache/james-project/pull/356#discussion_r606189507



##########
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:
       idem




-- 
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


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

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #356:
URL: https://github.com/apache/james-project/pull/356#discussion_r606189725



##########
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:
       No, it is required to have a Tuple2. The syntax is `(a, b)`




-- 
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


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

Posted by GitBox <gi...@apache.org>.
jeantil commented on a change in pull request #356:
URL: https://github.com/apache/james-project/pull/356#discussion_r606658720



##########
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:
       alternative syntax for tuple2 `a -> b`




-- 
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


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

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #356:
URL: https://github.com/apache/james-project/pull/356#discussion_r606189466



##########
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:
       Yes, as we need to transform `Either[String, X]` into `Either[IllegalArgumentException, X]`




-- 
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


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

Posted by GitBox <gi...@apache.org>.
jeantil commented on a change in pull request #356:
URL: https://github.com/apache/james-project/pull/356#discussion_r606658720



##########
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:
       alternative syntax for tuple2 `a->b`




-- 
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


[GitHub] [james-project] chibenwa merged pull request #356: JAMES-3434 Fix EmailSubmission/set onSuccessUpdateEmail property

Posted by GitBox <gi...@apache.org>.
chibenwa merged pull request #356:
URL: https://github.com/apache/james-project/pull/356


   


-- 
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


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

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #356:
URL: https://github.com/apache/james-project/pull/356#discussion_r606674733



##########
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:
       Thanks for the tip!




-- 
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


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

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #356:
URL: https://github.com/apache/james-project/pull/356#discussion_r606675085



##########
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:
       Only Tuple2 right?




-- 
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