private List<ImapResponse> saslAuthPlain() throws IOException, MessagingException { String command = Commands.AUTHENTICATE_PLAIN; String tag = sendCommand(command, false); readContinuationResponse(tag); String credentials = "\000" + settings.getUsername() + "\000" + settings.getPassword(); byte[] encodedCredentials = Base64.encodeBase64(credentials.getBytes()); outputStream.write(encodedCredentials); outputStream.write('\r'); outputStream.write('\n'); outputStream.flush(); try { return responseParser.readStatusResponse(tag, command, getLogId(), null); } catch (NegativeImapResponseException e) { throw handleAuthenticationFailure(e); } }
public List<ImapResponse> executeSimpleCommand(String command, boolean sensitive) throws IOException, MessagingException { String commandToLog = command; if (sensitive && !K9MailLib.isDebugSensitive()) { commandToLog = "*sensitive*"; } String tag = sendCommand(command, sensitive); try { return responseParser.readStatusResponse(tag, commandToLog, getLogId(), null); } catch (IOException e) { close(); throw e; } }
private List<ImapResponse> authCramMD5() throws MessagingException, IOException { String command = Commands.AUTHENTICATE_CRAM_MD5; String tag = sendCommand(command, false); ImapResponse response = readContinuationResponse(tag); if (response.size() != 1 || !(response.get(0) instanceof String)) { throw new MessagingException("Invalid Cram-MD5 nonce received"); } byte[] b64Nonce = response.getString(0).getBytes(); byte[] b64CRAM = Authentication.computeCramMd5Bytes(settings.getUsername(), settings.getPassword(), b64Nonce); outputStream.write(b64CRAM); outputStream.write('\r'); outputStream.write('\n'); outputStream.flush(); try { return responseParser.readStatusResponse(tag, command, getLogId(), null); } catch (NegativeImapResponseException e) { throw handleAuthenticationFailure(e); } }
private void sendIdle(ImapConnection conn) throws MessagingException, IOException { String tag = conn.sendCommand(Commands.IDLE, false); List<ImapResponse> responses; try { try { responses = conn.readStatusResponse(tag, Commands.IDLE, this); } finally { idleStopper.stopAcceptingDoneContinuation(); } } catch (IOException e) { conn.close(); throw e; } handleUntaggedResponses(responses); }
String commaSeparatedUids = ImapUtility.join(",", uidWindow); String command = String.format("UID FETCH %s (%s)", commaSeparatedUids, spaceSeparatedFetchFields); connection.sendCommand(command, 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 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 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_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_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_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); }
connection.sendCommand(command, false);
String command = String.format(Locale.US, "APPEND %s (%s) {%d}", escapedFolderName, combinedFlags, messageSize); connection.sendCommand(command, false);
@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(); }