diff --git a/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/JMAPExtensionConfiguration.scala b/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/JMAPExtensionConfiguration.scala index 0541ddb9b1..994c707e7f 100644 --- a/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/JMAPExtensionConfiguration.scala +++ b/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/JMAPExtensionConfiguration.scala @@ -1,5 +1,7 @@ package com.linagora.tmail.james.jmap +import java.time.Duration +import java.time.temporal.ChronoUnit import java.util.Locale import com.linagora.tmail.james.jmap.JMAPExtensionConfiguration.{CALENDAR_EVENT_REPLY_SUPPORTED_LANGUAGES_DEFAULT, PUBLIC_ASSET_TOTAL_SIZE_LIMIT_DEFAULT, TICKET_IP_VALIDATION_ENABLED} @@ -10,7 +12,7 @@ import org.apache.commons.configuration2.Configuration import org.apache.james.core.MailAddress import org.apache.james.jmap.core.UnsignedInt.{UnsignedInt, UnsignedIntConstraint} import org.apache.james.server.core.MissingArgumentException -import org.apache.james.util.Size +import org.apache.james.util.{DurationParser, Size} import scala.util.{Failure, Success, Try} @@ -46,8 +48,10 @@ object JMAPExtensionConfiguration { })) .fold(_ => Set.empty, identity)) + val emailRecoveryActionConfiguration: EmailRecoveryActionConfiguration = EmailRecoveryActionConfiguration.from(configuration) + JMAPExtensionConfiguration(publicAssetTotalSizeLimit, supportMailAddressOpt, ticketIpValidationEnable, - calendarEventReplySupportedLanguagesConfig) + calendarEventReplySupportedLanguagesConfig, emailRecoveryActionConfiguration) } } @@ -61,7 +65,8 @@ object PublicAssetTotalSizeLimit { case class JMAPExtensionConfiguration(publicAssetTotalSizeLimit: PublicAssetTotalSizeLimit = PUBLIC_ASSET_TOTAL_SIZE_LIMIT_DEFAULT, supportMailAddress: Option[MailAddress] = Option.empty, ticketIpValidationEnable: TicketIpValidationEnable = TICKET_IP_VALIDATION_ENABLED, - calendarEventReplySupportedLanguagesConfig: CalendarEventReplySupportedLanguagesConfig = CALENDAR_EVENT_REPLY_SUPPORTED_LANGUAGES_DEFAULT) { + calendarEventReplySupportedLanguagesConfig: CalendarEventReplySupportedLanguagesConfig = CALENDAR_EVENT_REPLY_SUPPORTED_LANGUAGES_DEFAULT, + emailRecoveryActionConfiguration: EmailRecoveryActionConfiguration = EmailRecoveryActionConfiguration.DEFAULT) { def this(publicAssetTotalSizeLimit: PublicAssetTotalSizeLimit) = { this(publicAssetTotalSizeLimit, Option.empty) } @@ -81,4 +86,22 @@ case class PublicAssetTotalSizeLimit(value: UnsignedInt) { case class TicketIpValidationEnable(value: Boolean) -case class CalendarEventReplySupportedLanguagesConfig(supportedLanguages: Set[Locale]) \ No newline at end of file +case class CalendarEventReplySupportedLanguagesConfig(supportedLanguages: Set[Locale]) + +object EmailRecoveryActionConfiguration { + val DEFAULT_MAX_EMAIL_RECOVERY_PER_REQUEST: Long = 5 + val DEFAULT_RESTORATION_HORIZON: Duration = DurationParser.parse("15", ChronoUnit.DAYS) + val DEFAULT: EmailRecoveryActionConfiguration = EmailRecoveryActionConfiguration(DEFAULT_MAX_EMAIL_RECOVERY_PER_REQUEST, DEFAULT_RESTORATION_HORIZON) + + def from(jmapConfiguration: Configuration): EmailRecoveryActionConfiguration = { + val maxEmailRecoveryPerRequest: Long = jmapConfiguration.getLong("emailRecoveryAction.maxEmailRecoveryPerRequest", DEFAULT_MAX_EMAIL_RECOVERY_PER_REQUEST) + + val restorationHorizon: Duration = Option(jmapConfiguration.getString("emailRecoveryAction.restorationHorizon", null)) + .map(DurationParser.parse) + .getOrElse(DEFAULT_RESTORATION_HORIZON) + + EmailRecoveryActionConfiguration(maxEmailRecoveryPerRequest, restorationHorizon) + } +} + +case class EmailRecoveryActionConfiguration(maxEmailRecoveryPerRequest: Long, restorationHorizon: Duration) \ No newline at end of file diff --git a/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/method/EmailRecoveryActionSetMethod.scala b/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/method/EmailRecoveryActionSetMethod.scala index 7e183f9948..47f1780794 100644 --- a/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/method/EmailRecoveryActionSetMethod.scala +++ b/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/method/EmailRecoveryActionSetMethod.scala @@ -1,7 +1,6 @@ package com.linagora.tmail.james.jmap.method -import java.time.temporal.ChronoUnit -import java.time.{Duration, ZonedDateTime} +import java.time.ZonedDateTime import com.google.common.collect.ImmutableList import com.google.inject.multibindings.Multibinder @@ -10,6 +9,7 @@ import com.linagora.tmail.james.jmap.json.EmailRecoveryActionSerializer import com.linagora.tmail.james.jmap.method.CapabilityIdentifier.LINAGORA_MESSAGE_VAULT import com.linagora.tmail.james.jmap.method.EmailRecoveryActionSetCreatePerformer.CreationResults import com.linagora.tmail.james.jmap.model.{EmailRecoveryActionCreation, EmailRecoveryActionCreationId, EmailRecoveryActionCreationParseException, EmailRecoveryActionCreationRequest, EmailRecoveryActionCreationResponse, EmailRecoveryActionSetRequest, EmailRecoveryActionSetResponse, EmailRecoveryActionUpdateException, EmailRecoveryActionUpdatePatchObject, EmailRecoveryActionUpdateRequest, EmailRecoveryActionUpdateResponse, EmailRecoveryActionUpdateStatus, UnparsedEmailRecoveryActionId} +import com.linagora.tmail.james.jmap.{EmailRecoveryActionConfiguration, JMAPExtensionConfiguration} import eu.timepit.refined.auto._ import jakarta.inject.Inject import org.apache.james.core.Username @@ -24,8 +24,7 @@ import org.apache.james.lifecycle.api.Startable import org.apache.james.mailbox.MailboxSession import org.apache.james.metrics.api.MetricFactory import org.apache.james.task.{TaskExecutionDetails, TaskId, TaskManager, TaskNotFoundException} -import org.apache.james.util.{DurationParser, ReactorUtils} -import org.apache.james.utils.PropertiesProvider +import org.apache.james.util.ReactorUtils import org.apache.james.vault.search.{CriterionFactory, Query} import org.apache.james.webadmin.vault.routes.DeletedMessagesVaultRestoreTask.{AdditionalInformation => DeletedMessagesVaultRestoreTaskAdditionalInformation} import org.apache.james.webadmin.vault.routes.{DeletedMessagesVaultRestoreTask, RestoreService} @@ -35,7 +34,6 @@ import play.api.libs.json.{JsError, JsObject} import reactor.core.scala.publisher.{SFlux, SMono} import scala.jdk.OptionConverters._ -import scala.util.Try class EmailRecoveryActionMethodModule extends AbstractModule { override def configure(): Unit = { @@ -50,34 +48,10 @@ class EmailRecoveryActionMethodModule extends AbstractModule { @Singleton @Provides - def provideEmailRecoveryActionConfiguration(propertiesProvider: PropertiesProvider): EmailRecoveryActionConfiguration = - EmailRecoveryActionConfiguration.from(propertiesProvider) + def provideEmailRecoveryActionConfiguration(jmapExtensionConfiguration: JMAPExtensionConfiguration): EmailRecoveryActionConfiguration = + jmapExtensionConfiguration.emailRecoveryActionConfiguration } -object EmailRecoveryActionConfiguration { - - val DEFAULT_MAX_EMAIL_RECOVERY_PER_REQUEST: Long = 5 - val DEFAULT_RESTORATION_HORIZON: Duration = DurationParser.parse("15", ChronoUnit.DAYS) - - def from(propertiesProvider: PropertiesProvider): EmailRecoveryActionConfiguration = { - val config = Try(propertiesProvider.getConfiguration("jmap")) - - val maxEmailRecoveryPerRequest: Option[Long] = config - .map(_.getLong("emailRecoveryAction.maxEmailRecoveryPerRequest")) - .toOption - val restorationHorizon: Option[Duration] = config - .map(_.getString("emailRecoveryAction.restorationHorizon")) - .map(DurationParser.parse) - .toOption - - EmailRecoveryActionConfiguration( - maxEmailRecoveryPerRequest = maxEmailRecoveryPerRequest.getOrElse(DEFAULT_MAX_EMAIL_RECOVERY_PER_REQUEST), - restorationHorizon = restorationHorizon.getOrElse(DEFAULT_RESTORATION_HORIZON)) - } -} - -case class EmailRecoveryActionConfiguration(maxEmailRecoveryPerRequest: Long, restorationHorizon: Duration) - class EmailRecoveryActionSetMethod @Inject()(val createPerformer: EmailRecoveryActionSetCreatePerformer, val updatePerformer: EmailRecoveryActionSetUpdatePerformer, val metricFactory: MetricFactory,