mirror of https://github.com/M66B/FairEmail.git
Fixed regex search
This commit is contained in:
parent
c022d01270
commit
8c20cf7969
|
@ -307,88 +307,14 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|||
if (message == null || message.ui_hide)
|
||||
continue;
|
||||
|
||||
if (criteria.with_unseen) {
|
||||
if (message.ui_seen)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (criteria.with_flagged) {
|
||||
if (!message.ui_flagged)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (criteria.with_hidden) {
|
||||
if (message.ui_snoozed == null)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (criteria.with_encrypted) {
|
||||
if (message.encrypt == null ||
|
||||
EntityMessage.ENCRYPT_NONE.equals(message.encrypt))
|
||||
continue;
|
||||
}
|
||||
|
||||
if (criteria.with_attachments) {
|
||||
if (message.attachments == 0)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (excluded.contains(message.folder))
|
||||
continue;
|
||||
|
||||
boolean matched = false;
|
||||
|
||||
if (!matched && criteria.in_senders) {
|
||||
if (contains(message.from, criteria.query))
|
||||
matched = true;
|
||||
}
|
||||
|
||||
if (!matched && criteria.in_recipients) {
|
||||
if (contains(message.to, criteria.query) ||
|
||||
contains(message.cc, criteria.query) ||
|
||||
contains(message.bcc, criteria.query))
|
||||
matched = true;
|
||||
}
|
||||
|
||||
if (!matched && criteria.in_subject) {
|
||||
if (contains(message.subject, criteria.query, false))
|
||||
matched = true;
|
||||
}
|
||||
|
||||
if (!matched && criteria.in_keywords) {
|
||||
if (message.keywords != null)
|
||||
for (String keyword : message.keywords)
|
||||
if (contains(keyword, criteria.query, false)) {
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!matched && criteria.in_notes) {
|
||||
if (contains(message.notes, criteria.query, false))
|
||||
matched = true;
|
||||
}
|
||||
|
||||
if (!matched && criteria.in_message)
|
||||
try {
|
||||
File file = EntityMessage.getFile(context, id);
|
||||
if (file.exists()) {
|
||||
String html = Helper.readText(file);
|
||||
if (contains(html, criteria.query, true)) {
|
||||
String text = HtmlHelper.getFullText(html);
|
||||
if (contains(text, criteria.query, false))
|
||||
matched = true;
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
|
||||
if (!matched)
|
||||
if (!matchMessage(context, message, criteria))
|
||||
continue;
|
||||
|
||||
found += db.message().setMessageFound(id, true);
|
||||
Log.i("Boundary matched=" + id + " found=" + found);
|
||||
found += db.message().setMessageFound(message.id, true);
|
||||
Log.i("Boundary matched=" + message.id + " found=" + found);
|
||||
}
|
||||
db.setTransactionSuccessful();
|
||||
|
||||
|
@ -406,13 +332,13 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|||
state.matches = db.message().matchMessages(
|
||||
account, folder, exclude,
|
||||
query,
|
||||
criteria.in_senders,
|
||||
criteria.in_recipients,
|
||||
criteria.in_subject,
|
||||
criteria.in_keywords,
|
||||
criteria.in_message,
|
||||
criteria.in_notes,
|
||||
criteria.in_headers,
|
||||
//criteria.in_senders,
|
||||
//criteria.in_recipients,
|
||||
//criteria.in_subject,
|
||||
//criteria.in_keywords,
|
||||
//criteria.in_message,
|
||||
//criteria.in_notes,
|
||||
//criteria.in_headers,
|
||||
criteria.with_unseen,
|
||||
criteria.with_flagged,
|
||||
criteria.with_hidden,
|
||||
|
@ -443,34 +369,12 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|||
state.index = i + 1;
|
||||
|
||||
TupleMatch match = state.matches.get(i);
|
||||
boolean matched = (match.matched != null && match.matched &&
|
||||
plus.size() + minus.size() == 0);
|
||||
boolean matched = (criteria.query == null || Boolean.TRUE.equals(match.matched));
|
||||
|
||||
if (!matched && criteria.query != null &&
|
||||
criteria.in_subject && plus.size() + minus.size() > 0) {
|
||||
if (!matched) {
|
||||
EntityMessage message = db.message().getMessage(match.id);
|
||||
if (message != null)
|
||||
matched = contains(message.subject, criteria.query, false);
|
||||
}
|
||||
|
||||
if (!matched && criteria.query != null &&
|
||||
(criteria.in_message || criteria.in_html))
|
||||
try {
|
||||
File file = EntityMessage.getFile(context, match.id);
|
||||
if (file.exists()) {
|
||||
String html = Helper.readText(file);
|
||||
if (contains(html, criteria.query, true)) {
|
||||
if (criteria.in_html)
|
||||
matched = true;
|
||||
else {
|
||||
String text = HtmlHelper.getFullText(html);
|
||||
if (contains(text, criteria.query, false))
|
||||
matched = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
Log.e(ex);
|
||||
if (message != null && !message.ui_hide)
|
||||
matched = matchMessage(context, message, criteria);
|
||||
}
|
||||
|
||||
if (matched) {
|
||||
|
@ -818,6 +722,109 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|||
return imessages;
|
||||
}
|
||||
|
||||
private static boolean matchMessage(Context context, EntityMessage message, SearchCriteria criteria) {
|
||||
if (criteria.with_unseen) {
|
||||
if (message.ui_seen)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (criteria.with_flagged) {
|
||||
if (!message.ui_flagged)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (criteria.with_hidden) {
|
||||
if (message.ui_snoozed == null)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (criteria.with_encrypted) {
|
||||
if (message.encrypt == null ||
|
||||
EntityMessage.ENCRYPT_NONE.equals(message.encrypt))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (criteria.with_attachments) {
|
||||
if (message.attachments == 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
if (criteria.with_notes) {
|
||||
if (message.notes == null)
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
if (criteria.with_size != null) {
|
||||
if (message.total == null || message.total < criteria.with_size)
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
if (criteria.before != null) {
|
||||
if (message.received > criteria.before)
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
if (criteria.after != null) {
|
||||
if (message.received < criteria.after)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (criteria.in_senders) {
|
||||
if (contains(message.from, criteria.query))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (criteria.in_recipients) {
|
||||
if (contains(message.to, criteria.query) ||
|
||||
contains(message.cc, criteria.query) ||
|
||||
contains(message.bcc, criteria.query))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (criteria.in_subject) {
|
||||
if (contains(message.subject, criteria.query, false))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (criteria.in_keywords) {
|
||||
if (message.keywords != null)
|
||||
for (String keyword : message.keywords)
|
||||
if (contains(keyword, criteria.query, false))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (criteria.in_notes) {
|
||||
if (contains(message.notes, criteria.query, false))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (criteria.in_headers) {
|
||||
if (contains(message.headers, criteria.query, false))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (criteria.in_message)
|
||||
try {
|
||||
File file = EntityMessage.getFile(context, message.id);
|
||||
if (file.exists()) {
|
||||
String html = Helper.readText(file);
|
||||
if (contains(html, criteria.query, true)) {
|
||||
String text = HtmlHelper.getFullText(html);
|
||||
if (contains(text, criteria.query, false))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean contains(Address[] addresses, String query) {
|
||||
if (addresses == null)
|
||||
return false;
|
||||
|
|
|
@ -336,15 +336,15 @@ public interface DaoMessage {
|
|||
Cursor getMessageFts();
|
||||
|
||||
@Query("SELECT message.id, account, thread, (:find IS NULL" +
|
||||
" OR (:senders AND `from` LIKE :find COLLATE NOCASE)" + // no index
|
||||
" OR (:recipients AND `to` LIKE :find COLLATE NOCASE)" + // no index
|
||||
" OR (:recipients AND `cc` LIKE :find COLLATE NOCASE)" + // no index
|
||||
" OR (:recipients AND `bcc` LIKE :find COLLATE NOCASE)" + // no index
|
||||
" OR (:subject AND `subject` LIKE :find COLLATE NOCASE)" + // unsuitable index
|
||||
" OR (:keywords AND `keywords` LIKE :find COLLATE NOCASE)" + // no index
|
||||
" OR (:message AND `preview` LIKE :find COLLATE NOCASE)" + // no index
|
||||
" OR (:notes AND `notes` LIKE :find COLLATE NOCASE)" + // no index
|
||||
" OR (:headers AND `headers` LIKE :find COLLATE NOCASE)" + // no index
|
||||
//" OR (:senders AND `from` LIKE :find COLLATE NOCASE)" + // no index
|
||||
//" OR (:recipients AND `to` LIKE :find COLLATE NOCASE)" + // no index
|
||||
//" OR (:recipients AND `cc` LIKE :find COLLATE NOCASE)" + // no index
|
||||
//" OR (:recipients AND `bcc` LIKE :find COLLATE NOCASE)" + // no index
|
||||
//" OR (:subject AND `subject` LIKE :find COLLATE NOCASE)" + // unsuitable index
|
||||
//" OR (:keywords AND `keywords` LIKE :find COLLATE NOCASE)" + // no index
|
||||
//" OR (:message AND `preview` LIKE :find COLLATE NOCASE)" + // no index
|
||||
//" OR (:notes AND `notes` LIKE :find COLLATE NOCASE)" + // no index
|
||||
//" OR (:headers AND `headers` LIKE :find COLLATE NOCASE)" + // no index
|
||||
" OR (attachment.name LIKE :find COLLATE NOCASE)" + // no index
|
||||
" OR (attachment.type LIKE :find COLLATE NOCASE)) AS matched" + // no index
|
||||
" FROM message" +
|
||||
|
@ -368,7 +368,7 @@ public interface DaoMessage {
|
|||
" LIMIT :limit OFFSET :offset")
|
||||
List<TupleMatch> matchMessages(
|
||||
Long account, Long folder, long[] exclude, String find,
|
||||
boolean senders, boolean recipients, boolean subject, boolean keywords, boolean message, boolean notes, boolean headers,
|
||||
//boolean senders, boolean recipients, boolean subject, boolean keywords, boolean message, boolean notes, boolean headers,
|
||||
boolean unseen, boolean flagged, boolean hidden, boolean encrypted, boolean with_attachments, boolean with_notes,
|
||||
int type_count, String[] types,
|
||||
Integer size,
|
||||
|
|
Loading…
Reference in New Issue