@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);  }