target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test public void open_authPlainWithAuthenticationFailure_shouldFallbackToLogin() throws Exception { settings.setAuthType(AuthType.PLAIN); MockImapServer server = new MockImapServer(); preAuthenticationDialog(server, "AUTH=PLAIN"); server.expect("2 AUTHENTICATE PLAIN"); server.output("+"); server.expect(ByteString.encodeUtf8("\000" + USERNAME + "\000" + PASSWORD).base64()); server.output("2 NO Login Failure"); server.expect("3 LOGIN \"" + USERNAME + "\" \"" + PASSWORD + "\""); server.output("3 OK LOGIN completed"); postAuthenticationDialogRequestingCapabilities(server, 4); ImapConnection imapConnection = startServerAndCreateImapConnection(server); imapConnection.open(); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void open_authPlainAndLoginFallbackWithAuthenticationFailure_shouldThrow() throws Exception { settings.setAuthType(AuthType.PLAIN); MockImapServer server = new MockImapServer(); preAuthenticationDialog(server, "AUTH=PLAIN"); server.expect("2 AUTHENTICATE PLAIN"); server.output("+"); server.expect(ByteString.encodeUtf8("\000" + USERNAME + "\000" + PASSWORD).base64()); server.output("2 NO Login Failure"); server.expect("3 LOGIN \"" + USERNAME + "\" \"" + PASSWORD + "\""); server.output("3 NO Go away"); ImapConnection imapConnection = startServerAndCreateImapConnection(server); try { imapConnection.open(); fail("Expected exception"); } catch (AuthenticationFailedException e) { assertThat(e.getMessage(), containsString("Go away")); } server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void open_authPlainWithByeResponseAndConnectionClose_shouldThrowAuthenticationFailedException() throws Exception { settings.setAuthType(AuthType.PLAIN); MockImapServer server = new MockImapServer(); preAuthenticationDialog(server, "AUTH=PLAIN"); server.expect("2 AUTHENTICATE PLAIN"); server.output("+"); server.expect(ByteString.encodeUtf8("\000" + USERNAME + "\000" + PASSWORD).base64()); server.output("* BYE Go away"); server.output("2 NO Login Failure"); server.closeConnection(); ImapConnection imapConnection = startServerAndCreateImapConnection(server); try { imapConnection.open(); fail("Expected exception"); } catch (AuthenticationFailedException e) { assertThat(e.getMessage(), containsString("Login Failure")); } server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void open_authPlainWithoutAuthPlainCapability_shouldUseLoginMethod() throws Exception { settings.setAuthType(AuthType.PLAIN); MockImapServer server = new MockImapServer(); preAuthenticationDialog(server); server.expect("2 LOGIN \"" + USERNAME + "\" \"" + PASSWORD + "\""); server.output("2 OK LOGIN completed"); postAuthenticationDialogRequestingCapabilities(server); ImapConnection imapConnection = startServerAndCreateImapConnection(server); imapConnection.open(); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void uriWithUppercaseScheme() { String uri = "HTTP: UriLinkifier.linkifyText(uri, outputBuffer); assertEquals("<a href=\"HTTP: } | public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } | UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } } | UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } } | UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } static void linkifyText(String text, StringBuffer outputBuffer); } | UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } static void linkifyText(String text, StringBuffer outputBuffer); } |
@Test public void open_authCramMd5() throws Exception { settings.setAuthType(AuthType.CRAM_MD5); MockImapServer server = new MockImapServer(); preAuthenticationDialog(server, "AUTH=CRAM-MD5"); server.expect("2 AUTHENTICATE CRAM-MD5"); server.output("+ " + ByteString.encodeUtf8("<[email protected]>").base64()); server.expect("dXNlciA2ZjdiOTcyYjk5YTI4NDk4OTRhN2YyMmE3MGRhZDg0OQ=="); server.output("2 OK Success"); postAuthenticationDialogRequestingCapabilities(server); ImapConnection imapConnection = startServerAndCreateImapConnection(server); imapConnection.open(); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void open_authCramMd5WithAuthenticationFailure_shouldThrow() throws Exception { settings.setAuthType(AuthType.CRAM_MD5); MockImapServer server = new MockImapServer(); preAuthenticationDialog(server, "AUTH=CRAM-MD5"); server.expect("2 AUTHENTICATE CRAM-MD5"); server.output("+ " + ByteString.encodeUtf8("<[email protected]>").base64()); server.expect("dXNlciA2ZjdiOTcyYjk5YTI4NDk4OTRhN2YyMmE3MGRhZDg0OQ=="); server.output("2 NO Who are you?"); ImapConnection imapConnection = startServerAndCreateImapConnection(server); try { imapConnection.open(); fail("Expected exception"); } catch (AuthenticationFailedException e) { assertThat(e.getMessage(), containsString("Who are you?")); } server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void open_authCramMd5WithoutAuthCramMd5Capability_shouldThrow() throws Exception { settings.setAuthType(AuthType.CRAM_MD5); MockImapServer server = new MockImapServer(); preAuthenticationDialog(server, "AUTH=PLAIN"); ImapConnection imapConnection = startServerAndCreateImapConnection(server); try { imapConnection.open(); fail("Expected exception"); } catch (MessagingException e) { assertEquals("Server doesn't support encrypted passwords using CRAM-MD5.", e.getMessage()); } server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void open_authXoauthWithSaslIr() throws Exception { settings.setAuthType(AuthType.XOAUTH2); MockImapServer server = new MockImapServer(); preAuthenticationDialog(server, "SASL-IR AUTH=XOAUTH AUTH=XOAUTH2"); server.expect("2 AUTHENTICATE XOAUTH2 " + XOAUTH_STRING); server.output("2 OK Success"); postAuthenticationDialogRequestingCapabilities(server); ImapConnection imapConnection = startServerAndCreateImapConnection(server); imapConnection.open(); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void open_authXoauthWithSaslIrThrowsExeptionOn401Response() throws Exception { settings.setAuthType(AuthType.XOAUTH2); MockImapServer server = new MockImapServer(); preAuthenticationDialog(server, "SASL-IR AUTH=XOAUTH AUTH=XOAUTH2"); server.expect("2 AUTHENTICATE XOAUTH2 " + XOAUTH_STRING); server.output("+ " + XOAuth2ChallengeParserTest.STATUS_401_RESPONSE); server.expect(""); server.output("2 NO SASL authentication failed"); ImapConnection imapConnection = startServerAndCreateImapConnection(server); try { imapConnection.open(); fail(); } catch (AuthenticationFailedException e) { assertEquals("Command: AUTHENTICATE XOAUTH2; response: #2# [NO, SASL authentication failed]", e.getMessage()); } } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void open_authXoauthWithSaslIrInvalidatesAndRetriesNewTokenOn400Response() throws Exception { settings.setAuthType(AuthType.XOAUTH2); MockImapServer server = new MockImapServer(); preAuthenticationDialog(server, "SASL-IR AUTH=XOAUTH AUTH=XOAUTH2"); server.expect("2 AUTHENTICATE XOAUTH2 " + XOAUTH_STRING); server.output("+ " + XOAuth2ChallengeParserTest.STATUS_400_RESPONSE); server.expect(""); server.output("2 NO SASL authentication failed"); server.expect("3 AUTHENTICATE XOAUTH2 " + XOAUTH_STRING_RETRY); server.output("3 OK Success"); postAuthenticationDialogRequestingCapabilities(server, 4); ImapConnection imapConnection = startServerAndCreateImapConnection(server); imapConnection.open(); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void open_authXoauthWithSaslIrWithOldTokenThrowsExceptionIfRetryFails() throws Exception { settings.setAuthType(AuthType.XOAUTH2); MockImapServer server = new MockImapServer(); preAuthenticationDialog(server, "SASL-IR AUTH=XOAUTH AUTH=XOAUTH2"); server.expect("2 AUTHENTICATE XOAUTH2 " + XOAUTH_STRING); server.output("+ r3j3krj3irj3oir3ojo"); server.expect(""); server.output("2 NO SASL authentication failed"); server.expect("3 AUTHENTICATE XOAUTH2 " + XOAUTH_STRING_RETRY); server.output("+ 433ba3a3a"); server.expect(""); server.output("3 NO SASL authentication failed"); postAuthenticationDialogRequestingCapabilities(server); ImapConnection imapConnection = startServerAndCreateImapConnection(server); try { imapConnection.open(); fail(); } catch (AuthenticationFailedException e) { assertEquals("Command: AUTHENTICATE XOAUTH2; response: #3# [NO, SASL authentication failed]", e.getMessage()); } } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void open_authExternal() throws Exception { settings.setAuthType(AuthType.EXTERNAL); MockImapServer server = new MockImapServer(); preAuthenticationDialog(server, "AUTH=EXTERNAL"); server.expect("2 AUTHENTICATE EXTERNAL " + ByteString.encodeUtf8(USERNAME).base64()); server.output("2 OK Success"); postAuthenticationDialogRequestingCapabilities(server); ImapConnection imapConnection = startServerAndCreateImapConnection(server); imapConnection.open(); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void open_authExternalWithAuthenticationFailure_shouldThrow() throws Exception { settings.setAuthType(AuthType.EXTERNAL); MockImapServer server = new MockImapServer(); preAuthenticationDialog(server, "AUTH=EXTERNAL"); server.expect("2 AUTHENTICATE EXTERNAL " + ByteString.encodeUtf8(USERNAME).base64()); server.output("2 NO Bad certificate"); ImapConnection imapConnection = startServerAndCreateImapConnection(server); try { imapConnection.open(); fail("Expected exception"); } catch (CertificateValidationException e) { assertThat(e.getMessage(), containsString("Bad certificate")); } server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void open_authExternalWithoutAuthExternalCapability_shouldThrow() throws Exception { settings.setAuthType(AuthType.EXTERNAL); MockImapServer server = new MockImapServer(); preAuthenticationDialog(server, "AUTH=PLAIN"); ImapConnection imapConnection = startServerAndCreateImapConnection(server); try { imapConnection.open(); fail("Expected exception"); } catch (CertificateValidationException e) { assertEquals(Reason.MissingCapability, e.getReason()); } server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void uriNotPrecededByValidSeparator_shouldNotBeLinkified() { String text = "myhttp: UriLinkifier.linkifyText(text, outputBuffer); assertEquals(text, outputBuffer.toString()); } | public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } | UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } } | UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } } | UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } static void linkifyText(String text, StringBuffer outputBuffer); } | UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } static void linkifyText(String text, StringBuffer outputBuffer); } |
@Test public void open_withNamespaceCapability_shouldIssueNamespaceCommand() throws Exception { MockImapServer server = new MockImapServer(); simplePreAuthAndLoginDialog(server, "NAMESPACE"); server.expect("3 NAMESPACE"); server.output("* NAMESPACE ((\"\" \"/\")) NIL NIL"); server.output("3 OK command completed"); ImapConnection imapConnection = startServerAndCreateImapConnection(server); imapConnection.open(); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void open_withConnectionError_shouldThrow() throws Exception { settings.setHost("127.1.2.3"); settings.setPort(143); ImapConnection imapConnection = createImapConnection( settings, socketFactory, connectivityManager, oAuth2TokenProvider); try { imapConnection.open(); fail("Expected exception"); } catch (MessagingException e) { assertEquals("Cannot connect to host", e.getMessage()); assertTrue(e.getCause() instanceof IOException); } } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void open_withStartTlsButWithoutStartTlsCapability_shouldThrow() throws Exception { settings.setConnectionSecurity(ConnectionSecurity.STARTTLS_REQUIRED); MockImapServer server = new MockImapServer(); preAuthenticationDialog(server); ImapConnection imapConnection = startServerAndCreateImapConnection(server); try { imapConnection.open(); fail("Expected exception"); } catch (CertificateValidationException e) { assertEquals("STARTTLS connection security not available", e.getMessage()); } server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void open_withNegativeResponseToStartTlsCommand_shouldThrow() throws Exception { settings.setAuthType(AuthType.PLAIN); settings.setConnectionSecurity(ConnectionSecurity.STARTTLS_REQUIRED); MockImapServer server = new MockImapServer(); preAuthenticationDialog(server, "STARTTLS"); server.expect("2 STARTTLS"); server.output("2 NO"); ImapConnection imapConnection = startServerAndCreateImapConnection(server); try { imapConnection.open(); fail("Expected exception"); } catch (NegativeImapResponseException e) { assertEquals(e.getMessage(), "Command: STARTTLS; response: #2# [NO]"); } server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void open_withNegativeResponseToCompressionCommand_shouldContinue() throws Exception { settings.setAuthType(AuthType.PLAIN); settings.setUseCompression(true); MockImapServer server = new MockImapServer(); simplePreAuthAndLoginDialog(server, "COMPRESS=DEFLATE"); server.expect("3 COMPRESS DEFLATE"); server.output("3 NO"); simplePostAuthenticationDialog(server, 4); ImapConnection imapConnection = startServerAndCreateImapConnection(server); imapConnection.open(); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void open_withIoExceptionDuringCompressionCommand_shouldThrow() throws Exception { settings.setAuthType(AuthType.PLAIN); settings.setUseCompression(true); MockImapServer server = new MockImapServer(); simplePreAuthAndLoginDialog(server, "COMPRESS=DEFLATE"); server.expect("3 COMPRESS DEFLATE"); server.closeConnection(); ImapConnection imapConnection = startServerAndCreateImapConnection(server); try { imapConnection.open(); fail("Exception expected"); } catch (IOException ignored) { } server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void open_withIoExceptionDuringListCommand_shouldThrow() throws Exception { settings.setAuthType(AuthType.PLAIN); MockImapServer server = new MockImapServer(); simplePreAuthAndLoginDialog(server, ""); server.expect("3 LIST \"\" \"\""); server.output("* Now what?"); ImapConnection imapConnection = startServerAndCreateImapConnection(server); try { imapConnection.open(); fail("Exception expected"); } catch (IOException ignored) { } server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void open_withNegativeResponseToListCommand() throws Exception { settings.setAuthType(AuthType.PLAIN); MockImapServer server = new MockImapServer(); simplePreAuthAndLoginDialog(server, ""); server.expect("3 LIST \"\" \"\""); server.output("3 NO"); ImapConnection imapConnection = startServerAndCreateImapConnection(server); imapConnection.open(); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); } | public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void open() throws IOException, MessagingException { if (open) { return; } else if (stacktraceForClose != null) { throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose); } open = true; boolean authSuccess = false; nextCommandTag = 1; adjustDNSCacheTTL(); try { socket = connect(); configureSocket(); setUpStreamsAndParserFromSocket(); readInitialResponse(); requestCapabilitiesIfNecessary(); upgradeToTlsIfNecessary(); List<ImapResponse> responses = authenticate(); authSuccess = true; extractOrRequestCapabilities(responses); enableCompressionIfRequested(); retrievePathPrefixIfNecessary(); retrievePathDelimiterIfNecessary(); } catch (SSLException e) { handleSslException(e); } catch (ConnectException e) { handleConnectException(e); } catch (GeneralSecurityException e) { throw new MessagingException("Unable to open connection to IMAP server due to security error.", e); } finally { if (!authSuccess) { Timber.e("Failed to login, closing connection for %s", getLogId()); close(); } } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void isConnected_withoutPreviousOpen_shouldReturnFalse() throws Exception { ImapConnection imapConnection = createImapConnection( settings, socketFactory, connectivityManager, oAuth2TokenProvider); boolean result = imapConnection.isConnected(); assertFalse(result); } | public boolean isConnected() { return inputStream != null && outputStream != null && socket != null && socket.isConnected() && !socket.isClosed(); } | ImapConnection { public boolean isConnected() { return inputStream != null && outputStream != null && socket != null && socket.isConnected() && !socket.isClosed(); } } | ImapConnection { public boolean isConnected() { return inputStream != null && outputStream != null && socket != null && socket.isConnected() && !socket.isClosed(); } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public boolean isConnected() { return inputStream != null && outputStream != null && socket != null && socket.isConnected() && !socket.isClosed(); } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public boolean isConnected() { return inputStream != null && outputStream != null && socket != null && socket.isConnected() && !socket.isClosed(); } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void isConnected_afterOpen_shouldReturnTrue() throws Exception { MockImapServer server = new MockImapServer(); ImapConnection imapConnection = simpleOpen(server); boolean result = imapConnection.isConnected(); assertTrue(result); server.verifyConnectionStillOpen(); server.shutdown(); } | public boolean isConnected() { return inputStream != null && outputStream != null && socket != null && socket.isConnected() && !socket.isClosed(); } | ImapConnection { public boolean isConnected() { return inputStream != null && outputStream != null && socket != null && socket.isConnected() && !socket.isClosed(); } } | ImapConnection { public boolean isConnected() { return inputStream != null && outputStream != null && socket != null && socket.isConnected() && !socket.isClosed(); } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public boolean isConnected() { return inputStream != null && outputStream != null && socket != null && socket.isConnected() && !socket.isClosed(); } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public boolean isConnected() { return inputStream != null && outputStream != null && socket != null && socket.isConnected() && !socket.isClosed(); } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void uriNotPrecededByValidSeparatorFollowedByValidUri() { String text = "myhttp: http: UriLinkifier.linkifyText(text, outputBuffer); assertEquals("myhttp: <a href=\"http: } | public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } | UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } } | UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } } | UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } static void linkifyText(String text, StringBuffer outputBuffer); } | UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } static void linkifyText(String text, StringBuffer outputBuffer); } |
@Test public void close_withoutOpen_shouldNotThrow() throws Exception { ImapConnection imapConnection = createImapConnection( settings, socketFactory, connectivityManager, oAuth2TokenProvider); imapConnection.close(); } | public void close() { open = false; stacktraceForClose = new Exception(); untagQuietly(socket); IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(outputStream); IOUtils.closeQuietly(socket); inputStream = null; outputStream = null; socket = null; } | ImapConnection { public void close() { open = false; stacktraceForClose = new Exception(); untagQuietly(socket); IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(outputStream); IOUtils.closeQuietly(socket); inputStream = null; outputStream = null; socket = null; } } | ImapConnection { public void close() { open = false; stacktraceForClose = new Exception(); untagQuietly(socket); IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(outputStream); IOUtils.closeQuietly(socket); inputStream = null; outputStream = null; socket = null; } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void close() { open = false; stacktraceForClose = new Exception(); untagQuietly(socket); IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(outputStream); IOUtils.closeQuietly(socket); inputStream = null; outputStream = null; socket = null; } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void close() { open = false; stacktraceForClose = new Exception(); untagQuietly(socket); IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(outputStream); IOUtils.closeQuietly(socket); inputStream = null; outputStream = null; socket = null; } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void close_afterOpen_shouldCloseConnection() throws Exception { MockImapServer server = new MockImapServer(); ImapConnection imapConnection = simpleOpen(server); imapConnection.close(); server.verifyConnectionClosed(); server.shutdown(); } | public void close() { open = false; stacktraceForClose = new Exception(); untagQuietly(socket); IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(outputStream); IOUtils.closeQuietly(socket); inputStream = null; outputStream = null; socket = null; } | ImapConnection { public void close() { open = false; stacktraceForClose = new Exception(); untagQuietly(socket); IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(outputStream); IOUtils.closeQuietly(socket); inputStream = null; outputStream = null; socket = null; } } | ImapConnection { public void close() { open = false; stacktraceForClose = new Exception(); untagQuietly(socket); IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(outputStream); IOUtils.closeQuietly(socket); inputStream = null; outputStream = null; socket = null; } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void close() { open = false; stacktraceForClose = new Exception(); untagQuietly(socket); IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(outputStream); IOUtils.closeQuietly(socket); inputStream = null; outputStream = null; socket = null; } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void close() { open = false; stacktraceForClose = new Exception(); untagQuietly(socket); IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(outputStream); IOUtils.closeQuietly(socket); inputStream = null; outputStream = null; socket = null; } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void isIdleCapable_withoutIdleCapability() throws Exception { MockImapServer server = new MockImapServer(); ImapConnection imapConnection = simpleOpen(server); boolean result = imapConnection.isIdleCapable(); assertFalse(result); server.shutdown(); } | protected boolean isIdleCapable() { if (K9MailLib.isDebug()) { Timber.v("Connection %s has %d capabilities", getLogId(), capabilities.size()); } return capabilities.contains(Capabilities.IDLE); } | ImapConnection { protected boolean isIdleCapable() { if (K9MailLib.isDebug()) { Timber.v("Connection %s has %d capabilities", getLogId(), capabilities.size()); } return capabilities.contains(Capabilities.IDLE); } } | ImapConnection { protected boolean isIdleCapable() { if (K9MailLib.isDebug()) { Timber.v("Connection %s has %d capabilities", getLogId(), capabilities.size()); } return capabilities.contains(Capabilities.IDLE); } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { protected boolean isIdleCapable() { if (K9MailLib.isDebug()) { Timber.v("Connection %s has %d capabilities", getLogId(), capabilities.size()); } return capabilities.contains(Capabilities.IDLE); } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { protected boolean isIdleCapable() { if (K9MailLib.isDebug()) { Timber.v("Connection %s has %d capabilities", getLogId(), capabilities.size()); } return capabilities.contains(Capabilities.IDLE); } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void isIdleCapable_withIdleCapability() throws Exception { MockImapServer server = new MockImapServer(); ImapConnection imapConnection = simpleOpenWithCapabilities(server, "IDLE"); boolean result = imapConnection.isIdleCapable(); assertTrue(result); server.shutdown(); } | protected boolean isIdleCapable() { if (K9MailLib.isDebug()) { Timber.v("Connection %s has %d capabilities", getLogId(), capabilities.size()); } return capabilities.contains(Capabilities.IDLE); } | ImapConnection { protected boolean isIdleCapable() { if (K9MailLib.isDebug()) { Timber.v("Connection %s has %d capabilities", getLogId(), capabilities.size()); } return capabilities.contains(Capabilities.IDLE); } } | ImapConnection { protected boolean isIdleCapable() { if (K9MailLib.isDebug()) { Timber.v("Connection %s has %d capabilities", getLogId(), capabilities.size()); } return capabilities.contains(Capabilities.IDLE); } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { protected boolean isIdleCapable() { if (K9MailLib.isDebug()) { Timber.v("Connection %s has %d capabilities", getLogId(), capabilities.size()); } return capabilities.contains(Capabilities.IDLE); } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { protected boolean isIdleCapable() { if (K9MailLib.isDebug()) { Timber.v("Connection %s has %d capabilities", getLogId(), capabilities.size()); } return capabilities.contains(Capabilities.IDLE); } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@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(); } | public void sendContinuation(String continuation) throws IOException { outputStream.write(continuation.getBytes()); outputStream.write('\r'); outputStream.write('\n'); outputStream.flush(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s>>> %s", getLogId(), continuation); } } | ImapConnection { public void sendContinuation(String continuation) throws IOException { outputStream.write(continuation.getBytes()); outputStream.write('\r'); outputStream.write('\n'); outputStream.flush(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s>>> %s", getLogId(), continuation); } } } | ImapConnection { public void sendContinuation(String continuation) throws IOException { outputStream.write(continuation.getBytes()); outputStream.write('\r'); outputStream.write('\n'); outputStream.flush(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s>>> %s", getLogId(), continuation); } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public void sendContinuation(String continuation) throws IOException { outputStream.write(continuation.getBytes()); outputStream.write('\r'); outputStream.write('\n'); outputStream.flush(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s>>> %s", getLogId(), continuation); } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public void sendContinuation(String continuation) throws IOException { outputStream.write(continuation.getBytes()); outputStream.write('\r'); outputStream.write('\n'); outputStream.flush(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s>>> %s", getLogId(), continuation); } } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void executeSingleCommand_withOkResponse_shouldReturnResult() throws Exception { MockImapServer server = new MockImapServer(); simpleOpenDialog(server, ""); server.expect("4 CREATE Folder"); server.output("4 OK Folder created"); ImapConnection imapConnection = startServerAndCreateImapConnection(server); List<ImapResponse> result = imapConnection.executeSimpleCommand("CREATE Folder"); assertEquals(result.size(), 1); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); } | public List<ImapResponse> executeSimpleCommand(String command) throws IOException, MessagingException { return executeSimpleCommand(command, false); } | ImapConnection { public List<ImapResponse> executeSimpleCommand(String command) throws IOException, MessagingException { return executeSimpleCommand(command, false); } } | ImapConnection { public List<ImapResponse> executeSimpleCommand(String command) throws IOException, MessagingException { return executeSimpleCommand(command, false); } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public List<ImapResponse> executeSimpleCommand(String command) throws IOException, MessagingException { return executeSimpleCommand(command, false); } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public List<ImapResponse> executeSimpleCommand(String command) throws IOException, MessagingException { return executeSimpleCommand(command, false); } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void executeSingleCommand_withNoResponse_shouldThrowNegativeImapResponseException() throws Exception { MockImapServer server = new MockImapServer(); simpleOpenDialog(server, ""); server.expect("4 CREATE Folder"); server.output("4 NO Folder exists"); ImapConnection imapConnection = startServerAndCreateImapConnection(server); try { imapConnection.executeSimpleCommand("CREATE Folder"); fail("Expected exception"); } catch (NegativeImapResponseException e) { assertEquals("Folder exists", e.getLastResponse().getString(1)); } server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); } | public List<ImapResponse> executeSimpleCommand(String command) throws IOException, MessagingException { return executeSimpleCommand(command, false); } | ImapConnection { public List<ImapResponse> executeSimpleCommand(String command) throws IOException, MessagingException { return executeSimpleCommand(command, false); } } | ImapConnection { public List<ImapResponse> executeSimpleCommand(String command) throws IOException, MessagingException { return executeSimpleCommand(command, false); } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); } | ImapConnection { public List<ImapResponse> executeSimpleCommand(String command) throws IOException, MessagingException { return executeSimpleCommand(command, false); } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapConnection { public List<ImapResponse> executeSimpleCommand(String command) throws IOException, MessagingException { return executeSimpleCommand(command, false); } ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider,
int socketConnectTimeout, int socketReadTimeout); void open(); boolean isConnected(); void close(); OutputStream getOutputStream(); List<ImapResponse> executeSimpleCommand(String command); List<ImapResponse> executeSimpleCommand(String command, boolean sensitive); List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler); String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive); String sendCommand(String command, boolean sensitive); void sendContinuation(String continuation); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void encode_withAsciiArgument_shouldReturnInput() throws Exception { String folderName = "ASCII"; String result = folderNameCode.encode(folderName); assertEquals(folderName, result); } | public String encode(String folderName) { ByteBuffer byteBuffer = modifiedUtf7Charset.encode(folderName); byte[] bytes = new byte[byteBuffer.limit()]; byteBuffer.get(bytes); return new String(bytes, asciiCharset); } | FolderNameCodec { public String encode(String folderName) { ByteBuffer byteBuffer = modifiedUtf7Charset.encode(folderName); byte[] bytes = new byte[byteBuffer.limit()]; byteBuffer.get(bytes); return new String(bytes, asciiCharset); } } | FolderNameCodec { public String encode(String folderName) { ByteBuffer byteBuffer = modifiedUtf7Charset.encode(folderName); byte[] bytes = new byte[byteBuffer.limit()]; byteBuffer.get(bytes); return new String(bytes, asciiCharset); } private FolderNameCodec(); } | FolderNameCodec { public String encode(String folderName) { ByteBuffer byteBuffer = modifiedUtf7Charset.encode(folderName); byte[] bytes = new byte[byteBuffer.limit()]; byteBuffer.get(bytes); return new String(bytes, asciiCharset); } private FolderNameCodec(); static FolderNameCodec newInstance(); String encode(String folderName); String decode(String encodedFolderName); } | FolderNameCodec { public String encode(String folderName) { ByteBuffer byteBuffer = modifiedUtf7Charset.encode(folderName); byte[] bytes = new byte[byteBuffer.limit()]; byteBuffer.get(bytes); return new String(bytes, asciiCharset); } private FolderNameCodec(); static FolderNameCodec newInstance(); String encode(String folderName); String decode(String encodedFolderName); } |
@Test public void encode_withNonAsciiArgument_shouldReturnEncodedString() throws Exception { String folderName = "über"; String result = folderNameCode.encode(folderName); assertEquals("&APw-ber", result); } | public String encode(String folderName) { ByteBuffer byteBuffer = modifiedUtf7Charset.encode(folderName); byte[] bytes = new byte[byteBuffer.limit()]; byteBuffer.get(bytes); return new String(bytes, asciiCharset); } | FolderNameCodec { public String encode(String folderName) { ByteBuffer byteBuffer = modifiedUtf7Charset.encode(folderName); byte[] bytes = new byte[byteBuffer.limit()]; byteBuffer.get(bytes); return new String(bytes, asciiCharset); } } | FolderNameCodec { public String encode(String folderName) { ByteBuffer byteBuffer = modifiedUtf7Charset.encode(folderName); byte[] bytes = new byte[byteBuffer.limit()]; byteBuffer.get(bytes); return new String(bytes, asciiCharset); } private FolderNameCodec(); } | FolderNameCodec { public String encode(String folderName) { ByteBuffer byteBuffer = modifiedUtf7Charset.encode(folderName); byte[] bytes = new byte[byteBuffer.limit()]; byteBuffer.get(bytes); return new String(bytes, asciiCharset); } private FolderNameCodec(); static FolderNameCodec newInstance(); String encode(String folderName); String decode(String encodedFolderName); } | FolderNameCodec { public String encode(String folderName) { ByteBuffer byteBuffer = modifiedUtf7Charset.encode(folderName); byte[] bytes = new byte[byteBuffer.limit()]; byteBuffer.get(bytes); return new String(bytes, asciiCharset); } private FolderNameCodec(); static FolderNameCodec newInstance(); String encode(String folderName); String decode(String encodedFolderName); } |
@Test public void decode_withEncodedArgument_shouldReturnDecodedString() throws Exception { String encodedFolderName = "&ANw-bergr&APYA3w-entr&AOQ-ger"; String result = folderNameCode.decode(encodedFolderName); assertEquals("Übergrößenträger", result); } | public String decode(String encodedFolderName) throws CharacterCodingException { CharsetDecoder decoder = modifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT); ByteBuffer byteBuffer = ByteBuffer.wrap(encodedFolderName.getBytes(asciiCharset)); CharBuffer charBuffer = decoder.decode(byteBuffer); return charBuffer.toString(); } | FolderNameCodec { public String decode(String encodedFolderName) throws CharacterCodingException { CharsetDecoder decoder = modifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT); ByteBuffer byteBuffer = ByteBuffer.wrap(encodedFolderName.getBytes(asciiCharset)); CharBuffer charBuffer = decoder.decode(byteBuffer); return charBuffer.toString(); } } | FolderNameCodec { public String decode(String encodedFolderName) throws CharacterCodingException { CharsetDecoder decoder = modifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT); ByteBuffer byteBuffer = ByteBuffer.wrap(encodedFolderName.getBytes(asciiCharset)); CharBuffer charBuffer = decoder.decode(byteBuffer); return charBuffer.toString(); } private FolderNameCodec(); } | FolderNameCodec { public String decode(String encodedFolderName) throws CharacterCodingException { CharsetDecoder decoder = modifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT); ByteBuffer byteBuffer = ByteBuffer.wrap(encodedFolderName.getBytes(asciiCharset)); CharBuffer charBuffer = decoder.decode(byteBuffer); return charBuffer.toString(); } private FolderNameCodec(); static FolderNameCodec newInstance(); String encode(String folderName); String decode(String encodedFolderName); } | FolderNameCodec { public String decode(String encodedFolderName) throws CharacterCodingException { CharsetDecoder decoder = modifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT); ByteBuffer byteBuffer = ByteBuffer.wrap(encodedFolderName.getBytes(asciiCharset)); CharBuffer charBuffer = decoder.decode(byteBuffer); return charBuffer.toString(); } private FolderNameCodec(); static FolderNameCodec newInstance(); String encode(String folderName); String decode(String encodedFolderName); } |
@Test public void schemaMatchWithInvalidUriInMiddleOfTextFollowedByValidUri() { String text = "prefix http:42 http: UriLinkifier.linkifyText(text, outputBuffer); assertEquals("prefix http:42 <a href=\"http: } | public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } | UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } } | UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } } | UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } static void linkifyText(String text, StringBuffer outputBuffer); } | UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } static void linkifyText(String text, StringBuffer outputBuffer); } |
@Test public void decode_withInvalidEncodedArgument_shouldThrow() throws Exception { String encodedFolderName = "&12-foo"; try { folderNameCode.decode(encodedFolderName); fail("Expected exception"); } catch (CharacterCodingException ignored) { } } | public String decode(String encodedFolderName) throws CharacterCodingException { CharsetDecoder decoder = modifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT); ByteBuffer byteBuffer = ByteBuffer.wrap(encodedFolderName.getBytes(asciiCharset)); CharBuffer charBuffer = decoder.decode(byteBuffer); return charBuffer.toString(); } | FolderNameCodec { public String decode(String encodedFolderName) throws CharacterCodingException { CharsetDecoder decoder = modifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT); ByteBuffer byteBuffer = ByteBuffer.wrap(encodedFolderName.getBytes(asciiCharset)); CharBuffer charBuffer = decoder.decode(byteBuffer); return charBuffer.toString(); } } | FolderNameCodec { public String decode(String encodedFolderName) throws CharacterCodingException { CharsetDecoder decoder = modifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT); ByteBuffer byteBuffer = ByteBuffer.wrap(encodedFolderName.getBytes(asciiCharset)); CharBuffer charBuffer = decoder.decode(byteBuffer); return charBuffer.toString(); } private FolderNameCodec(); } | FolderNameCodec { public String decode(String encodedFolderName) throws CharacterCodingException { CharsetDecoder decoder = modifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT); ByteBuffer byteBuffer = ByteBuffer.wrap(encodedFolderName.getBytes(asciiCharset)); CharBuffer charBuffer = decoder.decode(byteBuffer); return charBuffer.toString(); } private FolderNameCodec(); static FolderNameCodec newInstance(); String encode(String folderName); String decode(String encodedFolderName); } | FolderNameCodec { public String decode(String encodedFolderName) throws CharacterCodingException { CharsetDecoder decoder = modifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT); ByteBuffer byteBuffer = ByteBuffer.wrap(encodedFolderName.getBytes(asciiCharset)); CharBuffer charBuffer = decoder.decode(byteBuffer); return charBuffer.toString(); } private FolderNameCodec(); static FolderNameCodec newInstance(); String encode(String folderName); String decode(String encodedFolderName); } |
@Test public void getFolder_shouldReturnImapFolderInstance() throws Exception { Folder result = imapStore.getFolder("INBOX"); assertEquals(ImapFolder.class, result.getClass()); } | @Override @NonNull public ImapFolder getFolder(String folderId) { ImapFolder folder; synchronized (folderCache) { folder = folderCache.get(folderId); if (folder == null) { folder = new ImapFolder(this, folderId); folderCache.put(folderId, folder); } } return folder; } | ImapStore extends RemoteStore { @Override @NonNull public ImapFolder getFolder(String folderId) { ImapFolder folder; synchronized (folderCache) { folder = folderCache.get(folderId); if (folder == null) { folder = new ImapFolder(this, folderId); folderCache.put(folderId, folder); } } return folder; } } | ImapStore extends RemoteStore { @Override @NonNull public ImapFolder getFolder(String folderId) { ImapFolder folder; synchronized (folderCache) { folder = folderCache.get(folderId); if (folder == null) { folder = new ImapFolder(this, folderId); folderCache.put(folderId, folder); } } return folder; } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); } | ImapStore extends RemoteStore { @Override @NonNull public ImapFolder getFolder(String folderId) { ImapFolder folder; synchronized (folderCache) { folder = folderCache.get(folderId); if (folder == null) { folder = new ImapFolder(this, folderId); folderCache.put(folderId, folder); } } return folder; } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } | ImapStore extends RemoteStore { @Override @NonNull public ImapFolder getFolder(String folderId) { ImapFolder folder; synchronized (folderCache) { folder = folderCache.get(folderId); if (folder == null) { folder = new ImapFolder(this, folderId); folderCache.put(folderId, folder); } } return folder; } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } |
@Test public void getFolder_calledTwice_shouldReturnFirstInstance() throws Exception { String folderName = "Trash"; Folder imapFolder = imapStore.getFolder(folderName); Folder result = imapStore.getFolder(folderName); assertEquals(imapFolder, result); } | @Override @NonNull public ImapFolder getFolder(String folderId) { ImapFolder folder; synchronized (folderCache) { folder = folderCache.get(folderId); if (folder == null) { folder = new ImapFolder(this, folderId); folderCache.put(folderId, folder); } } return folder; } | ImapStore extends RemoteStore { @Override @NonNull public ImapFolder getFolder(String folderId) { ImapFolder folder; synchronized (folderCache) { folder = folderCache.get(folderId); if (folder == null) { folder = new ImapFolder(this, folderId); folderCache.put(folderId, folder); } } return folder; } } | ImapStore extends RemoteStore { @Override @NonNull public ImapFolder getFolder(String folderId) { ImapFolder folder; synchronized (folderCache) { folder = folderCache.get(folderId); if (folder == null) { folder = new ImapFolder(this, folderId); folderCache.put(folderId, folder); } } return folder; } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); } | ImapStore extends RemoteStore { @Override @NonNull public ImapFolder getFolder(String folderId) { ImapFolder folder; synchronized (folderCache) { folder = folderCache.get(folderId); if (folder == null) { folder = new ImapFolder(this, folderId); folderCache.put(folderId, folder); } } return folder; } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } | ImapStore extends RemoteStore { @Override @NonNull public ImapFolder getFolder(String folderId) { ImapFolder folder; synchronized (folderCache) { folder = folderCache.get(folderId); if (folder == null) { folder = new ImapFolder(this, folderId); folderCache.put(folderId, folder); } } return folder; } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } |
@Test public void checkSettings_shouldCreateImapConnectionAndCallOpen() throws Exception { ImapConnection imapConnection = mock(ImapConnection.class); imapStore.enqueueImapConnection(imapConnection); imapStore.checkSettings(); verify(imapConnection).open(); } | @Override public void checkSettings() throws MessagingException { try { ImapConnection connection = createImapConnection(); connection.open(); autoconfigureFolders(connection); connection.close(); } catch (IOException ioe) { throw new MessagingException("Unable to connect", ioe); } } | ImapStore extends RemoteStore { @Override public void checkSettings() throws MessagingException { try { ImapConnection connection = createImapConnection(); connection.open(); autoconfigureFolders(connection); connection.close(); } catch (IOException ioe) { throw new MessagingException("Unable to connect", ioe); } } } | ImapStore extends RemoteStore { @Override public void checkSettings() throws MessagingException { try { ImapConnection connection = createImapConnection(); connection.open(); autoconfigureFolders(connection); connection.close(); } catch (IOException ioe) { throw new MessagingException("Unable to connect", ioe); } } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); } | ImapStore extends RemoteStore { @Override public void checkSettings() throws MessagingException { try { ImapConnection connection = createImapConnection(); connection.open(); autoconfigureFolders(connection); connection.close(); } catch (IOException ioe) { throw new MessagingException("Unable to connect", ioe); } } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } | ImapStore extends RemoteStore { @Override public void checkSettings() throws MessagingException { try { ImapConnection connection = createImapConnection(); connection.open(); autoconfigureFolders(connection); connection.close(); } catch (IOException ioe) { throw new MessagingException("Unable to connect", ioe); } } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } |
@Test public void checkSettings_withOpenThrowing_shouldThrowMessagingException() throws Exception { ImapConnection imapConnection = mock(ImapConnection.class); doThrow(IOException.class).when(imapConnection).open(); imapStore.enqueueImapConnection(imapConnection); try { imapStore.checkSettings(); fail("Expected exception"); } catch (MessagingException e) { assertEquals("Unable to connect", e.getMessage()); assertNotNull(e.getCause()); assertEquals(IOException.class, e.getCause().getClass()); } } | @Override public void checkSettings() throws MessagingException { try { ImapConnection connection = createImapConnection(); connection.open(); autoconfigureFolders(connection); connection.close(); } catch (IOException ioe) { throw new MessagingException("Unable to connect", ioe); } } | ImapStore extends RemoteStore { @Override public void checkSettings() throws MessagingException { try { ImapConnection connection = createImapConnection(); connection.open(); autoconfigureFolders(connection); connection.close(); } catch (IOException ioe) { throw new MessagingException("Unable to connect", ioe); } } } | ImapStore extends RemoteStore { @Override public void checkSettings() throws MessagingException { try { ImapConnection connection = createImapConnection(); connection.open(); autoconfigureFolders(connection); connection.close(); } catch (IOException ioe) { throw new MessagingException("Unable to connect", ioe); } } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); } | ImapStore extends RemoteStore { @Override public void checkSettings() throws MessagingException { try { ImapConnection connection = createImapConnection(); connection.open(); autoconfigureFolders(connection); connection.close(); } catch (IOException ioe) { throw new MessagingException("Unable to connect", ioe); } } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } | ImapStore extends RemoteStore { @Override public void checkSettings() throws MessagingException { try { ImapConnection connection = createImapConnection(); connection.open(); autoconfigureFolders(connection); connection.close(); } catch (IOException ioe) { throw new MessagingException("Unable to connect", ioe); } } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } |
@Test public void autoconfigureFolders_withSpecialUseCapability_shouldSetSpecialFolders() throws Exception { ImapConnection imapConnection = mock(ImapConnection.class); when(imapConnection.hasCapability(Capabilities.SPECIAL_USE)).thenReturn(true); List<ImapResponse> imapResponses = Arrays.asList( createImapResponse("* LIST (\\HasNoChildren) \"/\" \"INBOX\""), createImapResponse("* LIST (\\Noselect \\HasChildren) \"/\" \"[Gmail]\""), createImapResponse("* LIST (\\HasNoChildren \\All) \"/\" \"[Gmail]/All Mail\""), createImapResponse("* LIST (\\HasNoChildren \\Drafts) \"/\" \"[Gmail]/Drafts\""), createImapResponse("* LIST (\\HasNoChildren \\Important) \"/\" \"[Gmail]/Important\""), createImapResponse("* LIST (\\HasNoChildren \\Sent) \"/\" \"[Gmail]/Sent Mail\""), createImapResponse("* LIST (\\HasNoChildren \\Junk) \"/\" \"[Gmail]/Spam\""), createImapResponse("* LIST (\\HasNoChildren \\Flagged) \"/\" \"[Gmail]/Starred\""), createImapResponse("* LIST (\\HasNoChildren \\Trash) \"/\" \"[Gmail]/Trash\""), createImapResponse("5 OK Success") ); when(imapConnection.executeSimpleCommand("LIST (SPECIAL-USE) \"\" \"*\"")).thenReturn(imapResponses); imapStore.autoconfigureFolders(imapConnection); verify(storeConfig).setDraftsFolderId("[Gmail]/Drafts"); verify(storeConfig).setSentFolderId("[Gmail]/Sent Mail"); verify(storeConfig).setSpamFolderId("[Gmail]/Spam"); verify(storeConfig).setTrashFolderId("[Gmail]/Trash"); verify(storeConfig).setArchiveFolderId("[Gmail]/All Mail"); } | void autoconfigureFolders(final ImapConnection connection) throws IOException, MessagingException { if (!connection.hasCapability(Capabilities.SPECIAL_USE)) { if (K9MailLib.isDebug()) { Timber.d("No detected folder auto-configuration methods."); } return; } if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration: Using RFC6154/SPECIAL-USE."); } String command = String.format("LIST (SPECIAL-USE) \"\" %s", ImapUtility.encodeString(getCombinedPrefix() + "*")); List<ImapResponse> responses = connection.executeSimpleCommand(command); List<ListResponse> listResponses = ListResponse.parseList(responses); for (ListResponse listResponse : listResponses) { String decodedFolderName; try { decodedFolderName = folderNameCodec.decode(listResponse.getName()); } catch (CharacterCodingException e) { Timber.w(e, "Folder name not correctly encoded with the UTF-7 variant as defined by RFC 3501: %s", listResponse.getName()); continue; } if (pathDelimiter == null) { pathDelimiter = listResponse.getHierarchyDelimiter(); combinedPrefix = null; } if (listResponse.hasAttribute("\\Archive") || listResponse.hasAttribute("\\All")) { mStoreConfig.setArchiveFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Archive folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Drafts")) { mStoreConfig.setDraftsFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Drafts folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Sent")) { mStoreConfig.setSentFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Sent folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Junk")) { mStoreConfig.setSpamFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Spam folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Trash")) { mStoreConfig.setTrashFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Trash folder: %s", decodedFolderName); } } } } | ImapStore extends RemoteStore { void autoconfigureFolders(final ImapConnection connection) throws IOException, MessagingException { if (!connection.hasCapability(Capabilities.SPECIAL_USE)) { if (K9MailLib.isDebug()) { Timber.d("No detected folder auto-configuration methods."); } return; } if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration: Using RFC6154/SPECIAL-USE."); } String command = String.format("LIST (SPECIAL-USE) \"\" %s", ImapUtility.encodeString(getCombinedPrefix() + "*")); List<ImapResponse> responses = connection.executeSimpleCommand(command); List<ListResponse> listResponses = ListResponse.parseList(responses); for (ListResponse listResponse : listResponses) { String decodedFolderName; try { decodedFolderName = folderNameCodec.decode(listResponse.getName()); } catch (CharacterCodingException e) { Timber.w(e, "Folder name not correctly encoded with the UTF-7 variant as defined by RFC 3501: %s", listResponse.getName()); continue; } if (pathDelimiter == null) { pathDelimiter = listResponse.getHierarchyDelimiter(); combinedPrefix = null; } if (listResponse.hasAttribute("\\Archive") || listResponse.hasAttribute("\\All")) { mStoreConfig.setArchiveFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Archive folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Drafts")) { mStoreConfig.setDraftsFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Drafts folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Sent")) { mStoreConfig.setSentFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Sent folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Junk")) { mStoreConfig.setSpamFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Spam folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Trash")) { mStoreConfig.setTrashFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Trash folder: %s", decodedFolderName); } } } } } | ImapStore extends RemoteStore { void autoconfigureFolders(final ImapConnection connection) throws IOException, MessagingException { if (!connection.hasCapability(Capabilities.SPECIAL_USE)) { if (K9MailLib.isDebug()) { Timber.d("No detected folder auto-configuration methods."); } return; } if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration: Using RFC6154/SPECIAL-USE."); } String command = String.format("LIST (SPECIAL-USE) \"\" %s", ImapUtility.encodeString(getCombinedPrefix() + "*")); List<ImapResponse> responses = connection.executeSimpleCommand(command); List<ListResponse> listResponses = ListResponse.parseList(responses); for (ListResponse listResponse : listResponses) { String decodedFolderName; try { decodedFolderName = folderNameCodec.decode(listResponse.getName()); } catch (CharacterCodingException e) { Timber.w(e, "Folder name not correctly encoded with the UTF-7 variant as defined by RFC 3501: %s", listResponse.getName()); continue; } if (pathDelimiter == null) { pathDelimiter = listResponse.getHierarchyDelimiter(); combinedPrefix = null; } if (listResponse.hasAttribute("\\Archive") || listResponse.hasAttribute("\\All")) { mStoreConfig.setArchiveFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Archive folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Drafts")) { mStoreConfig.setDraftsFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Drafts folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Sent")) { mStoreConfig.setSentFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Sent folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Junk")) { mStoreConfig.setSpamFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Spam folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Trash")) { mStoreConfig.setTrashFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Trash folder: %s", decodedFolderName); } } } } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); } | ImapStore extends RemoteStore { void autoconfigureFolders(final ImapConnection connection) throws IOException, MessagingException { if (!connection.hasCapability(Capabilities.SPECIAL_USE)) { if (K9MailLib.isDebug()) { Timber.d("No detected folder auto-configuration methods."); } return; } if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration: Using RFC6154/SPECIAL-USE."); } String command = String.format("LIST (SPECIAL-USE) \"\" %s", ImapUtility.encodeString(getCombinedPrefix() + "*")); List<ImapResponse> responses = connection.executeSimpleCommand(command); List<ListResponse> listResponses = ListResponse.parseList(responses); for (ListResponse listResponse : listResponses) { String decodedFolderName; try { decodedFolderName = folderNameCodec.decode(listResponse.getName()); } catch (CharacterCodingException e) { Timber.w(e, "Folder name not correctly encoded with the UTF-7 variant as defined by RFC 3501: %s", listResponse.getName()); continue; } if (pathDelimiter == null) { pathDelimiter = listResponse.getHierarchyDelimiter(); combinedPrefix = null; } if (listResponse.hasAttribute("\\Archive") || listResponse.hasAttribute("\\All")) { mStoreConfig.setArchiveFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Archive folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Drafts")) { mStoreConfig.setDraftsFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Drafts folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Sent")) { mStoreConfig.setSentFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Sent folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Junk")) { mStoreConfig.setSpamFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Spam folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Trash")) { mStoreConfig.setTrashFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Trash folder: %s", decodedFolderName); } } } } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } | ImapStore extends RemoteStore { void autoconfigureFolders(final ImapConnection connection) throws IOException, MessagingException { if (!connection.hasCapability(Capabilities.SPECIAL_USE)) { if (K9MailLib.isDebug()) { Timber.d("No detected folder auto-configuration methods."); } return; } if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration: Using RFC6154/SPECIAL-USE."); } String command = String.format("LIST (SPECIAL-USE) \"\" %s", ImapUtility.encodeString(getCombinedPrefix() + "*")); List<ImapResponse> responses = connection.executeSimpleCommand(command); List<ListResponse> listResponses = ListResponse.parseList(responses); for (ListResponse listResponse : listResponses) { String decodedFolderName; try { decodedFolderName = folderNameCodec.decode(listResponse.getName()); } catch (CharacterCodingException e) { Timber.w(e, "Folder name not correctly encoded with the UTF-7 variant as defined by RFC 3501: %s", listResponse.getName()); continue; } if (pathDelimiter == null) { pathDelimiter = listResponse.getHierarchyDelimiter(); combinedPrefix = null; } if (listResponse.hasAttribute("\\Archive") || listResponse.hasAttribute("\\All")) { mStoreConfig.setArchiveFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Archive folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Drafts")) { mStoreConfig.setDraftsFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Drafts folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Sent")) { mStoreConfig.setSentFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Sent folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Junk")) { mStoreConfig.setSpamFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Spam folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Trash")) { mStoreConfig.setTrashFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Trash folder: %s", decodedFolderName); } } } } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } |
@Test public void autoconfigureFolders_withoutSpecialUseCapability_shouldNotIssueImapCommand() throws Exception { ImapConnection imapConnection = mock(ImapConnection.class); when(imapConnection.hasCapability(Capabilities.SPECIAL_USE)).thenReturn(false); imapStore.autoconfigureFolders(imapConnection); verify(imapConnection, atLeastOnce()).hasCapability(anyString()); verifyNoMoreInteractions(imapConnection); } | void autoconfigureFolders(final ImapConnection connection) throws IOException, MessagingException { if (!connection.hasCapability(Capabilities.SPECIAL_USE)) { if (K9MailLib.isDebug()) { Timber.d("No detected folder auto-configuration methods."); } return; } if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration: Using RFC6154/SPECIAL-USE."); } String command = String.format("LIST (SPECIAL-USE) \"\" %s", ImapUtility.encodeString(getCombinedPrefix() + "*")); List<ImapResponse> responses = connection.executeSimpleCommand(command); List<ListResponse> listResponses = ListResponse.parseList(responses); for (ListResponse listResponse : listResponses) { String decodedFolderName; try { decodedFolderName = folderNameCodec.decode(listResponse.getName()); } catch (CharacterCodingException e) { Timber.w(e, "Folder name not correctly encoded with the UTF-7 variant as defined by RFC 3501: %s", listResponse.getName()); continue; } if (pathDelimiter == null) { pathDelimiter = listResponse.getHierarchyDelimiter(); combinedPrefix = null; } if (listResponse.hasAttribute("\\Archive") || listResponse.hasAttribute("\\All")) { mStoreConfig.setArchiveFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Archive folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Drafts")) { mStoreConfig.setDraftsFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Drafts folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Sent")) { mStoreConfig.setSentFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Sent folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Junk")) { mStoreConfig.setSpamFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Spam folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Trash")) { mStoreConfig.setTrashFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Trash folder: %s", decodedFolderName); } } } } | ImapStore extends RemoteStore { void autoconfigureFolders(final ImapConnection connection) throws IOException, MessagingException { if (!connection.hasCapability(Capabilities.SPECIAL_USE)) { if (K9MailLib.isDebug()) { Timber.d("No detected folder auto-configuration methods."); } return; } if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration: Using RFC6154/SPECIAL-USE."); } String command = String.format("LIST (SPECIAL-USE) \"\" %s", ImapUtility.encodeString(getCombinedPrefix() + "*")); List<ImapResponse> responses = connection.executeSimpleCommand(command); List<ListResponse> listResponses = ListResponse.parseList(responses); for (ListResponse listResponse : listResponses) { String decodedFolderName; try { decodedFolderName = folderNameCodec.decode(listResponse.getName()); } catch (CharacterCodingException e) { Timber.w(e, "Folder name not correctly encoded with the UTF-7 variant as defined by RFC 3501: %s", listResponse.getName()); continue; } if (pathDelimiter == null) { pathDelimiter = listResponse.getHierarchyDelimiter(); combinedPrefix = null; } if (listResponse.hasAttribute("\\Archive") || listResponse.hasAttribute("\\All")) { mStoreConfig.setArchiveFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Archive folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Drafts")) { mStoreConfig.setDraftsFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Drafts folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Sent")) { mStoreConfig.setSentFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Sent folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Junk")) { mStoreConfig.setSpamFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Spam folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Trash")) { mStoreConfig.setTrashFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Trash folder: %s", decodedFolderName); } } } } } | ImapStore extends RemoteStore { void autoconfigureFolders(final ImapConnection connection) throws IOException, MessagingException { if (!connection.hasCapability(Capabilities.SPECIAL_USE)) { if (K9MailLib.isDebug()) { Timber.d("No detected folder auto-configuration methods."); } return; } if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration: Using RFC6154/SPECIAL-USE."); } String command = String.format("LIST (SPECIAL-USE) \"\" %s", ImapUtility.encodeString(getCombinedPrefix() + "*")); List<ImapResponse> responses = connection.executeSimpleCommand(command); List<ListResponse> listResponses = ListResponse.parseList(responses); for (ListResponse listResponse : listResponses) { String decodedFolderName; try { decodedFolderName = folderNameCodec.decode(listResponse.getName()); } catch (CharacterCodingException e) { Timber.w(e, "Folder name not correctly encoded with the UTF-7 variant as defined by RFC 3501: %s", listResponse.getName()); continue; } if (pathDelimiter == null) { pathDelimiter = listResponse.getHierarchyDelimiter(); combinedPrefix = null; } if (listResponse.hasAttribute("\\Archive") || listResponse.hasAttribute("\\All")) { mStoreConfig.setArchiveFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Archive folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Drafts")) { mStoreConfig.setDraftsFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Drafts folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Sent")) { mStoreConfig.setSentFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Sent folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Junk")) { mStoreConfig.setSpamFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Spam folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Trash")) { mStoreConfig.setTrashFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Trash folder: %s", decodedFolderName); } } } } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); } | ImapStore extends RemoteStore { void autoconfigureFolders(final ImapConnection connection) throws IOException, MessagingException { if (!connection.hasCapability(Capabilities.SPECIAL_USE)) { if (K9MailLib.isDebug()) { Timber.d("No detected folder auto-configuration methods."); } return; } if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration: Using RFC6154/SPECIAL-USE."); } String command = String.format("LIST (SPECIAL-USE) \"\" %s", ImapUtility.encodeString(getCombinedPrefix() + "*")); List<ImapResponse> responses = connection.executeSimpleCommand(command); List<ListResponse> listResponses = ListResponse.parseList(responses); for (ListResponse listResponse : listResponses) { String decodedFolderName; try { decodedFolderName = folderNameCodec.decode(listResponse.getName()); } catch (CharacterCodingException e) { Timber.w(e, "Folder name not correctly encoded with the UTF-7 variant as defined by RFC 3501: %s", listResponse.getName()); continue; } if (pathDelimiter == null) { pathDelimiter = listResponse.getHierarchyDelimiter(); combinedPrefix = null; } if (listResponse.hasAttribute("\\Archive") || listResponse.hasAttribute("\\All")) { mStoreConfig.setArchiveFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Archive folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Drafts")) { mStoreConfig.setDraftsFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Drafts folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Sent")) { mStoreConfig.setSentFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Sent folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Junk")) { mStoreConfig.setSpamFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Spam folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Trash")) { mStoreConfig.setTrashFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Trash folder: %s", decodedFolderName); } } } } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } | ImapStore extends RemoteStore { void autoconfigureFolders(final ImapConnection connection) throws IOException, MessagingException { if (!connection.hasCapability(Capabilities.SPECIAL_USE)) { if (K9MailLib.isDebug()) { Timber.d("No detected folder auto-configuration methods."); } return; } if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration: Using RFC6154/SPECIAL-USE."); } String command = String.format("LIST (SPECIAL-USE) \"\" %s", ImapUtility.encodeString(getCombinedPrefix() + "*")); List<ImapResponse> responses = connection.executeSimpleCommand(command); List<ListResponse> listResponses = ListResponse.parseList(responses); for (ListResponse listResponse : listResponses) { String decodedFolderName; try { decodedFolderName = folderNameCodec.decode(listResponse.getName()); } catch (CharacterCodingException e) { Timber.w(e, "Folder name not correctly encoded with the UTF-7 variant as defined by RFC 3501: %s", listResponse.getName()); continue; } if (pathDelimiter == null) { pathDelimiter = listResponse.getHierarchyDelimiter(); combinedPrefix = null; } if (listResponse.hasAttribute("\\Archive") || listResponse.hasAttribute("\\All")) { mStoreConfig.setArchiveFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Archive folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Drafts")) { mStoreConfig.setDraftsFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Drafts folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Sent")) { mStoreConfig.setSentFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Sent folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Junk")) { mStoreConfig.setSpamFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Spam folder: %s", decodedFolderName); } } else if (listResponse.hasAttribute("\\Trash")) { mStoreConfig.setTrashFolderId(decodedFolderName); if (K9MailLib.isDebug()) { Timber.d("Folder auto-configuration detected Trash folder: %s", decodedFolderName); } } } } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } |
@Test public void getPersonalNamespaces_withForceListAll() throws Exception { when(storeConfig.subscribedFoldersOnly()).thenReturn(true); ImapConnection imapConnection = mock(ImapConnection.class); List<ImapResponse> imapResponses = Arrays.asList( createImapResponse("* LIST (\\HasNoChildren) \".\" \"INBOX\""), createImapResponse("* LIST (\\Noselect \\HasChildren) \".\" \"Folder\""), createImapResponse("* LIST (\\HasNoChildren) \".\" \"Folder.SubFolder\""), createImapResponse("6 OK Success") ); when(imapConnection.executeSimpleCommand("LIST \"\" \"*\"")).thenReturn(imapResponses); imapStore.enqueueImapConnection(imapConnection); List<? extends Folder> result = imapStore.getFolders(true); assertNotNull(result); assertEquals(Sets.newSet("INBOX", "Folder.SubFolder"), extractFolderIds(result)); } | @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } |
@Test public void getPersonalNamespaces_withPathPrefix() throws Exception { when(storeConfig.getStoreUri()).thenReturn("imap: imapStore = new TestImapStore(storeConfig, trustedSocketFactory, connectivityManager, oauth2TokenProvider); ImapConnection imapConnection = mock(ImapConnection.class); List<ImapResponse> imapResponses = Arrays.asList( createImapResponse("* LIST (\\HasNoChildren) \".\" \"pathPrefix/INBOX\""), createImapResponse("* LIST (\\Noselect \\HasChildren) \".\" \"pathPrefix/.Folder\""), createImapResponse("* LIST (\\HasNoChildren) \".\" \"pathPrefix/.Folder.SubFolder\""), createImapResponse("6 OK Success") ); when(imapConnection.executeSimpleCommand("LIST \"\" \"pathPrefix/*\"")).thenReturn(imapResponses); imapStore.enqueueImapConnection(imapConnection); List<? extends Folder> result = imapStore.getFolders(true); assertNotNull(result); assertEquals(Sets.newSet("INBOX", "Folder.SubFolder"), extractFolderIds(result)); } | @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } |
@Test public void getPersonalNamespaces_withoutForceListAllAndWithoutSubscribedFoldersOnly() throws Exception { when(storeConfig.subscribedFoldersOnly()).thenReturn(false); ImapConnection imapConnection = mock(ImapConnection.class); List<ImapResponse> imapResponses = Arrays.asList( createImapResponse("* LIST (\\HasNoChildren) \".\" \"INBOX\""), createImapResponse("* LIST (\\Noselect \\HasChildren) \".\" \"Folder\""), createImapResponse("* LIST (\\HasNoChildren) \".\" \"Folder.SubFolder\""), createImapResponse("6 OK Success") ); when(imapConnection.executeSimpleCommand("LIST \"\" \"*\"")).thenReturn(imapResponses); imapStore.enqueueImapConnection(imapConnection); List<? extends Folder> result = imapStore.getFolders(false); assertNotNull(result); assertEquals(Sets.newSet("INBOX", "Folder.SubFolder"), extractFolderIds(result)); } | @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } |
@Test public void multipleValidUrisInRow() { String text = "prefix http: UriLinkifier.linkifyText(text, outputBuffer); assertEquals( "prefix <a href=\"http: "<a href=\"http: outputBuffer.toString()); } | public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } | UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } } | UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } } | UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } static void linkifyText(String text, StringBuffer outputBuffer); } | UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch); String scheme = matcher.group(1).toLowerCase(Locale.US); UriParser parser = SUPPORTED_URIS.get(scheme); int newPos = parser.linkifyUri(text, startPos, outputBuffer); boolean uriWasNotLinkified = newPos <= startPos; if (uriWasNotLinkified) { outputBuffer.append(text.charAt(startPos)); currentPos = startPos + 1; } else { currentPos = (newPos > currentPos) ? newPos : currentPos + 1; } if (currentPos >= text.length()) { break; } } String textAfterLastMatch = text.substring(currentPos); outputBuffer.append(textAfterLastMatch); } static void linkifyText(String text, StringBuffer outputBuffer); } |
@Test public void getPersonalNamespaces_withSubscribedFoldersOnlyAndWithoutForceListAll_shouldOnlyReturnExistingSubscribedFolders() throws Exception { when(storeConfig.subscribedFoldersOnly()).thenReturn(true); ImapConnection imapConnection = mock(ImapConnection.class); List<ImapResponse> lsubResponses = Arrays.asList( createImapResponse("* LSUB (\\HasNoChildren) \".\" \"INBOX\""), createImapResponse("* LSUB (\\Noselect \\HasChildren) \".\" \"Folder\""), createImapResponse("* LSUB (\\HasNoChildren) \".\" \"Folder.SubFolder\""), createImapResponse("* LSUB (\\HasNoChildren) \".\" \"SubscribedFolderThatHasBeenDeleted\""), createImapResponse("5 OK Success") ); when(imapConnection.executeSimpleCommand("LSUB \"\" \"*\"")).thenReturn(lsubResponses); List<ImapResponse> imapResponses = Arrays.asList( createImapResponse("* LIST (\\HasNoChildren) \".\" \"INBOX\""), createImapResponse("* LIST (\\Noselect \\HasChildren) \".\" \"Folder\""), createImapResponse("* LIST (\\HasNoChildren) \".\" \"Folder.SubFolder\""), createImapResponse("6 OK Success") ); when(imapConnection.executeSimpleCommand("LIST \"\" \"*\"")).thenReturn(imapResponses); imapStore.enqueueImapConnection(imapConnection); List<? extends Folder> result = imapStore.getFolders(false); assertNotNull(result); assertEquals(Sets.newSet("INBOX", "Folder.SubFolder"), extractFolderIds(result)); } | @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } |
@Test public void getPersonalNamespaces_withoutException_shouldLeaveImapConnectionOpen() throws Exception { ImapConnection imapConnection = mock(ImapConnection.class); List<ImapResponse> imapResponses = Collections.singletonList(createImapResponse("5 OK Success")); when(imapConnection.executeSimpleCommand(anyString())).thenReturn(imapResponses); imapStore.enqueueImapConnection(imapConnection); imapStore.getFolders(true); verify(imapConnection, never()).close(); } | @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } |
@Test public void getPersonalNamespaces_withIoException_shouldCloseImapConnection() throws Exception { ImapConnection imapConnection = mock(ImapConnection.class); doThrow(IOException.class).when(imapConnection).executeSimpleCommand("LIST \"\" \"*\""); imapStore.enqueueImapConnection(imapConnection); try { imapStore.getFolders(true); fail("Expected exception"); } catch (MessagingException ignored) { } verify(imapConnection).close(); } | @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } | ImapStore extends RemoteStore { @Override @NonNull public List<ImapFolder> getFolders(boolean forceListAll) throws MessagingException { return getPersonalNamespaces(forceListAll); } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } |
@Test public void getConnection_shouldCreateImapConnection() throws Exception { ImapConnection imapConnection = mock(ImapConnection.class); imapStore.enqueueImapConnection(imapConnection); ImapConnection result = imapStore.getConnection(); assertSame(imapConnection, result); } | ImapConnection getConnection() throws MessagingException { ImapConnection connection; while ((connection = pollConnection()) != null) { try { connection.executeSimpleCommand(Commands.NOOP); break; } catch (IOException ioe) { connection.close(); } } if (connection == null) { connection = createImapConnection(); } return connection; } | ImapStore extends RemoteStore { ImapConnection getConnection() throws MessagingException { ImapConnection connection; while ((connection = pollConnection()) != null) { try { connection.executeSimpleCommand(Commands.NOOP); break; } catch (IOException ioe) { connection.close(); } } if (connection == null) { connection = createImapConnection(); } return connection; } } | ImapStore extends RemoteStore { ImapConnection getConnection() throws MessagingException { ImapConnection connection; while ((connection = pollConnection()) != null) { try { connection.executeSimpleCommand(Commands.NOOP); break; } catch (IOException ioe) { connection.close(); } } if (connection == null) { connection = createImapConnection(); } return connection; } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); } | ImapStore extends RemoteStore { ImapConnection getConnection() throws MessagingException { ImapConnection connection; while ((connection = pollConnection()) != null) { try { connection.executeSimpleCommand(Commands.NOOP); break; } catch (IOException ioe) { connection.close(); } } if (connection == null) { connection = createImapConnection(); } return connection; } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } | ImapStore extends RemoteStore { ImapConnection getConnection() throws MessagingException { ImapConnection connection; while ((connection = pollConnection()) != null) { try { connection.executeSimpleCommand(Commands.NOOP); break; } catch (IOException ioe) { connection.close(); } } if (connection == null) { connection = createImapConnection(); } return connection; } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } |
@Test public void getConnection_calledTwiceWithoutRelease_shouldCreateTwoImapConnection() throws Exception { ImapConnection imapConnectionOne = mock(ImapConnection.class); ImapConnection imapConnectionTwo = mock(ImapConnection.class); imapStore.enqueueImapConnection(imapConnectionOne); imapStore.enqueueImapConnection(imapConnectionTwo); ImapConnection resultOne = imapStore.getConnection(); ImapConnection resultTwo = imapStore.getConnection(); assertSame(imapConnectionOne, resultOne); assertSame(imapConnectionTwo, resultTwo); } | ImapConnection getConnection() throws MessagingException { ImapConnection connection; while ((connection = pollConnection()) != null) { try { connection.executeSimpleCommand(Commands.NOOP); break; } catch (IOException ioe) { connection.close(); } } if (connection == null) { connection = createImapConnection(); } return connection; } | ImapStore extends RemoteStore { ImapConnection getConnection() throws MessagingException { ImapConnection connection; while ((connection = pollConnection()) != null) { try { connection.executeSimpleCommand(Commands.NOOP); break; } catch (IOException ioe) { connection.close(); } } if (connection == null) { connection = createImapConnection(); } return connection; } } | ImapStore extends RemoteStore { ImapConnection getConnection() throws MessagingException { ImapConnection connection; while ((connection = pollConnection()) != null) { try { connection.executeSimpleCommand(Commands.NOOP); break; } catch (IOException ioe) { connection.close(); } } if (connection == null) { connection = createImapConnection(); } return connection; } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); } | ImapStore extends RemoteStore { ImapConnection getConnection() throws MessagingException { ImapConnection connection; while ((connection = pollConnection()) != null) { try { connection.executeSimpleCommand(Commands.NOOP); break; } catch (IOException ioe) { connection.close(); } } if (connection == null) { connection = createImapConnection(); } return connection; } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } | ImapStore extends RemoteStore { ImapConnection getConnection() throws MessagingException { ImapConnection connection; while ((connection = pollConnection()) != null) { try { connection.executeSimpleCommand(Commands.NOOP); break; } catch (IOException ioe) { connection.close(); } } if (connection == null) { connection = createImapConnection(); } return connection; } ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider); static ImapStoreSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull ImapFolder getFolder(String folderId); @Override @NonNull List<ImapFolder> getFolders(boolean forceListAll); @Override @NonNull List<ImapFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @NonNull List<ImapFolder> getPersonalNamespaces(boolean forceListAll); @Override void checkSettings(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); @Override boolean isPushCapable(); @Override boolean isExpungeCapable(); @Override Pusher getPusher(PushReceiver receiver); String getFolderName(String id); } |
@Test public void testGetImapSequenceValues() { String[] expected; List<String> actual; expected = new String[] {"1"}; actual = ImapUtility.getImapSequenceValues("1"); assertArrayEquals(expected, actual.toArray()); expected = new String[] {"2147483648"}; actual = ImapUtility.getImapSequenceValues("2147483648"); assertArrayEquals(expected, actual.toArray()); expected = new String[] {"4294967295"}; actual = ImapUtility.getImapSequenceValues("4294967295"); assertArrayEquals(expected, actual.toArray()); expected = new String[] {"1", "3", "2"}; actual = ImapUtility.getImapSequenceValues("1,3,2"); assertArrayEquals(expected, actual.toArray()); expected = new String[] {"4", "5", "6"}; actual = ImapUtility.getImapSequenceValues("4:6"); assertArrayEquals(expected, actual.toArray()); expected = new String[] {"9", "8", "7"}; actual = ImapUtility.getImapSequenceValues("9:7"); assertArrayEquals(expected, actual.toArray()); expected = new String[] {"1", "2", "3", "4", "9", "8", "7"}; actual = ImapUtility.getImapSequenceValues("1,2:4,9:7"); assertArrayEquals(expected, actual.toArray()); expected = new String[] {"2147483646", "2147483647", "2147483648"}; actual = ImapUtility.getImapSequenceValues("2147483646:2147483648"); assertArrayEquals(expected, actual.toArray()); expected = new String[] { "1", "5" }; actual = ImapUtility.getImapSequenceValues("1,x,5"); assertArrayEquals(expected, actual.toArray()); expected = new String[] { "1", "2", "3" }; actual = ImapUtility.getImapSequenceValues("a:d,1:3"); assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapSequenceValues(""); assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapSequenceValues(null); assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapSequenceValues("a"); assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapSequenceValues("1:x"); assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapSequenceValues("4294967296:4294967297"); assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapSequenceValues("4294967296"); assertArrayEquals(expected, actual.toArray()); } | public static List<String> getImapSequenceValues(String set) { List<String> list = new ArrayList<String>(); if (set != null) { String[] setItems = set.split(","); for (String item : setItems) { if (item.indexOf(':') == -1) { if (isNumberValid(item)) { list.add(item); } } else { list.addAll(getImapRangeValues(item)); } } } return list; } | ImapUtility { public static List<String> getImapSequenceValues(String set) { List<String> list = new ArrayList<String>(); if (set != null) { String[] setItems = set.split(","); for (String item : setItems) { if (item.indexOf(':') == -1) { if (isNumberValid(item)) { list.add(item); } } else { list.addAll(getImapRangeValues(item)); } } } return list; } } | ImapUtility { public static List<String> getImapSequenceValues(String set) { List<String> list = new ArrayList<String>(); if (set != null) { String[] setItems = set.split(","); for (String item : setItems) { if (item.indexOf(':') == -1) { if (isNumberValid(item)) { list.add(item); } } else { list.addAll(getImapRangeValues(item)); } } } return list; } } | ImapUtility { public static List<String> getImapSequenceValues(String set) { List<String> list = new ArrayList<String>(); if (set != null) { String[] setItems = set.split(","); for (String item : setItems) { if (item.indexOf(':') == -1) { if (isNumberValid(item)) { list.add(item); } } else { list.addAll(getImapRangeValues(item)); } } } return list; } static List<String> getImapSequenceValues(String set); static List<String> getImapRangeValues(String range); static String encodeString(String str); static ImapResponse getLastResponse(List<ImapResponse> responses); } | ImapUtility { public static List<String> getImapSequenceValues(String set) { List<String> list = new ArrayList<String>(); if (set != null) { String[] setItems = set.split(","); for (String item : setItems) { if (item.indexOf(':') == -1) { if (isNumberValid(item)) { list.add(item); } } else { list.addAll(getImapRangeValues(item)); } } } return list; } static List<String> getImapSequenceValues(String set); static List<String> getImapRangeValues(String range); static String encodeString(String str); static ImapResponse getLastResponse(List<ImapResponse> responses); } |
@Test public void testGetImapRangeValues() { String[] expected; List<String> actual; expected = new String[] {"1", "2", "3"}; actual = ImapUtility.getImapRangeValues("1:3"); assertArrayEquals(expected, actual.toArray()); expected = new String[] {"16", "15", "14"}; actual = ImapUtility.getImapRangeValues("16:14"); assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapRangeValues(""); assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapRangeValues(null); assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapRangeValues("a"); assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapRangeValues("6"); assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapRangeValues("1:3,6"); assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapRangeValues("1:x"); assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapRangeValues("1:*"); assertArrayEquals(expected, actual.toArray()); } | public static List<String> getImapRangeValues(String range) { List<String> list = new ArrayList<String>(); try { if (range != null) { int colonPos = range.indexOf(':'); if (colonPos > 0) { long first = Long.parseLong(range.substring(0, colonPos)); long second = Long.parseLong(range.substring(colonPos + 1)); if (is32bitValue(first) && is32bitValue(second)) { if (first < second) { for (long i = first; i <= second; i++) { list.add(Long.toString(i)); } } else { for (long i = first; i >= second; i--) { list.add(Long.toString(i)); } } } else { Timber.d("Invalid range: %s", range); } } } } catch (NumberFormatException e) { Timber.d(e, "Invalid range value: %s", range); } return list; } | ImapUtility { public static List<String> getImapRangeValues(String range) { List<String> list = new ArrayList<String>(); try { if (range != null) { int colonPos = range.indexOf(':'); if (colonPos > 0) { long first = Long.parseLong(range.substring(0, colonPos)); long second = Long.parseLong(range.substring(colonPos + 1)); if (is32bitValue(first) && is32bitValue(second)) { if (first < second) { for (long i = first; i <= second; i++) { list.add(Long.toString(i)); } } else { for (long i = first; i >= second; i--) { list.add(Long.toString(i)); } } } else { Timber.d("Invalid range: %s", range); } } } } catch (NumberFormatException e) { Timber.d(e, "Invalid range value: %s", range); } return list; } } | ImapUtility { public static List<String> getImapRangeValues(String range) { List<String> list = new ArrayList<String>(); try { if (range != null) { int colonPos = range.indexOf(':'); if (colonPos > 0) { long first = Long.parseLong(range.substring(0, colonPos)); long second = Long.parseLong(range.substring(colonPos + 1)); if (is32bitValue(first) && is32bitValue(second)) { if (first < second) { for (long i = first; i <= second; i++) { list.add(Long.toString(i)); } } else { for (long i = first; i >= second; i--) { list.add(Long.toString(i)); } } } else { Timber.d("Invalid range: %s", range); } } } } catch (NumberFormatException e) { Timber.d(e, "Invalid range value: %s", range); } return list; } } | ImapUtility { public static List<String> getImapRangeValues(String range) { List<String> list = new ArrayList<String>(); try { if (range != null) { int colonPos = range.indexOf(':'); if (colonPos > 0) { long first = Long.parseLong(range.substring(0, colonPos)); long second = Long.parseLong(range.substring(colonPos + 1)); if (is32bitValue(first) && is32bitValue(second)) { if (first < second) { for (long i = first; i <= second; i++) { list.add(Long.toString(i)); } } else { for (long i = first; i >= second; i--) { list.add(Long.toString(i)); } } } else { Timber.d("Invalid range: %s", range); } } } } catch (NumberFormatException e) { Timber.d(e, "Invalid range value: %s", range); } return list; } static List<String> getImapSequenceValues(String set); static List<String> getImapRangeValues(String range); static String encodeString(String str); static ImapResponse getLastResponse(List<ImapResponse> responses); } | ImapUtility { public static List<String> getImapRangeValues(String range) { List<String> list = new ArrayList<String>(); try { if (range != null) { int colonPos = range.indexOf(':'); if (colonPos > 0) { long first = Long.parseLong(range.substring(0, colonPos)); long second = Long.parseLong(range.substring(colonPos + 1)); if (is32bitValue(first) && is32bitValue(second)) { if (first < second) { for (long i = first; i <= second; i++) { list.add(Long.toString(i)); } } else { for (long i = first; i >= second; i--) { list.add(Long.toString(i)); } } } else { Timber.d("Invalid range: %s", range); } } } } catch (NumberFormatException e) { Timber.d(e, "Invalid range value: %s", range); } return list; } static List<String> getImapSequenceValues(String set); static List<String> getImapRangeValues(String range); static String encodeString(String str); static ImapResponse getLastResponse(List<ImapResponse> responses); } |
@Test public void parse_withValidArgument() throws Exception { ImapPushState result = ImapPushState.parse("uidNext=42"); assertNotNull(result); assertEquals(42L, result.uidNext); } | public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } ImapPushState(long uidNext); } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } ImapPushState(long uidNext); static ImapPushState parse(String pushState); @Override String toString(); } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } ImapPushState(long uidNext); static ImapPushState parse(String pushState); @Override String toString(); final long uidNext; } |
@Test public void parse_withNullArgument_shouldReturnUidNextOfMinusOne() throws Exception { ImapPushState result = ImapPushState.parse(null); assertNotNull(result); assertEquals(-1L, result.uidNext); } | public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } ImapPushState(long uidNext); } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } ImapPushState(long uidNext); static ImapPushState parse(String pushState); @Override String toString(); } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } ImapPushState(long uidNext); static ImapPushState parse(String pushState); @Override String toString(); final long uidNext; } |
@Test public void parse_withEmptyArgument_shouldReturnUidNextOfMinusOne() throws Exception { ImapPushState result = ImapPushState.parse(""); assertNotNull(result); assertEquals(-1L, result.uidNext); } | public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } ImapPushState(long uidNext); } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } ImapPushState(long uidNext); static ImapPushState parse(String pushState); @Override String toString(); } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } ImapPushState(long uidNext); static ImapPushState parse(String pushState); @Override String toString(); final long uidNext; } |
@Test public void testTextQuoteToHtmlBlockquote() { String message = "Panama!\r\n" + "\r\n" + "Bob Barker <[email protected]> wrote:\r\n" + "> a canal\r\n" + ">\r\n" + "> Dorothy Jo Gideon <[email protected]> espoused:\r\n" + "> >A man, a plan...\r\n" + "> Too easy!\r\n" + "\r\n" + "Nice job :)\r\n" + ">> Guess!"; String result = HtmlConverter.textToHtml(message); writeToFile(result); assertEquals("<pre class=\"k9mail\">" + "Panama!<br />" + "<br />" + "Bob Barker <[email protected]> wrote:<br />" + "<blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;\">" + " a canal<br />" + "<br />" + " Dorothy Jo Gideon <[email protected]> espoused:<br />" + "<blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;\">" + "A man, a plan...<br />" + "</blockquote>" + " Too easy!<br />" + "</blockquote>" + "<br />" + "Nice job :)<br />" + "<blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;\">" + "<blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;\">" + " Guess!" + "</blockquote>" + "</blockquote>" + "</pre>", result); } | public static String textToHtml(String text) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { return simpleTextToHtml(text); } StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); boolean isStartOfLine = true; int spaces = 0; int quoteDepth = 0; int quotesThisLine = 0; for (int index = 0; index < text.length(); index++) { char c = text.charAt(index); if (isStartOfLine) { switch (c) { case ' ': spaces++; break; case '>': quotesThisLine++; spaces = 0; break; case '\n': appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = true; quotesThisLine = 0; break; default: isStartOfLine = false; appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = false; break; } } else { appendchar(buff, c); if (c == '\n') { isStartOfLine = true; quotesThisLine = 0; } } } if (quoteDepth > 0) { for (int i = quoteDepth; i > 0; i--) { buff.append(HTML_BLOCKQUOTE_END); } } text = buff.toString(); text = text.replaceAll( "\\Q" + HTML_NEWLINE + "\\E((\\Q" + HTML_NEWLINE + "\\E)+?)\\Q" + HTML_BLOCKQUOTE_END + "\\E", HTML_BLOCKQUOTE_END + "$1" ); text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>"); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); sb.append(htmlifyMessageHeader()); UriLinkifier.linkifyText(text, sb); sb.append(htmlifyMessageFooter()); text = sb.toString(); text = text.replaceAll("<gt>", ">"); return text; } | HtmlConverter { public static String textToHtml(String text) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { return simpleTextToHtml(text); } StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); boolean isStartOfLine = true; int spaces = 0; int quoteDepth = 0; int quotesThisLine = 0; for (int index = 0; index < text.length(); index++) { char c = text.charAt(index); if (isStartOfLine) { switch (c) { case ' ': spaces++; break; case '>': quotesThisLine++; spaces = 0; break; case '\n': appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = true; quotesThisLine = 0; break; default: isStartOfLine = false; appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = false; break; } } else { appendchar(buff, c); if (c == '\n') { isStartOfLine = true; quotesThisLine = 0; } } } if (quoteDepth > 0) { for (int i = quoteDepth; i > 0; i--) { buff.append(HTML_BLOCKQUOTE_END); } } text = buff.toString(); text = text.replaceAll( "\\Q" + HTML_NEWLINE + "\\E((\\Q" + HTML_NEWLINE + "\\E)+?)\\Q" + HTML_BLOCKQUOTE_END + "\\E", HTML_BLOCKQUOTE_END + "$1" ); text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>"); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); sb.append(htmlifyMessageHeader()); UriLinkifier.linkifyText(text, sb); sb.append(htmlifyMessageFooter()); text = sb.toString(); text = text.replaceAll("<gt>", ">"); return text; } } | HtmlConverter { public static String textToHtml(String text) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { return simpleTextToHtml(text); } StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); boolean isStartOfLine = true; int spaces = 0; int quoteDepth = 0; int quotesThisLine = 0; for (int index = 0; index < text.length(); index++) { char c = text.charAt(index); if (isStartOfLine) { switch (c) { case ' ': spaces++; break; case '>': quotesThisLine++; spaces = 0; break; case '\n': appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = true; quotesThisLine = 0; break; default: isStartOfLine = false; appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = false; break; } } else { appendchar(buff, c); if (c == '\n') { isStartOfLine = true; quotesThisLine = 0; } } } if (quoteDepth > 0) { for (int i = quoteDepth; i > 0; i--) { buff.append(HTML_BLOCKQUOTE_END); } } text = buff.toString(); text = text.replaceAll( "\\Q" + HTML_NEWLINE + "\\E((\\Q" + HTML_NEWLINE + "\\E)+?)\\Q" + HTML_BLOCKQUOTE_END + "\\E", HTML_BLOCKQUOTE_END + "$1" ); text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>"); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); sb.append(htmlifyMessageHeader()); UriLinkifier.linkifyText(text, sb); sb.append(htmlifyMessageFooter()); text = sb.toString(); text = text.replaceAll("<gt>", ">"); return text; } } | HtmlConverter { public static String textToHtml(String text) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { return simpleTextToHtml(text); } StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); boolean isStartOfLine = true; int spaces = 0; int quoteDepth = 0; int quotesThisLine = 0; for (int index = 0; index < text.length(); index++) { char c = text.charAt(index); if (isStartOfLine) { switch (c) { case ' ': spaces++; break; case '>': quotesThisLine++; spaces = 0; break; case '\n': appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = true; quotesThisLine = 0; break; default: isStartOfLine = false; appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = false; break; } } else { appendchar(buff, c); if (c == '\n') { isStartOfLine = true; quotesThisLine = 0; } } } if (quoteDepth > 0) { for (int i = quoteDepth; i > 0; i--) { buff.append(HTML_BLOCKQUOTE_END); } } text = buff.toString(); text = text.replaceAll( "\\Q" + HTML_NEWLINE + "\\E((\\Q" + HTML_NEWLINE + "\\E)+?)\\Q" + HTML_BLOCKQUOTE_END + "\\E", HTML_BLOCKQUOTE_END + "$1" ); text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>"); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); sb.append(htmlifyMessageHeader()); UriLinkifier.linkifyText(text, sb); sb.append(htmlifyMessageFooter()); text = sb.toString(); text = text.replaceAll("<gt>", ">"); return text; } static String htmlToText(final String html); static String textToHtml(String text); static String convertEmoji2Img(String html); static String wrapStatusMessage(CharSequence status); static String wrapMessageContent(CharSequence messageContent); static String textToHtmlFragment(final String text); static Spanned htmlToSpanned(String html); } | HtmlConverter { public static String textToHtml(String text) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { return simpleTextToHtml(text); } StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); boolean isStartOfLine = true; int spaces = 0; int quoteDepth = 0; int quotesThisLine = 0; for (int index = 0; index < text.length(); index++) { char c = text.charAt(index); if (isStartOfLine) { switch (c) { case ' ': spaces++; break; case '>': quotesThisLine++; spaces = 0; break; case '\n': appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = true; quotesThisLine = 0; break; default: isStartOfLine = false; appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = false; break; } } else { appendchar(buff, c); if (c == '\n') { isStartOfLine = true; quotesThisLine = 0; } } } if (quoteDepth > 0) { for (int i = quoteDepth; i > 0; i--) { buff.append(HTML_BLOCKQUOTE_END); } } text = buff.toString(); text = text.replaceAll( "\\Q" + HTML_NEWLINE + "\\E((\\Q" + HTML_NEWLINE + "\\E)+?)\\Q" + HTML_BLOCKQUOTE_END + "\\E", HTML_BLOCKQUOTE_END + "$1" ); text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>"); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); sb.append(htmlifyMessageHeader()); UriLinkifier.linkifyText(text, sb); sb.append(htmlifyMessageFooter()); text = sb.toString(); text = text.replaceAll("<gt>", ">"); return text; } static String htmlToText(final String html); static String textToHtml(String text); static String convertEmoji2Img(String html); static String wrapStatusMessage(CharSequence status); static String wrapMessageContent(CharSequence messageContent); static String textToHtmlFragment(final String text); static Spanned htmlToSpanned(String html); } |
@Test public void parse_withInvalidArgument_shouldReturnUidNextOfMinusOne() throws Exception { ImapPushState result = ImapPushState.parse("xyz"); assertNotNull(result); assertEquals(-1L, result.uidNext); } | public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } ImapPushState(long uidNext); } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } ImapPushState(long uidNext); static ImapPushState parse(String pushState); @Override String toString(); } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } ImapPushState(long uidNext); static ImapPushState parse(String pushState); @Override String toString(); final long uidNext; } |
@Test public void parse_withIncompleteArgument_shouldReturnUidNextOfMinusOne() throws Exception { ImapPushState result = ImapPushState.parse("uidNext="); assertNotNull(result); assertEquals(-1L, result.uidNext); } | public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } ImapPushState(long uidNext); } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } ImapPushState(long uidNext); static ImapPushState parse(String pushState); @Override String toString(); } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } ImapPushState(long uidNext); static ImapPushState parse(String pushState); @Override String toString(); final long uidNext; } |
@Test public void parse_withoutIntegerAsUidNext_shouldReturnUidNextOfMinusOne() throws Exception { ImapPushState result = ImapPushState.parse("uidNext=xyz"); assertNotNull(result); assertEquals(-1L, result.uidNext); } | public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } ImapPushState(long uidNext); } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } ImapPushState(long uidNext); static ImapPushState parse(String pushState); @Override String toString(); } | ImapPushState { public static ImapPushState parse(String pushState) { if (pushState == null || !pushState.startsWith(PUSH_STATE_PREFIX)) { return createDefaultImapPushState(); } String value = pushState.substring(PUSH_STATE_PREFIX_LENGTH); try { long newUidNext = Long.parseLong(value); return new ImapPushState(newUidNext); } catch (NumberFormatException e) { Timber.e(e, "Unable to part uidNext value %s", value); } return createDefaultImapPushState(); } ImapPushState(long uidNext); static ImapPushState parse(String pushState); @Override String toString(); final long uidNext; } |
@Test public void toString_shouldReturnExpectedResult() throws Exception { ImapPushState imapPushState = new ImapPushState(23L); String result = imapPushState.toString(); assertEquals("uidNext=23", result); } | @Override public String toString() { return "uidNext=" + uidNext; } | ImapPushState { @Override public String toString() { return "uidNext=" + uidNext; } } | ImapPushState { @Override public String toString() { return "uidNext=" + uidNext; } ImapPushState(long uidNext); } | ImapPushState { @Override public String toString() { return "uidNext=" + uidNext; } ImapPushState(long uidNext); static ImapPushState parse(String pushState); @Override String toString(); } | ImapPushState { @Override public String toString() { return "uidNext=" + uidNext; } ImapPushState(long uidNext); static ImapPushState parse(String pushState); @Override String toString(); final long uidNext; } |
@Test public void getAlertText_withProperAlertResponse() throws Exception { ImapResponse imapResponse = createImapResponse("x NO [ALERT] Please don't do that"); String result = AlertResponse.getAlertText(imapResponse); assertEquals("Please don't do that", result); } | public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } private AlertResponse(); } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } private AlertResponse(); static String getAlertText(ImapResponse response); } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } private AlertResponse(); static String getAlertText(ImapResponse response); } |
@Test public void getAlertText_withoutResponseCodeText_shouldReturnNull() throws Exception { ImapResponse imapResponse = createImapResponse("x NO"); String result = AlertResponse.getAlertText(imapResponse); assertNull(result); } | public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } private AlertResponse(); } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } private AlertResponse(); static String getAlertText(ImapResponse response); } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } private AlertResponse(); static String getAlertText(ImapResponse response); } |
@Test public void getAlertText_withoutAlertText_shouldReturnNull() throws Exception { ImapResponse imapResponse = createImapResponse("x NO [ALERT]"); String result = AlertResponse.getAlertText(imapResponse); assertNull(result); } | public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } private AlertResponse(); } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } private AlertResponse(); static String getAlertText(ImapResponse response); } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } private AlertResponse(); static String getAlertText(ImapResponse response); } |
@Test public void getAlertText_withoutResponseCodeTextList_shouldReturnNull() throws Exception { ImapResponse imapResponse = createImapResponse("x NO ALERT ALARM!"); String result = AlertResponse.getAlertText(imapResponse); assertNull(result); } | public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } private AlertResponse(); } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } private AlertResponse(); static String getAlertText(ImapResponse response); } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } private AlertResponse(); static String getAlertText(ImapResponse response); } |
@Test public void getAlertText_withResponseCodeTextContainingTooManyItems_shouldReturnNull() throws Exception { ImapResponse imapResponse = createImapResponse("x NO [ALERT SOMETHING] ALARM!"); String result = AlertResponse.getAlertText(imapResponse); assertNull(result); } | public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } private AlertResponse(); } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } private AlertResponse(); static String getAlertText(ImapResponse response); } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } private AlertResponse(); static String getAlertText(ImapResponse response); } |
@Test public void getAlertText_withWrongResponseCodeText_shouldReturnNull() throws Exception { ImapResponse imapResponse = createImapResponse("x NO [ALARM] ALERT!"); String result = AlertResponse.getAlertText(imapResponse); assertNull(result); } | public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } private AlertResponse(); } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } private AlertResponse(); static String getAlertText(ImapResponse response); } | AlertResponse { public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } private AlertResponse(); static String getAlertText(ImapResponse response); } |
@Test public void testTextQuoteToHtmlBlockquoteIndented() { String message = "*facepalm*\r\n" + "\r\n" + "Bob Barker <[email protected]> wrote:\r\n" + "> A wise man once said...\r\n" + ">\r\n" + "> LOL F1RST!!!!!\r\n" + ">\r\n" + "> :)"; String result = HtmlConverter.textToHtml(message); writeToFile(result); assertEquals("<pre class=\"k9mail\">" + "*facepalm*<br />" + "<br />" + "Bob Barker <[email protected]> wrote:<br />" + "<blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;\">" + " A wise man once said...<br />" + "<br />" + " LOL F1RST!!!!!<br />" + "<br />" + " :)" + "</blockquote></pre>", result); } | public static String textToHtml(String text) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { return simpleTextToHtml(text); } StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); boolean isStartOfLine = true; int spaces = 0; int quoteDepth = 0; int quotesThisLine = 0; for (int index = 0; index < text.length(); index++) { char c = text.charAt(index); if (isStartOfLine) { switch (c) { case ' ': spaces++; break; case '>': quotesThisLine++; spaces = 0; break; case '\n': appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = true; quotesThisLine = 0; break; default: isStartOfLine = false; appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = false; break; } } else { appendchar(buff, c); if (c == '\n') { isStartOfLine = true; quotesThisLine = 0; } } } if (quoteDepth > 0) { for (int i = quoteDepth; i > 0; i--) { buff.append(HTML_BLOCKQUOTE_END); } } text = buff.toString(); text = text.replaceAll( "\\Q" + HTML_NEWLINE + "\\E((\\Q" + HTML_NEWLINE + "\\E)+?)\\Q" + HTML_BLOCKQUOTE_END + "\\E", HTML_BLOCKQUOTE_END + "$1" ); text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>"); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); sb.append(htmlifyMessageHeader()); UriLinkifier.linkifyText(text, sb); sb.append(htmlifyMessageFooter()); text = sb.toString(); text = text.replaceAll("<gt>", ">"); return text; } | HtmlConverter { public static String textToHtml(String text) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { return simpleTextToHtml(text); } StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); boolean isStartOfLine = true; int spaces = 0; int quoteDepth = 0; int quotesThisLine = 0; for (int index = 0; index < text.length(); index++) { char c = text.charAt(index); if (isStartOfLine) { switch (c) { case ' ': spaces++; break; case '>': quotesThisLine++; spaces = 0; break; case '\n': appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = true; quotesThisLine = 0; break; default: isStartOfLine = false; appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = false; break; } } else { appendchar(buff, c); if (c == '\n') { isStartOfLine = true; quotesThisLine = 0; } } } if (quoteDepth > 0) { for (int i = quoteDepth; i > 0; i--) { buff.append(HTML_BLOCKQUOTE_END); } } text = buff.toString(); text = text.replaceAll( "\\Q" + HTML_NEWLINE + "\\E((\\Q" + HTML_NEWLINE + "\\E)+?)\\Q" + HTML_BLOCKQUOTE_END + "\\E", HTML_BLOCKQUOTE_END + "$1" ); text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>"); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); sb.append(htmlifyMessageHeader()); UriLinkifier.linkifyText(text, sb); sb.append(htmlifyMessageFooter()); text = sb.toString(); text = text.replaceAll("<gt>", ">"); return text; } } | HtmlConverter { public static String textToHtml(String text) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { return simpleTextToHtml(text); } StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); boolean isStartOfLine = true; int spaces = 0; int quoteDepth = 0; int quotesThisLine = 0; for (int index = 0; index < text.length(); index++) { char c = text.charAt(index); if (isStartOfLine) { switch (c) { case ' ': spaces++; break; case '>': quotesThisLine++; spaces = 0; break; case '\n': appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = true; quotesThisLine = 0; break; default: isStartOfLine = false; appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = false; break; } } else { appendchar(buff, c); if (c == '\n') { isStartOfLine = true; quotesThisLine = 0; } } } if (quoteDepth > 0) { for (int i = quoteDepth; i > 0; i--) { buff.append(HTML_BLOCKQUOTE_END); } } text = buff.toString(); text = text.replaceAll( "\\Q" + HTML_NEWLINE + "\\E((\\Q" + HTML_NEWLINE + "\\E)+?)\\Q" + HTML_BLOCKQUOTE_END + "\\E", HTML_BLOCKQUOTE_END + "$1" ); text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>"); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); sb.append(htmlifyMessageHeader()); UriLinkifier.linkifyText(text, sb); sb.append(htmlifyMessageFooter()); text = sb.toString(); text = text.replaceAll("<gt>", ">"); return text; } } | HtmlConverter { public static String textToHtml(String text) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { return simpleTextToHtml(text); } StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); boolean isStartOfLine = true; int spaces = 0; int quoteDepth = 0; int quotesThisLine = 0; for (int index = 0; index < text.length(); index++) { char c = text.charAt(index); if (isStartOfLine) { switch (c) { case ' ': spaces++; break; case '>': quotesThisLine++; spaces = 0; break; case '\n': appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = true; quotesThisLine = 0; break; default: isStartOfLine = false; appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = false; break; } } else { appendchar(buff, c); if (c == '\n') { isStartOfLine = true; quotesThisLine = 0; } } } if (quoteDepth > 0) { for (int i = quoteDepth; i > 0; i--) { buff.append(HTML_BLOCKQUOTE_END); } } text = buff.toString(); text = text.replaceAll( "\\Q" + HTML_NEWLINE + "\\E((\\Q" + HTML_NEWLINE + "\\E)+?)\\Q" + HTML_BLOCKQUOTE_END + "\\E", HTML_BLOCKQUOTE_END + "$1" ); text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>"); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); sb.append(htmlifyMessageHeader()); UriLinkifier.linkifyText(text, sb); sb.append(htmlifyMessageFooter()); text = sb.toString(); text = text.replaceAll("<gt>", ">"); return text; } static String htmlToText(final String html); static String textToHtml(String text); static String convertEmoji2Img(String html); static String wrapStatusMessage(CharSequence status); static String wrapMessageContent(CharSequence messageContent); static String textToHtmlFragment(final String text); static Spanned htmlToSpanned(String html); } | HtmlConverter { public static String textToHtml(String text) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { return simpleTextToHtml(text); } StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); boolean isStartOfLine = true; int spaces = 0; int quoteDepth = 0; int quotesThisLine = 0; for (int index = 0; index < text.length(); index++) { char c = text.charAt(index); if (isStartOfLine) { switch (c) { case ' ': spaces++; break; case '>': quotesThisLine++; spaces = 0; break; case '\n': appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = true; quotesThisLine = 0; break; default: isStartOfLine = false; appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = false; break; } } else { appendchar(buff, c); if (c == '\n') { isStartOfLine = true; quotesThisLine = 0; } } } if (quoteDepth > 0) { for (int i = quoteDepth; i > 0; i--) { buff.append(HTML_BLOCKQUOTE_END); } } text = buff.toString(); text = text.replaceAll( "\\Q" + HTML_NEWLINE + "\\E((\\Q" + HTML_NEWLINE + "\\E)+?)\\Q" + HTML_BLOCKQUOTE_END + "\\E", HTML_BLOCKQUOTE_END + "$1" ); text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>"); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); sb.append(htmlifyMessageHeader()); UriLinkifier.linkifyText(text, sb); sb.append(htmlifyMessageFooter()); text = sb.toString(); text = text.replaceAll("<gt>", ">"); return text; } static String htmlToText(final String html); static String textToHtml(String text); static String convertEmoji2Img(String html); static String wrapStatusMessage(CharSequence status); static String wrapMessageContent(CharSequence messageContent); static String textToHtmlFragment(final String text); static Spanned htmlToSpanned(String html); } |
@Test public void findEncryptedPartsShouldReturnEmptyListForEmptyMessage() throws Exception { MimeMessage emptyMessage = new MimeMessage(); List<Part> encryptedParts = MessageDecryptVerifier.findEncryptedParts(emptyMessage); assertEquals(0, encryptedParts.size()); } | public static List<Part> findEncryptedParts(Part startPart) { List<Part> encryptedParts = new ArrayList<>(); Stack<Part> partsToCheck = new Stack<>(); partsToCheck.push(startPart); while (!partsToCheck.isEmpty()) { Part part = partsToCheck.pop(); Body body = part.getBody(); if (isPartMultipartEncrypted(part)) { encryptedParts.add(part); continue; } if (body instanceof Multipart) { Multipart multipart = (Multipart) body; for (int i = multipart.getCount() - 1; i >= 0; i--) { BodyPart bodyPart = multipart.getBodyPart(i); partsToCheck.push(bodyPart); } } } return encryptedParts; } | MessageDecryptVerifier { public static List<Part> findEncryptedParts(Part startPart) { List<Part> encryptedParts = new ArrayList<>(); Stack<Part> partsToCheck = new Stack<>(); partsToCheck.push(startPart); while (!partsToCheck.isEmpty()) { Part part = partsToCheck.pop(); Body body = part.getBody(); if (isPartMultipartEncrypted(part)) { encryptedParts.add(part); continue; } if (body instanceof Multipart) { Multipart multipart = (Multipart) body; for (int i = multipart.getCount() - 1; i >= 0; i--) { BodyPart bodyPart = multipart.getBodyPart(i); partsToCheck.push(bodyPart); } } } return encryptedParts; } } | MessageDecryptVerifier { public static List<Part> findEncryptedParts(Part startPart) { List<Part> encryptedParts = new ArrayList<>(); Stack<Part> partsToCheck = new Stack<>(); partsToCheck.push(startPart); while (!partsToCheck.isEmpty()) { Part part = partsToCheck.pop(); Body body = part.getBody(); if (isPartMultipartEncrypted(part)) { encryptedParts.add(part); continue; } if (body instanceof Multipart) { Multipart multipart = (Multipart) body; for (int i = multipart.getCount() - 1; i >= 0; i--) { BodyPart bodyPart = multipart.getBodyPart(i); partsToCheck.push(bodyPart); } } } return encryptedParts; } } | MessageDecryptVerifier { public static List<Part> findEncryptedParts(Part startPart) { List<Part> encryptedParts = new ArrayList<>(); Stack<Part> partsToCheck = new Stack<>(); partsToCheck.push(startPart); while (!partsToCheck.isEmpty()) { Part part = partsToCheck.pop(); Body body = part.getBody(); if (isPartMultipartEncrypted(part)) { encryptedParts.add(part); continue; } if (body instanceof Multipart) { Multipart multipart = (Multipart) body; for (int i = multipart.getCount() - 1; i >= 0; i--) { BodyPart bodyPart = multipart.getBodyPart(i); partsToCheck.push(bodyPart); } } } return encryptedParts; } static Part findPrimaryEncryptedOrSignedPart(Part part, List<Part> outputExtraParts); static List<Part> findEncryptedParts(Part startPart); static List<Part> findSignedParts(Part startPart, MessageCryptoAnnotations messageCryptoAnnotations); static List<Part> findPgpInlineParts(Part startPart); static byte[] getSignatureData(Part part); static boolean isPgpMimeEncryptedOrSignedPart(Part part); static boolean isSMimeEncryptedOrSignedPart(Part part); static boolean isPartPgpInlineEncrypted(@Nullable Part part); } | MessageDecryptVerifier { public static List<Part> findEncryptedParts(Part startPart) { List<Part> encryptedParts = new ArrayList<>(); Stack<Part> partsToCheck = new Stack<>(); partsToCheck.push(startPart); while (!partsToCheck.isEmpty()) { Part part = partsToCheck.pop(); Body body = part.getBody(); if (isPartMultipartEncrypted(part)) { encryptedParts.add(part); continue; } if (body instanceof Multipart) { Multipart multipart = (Multipart) body; for (int i = multipart.getCount() - 1; i >= 0; i--) { BodyPart bodyPart = multipart.getBodyPart(i); partsToCheck.push(bodyPart); } } } return encryptedParts; } static Part findPrimaryEncryptedOrSignedPart(Part part, List<Part> outputExtraParts); static List<Part> findEncryptedParts(Part startPart); static List<Part> findSignedParts(Part startPart, MessageCryptoAnnotations messageCryptoAnnotations); static List<Part> findPgpInlineParts(Part startPart); static byte[] getSignatureData(Part part); static boolean isPgpMimeEncryptedOrSignedPart(Part part); static boolean isSMimeEncryptedOrSignedPart(Part part); static boolean isPartPgpInlineEncrypted(@Nullable Part part); } |
@Test public void parse_withTaggedResponse_shouldReturnNull() throws Exception { CapabilityResponse result = parse("1 OK"); assertNull(result); } | public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); static CapabilityResponse parse(List<ImapResponse> responses); Set<String> getCapabilities(); } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); static CapabilityResponse parse(List<ImapResponse> responses); Set<String> getCapabilities(); } |
@Test public void parse_withoutOkResponse_shouldReturnNull() throws Exception { CapabilityResponse result = parse("* BAD Go Away"); assertNull(result); } | public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); static CapabilityResponse parse(List<ImapResponse> responses); Set<String> getCapabilities(); } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); static CapabilityResponse parse(List<ImapResponse> responses); Set<String> getCapabilities(); } |
@Test public void parse_withOkResponseWithoutList_shouldReturnNull() throws Exception { CapabilityResponse result = parse("* OK Welcome"); assertNull(result); } | public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); static CapabilityResponse parse(List<ImapResponse> responses); Set<String> getCapabilities(); } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); static CapabilityResponse parse(List<ImapResponse> responses); Set<String> getCapabilities(); } |
@Test public void parse_withListInCapabilityResponse_shouldReturnNull() throws Exception { ImapList list = createImapResponse("* CAPABILITY IMAP4rev1 []"); CapabilityResponse result = CapabilityResponse.parse(list); assertNull(result); } | public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); static CapabilityResponse parse(List<ImapResponse> responses); Set<String> getCapabilities(); } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); static CapabilityResponse parse(List<ImapResponse> responses); Set<String> getCapabilities(); } |
@Test public void parse_withoutCapabilityResponse_shouldReturnNull() throws Exception { ImapList list = createImapResponse("* EXISTS 1"); CapabilityResponse result = CapabilityResponse.parse(list); assertNull(result); } | public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); static CapabilityResponse parse(List<ImapResponse> responses); Set<String> getCapabilities(); } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); static CapabilityResponse parse(List<ImapResponse> responses); Set<String> getCapabilities(); } |
@Test public void parse_withEmptyResponseList_shouldReturnNull() throws Exception { List<ImapResponse> responses = Collections.emptyList(); CapabilityResponse result = CapabilityResponse.parse(responses); assertNull(result); } | public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); static CapabilityResponse parse(List<ImapResponse> responses); Set<String> getCapabilities(); } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); static CapabilityResponse parse(List<ImapResponse> responses); Set<String> getCapabilities(); } |
@Test public void parse_withoutCapabilityResponseInResponseList_shouldReturnNull() throws Exception { List<ImapResponse> responses = Collections.singletonList(createImapResponse("* EXISTS 42")); CapabilityResponse result = CapabilityResponse.parse(responses); assertNull(result); } | public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); static CapabilityResponse parse(List<ImapResponse> responses); Set<String> getCapabilities(); } | CapabilityResponse { public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; } private CapabilityResponse(Set<String> capabilities); static CapabilityResponse parse(List<ImapResponse> responses); Set<String> getCapabilities(); } |
@Test public void parse_withTaggedResponse_shouldReturnNull() throws Exception { ImapResponse response = createImapResponse("1 OK [PERMANENTFLAGS (\\Deleted \\Seen)] Flags permitted."); PermanentFlagsResponse result = PermanentFlagsResponse.parse(response); assertNull(result); } | public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); static PermanentFlagsResponse parse(ImapResponse response); Set<Flag> getFlags(); boolean canCreateKeywords(); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); static PermanentFlagsResponse parse(ImapResponse response); Set<Flag> getFlags(); boolean canCreateKeywords(); } |
@Test public void parse_withoutOkResponse_shouldReturnNull() throws Exception { ImapResponse response = createImapResponse("* BYE See you"); PermanentFlagsResponse result = PermanentFlagsResponse.parse(response); assertNull(result); } | public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); static PermanentFlagsResponse parse(ImapResponse response); Set<Flag> getFlags(); boolean canCreateKeywords(); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); static PermanentFlagsResponse parse(ImapResponse response); Set<Flag> getFlags(); boolean canCreateKeywords(); } |
@Test public void parse_withoutResponseText_shouldReturnNull() throws Exception { ImapResponse response = createImapResponse("* OK Success"); PermanentFlagsResponse result = PermanentFlagsResponse.parse(response); assertNull(result); } | public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); static PermanentFlagsResponse parse(ImapResponse response); Set<Flag> getFlags(); boolean canCreateKeywords(); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); static PermanentFlagsResponse parse(ImapResponse response); Set<Flag> getFlags(); boolean canCreateKeywords(); } |
@Test public void testPreserveSpacesAtFirst() { String message = "foo\r\n" + " bar\r\n" + " baz\r\n"; String result = HtmlConverter.textToHtml(message); writeToFile(result); assertEquals("<pre class=\"k9mail\">" + "foo<br />" + " bar<br />" + " baz<br />" + "</pre>", result); } | public static String textToHtml(String text) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { return simpleTextToHtml(text); } StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); boolean isStartOfLine = true; int spaces = 0; int quoteDepth = 0; int quotesThisLine = 0; for (int index = 0; index < text.length(); index++) { char c = text.charAt(index); if (isStartOfLine) { switch (c) { case ' ': spaces++; break; case '>': quotesThisLine++; spaces = 0; break; case '\n': appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = true; quotesThisLine = 0; break; default: isStartOfLine = false; appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = false; break; } } else { appendchar(buff, c); if (c == '\n') { isStartOfLine = true; quotesThisLine = 0; } } } if (quoteDepth > 0) { for (int i = quoteDepth; i > 0; i--) { buff.append(HTML_BLOCKQUOTE_END); } } text = buff.toString(); text = text.replaceAll( "\\Q" + HTML_NEWLINE + "\\E((\\Q" + HTML_NEWLINE + "\\E)+?)\\Q" + HTML_BLOCKQUOTE_END + "\\E", HTML_BLOCKQUOTE_END + "$1" ); text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>"); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); sb.append(htmlifyMessageHeader()); UriLinkifier.linkifyText(text, sb); sb.append(htmlifyMessageFooter()); text = sb.toString(); text = text.replaceAll("<gt>", ">"); return text; } | HtmlConverter { public static String textToHtml(String text) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { return simpleTextToHtml(text); } StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); boolean isStartOfLine = true; int spaces = 0; int quoteDepth = 0; int quotesThisLine = 0; for (int index = 0; index < text.length(); index++) { char c = text.charAt(index); if (isStartOfLine) { switch (c) { case ' ': spaces++; break; case '>': quotesThisLine++; spaces = 0; break; case '\n': appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = true; quotesThisLine = 0; break; default: isStartOfLine = false; appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = false; break; } } else { appendchar(buff, c); if (c == '\n') { isStartOfLine = true; quotesThisLine = 0; } } } if (quoteDepth > 0) { for (int i = quoteDepth; i > 0; i--) { buff.append(HTML_BLOCKQUOTE_END); } } text = buff.toString(); text = text.replaceAll( "\\Q" + HTML_NEWLINE + "\\E((\\Q" + HTML_NEWLINE + "\\E)+?)\\Q" + HTML_BLOCKQUOTE_END + "\\E", HTML_BLOCKQUOTE_END + "$1" ); text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>"); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); sb.append(htmlifyMessageHeader()); UriLinkifier.linkifyText(text, sb); sb.append(htmlifyMessageFooter()); text = sb.toString(); text = text.replaceAll("<gt>", ">"); return text; } } | HtmlConverter { public static String textToHtml(String text) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { return simpleTextToHtml(text); } StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); boolean isStartOfLine = true; int spaces = 0; int quoteDepth = 0; int quotesThisLine = 0; for (int index = 0; index < text.length(); index++) { char c = text.charAt(index); if (isStartOfLine) { switch (c) { case ' ': spaces++; break; case '>': quotesThisLine++; spaces = 0; break; case '\n': appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = true; quotesThisLine = 0; break; default: isStartOfLine = false; appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = false; break; } } else { appendchar(buff, c); if (c == '\n') { isStartOfLine = true; quotesThisLine = 0; } } } if (quoteDepth > 0) { for (int i = quoteDepth; i > 0; i--) { buff.append(HTML_BLOCKQUOTE_END); } } text = buff.toString(); text = text.replaceAll( "\\Q" + HTML_NEWLINE + "\\E((\\Q" + HTML_NEWLINE + "\\E)+?)\\Q" + HTML_BLOCKQUOTE_END + "\\E", HTML_BLOCKQUOTE_END + "$1" ); text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>"); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); sb.append(htmlifyMessageHeader()); UriLinkifier.linkifyText(text, sb); sb.append(htmlifyMessageFooter()); text = sb.toString(); text = text.replaceAll("<gt>", ">"); return text; } } | HtmlConverter { public static String textToHtml(String text) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { return simpleTextToHtml(text); } StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); boolean isStartOfLine = true; int spaces = 0; int quoteDepth = 0; int quotesThisLine = 0; for (int index = 0; index < text.length(); index++) { char c = text.charAt(index); if (isStartOfLine) { switch (c) { case ' ': spaces++; break; case '>': quotesThisLine++; spaces = 0; break; case '\n': appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = true; quotesThisLine = 0; break; default: isStartOfLine = false; appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = false; break; } } else { appendchar(buff, c); if (c == '\n') { isStartOfLine = true; quotesThisLine = 0; } } } if (quoteDepth > 0) { for (int i = quoteDepth; i > 0; i--) { buff.append(HTML_BLOCKQUOTE_END); } } text = buff.toString(); text = text.replaceAll( "\\Q" + HTML_NEWLINE + "\\E((\\Q" + HTML_NEWLINE + "\\E)+?)\\Q" + HTML_BLOCKQUOTE_END + "\\E", HTML_BLOCKQUOTE_END + "$1" ); text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>"); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); sb.append(htmlifyMessageHeader()); UriLinkifier.linkifyText(text, sb); sb.append(htmlifyMessageFooter()); text = sb.toString(); text = text.replaceAll("<gt>", ">"); return text; } static String htmlToText(final String html); static String textToHtml(String text); static String convertEmoji2Img(String html); static String wrapStatusMessage(CharSequence status); static String wrapMessageContent(CharSequence messageContent); static String textToHtmlFragment(final String text); static Spanned htmlToSpanned(String html); } | HtmlConverter { public static String textToHtml(String text) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { return simpleTextToHtml(text); } StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); boolean isStartOfLine = true; int spaces = 0; int quoteDepth = 0; int quotesThisLine = 0; for (int index = 0; index < text.length(); index++) { char c = text.charAt(index); if (isStartOfLine) { switch (c) { case ' ': spaces++; break; case '>': quotesThisLine++; spaces = 0; break; case '\n': appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = true; quotesThisLine = 0; break; default: isStartOfLine = false; appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = false; break; } } else { appendchar(buff, c); if (c == '\n') { isStartOfLine = true; quotesThisLine = 0; } } } if (quoteDepth > 0) { for (int i = quoteDepth; i > 0; i--) { buff.append(HTML_BLOCKQUOTE_END); } } text = buff.toString(); text = text.replaceAll( "\\Q" + HTML_NEWLINE + "\\E((\\Q" + HTML_NEWLINE + "\\E)+?)\\Q" + HTML_BLOCKQUOTE_END + "\\E", HTML_BLOCKQUOTE_END + "$1" ); text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>"); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); sb.append(htmlifyMessageHeader()); UriLinkifier.linkifyText(text, sb); sb.append(htmlifyMessageFooter()); text = sb.toString(); text = text.replaceAll("<gt>", ">"); return text; } static String htmlToText(final String html); static String textToHtml(String text); static String convertEmoji2Img(String html); static String wrapStatusMessage(CharSequence status); static String wrapMessageContent(CharSequence messageContent); static String textToHtmlFragment(final String text); static Spanned htmlToSpanned(String html); } |
@Test public void parse_withTooShortResponseText_shouldReturnNull() throws Exception { ImapResponse response = createImapResponse("* OK [PERMANENTFLAGS]"); PermanentFlagsResponse result = PermanentFlagsResponse.parse(response); assertNull(result); } | public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); static PermanentFlagsResponse parse(ImapResponse response); Set<Flag> getFlags(); boolean canCreateKeywords(); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); static PermanentFlagsResponse parse(ImapResponse response); Set<Flag> getFlags(); boolean canCreateKeywords(); } |
@Test public void parse_withoutPermanentFlagsResponse_shouldReturnNull() throws Exception { ImapResponse response = createImapResponse("* OK [UIDNEXT 1]"); PermanentFlagsResponse result = PermanentFlagsResponse.parse(response); assertNull(result); } | public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); static PermanentFlagsResponse parse(ImapResponse response); Set<Flag> getFlags(); boolean canCreateKeywords(); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); static PermanentFlagsResponse parse(ImapResponse response); Set<Flag> getFlags(); boolean canCreateKeywords(); } |
@Test public void parse_withoutPermanentFlagsList_shouldReturnNull() throws Exception { ImapResponse response = createImapResponse("* OK [PERMANENTFLAGS none]"); PermanentFlagsResponse result = PermanentFlagsResponse.parse(response); assertNull(result); } | public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); static PermanentFlagsResponse parse(ImapResponse response); Set<Flag> getFlags(); boolean canCreateKeywords(); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); static PermanentFlagsResponse parse(ImapResponse response); Set<Flag> getFlags(); boolean canCreateKeywords(); } |
@Test public void parse_withInvalidElementInPermanentFlagsList_shouldReturnNull() throws Exception { ImapResponse response = createImapResponse("* OK [PERMANENTFLAGS (\\Seen ())]"); PermanentFlagsResponse result = PermanentFlagsResponse.parse(response); assertNull(result); } | public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); static PermanentFlagsResponse parse(ImapResponse response); Set<Flag> getFlags(); boolean canCreateKeywords(); } | PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); static PermanentFlagsResponse parse(ImapResponse response); Set<Flag> getFlags(); boolean canCreateKeywords(); } |
@Test public void testSimpleOkResponse() throws IOException { ImapResponseParser parser = createParser("* OK\r\n"); ImapResponse response = parser.readResponse(); assertNotNull(response); assertEquals(1, response.size()); assertEquals("OK", response.get(0)); } | public ImapResponse readResponse() throws IOException { return readResponse(null); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void testOkResponseWithText() throws IOException { ImapResponseParser parser = createParser("* OK Some text here\r\n"); ImapResponse response = parser.readResponse(); assertNotNull(response); assertEquals(2, response.size()); assertEquals("OK", response.get(0)); assertEquals("Some text here", response.get(1)); } | public ImapResponse readResponse() throws IOException { return readResponse(null); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void testOkResponseWithRespTextCode() throws IOException { ImapResponseParser parser = createParser("* OK [UIDVALIDITY 3857529045]\r\n"); ImapResponse response = parser.readResponse(); assertNotNull(response); assertEquals(2, response.size()); assertEquals("OK", response.get(0)); assertTrue(response.get(1) instanceof ImapList); ImapList respTextCode = (ImapList) response.get(1); assertEquals(2, respTextCode.size()); assertEquals("UIDVALIDITY", respTextCode.get(0)); assertEquals("3857529045", respTextCode.get(1)); } | public ImapResponse readResponse() throws IOException { return readResponse(null); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void testOkResponseWithRespTextCodeAndText() throws IOException { ImapResponseParser parser = createParser("* OK [token1 token2] {x} test [...]\r\n"); ImapResponse response = parser.readResponse(); assertNotNull(response); assertEquals(3, response.size()); assertEquals("OK", response.get(0)); assertTrue(response.get(1) instanceof ImapList); assertEquals("{x} test [...]", response.get(2)); ImapList respTextCode = (ImapList) response.get(1); assertEquals(2, respTextCode.size()); assertEquals("token1", respTextCode.get(0)); assertEquals("token2", respTextCode.get(1)); } | public ImapResponse readResponse() throws IOException { return readResponse(null); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void testReadStatusResponseWithOKResponse() throws Exception { ImapResponseParser parser = createParser("* COMMAND BAR\tBAZ\r\n" + "TAG OK COMMAND completed\r\n"); List<ImapResponse> responses = parser.readStatusResponse("TAG", null, null, null); assertEquals(2, responses.size()); assertEquals(asList("COMMAND", "BAR", "BAZ"), responses.get(0)); assertEquals(asList("OK", "COMMAND completed"), responses.get(1)); } | List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } | ImapResponseParser { List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } } | ImapResponseParser { List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } ImapResponseParser(PeekableInputStream in); } | ImapResponseParser { List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapResponseParser { List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void testReadStatusResponseUntaggedHandlerGetsUntaggedOnly() throws Exception { ImapResponseParser parser = createParser( "* UNTAGGED\r\n" + "A2 OK COMMAND completed\r\n"); TestUntaggedHandler untaggedHandler = new TestUntaggedHandler(); parser.readStatusResponse("A2", null, null, untaggedHandler); assertEquals(1, untaggedHandler.responses.size()); assertEquals(asList("UNTAGGED"), untaggedHandler.responses.get(0)); } | List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } | ImapResponseParser { List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } } | ImapResponseParser { List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } ImapResponseParser(PeekableInputStream in); } | ImapResponseParser { List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapResponseParser { List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void testPreserveSpacesAtFirstForSpecialCharacters() { String message = " \r\n" + " &\r\n" + " \n" + " <\r\n" + " > \r\n"; String result = HtmlConverter.textToHtml(message); writeToFile(result); assertEquals("<pre class=\"k9mail\">" + " <br />" + " &<br />" + " <br />" + " <<br />" + "<blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;\">" + " <br />" + "</blockquote>" + "</pre>", result); } | public static String textToHtml(String text) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { return simpleTextToHtml(text); } StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); boolean isStartOfLine = true; int spaces = 0; int quoteDepth = 0; int quotesThisLine = 0; for (int index = 0; index < text.length(); index++) { char c = text.charAt(index); if (isStartOfLine) { switch (c) { case ' ': spaces++; break; case '>': quotesThisLine++; spaces = 0; break; case '\n': appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = true; quotesThisLine = 0; break; default: isStartOfLine = false; appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = false; break; } } else { appendchar(buff, c); if (c == '\n') { isStartOfLine = true; quotesThisLine = 0; } } } if (quoteDepth > 0) { for (int i = quoteDepth; i > 0; i--) { buff.append(HTML_BLOCKQUOTE_END); } } text = buff.toString(); text = text.replaceAll( "\\Q" + HTML_NEWLINE + "\\E((\\Q" + HTML_NEWLINE + "\\E)+?)\\Q" + HTML_BLOCKQUOTE_END + "\\E", HTML_BLOCKQUOTE_END + "$1" ); text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>"); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); sb.append(htmlifyMessageHeader()); UriLinkifier.linkifyText(text, sb); sb.append(htmlifyMessageFooter()); text = sb.toString(); text = text.replaceAll("<gt>", ">"); return text; } | HtmlConverter { public static String textToHtml(String text) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { return simpleTextToHtml(text); } StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); boolean isStartOfLine = true; int spaces = 0; int quoteDepth = 0; int quotesThisLine = 0; for (int index = 0; index < text.length(); index++) { char c = text.charAt(index); if (isStartOfLine) { switch (c) { case ' ': spaces++; break; case '>': quotesThisLine++; spaces = 0; break; case '\n': appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = true; quotesThisLine = 0; break; default: isStartOfLine = false; appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = false; break; } } else { appendchar(buff, c); if (c == '\n') { isStartOfLine = true; quotesThisLine = 0; } } } if (quoteDepth > 0) { for (int i = quoteDepth; i > 0; i--) { buff.append(HTML_BLOCKQUOTE_END); } } text = buff.toString(); text = text.replaceAll( "\\Q" + HTML_NEWLINE + "\\E((\\Q" + HTML_NEWLINE + "\\E)+?)\\Q" + HTML_BLOCKQUOTE_END + "\\E", HTML_BLOCKQUOTE_END + "$1" ); text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>"); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); sb.append(htmlifyMessageHeader()); UriLinkifier.linkifyText(text, sb); sb.append(htmlifyMessageFooter()); text = sb.toString(); text = text.replaceAll("<gt>", ">"); return text; } } | HtmlConverter { public static String textToHtml(String text) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { return simpleTextToHtml(text); } StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); boolean isStartOfLine = true; int spaces = 0; int quoteDepth = 0; int quotesThisLine = 0; for (int index = 0; index < text.length(); index++) { char c = text.charAt(index); if (isStartOfLine) { switch (c) { case ' ': spaces++; break; case '>': quotesThisLine++; spaces = 0; break; case '\n': appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = true; quotesThisLine = 0; break; default: isStartOfLine = false; appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = false; break; } } else { appendchar(buff, c); if (c == '\n') { isStartOfLine = true; quotesThisLine = 0; } } } if (quoteDepth > 0) { for (int i = quoteDepth; i > 0; i--) { buff.append(HTML_BLOCKQUOTE_END); } } text = buff.toString(); text = text.replaceAll( "\\Q" + HTML_NEWLINE + "\\E((\\Q" + HTML_NEWLINE + "\\E)+?)\\Q" + HTML_BLOCKQUOTE_END + "\\E", HTML_BLOCKQUOTE_END + "$1" ); text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>"); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); sb.append(htmlifyMessageHeader()); UriLinkifier.linkifyText(text, sb); sb.append(htmlifyMessageFooter()); text = sb.toString(); text = text.replaceAll("<gt>", ">"); return text; } } | HtmlConverter { public static String textToHtml(String text) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { return simpleTextToHtml(text); } StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); boolean isStartOfLine = true; int spaces = 0; int quoteDepth = 0; int quotesThisLine = 0; for (int index = 0; index < text.length(); index++) { char c = text.charAt(index); if (isStartOfLine) { switch (c) { case ' ': spaces++; break; case '>': quotesThisLine++; spaces = 0; break; case '\n': appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = true; quotesThisLine = 0; break; default: isStartOfLine = false; appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = false; break; } } else { appendchar(buff, c); if (c == '\n') { isStartOfLine = true; quotesThisLine = 0; } } } if (quoteDepth > 0) { for (int i = quoteDepth; i > 0; i--) { buff.append(HTML_BLOCKQUOTE_END); } } text = buff.toString(); text = text.replaceAll( "\\Q" + HTML_NEWLINE + "\\E((\\Q" + HTML_NEWLINE + "\\E)+?)\\Q" + HTML_BLOCKQUOTE_END + "\\E", HTML_BLOCKQUOTE_END + "$1" ); text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>"); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); sb.append(htmlifyMessageHeader()); UriLinkifier.linkifyText(text, sb); sb.append(htmlifyMessageFooter()); text = sb.toString(); text = text.replaceAll("<gt>", ">"); return text; } static String htmlToText(final String html); static String textToHtml(String text); static String convertEmoji2Img(String html); static String wrapStatusMessage(CharSequence status); static String wrapMessageContent(CharSequence messageContent); static String textToHtmlFragment(final String text); static Spanned htmlToSpanned(String html); } | HtmlConverter { public static String textToHtml(String text) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { return simpleTextToHtml(text); } StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); boolean isStartOfLine = true; int spaces = 0; int quoteDepth = 0; int quotesThisLine = 0; for (int index = 0; index < text.length(); index++) { char c = text.charAt(index); if (isStartOfLine) { switch (c) { case ' ': spaces++; break; case '>': quotesThisLine++; spaces = 0; break; case '\n': appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = true; quotesThisLine = 0; break; default: isStartOfLine = false; appendbq(buff, quotesThisLine, quoteDepth); quoteDepth = quotesThisLine; appendsp(buff, spaces); spaces = 0; appendchar(buff, c); isStartOfLine = false; break; } } else { appendchar(buff, c); if (c == '\n') { isStartOfLine = true; quotesThisLine = 0; } } } if (quoteDepth > 0) { for (int i = quoteDepth; i > 0; i--) { buff.append(HTML_BLOCKQUOTE_END); } } text = buff.toString(); text = text.replaceAll( "\\Q" + HTML_NEWLINE + "\\E((\\Q" + HTML_NEWLINE + "\\E)+?)\\Q" + HTML_BLOCKQUOTE_END + "\\E", HTML_BLOCKQUOTE_END + "$1" ); text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>"); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); sb.append(htmlifyMessageHeader()); UriLinkifier.linkifyText(text, sb); sb.append(htmlifyMessageFooter()); text = sb.toString(); text = text.replaceAll("<gt>", ">"); return text; } static String htmlToText(final String html); static String textToHtml(String text); static String convertEmoji2Img(String html); static String wrapStatusMessage(CharSequence status); static String wrapMessageContent(CharSequence messageContent); static String textToHtmlFragment(final String text); static Spanned htmlToSpanned(String html); } |
@Test public void testReadStatusResponseSkippingWrongTag() throws Exception { ImapResponseParser parser = createParser("* UNTAGGED\r\n" + "* 0 EXPUNGE\r\n" + "* 42 EXISTS\r\n" + "A1 COMMAND BAR BAZ\r\n" + "A2 OK COMMAND completed\r\n"); TestUntaggedHandler untaggedHandler = new TestUntaggedHandler(); List<ImapResponse> responses = parser.readStatusResponse("A2", null, null, untaggedHandler); assertEquals(3, responses.size()); assertEquals(asList("0", "EXPUNGE"), responses.get(0)); assertEquals(asList("42", "EXISTS"), responses.get(1)); assertEquals(asList("OK", "COMMAND completed"), responses.get(2)); assertEquals(asList("UNTAGGED"), untaggedHandler.responses.get(0)); assertEquals(responses.get(0), untaggedHandler.responses.get(1)); assertEquals(responses.get(1), untaggedHandler.responses.get(2)); } | List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } | ImapResponseParser { List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } } | ImapResponseParser { List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } ImapResponseParser(PeekableInputStream in); } | ImapResponseParser { List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapResponseParser { List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void testReadStatusResponseUntaggedHandlerStillCalledOnNegativeReply() throws Exception { ImapResponseParser parser = createParser( "+ text\r\n" + "A2 NO Bad response\r\n"); TestUntaggedHandler untaggedHandler = new TestUntaggedHandler(); try { List<ImapResponse> responses = parser.readStatusResponse("A2", null, null, untaggedHandler); } catch (NegativeImapResponseException e) { } assertEquals(1, untaggedHandler.responses.size()); assertEquals(asList("text"), untaggedHandler.responses.get(0)); } | List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } | ImapResponseParser { List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } } | ImapResponseParser { List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } ImapResponseParser(PeekableInputStream in); } | ImapResponseParser { List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapResponseParser { List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test(expected = NegativeImapResponseException.class) public void testReadStatusResponseWithErrorResponse() throws Exception { ImapResponseParser parser = createParser("* COMMAND BAR BAZ\r\nTAG ERROR COMMAND errored\r\n"); parser.readStatusResponse("TAG", null, null, null); } | List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } | ImapResponseParser { List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } } | ImapResponseParser { List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } ImapResponseParser(PeekableInputStream in); } | ImapResponseParser { List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapResponseParser { List<ImapResponse> readStatusResponse(String tag, String commandToLog, String logId, UntaggedHandler untaggedHandler) throws IOException, NegativeImapResponseException { List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { response = readResponse(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s<<<%s", logId, response); } if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); Iterator<ImapResponse> responseIterator = responses.iterator(); while (responseIterator.hasNext()) { ImapResponse delResponse = responseIterator.next(); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); } } response = null; continue; } if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } responses.add(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses); } return responses; } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void testRespTextCodeWithList() throws Exception { ImapResponseParser parser = createParser("* OK [PERMANENTFLAGS (\\Answered \\Flagged \\Deleted \\Seen " + "\\Draft NonJunk $MDNSent \\*)] Flags permitted.\r\n"); ImapResponse response = parser.readResponse(); assertEquals(3, response.size()); assertTrue(response.get(1) instanceof ImapList); assertEquals(2, response.getList(1).size()); assertEquals("PERMANENTFLAGS", response.getList(1).getString(0)); assertTrue(response.getList(1).get(1) instanceof ImapList); assertEquals("\\Answered", response.getList(1).getList(1).getString(0)); assertEquals("\\Flagged", response.getList(1).getList(1).getString(1)); assertEquals("\\Deleted", response.getList(1).getList(1).getString(2)); assertEquals("\\Seen", response.getList(1).getList(1).getString(3)); assertEquals("\\Draft", response.getList(1).getList(1).getString(4)); assertEquals("NonJunk", response.getList(1).getList(1).getString(5)); assertEquals("$MDNSent", response.getList(1).getList(1).getString(6)); assertEquals("\\*", response.getList(1).getList(1).getString(7)); } | public ImapResponse readResponse() throws IOException { return readResponse(null); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test public void testExistsResponse() throws Exception { ImapResponseParser parser = createParser("* 23 EXISTS\r\n"); ImapResponse response = parser.readResponse(); assertEquals(2, response.size()); assertEquals(23, response.getNumber(0)); assertEquals("EXISTS", response.getString(1)); } | public ImapResponse readResponse() throws IOException { return readResponse(null); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
@Test(expected = IOException.class) public void testReadStringUntilEndOfStream() throws IOException { ImapResponseParser parser = createParser("* OK Some text "); parser.readResponse(); } | public ImapResponse readResponse() throws IOException { return readResponse(null); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } | ImapResponseParser { public ImapResponse readResponse() throws IOException { return readResponse(null); } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.