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/12 09:05:23 UTC

[GitHub] [james-project] chibenwa commented on a change in pull request #385: [WIP] JAMES-3520 MDN/send

chibenwa commented on a change in pull request #385:
URL: https://github.com/apache/james-project/pull/385#discussion_r611441321



##########
File path: mdn/src/main/java/org/apache/james/mdn/fields/ReportingUserAgent.java
##########
@@ -60,6 +62,17 @@ public Builder userAgentProduct(String userAgentProduct) {
             return this;
         }
 
+        public Builder parse(String value) {
+            var list = ImmutableList.copyOf(Splitter.on("; ").omitEmptyStrings().split(value));

Review comment:
       We don't use var in java.

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MDNSend.scala
##########
@@ -0,0 +1,216 @@
+/****************************************************************
+ * 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 cats.implicits.toTraverseOps
+import eu.timepit.refined.refineV
+import org.apache.james.jmap.core.Id.{Id, IdConstraint}
+import org.apache.james.jmap.core.SetError.SetErrorDescription
+import org.apache.james.jmap.core.{AccountId, SetError}
+import org.apache.james.jmap.mail.MDNSend.MDNSendId
+import org.apache.james.jmap.method.WithAccountId
+import org.apache.james.mailbox.model.MessageId
+import play.api.libs.json.{JsObject, JsPath, JsonValidationError}
+
+object MDNSend {
+  type MDNSendId = Id
+}

Review comment:
       Please use `case class MDNId(Id id)` instead of a type.

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MDNSend.scala
##########
@@ -0,0 +1,216 @@
+/****************************************************************
+ * 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 cats.implicits.toTraverseOps
+import eu.timepit.refined.refineV
+import org.apache.james.jmap.core.Id.{Id, IdConstraint}
+import org.apache.james.jmap.core.SetError.SetErrorDescription
+import org.apache.james.jmap.core.{AccountId, SetError}
+import org.apache.james.jmap.mail.MDNSend.MDNSendId
+import org.apache.james.jmap.method.WithAccountId
+import org.apache.james.mailbox.model.MessageId
+import play.api.libs.json.{JsObject, JsPath, JsonValidationError}
+
+object MDNSend {
+  type MDNSendId = Id
+}
+
+object MDNSendParseException {
+  def parse(errors: collection.Seq[(JsPath, collection.Seq[JsonValidationError])]) : MDNSendParseException = {
+    val setError = errors.head match {
+      case (path, Seq()) => SetError.invalidArguments(SetErrorDescription(s"'$path' property in MDNSend object is not valid"))
+      case (path, Seq(JsonValidationError(Seq("error.path.missing")))) => SetError.invalidArguments(SetErrorDescription(s"Missing '$path' property in MDNSend object"))
+      case (path, Seq(JsonValidationError(Seq(message)))) => SetError.invalidArguments(SetErrorDescription(s"'$path' property in MDNSend object is not valid: $message"))
+      case (path, _) => SetError.invalidArguments(SetErrorDescription(s"Unknown error on property '$path'"))
+    }
+    MDNSendParseException(setError)
+  }
+}
+case class MDNSendParseException(error: SetError) extends Exception
+case class MDNSendForEmailIdNotFoundException(description: String) extends Exception
+case class MDNSendForbiddenException() extends Exception
+case class MDNSendForbiddenFromException() extends Exception
+case class MDNSendOverQuotaException() extends Exception
+case class MDNSendTooLargeException() extends Exception
+case class MDNSendRateLimitException() extends Exception
+case class MDNSendInvalidPropertiesException() extends Exception
+case class MDNSendAlreadySentException() extends Exception
+
+
+case class MDNGatewayField(value: String) extends AnyVal
+
+object MDNSendCreateRequest {
+  private val assignableProperties: Set[String] = Set("forEmailId", "subject", "textBody", "reportingUA",
+    "finalRecipient", "includeOriginalMessage", "disposition", "extensionFields")
+
+  def validateProperties(jsObject: JsObject): Either[MDNSendParseException, JsObject] =
+    jsObject.keys.diff(assignableProperties) match {
+      case unknownProperties if unknownProperties.nonEmpty =>
+        Left(MDNSendParseException(SetError.invalidArguments(
+          SetErrorDescription("Some unknown properties were specified"),
+          Some(toProperties(unknownProperties.toSet)))))
+      case _ => scala.Right(jsObject)
+    }
+}
+case class MDNSendCreateRequest(forEmailId: ForEmailIdField,
+                                subject: Option[SubjectField],
+                                textBody: Option[TextBodyField],
+                                reportingUA: Option[ReportUAField],
+                                finalRecipient: Option[FinalRecipientField],
+                                includeOriginalMessage: Option[IncludeOriginalMessageField],
+                                disposition: MDNDisposition,
+                                extensionFields: Option[Map[String, String]]) {
+  def validate : Either[MDNSendParseException, MDNSendCreateRequest] =
+    scala.Right(this)
+}
+
+case class MDNSendCreateResponse(subject: Option[SubjectField],
+                                 textBody: Option[TextBodyField],
+                                 reportingUA: Option[ReportUAField],
+                                 mdnGateway: Option[MDNGatewayField],
+                                 originalRecipient: Option[OriginalRecipientField],
+                                 finalRecipient: Option[FinalRecipientField],
+                                 includeOriginalMessage: Option[IncludeOriginalMessageField],
+                                 error: Option[Seq[ErrorField]],
+                                 extensionFields: Option[Map[String, String]])
+
+case class IdentityId(id: Id)

Review comment:
       This IdentityId stuff already exist, do not duplicate it.

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MDNSend.scala
##########
@@ -0,0 +1,216 @@
+/****************************************************************
+ * 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 cats.implicits.toTraverseOps
+import eu.timepit.refined.refineV
+import org.apache.james.jmap.core.Id.{Id, IdConstraint}
+import org.apache.james.jmap.core.SetError.SetErrorDescription
+import org.apache.james.jmap.core.{AccountId, SetError}
+import org.apache.james.jmap.mail.MDNSend.MDNSendId
+import org.apache.james.jmap.method.WithAccountId
+import org.apache.james.mailbox.model.MessageId
+import play.api.libs.json.{JsObject, JsPath, JsonValidationError}
+
+object MDNSend {
+  type MDNSendId = Id
+}
+
+object MDNSendParseException {
+  def parse(errors: collection.Seq[(JsPath, collection.Seq[JsonValidationError])]) : MDNSendParseException = {
+    val setError = errors.head match {
+      case (path, Seq()) => SetError.invalidArguments(SetErrorDescription(s"'$path' property in MDNSend object is not valid"))
+      case (path, Seq(JsonValidationError(Seq("error.path.missing")))) => SetError.invalidArguments(SetErrorDescription(s"Missing '$path' property in MDNSend object"))
+      case (path, Seq(JsonValidationError(Seq(message)))) => SetError.invalidArguments(SetErrorDescription(s"'$path' property in MDNSend object is not valid: $message"))
+      case (path, _) => SetError.invalidArguments(SetErrorDescription(s"Unknown error on property '$path'"))
+    }
+    MDNSendParseException(setError)
+  }
+}
+case class MDNSendParseException(error: SetError) extends Exception
+case class MDNSendForEmailIdNotFoundException(description: String) extends Exception
+case class MDNSendForbiddenException() extends Exception
+case class MDNSendForbiddenFromException() extends Exception
+case class MDNSendOverQuotaException() extends Exception
+case class MDNSendTooLargeException() extends Exception
+case class MDNSendRateLimitException() extends Exception
+case class MDNSendInvalidPropertiesException() extends Exception
+case class MDNSendAlreadySentException() extends Exception
+
+
+case class MDNGatewayField(value: String) extends AnyVal
+
+object MDNSendCreateRequest {
+  private val assignableProperties: Set[String] = Set("forEmailId", "subject", "textBody", "reportingUA",
+    "finalRecipient", "includeOriginalMessage", "disposition", "extensionFields")
+
+  def validateProperties(jsObject: JsObject): Either[MDNSendParseException, JsObject] =
+    jsObject.keys.diff(assignableProperties) match {
+      case unknownProperties if unknownProperties.nonEmpty =>
+        Left(MDNSendParseException(SetError.invalidArguments(
+          SetErrorDescription("Some unknown properties were specified"),
+          Some(toProperties(unknownProperties.toSet)))))
+      case _ => scala.Right(jsObject)
+    }
+}
+case class MDNSendCreateRequest(forEmailId: ForEmailIdField,
+                                subject: Option[SubjectField],
+                                textBody: Option[TextBodyField],
+                                reportingUA: Option[ReportUAField],
+                                finalRecipient: Option[FinalRecipientField],
+                                includeOriginalMessage: Option[IncludeOriginalMessageField],
+                                disposition: MDNDisposition,
+                                extensionFields: Option[Map[String, String]]) {

Review comment:
       `String, String` ? Can we get strong types?

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/package.scala
##########
@@ -0,0 +1,15 @@
+package org.apache.james.jmap

Review comment:
       Missing license

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/MDNSendSerializer.scala
##########
@@ -0,0 +1,86 @@
+/****************************************************************
+ * 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.json
+
+import org.apache.james.jmap.core.{Id, SetError}
+import org.apache.james.jmap.mail.MDNSend.MDNSendId
+import org.apache.james.jmap.mail.{ErrorField, FinalRecipientField, ForEmailIdField, IdentityId, IncludeOriginalMessageField, MDNDisposition, MDNGatewayField, MDNSendCreateRequest, MDNSendCreateResponse, MDNSendRequest, MDNSendResponse, OriginalMessageIdField, OriginalRecipientField, ReportUAField, SubjectField, TextBodyField}
+import org.apache.james.mailbox.model.MessageId
+import play.api.libs.json._
+
+import javax.inject.Inject
+import scala.util.Try
+
+
+class MDNSendSerializer @Inject()(messageIdFactory: MessageId.Factory) {

Review comment:
       Can we reuse MDNParseSerializer? Maybe rename it MDNSerializer...

##########
File path: server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MDNSendMethodContract.scala
##########
@@ -0,0 +1,619 @@
+/****************************************************************
+ * 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 io.netty.handler.codec.http.HttpHeaderNames.ACCEPT
+import io.restassured.RestAssured._
+import io.restassured.http.ContentType.JSON
+import net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson
+import org.apache.http.HttpStatus.SC_OK
+import org.apache.james.GuiceJamesServer
+import org.apache.james.jmap.core.ResponseObject.SESSION_STATE
+import org.apache.james.jmap.http.UserCredential
+import org.apache.james.jmap.rfc8621.contract.Fixture.{BOB, BOB_PASSWORD, DOMAIN, authScheme, baseRequestSpecBuilder, _}
+import org.apache.james.mailbox.MessageManager.AppendCommand
+import org.apache.james.mailbox.model.{MailboxPath, MessageId}
+import org.apache.james.mime4j.dom.Message
+import org.apache.james.modules.MailboxProbeImpl
+import org.apache.james.utils.DataProbeImpl
+import org.junit.jupiter.api.{BeforeEach, Test}
+
+import java.nio.charset.StandardCharsets
+
+trait MDNSendMethodContract {
+
+  @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()
+  }
+
+  def randomMessageId: MessageId
+
+  @Test
+  def sendShouldBeSuccessWhenRequestIsValid(guiceJamesServer: GuiceJamesServer): Unit = {
+    val path: MailboxPath = MailboxPath.inbox(BOB)
+    val mailboxProbe: MailboxProbeImpl = guiceJamesServer.getProbe(classOf[MailboxProbeImpl])
+    mailboxProbe.createMailbox(path)
+
+    val message: Message = Message.Builder
+      .of
+      .setSubject("test")
+      .setSender(BOB.asString)
+      .setFrom(BOB.asString)
+      .setTo(ANDRE.asString)
+      .setBody("testmail", StandardCharsets.UTF_8)
+      .build
+    val emailIdRelated: MessageId = mailboxProbe
+      .appendMessage(BOB.asString(), path, AppendCommand.builder()
+        .build(message))
+      .getMessageId
+
+    val request =
+      s"""{
+         |  "using": [
+         |    "urn:ietf:params:jmap:core",
+         |    "urn:ietf:params:jmap:mail",
+         |    "urn:ietf:params:jmap:mdn"
+         |  ],
+         |  "methodCalls": [
+         |    [
+         |      "MDN/send",
+         |      {
+         |        "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |        "identityId": "I64588216",
+         |        "send": {
+         |          "k1546": {
+         |            "forEmailId": "${emailIdRelated.serialize()}",
+         |            "subject": "Read receipt for: World domination",
+         |            "textBody": "This receipt shows that the email has been displayed on your recipient's computer. ",
+         |            "reportingUA": "joes-pc.cs.example.com; Foomail 97.1",
+         |            "disposition": {
+         |              "actionMode": "manual-action",
+         |              "sendingMode": "mdn-sent-manually",
+         |              "type": "displayed"
+         |            },
+         |            "extensionFields": {
+         |              "X-EXTENSION-EXAMPLE": "example.com"
+         |            }
+         |          }
+         |        },
+         |        "onSuccessUpdateEmail": {
+         |          "#k1546": {
+         |            "keywords/$$mdnsent": true
+         |          }
+         |        }
+         |      },
+         |      "c1"
+         |    ]
+         |  ]
+         |}""".stripMargin
+
+    val response = `given`
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(request)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response)
+      .whenIgnoringPaths("methodResponses[1][1].newState",
+        "methodResponses[1][1].oldState")
+      .isEqualTo(s"""{
+                    |    "sessionState": "${SESSION_STATE.value}",
+                    |    "methodResponses": [
+                    |        [
+                    |            "MDN/send",
+                    |            {
+                    |                "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+                    |                "sent": {
+                    |                    "k1546": {
+                    |                        "finalRecipient": "rfc822; bob@domain.tld",
+                    |                        "includeOriginalMessage": false
+                    |                    }
+                    |                }
+                    |            },
+                    |            "c1"
+                    |        ],
+                    |        [
+                    |            "Email/set",
+                    |            {
+                    |                "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+                    |                "oldState": "23",
+                    |                "newState": "42",
+                    |                "updated": {
+                    |                    "${emailIdRelated.serialize()}": null
+                    |                }
+                    |            },
+                    |            "c1"
+                    |        ]
+                    |    ]
+                    |}""".stripMargin)

Review comment:
       Do the original sender receives the MDN? (can we add a test)




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