private void assertMessageBelongsToOutbox(MessageId messageId, MailboxSession mailboxSession) throws MailboxException, MailShouldBeInOutboxException { MailboxId outboxMailboxId = getOutboxMailboxId(mailboxSession); List<MessageResult> messages = messageIdManager.getMessages(ImmutableList.of(messageId), FetchGroupImpl.MINIMAL, mailboxSession); for (MessageResult message: messages) { if (message.getMailboxId().equals(outboxMailboxId)) { return; } } throw new MailShouldBeInOutboxException(messageId); }
private Stream<MailboxException> updateFlags(MessageId messageId, UpdateMessagePatch updateMessagePatch, MailboxSession mailboxSession, MessageResult messageResult) { try { if (!updateMessagePatch.isFlagsIdentity()) { messageIdManager.setFlags( updateMessagePatch.applyToState(messageResult.getFlags()), FlagsUpdateMode.REPLACE, messageId, ImmutableList.of(messageResult.getMailboxId()), mailboxSession); } return Stream.of(); } catch (MailboxException e) { return Stream.of(e); } }
@Before public void setUp() throws MailboxException { ImapSession imapSession = mock(ImapSession.class); when(imapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)) .thenReturn(MAILBOX_SESSION); when(imapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED); MailboxManager mailboxManager = mock(MailboxManager.class); MessageManager messageManager = mock(MessageManager.class); when(mailboxManager.getDelimiter()).thenReturn(PATH_DELIMITER); when(mailboxManager.getMailbox(any(MailboxId.class), any(MailboxSession.class))) .thenReturn(messageManager); when(mailboxManager.getMailbox(any(MailboxPath.class), any(MailboxSession.class))) .thenReturn(messageManager); MessageResult messageResult = mock(MessageResult.class); when(messageResult.getMailboxId()).thenReturn(TestId.of(36)); when(messageResult.getUid()).thenReturn(MESSAGE_UID); when(messageManager.getApplicableFlags(any())) .thenReturn(new Flags()); when(messageManager.search(any(), any())) .thenReturn(ImmutableList.of(MESSAGE_UID).iterator()); when(messageManager.getMessages(any(), any(), any())) .thenReturn(new SingleMessageResultIterator(messageResult)); testee = new SelectedMailboxImpl(mailboxManager, imapSession, MAILBOX_PATH); }
public static Builder builderFromMessageResult(MessageResult messageResult) throws MailboxException { Builder builder = builder() .uid(messageResult.getUid()) .modSeq(messageResult.getModSeq()) .size(messageResult.getSize()) .internalDate(messageResult.getInternalDate().toInstant()) .attachments(messageResult.getAttachments()) .mailboxId(messageResult.getMailboxId()); try { return builder.content(messageResult.getFullContent().getInputStream()); } catch (IOException e) { throw new MailboxException("Can't get message full content: " + e.getMessage(), e); } }