Skip to content

Commit

Permalink
fixup! JMAP Email/set create should use tooLarge when attempt to crea…
Browse files Browse the repository at this point in the history
…te an oversize mail
  • Loading branch information
vttranlina committed Mar 15, 2022
1 parent 5b2b1c0 commit 007d6ca
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand All @@ -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)))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down

0 comments on commit 007d6ca

Please sign in to comment.