diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index c11d91903b..4568aef97a 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -4991,6 +4991,43 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } } + private void handleExit() { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + boolean auto_undecrypt = prefs.getBoolean("auto_undecrypt", false); + if (auto_undecrypt) { + List ids = new ArrayList<>(); + for (int i = 0; i < adapter.getItemCount(); i++) { + TupleMessageEx message = adapter.getItemAtPosition(i); + if (message == null) + continue; + if ((EntityMessage.PGP_SIGNENCRYPT.equals(message.ui_encrypt) && + !EntityMessage.PGP_SIGNENCRYPT.equals(message.encrypt)) || + (EntityMessage.SMIME_SIGNENCRYPT.equals(message.ui_encrypt) && + !EntityMessage.SMIME_SIGNENCRYPT.equals(message.encrypt))) + ids.add(message.id); + } + + Bundle args = new Bundle(); + args.putLongArray("ids", Helper.toLongArray(ids)); + + new SimpleTask() { + @Override + protected Void onExecute(Context context, Bundle args) throws Throwable { + long[] ids = args.getLongArray("ids"); + + for (long id : ids) + lockMessage(id); + return null; + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(getParentFragmentManager(), ex); + } + }.execute(this, args, "messages:lock"); + } + } + private void navigate(long id, final boolean left) { if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) return; @@ -5450,6 +5487,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. return true; } + handleExit(); + return false; } diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsEncryption.java b/app/src/main/java/eu/faircode/email/FragmentOptionsEncryption.java index e0542e8fe6..c4d187f24a 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsEncryption.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsEncryption.java @@ -72,6 +72,7 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre private SwitchCompat swSign; private SwitchCompat swEncrypt; private SwitchCompat swAutoDecrypt; + private SwitchCompat swAutoUndoDecrypt; private Spinner spOpenPgp; private TextView tvOpenPgpStatus; @@ -90,7 +91,7 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre private List openPgpProvider = new ArrayList<>(); private final static String[] RESET_OPTIONS = new String[]{ - "sign_default", "encrypt_default", "auto_decrypt", + "sign_default", "encrypt_default", "auto_decrypt", "auto_undecrypt", "openpgp_provider", "autocrypt", "autocrypt_mutual", "encrypt_subject", "check_certificate" }; @@ -109,6 +110,7 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre swSign = view.findViewById(R.id.swSign); swEncrypt = view.findViewById(R.id.swEncrypt); swAutoDecrypt = view.findViewById(R.id.swAutoDecrypt); + swAutoUndoDecrypt = view.findViewById(R.id.swAutoUndoDecrypt); spOpenPgp = view.findViewById(R.id.spOpenPgp); tvOpenPgpStatus = view.findViewById(R.id.tvOpenPgpStatus); @@ -170,6 +172,13 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre } }); + swAutoUndoDecrypt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("auto_undecrypt", checked).apply(); + } + }); + // PGP spOpenPgp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @@ -363,6 +372,7 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre swEncrypt.setChecked(prefs.getBoolean("encrypt_default", false)); swSign.setEnabled(!swEncrypt.isChecked()); swAutoDecrypt.setChecked(prefs.getBoolean("auto_decrypt", false)); + swAutoUndoDecrypt.setChecked(prefs.getBoolean("auto_undecrypt", false)); String provider = prefs.getString("openpgp_provider", "org.sufficientlysecure.keychain"); spOpenPgp.setTag(provider); diff --git a/app/src/main/res/layout/fragment_options_encryption.xml b/app/src/main/res/layout/fragment_options_encryption.xml index a15317a684..60f8ea0245 100644 --- a/app/src/main/res/layout/fragment_options_encryption.xml +++ b/app/src/main/res/layout/fragment_options_encryption.xml @@ -73,6 +73,17 @@ app:layout_constraintTop_toBottomOf="@id/swEncrypt" app:switchPadding="12dp" /> + + + app:layout_constraintTop_toBottomOf="@id/swAutoUndoDecrypt" /> Sign by default Encrypt by default Automatically decrypt messages + Undo decryption on closing conversation OpenPGP provider Use Autocrypt Autocrypt mutual mode