From d14bdc0b79fd775efb57e74efcdb2d208ab7618c Mon Sep 17 00:00:00 2001 From: cketti Date: Tue, 23 Apr 2013 20:14:29 +0200 Subject: [PATCH] Exclude folders Trash, Spam, and Outbox from "All messages" --- src/com/fsck/k9/Account.java | 24 +++++++++++++++++++++ src/com/fsck/k9/search/SqlQueryBuilder.java | 10 +++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/com/fsck/k9/Account.java b/src/com/fsck/k9/Account.java index c12dad60a..ecb7059a3 100644 --- a/src/com/fsck/k9/Account.java +++ b/src/com/fsck/k9/Account.java @@ -1856,6 +1856,30 @@ public class Account implements BaseAccount { search.or(new SearchCondition(Searchfield.FOLDER, Attribute.EQUALS, getInboxFolderName())); } + /** + * Modify the supplied {@link LocalSearch} instance to exclude "unwanted" folders. + * + *

+ * Currently the following folders are excluded: + *

+ * The Inbox will always be included even if one of the special folders is configured to point + * to the Inbox. + *

+ * + * @param search + * The {@code LocalSearch} instance to modify. + */ + public void excludeUnwantedFolders(LocalSearch search) { + excludeSpecialFolder(search, getTrashFolderName()); + excludeSpecialFolder(search, getSpamFolderName()); + excludeSpecialFolder(search, getOutboxFolderName()); + search.or(new SearchCondition(Searchfield.FOLDER, Attribute.EQUALS, getInboxFolderName())); + } + private void excludeSpecialFolder(LocalSearch search, String folderName) { if (!K9.FOLDER_NONE.equals(folderName)) { search.and(Searchfield.FOLDER, folderName, Attribute.NOT_EQUALS); diff --git a/src/com/fsck/k9/search/SqlQueryBuilder.java b/src/com/fsck/k9/search/SqlQueryBuilder.java index 0ad6158b4..d0f2bfeb0 100644 --- a/src/com/fsck/k9/search/SqlQueryBuilder.java +++ b/src/com/fsck/k9/search/SqlQueryBuilder.java @@ -42,8 +42,14 @@ public class SqlQueryBuilder { case SEARCHABLE: { switch (account.getSearchableFolders()) { case ALL: { - // Dummy condition, always select - query.append("1"); + // Create temporary LocalSearch object so we can use... + LocalSearch tempSearch = new LocalSearch(); + // ...the helper methods in Account to create the necessary conditions + // to exclude "unwanted" folders. + account.excludeUnwantedFolders(tempSearch); + + buildWhereClauseInternal(account, tempSearch.getConditions(), query, + selectionArgs); break; } case DISPLAYABLE: {