Auto identity for mailto

This commit is contained in:
M66B 2022-04-30 07:58:31 +02:00
parent ba40162fd3
commit 1d66c3426b
1 changed files with 24 additions and 0 deletions

View File

@ -4510,6 +4510,9 @@ public class FragmentCompose extends FragmentBase {
boolean receipt_default = prefs.getBoolean("receipt_default", false); boolean receipt_default = prefs.getBoolean("receipt_default", false);
boolean write_below = prefs.getBoolean("write_below", false); boolean write_below = prefs.getBoolean("write_below", false);
boolean save_drafts = prefs.getBoolean("save_drafts", true); boolean save_drafts = prefs.getBoolean("save_drafts", true);
boolean auto_identity = prefs.getBoolean("auto_identity", true);
boolean suggest_sent = prefs.getBoolean("suggest_sent", true);
boolean suggest_received = prefs.getBoolean("suggest_received", false);
Log.i("Load draft action=" + action + " id=" + id + " reference=" + reference); Log.i("Load draft action=" + action + " id=" + id + " reference=" + reference);
@ -4611,6 +4614,27 @@ public class FragmentCompose extends FragmentBase {
} }
} }
if (selected == null && auto_identity)
try {
Address[] tos = MessageHelper.parseAddresses(context, to);
if (tos != null && tos.length > 0) {
String email = ((InternetAddress) tos[0]).getAddress();
List<Integer> types = new ArrayList<>();
if (suggest_sent)
types.add(EntityContact.TYPE_TO);
if (suggest_received)
types.add(EntityContact.TYPE_FROM);
List<Long> identities = db.contact().getIdentities(email, types);
if (identities != null && identities.size() == 1) {
EntityIdentity identity = db.identity().getIdentity(identities.get(0));
if (identity != null)
selected = identity;
}
}
} catch (AddressException ex) {
Log.i(ex);
}
if (selected == null) if (selected == null)
for (EntityIdentity identity : data.identities) for (EntityIdentity identity : data.identities)
if (identity.account.equals(aid) && identity.primary) { if (identity.account.equals(aid) && identity.primary) {