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/23 03:14:27 UTC

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

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


##########
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/Capability.scala:
##########
@@ -161,16 +164,41 @@ final case class EhloArg(value: String) extends AnyVal
 final case class EhloArgs(values: List[EhloArg]) extends AnyVal
 
 final case class SubmissionCapability(identifier: CapabilityIdentifier = EMAIL_SUBMISSION,
-                                      properties: SubmissionProperties = SubmissionProperties()) extends Capability
+                                      properties: SubmissionProperties) extends Capability
 
-case object SubmissionCapabilityFactory extends CapabilityFactory {
+case object SubmissionCapabilityFactory {
+  val maximumDelays = Duration.ofDays(1)
+}
+
+final case class SubmissionCapabilityFactory(clock: Clock, supportsDelaySends: Boolean) extends CapabilityFactory {
   override def id(): CapabilityIdentifier = EMAIL_SUBMISSION
 
-  override def create(urlPrefixes: UrlPrefixes): Capability = SubmissionCapability()
+  override def create(urlPrefixes: UrlPrefixes): Capability =
+    if (supportsDelaySends) {
+      advertiseDelaySendSupport
+    } else {
+      advertiseNoDelaySendSupport
+    }
+
+  private def advertiseDelaySendSupport = {
+    val dateAsString = DateTimeFormatter.ISO_INSTANT.withZone(ZoneId.of("UTC")).format(clock.instant().plus(maximumDelays))
+
+    SubmissionCapability(EMAIL_SUBMISSION,
+      SubmissionProperties(MaxDelayedSend(maximumDelays.toSeconds.toInt),
+        Map(EhloName("FUTURERELEASE") -> EhloArgs(List(EhloArg(maximumDelays.toSeconds.toString()), EhloArg(dateAsString))))))
+  }
+
+  private def advertiseNoDelaySendSupport =
+    SubmissionCapability(EMAIL_SUBMISSION,
+      SubmissionProperties(MaxDelayedSend(0),
+        Map()))
+
+  def create(maxDelayedSend: MaxDelayedSend, submissionExtensions: Map[EhloName, EhloArgs]): Capability =
+    SubmissionCapability(EMAIL_SUBMISSION, SubmissionProperties(maxDelayedSend, submissionExtensions))
 }
 
-final case class SubmissionProperties(maxDelayedSend: MaxDelayedSend = MaxDelayedSend(0),
-                                      submissionExtensions: Map[EhloName, EhloArgs] = Map()) extends CapabilityProperties {
+final case class SubmissionProperties(maxDelayedSend: MaxDelayedSend = MaxDelayedSend(86400),

Review Comment:
   Can we leverage the `SubmissionCapabilityFactory.maximumDelays` constant instead of an 86400 number?



##########
server/queue/queue-pulsar/src/main/scala/org/apache/james/queue/pulsar/PulsarMailQueue.scala:
##########
@@ -666,5 +666,4 @@ class PulsarMailQueue(
 
     Source.fromPublisher(doDelete())
   }
-

Review Comment:
   Still not resolved, and why did you mark this as resolved? That is a bigger problem than this comment itself.



##########
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSubmissionSetMethod.scala:
##########
@@ -240,14 +248,20 @@ class EmailSubmissionSetMethod @Inject()(serializer: EmailSubmissionSetSerialize
 
   private def sendEmail(mailboxSession: MailboxSession,
                         request: EmailSubmissionCreationRequest): SMono[(EmailSubmissionCreationResponse, MessageId)] =
-   for {
+    for {
       message <- SFlux(messageIdManager.getMessagesReactive(List(request.emailId).asJava, FetchGroup.FULL_CONTENT, mailboxSession))
         .next
         .switchIfEmpty(SMono.error(MessageNotFoundException(request.emailId)))
       submissionId = EmailSubmissionId.generate
       message <- SMono.fromTry(toMimeMessage(submissionId.value, message))
       envelope <- SMono.fromTry(resolveEnvelope(message, request.envelope))
       _ <- validate(mailboxSession)(message, envelope)
+      fromParameters = envelope.mailFrom.parameters
+      _ <- SMono.fromTry(validateFromParameters(fromParameters))
+      delay <- SMono.fromTry(retrieveDelay(fromParameters))

Review Comment:
   No need the temporary `fromParameters`  variable IMO.



##########
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailSubmissionSet.scala:
##########
@@ -120,25 +128,30 @@ case class EmailSubmissionSetResponse(accountId: AccountId,
 
 case class EmailSubmissionId(value: Id)
 
-case class EmailSubmissionCreationResponse(id: EmailSubmissionId)
-
-case class EmailSubmissionAddress(email: MailAddress)
+case class EmailSubmissionCreationResponse(id: EmailSubmissionId, sendAt: UTCDate = UTCDate(ZonedDateTime.ofInstant(DATE, ZoneId.of("Z"))))
+case class ParameterName(value: String) extends AnyVal
+case class ParameterValue(value: String) extends AnyVal
+case class EmailSubmissionAddress(email: MailAddress, parameters: Option[Map[ParameterName, Option[ParameterValue]]] = Option.empty)
 
 case class Envelope(mailFrom: EmailSubmissionAddress, rcptTo: List[EmailSubmissionAddress])
 
 object EmailSubmissionCreationRequest {
   private val assignableProperties = Set("emailId", "envelope", "identityId", "onSuccessUpdateEmail")
 
-  def validateProperties(jsObject: JsObject): Either[EmailSubmissionCreationParseException, JsObject] =
+  def validateProperties(jsObject: JsObject): Either[EmailSubmissionCreationParseException, JsObject] = {
     jsObject.keys.diff(assignableProperties) match {
       case unknownProperties if unknownProperties.nonEmpty =>
         Left(EmailSubmissionCreationParseException(SetError.invalidArguments(
           SetErrorDescription("Some unknown properties were specified"),
           Some(toProperties(unknownProperties.toSet)))))
       case _ => scala.Right(jsObject)
+
     }

Review Comment:
   Still not resolved too...



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