// 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);