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/06 03:29:45 UTC

[GitHub] [james-project] vttranlina opened a new pull request #365: JAMES-3520 MDN/parse should position forEmailId property

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


   Ref: https://github.com/linagora/james-project/issues/4312


-- 
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 pull request #365: JAMES-3520 MDN/parse should position forEmailId property

Posted by GitBox <gi...@apache.org>.
chibenwa commented on pull request #365:
URL: https://github.com/apache/james-project/pull/365#issuecomment-814526730


   You need to rebase this PR on master.


-- 
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 #365: JAMES-3520 MDN/parse should position forEmailId property

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



##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNParseMethod.scala
##########
@@ -20,25 +20,31 @@
 package org.apache.james.jmap.method
 
 import eu.timepit.refined.auto._
+import org.apache.james.core.Username
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JMAP_CORE, JMAP_MAIL, JMAP_MDN}
 import org.apache.james.jmap.core.Invocation
 import org.apache.james.jmap.core.Invocation._
 import org.apache.james.jmap.json.{MDNParseSerializer, ResponseSerializer}
-import org.apache.james.jmap.mail.{BlobId, MDNParseRequest, MDNParseResponse, MDNParseResults, MDNParsed}
+import org.apache.james.jmap.mail.{BlobId, BlobUnParsableException, MDNParseRequest, MDNParseResponse, MDNParseResults, MDNParsed}
 import org.apache.james.jmap.routes.{BlobNotFoundException, BlobResolvers, SessionSupplier}
-import org.apache.james.mailbox.MailboxSession
+import org.apache.james.mailbox.model.{MessageId, MultimailboxesSearchQuery, SearchQuery}
+import org.apache.james.mailbox.{MailboxManager, MailboxSession}
 import org.apache.james.mdn.MDN
+import org.apache.james.mdn.fields.{OriginalMessageId}

Review comment:
       {} no longer needed

