mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-22 06:01:12 +00:00
Check for any/all PGP or S/MIME keys
This commit is contained in:
parent
09cc268690
commit
388be88d0f
4 changed files with 14 additions and 13 deletions
|
@ -344,9 +344,9 @@ public class EditTextMultiAutoComplete extends AppCompatMultiAutoCompleteTextVie
|
|||
public void run() {
|
||||
try {
|
||||
int has = 0;
|
||||
if (PgpHelper.hasPgpKey(context, recipient))
|
||||
if (PgpHelper.hasPgpKey(context, recipient, true))
|
||||
has |= 1;
|
||||
if (SmimeHelper.hasSmimeKey(context, recipient))
|
||||
if (SmimeHelper.hasSmimeKey(context, recipient, true))
|
||||
has |= 2;
|
||||
encryption.put(email, has);
|
||||
|
||||
|
|
|
@ -5137,13 +5137,13 @@ public class FragmentCompose extends FragmentBase {
|
|||
EntityMessage.PGP_SIGNENCRYPT.equals(ref.ui_encrypt)) {
|
||||
if (Helper.isOpenKeychainInstalled(context) &&
|
||||
selected.sign_key != null &&
|
||||
PgpHelper.hasPgpKey(context, recipients))
|
||||
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))
|
||||
SmimeHelper.hasSmimeKey(context, recipients, true))
|
||||
data.draft.ui_encrypt = ref.ui_encrypt;
|
||||
}
|
||||
}
|
||||
|
@ -6400,8 +6400,8 @@ 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", PgpHelper.hasPgpKey(context, recipients));
|
||||
args.putBoolean("remind_smime", SmimeHelper.hasSmimeKey(context, recipients));
|
||||
args.putBoolean("remind_pgp", PgpHelper.hasPgpKey(context, recipients, false));
|
||||
args.putBoolean("remind_smime", SmimeHelper.hasSmimeKey(context, recipients, false));
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(draft.subject))
|
||||
|
|
|
@ -68,11 +68,11 @@ public class PgpHelper {
|
|||
}
|
||||
}
|
||||
|
||||
static boolean hasPgpKey(Context context, List<Address> recipients) {
|
||||
return hasPgpKey(context, recipients, KEY_TIMEOUT); // milliseconds
|
||||
static boolean hasPgpKey(Context context, List<Address> recipients, boolean all) {
|
||||
return hasPgpKey(context, recipients, all, KEY_TIMEOUT); // milliseconds
|
||||
}
|
||||
|
||||
private static boolean hasPgpKey(Context context, List<Address> recipients, long timeout) {
|
||||
private static boolean hasPgpKey(Context context, List<Address> recipients, boolean all, long timeout) {
|
||||
if (recipients == null || recipients.size() == 0)
|
||||
return false;
|
||||
|
||||
|
@ -90,7 +90,7 @@ public class PgpHelper {
|
|||
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);
|
||||
return (all ? keyIds.length == recipients.size() : keyIds.length > 0);
|
||||
}
|
||||
} catch (OperationCanceledException ignored) {
|
||||
// Do nothing
|
||||
|
|
|
@ -27,18 +27,19 @@ import javax.mail.Address;
|
|||
import javax.mail.internet.InternetAddress;
|
||||
|
||||
public class SmimeHelper {
|
||||
static boolean hasSmimeKey(Context context, List<Address> recipients) {
|
||||
static boolean hasSmimeKey(Context context, List<Address> recipients, boolean all) {
|
||||
if (recipients == null || recipients.size() == 0)
|
||||
return false;
|
||||
|
||||
int count = 0;
|
||||
DB db = DB.getInstance(context);
|
||||
for (Address address : recipients) {
|
||||
String email = ((InternetAddress) address).getAddress();
|
||||
List<EntityCertificate> certs = db.certificate().getCertificateByEmail(email);
|
||||
if (certs != null && certs.size() > 0)
|
||||
return true;
|
||||
count++;
|
||||
}
|
||||
|
||||
return false;
|
||||
return (all ? count == recipients.size() : count > 0);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue