diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Email.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Email.scala index 179e627fe35..b60b4ae0eb8 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Email.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Email.scala @@ -32,11 +32,11 @@ import eu.timepit.refined.auto._ import eu.timepit.refined.types.string.NonEmptyString import jakarta.inject.Inject import org.apache.commons.lang3.StringUtils +import org.apache.james.jmap.api.model.Preview import org.apache.james.jmap.api.model.Size.{Size, sanitizeSize} -import org.apache.james.jmap.api.model.{EmailAddress, Preview} import org.apache.james.jmap.api.projections.{MessageFastViewPrecomputedProperties, MessageFastViewProjection} import org.apache.james.jmap.core.Id.{Id, IdConstraint} -import org.apache.james.jmap.core.{JmapRfc8621Configuration, Properties, UTCDate} +import org.apache.james.jmap.core.{Properties, UTCDate} import org.apache.james.jmap.mail.BracketHeader.sanitize import org.apache.james.jmap.mail.EmailFullViewFactory.extractBodyValues import org.apache.james.jmap.mail.EmailGetRequest.MaxBodyValueBytes @@ -55,8 +55,8 @@ import org.apache.james.mime4j.field.{AddressListFieldLenientImpl, LenientFieldP import org.apache.james.mime4j.message.DefaultMessageBuilder import org.apache.james.mime4j.stream.{Field, MimeConfig, RawFieldParser} import org.apache.james.mime4j.util.MimeUtil -import org.apache.james.util.AuditTrail import org.apache.james.util.html.HtmlTextExtractor +import org.apache.james.util.{AuditTrail, ReactorUtils} import org.slf4j.{Logger, LoggerFactory} import reactor.core.scala.publisher.{SFlux, SMono} import reactor.core.scheduler.Schedulers @@ -662,8 +662,8 @@ private class EmailFullViewReader @Inject()(messageIdManager: MessageIdManager, private val reader: GenericEmailViewReader[EmailFullView] = new GenericEmailViewReader[EmailFullView](messageIdManager, FULL_CONTENT, htmlTextExtractor, fullViewFactory) - override def read[T >: EmailFullView](ids: Seq[MessageId], request: EmailGetRequest, mailboxSession: MailboxSession): SFlux[T] = { - AuditTrail.entry + override def read[T >: EmailFullView](ids: Seq[MessageId], request: EmailGetRequest, mailboxSession: MailboxSession): SFlux[T] = + SMono(ReactorUtils.logAsMono(() => AuditTrail.entry .username(() => mailboxSession.getUser.asString()) .protocol("JMAP") .action("Email full view read") @@ -671,10 +671,8 @@ private class EmailFullViewReader @Inject()(messageIdManager: MessageIdManager, "loggedInUser", mailboxSession.getLoggedInUser.toScala .map(_.asString()) .getOrElse(""))) - .log("JMAP Email full view read.") - - reader.read(ids, request, mailboxSession) - } + .log("JMAP Email full view read."))) + .thenMany(reader.read(ids, request, mailboxSession)) } object EmailFastViewReader { diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/DelegateSetCreatePerformer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/DelegateSetCreatePerformer.scala index a549dcd3573..f4bf528149b 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/DelegateSetCreatePerformer.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/DelegateSetCreatePerformer.scala @@ -98,13 +98,13 @@ class DelegateSetCreatePerformer @Inject()(delegationStore: DelegationStore, SMono.fromPublisher(usersRepository.containsReactive(request.username)) .filter(bool => bool) .flatMap(_ => SMono.fromPublisher(delegationStore.addAuthorizedUser(mailboxSession.getUser, request.username)) - .doOnSuccess(_ => ReactorUtils.logAsMono(() => AuditTrail.entry + .`then`(SMono(ReactorUtils.logAsMono(() => AuditTrail.entry .username(() => mailboxSession.getUser.asString()) .protocol("JMAP") .action("DelegateSet/create") .parameters(() => ImmutableMap.of("delegator", mailboxSession.getUser.asString(), "delegatee", request.username.asString())) - .log("Delegation added."))) + .log("Delegation added.")))) .`then`(SMono.just[CreationResult](CreationSuccess(delegateCreationId, evaluateCreationResponse(request, mailboxSession)))) .onErrorResume(e => SMono.just[CreationResult](CreationFailure(delegateCreationId, e)))) .switchIfEmpty(SMono.just[CreationResult](CreationFailure(delegateCreationId, new UserDoesNotExistException(request.username)))) diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/DelegateSetDeletePerformer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/DelegateSetDeletePerformer.scala index aa966b0044e..6e903d0bcea 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/DelegateSetDeletePerformer.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/DelegateSetDeletePerformer.scala @@ -80,12 +80,12 @@ class DelegateSetDeletePerformer @Inject()(delegationStore: DelegationStore) { .filter(authorizedUser => DelegationId.from(baseUser, authorizedUser).equals(id)) .next() .flatMap(authorizedUser => SMono(delegationStore.removeAuthorizedUser(baseUser, authorizedUser)) - .doOnSuccess(_ => ReactorUtils.logAsMono(() => AuditTrail.entry + .`then`(SMono(ReactorUtils.logAsMono(() => AuditTrail.entry .username(() => baseUser.asString()) .protocol("JMAP") .action("DelegateSet/destroy") .parameters(() => ImmutableMap.of("delegator", baseUser.asString(), "delegatee", authorizedUser.asString())) - .log("Delegation removed.")))) + .log("Delegation removed."))))) .`then`(SMono.just[DelegateDeletionResult](DelegateDeletionSuccess(id)))) } diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/DelegatedAccountDeletePerformer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/DelegatedAccountDeletePerformer.scala index d40aa7c4ac4..223896205f3 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/DelegatedAccountDeletePerformer.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/DelegatedAccountDeletePerformer.scala @@ -80,12 +80,12 @@ class DelegatedAccountDeletePerformer @Inject()(delegationStore: DelegationStore .filter(delegatedUser => DelegationId.from(delegatedUser, baseUser).equals(id)) .next() .flatMap(delegatedUser => SMono(delegationStore.removeDelegatedUser(baseUser, delegatedUser)) - .doOnSuccess(_ => ReactorUtils.logAsMono(() => AuditTrail.entry + .`then`(SMono(ReactorUtils.logAsMono(() => AuditTrail.entry .username(() => baseUser.asString()) .protocol("JMAP") .action("DelegatedAccountSet/destroy") .parameters(() => ImmutableMap.of("delegator", delegatedUser.asString(), "delegatee", baseUser.asString())) - .log("Delegation removed.")))) + .log("Delegation removed."))))) .`then`(SMono.just[DelegatedAccountDeletionResult](DelegatedAccountDeletionSuccess(id)))) } \ No newline at end of file diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSetDeletePerformer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSetDeletePerformer.scala index e62732a1f3c..9a23f3a94c7 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSetDeletePerformer.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSetDeletePerformer.scala @@ -30,7 +30,6 @@ import org.apache.james.mailbox.model.{DeleteResult, MessageId} import org.apache.james.mailbox.{MailboxSession, MessageIdManager} import org.apache.james.util.{AuditTrail, ReactorUtils} import org.slf4j.LoggerFactory -import reactor.core.publisher.Mono import reactor.core.scala.publisher.SMono import scala.jdk.CollectionConverters._ @@ -98,7 +97,8 @@ class EmailSetDeletePerformer @Inject()(messageIdManager: MessageIdManager, } SMono(messageIdManager.delete(messageIds.toSet.asJava, mailboxSession)) - .doOnSuccess(auditTrail(_, mailboxSession)) + .flatMap(deleteResult => auditTrail(deleteResult, mailboxSession) + .`then`(SMono.just(deleteResult))) .map(DestroyResult.from) .onErrorResume(e => SMono.just(messageIds.map(id => DestroyFailure(EmailSet.asUnparsed(id), e)))) .map(_ ++ parsingErrors) @@ -108,9 +108,9 @@ class EmailSetDeletePerformer @Inject()(messageIdManager: MessageIdManager, } } - private def auditTrail(deleteResult: DeleteResult, mailboxSession: MailboxSession): Unit = + private def auditTrail(deleteResult: DeleteResult, mailboxSession: MailboxSession): SMono[Void] = if (!deleteResult.getDestroyed.isEmpty) { - ReactorUtils.logAsMono(() => AuditTrail.entry + SMono(ReactorUtils.logAsMono(() => AuditTrail.entry .username(() => mailboxSession.getUser.asString()) .protocol("JMAP") .action("Email/set destroy") @@ -118,6 +118,8 @@ class EmailSetDeletePerformer @Inject()(messageIdManager: MessageIdManager, "loggedInUser", mailboxSession.getLoggedInUser.toScala .map(_.asString()) .getOrElse(""))) - .log("Mails deleted.")) + .log("Mails deleted."))) + } else { + SMono.empty } } diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSubmissionSetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSubmissionSetMethod.scala index b58b5f2b738..31e1c287fc5 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSubmissionSetMethod.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSubmissionSetMethod.scala @@ -298,7 +298,7 @@ class EmailSubmissionSetMethod @Inject()(serializer: EmailSubmissionSetSerialize private def enqueue(mail: Mail, delay: Duration, mailboxSession: MailboxSession): SMono[Unit] = (delay match { case d if d.isNegative || d.isZero => SMono(queue.enqueueReactive(mail)) - .doOnSuccess(_ => ReactorUtils.logAsMono(() => AuditTrail.entry + .`then`(SMono(ReactorUtils.logAsMono(() => AuditTrail.entry .username(() => mailboxSession.getUser.asString()) .protocol("JMAP") .action("EmailSubmission") @@ -312,9 +312,9 @@ class EmailSubmissionSetMethod @Inject()(serializer: EmailSubmissionSetSerialize "loggedInUser", mailboxSession.getLoggedInUser.toScala .map(_.asString()) .getOrElse(""))) - .log("JMAP mail spooled."))) + .log("JMAP mail spooled.")))) case _ => SMono(queue.enqueueReactive(mail, delay)) - .doOnSuccess(_ => ReactorUtils.logAsMono(() => AuditTrail.entry + .`then`(SMono(ReactorUtils.logAsMono(() => AuditTrail.entry .username(() => mailboxSession.getUser.asString()) .protocol("JMAP") .action("EmailSubmission") @@ -329,7 +329,7 @@ class EmailSubmissionSetMethod @Inject()(serializer: EmailSubmissionSetSerialize "loggedInUser", mailboxSession.getLoggedInUser.toScala .map(_.asString()) .getOrElse(""))) - .log("JMAP mail spooled."))) + .log("JMAP mail spooled.")))) }).`then`(SMono.fromCallable(() => LifecycleUtil.dispose(mail)).subscribeOn(Schedulers.boundedElastic())) private def retrieveDelay(mailParameters: Option[Map[ParameterName, Option[ParameterValue]]]): Try[Duration] = diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetUpdatePerformer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetUpdatePerformer.scala index 0b6d3dd1666..ad9844c45ec 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetUpdatePerformer.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetUpdatePerformer.scala @@ -251,7 +251,7 @@ class MailboxSetUpdatePerformer @Inject()(serializer: MailboxSerializer, val partialUpdatesOperation: SMono[Unit] = SFlux.fromIterable(validatedPatch.rightsPartialUpdates) .flatMap(partialUpdate => SMono.fromCallable(() => mailboxManager.applyRightsCommand(mailboxId, partialUpdate.asACLCommand(), mailboxSession)) - .doOnSuccess(_ => ReactorUtils.logAsMono(() => AuditTrail.entry + .`then`(SMono(ReactorUtils.logAsMono(() => AuditTrail.entry .username(() => mailboxSession.getUser.asString()) .protocol("JMAP") .action("Mailbox/set update") @@ -260,7 +260,7 @@ class MailboxSetUpdatePerformer @Inject()(serializer: MailboxSerializer, "delegatee", partialUpdate.entryKey.getName, "mailboxId", mailboxId.serialize(), "rights", partialUpdate.rights.asJava.serialize())) - .log("JMAP mailbox shared."))), + .log("JMAP mailbox shared.")))), maxConcurrency = 5) .`then`()