From dc37308af022a3a1397d7d2ad01644f836b9d629 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 4 Mar 2022 13:35:11 +0100 Subject: [PATCH] Refactoring --- .../eu/faircode/email/FragmentCompose.java | 19 +------- .../java/eu/faircode/email/SmimeHelper.java | 44 +++++++++++++++++++ 2 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 app/src/main/java/eu/faircode/email/SmimeHelper.java diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 0c56bcb572..f46dd094ca 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -4616,7 +4616,7 @@ public class FragmentCompose extends FragmentBase { EntityMessage.SMIME_SIGNENCRYPT.equals(ref.ui_encrypt)) { if (ActivityBilling.isPro(context) && selected.sign_key_alias != null && - hasSmimeKey(context, recipients)) + SmimeHelper.hasSmimeKey(context, recipients)) data.draft.ui_encrypt = ref.ui_encrypt; } } @@ -5847,7 +5847,7 @@ public class FragmentCompose extends FragmentBase { (draft.ui_encrypt == null || EntityMessage.ENCRYPT_NONE.equals(draft.ui_encrypt))) { args.putBoolean("remind_pgp", PgpHelper.hasPgpKey(context, recipients, MAX_PGP_BIND_DELAY)); - args.putBoolean("remind_smime", hasSmimeKey(context, recipients)); + args.putBoolean("remind_smime", SmimeHelper.hasSmimeKey(context, recipients)); } if (TextUtils.isEmpty(draft.subject)) @@ -6502,21 +6502,6 @@ public class FragmentCompose extends FragmentBase { return -1; } - private boolean hasSmimeKey(Context context, List
recipients) { - if (recipients == null || recipients.size() == 0) - return false; - - DB db = DB.getInstance(context); - for (Address address : recipients) { - String email = ((InternetAddress) address).getAddress(); - List certs = db.certificate().getCertificateByEmail(email); - if (certs != null && certs.size() > 0) - return true; - } - - return false; - } - private AdapterView.OnItemSelectedListener identitySelected = new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { diff --git a/app/src/main/java/eu/faircode/email/SmimeHelper.java b/app/src/main/java/eu/faircode/email/SmimeHelper.java new file mode 100644 index 0000000000..bf5a094dd2 --- /dev/null +++ b/app/src/main/java/eu/faircode/email/SmimeHelper.java @@ -0,0 +1,44 @@ +package eu.faircode.email; + +/* + This file is part of FairEmail. + + FairEmail is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + FairEmail is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FairEmail. If not, see . + + Copyright 2018-2022 by Marcel Bokhorst (M66B) +*/ + +import android.content.Context; + +import java.util.List; + +import javax.mail.Address; +import javax.mail.internet.InternetAddress; + +public class SmimeHelper { + static boolean hasSmimeKey(Context context, List
recipients) { + if (recipients == null || recipients.size() == 0) + return false; + + DB db = DB.getInstance(context); + for (Address address : recipients) { + String email = ((InternetAddress) address).getAddress(); + List certs = db.certificate().getCertificateByEmail(email); + if (certs != null && certs.size() > 0) + return true; + } + + return false; + } +}