quantranhong1999 commented on code in PR #1561:
URL: https://github.com/apache/james-project/pull/1561#discussion_r1217639682
##########
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSubmissionSetMethod.scala:
##########
@@ -273,59 +275,37 @@ class EmailSubmissionSetMethod @Inject()(serializer:
EmailSubmissionSetSerialize
mailImpl.setMessageNoCopy(message)
mailImpl
}
- //
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 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
- if (parameterName.eq("holdFor")) {
- val delay = Duration.ofSeconds(parameterValue.toLong)
- if ((delay.getSeconds >=0) && (delay.getSeconds <=
SubmissionCapabilityFactory.maximumDelays.getSeconds)) {
- Success(delay)
- } else {
- Failure(new IllegalArgumentException("Invalid Arguments"))
+ } else mailParameters.get.size match {
+ case 1 => {
+ val parameterName = mailParameters.get.head._1.value
+ val parameterValue = mailParameters.get.head._2.get.value
+ val delay: Duration = parameterName match {
+ case "holdFor" => Duration.ofSeconds(parameterValue.toLong)
+ case "holdUntil" => Duration.between(LocalDateTime.now(clock),
LocalDateTime.parse(parameterValue, formatter))
+ case _ => throw new IllegalArgumentException("Unsupported
parameterName")
}
- } else if (parameterName.eq("holdUntil")) {
- val formatter = DateTimeFormatter.ISO_INSTANT.withZone(ZoneId.of("Z"))
- val delay = Duration.between(LocalDateTime.now(clock),
LocalDateTime.parse(parameterValue, formatter))
- if ((delay.getSeconds >=0) && (delay.getSeconds <=
SubmissionCapabilityFactory.maximumDelays.getSeconds)) {
+
+ if (delay.getSeconds >= 0 && delay.getSeconds <=
SubmissionCapabilityFactory.maximumDelays.getSeconds) {
Success(delay)
} else {
- Failure(new IllegalArgumentException("Invalid holdUntil Arguments"))
+ Failure(new IllegalArgumentException("Invalid Arguments"))
}
- } else Failure(new IllegalArgumentException("Unsupported parameterName"))
- } else {
- Failure(new IllegalArgumentException("Mail parameter must have only one
value"))
+ }
Review Comment:
My suggestion (quickly put it a try, may not be the best design yet, mainly
for Thanh to better understand)
```scala
trait JmapSubmissionExtension
object FutureReleaseExtension {
val HOLD_FOR_PARAMETER_NAME: String = "holdFor"
val HOLD_UNTIL_PARAMETER_NAME: String = "holdUntil"
def fromHoldFor(value: Option[ParameterValue]): FutureReleaseExtension =
???
def fromHoldUntil(value: Option[ParameterValue]): FutureReleaseExtension
= ???
}
case class FutureReleaseExtension(delay: Duration) extends
JmapSubmissionExtension
private def toExtensions(parameters: Option[Map[ParameterName,
Option[ParameterValue]]]): List[JmapSubmissionExtension] =
parameters.map(parametersMap => parametersMap
.flatMap(keyToValue => keyToValue._1 match {
case ParameterName(FutureReleaseExtension.HOLD_FOR_PARAMETER_NAME)
=> Some(FutureReleaseExtension.fromHoldFor(keyToValue._2))
case ParameterName(FutureReleaseExtension.HOLD_UNTIL_PARAMETER_NAME)
=> Some(FutureReleaseExtension.fromHoldUntil(keyToValue._2))
// case DSN ...
case _ => None
})
.toList)
.getOrElse(List())
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]