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 {
// Deduplicate message IDs
List<UUID> depdupeMessageIds =
new ArrayList<UUID>(new LinkedHashSet<UUID>(messageIds));
// Prepare modification
MessageModification modification = new MessageModification.Builder()
.addLabels(addLabels).removeLabels(removeLabels)
.addMarkers(addMarkers).removeMarkers(removeMarkers)
.build();
messageDAO.modify(mailbox, depdupeMessageIds, modification);
} 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);
}