diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSetCreatePerformer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSetCreatePerformer.scala index 84d5aeac749..0e5a8dcd90c 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSetCreatePerformer.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSetCreatePerformer.scala @@ -68,14 +68,16 @@ object EmailSetCreatePerformer { def asMessageSetError: SetError = e match { case e: MailboxNotFoundException => SetError.notFound(SetErrorDescription("Mailbox " + e.getMessage)) case e: BlobNotFoundException => SetError.invalidArguments(SetErrorDescription(s"Attachment not found: ${e.blobId.value}"), Some(Properties("attachments"))) + case e: SizeExceededException => SetError.tooLarge(SetErrorDescription(e.getMessage)) case e: IllegalArgumentException => SetError.invalidArguments(SetErrorDescription(e.getMessage)) case e: OverQuotaException => SetError.overQuota(SetErrorDescription(e.getMessage)) - case e: TooLargeException => SetError.tooLarge(SetErrorDescription(e.getMessage)) case _ => SetError.serverFail(SetErrorDescription(e.getMessage)) } } } +case class SizeExceededException(actualSize: Long, maximumSize: Long) extends IllegalArgumentException(s"Attempt to create a message of $actualSize bytes while the maximum allowed is $maximumSize") + class EmailSetCreatePerformer @Inject()(serializer: EmailSetSerializer, blobResolvers: BlobResolvers, htmlTextExtractor: HtmlTextExtractor, @@ -118,7 +120,7 @@ class EmailSetCreatePerformer @Inject()(serializer: EmailSetSerializer, } } - private def asAppendCommand(request: EmailCreationRequest, message: Message): Either[Exception, AppendCommand] = + private def asAppendCommand(request: EmailCreationRequest, message: Message): Either[IllegalArgumentException, AppendCommand] = Right( AppendCommand.builder() .recent() @@ -128,6 +130,6 @@ class EmailSetCreatePerformer @Inject()(serializer: EmailSetSerializer, .flatMap(appendCommand => configuration.getMaximumSendSize.toScala .filter(limit => appendCommand.getMsgIn.size() > limit) - .map(limit => Left(TooLargeException(appendCommand.getMsgIn.size(), limit))) + .map(limit => Left(SizeExceededException(appendCommand.getMsgIn.size(), limit))) .getOrElse(Right(appendCommand))) } diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/Method.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/Method.scala index c54dee3251e..71f0ae3ef8b 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/Method.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/Method.scala @@ -32,8 +32,6 @@ import reactor.core.scala.publisher.SFlux case class AccountNotFoundException(invocation: Invocation) extends IllegalArgumentException -case class TooLargeException(actualSize: Long, maximumSize: Long) extends Exception(s"Attempt to create a message of $actualSize bytes while the maximum allowed is $maximumSize") - case class InvocationWithContext(invocation: Invocation, processingContext: ProcessingContext) { def recordInvocation: InvocationWithContext = InvocationWithContext(invocation, processingContext.recordInvocation(invocation)) }