Limit subject threading to 24 hours

pull/194/merge
M66B 3 years ago
parent 8cead67e07
commit 6ec57066bd

@ -424,8 +424,9 @@ public interface DaoMessage {
@Query("SELECT * FROM message" +
" WHERE account = :account" +
" AND sender = :sender" +
" AND subject = :subject")
List<EntityMessage> getMessagesBySubject(long account, String sender, String subject);
" AND subject = :subject" +
" AND received >= :since")
List<EntityMessage> getMessagesBySubject(long account, String sender, String subject, long since);
@Query("SELECT message.* FROM message" +
" LEFT JOIN message AS base ON base.id = :id" +
@ -647,8 +648,10 @@ public interface DaoMessage {
int updateMessage(EntityMessage message);
@Query("UPDATE message SET thread = :thread" +
" WHERE account = :account AND thread = :old AND NOT (:old IS :thread)")
int updateMessageThread(long account, String old, String thread);
" WHERE account = :account" +
" AND thread = :old AND NOT (:old IS :thread)" +
" AND (:since IS NULL OR received >= :since)")
int updateMessageThread(long account, String old, String thread, Long since);
@Query("UPDATE message SET uid = :uid WHERE id = :id AND NOT (uid IS :uid)")
int setMessageUid(long id, Long uid);

@ -83,6 +83,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
private SwitchCompat swSyncKept;
private SwitchCompat swGmailThread;
private SwitchCompat swSubjectThreading;
private TextView tvSubjectThreading;
private SwitchCompat swSyncFolders;
private SwitchCompat swSyncFoldersPoll;
private SwitchCompat swSyncSharedFolders;
@ -152,6 +153,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
swSyncKept = view.findViewById(R.id.swSyncKept);
swGmailThread = view.findViewById(R.id.swGmailThread);
swSubjectThreading = view.findViewById(R.id.swSubjectThreading);
tvSubjectThreading = view.findViewById(R.id.tvSubjectThreading);
swSyncFolders = view.findViewById(R.id.swSyncFolders);
swSyncFoldersPoll = view.findViewById(R.id.swSyncFoldersPoll);
swSyncSharedFolders = view.findViewById(R.id.swSyncSharedFolders);
@ -422,6 +424,8 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
// Initialize
FragmentDialogTheme.setBackground(getContext(), view, false);
tvSubjectThreading.setText(getString(R.string.title_advanced_subject_threading_hint, MessageHelper.MAX_SUBJECT_AGE));
DB db = DB.getInstance(getContext());
db.account().liveSynchronizingAccounts().observe(getViewLifecycleOwner(), new Observer<List<EntityAccount>>() {
@Override

@ -129,6 +129,7 @@ public class MessageHelper {
static final int SMALL_MESSAGE_SIZE = 192 * 1024; // bytes
static final int DEFAULT_DOWNLOAD_SIZE = 4 * 1024 * 1024; // bytes
static final String HEADER_CORRELATION_ID = "X-Correlation-ID";
static final int MAX_SUBJECT_AGE = 48; // hours
private static final int MAX_HEADER_LENGTH = 998;
private static final int MAX_MESSAGE_SIZE = 10 * 1024 * 1024; // bytes
@ -1324,31 +1325,31 @@ public class MessageHelper {
for (EntityMessage message : before)
if (!thread.equals(message.thread)) {
Log.w("Updating before thread from " + message.thread + " to " + thread);
db.message().updateMessageThread(message.account, message.thread, thread);
db.message().updateMessageThread(message.account, message.thread, thread, null);
}
List<EntityMessage> after = db.message().getMessagesByInReplyTo(account, msgid);
for (EntityMessage message : after)
if (!thread.equals(message.thread)) {
Log.w("Updating after thread from " + message.thread + " to " + thread);
db.message().updateMessageThread(message.account, message.thread, thread);
db.message().updateMessageThread(message.account, message.thread, thread, null);
}
boolean subject_threading = prefs.getBoolean("subject_threading", false);
if (subject_threading) {
String sender = getSortKey(getFrom());
String subject = getSubject();
long since = new Date().getTime() - MAX_SUBJECT_AGE * 3600 * 1000L;
if (!TextUtils.isEmpty(sender) && !TextUtils.isEmpty(subject)) {
List<EntityMessage> subjects = db.message().getMessagesBySubject(account, sender, subject);
List<EntityMessage> subjects = db.message().getMessagesBySubject(account, sender, subject, since);
for (EntityMessage message : subjects)
if (!thread.equals(message.thread)) {
Log.w("Updating subject thread from " + message.thread + " to " + thread);
db.message().updateMessageThread(message.account, message.thread, thread);
db.message().updateMessageThread(message.account, message.thread, thread, since);
}
}
}
return thread;
}

@ -589,6 +589,19 @@
app:layout_constraintTop_toBottomOf="@id/tvGmailThreadHint"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvSubjectThreading"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_subject_threading_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swSubjectThreading" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSyncFolders"
android:layout_width="0dp"
@ -598,7 +611,7 @@
android:text="@string/title_advanced_sync_folders"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swSubjectThreading"
app:layout_constraintTop_toBottomOf="@id/tvSubjectThreading"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView

@ -716,6 +716,7 @@
<string name="title_advanced_deleted_unseen">When disabled, unread messages are kept on the device forever</string>
<string name="title_advanced_sync_kept_hint">This will transfer extra data and consume extra battery power, especially if a lot of messages are stored on the device</string>
<string name="title_advanced_gmail_thread_hint">This only applies to newly received messages and can break existing groups</string>
<string name="title_advanced_subject_threading_hint">Only messages received in the last %1$d hours</string>
<string name="title_advanced_sync_folders_hint">Disabling this will reduce data and battery usage somewhat, but will disable updating the list of folders too</string>
<string name="title_advanced_poll_folders_hint">Periodically synchronize the folder list in addition to after connecting to an account</string>
<string name="title_advanced_check_authentication_hint">This will check the results of DKIM, SPF and DMARC authentication as performed by the email server</string>

Loading…
Cancel
Save