class SetMessagesCreationProcessor implements SetMessagesProcessor {

    @VisibleForTesting
    void assertUserCanSendFrom(Username connectedUser, Optional<DraftEmailer> from) throws MailboxSendingNotAllowedException {

        Optional<Username> maybeFromUser = from.flatMap(DraftEmailer::getEmail)
            .map(Username::of);

        if (!canSendMailUsingIdentity(connectedUser, maybeFromUser)) {
            String allowedSender = connectedUser.asString();
            throw new MailboxSendingNotAllowedException(connectedUser, maybeFromUser);
        } else {
            LOG.debug("{} is allowed to send a mail using {} identity", connectedUser.asString(), from);
        }
    }

    @VisibleForTesting @Inject  SetMessagesCreationProcessor(MessageFullViewFactory messageFullViewFactory,
                                 SystemMailboxesProvider systemMailboxesProvider,
                                 AttachmentChecker attachmentChecker,
                                 MetricFactory metricFactory,
                                 MailboxManager mailboxManager,
                                 MailboxId.Factory mailboxIdFactory,
                                 MessageAppender messageAppender,
                                 MessageSender messageSender,
                                 ReferenceUpdater referenceUpdater,
                                 CanSendFrom canSendFrom);

}