##########
File path: server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MDNParseMethodContract.scala
##########
@@ -696,4 +696,141 @@ trait MDNParseMethodContract {
          |    "c1"]]
          |}""".stripMargin)
   }
+
+  @Test
+  def forEmailIdShouldReturnWhenOriginalMessageIdIsRelated(guiceJamesServer: GuiceJamesServer): Unit = {
+    val path: MailboxPath = MailboxPath.inbox(BOB)
+    val mailboxProbe: MailboxProbeImpl = guiceJamesServer.getProbe(classOf[MailboxProbeImpl])
+    mailboxProbe.createMailbox(path)
+
+    val originalMessageId: MessageId = mailboxProbe
+      .appendMessage(BOB.asString(), path, AppendCommand.from(
+        ClassLoaderUtils.getSystemResourceAsSharedStream("eml/mdn_relate_original_message.eml")))
+      .getMessageId
+
+    val mdnBodyPart = BodyPartBuilder
+      .create
+      .setBody(SingleBodyBuilder.create
+        .setText(s"""Reporting-UA: UA_name; UA_product
+                    |MDN-Gateway: smtp; apache.org
+                    |Original-Recipient: rfc822; originalRecipient
+                    |Final-Recipient: rfc822; ${BOB.asString()}
+                    |Original-Message-ID: <me...@Atlassian.JIRA>
+                    |Disposition: automatic-action/MDN-sent-automatically;processed/error,failed
+                    |""".replace(System.lineSeparator(), "\r\n")
+          .stripMargin)
+        .buildText)
+      .setContentType("message/disposition-notification")
+      .build
+
+    val mdnMessageId = mailboxProbe
+      .appendMessage(BOB.asString(), path, AppendCommand.builder()
+        .build(Message.Builder
+          .of
+          .setSubject("Subject MDN")
+          .setSender(BOB.asString())
+          .setFrom(BOB.asString())
+          .setBody(MultipartBuilder.create("report")
+            .addTextPart("This is body of text part", StandardCharsets.UTF_8)
+            .addBodyPart(mdnBodyPart)
+            .build)
+          .build))
+      .getMessageId
+
+    val request =
+      s"""{
+         |  "using": [
+         |    "urn:ietf:params:jmap:core",
+         |    "urn:ietf:params:jmap:mdn",
+         |    "urn:ietf:params:jmap:mail"],
+         |  "methodCalls": [[
+         |    "MDN/parse",
+         |    {
+         |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |      "blobIds": [ "${mdnMessageId.serialize()}" ]
+         |    },
+         |    "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)
+      .inPath("methodResponses[0][1].parsed.2.forEmailId")
+      .isEqualTo(s""""${originalMessageId.serialize}"""")
+  }
+
+  @Test
+  def forEmailIdShouldBeNullWhenOriginalMessageIdIsNotFound(guiceJamesServer: GuiceJamesServer): Unit = {
+    val path: MailboxPath = MailboxPath.inbox(BOB)
+    val mailboxProbe: MailboxProbeImpl = guiceJamesServer.getProbe(classOf[MailboxProbeImpl])
+    mailboxProbe.createMailbox(path)
+    val mdnBodyPart = BodyPartBuilder
+      .create
+      .setBody(SingleBodyBuilder.create
+        .setText(s"""Reporting-UA: UA_name; UA_product
+                    |MDN-Gateway: smtp; apache.org
+                    |Original-Recipient: rfc822; originalRecipient
+                    |Final-Recipient: rfc822; final_recipient
+                    |Original-Message-ID: <no...@Atlassian.JIRA>
+                    |Disposition: automatic-action/MDN-sent-automatically;processed/error,failed
+                    |""".replace(System.lineSeparator(), "\r\n")
+          .stripMargin)
+        .buildText)
+      .setContentType("message/disposition-notification")
+      .build
+
+    val mdnMessageId = mailboxProbe
+      .appendMessage(BOB.asString(), path, AppendCommand.builder()
+        .build(Message.Builder
+          .of
+          .setSubject("Subject MDN")
+          .setSender(BOB.asString())
+          .setFrom(BOB.asString())
+          .setBody(MultipartBuilder.create("report")
+            .addTextPart("This is body of text part", StandardCharsets.UTF_8)
+            .addBodyPart(mdnBodyPart)
+            .build)
+          .build))
+      .getMessageId
+
+    val request =
+      s"""{
+         |  "using": [
+         |    "urn:ietf:params:jmap:core",
+         |    "urn:ietf:params:jmap:mdn",
+         |    "urn:ietf:params:jmap:mail"],
+         |  "methodCalls": [[
+         |    "MDN/parse",
+         |    {
+         |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |      "blobIds": [ "${mdnMessageId.serialize()}" ]
+         |    },
+         |    "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)
+      .inPath("methodResponses[0][1].parsed.2.forEmailId").isAbsent()

Review comment:
       Does it pass the distributed test?
   
   Use mdnMessageId instead of 2

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNParseMethod.scala
##########
@@ -77,29 +83,52 @@ class MDNParseMethod @Inject()(val blobResolvers: BlobResolvers,
 
     val parsed: SFlux[MDNParseResults] = SFlux.fromIterable(parsedIds)
       .flatMap(blobId => toParseResults(blobId, mailboxSession))
-      .map(_.fold(e => MDNParseResults.notFound(e.blobId), result => result))
 
     SFlux.merge(Seq(parsed, SFlux.fromIterable(invalid)))
       .reduce(MDNParseResults.empty())(MDNParseResults.merge)
       .map(_.asResponse(request.accountId))
   }
 
-  private def toParseResults(blobId: BlobId, mailboxSession: MailboxSession): SMono[Either[BlobNotFoundException, MDNParseResults]] =
+  private def toParseResults(blobId: BlobId, mailboxSession: MailboxSession): SMono[MDNParseResults] =
     blobResolvers.resolve(blobId, mailboxSession)
-      .map(blob => Right(parse(blob.blobId, blob.content)))
+      .flatMap(blob => parse(blob.blobId, blob.content)
+        .flatMap(mdnAndMsg => buildMDNParseResults(blobId, mdnAndMsg._1, mdnAndMsg._2, mailboxSession)))
       .onErrorResume {
-        case e: BlobNotFoundException => SMono.just(Left(e))
+        case e: BlobNotFoundException => SMono.just(MDNParseResults.notFound(e.blobId))
+        case e: BlobUnParsableException => SMono.just(MDNParseResults.notParse(e.blobId))
+        case _ => SMono.just(MDNParseResults.notParse(blobId))
       }
 
-  private def parse(blobId: BlobId, blobContent: InputStream): MDNParseResults = {
+  private def buildMDNParseResults(blobId: BlobId, mdn: MDN, message: Message, session: MailboxSession): SMono[MDNParseResults] = {

Review comment:
       {} not needed 

##########
File path: server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MDNParseMethodContract.scala
##########
@@ -696,4 +696,141 @@ trait MDNParseMethodContract {
          |    "c1"]]
          |}""".stripMargin)
   }
+
+  @Test
+  def forEmailIdShouldReturnWhenOriginalMessageIdIsRelated(guiceJamesServer: GuiceJamesServer): Unit = {
+    val path: MailboxPath = MailboxPath.inbox(BOB)
+    val mailboxProbe: MailboxProbeImpl = guiceJamesServer.getProbe(classOf[MailboxProbeImpl])
+    mailboxProbe.createMailbox(path)
+
+    val originalMessageId: MessageId = mailboxProbe
+      .appendMessage(BOB.asString(), path, AppendCommand.from(
+        ClassLoaderUtils.getSystemResourceAsSharedStream("eml/mdn_relate_original_message.eml")))
+      .getMessageId
+
+    val mdnBodyPart = BodyPartBuilder
+      .create
+      .setBody(SingleBodyBuilder.create
+        .setText(s"""Reporting-UA: UA_name; UA_product
+                    |MDN-Gateway: smtp; apache.org
+                    |Original-Recipient: rfc822; originalRecipient
+                    |Final-Recipient: rfc822; ${BOB.asString()}
+                    |Original-Message-ID: <me...@Atlassian.JIRA>
+                    |Disposition: automatic-action/MDN-sent-automatically;processed/error,failed
+                    |""".replace(System.lineSeparator(), "\r\n")
+          .stripMargin)
+        .buildText)
+      .setContentType("message/disposition-notification")
+      .build
+
+    val mdnMessageId = mailboxProbe
+      .appendMessage(BOB.asString(), path, AppendCommand.builder()
+        .build(Message.Builder
+          .of
+          .setSubject("Subject MDN")
+          .setSender(BOB.asString())
+          .setFrom(BOB.asString())
+          .setBody(MultipartBuilder.create("report")
+            .addTextPart("This is body of text part", StandardCharsets.UTF_8)
+            .addBodyPart(mdnBodyPart)
+            .build)
+          .build))
+      .getMessageId
+
+    val request =
+      s"""{
+         |  "using": [
+         |    "urn:ietf:params:jmap:core",
+         |    "urn:ietf:params:jmap:mdn",
+         |    "urn:ietf:params:jmap:mail"],
+         |  "methodCalls": [[
+         |    "MDN/parse",
+         |    {
+         |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |      "blobIds": [ "${mdnMessageId.serialize()}" ]
+         |    },
+         |    "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)
+      .inPath("methodResponses[0][1].parsed.2.forEmailId")

Review comment:
       
   
   Does it pass the distributed test?
   
   Use mdnMessageId instead of 2
   




-- 
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] vttranlina commented on pull request #365: JAMES-3520 MDN/parse should position forEmailId property

Posted by GitBox <gi...@apache.org>.
vttranlina commented on pull request #365:
URL: https://github.com/apache/james-project/pull/365#issuecomment-815395853


   What should I do?


-- 
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 #365: JAMES-3520 MDN/parse should position forEmailId property

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



##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNParseMethod.scala
##########
@@ -82,27 +83,30 @@ class MDNParseMethod @Inject()(val blobResolvers: BlobResolvers,
     val invalid: Seq[MDNParseResults] = validations.map(_.left).flatMap(_.toOption)
 
     val parsed: SFlux[MDNParseResults] = SFlux.fromIterable(parsedIds)
-      .flatMap(blobId => toParseResults(blobId, mailboxSession, mdnEmailIdResolver))
+      .flatMap(blobId => toParseResults(blobId, mailboxSession))
 
     SFlux.merge(Seq(parsed, SFlux.fromIterable(invalid)))
       .reduce(MDNParseResults.empty())(MDNParseResults.merge)
       .map(_.asResponse(request.accountId))
   }
 
-  private def toParseResults(blobId: BlobId, mailboxSession: MailboxSession, mdnEmailIdResolver: MDNEmailIdResolver): SMono[MDNParseResults] =
+  private def toParseResults(blobId: BlobId, mailboxSession: MailboxSession): SMono[MDNParseResults] =
     blobResolvers.resolve(blobId, mailboxSession)
       .flatMap(blob => parse(blob.blobId, blob.content)
-        .flatMap(mdnAndMsg =>  {
-          mdnEmailIdResolver.resolveForEmailId(mdnAndMsg._1.getReport.getOriginalMessageIdField.toScala, mdnAndMsg._1.getReport.getFinalRecipientField)
-            .map(messageId => MDNParsed.fromMDN(mdnAndMsg._1, mdnAndMsg._2, messageId))
-            .map(mdnParsed => MDNParseResults.parse(blobId, mdnParsed))
-        }))
+        .flatMap(mdnAndMsg => buildMDNParser(blobId, mdnAndMsg._1, mdnAndMsg._2)))
       .onErrorResume {
         case e: BlobNotFoundException => SMono.just(MDNParseResults.notFound(e.blobId))
         case e: BlobUnParsableException => SMono.just(MDNParseResults.notParse(e.blobId))
         case _ => SMono.just(MDNParseResults.notParse(blobId))
       }
 
+  private def buildMDNParser(blobId: BlobId, mdn: MDN, message: Message): SMono[MDNParseResults] = {
+    val session = mailboxManager.createSystemSession(Username.of(mdn.getReport.getFinalRecipientField.getFinalRecipient.formatted()))

Review comment:
       We are searching in the mailbox of the guy owning the MDN (so the MDN receiver).
   
   The original email will be in his `Sent` mailbox.




-- 
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 pull request #365: JAMES-3520 MDN/parse should position forEmailId property

Posted by GitBox <gi...@apache.org>.
Arsnael commented on pull request #365:
URL: https://github.com/apache/james-project/pull/365#issuecomment-815410880


   > What should I do?
   
   Just wait for the build to finish :)


-- 
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 #365: JAMES-3520 MDN/parse should position forEmailId property

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



##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNParseMethod.scala
##########
@@ -77,29 +82,51 @@ class MDNParseMethod @Inject()(val blobResolvers: BlobResolvers,
 
     val parsed: SFlux[MDNParseResults] = SFlux.fromIterable(parsedIds)
       .flatMap(blobId => toParseResults(blobId, mailboxSession))
-      .map(_.fold(e => MDNParseResults.notFound(e.blobId), result => result))
 
     SFlux.merge(Seq(parsed, SFlux.fromIterable(invalid)))
       .reduce(MDNParseResults.empty())(MDNParseResults.merge)
       .map(_.asResponse(request.accountId))
   }
 
-  private def toParseResults(blobId: BlobId, mailboxSession: MailboxSession): SMono[Either[BlobNotFoundException, MDNParseResults]] =
+  private def toParseResults(blobId: BlobId, mailboxSession: MailboxSession): SMono[MDNParseResults] =
     blobResolvers.resolve(blobId, mailboxSession)
-      .map(blob => Right(parse(blob.blobId, blob.content)))
+      .flatMap(blob => parse(blob.blobId, blob.content)
+        .flatMap(mdnAndMsg => buildMDNParseResults(blobId, mdnAndMsg._1, mdnAndMsg._2, mailboxSession)))

Review comment:
       ```suggestion
           .flatMap {
             case (mdn, message) => buildMDNParseResults(blobId, mdn, message, mailboxSession)
           }
   ```

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MDNParse.scala
##########
@@ -103,9 +106,9 @@ object IncludeOriginalMessageField {
 case class IncludeOriginalMessageField(value: Boolean) extends AnyVal
 
 object MDNParsed {
-  def fromMDN(mdn: MDN, message: Message): MDNParsed = {
+  def fromMDN(mdn: MDN, message: Message, originalMessageId: Option[MessageId]): MDNParsed = {
     val report = mdn.getReport
-    MDNParsed(forEmailId = None,
+    MDNParsed(forEmailId = originalMessageId.map(msgId => ForEmailIdField(msgId)),

Review comment:
       ```suggestion
       MDNParsed(forEmailId = originalMessageId.map(ForEmailIdField(_)),
   ```




-- 
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 #365: JAMES-3520 MDN/parse should position forEmailId property

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



##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNParseMethod.scala
##########
@@ -82,27 +83,30 @@ class MDNParseMethod @Inject()(val blobResolvers: BlobResolvers,
     val invalid: Seq[MDNParseResults] = validations.map(_.left).flatMap(_.toOption)
 
     val parsed: SFlux[MDNParseResults] = SFlux.fromIterable(parsedIds)
-      .flatMap(blobId => toParseResults(blobId, mailboxSession, mdnEmailIdResolver))
+      .flatMap(blobId => toParseResults(blobId, mailboxSession))
 
     SFlux.merge(Seq(parsed, SFlux.fromIterable(invalid)))
       .reduce(MDNParseResults.empty())(MDNParseResults.merge)
       .map(_.asResponse(request.accountId))
   }
 
-  private def toParseResults(blobId: BlobId, mailboxSession: MailboxSession, mdnEmailIdResolver: MDNEmailIdResolver): SMono[MDNParseResults] =
+  private def toParseResults(blobId: BlobId, mailboxSession: MailboxSession): SMono[MDNParseResults] =
     blobResolvers.resolve(blobId, mailboxSession)
       .flatMap(blob => parse(blob.blobId, blob.content)
-        .flatMap(mdnAndMsg =>  {
-          mdnEmailIdResolver.resolveForEmailId(mdnAndMsg._1.getReport.getOriginalMessageIdField.toScala, mdnAndMsg._1.getReport.getFinalRecipientField)
-            .map(messageId => MDNParsed.fromMDN(mdnAndMsg._1, mdnAndMsg._2, messageId))
-            .map(mdnParsed => MDNParseResults.parse(blobId, mdnParsed))
-        }))
+        .flatMap(mdnAndMsg => buildMDNParser(blobId, mdnAndMsg._1, mdnAndMsg._2)))
       .onErrorResume {
         case e: BlobNotFoundException => SMono.just(MDNParseResults.notFound(e.blobId))
         case e: BlobUnParsableException => SMono.just(MDNParseResults.notParse(e.blobId))
         case _ => SMono.just(MDNParseResults.notParse(blobId))
       }
 
+  private def buildMDNParser(blobId: BlobId, mdn: MDN, message: Message): SMono[MDNParseResults] = {
+    val session = mailboxManager.createSystemSession(Username.of(mdn.getReport.getFinalRecipientField.getFinalRecipient.formatted()))

Review comment:
       No problem :-)




-- 
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 #365: JAMES-3520 MDN/parse should position forEmailId property

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



##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNParseMethod.scala
##########
@@ -82,27 +83,30 @@ class MDNParseMethod @Inject()(val blobResolvers: BlobResolvers,
     val invalid: Seq[MDNParseResults] = validations.map(_.left).flatMap(_.toOption)
 
     val parsed: SFlux[MDNParseResults] = SFlux.fromIterable(parsedIds)
-      .flatMap(blobId => toParseResults(blobId, mailboxSession, mdnEmailIdResolver))
+      .flatMap(blobId => toParseResults(blobId, mailboxSession))
 
     SFlux.merge(Seq(parsed, SFlux.fromIterable(invalid)))
       .reduce(MDNParseResults.empty())(MDNParseResults.merge)
       .map(_.asResponse(request.accountId))
   }
 
-  private def toParseResults(blobId: BlobId, mailboxSession: MailboxSession, mdnEmailIdResolver: MDNEmailIdResolver): SMono[MDNParseResults] =
+  private def toParseResults(blobId: BlobId, mailboxSession: MailboxSession): SMono[MDNParseResults] =
     blobResolvers.resolve(blobId, mailboxSession)
       .flatMap(blob => parse(blob.blobId, blob.content)
-        .flatMap(mdnAndMsg =>  {
-          mdnEmailIdResolver.resolveForEmailId(mdnAndMsg._1.getReport.getOriginalMessageIdField.toScala, mdnAndMsg._1.getReport.getFinalRecipientField)
-            .map(messageId => MDNParsed.fromMDN(mdnAndMsg._1, mdnAndMsg._2, messageId))
-            .map(mdnParsed => MDNParseResults.parse(blobId, mdnParsed))
-        }))
+        .flatMap(mdnAndMsg => buildMDNParser(blobId, mdnAndMsg._1, mdnAndMsg._2)))
       .onErrorResume {
         case e: BlobNotFoundException => SMono.just(MDNParseResults.notFound(e.blobId))
         case e: BlobUnParsableException => SMono.just(MDNParseResults.notParse(e.blobId))
         case _ => SMono.just(MDNParseResults.notParse(blobId))
       }
 
+  private def buildMDNParser(blobId: BlobId, mdn: MDN, message: Message): SMono[MDNParseResults] = {

Review comment:
       buildMDNParseResults

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNParseMethod.scala
##########
@@ -116,11 +120,12 @@ class MDNParseMethod @Inject()(val blobResolvers: BlobResolvers,
 
 case class MDNEmailIdResolver @Inject()(mailboxManager: MailboxManager) {
 
-  def resolveForEmailId(originalMessageId: Option[OriginalMessageId], finalRecipient: FinalRecipient): SMono[Option[MessageId]] =
+  val NUMBER_OF_ORIGINAL_MESSAGE_ID_VALID: 1 = 1

Review comment:
       And we can move it is a top level object:
   
   ```
   object MDNEmailIdResolver {
       val NUMBER_OF_ORIGINAL_MESSAGE_ID_VALID: Int = 1
   }
   
   case class MDNEmailIdResolver @Inject()(mailboxManager: MailboxManager) {
     // use MDNEmailIdResolver.NUMBER_OF_ORIGINAL_MESSAGE_ID_VALID
   }
   ```

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNParseMethod.scala
##########
@@ -116,11 +120,12 @@ class MDNParseMethod @Inject()(val blobResolvers: BlobResolvers,
 
 case class MDNEmailIdResolver @Inject()(mailboxManager: MailboxManager) {
 
-  def resolveForEmailId(originalMessageId: Option[OriginalMessageId], finalRecipient: FinalRecipient): SMono[Option[MessageId]] =
+  val NUMBER_OF_ORIGINAL_MESSAGE_ID_VALID: 1 = 1

Review comment:
       ```suggestion
     val NUMBER_OF_ORIGINAL_MESSAGE_ID_VALID: Int = 1
   ```

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNParseMethod.scala
##########
@@ -82,27 +83,30 @@ class MDNParseMethod @Inject()(val blobResolvers: BlobResolvers,
     val invalid: Seq[MDNParseResults] = validations.map(_.left).flatMap(_.toOption)
 
     val parsed: SFlux[MDNParseResults] = SFlux.fromIterable(parsedIds)
-      .flatMap(blobId => toParseResults(blobId, mailboxSession, mdnEmailIdResolver))
+      .flatMap(blobId => toParseResults(blobId, mailboxSession))
 
     SFlux.merge(Seq(parsed, SFlux.fromIterable(invalid)))
       .reduce(MDNParseResults.empty())(MDNParseResults.merge)
       .map(_.asResponse(request.accountId))
   }
 
-  private def toParseResults(blobId: BlobId, mailboxSession: MailboxSession, mdnEmailIdResolver: MDNEmailIdResolver): SMono[MDNParseResults] =
+  private def toParseResults(blobId: BlobId, mailboxSession: MailboxSession): SMono[MDNParseResults] =
     blobResolvers.resolve(blobId, mailboxSession)
       .flatMap(blob => parse(blob.blobId, blob.content)
-        .flatMap(mdnAndMsg =>  {
-          mdnEmailIdResolver.resolveForEmailId(mdnAndMsg._1.getReport.getOriginalMessageIdField.toScala, mdnAndMsg._1.getReport.getFinalRecipientField)
-            .map(messageId => MDNParsed.fromMDN(mdnAndMsg._1, mdnAndMsg._2, messageId))
-            .map(mdnParsed => MDNParseResults.parse(blobId, mdnParsed))
-        }))
+        .flatMap(mdnAndMsg => buildMDNParser(blobId, mdnAndMsg._1, mdnAndMsg._2)))
       .onErrorResume {
         case e: BlobNotFoundException => SMono.just(MDNParseResults.notFound(e.blobId))
         case e: BlobUnParsableException => SMono.just(MDNParseResults.notParse(e.blobId))
         case _ => SMono.just(MDNParseResults.notParse(blobId))
       }
 
+  private def buildMDNParser(blobId: BlobId, mdn: MDN, message: Message): SMono[MDNParseResults] = {
+    val session = mailboxManager.createSystemSession(Username.of(mdn.getReport.getFinalRecipientField.getFinalRecipient.formatted()))

Review comment:
       No we need to reuse the mailboxSession passed as a parameter of `toParseResults`




-- 
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 #365: JAMES-3520 MDN/parse should position forEmailId property

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



##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNParseMethod.scala
##########
@@ -118,9 +116,12 @@ class MDNParseMethod @Inject()(val blobResolvers: BlobResolvers,
   }
 }
 
-case class MDNEmailIdResolver @Inject()(mailboxManager: MailboxManager) {
+object MDNEmailIdResolver {
+  val NUMBER_OF_ORIGINAL_MESSAGE_ID_VALID: Int = 1
+}
 
-  val NUMBER_OF_ORIGINAL_MESSAGE_ID_VALID: 1 = 1
+case class MDNEmailIdResolver @Inject()(mailboxManager: MailboxManager) {
+  import MDNEmailIdResolver._

Review comment:
       ```suggestion
     import MDNEmailIdResolver.NUMBER_OF_ORIGINAL_MESSAGE_ID_VALID
   ```




-- 
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] vttranlina commented on a change in pull request #365: JAMES-3520 MDN/parse should position forEmailId property

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



##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNParseMethod.scala
##########
@@ -82,27 +83,30 @@ class MDNParseMethod @Inject()(val blobResolvers: BlobResolvers,
     val invalid: Seq[MDNParseResults] = validations.map(_.left).flatMap(_.toOption)
 
     val parsed: SFlux[MDNParseResults] = SFlux.fromIterable(parsedIds)
-      .flatMap(blobId => toParseResults(blobId, mailboxSession, mdnEmailIdResolver))
+      .flatMap(blobId => toParseResults(blobId, mailboxSession))
 
     SFlux.merge(Seq(parsed, SFlux.fromIterable(invalid)))
       .reduce(MDNParseResults.empty())(MDNParseResults.merge)
       .map(_.asResponse(request.accountId))
   }
 
-  private def toParseResults(blobId: BlobId, mailboxSession: MailboxSession, mdnEmailIdResolver: MDNEmailIdResolver): SMono[MDNParseResults] =
+  private def toParseResults(blobId: BlobId, mailboxSession: MailboxSession): SMono[MDNParseResults] =
     blobResolvers.resolve(blobId, mailboxSession)
       .flatMap(blob => parse(blob.blobId, blob.content)
-        .flatMap(mdnAndMsg =>  {
-          mdnEmailIdResolver.resolveForEmailId(mdnAndMsg._1.getReport.getOriginalMessageIdField.toScala, mdnAndMsg._1.getReport.getFinalRecipientField)
-            .map(messageId => MDNParsed.fromMDN(mdnAndMsg._1, mdnAndMsg._2, messageId))
-            .map(mdnParsed => MDNParseResults.parse(blobId, mdnParsed))
-        }))
+        .flatMap(mdnAndMsg => buildMDNParser(blobId, mdnAndMsg._1, mdnAndMsg._2)))
       .onErrorResume {
         case e: BlobNotFoundException => SMono.just(MDNParseResults.notFound(e.blobId))
         case e: BlobUnParsableException => SMono.just(MDNParseResults.notParse(e.blobId))
         case _ => SMono.just(MDNParseResults.notParse(blobId))
       }
 
+  private def buildMDNParser(blobId: BlobId, mdn: MDN, message: Message): SMono[MDNParseResults] = {
+    val session = mailboxManager.createSystemSession(Username.of(mdn.getReport.getFinalRecipientField.getFinalRecipient.formatted()))

Review comment:
       we are searching in sender mailbox, not receiver mailbox. 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


[GitHub] [james-project] vttranlina commented on pull request #365: JAMES-3520 MDN/parse should position forEmailId property

Posted by GitBox <gi...@apache.org>.
vttranlina commented on pull request #365:
URL: https://github.com/apache/james-project/pull/365#issuecomment-813796330


   > Please anonimize this EML.
   
   I copied it from `mailbox/store/src/test/resources/eml/mail2.eml` , so I think it is not sensitive


-- 
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] vttranlina commented on a change in pull request #365: JAMES-3520 MDN/parse should position forEmailId property

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



##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNParseMethod.scala
##########
@@ -82,27 +83,30 @@ class MDNParseMethod @Inject()(val blobResolvers: BlobResolvers,
     val invalid: Seq[MDNParseResults] = validations.map(_.left).flatMap(_.toOption)
 
     val parsed: SFlux[MDNParseResults] = SFlux.fromIterable(parsedIds)
-      .flatMap(blobId => toParseResults(blobId, mailboxSession, mdnEmailIdResolver))
+      .flatMap(blobId => toParseResults(blobId, mailboxSession))
 
     SFlux.merge(Seq(parsed, SFlux.fromIterable(invalid)))
       .reduce(MDNParseResults.empty())(MDNParseResults.merge)
       .map(_.asResponse(request.accountId))
   }
 
-  private def toParseResults(blobId: BlobId, mailboxSession: MailboxSession, mdnEmailIdResolver: MDNEmailIdResolver): SMono[MDNParseResults] =
+  private def toParseResults(blobId: BlobId, mailboxSession: MailboxSession): SMono[MDNParseResults] =
     blobResolvers.resolve(blobId, mailboxSession)
       .flatMap(blob => parse(blob.blobId, blob.content)
-        .flatMap(mdnAndMsg =>  {
-          mdnEmailIdResolver.resolveForEmailId(mdnAndMsg._1.getReport.getOriginalMessageIdField.toScala, mdnAndMsg._1.getReport.getFinalRecipientField)
-            .map(messageId => MDNParsed.fromMDN(mdnAndMsg._1, mdnAndMsg._2, messageId))
-            .map(mdnParsed => MDNParseResults.parse(blobId, mdnParsed))
-        }))
+        .flatMap(mdnAndMsg => buildMDNParser(blobId, mdnAndMsg._1, mdnAndMsg._2)))
       .onErrorResume {
         case e: BlobNotFoundException => SMono.just(MDNParseResults.notFound(e.blobId))
         case e: BlobUnParsableException => SMono.just(MDNParseResults.notParse(e.blobId))
         case _ => SMono.just(MDNParseResults.notParse(blobId))
       }
 
+  private def buildMDNParser(blobId: BlobId, mdn: MDN, message: Message): SMono[MDNParseResults] = {
+    val session = mailboxManager.createSystemSession(Username.of(mdn.getReport.getFinalRecipientField.getFinalRecipient.formatted()))

Review comment:
       if we reuse `the mailboxSession passed as a parameter of toParseResults`, we won't get any originalMessageId when `mailboxManager.search` .
   
   




-- 
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 pull request #365: JAMES-3520 MDN/parse should position forEmailId property

Posted by GitBox <gi...@apache.org>.
Arsnael commented on pull request #365:
URL: https://github.com/apache/james-project/pull/365#issuecomment-815391971


   Timeout issue... I don't think it's relevant. I restarted the build


-- 
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 pull request #365: JAMES-3520 MDN/parse should position forEmailId property

Posted by GitBox <gi...@apache.org>.
chibenwa commented on pull request #365:
URL: https://github.com/apache/james-project/pull/365#issuecomment-814631446


   ```
   06:00:12,103 [ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.4.6:compile (scala-compile-first) on project james-server-jmap-rfc-8621: wrap: org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1]
   ```
   
   Can you check and fix the compilation failure?


-- 
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] vttranlina commented on a change in pull request #365: JAMES-3520 MDN/parse should position forEmailId property

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



##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNParseMethod.scala
##########
@@ -82,27 +83,30 @@ class MDNParseMethod @Inject()(val blobResolvers: BlobResolvers,
     val invalid: Seq[MDNParseResults] = validations.map(_.left).flatMap(_.toOption)
 
     val parsed: SFlux[MDNParseResults] = SFlux.fromIterable(parsedIds)
-      .flatMap(blobId => toParseResults(blobId, mailboxSession, mdnEmailIdResolver))
+      .flatMap(blobId => toParseResults(blobId, mailboxSession))
 
     SFlux.merge(Seq(parsed, SFlux.fromIterable(invalid)))
       .reduce(MDNParseResults.empty())(MDNParseResults.merge)
       .map(_.asResponse(request.accountId))
   }
 
-  private def toParseResults(blobId: BlobId, mailboxSession: MailboxSession, mdnEmailIdResolver: MDNEmailIdResolver): SMono[MDNParseResults] =
+  private def toParseResults(blobId: BlobId, mailboxSession: MailboxSession): SMono[MDNParseResults] =
     blobResolvers.resolve(blobId, mailboxSession)
       .flatMap(blob => parse(blob.blobId, blob.content)
-        .flatMap(mdnAndMsg =>  {
-          mdnEmailIdResolver.resolveForEmailId(mdnAndMsg._1.getReport.getOriginalMessageIdField.toScala, mdnAndMsg._1.getReport.getFinalRecipientField)
-            .map(messageId => MDNParsed.fromMDN(mdnAndMsg._1, mdnAndMsg._2, messageId))
-            .map(mdnParsed => MDNParseResults.parse(blobId, mdnParsed))
-        }))
+        .flatMap(mdnAndMsg => buildMDNParser(blobId, mdnAndMsg._1, mdnAndMsg._2)))
       .onErrorResume {
         case e: BlobNotFoundException => SMono.just(MDNParseResults.notFound(e.blobId))
         case e: BlobUnParsableException => SMono.just(MDNParseResults.notParse(e.blobId))
         case _ => SMono.just(MDNParseResults.notParse(blobId))
       }
 
+  private def buildMDNParser(blobId: BlobId, mdn: MDN, message: Message): SMono[MDNParseResults] = {
+    val session = mailboxManager.createSystemSession(Username.of(mdn.getReport.getFinalRecipientField.getFinalRecipient.formatted()))

Review comment:
       (y) sorry, im lag




-- 
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 #365: JAMES-3520 MDN/parse should position forEmailId property

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


   


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