public boolean isCondstoreCapable() throws IOException, MessagingException { return hasCapability(Capabilities.CONDSTORE); }
private void enableCompressionIfRequested() throws IOException, MessagingException { if (hasCapability(Capabilities.COMPRESS_DEFLATE) && shouldEnableCompression()) { enableCompression(); } }
private void upgradeToTls() throws IOException, MessagingException, GeneralSecurityException { if (!hasCapability(Capabilities.STARTTLS)) { /* * This exception triggers a "Certificate error" * notification that takes the user to the incoming * server settings for review. This might be needed if * the account was configured with an obsolete * "STARTTLS (if available)" setting. */ throw new CertificateValidationException("STARTTLS connection security not available"); } startTLS(); }
if (oauthTokenProvider == null) { throw new MessagingException("No OAuthToken Provider available."); } else if (hasCapability(Capabilities.AUTH_XOAUTH2) && hasCapability(Capabilities.SASL_IR)) { return authXoauth2withSASLIR(); } else { if (hasCapability(Capabilities.AUTH_CRAM_MD5)) { return authCramMD5(); } else { if (hasCapability(Capabilities.AUTH_PLAIN)) { return saslAuthPlainWithLoginFallback(); } else if (!hasCapability(Capabilities.LOGINDISABLED)) { return login(); } else { if (hasCapability(Capabilities.AUTH_EXTERNAL)) { return saslAuthExternal(); } else {
@Test public void getPersonalNamespaces_withoutSpecialUseCapability_shouldUseSimpleListCommand() throws Exception { ImapConnection imapConnection = mock(ImapConnection.class); when(imapConnection.hasCapability(Capabilities.LIST_EXTENDED)).thenReturn(true); when(imapConnection.hasCapability(Capabilities.SPECIAL_USE)).thenReturn(false); imapStore.enqueueImapConnection(imapConnection); imapStore.getPersonalNamespaces(); verify(imapConnection, never()).executeSimpleCommand("LIST \"\" \"*\" RETURN (SPECIAL-USE)"); verify(imapConnection).executeSimpleCommand("LIST \"\" \"*\""); }
@Test public void getPersonalNamespaces_withoutListExtendedCapability_shouldUseSimpleListCommand() throws Exception { ImapConnection imapConnection = mock(ImapConnection.class); when(imapConnection.hasCapability(Capabilities.LIST_EXTENDED)).thenReturn(false); when(imapConnection.hasCapability(Capabilities.SPECIAL_USE)).thenReturn(true); imapStore.enqueueImapConnection(imapConnection); imapStore.getPersonalNamespaces(); verify(imapConnection, never()).executeSimpleCommand("LIST \"\" \"*\" RETURN (SPECIAL-USE)"); verify(imapConnection).executeSimpleCommand("LIST \"\" \"*\""); }
private void retrievePathPrefixIfNecessary() throws IOException, MessagingException { if (settings.getPathPrefix() != null) { return; } if (hasCapability(Capabilities.NAMESPACE)) { if (K9MailLib.isDebug()) { Timber.i("pathPrefix is unset and server has NAMESPACE capability"); } handleNamespace(); } else { if (K9MailLib.isDebug()) { Timber.i("pathPrefix is unset but server does not have NAMESPACE capability"); } settings.setPathPrefix(""); } }
if (subscribedOnly) { commandFormat = "LSUB \"\" %s"; } else if (connection.hasCapability(Capabilities.SPECIAL_USE) && connection.hasCapability(Capabilities.LIST_EXTENDED)) { commandFormat = "LIST \"\" %s RETURN (SPECIAL-USE)"; } else {
@Test public void getPersonalNamespaces_withSpecialUseCapability_shouldReturnSpecialFolderInfo() throws Exception { ImapConnection imapConnection = mock(ImapConnection.class); when(imapConnection.hasCapability(Capabilities.LIST_EXTENDED)).thenReturn(true); 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 \"\" \"*\" RETURN (SPECIAL-USE)")).thenReturn(imapResponses); imapStore.enqueueImapConnection(imapConnection); List<ImapFolder> folders = imapStore.getPersonalNamespaces(); Map<String, ImapFolder> folderMap = toFolderMap(folders); assertEquals(FolderType.INBOX, folderMap.get("INBOX").getType()); assertEquals(FolderType.DRAFTS, folderMap.get("[Gmail]/Drafts").getType()); assertEquals(FolderType.SENT, folderMap.get("[Gmail]/Sent Mail").getType()); assertEquals(FolderType.SPAM, folderMap.get("[Gmail]/Spam").getType()); assertEquals(FolderType.TRASH, folderMap.get("[Gmail]/Trash").getType()); assertEquals(FolderType.ARCHIVE, folderMap.get("[Gmail]/All Mail").getType()); }
@Test public void hasCapability_withNotYetOpenedConnection_shouldConnectAndFetchCapabilities() throws Exception { MockImapServer server = new MockImapServer(); simpleOpenDialog(server, "X-SOMETHING"); ImapConnection imapConnection = startServerAndCreateImapConnection(server); boolean capabilityPresent = imapConnection.hasCapability("X-SOMETHING"); assertTrue(capabilityPresent); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); }
@Test public void open_authXoauthWithSaslIrParsesCapabilities() 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 [CAPABILITY IMAP4REV1 IDLE XM-GM-EXT-1]"); simplePostAuthenticationDialog(server, 3); ImapConnection imapConnection = startServerAndCreateImapConnection(server); imapConnection.open(); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); assertTrue(imapConnection.hasCapability("XM-GM-EXT-1")); }