コード例 #1
0
  /**
   * Delete multiple messages
   *
   * @param account
   * @param requestJSONContent JSON array of message UUIDs e.g. [uuid1, uuid2, ...]
   * @return
   */
  @DELETE
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_JSON)
  public Response deleteMessages(
      @PathParam("user") final String user,
      @PathParam("domain") final String domain,
      final String requestJSONContent) {
    Mailbox mailbox = new Mailbox(user, domain);
    List<UUID> messageIds = null;

    try {
      messageIds = JSONUtils.toUUIDList(requestJSONContent);
    } catch (IllegalStateException jpe) {
      logger.info("Malformed JSON request: {}", jpe.getMessage());
      throw new BadRequestException("Malformed JSON request");
    }

    if (messageIds == null || messageIds.isEmpty())
      throw new BadRequestException("Malformed JSON request");

    try {
      // delete message and ignore other parameters
      messageDAO.delete(mailbox, messageIds);
    } catch (Exception e) {
      logger.error("Message deletion failed: ", e);
      throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }

    return Response.noContent().build();
  }
コード例 #2
0
  /**
   * Modify multiple messages' labels and markers
   *
   * @param account
   * @param addLabels
   * @param removeLabels
   * @param addMarkers
   * @param removeMarkers
   * @param requestJSONContent JSON array of message UUIDs e.g. [uuid1, uuid2, ...]
   * @return
   */
  @PUT
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_JSON)
  public Response modifyMessages(
      @PathParam("user") final String user,
      @PathParam("domain") final String domain,
      @QueryParam("addlabel") final Set<Integer> addLabels,
      @QueryParam("removelabel") final Set<Integer> removeLabels,
      @QueryParam("addmarker") final Set<Marker> addMarkers,
      @QueryParam("removemarker") final Set<Marker> removeMarkers,
      final String requestJSONContent) {
    Mailbox mailbox = new Mailbox(user, domain);
    List<UUID> messageIds = null;

    try {
      messageIds = JSONUtils.toUUIDList(requestJSONContent);
    } catch (IllegalStateException jpe) {
      logger.info("Malformed JSON request: {}", jpe.getMessage());
      throw new BadRequestException("Malformed JSON request");
    }

    if (messageIds == null || messageIds.isEmpty())
      throw new BadRequestException("Malformed JSON request");

    try {
      // TODO: make batch request

      // add labels to message
      messageDAO.addLabel(mailbox, addLabels, messageIds);

      // remove label from message
      messageDAO.removeLabel(mailbox, removeLabels, messageIds);

      // add marker
      messageDAO.addMarker(mailbox, addMarkers, messageIds);

      // remove marker
      messageDAO.removeMarker(mailbox, removeMarkers, messageIds);
    } catch (IllegalLabelException ile) {
      throw new BadRequestException(ile.getMessage());
    } catch (Exception e) {
      logger.error("Message modifications failed: ", e);
      throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }

    return Response.noContent().build();
  }