2012-10-12 06:30:26 -04:00
|
|
|
package com.fsck.k9.search;
|
2010-04-21 22:20:35 -04:00
|
|
|
|
2012-10-12 07:22:54 -04:00
|
|
|
import android.os.Parcel;
|
|
|
|
import android.os.Parcelable;
|
2010-04-29 00:59:14 -04:00
|
|
|
|
2012-10-12 07:22:54 -04:00
|
|
|
public interface SearchSpecification extends Parcelable {
|
2012-10-16 16:42:51 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all the uuids of accounts this search acts on.
|
|
|
|
* @return Array of uuids.
|
|
|
|
*/
|
2012-10-12 07:22:54 -04:00
|
|
|
public String[] getAccountUuids();
|
2012-10-16 16:42:51 -04:00
|
|
|
|
2012-10-12 07:22:54 -04:00
|
|
|
/**
|
|
|
|
* Returns the search's name if it was named.
|
|
|
|
* @return Name of the search.
|
|
|
|
*/
|
2012-10-16 16:42:51 -04:00
|
|
|
public String getName();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the root node of the condition tree accompanying
|
|
|
|
* the search.
|
|
|
|
*
|
|
|
|
* @return Root node of conditions tree.
|
|
|
|
*/
|
|
|
|
public ConditionsTreeNode getConditions();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some meta names for certain conditions.
|
|
|
|
*/
|
2012-10-12 07:22:54 -04:00
|
|
|
public static final String ALL_ACCOUNTS = "allAccounts";
|
2012-10-16 16:42:51 -04:00
|
|
|
public static final String GENERIC_INBOX_NAME = "genericInboxName";
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// ATTRIBUTE enum
|
|
|
|
///////////////////////////////////////////////////////////////
|
2012-10-17 14:52:03 -04:00
|
|
|
public enum Attribute {
|
2012-10-16 16:42:51 -04:00
|
|
|
CONTAINS(false), EQUALS(false), STARTSWITH(false), ENDSWITH(false),
|
|
|
|
NOT_CONTAINS(true), NOT_EQUALS(true), NOT_STARTSWITH(true), NOT_ENDSWITH(true);
|
|
|
|
|
|
|
|
private boolean mNegation;
|
|
|
|
|
2012-10-17 14:52:03 -04:00
|
|
|
private Attribute(boolean negation) {
|
2012-10-16 16:42:51 -04:00
|
|
|
this.mNegation = negation;
|
|
|
|
}
|
|
|
|
|
2012-10-12 07:22:54 -04:00
|
|
|
public String formQuery(String value) {
|
2012-10-16 16:42:51 -04:00
|
|
|
String queryPart = "";
|
|
|
|
|
|
|
|
switch (this) {
|
|
|
|
case NOT_CONTAINS:
|
|
|
|
case CONTAINS:
|
|
|
|
queryPart = "'%"+value+"%'";
|
|
|
|
break;
|
|
|
|
case NOT_EQUALS:
|
|
|
|
case EQUALS:
|
|
|
|
queryPart = "'"+value+"'";
|
|
|
|
break;
|
|
|
|
case NOT_STARTSWITH:
|
|
|
|
case STARTSWITH:
|
|
|
|
queryPart = "'%"+value+"'";
|
|
|
|
break;
|
|
|
|
case NOT_ENDSWITH:
|
|
|
|
case ENDSWITH:
|
|
|
|
queryPart = "'"+value+"%'";
|
|
|
|
break;
|
|
|
|
default: queryPart = "'"+value+"'";
|
|
|
|
}
|
|
|
|
|
|
|
|
return (mNegation ? " NOT LIKE " : " LIKE ") + queryPart;
|
2012-10-12 07:22:54 -04:00
|
|
|
}
|
2012-10-17 14:52:03 -04:00
|
|
|
}
|
2012-10-16 16:42:51 -04:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// SEARCHFIELD enum
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
/*
|
|
|
|
* Using an enum in order to have more robust code. Users ( & coders )
|
|
|
|
* are prevented from passing illegal fields. No database overhead
|
2012-10-12 07:22:54 -04:00
|
|
|
* when invalid fields passed.
|
|
|
|
*
|
|
|
|
* By result, only the fields in here are searchable.
|
|
|
|
*
|
|
|
|
* Fields not in here at this moment ( and by effect not searchable ):
|
|
|
|
* id, html_content, internal_date, message_id,
|
|
|
|
* preview, mime_type
|
2012-10-16 16:42:51 -04:00
|
|
|
*
|
2012-10-12 07:22:54 -04:00
|
|
|
*/
|
2012-10-17 14:52:03 -04:00
|
|
|
public enum Searchfield {
|
2012-10-12 07:22:54 -04:00
|
|
|
SUBJECT("subject"), DATE("date"), UID("uid"), FLAG("flags"),
|
|
|
|
SENDER("sender_list"), TO("to_list"), CC("cc_list"), FOLDER("folder_id"),
|
|
|
|
BCC("bcc_list"), REPLY_TO("reply_to_list"), MESSAGE("text_content"),
|
2012-10-13 09:28:19 -04:00
|
|
|
ATTACHMENT_COUNT("attachment_count"), DELETED("deleted"), THREAD_ROOT("thread_root");
|
2010-04-21 22:20:35 -04:00
|
|
|
|
2012-10-12 07:22:54 -04:00
|
|
|
private String dbName;
|
2012-10-16 16:42:51 -04:00
|
|
|
|
2012-10-17 14:52:03 -04:00
|
|
|
private Searchfield(String dbName) {
|
2012-10-12 07:22:54 -04:00
|
|
|
this.dbName = dbName;
|
|
|
|
}
|
2010-04-29 00:59:14 -04:00
|
|
|
|
2012-10-12 07:22:54 -04:00
|
|
|
public String getDatabaseName() {
|
|
|
|
return dbName;
|
|
|
|
}
|
|
|
|
}
|
2012-10-16 16:42:51 -04:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// SearchCondition class
|
|
|
|
///////////////////////////////////////////////////////////////
|
2012-10-12 07:22:54 -04:00
|
|
|
/**
|
|
|
|
* This class represents 1 value for a certain search field. One
|
2012-10-16 16:42:51 -04:00
|
|
|
* value consists of three things:
|
2012-10-12 07:22:54 -04:00
|
|
|
* an attribute: equals, starts with, contains,...
|
|
|
|
* a searchfield: date, flags, sender, subject,...
|
|
|
|
* a value: "apple", "jesse",..
|
2012-10-16 16:42:51 -04:00
|
|
|
*
|
2012-10-12 07:22:54 -04:00
|
|
|
* @author dzan
|
|
|
|
*/
|
2012-10-17 14:52:03 -04:00
|
|
|
public class SearchCondition implements Parcelable {
|
2012-10-12 07:22:54 -04:00
|
|
|
public String value;
|
2012-10-17 14:52:03 -04:00
|
|
|
public Attribute attribute;
|
|
|
|
public Searchfield field;
|
2012-10-16 16:42:51 -04:00
|
|
|
|
2012-10-17 14:52:03 -04:00
|
|
|
public SearchCondition(Searchfield field, Attribute attribute, String value) {
|
2012-10-12 07:22:54 -04:00
|
|
|
this.value = value;
|
|
|
|
this.attribute = attribute;
|
|
|
|
this.field = field;
|
|
|
|
}
|
2010-04-21 22:20:35 -04:00
|
|
|
|
2012-10-12 07:22:54 -04:00
|
|
|
private SearchCondition(Parcel in) {
|
2012-10-16 16:42:51 -04:00
|
|
|
this.value = in.readString();
|
2012-10-17 14:52:03 -04:00
|
|
|
this.attribute = Attribute.values()[in.readInt()];
|
|
|
|
this.field = Searchfield.values()[in.readInt()];
|
2012-10-16 16:42:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public String toHumanString() {
|
|
|
|
return field.toString() + attribute.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return field.getDatabaseName() + attribute.formQuery(value);
|
2012-10-12 07:22:54 -04:00
|
|
|
}
|
2012-10-16 16:42:51 -04:00
|
|
|
|
2012-10-12 07:22:54 -04:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
if (o instanceof SearchCondition) {
|
|
|
|
SearchCondition tmp = (SearchCondition) o;
|
2012-10-17 14:52:03 -04:00
|
|
|
if (tmp.attribute == attribute &&
|
|
|
|
tmp.field == field &&
|
|
|
|
tmp.value.equals(value)) {
|
2012-10-12 07:22:54 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-10-17 14:52:03 -04:00
|
|
|
|
|
|
|
return false;
|
2012-10-12 07:22:54 -04:00
|
|
|
}
|
2010-04-29 00:59:14 -04:00
|
|
|
|
2012-10-16 16:42:51 -04:00
|
|
|
@Override
|
|
|
|
public int describeContents() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToParcel(Parcel dest, int flags) {
|
|
|
|
dest.writeString(value);
|
|
|
|
dest.writeInt(attribute.ordinal());
|
|
|
|
dest.writeInt(field.ordinal());
|
|
|
|
}
|
|
|
|
|
2012-10-17 14:52:03 -04:00
|
|
|
public static final Parcelable.Creator<SearchCondition> CREATOR =
|
|
|
|
new Parcelable.Creator<SearchCondition>() {
|
|
|
|
|
|
|
|
@Override
|
2012-10-16 16:42:51 -04:00
|
|
|
public SearchCondition createFromParcel(Parcel in) {
|
|
|
|
return new SearchCondition(in);
|
|
|
|
}
|
|
|
|
|
2012-10-17 14:52:03 -04:00
|
|
|
@Override
|
2012-10-16 16:42:51 -04:00
|
|
|
public SearchCondition[] newArray(int size) {
|
|
|
|
return new SearchCondition[size];
|
|
|
|
}
|
|
|
|
};
|
2012-10-12 07:22:54 -04:00
|
|
|
}
|
2010-04-21 22:20:35 -04:00
|
|
|
}
|