class PostDequeueDecorator extends MailQueueItemDecorator {

    @Override
    public void done(boolean success) throws MailQueueException {
        mailQueueItem.done(success);
        if (success && mandatoryJmapMetaDataIsPresent()) {
            Optional<?> optionalRawMessageId = retrieveMessageId();
            MessageId messageId = messageIdFactory.fromString((String) optionalRawMessageId.get());
            Optional<String> username = retrieveUsername();
            if (!getMail().getAttribute(IS_DELIVERED.getName()).isPresent()) {
                try {
                    MailboxSession mailboxSession = mailboxManager.createSystemSession(Username.of(username.get()));
                    moveFromOutboxToSentWithSeenFlag(messageId, mailboxSession);
                    getMail().setAttribute(IS_DELIVERED);
                } catch (MailShouldBeInOutboxException e) {
                    LOG.info("Message does not exist on Outbox anymore, it could have already been sent", e);
                } catch (MailboxException e) {
                    throw new MailQueueException(e.getMessage(), e);
                }
            }
        }
    }

    public  PostDequeueDecorator(MailQueueItem mailQueueItem,
                                MailboxManager mailboxManager,
                                Factory messageIdFactory,
                                MessageIdManager messageIdManager,
                                SystemMailboxesProvider systemMailboxesProvider);

}