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<>();