Search in sources :

Example 6 with LocalSearch

use of com.fsck.k9.search.LocalSearch in project k-9 by k9mail.

the class MessageList method showMoreFromSameSender.

@Override
public void showMoreFromSameSender(String senderAddress) {
    LocalSearch tmpSearch = new LocalSearch("From " + senderAddress);
    tmpSearch.addAccountUuids(mSearch.getAccountUuids());
    tmpSearch.and(SearchField.SENDER, senderAddress, Attribute.CONTAINS);
    MessageListFragment fragment = MessageListFragment.newInstance(tmpSearch, false, false);
    addMessageListFragment(fragment, true);
}
Also used : LocalSearch(com.fsck.k9.search.LocalSearch) MessageListFragment(com.fsck.k9.fragment.MessageListFragment)

Example 7 with LocalSearch

use of com.fsck.k9.search.LocalSearch in project k-9 by k9mail.

the class Account method excludeSpecialFolders.

/**
     * Modify the supplied {@link LocalSearch} instance to exclude special folders.
     *
     * <p>
     * Currently the following folders are excluded:
     * <ul>
     *   <li>Trash</li>
     *   <li>Drafts</li>
     *   <li>Spam</li>
     *   <li>Outbox</li>
     *   <li>Sent</li>
     * </ul>
     * The Inbox will always be included even if one of the special folders is configured to point
     * to the Inbox.
     * </p>
     *
     * @param search
     *         The {@code LocalSearch} instance to modify.
     */
public void excludeSpecialFolders(LocalSearch search) {
    excludeSpecialFolder(search, getTrashFolderName());
    excludeSpecialFolder(search, getDraftsFolderName());
    excludeSpecialFolder(search, getSpamFolderName());
    excludeSpecialFolder(search, getOutboxFolderName());
    excludeSpecialFolder(search, getSentFolderName());
    excludeSpecialFolder(search, getErrorFolderName());
    search.or(new SearchCondition(SearchField.FOLDER, Attribute.EQUALS, getInboxFolderName()));
}
Also used : SearchCondition(com.fsck.k9.search.SearchSpecification.SearchCondition)

Example 8 with LocalSearch

use of com.fsck.k9.search.LocalSearch in project k-9 by k9mail.

the class Account method getStats.

/**
     * @return <code>null</code> if not available
     * @throws MessagingException
     * @see {@link #isAvailable(Context)}
     */
public AccountStats getStats(Context context) throws MessagingException {
    if (!isAvailable(context)) {
        return null;
    }
    AccountStats stats = new AccountStats();
    ContentResolver cr = context.getContentResolver();
    Uri uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI, "account/" + getUuid() + "/stats");
    String[] projection = { StatsColumns.UNREAD_COUNT, StatsColumns.FLAGGED_COUNT };
    // Create LocalSearch instance to exclude special folders (Trash, Drafts, Spam, Outbox,
    // Sent) and limit the search to displayable folders.
    LocalSearch search = new LocalSearch();
    excludeSpecialFolders(search);
    limitToDisplayableFolders(search);
    // Use the LocalSearch instance to create a WHERE clause to query the content provider
    StringBuilder query = new StringBuilder();
    List<String> queryArgs = new ArrayList<>();
    ConditionsTreeNode conditions = search.getConditions();
    SqlQueryBuilder.buildWhereClause(this, conditions, query, queryArgs);
    String selection = query.toString();
    String[] selectionArgs = queryArgs.toArray(new String[0]);
    Cursor cursor = cr.query(uri, projection, selection, selectionArgs, null);
    try {
        if (cursor != null && cursor.moveToFirst()) {
            stats.unreadMessageCount = cursor.getInt(0);
            stats.flaggedMessageCount = cursor.getInt(1);
        }
    } finally {
        Utility.closeQuietly(cursor);
    }
    LocalStore localStore = getLocalStore();
    if (K9.measureAccounts()) {
        stats.size = localStore.getSize();
    }
    return stats;
}
Also used : ConditionsTreeNode(com.fsck.k9.search.ConditionsTreeNode) LocalSearch(com.fsck.k9.search.LocalSearch) ArrayList(java.util.ArrayList) LocalStore(com.fsck.k9.mailstore.LocalStore) Cursor(android.database.Cursor) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 9 with LocalSearch

use of com.fsck.k9.search.LocalSearch in project k-9 by k9mail.

the class Account method excludeUnwantedFolders.

/**
     * Modify the supplied {@link LocalSearch} instance to exclude "unwanted" folders.
     *
     * <p>
     * Currently the following folders are excluded:
     * <ul>
     *   <li>Trash</li>
     *   <li>Spam</li>
     *   <li>Outbox</li>
     * </ul>
     * The Inbox will always be included even if one of the special folders is configured to point
     * to the Inbox.
     * </p>
     *
     * @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()));
}
Also used : SearchCondition(com.fsck.k9.search.SearchSpecification.SearchCondition)

Example 10 with LocalSearch

use of com.fsck.k9.search.LocalSearch in project k-9 by k9mail.

the class Accounts method createUnreadSearch.

public static LocalSearch createUnreadSearch(Context context, BaseAccount account) {
    String searchTitle = context.getString(R.string.search_title, account.getDescription(), context.getString(R.string.unread_modifier));
    LocalSearch search;
    if (account instanceof SearchAccount) {
        search = ((SearchAccount) account).getRelatedSearch().clone();
        search.setName(searchTitle);
    } else {
        search = new LocalSearch(searchTitle);
        search.addAccountUuid(account.getUuid());
        Account realAccount = (Account) account;
        realAccount.excludeSpecialFolders(search);
        realAccount.limitToDisplayableFolders(search);
    }
    search.and(SearchField.READ, "1", Attribute.NOT_EQUALS);
    return search;
}
Also used : SearchAccount(com.fsck.k9.search.SearchAccount) Account(com.fsck.k9.Account) BaseAccount(com.fsck.k9.BaseAccount) LocalSearch(com.fsck.k9.search.LocalSearch) SearchAccount(com.fsck.k9.search.SearchAccount)

Aggregations

LocalSearch (com.fsck.k9.search.LocalSearch)13 Account (com.fsck.k9.Account)6 SearchAccount (com.fsck.k9.search.SearchAccount)6 SearchCondition (com.fsck.k9.search.SearchSpecification.SearchCondition)4 PendingIntent (android.app.PendingIntent)3 Intent (android.content.Intent)3 Uri (android.net.Uri)3 AccountStats (com.fsck.k9.AccountStats)3 BaseAccount (com.fsck.k9.BaseAccount)3 ArrayList (java.util.ArrayList)3 ContentResolver (android.content.ContentResolver)2 Cursor (android.database.Cursor)2 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)2 Preferences (com.fsck.k9.Preferences)2 MessageListFragment (com.fsck.k9.fragment.MessageListFragment)2 LocalStore (com.fsck.k9.mailstore.LocalStore)2 ConditionsTreeNode (com.fsck.k9.search.ConditionsTreeNode)2 SuppressLint (android.annotation.SuppressLint)1 Bundle (android.os.Bundle)1 VisibleForTesting (android.support.annotation.VisibleForTesting)1