Case insensitive email lookup

pull/182/head
M66B 5 years ago
parent be60e5f07a
commit ad75914803

@ -155,11 +155,12 @@ public class ContactInfo {
boolean identicons = prefs.getBoolean("identicons", false); boolean identicons = prefs.getBoolean("identicons", false);
boolean circular = prefs.getBoolean("circular", true); boolean circular = prefs.getBoolean("circular", true);
if (Helper.hasPermission(context, Manifest.permission.READ_CONTACTS)) { if (!TextUtils.isEmpty(info.email) &&
Helper.hasPermission(context, Manifest.permission.READ_CONTACTS)) {
ContentResolver resolver = context.getContentResolver(); ContentResolver resolver = context.getContentResolver();
Uri uri = Uri.withAppendedPath( Uri uri = Uri.withAppendedPath(
ContactsContract.CommonDataKinds.Email.CONTENT_LOOKUP_URI, ContactsContract.CommonDataKinds.Email.CONTENT_LOOKUP_URI,
Uri.encode(address.getAddress())); Uri.encode(info.email.toLowerCase(Locale.ROOT)));
try (Cursor cursor = resolver.query(uri, try (Cursor cursor = resolver.query(uri,
new String[]{ new String[]{
ContactsContract.CommonDataKinds.Photo.CONTACT_ID, ContactsContract.CommonDataKinds.Photo.CONTACT_ID,
@ -195,8 +196,8 @@ public class ContactInfo {
} }
if (info.bitmap == null) { if (info.bitmap == null) {
if (gravatars) { if (gravatars && !TextUtils.isEmpty(info.email)) {
String gkey = address.getAddress().toLowerCase(Locale.ROOT); String gkey = info.email.toLowerCase(Locale.ROOT);
boolean lookup; boolean lookup;
synchronized (emailGravatar) { synchronized (emailGravatar) {
Avatar avatar = emailGravatar.get(gkey); Avatar avatar = emailGravatar.get(gkey);
@ -245,14 +246,14 @@ public class ContactInfo {
boolean identicon = false; boolean identicon = false;
if (info.bitmap == null) { if (info.bitmap == null) {
int dp = Helper.dp2pixels(context, 96); int dp = Helper.dp2pixels(context, 96);
if (generated) { if (generated && !TextUtils.isEmpty(info.email)) {
if (identicons) { if (identicons) {
identicon = true; identicon = true;
info.bitmap = ImageHelper.generateIdenticon( info.bitmap = ImageHelper.generateIdenticon(
address.getAddress(), dp, 5, context); info.email, dp, 5, context);
} else } else
info.bitmap = ImageHelper.generateLetterIcon( info.bitmap = ImageHelper.generateLetterIcon(
address.getAddress(), address.getPersonal(), dp, context); info.email, address.getPersonal(), dp, context);
} }
} }
@ -262,7 +263,7 @@ public class ContactInfo {
if (info.displayName == null) if (info.displayName == null)
info.displayName = address.getPersonal(); info.displayName = address.getPersonal();
if (!info.known) { if (!info.known && !TextUtils.isEmpty(info.email)) {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityContact contact = db.contact().getContact(account, EntityContact.TYPE_TO, info.email); EntityContact contact = db.contact().getContact(account, EntityContact.TYPE_TO, info.email);
info.known = (contact != null); info.known = (contact != null);
@ -320,8 +321,11 @@ public class ContactInfo {
for (Address from : addresses) { for (Address from : addresses) {
String email = ((InternetAddress) from).getAddress(); String email = ((InternetAddress) from).getAddress();
if (emailLookup.containsKey(email)) if (!TextUtils.isEmpty(email)) {
return emailLookup.get(email).uri; Lookup lookup = emailLookup.get(email.toLowerCase(Locale.ROOT));
if (lookup != null)
return lookup.uri;
}
} }
return null; return null;
@ -336,10 +340,10 @@ public class ContactInfo {
InternetAddress address = (InternetAddress) addresses[i]; InternetAddress address = (InternetAddress) addresses[i];
String email = address.getAddress(); String email = address.getAddress();
String personal = address.getPersonal(); String personal = address.getPersonal();
if (!TextUtils.isEmpty(email) && emailLookup.containsKey(email)) { if (!TextUtils.isEmpty(email)) {
Lookup lookup = emailLookup.get(email); Lookup lookup = emailLookup.get(email.toLowerCase(Locale.ROOT));
if (TextUtils.isEmpty(personal) || if (lookup != null &&
(prefer_contact && !personal.equals(lookup.displayName))) (TextUtils.isEmpty(personal) || prefer_contact))
personal = lookup.displayName; personal = lookup.displayName;
} }
try { try {
@ -378,7 +382,7 @@ public class ContactInfo {
Lookup lookup = new Lookup(); Lookup lookup = new Lookup();
lookup.uri = ContactsContract.Contacts.getLookupUri(contactId, lookupKey); lookup.uri = ContactsContract.Contacts.getLookupUri(contactId, lookupKey);
lookup.displayName = displayName; lookup.displayName = displayName;
all.put(email, lookup); all.put(email.toLowerCase(Locale.ROOT), lookup);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);

Loading…
Cancel
Save