Limit thread search range

pull/207/head
M66B 3 years ago
parent 88d4b5cf66
commit e5ec014a6a

@ -2909,7 +2909,7 @@ class Core {
message.references = TextUtils.join(" ", helper.getReferences()); message.references = TextUtils.join(" ", helper.getReferences());
message.inreplyto = helper.getInReplyTo(); message.inreplyto = helper.getInReplyTo();
message.deliveredto = helper.getDeliveredTo(); message.deliveredto = helper.getDeliveredTo();
message.thread = helper.getThreadId(context, account.id, folder.id, 0); message.thread = helper.getThreadId(context, account.id, folder.id, 0, received);
message.priority = helper.getPriority(); message.priority = helper.getPriority();
message.sensitivity = helper.getSensitivity(); message.sensitivity = helper.getSensitivity();
message.auto_submitted = helper.getAutoSubmitted(); message.auto_submitted = helper.getAutoSubmitted();
@ -3807,7 +3807,7 @@ class Core {
have = true; have = true;
if (dup.folder.equals(folder.id)) { if (dup.folder.equals(folder.id)) {
String thread = helper.getThreadId(context, account.id, folder.id, uid); String thread = helper.getThreadId(context, account.id, folder.id, uid, dup.received);
Log.i(folder.name + " found as id=" + dup.id + Log.i(folder.name + " found as id=" + dup.id +
" uid=" + dup.uid + "/" + uid + " uid=" + dup.uid + "/" + uid +
" msgid=" + msgid + " thread=" + thread); " msgid=" + msgid + " thread=" + thread);
@ -3886,7 +3886,7 @@ class Core {
message.inreplyto = helper.getInReplyTo(); message.inreplyto = helper.getInReplyTo();
// Local address contains control or whitespace in string ``mailing list someone@example.org'' // Local address contains control or whitespace in string ``mailing list someone@example.org''
message.deliveredto = helper.getDeliveredTo(); message.deliveredto = helper.getDeliveredTo();
message.thread = helper.getThreadId(context, account.id, folder.id, uid); message.thread = helper.getThreadId(context, account.id, folder.id, uid, received);
if (BuildConfig.DEBUG && message.thread.startsWith("outlook:")) if (BuildConfig.DEBUG && message.thread.startsWith("outlook:"))
message.warning = message.thread; message.warning = message.thread;
message.priority = helper.getPriority(); message.priority = helper.getPriority();

@ -424,8 +424,9 @@ public interface DaoMessage {
@Query("SELECT thread, msgid, hash, inreplyto FROM message" + @Query("SELECT thread, msgid, hash, inreplyto FROM message" +
" WHERE account = :account" + " WHERE account = :account" +
" AND (msgid IN (:msgids) OR inreplyto IN (:msgids))") " AND (msgid IN (:msgids) OR inreplyto IN (:msgids))" +
List<TupleThreadInfo> getThreadInfo(long account, List<String> msgids); " AND (:range IS NULL || received > :range)")
List<TupleThreadInfo> getThreadInfo(long account, List<String> msgids, Long range);
@Query("SELECT * FROM message" + @Query("SELECT * FROM message" +
" WHERE account = :account" + " WHERE account = :account" +

@ -141,6 +141,7 @@ public class MessageHelper {
static final int DEFAULT_DOWNLOAD_SIZE = 4 * 1024 * 1024; // bytes static final int DEFAULT_DOWNLOAD_SIZE = 4 * 1024 * 1024; // bytes
static final String HEADER_CORRELATION_ID = "X-Correlation-ID"; static final String HEADER_CORRELATION_ID = "X-Correlation-ID";
static final int MAX_SUBJECT_AGE = 48; // hours static final int MAX_SUBJECT_AGE = 48; // hours
static final long MAX_THREAD_AGE = 180; // days
static final List<String> RECEIVED_WORDS = Collections.unmodifiableList(Arrays.asList( static final List<String> RECEIVED_WORDS = Collections.unmodifiableList(Arrays.asList(
"from", "by", "via", "with", "id", "for" "from", "by", "via", "with", "id", "for"
@ -1334,10 +1335,10 @@ public class MessageHelper {
return reportHeaders; return reportHeaders;
} }
String getThreadId(Context context, long account, long folder, long uid) throws MessagingException { String getThreadId(Context context, long account, long folder, long uid, long received) throws MessagingException {
if (threadId == null) if (threadId == null)
if (true) if (true)
threadId = _getThreadIdAlt(context, account, folder, uid); threadId = _getThreadIdAlt(context, account, folder, uid, received);
else else
threadId = _getThreadId(context, account, folder, uid); threadId = _getThreadId(context, account, folder, uid);
return threadId; return threadId;
@ -1429,7 +1430,7 @@ public class MessageHelper {
return thread; return thread;
} }
private String _getThreadIdAlt(Context context, long account, long folder, long uid) throws MessagingException { private String _getThreadIdAlt(Context context, long account, long folder, long uid, long received) throws MessagingException {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (imessage instanceof GmailMessage) { if (imessage instanceof GmailMessage) {
@ -1483,9 +1484,10 @@ public class MessageHelper {
List<String> all = new ArrayList<>(refs); List<String> all = new ArrayList<>(refs);
all.add(msgid); all.add(msgid);
Long range = (received == 0 ? null : received - MAX_THREAD_AGE * 24 * 3600L);
List<TupleThreadInfo> infos = (all.size() == 0 List<TupleThreadInfo> infos = (all.size() == 0
? new ArrayList<>() ? new ArrayList<>()
: db.message().getThreadInfo(account, all)); : db.message().getThreadInfo(account, all, range));
// References, In-Reply-To (sent before) // References, In-Reply-To (sent before)
for (TupleThreadInfo info : infos) for (TupleThreadInfo info : infos)

Loading…
Cancel
Save