def filter()

in server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetUpdatePerformer.scala [49:96]


    def filter(acceptableProperties: Properties): Option[Properties] = Some(patch
      .map(_.updatedProperties.intersect(acceptableProperties))
      .getOrElse(acceptableProperties))

    def asMailboxSetError: SetError = exception match {
      case e: MailboxNotFoundException =>
        LOGGER.info("Can't update mailbox: Mailbox not found: {}", e.getMessage)
        SetError.notFound(SetErrorDescription(e.getMessage))
      case e: MailboxNameException =>
        LOGGER.info("Invalid mailbox name: {}", e.getMessage)
        SetError.invalidArguments(SetErrorDescription(e.getMessage), filter(Properties("name", "parentId")))
      case e: MailboxExistsException =>
        LOGGER.info("Mailbox already exists: {}", e.getMessage)
        SetError.invalidArguments(SetErrorDescription(e.getMessage), filter(Properties("name", "parentId")))
      case e: UnsupportedPropertyUpdatedException =>
        LOGGER.info("Unsupported properties in Mailbox/set update: {}", e.getMessage)
        SetError.invalidArguments(SetErrorDescription(s"${e.property} property do not exist thus cannot be updated"), Some(Properties(e.property)))
      case e: InvalidUpdateException =>
        LOGGER.info("Invalid update in Mailbox/set update: {}", e.getMessage)
        SetError.invalidArguments(SetErrorDescription(s"${e.cause}"), Some(Properties(e.property)))
      case e: ServerSetPropertyException =>
        LOGGER.info("Unsupported server-set properties in Mailbox/set update: {}", e.getMessage)
        SetError.invalidArguments(SetErrorDescription("Can not modify server-set properties"), Some(Properties(e.property)))
      case e: InvalidPropertyException =>
        LOGGER.info("Invalid properties in Mailbox/set update: {}", e.getMessage)
        SetError.invalidPatch(SetErrorDescription(s"${e.cause}"))
      case e: InvalidPatchException =>
        LOGGER.info("Unsupported patch in Mailbox/set update: {}", e.getMessage)
        SetError.invalidPatch(SetErrorDescription(s"${e.cause}"))
      case e: SystemMailboxChangeException =>
        LOGGER.info("Attempt to update a system mailbox was rejected: {}", e.getMessage)
        SetError.invalidArguments(SetErrorDescription("Invalid change to a system mailbox"), filter(Properties("name", "parentId")))
      case e: LoopInMailboxGraphException =>
        LOGGER.info("Attempt to create a loop in mailbox graph was rejected: {}", e.getMessage)
        SetError.invalidArguments(SetErrorDescription("A mailbox parentId property can not be set to itself or one of its child"), Some(Properties("parentId")))
      case e: InsufficientRightsException =>
        LOGGER.info("Attempt to set a mailbox while having insufficient rights was rejected: {}", e.getMessage)
        SetError.forbidden(SetErrorDescription("Invalid change to a delegated mailbox"))
      case e: IllegalArgumentException =>
        LOGGER.info("Illegal argument in Mailbox/set update", e)
        SetError.invalidArguments(SetErrorDescription(e.getMessage), None)
      case e: DifferentDomainException =>
        LOGGER.info("Invalid arguments in Mailbox/set update", e)
        SetError.invalidArguments(SetErrorDescription("Invalid arguments in Mailbox/set update: different domains"), None)
      case e =>
        LOGGER.error("Failed to update mailbox", e)
        SetError.serverFail(SetErrorDescription(e.getMessage))
    }