/** * Return a List which holds all uids of recent messages and optional reset * the recent flag on the messages for the uids */ protected List<MessageUid> recent(final boolean reset, MailboxSession mailboxSession) throws MailboxException { if (reset) { if (!isWriteable(mailboxSession)) { throw new ReadOnlyException(getMailboxPath(), mailboxSession.getPathDelimiter()); } } final MessageMapper messageMapper = mapperFactory.getMessageMapper(mailboxSession); return messageMapper.execute(() -> { final List<MessageUid> members = messageMapper.findRecentMessageUidsInMailbox(getMailboxEntity()); // Convert to MessageRanges so we may be able to optimize the // flag update List<MessageRange> ranges = MessageRange.toRanges(members); for (MessageRange range : ranges) { if (reset) { // only call save if we need to messageMapper.updateFlags(getMailboxEntity(), new FlagsUpdateCalculator(new Flags(Flag.RECENT), FlagsUpdateMode.REMOVE), range); } } return members; }); }