From adad5602f05defdd807babab37d7df56f332e00c Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 21 Jul 2019 10:31:34 +0200 Subject: [PATCH] Used untrusted group instead relation --- FAQ.md | 2 +- .../java/eu/faircode/email/ContactInfo.java | 38 ++++++++++++++----- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/FAQ.md b/FAQ.md index ee95c70b44..681f553882 100644 --- a/FAQ.md +++ b/FAQ.md @@ -1962,7 +1962,7 @@ Reverted [commit](https://github.com/M66B/FairEmail/commit/2c80c25b8aa75af2287f4 You can show images in messages from trusted senders by default by enabled the display setting *Automatically show images for known contacts*. People in the Android contacts list are considered to be known and trusted, -unless the contact relation is set to '*Untrusted*' (case insensitive; the relation type, for example parent, child, friend, etc does not matter). +unless the contact is in the group / has the label '*Untrusted*' (case insensitive).
diff --git a/app/src/main/java/eu/faircode/email/ContactInfo.java b/app/src/main/java/eu/faircode/email/ContactInfo.java index 0f1b4ee935..e55a4cc592 100644 --- a/app/src/main/java/eu/faircode/email/ContactInfo.java +++ b/app/src/main/java/eu/faircode/email/ContactInfo.java @@ -253,6 +253,19 @@ public class ContactInfo { if (Helper.hasPermission(context, Manifest.permission.READ_CONTACTS)) { ContentResolver resolver = context.getContentResolver(); + + long untrusted = -1; + try (Cursor cursor = resolver.query( + ContactsContract.Groups.CONTENT_URI, + new String[]{ContactsContract.Groups._ID}, + ContactsContract.Groups.TITLE + " = ? COLLATE NOCASE", + new String[]{"untrusted"}, + null)) { + if (cursor != null && cursor.moveToNext()) + untrusted = cursor.getLong(0); + } + Log.i("Untrusted group=" + untrusted); + try (Cursor cursor = resolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, new String[]{ ContactsContract.CommonDataKinds.Photo.CONTACT_ID, @@ -266,17 +279,22 @@ public class ContactInfo { String lookupKey = cursor.getString(1); String email = cursor.getString(2); - Cursor relation = resolver.query( + try (Cursor group = resolver.query( ContactsContract.Data.CONTENT_URI, - new String[]{ContactsContract.CommonDataKinds.Relation.NAME}, - ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.Relation.CONTENT_ITEM_TYPE + "'" + - " AND " + ContactsContract.CommonDataKinds.Relation.NAME + " = 'UNTRUSTED' COLLATE NOCASE" + - " AND " + ContactsContract.CommonDataKinds.Relation.CONTACT_ID + " = ?", - new String[]{Long.toString(contactId)}, - null); - if (relation != null && relation.moveToNext()) { - Log.i("Contact email=" + email + " relation=" + relation.getString(0)); - continue; + new String[]{ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID}, + ContactsContract.Data.MIMETYPE + " = ?" + + " AND " + ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID + "= ?" + + " AND " + ContactsContract.CommonDataKinds.GroupMembership.CONTACT_ID + " = ?", + new String[]{ + ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE, + Long.toString(untrusted), + Long.toString(contactId) + }, + null)) { + if (group != null && group.moveToNext()) { + Log.i("Contact email=" + email + " untrusted"); + continue; + } } Uri uri = ContactsContract.Contacts.getLookupUri(contactId, lookupKey);