diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index a367aecb18..0c56bcb572 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -4610,7 +4610,7 @@ public class FragmentCompose extends FragmentBase { EntityMessage.PGP_SIGNENCRYPT.equals(ref.ui_encrypt)) { if (Helper.isOpenKeychainInstalled(context) && selected.sign_key != null && - hasPgpKey(context, recipients)) + PgpHelper.hasPgpKey(context, recipients, MAX_PGP_BIND_DELAY)) data.draft.ui_encrypt = ref.ui_encrypt; } else if (EntityMessage.SMIME_SIGNONLY.equals(ref.ui_encrypt) || EntityMessage.SMIME_SIGNENCRYPT.equals(ref.ui_encrypt)) { @@ -5846,7 +5846,7 @@ public class FragmentCompose extends FragmentBase { EntityMessage.DSN_NONE.equals(draft.dsn)) && (draft.ui_encrypt == null || EntityMessage.ENCRYPT_NONE.equals(draft.ui_encrypt))) { - args.putBoolean("remind_pgp", hasPgpKey(context, recipients)); + args.putBoolean("remind_pgp", PgpHelper.hasPgpKey(context, recipients, MAX_PGP_BIND_DELAY)); args.putBoolean("remind_smime", hasSmimeKey(context, recipients)); } @@ -6502,35 +6502,6 @@ public class FragmentCompose extends FragmentBase { return -1; } - private boolean hasPgpKey(Context context, List
recipients) { - if (recipients == null || recipients.size() == 0) - return false; - - String[] userIds = new String[recipients.size()]; - for (int i = 0; i < recipients.size(); i++) { - InternetAddress recipient = (InternetAddress) recipients.get(i); - userIds[i] = recipient.getAddress(); - } - - Intent intent = new Intent(OpenPgpApi.ACTION_GET_KEY_IDS); - intent.putExtra(OpenPgpApi.EXTRA_USER_IDS, userIds); - - try { - Intent result = PgpHelper.execute(context, intent, null, null, MAX_PGP_BIND_DELAY); - int resultCode = result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR); - if (resultCode == OpenPgpApi.RESULT_CODE_SUCCESS) { - long[] keyIds = result.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS); - return (keyIds.length > 0); - } - } catch (OperationCanceledException ignored) { - // Do nothing - } catch (Throwable ex) { - Log.w(ex); - } - - return false; - } - private boolean hasSmimeKey(Context context, List
recipients) { if (recipients == null || recipients.size() == 0) return false; diff --git a/app/src/main/java/eu/faircode/email/PgpHelper.java b/app/src/main/java/eu/faircode/email/PgpHelper.java index 886fd6606f..99f6b0a789 100644 --- a/app/src/main/java/eu/faircode/email/PgpHelper.java +++ b/app/src/main/java/eu/faircode/email/PgpHelper.java @@ -34,9 +34,13 @@ import org.openintents.openpgp.util.OpenPgpServiceConnection; import java.io.InputStream; import java.io.OutputStream; +import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import javax.mail.Address; +import javax.mail.internet.InternetAddress; + public class PgpHelper { private static final long CONNECT_TIMEOUT = 5000L; @@ -63,6 +67,35 @@ public class PgpHelper { } } + static boolean hasPgpKey(Context context, List
recipients, long timeout) { + if (recipients == null || recipients.size() == 0) + return false; + + String[] userIds = new String[recipients.size()]; + for (int i = 0; i < recipients.size(); i++) { + InternetAddress recipient = (InternetAddress) recipients.get(i); + userIds[i] = recipient.getAddress(); + } + + Intent intent = new Intent(OpenPgpApi.ACTION_GET_KEY_IDS); + intent.putExtra(OpenPgpApi.EXTRA_USER_IDS, userIds); + + try { + Intent result = execute(context, intent, null, null, timeout); + int resultCode = result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR); + if (resultCode == OpenPgpApi.RESULT_CODE_SUCCESS) { + long[] keyIds = result.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS); + return (keyIds.length > 0); + } + } catch (OperationCanceledException ignored) { + // Do nothing + } catch (Throwable ex) { + Log.w(ex); + } + + return false; + } + private static String getResultName(int code) { switch (code) { case RESULT_CODE_ERROR: