Debug: added option to save user flags

This commit is contained in:
M66B 2024-02-07 07:37:59 +01:00
parent 3fdedcd813
commit 0853694aa2
4 changed files with 37 additions and 4 deletions

View File

@ -1940,6 +1940,8 @@ class Core {
private static void onRaw(Context context, JSONArray jargs, EntityAccount account, EntityFolder folder, EntityMessage message, IMAPFolder ifolder) throws MessagingException, IOException, JSONException { private static void onRaw(Context context, JSONArray jargs, EntityAccount account, EntityFolder folder, EntityMessage message, IMAPFolder ifolder) throws MessagingException, IOException, JSONException {
// Download raw message // Download raw message
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean save_user_flags = prefs.getBoolean("save_user_flags", false);
if (message.raw == null || !message.raw) { if (message.raw == null || !message.raw) {
IMAPMessage imessage = (IMAPMessage) ifolder.getMessageByUID(message.uid); IMAPMessage imessage = (IMAPMessage) ifolder.getMessageByUID(message.uid);
@ -1955,12 +1957,21 @@ class Core {
Properties props = MessageHelper.getSessionProperties(account.unicode); Properties props = MessageHelper.getSessionProperties(account.unicode);
Session isession = Session.getInstance(props, null); Session isession = Session.getInstance(props, null);
MessageHelper helper; MimeMessage saved;
try (InputStream is = new FileInputStream(file)) { try (InputStream is = new FileInputStream(file)) {
helper = new MessageHelper(new MimeMessage(isession, is), context); saved = new MimeMessage(isession, is);
}
if (save_user_flags) {
String userFlags = TextUtils.join(",", imessage.getFlags().getUserFlags());
saved.addHeader("X-User-Flags", userFlags);
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
saved.writeTo(os);
}
} }
// Yahoo is returning incorrect messages // Yahoo is returning incorrect messages
MessageHelper helper = new MessageHelper(saved, context);
if (!Objects.equals(message.msgid, helper.getMessageID())) if (!Objects.equals(message.msgid, helper.getMessageID()))
throw new MessagingException("Incorrect msgid=" + message.msgid + "/" + helper.getMessageID()); throw new MessagingException("Incorrect msgid=" + message.msgid + "/" + helper.getMessageID());

View File

@ -221,6 +221,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private SwitchCompat swJsonLd; private SwitchCompat swJsonLd;
private SwitchCompat swDupMsgId; private SwitchCompat swDupMsgId;
private SwitchCompat swThreadByRef; private SwitchCompat swThreadByRef;
private SwitchCompat swSaveUserFlags;
private SwitchCompat swMdn; private SwitchCompat swMdn;
private SwitchCompat swAppChooser; private SwitchCompat swAppChooser;
private SwitchCompat swAppChooserShare; private SwitchCompat swAppChooserShare;
@ -287,7 +288,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
"exact_alarms", "exact_alarms",
"native_dkim", "native_arc", "native_arc_whitelist", "native_dkim", "native_arc", "native_arc_whitelist",
"webp", "animate_images", "webp", "animate_images",
"easy_correct", "infra", "tld_flags", "json_ld", "dup_msgids", "thread_byref", "mdn", "easy_correct", "infra", "tld_flags", "json_ld", "dup_msgids", "thread_byref", "save_user_flags", "mdn",
"app_chooser", "app_chooser_share", "adjacent_links", "adjacent_documents", "adjacent_portrait", "adjacent_landscape", "app_chooser", "app_chooser_share", "adjacent_links", "adjacent_documents", "adjacent_portrait", "adjacent_landscape",
"delete_confirmation", "global_keywords", "test_iab" "delete_confirmation", "global_keywords", "test_iab"
)); ));
@ -460,6 +461,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swJsonLd = view.findViewById(R.id.swJsonLd); swJsonLd = view.findViewById(R.id.swJsonLd);
swDupMsgId = view.findViewById(R.id.swDupMsgId); swDupMsgId = view.findViewById(R.id.swDupMsgId);
swThreadByRef = view.findViewById(R.id.swThreadByRef); swThreadByRef = view.findViewById(R.id.swThreadByRef);
swSaveUserFlags = view.findViewById(R.id.swSaveUserFlags);
swMdn = view.findViewById(R.id.swMdn); swMdn = view.findViewById(R.id.swMdn);
swAppChooser = view.findViewById(R.id.swAppChooser); swAppChooser = view.findViewById(R.id.swAppChooser);
swAppChooserShare = view.findViewById(R.id.swAppChooserShare); swAppChooserShare = view.findViewById(R.id.swAppChooserShare);
@ -1570,6 +1572,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
} }
}); });
swSaveUserFlags.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("save_user_flags", checked).apply();
}
});
swMdn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swMdn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -2365,6 +2374,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swJsonLd.setChecked(prefs.getBoolean("json_ld", false)); swJsonLd.setChecked(prefs.getBoolean("json_ld", false));
swDupMsgId.setChecked(prefs.getBoolean("dup_msgids", false)); swDupMsgId.setChecked(prefs.getBoolean("dup_msgids", false));
swThreadByRef.setChecked(prefs.getBoolean("thread_byref", true)); swThreadByRef.setChecked(prefs.getBoolean("thread_byref", true));
swSaveUserFlags.setChecked(prefs.getBoolean("save_user_flags", false));
swMdn.setChecked(prefs.getBoolean("mdn", swExperiments.isChecked())); swMdn.setChecked(prefs.getBoolean("mdn", swExperiments.isChecked()));
swAppChooser.setChecked(prefs.getBoolean("app_chooser", false)); swAppChooser.setChecked(prefs.getBoolean("app_chooser", false));
swAppChooserShare.setChecked(prefs.getBoolean("app_chooser_share", false)); swAppChooserShare.setChecked(prefs.getBoolean("app_chooser_share", false));

View File

@ -1867,6 +1867,17 @@
app:layout_constraintTop_toBottomOf="@id/swDupMsgId" app:layout_constraintTop_toBottomOf="@id/swDupMsgId"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSaveUserFlags"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_save_user_flags"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swThreadByRef"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swMdn" android:id="@+id/swMdn"
android:layout_width="0dp" android:layout_width="0dp"
@ -1875,7 +1886,7 @@
android:text="@string/title_advanced_mdn" android:text="@string/title_advanced_mdn"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swThreadByRef" app:layout_constraintTop_toBottomOf="@id/swSaveUserFlags"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat

View File

@ -948,6 +948,7 @@
<string name="title_advanced_json_ld" translatable="false">Show Linked Data (JSON-LD)</string> <string name="title_advanced_json_ld" translatable="false">Show Linked Data (JSON-LD)</string>
<string name="title_advanced_dup_msgid" translatable="false">Duplicates by message ID</string> <string name="title_advanced_dup_msgid" translatable="false">Duplicates by message ID</string>
<string name="title_advanced_thread_by_ref" translatable="false">Thread by common reference</string> <string name="title_advanced_thread_by_ref" translatable="false">Thread by common reference</string>
<string name="title_advanced_save_user_flags" translatable="false">Save user flags</string>
<string name="title_advanced_mdn" translatable="false">Process MDNs</string> <string name="title_advanced_mdn" translatable="false">Process MDNs</string>
<string name="title_advanced_app_chooser" translatable="false">Use Android app chooser for links</string> <string name="title_advanced_app_chooser" translatable="false">Use Android app chooser for links</string>
<string name="title_advanced_app_chooser_share" translatable="false">Use Android app chooser for files</string> <string name="title_advanced_app_chooser_share" translatable="false">Use Android app chooser for files</string>