public ImapResponse readResponse() throws IOException, MessagingException { return readResponse(null); }
private void setupSingleFetchResponseToCallback() throws IOException { when(imapConnection.readResponse(nullable(ImapResponseCallback.class))) .thenAnswer(new Answer<ImapResponse>() { @Override public ImapResponse answer(InvocationOnMock invocation) throws Throwable { ImapResponseCallback callback = (ImapResponseCallback) invocation.getArguments()[0]; return buildImapFetchResponse(callback); } }) .thenAnswer(new Answer<ImapResponse>() { @Override public ImapResponse answer(InvocationOnMock invocation) throws Throwable { ImapResponseCallback callback = (ImapResponseCallback) invocation.getArguments()[0]; return ImapResponse.newTaggedResponse(callback, "TAG"); } }); }
private ImapResponse readContinuationResponse(String tag) throws IOException, MessagingException { ImapResponse response; do { response = readResponse(); String responseTag = response.getTag(); if (responseTag != null) { if (responseTag.equalsIgnoreCase(tag)) { throw new MessagingException("Command continuation aborted: " + response); } else { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, getLogId()); } } } while (!response.isContinuationRequested()); return response; }
response = connection.readResponse(callback);
@Test public void appendMessages_shouldIssueRespectiveCommand() throws Exception { ImapFolder folder = createFolder("Folder"); prepareImapFolderForOpen(OPEN_MODE_RW); folder.open(OPEN_MODE_RW); List<ImapMessage> messages = createImapMessages("1"); when(imapConnection.readResponse()).thenReturn(createImapResponse("x OK [APPENDUID 1 23]")); folder.appendMessages(messages); verify(imapConnection).sendCommand("APPEND \"Folder\" () {0}", false); }
@Test public void fetch_withBodySaneFetchProfile_shouldIssueRespectiveCommand() throws Exception { ImapFolder folder = createFolder("Folder"); prepareImapFolderForOpen(OPEN_MODE_RO); folder.open(OPEN_MODE_RO); when(imapConnection.readResponse(nullable(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK")); List<ImapMessage> messages = createImapMessages("1"); FetchProfile fetchProfile = createFetchProfile(Item.BODY_SANE); when(storeConfig.getMaximumAutoDownloadMessageSize()).thenReturn(4096); folder.fetch(messages, fetchProfile, null); verify(imapConnection).sendCommand("UID FETCH 1 (UID BODY.PEEK[]<0.4096>)", false); }
@Test public void fetch_withBodySaneFetchProfileAndNoMaximumDownloadSize_shouldIssueRespectiveCommand() throws Exception { ImapFolder folder = createFolder("Folder"); prepareImapFolderForOpen(OPEN_MODE_RO); folder.open(OPEN_MODE_RO); when(imapConnection.readResponse(nullable(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK")); List<ImapMessage> messages = createImapMessages("1"); FetchProfile fetchProfile = createFetchProfile(Item.BODY_SANE); when(storeConfig.getMaximumAutoDownloadMessageSize()).thenReturn(0); folder.fetch(messages, fetchProfile, null); verify(imapConnection).sendCommand("UID FETCH 1 (UID BODY.PEEK[])", false); }
@Test public void fetchPart_withTextSection_shouldIssueRespectiveCommand() throws Exception { ImapFolder folder = createFolder("Folder"); prepareImapFolderForOpen(OPEN_MODE_RO); when(storeConfig.getMaximumAutoDownloadMessageSize()).thenReturn(4096); folder.open(OPEN_MODE_RO); ImapMessage message = createImapMessage("1"); Part part = createPart("TEXT"); when(imapConnection.readResponse(nullable(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK")); folder.fetchPart(message, part, null, null); verify(imapConnection).sendCommand("UID FETCH 1 (UID BODY.PEEK[TEXT]<0.4096>)", false); }
@Test public void fetch_withFlagsFetchProfile_shouldIssueRespectiveCommand() throws Exception { ImapFolder folder = createFolder("Folder"); prepareImapFolderForOpen(OPEN_MODE_RO); folder.open(OPEN_MODE_RO); when(imapConnection.readResponse(nullable(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK")); List<ImapMessage> messages = createImapMessages("1"); FetchProfile fetchProfile = createFetchProfile(Item.FLAGS); folder.fetch(messages, fetchProfile, null); verify(imapConnection).sendCommand("UID FETCH 1 (UID FLAGS)", false); }
@Test public void fetch_withStructureFetchProfile_shouldSetContentType() throws Exception { ImapFolder folder = createFolder("Folder"); prepareImapFolderForOpen(OPEN_MODE_RO); folder.open(OPEN_MODE_RO); String bodyStructure = "(\"TEXT\" \"PLAIN\" (\"CHARSET\" \"US-ASCII\") NIL NIL \"7BIT\" 2279 48)"; when(imapConnection.readResponse(nullable(ImapResponseCallback.class))) .thenReturn(createImapResponse("* 1 FETCH (BODYSTRUCTURE "+bodyStructure+" UID 1)")) .thenReturn(createImapResponse("x OK")); List<ImapMessage> messages = createImapMessages("1"); FetchProfile fetchProfile = createFetchProfile(Item.STRUCTURE); folder.fetch(messages, fetchProfile, null); verify(messages.get(0)).setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/plain;\r\n CHARSET=\"US-ASCII\""); }
@Test public void fetch_withFlagsFetchProfile_shouldSetFlags() throws Exception { ImapFolder folder = createFolder("Folder"); prepareImapFolderForOpen(OPEN_MODE_RO); folder.open(OPEN_MODE_RO); List<ImapMessage> messages = createImapMessages("1"); FetchProfile fetchProfile = createFetchProfile(Item.FLAGS); when(imapConnection.readResponse(nullable(ImapResponseCallback.class))) .thenReturn(createImapResponse("* 1 FETCH (FLAGS (\\Seen) UID 1)")) .thenReturn(createImapResponse("x OK")); folder.fetch(messages, fetchProfile, null); ImapMessage imapMessage = messages.get(0); verify(imapMessage).setFlagInternal(Flag.SEEN, true); }
@Test public void fetch_withStructureFetchProfile_shouldIssueRespectiveCommand() throws Exception { ImapFolder folder = createFolder("Folder"); prepareImapFolderForOpen(OPEN_MODE_RO); folder.open(OPEN_MODE_RO); when(imapConnection.readResponse(nullable(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK")); List<ImapMessage> messages = createImapMessages("1"); FetchProfile fetchProfile = createFetchProfile(Item.STRUCTURE); folder.fetch(messages, fetchProfile, null); verify(imapConnection).sendCommand("UID FETCH 1 (UID BODYSTRUCTURE)", false); }
@Test public void fetch_withBodyFetchProfileAndNoMaximumDownloadSize_shouldIssueRespectiveCommand() throws Exception { ImapFolder folder = createFolder("Folder"); prepareImapFolderForOpen(OPEN_MODE_RO); folder.open(OPEN_MODE_RO); when(imapConnection.readResponse(nullable(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK")); List<ImapMessage> messages = createImapMessages("1"); FetchProfile fetchProfile = createFetchProfile(Item.BODY); folder.fetch(messages, fetchProfile, null); verify(imapConnection).sendCommand("UID FETCH 1 (UID BODY.PEEK[])", false); }
@Test public void fetchPart_withNonTextSection_shouldIssueRespectiveCommand() throws Exception { ImapFolder folder = createFolder("Folder"); prepareImapFolderForOpen(OPEN_MODE_RO); folder.open(OPEN_MODE_RO); ImapMessage message = createImapMessage("1"); Part part = createPart("1.1"); when(imapConnection.readResponse(nullable(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK")); folder.fetchPart(message, part, null, null); verify(imapConnection).sendCommand("UID FETCH 1 (UID BODY.PEEK[1.1])", false); }
@Test public void fetch_withEnvelopeFetchProfile_shouldIssueRespectiveCommand() throws Exception { ImapFolder folder = createFolder("Folder"); prepareImapFolderForOpen(OPEN_MODE_RO); folder.open(OPEN_MODE_RO); when(imapConnection.readResponse(nullable(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK")); List<ImapMessage> messages = createImapMessages("1"); FetchProfile fetchProfile = createFetchProfile(Item.ENVELOPE); folder.fetch(messages, fetchProfile, null); verify(imapConnection).sendCommand("UID FETCH 1 (UID INTERNALDATE RFC822.SIZE BODY.PEEK[HEADER.FIELDS " + "(date subject from content-type to cc reply-to message-id references in-reply-to X-K9mail-Identity)]" + ")", false); }
response = connection.readResponse(callback);
response = connection.readResponse();
@Test public void sendContinuation() throws Exception { settings.setAuthType(AuthType.PLAIN); MockImapServer server = new MockImapServer(); simpleOpenDialog(server, "IDLE"); server.expect("4 IDLE"); server.output("+ idling"); server.expect("DONE"); ImapConnection imapConnection = startServerAndCreateImapConnection(server); imapConnection.open(); imapConnection.sendCommand("IDLE", false); imapConnection.readResponse(); imapConnection.sendContinuation("DONE"); server.waitForInteractionToComplete(); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); }