Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit af030655 authored by Wolf-Martell Montwé's avatar Wolf-Martell Montwé
Browse files

Add `:legacy:search` module and move `SearchField`, `SearchAttribute` and `SearchCondition`

parent bd9d1735
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ dependencies {
    api(projects.legacy.di)
    api(projects.legacy.folder)
    api(projects.legacy.notification)
    api(projects.legacy.search)

    implementation(projects.plugins.openpgpApiLib.openpgpApi)

+3 −3
Original line number Diff line number Diff line
@@ -48,8 +48,8 @@ import com.fsck.k9.mailstore.LockableDatabase.SchemaDefinition;
import com.fsck.k9.mailstore.StorageManager.InternalStorageProvider;
import com.fsck.k9.message.extractors.AttachmentInfoExtractor;
import com.fsck.k9.search.LocalSearch;
import com.fsck.k9.search.SearchSpecification.Attribute;
import com.fsck.k9.search.SearchSpecification.SearchField;
import app.k9mail.legacy.search.api.SearchAttribute;
import app.k9mail.legacy.search.api.SearchField;
import com.fsck.k9.search.SqlQueryBuilder;
import kotlinx.datetime.Clock;
import org.apache.commons.io.IOUtils;
@@ -422,7 +422,7 @@ public class LocalStore {
        String rootIdString = Long.toString(rootId);

        LocalSearch search = new LocalSearch();
        search.and(SearchField.THREAD_ID, rootIdString, Attribute.EQUALS);
        search.and(SearchField.THREAD_ID, rootIdString, SearchAttribute.EQUALS);

        return searchForMessages(search);
    }
+15 −9
Original line number Diff line number Diff line
@@ -2,10 +2,10 @@ package com.fsck.k9.search

import app.k9mail.legacy.account.Account
import app.k9mail.legacy.account.Account.FolderMode
import app.k9mail.legacy.search.api.SearchAttribute
import app.k9mail.legacy.search.api.SearchCondition
import app.k9mail.legacy.search.api.SearchField
import com.fsck.k9.mail.FolderClass
import com.fsck.k9.search.SearchSpecification.Attribute
import com.fsck.k9.search.SearchSpecification.SearchCondition
import com.fsck.k9.search.SearchSpecification.SearchField

/**
 * Modify the supplied [LocalSearch] instance to limit the search to displayable folders.
@@ -17,16 +17,16 @@ fun LocalSearch.limitToDisplayableFolders(account: Account) {
    when (account.folderDisplayMode) {
        FolderMode.FIRST_CLASS -> {
            // Count messages in the INBOX and non-special first class folders
            and(SearchField.DISPLAY_CLASS, FolderClass.FIRST_CLASS.name, Attribute.EQUALS)
            and(SearchField.DISPLAY_CLASS, FolderClass.FIRST_CLASS.name, SearchAttribute.EQUALS)
        }
        FolderMode.FIRST_AND_SECOND_CLASS -> {
            // Count messages in the INBOX and non-special first and second class folders
            and(SearchField.DISPLAY_CLASS, FolderClass.FIRST_CLASS.name, Attribute.EQUALS)
            and(SearchField.DISPLAY_CLASS, FolderClass.FIRST_CLASS.name, SearchAttribute.EQUALS)

            // TODO: Create a proper interface for creating arbitrary condition trees
            val searchCondition = SearchCondition(
                SearchField.DISPLAY_CLASS,
                Attribute.EQUALS,
                SearchAttribute.EQUALS,
                FolderClass.SECOND_CLASS.name,
            )
            val root = conditions
@@ -38,7 +38,7 @@ fun LocalSearch.limitToDisplayableFolders(account: Account) {
        }
        FolderMode.NOT_SECOND_CLASS -> {
            // Count messages in the INBOX and non-special non-second-class folders
            and(SearchField.DISPLAY_CLASS, FolderClass.SECOND_CLASS.name, Attribute.NOT_EQUALS)
            and(SearchField.DISPLAY_CLASS, FolderClass.SECOND_CLASS.name, SearchAttribute.NOT_EQUALS)
        }
        FolderMode.ALL, FolderMode.NONE -> {
            // Count messages in the INBOX and non-special folders
@@ -66,12 +66,18 @@ fun LocalSearch.excludeSpecialFolders(account: Account) {
    this.excludeSpecialFolder(account.sentFolderId)

    account.inboxFolderId?.let { inboxFolderId ->
        or(SearchCondition(SearchField.FOLDER, Attribute.EQUALS, inboxFolderId.toString()))
        or(
            SearchCondition(
                SearchField.FOLDER,
                SearchAttribute.EQUALS,
                inboxFolderId.toString(),
            ),
        )
    }
}

private fun LocalSearch.excludeSpecialFolder(folderId: Long?) {
    if (folderId != null) {
        and(SearchField.FOLDER, folderId.toString(), Attribute.NOT_EQUALS)
        and(SearchField.FOLDER, folderId.toString(), SearchAttribute.NOT_EQUALS)
    }
}
+4 −4
Original line number Diff line number Diff line
@@ -10,9 +10,9 @@ import android.database.Cursor;
import android.os.Parcel;
import android.os.Parcelable;

import com.fsck.k9.search.SearchSpecification.Attribute;
import com.fsck.k9.search.SearchSpecification.SearchCondition;
import com.fsck.k9.search.SearchSpecification.SearchField;
import app.k9mail.legacy.search.api.SearchAttribute;
import app.k9mail.legacy.search.api.SearchCondition;
import app.k9mail.legacy.search.api.SearchField;


/**
@@ -98,7 +98,7 @@ public class ConditionsTreeNode implements Parcelable {

        if (tmpValue == Operator.CONDITION) {
            condition = new SearchCondition(SearchField.valueOf(cursor.getString(0)),
                    Attribute.valueOf(cursor.getString(2)), cursor.getString(1));
                    SearchAttribute.valueOf(cursor.getString(2)), cursor.getString(1));
        }

        result = new ConditionsTreeNode(condition);
+8 −3
Original line number Diff line number Diff line
@@ -8,6 +8,11 @@ import java.util.Set;
import android.os.Parcel;
import android.os.Parcelable;

import app.k9mail.legacy.search.api.SearchAttribute;
import app.k9mail.legacy.search.api.SearchCondition;
import app.k9mail.legacy.search.api.SearchField;


/**
 * This class represents a local search.
 *
@@ -132,7 +137,7 @@ public class LocalSearch implements SearchSpecification {
     * @param value Value to look for.
     * @param attribute Attribute to use when matching.
     */
    public void and(SearchField field, String value, Attribute attribute) {
    public void and(SearchField field, String value, SearchAttribute attribute) {
        and(new SearchCondition(field, attribute, value));
    }

@@ -212,7 +217,7 @@ public class LocalSearch implements SearchSpecification {
         *          - do and on root of it & rest of search
         *          - do or between folder nodes
         */
        mConditions = and(new SearchCondition(SearchField.FOLDER, Attribute.EQUALS, Long.toString(folderId)));
        mConditions = and(new SearchCondition(SearchField.FOLDER, SearchAttribute.EQUALS, Long.toString(folderId)));
    }

    /*
@@ -224,7 +229,7 @@ public class LocalSearch implements SearchSpecification {
        List<Long> results = new ArrayList<>();
        for (ConditionsTreeNode node : mLeafSet) {
            if (node.mCondition.field == SearchField.FOLDER &&
                    node.mCondition.attribute == Attribute.EQUALS) {
                    node.mCondition.attribute == SearchAttribute.EQUALS) {
                results.add(Long.valueOf(node.mCondition.value));
            }
        }
Loading