private Optional<MailboxMessage> retrieveMailboxMessage(MailboxSession session, EventFactory.AddedImpl added, Mailbox mailbox, MessageUid next) { Optional<MailboxMessage> firstChoice = Optional.ofNullable(added.getAvailableMessages().get(next)); if (firstChoice.isPresent()) { return firstChoice; } else { try { return Optional.of(factory.getMessageMapper(session) .findInMailbox(mailbox, MessageRange.one(next), FetchType.Full, UNLIMITED) .next()); } catch (Exception e) { LOGGER.error("Could not retrieve message {} in mailbox {}", next, mailbox.getMailboxId().serialize(), e); return Optional.empty(); } } }