use of com.fsck.k9.search.SearchSpecification.SearchCondition in project k-9 by k9mail.
the class SqlQueryBuilder method buildWhereClauseInternal.
private static void buildWhereClauseInternal(Account account, ConditionsTreeNode node, StringBuilder query, List<String> selectionArgs) {
if (node == null) {
query.append("1");
return;
}
if (node.mLeft == null && node.mRight == null) {
SearchCondition condition = node.mCondition;
switch(condition.field) {
case FOLDER:
{
String folderName = condition.value;
long folderId = getFolderId(account, folderName);
if (condition.attribute == Attribute.EQUALS) {
query.append("folder_id = ?");
} else {
query.append("folder_id != ?");
}
selectionArgs.add(Long.toString(folderId));
break;
}
case SEARCHABLE:
{
switch(account.getSearchableFolders()) {
case ALL:
{
// 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:
{
// Create temporary LocalSearch object so we can use...
LocalSearch tempSearch = new LocalSearch();
// ...the helper methods in Account to create the necessary conditions
// to limit the selection to displayable, non-special folders.
account.excludeSpecialFolders(tempSearch);
account.limitToDisplayableFolders(tempSearch);
buildWhereClauseInternal(account, tempSearch.getConditions(), query, selectionArgs);
break;
}
case NONE:
{
// Dummy condition, never select
query.append("0");
break;
}
}
break;
}
case MESSAGE_CONTENTS:
{
String fulltextQueryString = condition.value;
if (condition.attribute != Attribute.CONTAINS) {
Timber.e("message contents can only be matched!");
}
query.append("(EXISTS (SELECT docid FROM messages_fulltext WHERE docid = id AND fulltext MATCH ?))");
selectionArgs.add(fulltextQueryString);
break;
}
default:
{
appendCondition(condition, query, selectionArgs);
}
}
} else {
query.append("(");
buildWhereClauseInternal(account, node.mLeft, query, selectionArgs);
query.append(") ");
query.append(node.mValue.name());
query.append(" (");
buildWhereClauseInternal(account, node.mRight, query, selectionArgs);
query.append(")");
}
}
use of com.fsck.k9.search.SearchSpecification.SearchCondition in project k-9 by k9mail.
the class MessageList method decodeExtras.
private boolean decodeExtras(Intent intent) {
String action = intent.getAction();
if (Intent.ACTION_VIEW.equals(action) && intent.getData() != null) {
Uri uri = intent.getData();
List<String> segmentList = uri.getPathSegments();
String accountId = segmentList.get(0);
Collection<Account> accounts = Preferences.getPreferences(this).getAvailableAccounts();
for (Account account : accounts) {
if (String.valueOf(account.getAccountNumber()).equals(accountId)) {
String folderName = segmentList.get(1);
String messageUid = segmentList.get(2);
mMessageReference = new MessageReference(account.getUuid(), folderName, messageUid, null);
break;
}
}
} else if (ACTION_SHORTCUT.equals(action)) {
// Handle shortcut intents
String specialFolder = intent.getStringExtra(EXTRA_SPECIAL_FOLDER);
if (SearchAccount.UNIFIED_INBOX.equals(specialFolder)) {
mSearch = SearchAccount.createUnifiedInboxAccount(this).getRelatedSearch();
} else if (SearchAccount.ALL_MESSAGES.equals(specialFolder)) {
mSearch = SearchAccount.createAllMessagesAccount(this).getRelatedSearch();
}
} else if (intent.getStringExtra(SearchManager.QUERY) != null) {
// check if this intent comes from the system search ( remote )
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
//Query was received from Search Dialog
String query = intent.getStringExtra(SearchManager.QUERY).trim();
mSearch = new LocalSearch(getString(R.string.search_results));
mSearch.setManualSearch(true);
mNoThreading = true;
mSearch.or(new SearchCondition(SearchField.SENDER, Attribute.CONTAINS, query));
mSearch.or(new SearchCondition(SearchField.SUBJECT, Attribute.CONTAINS, query));
mSearch.or(new SearchCondition(SearchField.MESSAGE_CONTENTS, Attribute.CONTAINS, query));
Bundle appData = intent.getBundleExtra(SearchManager.APP_DATA);
if (appData != null) {
mSearch.addAccountUuid(appData.getString(EXTRA_SEARCH_ACCOUNT));
// searches started from a folder list activity will provide an account, but no folder
if (appData.getString(EXTRA_SEARCH_FOLDER) != null) {
mSearch.addAllowedFolder(appData.getString(EXTRA_SEARCH_FOLDER));
}
} else {
mSearch.addAccountUuid(LocalSearch.ALL_ACCOUNTS);
}
}
} else if (intent.hasExtra(EXTRA_SEARCH_OLD)) {
mSearch = intent.getParcelableExtra(EXTRA_SEARCH_OLD);
mNoThreading = intent.getBooleanExtra(EXTRA_NO_THREADING, false);
} else {
// regular LocalSearch object was passed
mSearch = intent.hasExtra(EXTRA_SEARCH) ? ParcelableUtil.unmarshall(intent.getByteArrayExtra(EXTRA_SEARCH), LocalSearch.CREATOR) : null;
mNoThreading = intent.getBooleanExtra(EXTRA_NO_THREADING, false);
}
if (mMessageReference == null) {
String messageReferenceString = intent.getStringExtra(EXTRA_MESSAGE_REFERENCE);
mMessageReference = MessageReference.parse(messageReferenceString);
}
if (mMessageReference != null) {
mSearch = new LocalSearch();
mSearch.addAccountUuid(mMessageReference.getAccountUuid());
mSearch.addAllowedFolder(mMessageReference.getFolderName());
}
if (mSearch == null) {
// We've most likely been started by an old unread widget
String accountUuid = intent.getStringExtra("account");
String folderName = intent.getStringExtra("folder");
mSearch = new LocalSearch(folderName);
mSearch.addAccountUuid((accountUuid == null) ? "invalid" : accountUuid);
if (folderName != null) {
mSearch.addAllowedFolder(folderName);
}
}
Preferences prefs = Preferences.getPreferences(getApplicationContext());
String[] accountUuids = mSearch.getAccountUuids();
if (mSearch.searchAllAccounts()) {
List<Account> accounts = prefs.getAccounts();
mSingleAccountMode = (accounts.size() == 1);
if (mSingleAccountMode) {
mAccount = accounts.get(0);
}
} else {
mSingleAccountMode = (accountUuids.length == 1);
if (mSingleAccountMode) {
mAccount = prefs.getAccount(accountUuids[0]);
}
}
mSingleFolderMode = mSingleAccountMode && (mSearch.getFolderNames().size() == 1);
if (mSingleAccountMode && (mAccount == null || !mAccount.isAvailable(this))) {
Timber.i("not opening MessageList of unavailable account");
onAccountUnavailable();
return false;
}
if (mSingleFolderMode) {
mFolderName = mSearch.getFolderNames().get(0);
}
// now we know if we are in single account mode and need a subtitle
mActionBarSubTitle.setVisibility((!mSingleFolderMode) ? View.GONE : View.VISIBLE);
return true;
}
use of com.fsck.k9.search.SearchSpecification.SearchCondition 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()));
}
use of com.fsck.k9.search.SearchSpecification.SearchCondition 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()));
}
use of com.fsck.k9.search.SearchSpecification.SearchCondition in project k-9 by k9mail.
the class ConditionsTreeNode method buildNodeFromRow.
/**
* Converts a single database row to a single condition node.
*
* @param cursor Cursor pointing to the row we want to convert.
* @return A single ConditionsTreeNode
*/
private static ConditionsTreeNode buildNodeFromRow(Cursor cursor) {
ConditionsTreeNode result = null;
SearchCondition condition = null;
Operator tmpValue = ConditionsTreeNode.Operator.valueOf(cursor.getString(5));
if (tmpValue == Operator.CONDITION) {
condition = new SearchCondition(SearchField.valueOf(cursor.getString(0)), Attribute.valueOf(cursor.getString(2)), cursor.getString(1));
}
result = new ConditionsTreeNode(condition);
result.mValue = tmpValue;
result.mLeftMPTTMarker = cursor.getInt(3);
result.mRightMPTTMarker = cursor.getInt(4);
return result;
}
Aggregations