You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by "quantranhong1999 (via GitHub)" <gi...@apache.org> on 2023/06/02 03:28:28 UTC

[GitHub] [james-project] quantranhong1999 commented on a diff in pull request #1561: [WIP]JAMES 4865 - FutureRelease for JMAP

quantranhong1999 commented on code in PR #1561:
URL: https://github.com/apache/james-project/pull/1561#discussion_r1213878854


##########
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSubmissionSetMethod.scala:
##########
@@ -268,74 +273,120 @@ class EmailSubmissionSetMethod @Inject()(serializer: EmailSubmissionSetSerialize
         mailImpl.setMessageNoCopy(message)
         mailImpl
       }
-      _ <- SMono(queue.enqueueReactive(mail))
-        .`then`(SMono.fromCallable(() => LifecycleUtil.dispose(mail)).subscribeOn(Schedulers.boundedElastic()))
-        .`then`(SMono.just(submissionId))
+      //     SMono.fromPublisher(canSendFrom.userCanSendFromReactive(session.getUser, Username.fromMailAddress(envelope.mailFrom.email)))
+      //     .filter(bool => bool.equals(false))
+      //     .map(_ => Failure(ForbiddenFromException(envelope.mailFrom.email.asString)))
+      //     .switchIfEmpty(SMono.just(Success(mimeMessage)))
+      //     .switchIfEmpty(SMono.just(Success(mimeMessage)))
+
+     _ <- SMono(queue.enqueueReactive(mail, delay))
+       .`then`(SMono.fromCallable(() => LifecycleUtil.dispose(mail)).subscribeOn(Schedulers.boundedElastic()))
+       .`then`(SMono.just(submissionId))
+
+//     - <- SMono.just(delay.getSeconds.>=(0).&&(delay.getSeconds.<=(SubmissionCapabilityFactory.maximumDelays.getSeconds)))
+//       .filter(_.equals(true))
+//       .`then`(SMono(queue.enqueueReactive(mail, delay)))
+//       .`then`(SMono.fromCallable(() => LifecycleUtil.dispose(mail)).subscribeOn(Schedulers.boundedElastic()))
+//       .`then`(SMono.just(submissionId))
+
+//           _ <- SMono(queue.enqueueReactive(mail, delay))
+//             .`then`(SMono.fromCallable(() => LifecycleUtil.dispose(mail)).subscribeOn(Schedulers.boundedElastic()))
+//             .`then`(SMono.just(submissionId))
     } yield {
       EmailSubmissionCreationResponse(submissionId) -> request.emailId
     }
 
-  private def toMimeMessage(name: String, message: MessageResult): Try[MimeMessageWrapper] = {
-    val source = MessageMimeMessageSource(name, message)
-    // if MimeMessageCopyOnWriteProxy throws an error in the constructor we
-    // have to manually care disposing our source.
-    Try(new MimeMessageWrapper(source))
-      .recover(e => {
-        LifecycleUtil.dispose(source)
-        throw e
-      })
-  }
-
-  private def validate(session: MailboxSession)(mimeMessage: MimeMessage, envelope: Envelope): SMono[MimeMessage] =
-    SFlux.fromIterable(Option(mimeMessage.getSender).toList ++ Option(mimeMessage.getFrom).toList.flatten)
-      .map(_.asInstanceOf[InternetAddress].getAddress)
-      .filterWhen(addressAsString => SMono.fromPublisher(canSendFrom.userCanSendFromReactive(session.getUser, Username.fromMailAddress(new MailAddress(addressAsString))))
-        .map(Boolean.unbox(_)).map(!_), Queues.SMALL_BUFFER_SIZE)
-      .collectSeq()
-      .flatMap(forbiddenMailFrom => {
-        if (forbiddenMailFrom.nonEmpty) {
-          SMono.just(Failure(ForbiddenMailFromException(forbiddenMailFrom.toList)))
-        } else if (envelope.rcptTo.isEmpty) {
-          SMono.just(Failure(NoRecipientException()))
+  private def validateDelay(mailParameters: Option[Map[ParameterName, Option[ParameterValue]]]): Try[Duration] = {
+    println("Clock instance in EmailSubmissionSetMethod: " + clock)
+    if (mailParameters.isEmpty) {
+      Try(Duration.ZERO)
+    }
+    if (mailParameters.get.size == 1) {
+      val parameterName = mailParameters.get.head._1.value
+      val parameterValue = mailParameters.get.head._2.get.value

Review Comment:
   Can you write more contract tests for the cases we have many parameters than holdFor/holdUntil?
   E.g:
   - Only other parameters
   ```json
   "parameters": {
   	"anotherParam:": "whatever"
   }
   ```
   - other parameters (go first), then `holdFor`/`holdUntil` (second)
   ```json
   "parameters": {
   	"anotherParam:": "whatever",
   	"holdFor": "86400"
   }
   ```
   - What happens if the holdFor/holdUntil value is null (possibly following the spec)?
   ```json
   "parameters": {
   	"holdFor": null
   }
   ```
   
   And others if relevant.



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

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

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