@Test public void assertUserCanSendFromShouldThrowWhenSenderIsAnAliasOfAnotherUser() throws Exception { DraftEmailer sender = DraftEmailer .builder() .name("alias") .email("alias@example.com") .build(); recipientRewriteTable.addAliasMapping(MappingSource.fromUser("alias", "example.com"), OTHER_USER.asString()); assertThatThrownBy(() -> sut.assertUserCanSendFrom(USER, Optional.of(sender))) .isInstanceOf(MailboxSendingNotAllowedException.class); }
@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); } }
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); } } }
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); }
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); @Override SetMessagesResponse process(SetMessagesRequest request, MailboxSession mailboxSession); }
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); @Override SetMessagesResponse process(SetMessagesRequest request, MailboxSession mailboxSession);  }