Loading mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapConnection.java +12 −20 Original line number Diff line number Diff line Loading @@ -265,31 +265,24 @@ class ImapConnection { extractCapabilities(Collections.singletonList(initialResponse)); } private List<ImapResponse> extractCapabilities(List<ImapResponse> responses) { private boolean extractCapabilities(List<ImapResponse> responses) { CapabilityResponse capabilityResponse = CapabilityResponse.parse(responses); if (capabilityResponse != null) { Set<String> receivedCapabilities = capabilityResponse.getCapabilities(); if (K9MailLib.isDebug()) { Timber.d("Saving %s capabilities for %s", receivedCapabilities, getLogId()); } capabilities = receivedCapabilities; } return responses; if (capabilityResponse == null) { return false; } private List<ImapResponse> extractOrRequestCapabilities(List<ImapResponse> responses) throws IOException, MessagingException { CapabilityResponse capabilityResponse = CapabilityResponse.parse(responses); if (capabilityResponse != null) { Set<String> receivedCapabilities = capabilityResponse.getCapabilities(); Timber.d("Saving %s capabilities for %s", receivedCapabilities, getLogId()); capabilities = receivedCapabilities; } else { return true; } private void extractOrRequestCapabilities(List<ImapResponse> responses) throws IOException, MessagingException { if (!extractCapabilities(responses)) { Timber.i("Did not get capabilities in post-auth banner, requesting CAPABILITY for %s", getLogId()); requestCapabilities(); } return responses; } private void requestCapabilitiesIfNecessary() throws IOException, MessagingException { Loading @@ -303,8 +296,7 @@ class ImapConnection { } private void requestCapabilities() throws IOException, MessagingException { List<ImapResponse> responses = extractCapabilities(executeSimpleCommand(Commands.CAPABILITY)); if (responses.size() != 2) { if (!extractCapabilities(executeSimpleCommand(Commands.CAPABILITY))) { throw new MessagingException("Invalid CAPABILITY response received"); } } Loading mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapConnectionTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -691,6 +691,30 @@ public class ImapConnectionTest { server.verifyInteractionCompleted(); } @Test public void open_withUntaggedCapabilityAfterStartTls_shouldNotThrow() throws Exception { settings.setAuthType(AuthType.PLAIN); settings.setConnectionSecurity(ConnectionSecurity.STARTTLS_REQUIRED); MockImapServer server = new MockImapServer(); preAuthenticationDialog(server, "STARTTLS LOGINDISABLED"); server.expect("2 STARTTLS"); server.output("2 OK Begin TLS negotiation now"); server.startTls(); server.output("* CAPABILITY IMAP4REV1 IMAP4"); server.expect("3 CAPABILITY"); server.output("* CAPABILITY IMAP4 IMAP4REV1"); server.output("3 OK"); server.expect("4 LOGIN \"" + USERNAME + "\" \"" + PASSWORD + "\""); server.output("4 OK [CAPABILITY IMAP4REV1] LOGIN completed"); simplePostAuthenticationDialog(server, 5); ImapConnection imapConnection = startServerAndCreateImapConnection(server); imapConnection.open(); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); } @Test public void open_withNegativeResponseToStartTlsCommand_shouldThrow() throws Exception { settings.setAuthType(AuthType.PLAIN); Loading Loading
mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapConnection.java +12 −20 Original line number Diff line number Diff line Loading @@ -265,31 +265,24 @@ class ImapConnection { extractCapabilities(Collections.singletonList(initialResponse)); } private List<ImapResponse> extractCapabilities(List<ImapResponse> responses) { private boolean extractCapabilities(List<ImapResponse> responses) { CapabilityResponse capabilityResponse = CapabilityResponse.parse(responses); if (capabilityResponse != null) { Set<String> receivedCapabilities = capabilityResponse.getCapabilities(); if (K9MailLib.isDebug()) { Timber.d("Saving %s capabilities for %s", receivedCapabilities, getLogId()); } capabilities = receivedCapabilities; } return responses; if (capabilityResponse == null) { return false; } private List<ImapResponse> extractOrRequestCapabilities(List<ImapResponse> responses) throws IOException, MessagingException { CapabilityResponse capabilityResponse = CapabilityResponse.parse(responses); if (capabilityResponse != null) { Set<String> receivedCapabilities = capabilityResponse.getCapabilities(); Timber.d("Saving %s capabilities for %s", receivedCapabilities, getLogId()); capabilities = receivedCapabilities; } else { return true; } private void extractOrRequestCapabilities(List<ImapResponse> responses) throws IOException, MessagingException { if (!extractCapabilities(responses)) { Timber.i("Did not get capabilities in post-auth banner, requesting CAPABILITY for %s", getLogId()); requestCapabilities(); } return responses; } private void requestCapabilitiesIfNecessary() throws IOException, MessagingException { Loading @@ -303,8 +296,7 @@ class ImapConnection { } private void requestCapabilities() throws IOException, MessagingException { List<ImapResponse> responses = extractCapabilities(executeSimpleCommand(Commands.CAPABILITY)); if (responses.size() != 2) { if (!extractCapabilities(executeSimpleCommand(Commands.CAPABILITY))) { throw new MessagingException("Invalid CAPABILITY response received"); } } Loading
mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapConnectionTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -691,6 +691,30 @@ public class ImapConnectionTest { server.verifyInteractionCompleted(); } @Test public void open_withUntaggedCapabilityAfterStartTls_shouldNotThrow() throws Exception { settings.setAuthType(AuthType.PLAIN); settings.setConnectionSecurity(ConnectionSecurity.STARTTLS_REQUIRED); MockImapServer server = new MockImapServer(); preAuthenticationDialog(server, "STARTTLS LOGINDISABLED"); server.expect("2 STARTTLS"); server.output("2 OK Begin TLS negotiation now"); server.startTls(); server.output("* CAPABILITY IMAP4REV1 IMAP4"); server.expect("3 CAPABILITY"); server.output("* CAPABILITY IMAP4 IMAP4REV1"); server.output("3 OK"); server.expect("4 LOGIN \"" + USERNAME + "\" \"" + PASSWORD + "\""); server.output("4 OK [CAPABILITY IMAP4REV1] LOGIN completed"); simplePostAuthenticationDialog(server, 5); ImapConnection imapConnection = startServerAndCreateImapConnection(server); imapConnection.open(); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); } @Test public void open_withNegativeResponseToStartTlsCommand_shouldThrow() throws Exception { settings.setAuthType(AuthType.PLAIN); Loading