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 04:39:40 UTC

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

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