From 08b361ed3693ccb472f754bbab29fa0cc1b34fc6 Mon Sep 17 00:00:00 2001 From: cketti Date: Wed, 31 Oct 2012 01:45:44 +0100 Subject: [PATCH] Fix search for Unified Inbox We don't want to list the Inbox contents of all accounts but the contents of folders whose "Unify" setting is true. --- src/com/fsck/k9/activity/Accounts.java | 16 ++++------------ src/com/fsck/k9/mail/store/LocalStore.java | 6 +++--- src/com/fsck/k9/provider/EmailProvider.java | 6 ++++++ src/com/fsck/k9/search/SearchAccount.java | 4 +++- src/com/fsck/k9/search/SearchSpecification.java | 4 ++-- src/com/fsck/k9/search/SqlQueryBuilder.java | 16 +++++++--------- 6 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/com/fsck/k9/activity/Accounts.java b/src/com/fsck/k9/activity/Accounts.java index f9d02d5a7..ea11d1738 100644 --- a/src/com/fsck/k9/activity/Accounts.java +++ b/src/com/fsck/k9/activity/Accounts.java @@ -81,6 +81,8 @@ import com.fsck.k9.search.LocalSearch; import com.fsck.k9.search.SearchAccount; import com.fsck.k9.search.SearchModifier; import com.fsck.k9.search.SearchSpecification; +import com.fsck.k9.search.SearchSpecification.Attribute; +import com.fsck.k9.search.SearchSpecification.Searchfield; import com.fsck.k9.view.ColorChip; import com.fsck.k9.preferences.SettingsExporter; import com.fsck.k9.preferences.SettingsImportExportException; @@ -425,18 +427,8 @@ public class Accounts extends K9ListActivity implements OnItemClickListener { * Creates and initializes the special accounts ('Unified Inbox' and 'All Messages') */ private void createSpecialAccounts() { - // create the unified inbox meta account ( all accounts is default when none specified ) - String name = getString(R.string.integrated_inbox_title); - LocalSearch tmpSearch = new LocalSearch(name); - tmpSearch.addAllowedFolder(SearchSpecification.GENERIC_INBOX_NAME); - integratedInboxAccount = new SearchAccount(tmpSearch, name, - getString(R.string.integrated_inbox_detail)); - - // create the all messages search ( all accounts is default when none specified ) - name = getString(R.string.search_all_messages_title); - tmpSearch = new LocalSearch(name); - unreadAccount = new SearchAccount(tmpSearch, name, - getString(R.string.search_all_messages_detail)); + integratedInboxAccount = SearchAccount.createUnifiedInboxAccount(this); + unreadAccount = SearchAccount.createAllMessagesAccount(this); } @SuppressWarnings("unchecked") diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index 0a25a2b52..487ed7917 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -93,10 +93,9 @@ public class LocalStore extends Store implements Serializable { * in the correct order. */ static private String GET_MESSAGES_COLS = - "subject, sender_list, date, uid, flags, id, to_list, cc_list, " + "subject, sender_list, date, uid, flags, messages.id, to_list, cc_list, " + "bcc_list, reply_to_list, attachment_count, internal_date, message_id, folder_id, preview, thread_root, thread_parent "; - static private String GET_FOLDER_COLS = "id, name, unread_count, visible_limit, last_updated, status, push_state, last_pushed, flagged_count, integrate, top_group, poll_class, push_class, display_class"; @@ -967,7 +966,8 @@ public class LocalStore extends Store implements Serializable { String where = query.toString(); String[] selectionArgs = queryArgs.toArray(EMPTY_STRING_ARRAY); - String sqlQuery = "SELECT " + GET_MESSAGES_COLS + "FROM messages WHERE " + + String sqlQuery = "SELECT " + GET_MESSAGES_COLS + "FROM messages " + + "LEFT JOIN folders ON (folders.id = messages.id) WHERE " + "((empty IS NULL OR empty != 1) AND deleted = 0)" + ((!StringUtils.isNullOrEmpty(where)) ? " AND (" + where + ")" : "") + " ORDER BY date DESC"; diff --git a/src/com/fsck/k9/provider/EmailProvider.java b/src/com/fsck/k9/provider/EmailProvider.java index 07b2ee1fa..38ebb9cdc 100644 --- a/src/com/fsck/k9/provider/EmailProvider.java +++ b/src/com/fsck/k9/provider/EmailProvider.java @@ -95,6 +95,7 @@ public class EmailProvider extends ContentProvider { public static final String ACCOUNT_UUID = "account_uuid"; public static final String FOLDER_NAME = "name"; + public static final String INTEGRATE = "integrate"; } public interface MessageColumns { @@ -231,6 +232,7 @@ public class EmailProvider extends ContentProvider { } final Cursor cursor; + //TODO: check projection and selection for folder columns if (Utility.arrayContains(projection, SpecialColumns.FOLDER_NAME)) { StringBuilder query = new StringBuilder(); query.append("SELECT "); @@ -302,6 +304,9 @@ public class EmailProvider extends ContentProvider { } else if (SpecialColumns.FOLDER_NAME.equals(columnName)) { query.append("f." + SpecialColumns.FOLDER_NAME + " AS " + SpecialColumns.FOLDER_NAME); + } else if (SpecialColumns.INTEGRATE.equals(columnName)) { + query.append("f." + SpecialColumns.INTEGRATE + " AS " + + SpecialColumns.INTEGRATE); } else { query.append("m."); query.append(columnName); @@ -314,6 +319,7 @@ public class EmailProvider extends ContentProvider { " FROM messages h JOIN messages m " + "ON (h.id = m.thread_root OR h.id = m.id) "); + //TODO: check projection and selection for folder columns if (Utility.arrayContains(projection, SpecialColumns.FOLDER_NAME)) { query.append("LEFT JOIN folders f ON (m.folder_id = f.id) "); } diff --git a/src/com/fsck/k9/search/SearchAccount.java b/src/com/fsck/k9/search/SearchAccount.java index 201b7eb0a..1eb20a7b5 100644 --- a/src/com/fsck/k9/search/SearchAccount.java +++ b/src/com/fsck/k9/search/SearchAccount.java @@ -6,6 +6,8 @@ import android.content.Context; import com.fsck.k9.BaseAccount; import com.fsck.k9.R; +import com.fsck.k9.search.SearchSpecification.Attribute; +import com.fsck.k9.search.SearchSpecification.Searchfield; /** * This class is basically a wrapper around a LocalSearch. It allows to expose it as @@ -26,7 +28,7 @@ public class SearchAccount implements BaseAccount { public static SearchAccount createUnifiedInboxAccount(Context context) { String name = context.getString(R.string.integrated_inbox_title); LocalSearch tmpSearch = new LocalSearch(name); - tmpSearch.addAllowedFolder(SearchSpecification.GENERIC_INBOX_NAME); + tmpSearch.and(Searchfield.INTEGRATE, "1", Attribute.EQUALS); return new SearchAccount(tmpSearch, name, context.getString(R.string.integrated_inbox_detail)); } diff --git a/src/com/fsck/k9/search/SearchSpecification.java b/src/com/fsck/k9/search/SearchSpecification.java index f40f1dfba..1e599aed9 100644 --- a/src/com/fsck/k9/search/SearchSpecification.java +++ b/src/com/fsck/k9/search/SearchSpecification.java @@ -29,7 +29,6 @@ public interface SearchSpecification extends Parcelable { * Some meta names for certain conditions. */ public static final String ALL_ACCOUNTS = "allAccounts"; - public static final String GENERIC_INBOX_NAME = "genericInboxName"; /////////////////////////////////////////////////////////////// // ATTRIBUTE enum @@ -78,7 +77,8 @@ public interface SearchSpecification extends Parcelable { ATTACHMENT_COUNT, DELETED, THREAD_ROOT, - ID + ID, + INTEGRATE } diff --git a/src/com/fsck/k9/search/SqlQueryBuilder.java b/src/com/fsck/k9/search/SqlQueryBuilder.java index 3749c3507..478ecc7da 100644 --- a/src/com/fsck/k9/search/SqlQueryBuilder.java +++ b/src/com/fsck/k9/search/SqlQueryBuilder.java @@ -27,14 +27,7 @@ public class SqlQueryBuilder { SearchCondition condition = node.mCondition; switch (condition.field) { case FOLDER: { - String folderName; - //TODO: Fix the search condition used by the Unified Inbox (we search all - // folders with an enabled "Unify" folder setting). - if (LocalSearch.GENERIC_INBOX_NAME.equals(condition.value)) { - folderName = account.getInboxFolderName(); - } else { - folderName = condition.value; - } + String folderName = condition.value; long folderId = getFolderId(account, folderName); query.append("folder_id = ?"); selectionArgs.add(Long.toString(folderId)); @@ -139,6 +132,10 @@ public class SqlQueryBuilder { columnName = "uid"; break; } + case INTEGRATE: { + columnName = "integrate"; + break; + } } if (columnName == null) { @@ -191,7 +188,7 @@ public class SqlQueryBuilder { } case EQUALS: { if (isNumberColumn(field)) { - query.append("== ?"); + query.append("= ?"); } else { query.append("LIKE ?"); } @@ -214,6 +211,7 @@ public class SqlQueryBuilder { case DELETED: case FOLDER: case ID: + case INTEGRATE: case THREAD_ROOT: { return true; }