From 88b3c684eb3cac999c91823054d65d36da65f001 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 10 Apr 2020 11:51:50 +0200 Subject: [PATCH] Prepare searchin on date range --- .../email/BoundaryCallbackMessages.java | 20 ++++++++++++++++--- .../java/eu/faircode/email/DaoMessage.java | 3 +++ .../java/eu/faircode/email/FtsDbHelper.java | 11 ++++++++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java b/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java index 17a72b7a68..07c4b0bdec 100644 --- a/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java +++ b/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java @@ -44,6 +44,7 @@ import java.io.Serializable; import java.text.Normalizer; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.List; import java.util.Objects; import java.util.concurrent.ExecutorService; @@ -60,9 +61,11 @@ import javax.mail.UIDFolder; import javax.mail.internet.MimeMessage; import javax.mail.search.AndTerm; import javax.mail.search.BodyTerm; +import javax.mail.search.ComparisonTerm; import javax.mail.search.FlagTerm; import javax.mail.search.FromStringTerm; import javax.mail.search.OrTerm; +import javax.mail.search.ReceivedDateTerm; import javax.mail.search.RecipientStringTerm; import javax.mail.search.SearchTerm; import javax.mail.search.SubjectTerm; @@ -195,7 +198,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback 0)" + " AND (NOT :attachments OR attachments > 0)" + + " AND (:from IS NULL OR received > :from)" + + " AND (:to IS NULL OR received < :to)" + " ORDER BY received DESC" + " LIMIT :limit OFFSET :offset") List matchMessages( Long account, Long folder, String find, boolean unseen, boolean flagged, boolean hidden, boolean encrypted, boolean attachments, + Long from, Long to, int limit, int offset); @Query("SELECT id" + diff --git a/app/src/main/java/eu/faircode/email/FtsDbHelper.java b/app/src/main/java/eu/faircode/email/FtsDbHelper.java index c3b64f05fe..a87e971d18 100644 --- a/app/src/main/java/eu/faircode/email/FtsDbHelper.java +++ b/app/src/main/java/eu/faircode/email/FtsDbHelper.java @@ -107,9 +107,12 @@ public class FtsDbHelper extends SQLiteOpenHelper { db.delete("message", "rowid = ?", new Object[]{id}); } - static List match(SQLiteDatabase db, Long account, Long folder, String query) { + static List match( + SQLiteDatabase db, + Long account, Long folder, + BoundaryCallbackMessages.SearchCriteria criteria) { StringBuilder sb = new StringBuilder(); - for (String or : query.split(",")) { + for (String or : criteria.query.split(",")) { if (sb.length() > 0) sb.append(" OR "); @@ -137,6 +140,10 @@ public class FtsDbHelper extends SQLiteOpenHelper { select += "account = " + account + " AND "; if (folder != null) select += "folder = " + folder + " AND "; + if (criteria.from != null) + select += "time > " + criteria.from + " AND "; + if (criteria.to != null) + select += "time < " + criteria.to + " AND "; Log.i("FTS select=" + select + " search=" + search); List result = new ArrayList<>();