@Override protected CopyRequest createRequest(ImapCommand command, String tag, boolean useUids, IdRange[] idSet, String mailboxName) { return new CopyRequest(command, idSet, mailboxName, useUids, tag); }
@Override protected Closeable addContextToMDC(CopyRequest message) { return MDCBuilder.create() .addContext(MDCBuilder.ACTION, "COPY") .addContext("targetMailbox", message.getMailboxName()) .addContext("uidEnabled", message.isUseUids()) .addContext("idSet", IdRange.toString(message.getIdSet())) .build(); } }
/** * @see * org.apache.james.imap.decode.parser.AbstractUidCommandParser#decode(org.apache.james.imap.api.ImapCommand, * org.apache.james.imap.decode.ImapRequestLineReader, java.lang.String, * boolean, org.apache.james.imap.api.process.ImapSession) */ protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag, boolean useUids, ImapSession session) throws DecodingException { IdRange[] idSet = request.parseIdRange(session); String mailboxName = request.mailbox(); request.eol(); final ImapMessage result = new CopyRequest(command, idSet, mailboxName, useUids, tag); return result; }
final MailboxPath targetMailbox = buildFullPath(session, request.getMailboxName()); final IdRange[] idSet = request.getIdSet(); final boolean useUids = request.isUseUids(); final SelectedMailbox currentMailbox = session.getSelected(); try {
@Test public void testQuotaParsing() throws DecodingException { CopyCommandParser parser = new CopyCommandParser(); ImapCommand command = ImapCommand.anyStateCommand("Command"); String commandString = " 42:69 foo \n"; InputStream inputStream = new ByteArrayInputStream(commandString.getBytes()); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, null); CopyRequest request = (CopyRequest) parser.decode(command, lineReader, "A003", null); CopyRequest expected = new CopyRequest(command, new IdRange[] {new IdRange(42, 69)}, "foo", false, "A003"); assertThat(request).isEqualTo(expected); } }
@Test public void processShouldNotHandleCopyRequests() { CopyRequest copyRequest = new CopyRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(4, 6)}, ImapConstants.INBOX_NAME, true, TAG); testee.process(copyRequest, mockResponder, mockImapSession); verify(mockNextProcessor).process(copyRequest, mockResponder, mockImapSession); verifyNoMoreInteractions(mockMailboxManager, mockResponder, mockNextProcessor); } }
@Test public void processShouldRespondNoOnUnExistingTargetMailbox() throws Exception { CopyRequest copyRequest = new CopyRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(4, 6)}, ImapConstants.INBOX_NAME, true, TAG); MailboxSession.User user = mock(MailboxSession.User.class); when(user.getUserName()).thenReturn("username"); when(mockMailboxSession.getUser()).thenReturn(user); when(mockMailboxSession.getSessionId()).thenReturn(42L); when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED); when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession); MailboxPath inbox = MailboxPath.inbox(mockMailboxSession); MailboxPath selected = new MailboxPath(inbox, "selected"); SelectedMailbox selectedMailbox = mock(SelectedMailbox.class); when(selectedMailbox.getLastUid()).thenReturn(Optional.of(MessageUid.of(8))); when(selectedMailbox.existsCount()).thenReturn(8L); when(selectedMailbox.getPath()).thenReturn(selected); when(mockImapSession.getSelected()).thenReturn(selectedMailbox); when(mockMailboxManager.mailboxExists(inbox, mockMailboxSession)).thenReturn(false); StatusResponse noResponse = mock(StatusResponse.class); when(mockStatusResponseFactory.taggedNo(any(String.class), any(ImapCommand.class), any(HumanReadableText.class), any(StatusResponse.ResponseCode.class))).thenReturn(noResponse); testee.process(copyRequest, mockResponder, mockImapSession); verify(mockMailboxManager).startProcessingRequest(mockMailboxSession); verify(mockMailboxManager).endProcessingRequest(mockMailboxSession); verify(mockMailboxManager).mailboxExists(inbox, mockMailboxSession); verify(mockResponder).respond(noResponse); verifyNoMoreInteractions(mockMailboxManager, mockResponder, mockNextProcessor); }
@Test public void processShouldRespondNoOnMailboxException() throws Exception { CopyRequest copyRequest = new CopyRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(4, 6)}, ImapConstants.INBOX_NAME, true, TAG); MailboxSession.User user = mock(MailboxSession.User.class); when(user.getUserName()).thenReturn("username"); when(mockMailboxSession.getUser()).thenReturn(user); when(mockMailboxSession.getSessionId()).thenReturn(42L); when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED); when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession); MailboxPath inbox = MailboxPath.inbox(mockMailboxSession); MailboxPath selected = new MailboxPath(inbox, "selected"); SelectedMailbox selectedMailbox = mock(SelectedMailbox.class); when(selectedMailbox.getLastUid()).thenReturn(Optional.of(MessageUid.of(8))); when(selectedMailbox.existsCount()).thenReturn(8L); when(selectedMailbox.getPath()).thenReturn(selected); when(mockImapSession.getSelected()).thenReturn(selectedMailbox); when(mockMailboxManager.mailboxExists(inbox, mockMailboxSession)).thenThrow(new MailboxException()); StatusResponse noResponse = mock(StatusResponse.class); when(mockStatusResponseFactory.taggedNo(any(String.class), any(ImapCommand.class), any(HumanReadableText.class))).thenReturn(noResponse); testee.process(copyRequest, mockResponder, mockImapSession); verify(mockMailboxManager).startProcessingRequest(mockMailboxSession); verify(mockMailboxManager).endProcessingRequest(mockMailboxSession); verify(mockMailboxManager).mailboxExists(inbox, mockMailboxSession); verify(mockResponder).respond(noResponse); verifyNoMoreInteractions(mockMailboxManager, mockResponder, mockNextProcessor); }
@Test public void processShouldWorkWithMultipleRanges() throws Exception { CopyRequest copyRequest = new CopyRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(5, 6), new IdRange(1, 3)}, ImapConstants.INBOX_NAME, true, TAG);
@Test public void processShouldWork() throws Exception { CopyRequest copyRequest = new CopyRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(4, 6)}, ImapConstants.INBOX_NAME, true, TAG);