Loading app/core/src/main/java/com/fsck/k9/search/AccountSearchConditions.kt +17 −28 Original line number Diff line number Diff line package com.fsck.k9.search import com.fsck.k9.Account import com.fsck.k9.Account.FolderMode import com.fsck.k9.BaseAccount import com.fsck.k9.mail.Folder import com.fsck.k9.mail.Folder.FolderClass import com.fsck.k9.search.SearchSpecification.* class AccountSearchConditions { /** * Modify the supplied [LocalSearch] instance to limit the search to displayable folders. * * * * This method uses the current folder display mode to decide what folders to include/exclude. * * * @param search * The `LocalSearch` instance to modify. * Loading @@ -22,19 +21,17 @@ class AccountSearchConditions { val displayMode = account.folderDisplayMode when (displayMode) { Account.FolderMode.FIRST_CLASS -> { FolderMode.FIRST_CLASS -> { // Count messages in the INBOX and non-special first class folders search.and(SearchSpecification.SearchField.DISPLAY_CLASS, Folder.FolderClass.FIRST_CLASS.name, SearchSpecification.Attribute.EQUALS) search.and(SearchField.DISPLAY_CLASS, FolderClass.FIRST_CLASS.name, Attribute.EQUALS) } Account.FolderMode.FIRST_AND_SECOND_CLASS -> { FolderMode.FIRST_AND_SECOND_CLASS -> { // Count messages in the INBOX and non-special first and second class folders search.and(SearchSpecification.SearchField.DISPLAY_CLASS, Folder.FolderClass.FIRST_CLASS.name, SearchSpecification.Attribute.EQUALS) search.and(SearchField.DISPLAY_CLASS, FolderClass.FIRST_CLASS.name, Attribute.EQUALS) // TODO: Create a proper interface for creating arbitrary condition trees val searchCondition = SearchSpecification.SearchCondition(SearchSpecification.SearchField.DISPLAY_CLASS, SearchSpecification.Attribute.EQUALS, Folder.FolderClass.SECOND_CLASS.name) val searchCondition = SearchCondition( SearchField.DISPLAY_CLASS, Attribute.EQUALS, FolderClass.SECOND_CLASS.name) val root = search.conditions if (root.mRight != null) { root.mRight.or(searchCondition) Loading @@ -42,14 +39,12 @@ class AccountSearchConditions { search.or(searchCondition) } } Account.FolderMode.NOT_SECOND_CLASS -> { FolderMode.NOT_SECOND_CLASS -> { // Count messages in the INBOX and non-special non-second-class folders search.and(SearchSpecification.SearchField.DISPLAY_CLASS, Folder.FolderClass.SECOND_CLASS.name, SearchSpecification.Attribute.NOT_EQUALS) search.and(SearchField.DISPLAY_CLASS, FolderClass.SECOND_CLASS.name, Attribute.NOT_EQUALS) } Account.FolderMode.ALL -> { }// Count messages in the INBOX and non-special folders else -> { FolderMode.ALL, FolderMode.NONE -> { // Count messages in the INBOX and non-special folders } } } Loading @@ -57,8 +52,6 @@ class AccountSearchConditions { /** * Modify the supplied [LocalSearch] instance to exclude special folders. * * * * Currently the following folders are excluded: * * * Trash Loading @@ -70,7 +63,6 @@ class AccountSearchConditions { * The Inbox will always be included even if one of the special folders is configured to point * to the Inbox. * * * @param search * The `LocalSearch` instance to modify. */ Loading @@ -80,14 +72,12 @@ class AccountSearchConditions { excludeSpecialFolder(search, account.spamFolder) excludeSpecialFolder(search, account.outboxFolder) excludeSpecialFolder(search, account.sentFolder) search.or(SearchSpecification.SearchCondition(SearchSpecification.SearchField.FOLDER, SearchSpecification.Attribute.EQUALS, account.getInboxFolder())) search.or(SearchCondition(SearchField.FOLDER, Attribute.EQUALS, account.getInboxFolder())) } /** * Modify the supplied [LocalSearch] instance to exclude "unwanted" folders. * * * * Currently the following folders are excluded: * * * Trash Loading @@ -97,7 +87,6 @@ class AccountSearchConditions { * The Inbox will always be included even if one of the special folders is configured to point * to the Inbox. * * * @param search * The `LocalSearch` instance to modify. */ Loading @@ -105,12 +94,12 @@ class AccountSearchConditions { excludeSpecialFolder(search, account.trashFolder) excludeSpecialFolder(search, account.spamFolder) excludeSpecialFolder(search, account.outboxFolder) search.or(SearchSpecification.SearchCondition(SearchSpecification.SearchField.FOLDER, SearchSpecification.Attribute.EQUALS, account.inboxFolder)) search.or(SearchCondition(SearchField.FOLDER, Attribute.EQUALS, account.inboxFolder)) } private fun excludeSpecialFolder(search: LocalSearch, folderServerId: String?) { if (folderServerId != null) { search.and(SearchSpecification.SearchField.FOLDER, folderServerId, SearchSpecification.Attribute.NOT_EQUALS) search.and(SearchField.FOLDER, folderServerId, Attribute.NOT_EQUALS) } } Loading @@ -128,7 +117,7 @@ class AccountSearchConditions { limitToDisplayableFolders(realAccount, search) } search.and(SearchSpecification.SearchField.READ, "1", SearchSpecification.Attribute.NOT_EQUALS) search.and(SearchField.READ, "1", Attribute.NOT_EQUALS) return search } Loading Loading
app/core/src/main/java/com/fsck/k9/search/AccountSearchConditions.kt +17 −28 Original line number Diff line number Diff line package com.fsck.k9.search import com.fsck.k9.Account import com.fsck.k9.Account.FolderMode import com.fsck.k9.BaseAccount import com.fsck.k9.mail.Folder import com.fsck.k9.mail.Folder.FolderClass import com.fsck.k9.search.SearchSpecification.* class AccountSearchConditions { /** * Modify the supplied [LocalSearch] instance to limit the search to displayable folders. * * * * This method uses the current folder display mode to decide what folders to include/exclude. * * * @param search * The `LocalSearch` instance to modify. * Loading @@ -22,19 +21,17 @@ class AccountSearchConditions { val displayMode = account.folderDisplayMode when (displayMode) { Account.FolderMode.FIRST_CLASS -> { FolderMode.FIRST_CLASS -> { // Count messages in the INBOX and non-special first class folders search.and(SearchSpecification.SearchField.DISPLAY_CLASS, Folder.FolderClass.FIRST_CLASS.name, SearchSpecification.Attribute.EQUALS) search.and(SearchField.DISPLAY_CLASS, FolderClass.FIRST_CLASS.name, Attribute.EQUALS) } Account.FolderMode.FIRST_AND_SECOND_CLASS -> { FolderMode.FIRST_AND_SECOND_CLASS -> { // Count messages in the INBOX and non-special first and second class folders search.and(SearchSpecification.SearchField.DISPLAY_CLASS, Folder.FolderClass.FIRST_CLASS.name, SearchSpecification.Attribute.EQUALS) search.and(SearchField.DISPLAY_CLASS, FolderClass.FIRST_CLASS.name, Attribute.EQUALS) // TODO: Create a proper interface for creating arbitrary condition trees val searchCondition = SearchSpecification.SearchCondition(SearchSpecification.SearchField.DISPLAY_CLASS, SearchSpecification.Attribute.EQUALS, Folder.FolderClass.SECOND_CLASS.name) val searchCondition = SearchCondition( SearchField.DISPLAY_CLASS, Attribute.EQUALS, FolderClass.SECOND_CLASS.name) val root = search.conditions if (root.mRight != null) { root.mRight.or(searchCondition) Loading @@ -42,14 +39,12 @@ class AccountSearchConditions { search.or(searchCondition) } } Account.FolderMode.NOT_SECOND_CLASS -> { FolderMode.NOT_SECOND_CLASS -> { // Count messages in the INBOX and non-special non-second-class folders search.and(SearchSpecification.SearchField.DISPLAY_CLASS, Folder.FolderClass.SECOND_CLASS.name, SearchSpecification.Attribute.NOT_EQUALS) search.and(SearchField.DISPLAY_CLASS, FolderClass.SECOND_CLASS.name, Attribute.NOT_EQUALS) } Account.FolderMode.ALL -> { }// Count messages in the INBOX and non-special folders else -> { FolderMode.ALL, FolderMode.NONE -> { // Count messages in the INBOX and non-special folders } } } Loading @@ -57,8 +52,6 @@ class AccountSearchConditions { /** * Modify the supplied [LocalSearch] instance to exclude special folders. * * * * Currently the following folders are excluded: * * * Trash Loading @@ -70,7 +63,6 @@ class AccountSearchConditions { * The Inbox will always be included even if one of the special folders is configured to point * to the Inbox. * * * @param search * The `LocalSearch` instance to modify. */ Loading @@ -80,14 +72,12 @@ class AccountSearchConditions { excludeSpecialFolder(search, account.spamFolder) excludeSpecialFolder(search, account.outboxFolder) excludeSpecialFolder(search, account.sentFolder) search.or(SearchSpecification.SearchCondition(SearchSpecification.SearchField.FOLDER, SearchSpecification.Attribute.EQUALS, account.getInboxFolder())) search.or(SearchCondition(SearchField.FOLDER, Attribute.EQUALS, account.getInboxFolder())) } /** * Modify the supplied [LocalSearch] instance to exclude "unwanted" folders. * * * * Currently the following folders are excluded: * * * Trash Loading @@ -97,7 +87,6 @@ class AccountSearchConditions { * The Inbox will always be included even if one of the special folders is configured to point * to the Inbox. * * * @param search * The `LocalSearch` instance to modify. */ Loading @@ -105,12 +94,12 @@ class AccountSearchConditions { excludeSpecialFolder(search, account.trashFolder) excludeSpecialFolder(search, account.spamFolder) excludeSpecialFolder(search, account.outboxFolder) search.or(SearchSpecification.SearchCondition(SearchSpecification.SearchField.FOLDER, SearchSpecification.Attribute.EQUALS, account.inboxFolder)) search.or(SearchCondition(SearchField.FOLDER, Attribute.EQUALS, account.inboxFolder)) } private fun excludeSpecialFolder(search: LocalSearch, folderServerId: String?) { if (folderServerId != null) { search.and(SearchSpecification.SearchField.FOLDER, folderServerId, SearchSpecification.Attribute.NOT_EQUALS) search.and(SearchField.FOLDER, folderServerId, Attribute.NOT_EQUALS) } } Loading @@ -128,7 +117,7 @@ class AccountSearchConditions { limitToDisplayableFolders(realAccount, search) } search.and(SearchSpecification.SearchField.READ, "1", SearchSpecification.Attribute.NOT_EQUALS) search.and(SearchField.READ, "1", Attribute.NOT_EQUALS) return search } Loading