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: <[email protected]>
+ |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: <[email protected]>
+ |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: <[email protected]>
+ |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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]