protected void no(final ImapCommand command, final String tag, final ImapProcessor.Responder responder, final HumanReadableText displayTextKey) { final StatusResponse response = factory.taggedNo(tag, command, displayTextKey); responder.respond(response); }
protected void no(ImapCommand command, String tag, ImapProcessor.Responder responder, HumanReadableText displayTextKey) { final StatusResponse response = factory.taggedNo(tag, command, displayTextKey); responder.respond(response); }
protected void no(ImapCommand command, String tag, ImapProcessor.Responder responder, HumanReadableText displayTextKey, StatusResponse.ResponseCode responseCode) { final StatusResponse response = factory.taggedNo(tag, command, displayTextKey, responseCode); responder.respond(response); }
protected void no(final ImapCommand command, final String tag, final ImapProcessor.Responder responder, final HumanReadableText displayTextKey, final StatusResponse.ResponseCode responseCode) { final StatusResponse response = factory.taggedNo(tag, command, displayTextKey, responseCode); responder.respond(response); }
private ImapMessage unsupportedCharset(String tag, ImapCommand command) { final StatusResponseFactory factory = getStatusResponseFactory(); final ResponseCode badCharset = StatusResponse.ResponseCode.badCharset(CharsetUtil.getAvailableCharsetNames()); return factory.taggedNo(tag, command, HumanReadableText.BAD_CHARSET, badCharset); }
private ImapMessage unsupportedCharset(final String tag, final ImapCommand command) { final StatusResponseFactory factory = getStatusResponseFactory(); final ResponseCode badCharset = StatusResponse.ResponseCode.badCharset(CharsetUtil.getAvailableCharsetNames()); final StatusResponse result = factory.taggedNo(tag, command, HumanReadableText.BAD_CHARSET, badCharset); return result; }
@Test public void processShouldResponseNoWithNoSuchMailboxWhenManagerThrowMailboxNotFoundException() throws Exception { doThrow(MailboxNotFoundException.class).when(mockMailboxManager).updateAnnotations(eq(inbox), eq(mockMailboxSession), eq(mailboxAnnotations)); processor.process(request, mockResponder, mockImapSession); verify(mockStatusResponseFactory, times(1)).taggedNo(any(String.class), any(ImapCommand.class), humanTextCaptor.capture(), any(StatusResponse.ResponseCode.class)); assertThat(humanTextCaptor.getAllValues()).containsOnly(HumanReadableText.FAILURE_NO_SUCH_MAILBOX); }
@Test public void processShouldResponseNoWithGenericFailureWhenManagerThrowMailboxException() throws Exception { doThrow(MailboxException.class).when(mockMailboxManager).updateAnnotations(eq(inbox), eq(mockMailboxSession), eq(mailboxAnnotations)); processor.process(request, mockResponder, mockImapSession); verify(mockStatusResponseFactory, times(1)).taggedNo(any(String.class), any(ImapCommand.class), humanTextCaptor.capture()); assertThat(humanTextCaptor.getAllValues()).containsOnly(HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING); }
@Test public void processShouldResponseNoWithGenericFailureWhenManagerThrowMailboxException() throws Exception { doThrow(MailboxException.class).when(mockMailboxManager).getAllAnnotations(eq(inbox), eq(mailboxSession)); when(mockStatusResponseFactory.taggedNo(any(String.class), any(ImapCommand.class), any(HumanReadableText.class))) .thenReturn(statusResponse); processor.process(annotationRequestBuilder.build(), mockResponder, mockImapSession); verify(mockStatusResponseFactory, times(1)).taggedNo(any(String.class), any(ImapCommand.class), humanTextCaptor.capture()); verify(mockResponder).respond(statusResponse); verifyNoMoreInteractions(mockResponder); assertThat(humanTextCaptor.getAllValues()).containsOnly(HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING); }
@Test public void processShouldResponseNoWhenManagerThrowsAnnotationException() throws Exception { doThrow(AnnotationException.class).when(mockMailboxManager).updateAnnotations(eq(inbox), eq(mockMailboxSession), eq(mailboxAnnotations)); processor.process(request, mockResponder, mockImapSession); verify(mockStatusResponseFactory, times(1)).taggedNo(any(String.class), any(ImapCommand.class), humanTextCaptor.capture()); assertThat(humanTextCaptor.getAllValues().get(FIRST_ELEMENT_INDEX).getKey()).isEqualTo(HumanReadableText.MAILBOX_ANNOTATION_KEY); } }
@Override protected void doProcess(M request, ImapSession session, String tag, ImapCommand command, Responder responder) { final String mailboxName = request.getMailboxName(); try { final MailboxPath fullMailboxPath = PathConverter.forSession(session).buildFullPath(mailboxName); respond(tag, command, session, fullMailboxPath, request, responder); } catch (MailboxNotFoundException e) { LOGGER.debug("Select failed as mailbox does not exist {}", mailboxName, e); responder.respond(statusResponseFactory.taggedNo(tag, command, HumanReadableText.FAILURE_NO_SUCH_MAILBOX)); } catch (MailboxException e) { LOGGER.error("Select failed for mailbox {}", mailboxName, e); no(command, tag, responder, HumanReadableText.SELECT); } }
@Test public void processShouldResponseNoWithFailureWhenMailboxDoesNotExist() throws Exception { doThrow(MailboxNotFoundException.class).when(mockMailboxManager).getAllAnnotations(eq(inbox), eq(mailboxSession)); when(mockStatusResponseFactory.taggedNo(any(String.class), any(ImapCommand.class), any(HumanReadableText.class), any(ResponseCode.class))) .thenReturn(statusResponse); processor.process(annotationRequestBuilder.build(), mockResponder, mockImapSession); verify(mockStatusResponseFactory, times(1)).taggedNo(any(String.class), any(ImapCommand.class), humanTextCaptor.capture(), captorResponsecode.capture()); verify(mockResponder).respond(statusResponse); verifyNoMoreInteractions(mockResponder); assertThat(humanTextCaptor.getAllValues()).containsOnly(HumanReadableText.FAILURE_NO_SUCH_MAILBOX); assertThat(captorResponsecode.getAllValues()).containsOnly(ResponseCode.tryCreate()); }
@Test public void testBadCharset() throws Exception { ImapRequestLineReader reader = new ImapRequestStreamLineReader( new ByteArrayInputStream("CHARSET BOGUS ".getBytes("US-ASCII")), new ByteArrayOutputStream()); parser.decode(command, reader, TAG, false, session); verify(mockStatusResponseFactory, times(1)).taggedNo( eq(TAG), same(command), eq(HumanReadableText.BAD_CHARSET), eq(StatusResponse.ResponseCode.badCharset(CharsetUtil.getAvailableCharsetNames()))); verifyNoMoreInteractions(mockStatusResponseFactory); }
@Test public void testBadCharset() throws Exception { ImapRequestLineReader reader = new ImapRequestStreamLineReader( new ByteArrayInputStream("CHARSET BOGUS ".getBytes("US-ASCII")), new ByteArrayOutputStream()); parser.decode(command, reader, TAG, false, session); verify(mockStatusResponseFactory, times(1)).taggedNo( eq(TAG), same(command), eq(HumanReadableText.BAD_CHARSET), eq(StatusResponse.ResponseCode.badCharset(CharsetUtil.getAvailableCharsetNames()))); verifyNoMoreInteractions(mockStatusResponseFactory); }
/** * Parses a request into a command message for later processing. * * @param request * <code>ImapRequestLineReader</code>, not null * @return <code>ImapCommandMessage</code>, not null */ @Override public final ImapMessage parse(ImapRequestLineReader request, String tag, ImapSession session) { ImapMessage result; if (!command.validForState(session.getState())) { result = statusResponseFactory.taggedNo(tag, command, HumanReadableText.INVALID_COMMAND); } else { try { result = decode(command, request, tag, session); } catch (DecodingException e) { LOGGER.debug("Cannot parse protocol ", e); result = statusResponseFactory.taggedBad(tag, command, e.getKey()); } } return result; }
/** * @see * org.apache.james.imap.processor.AbstractMailboxProcessor#doProcess(org.apache.james.imap.api.message.request.ImapRequest, * org.apache.james.imap.api.process.ImapSession, java.lang.String, * org.apache.james.imap.api.ImapCommand, * org.apache.james.imap.api.process.ImapProcessor.Responder) */ protected void doProcess(AbstractMailboxSelectionRequest request, ImapSession session, String tag, ImapCommand command, Responder responder) { final String mailboxName = request.getMailboxName(); try { final MailboxPath fullMailboxPath = buildFullPath(session, mailboxName); respond(tag, command, session, fullMailboxPath, request, responder); } catch (MailboxNotFoundException e) { session.getLog().debug("Select failed as mailbox does not exist " + mailboxName, e); responder.respond(statusResponseFactory.taggedNo(tag, command, HumanReadableText.FAILURE_NO_SUCH_MAILBOX)); } catch (MailboxException e) { session.getLog().info("Select failed for mailbox " + mailboxName , e); no(command, tag, responder, HumanReadableText.SELECT); } }
@Test public void testTaggedNo() { StatusResponse response = factory.taggedNo(TAG, command, KEY); assertThat(response).isNotNull(); assertThat(response.getServerResponseType()).isEqualTo(StatusResponse.Type.NO); assertThat(response.getTag()).isEqualTo(TAG); assertThat(response.getTextKey()).isEqualTo(KEY); assertThat(response.getCommand()).isEqualTo(command); assertThat(response.getResponseCode()).isNull(); response = factory.taggedNo(TAG, command, KEY, CODE); assertThat(response).isNotNull(); assertThat(response.getServerResponseType()).isEqualTo(StatusResponse.Type.NO); assertThat(response.getTag()).isEqualTo(TAG); assertThat(response.getTextKey()).isEqualTo(KEY); assertThat(response.getResponseCode()).isEqualTo(CODE); assertThat(response.getCommand()).isEqualTo(command); }
final void doProcess(final M message, final ImapCommand command, final String tag, Responder responder, ImapSession session) { if (!command.validForState(session.getState())) { ImapResponseMessage response = factory.taggedNo(tag, command, HumanReadableText.INVALID_COMMAND); responder.respond(response); } else { getMailboxManager().startProcessingRequest(ImapSessionUtils.getMailboxSession(session)); doProcess(message, session, tag, command, responder); getMailboxManager().endProcessingRequest(ImapSessionUtils.getMailboxSession(session)); } }
final void doProcess(M message, ImapCommand command, String tag, Responder responder, ImapSession session) { try { if (!command.validForState(session.getState())) { ImapResponseMessage response = factory.taggedNo(tag, command, HumanReadableText.INVALID_COMMAND); responder.respond(response); } else { getMailboxManager().startProcessingRequest(ImapSessionUtils.getMailboxSession(session)); doProcess(message, session, tag, command, responder); getMailboxManager().endProcessingRequest(ImapSessionUtils.getMailboxSession(session)); } } catch (DeniedAccessOnSharedMailboxException e) { no(command, tag, responder, HumanReadableText.DENIED_SHARED_MAILBOX); } }
@Override protected void doProcess(CompressRequest request, Responder responder, ImapSession session) { if (session.isCompressionSupported()) { Object obj = session.getAttribute(COMPRESSED); if (obj != null) { responder.respond(factory.taggedNo(request.getTag(), request.getCommand(), HumanReadableText.COMPRESS_ALREADY_ACTIVE)); } else { if (request.getAlgorithm().equalsIgnoreCase(ALGO) == false) { responder.respond(factory.taggedBad(request.getTag(), request.getCommand(), HumanReadableText.ILLEGAL_ARGUMENTS)); } else { responder.respond(factory.taggedOk(request.getTag(), request.getCommand(), HumanReadableText.DEFLATE_ACTIVE)); if (session.startCompression()) { session.setAttribute(COMPRESSED, true); } } } } else { responder.respond(factory.taggedBad(request.getTag(), request.getCommand(), HumanReadableText.UNKNOWN_COMMAND)); } }