From 322cb2f803f70372413a17b2cfa3dd0f59b2338e Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 27 Jul 2024 08:53:14 +0200 Subject: [PATCH] Option to auto encrypt on reply --- .../java/eu/faircode/email/FragmentCompose.java | 9 +++++++-- .../faircode/email/FragmentOptionsEncryption.java | 12 +++++++++++- .../main/res/layout/fragment_options_encryption.xml | 13 ++++++++++++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 71e0ebbc0d..e9033707b5 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -5496,6 +5496,7 @@ public class FragmentCompose extends FragmentBase { boolean resize_reply = prefs.getBoolean("resize_reply", true); boolean sign_default = prefs.getBoolean("sign_default", false); boolean encrypt_default = prefs.getBoolean("encrypt_default", false); + boolean encrypt_reply = prefs.getBoolean("encrypt_reply", false); boolean receipt_default = prefs.getBoolean("receipt_default", false); boolean write_below = prefs.getBoolean("write_below", false); boolean perform_expunge = prefs.getBoolean("perform_expunge", true); @@ -5981,17 +5982,21 @@ public class FragmentCompose extends FragmentBase { // Encryption List
recipients = data.draft.getAllRecipients(); + boolean reply = (encrypt_reply && ( + EntityMessage.PGP_SIGNENCRYPT.equals(ref.ui_encrypt) || + EntityMessage.SMIME_SIGNENCRYPT.equals(ref.ui_encrypt))); + if (EntityMessage.PGP_SIGNONLY.equals(ref.ui_encrypt) || EntityMessage.PGP_SIGNENCRYPT.equals(ref.ui_encrypt)) { if (PgpHelper.isOpenKeychainInstalled(context) && selected.sign_key != null && - PgpHelper.hasPgpKey(context, recipients, true)) + (reply || PgpHelper.hasPgpKey(context, recipients, true))) data.draft.ui_encrypt = ref.ui_encrypt; } else if (EntityMessage.SMIME_SIGNONLY.equals(ref.ui_encrypt) || EntityMessage.SMIME_SIGNENCRYPT.equals(ref.ui_encrypt)) { if (ActivityBilling.isPro(context) && selected.sign_key_alias != null && - SmimeHelper.hasSmimeKey(context, recipients, true)) + (reply || SmimeHelper.hasSmimeKey(context, recipients, true))) data.draft.ui_encrypt = ref.ui_encrypt; } } diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsEncryption.java b/app/src/main/java/eu/faircode/email/FragmentOptionsEncryption.java index b7bde5ca2a..9a0d0053c0 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsEncryption.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsEncryption.java @@ -88,6 +88,7 @@ public class FragmentOptionsEncryption extends FragmentBase private SwitchCompat swSign; private SwitchCompat swEncrypt; private SwitchCompat swEncryptAuto; + private SwitchCompat swEncryptReply; private SwitchCompat swAutoVerify; private SwitchCompat swAutoDecrypt; private SwitchCompat swAutoUndoDecrypt; @@ -119,7 +120,7 @@ public class FragmentOptionsEncryption extends FragmentBase static final int REQUEST_IMPORT_CERTIFICATE = 1; final static List RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList( - "sign_default", "encrypt_default", "encrypt_auto", + "sign_default", "encrypt_default", "encrypt_auto", "encrypt_reply", "auto_verify", "auto_decrypt", "auto_undecrypt", "openpgp_provider", "autocrypt", "autocrypt_mutual", "encrypt_subject", "sign_algo_smime", "encrypt_algo_smime", "check_certificate" @@ -141,6 +142,7 @@ public class FragmentOptionsEncryption extends FragmentBase swSign = view.findViewById(R.id.swSign); swEncrypt = view.findViewById(R.id.swEncrypt); swEncryptAuto = view.findViewById(R.id.swEncryptAuto); + swEncryptReply = view.findViewById(R.id.swEncryptReply); swAutoVerify = view.findViewById(R.id.swAutoVerify); swAutoDecrypt = view.findViewById(R.id.swAutoDecrypt); swAutoUndoDecrypt = view.findViewById(R.id.swAutoUndoDecrypt); @@ -228,6 +230,13 @@ public class FragmentOptionsEncryption extends FragmentBase } }); + swEncryptReply.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("encrypt_reply", checked).apply(); + } + }); + swAutoVerify.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -664,6 +673,7 @@ public class FragmentOptionsEncryption extends FragmentBase swEncrypt.setChecked(prefs.getBoolean("encrypt_default", false)); swSign.setEnabled(!swEncrypt.isChecked()); swEncryptAuto.setChecked(prefs.getBoolean("encrypt_auto", false)); + swEncryptReply.setChecked(prefs.getBoolean("encrypt_reply", false)); swAutoVerify.setChecked(prefs.getBoolean("auto_verify", false)); swAutoDecrypt.setChecked(prefs.getBoolean("auto_decrypt", false)); swAutoUndoDecrypt.setChecked(prefs.getBoolean("auto_undecrypt", false)); diff --git a/app/src/main/res/layout/fragment_options_encryption.xml b/app/src/main/res/layout/fragment_options_encryption.xml index 70a76d89b3..4378a65bb3 100644 --- a/app/src/main/res/layout/fragment_options_encryption.xml +++ b/app/src/main/res/layout/fragment_options_encryption.xml @@ -130,6 +130,17 @@ app:layout_constraintTop_toBottomOf="@id/swEncrypt" app:switchPadding="12dp" /> + + Sign by default Encrypt by default Automatically encrypt when all recipients\' keys are available + Automatically encrypt when replying to an encrypted message Automatically verify signed messages Automatically decrypt messages Undo decryption on closing conversation