Added option to group by sender/subject

pull/194/merge
M66B 3 years ago
parent 0ee837d3ba
commit fdcf20dcd0

@ -421,6 +421,12 @@ public interface DaoMessage {
" AND inreplyto = :inreplyto")
List<EntityMessage> getMessagesByInReplyTo(long account, String inreplyto);
@Query("SELECT * FROM message" +
" WHERE account = :account" +
" AND sender = :sender" +
" AND subject = :subject")
List<EntityMessage> getMessagesBySubject(long account, String sender, String subject);
@Query("SELECT message.* FROM message" +
" LEFT JOIN message AS base ON base.id = :id" +
" WHERE message.account = :account" +

@ -82,6 +82,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
private SwitchCompat swDeleteUnseen;
private SwitchCompat swSyncKept;
private SwitchCompat swGmailThread;
private SwitchCompat swSubjectThreading;
private SwitchCompat swSyncFolders;
private SwitchCompat swSyncFoldersPoll;
private SwitchCompat swSyncSharedFolders;
@ -103,7 +104,8 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
private final static String[] RESET_OPTIONS = new String[]{
"enabled", "poll_interval", "auto_optimize", "schedule", "schedule_start", "schedule_end",
"sync_quick_imap", "sync_quick_pop",
"sync_nodate", "sync_unseen", "sync_flagged", "delete_unseen", "sync_kept", "gmail_thread_id",
"sync_nodate", "sync_unseen", "sync_flagged", "delete_unseen", "sync_kept",
"gmail_thread_id", "subject_threading",
"sync_folders", "sync_folders_poll", "sync_shared_folders", "subscriptions",
"check_authentication", "check_reply_domain", "check_mx", "check_blocklist", "use_blocklist",
"tune_keep_alive"
@ -149,6 +151,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
swDeleteUnseen = view.findViewById(R.id.swDeleteUnseen);
swSyncKept = view.findViewById(R.id.swSyncKept);
swGmailThread = view.findViewById(R.id.swGmailThread);
swSubjectThreading = view.findViewById(R.id.swSubjectThreading);
swSyncFolders = view.findViewById(R.id.swSyncFolders);
swSyncFoldersPoll = view.findViewById(R.id.swSyncFoldersPoll);
swSyncSharedFolders = view.findViewById(R.id.swSyncSharedFolders);
@ -325,6 +328,14 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("gmail_thread_id", checked).apply();
swSubjectThreading.setEnabled(!checked);
}
});
swSubjectThreading.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("subject_threading", checked).apply();
}
});
@ -493,6 +504,8 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
swDeleteUnseen.setChecked(prefs.getBoolean("delete_unseen", false));
swSyncKept.setChecked(prefs.getBoolean("sync_kept", true));
swGmailThread.setChecked(prefs.getBoolean("gmail_thread_id", false));
swSubjectThreading.setChecked(prefs.getBoolean("subject_threading", false));
swSubjectThreading.setEnabled(!swGmailThread.isChecked());
swSyncFolders.setChecked(prefs.getBoolean("sync_folders", true));
swSyncFoldersPoll.setChecked(prefs.getBoolean("sync_folders_poll", false));
swSyncFoldersPoll.setEnabled(swSyncFolders.isChecked());

@ -1274,9 +1274,10 @@ public class MessageHelper {
}
String getThreadId(Context context, long account, long folder, long uid) throws MessagingException {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (imessage instanceof GmailMessage) {
// https://developers.google.com/gmail/imap/imap-extensions#access_to_the_gmail_thread_id_x-gm-thrid
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean gmail_thread_id = prefs.getBoolean("gmail_thread_id", false);
if (gmail_thread_id) {
long thrid = ((GmailMessage) imessage).getThrId();
@ -1330,6 +1331,21 @@ public class MessageHelper {
db.message().updateMessageThread(message.account, message.thread, thread);
}
boolean subject_threading = prefs.getBoolean("subject_threading", false);
if (subject_threading) {
String sender = getSortKey(getFrom());
String subject = getSubject();
if (!TextUtils.isEmpty(sender) && !TextUtils.isEmpty(subject)) {
List<EntityMessage> subjects = db.message().getMessagesBySubject(account, sender, subject);
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);
}
}
}
return thread;
}

@ -577,6 +577,18 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swGmailThread" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSubjectThreading"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_subject_threading"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvGmailThreadHint"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSyncFolders"
android:layout_width="0dp"
@ -586,7 +598,7 @@
android:text="@string/title_advanced_sync_folders"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvGmailThreadHint"
app:layout_constraintTop_toBottomOf="@id/swSubjectThreading"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView

@ -351,6 +351,7 @@
<string name="title_advanced_delete_unseen">Delete old unread messages</string>
<string name="title_advanced_kept_removed">Check if old messages were removed from the server</string>
<string name="title_advanced_gmail_thread">Gmail message grouping style for Gmail accounts</string>
<string name="title_advanced_subject_threading">Group messages by sender and subject</string>
<string name="title_advanced_sync_folders">Synchronize folder list</string>
<string name="title_advanced_sync_folders_poll">Actively synchronize folder list</string>
<string name="title_advanced_sync_shared_folders">Synchronize shared folder lists</string>

Loading…
Cancel
Save