From 5182b28548999b531f0cc82bf6f0b436180d1f88 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 9 Jan 2023 22:46:42 +0100 Subject: [PATCH] Skip auto add groups --- .../java/eu/faircode/email/EntityRule.java | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EntityRule.java b/app/src/main/java/eu/faircode/email/EntityRule.java index a8ac5cd811..fa0faf8175 100644 --- a/app/src/main/java/eu/faircode/email/EntityRule.java +++ b/app/src/main/java/eu/faircode/email/EntityRule.java @@ -705,28 +705,36 @@ public class EntityRule { }, null)) { Log.i(this.name + " membership=" + membership.getCount()); - if (membership.getCount() != 1) - return false; - if (!membership.moveToNext()) - return false; - - long groupId = membership.getLong(0); - Log.i(this.name + " groupId=" + groupId); - - try (Cursor groups = resolver.query(ContactsContract.Groups.CONTENT_URI, - new String[]{ContactsContract.Groups.TITLE}, - ContactsContract.Groups._ID + " = ?", - new String[]{Long.toString(groupId)}, - ContactsContract.Groups.TITLE)) { - Log.i(this.name + " groups=" + groups.getCount()); - if (!groups.moveToNext()) - return false; - - String groupName = groups.getString(0); - Log.i(this.name + " groupName=" + groupName); - create = create.replace("$group$", groupName); + int count = 0; + String groupName = null; + while (membership.moveToNext()) { + long groupId = membership.getLong(0); + try (Cursor groups = resolver.query(ContactsContract.Groups.CONTENT_URI, + new String[]{ + ContactsContract.Groups.TITLE, + ContactsContract.Groups.AUTO_ADD, + ContactsContract.Groups.GROUP_VISIBLE, + }, + ContactsContract.Groups._ID + " = ?", + new String[]{Long.toString(groupId)}, + ContactsContract.Groups.TITLE)) { + while (groups.moveToNext()) { + groupName = groups.getString(0); + int auto_add = groups.getInt(1); + int visible = groups.getInt(2); + if (auto_add == 0) + count++; + Log.i(this.name + " membership groupId=" + groupId + + " name=" + groupName + " auto_add=" + auto_add + " visible=" + visible); + } + } } + Log.i(this.name + " name=" + groupName + " count=" + count); + if (count == 1) + create = create.replace("$group$", groupName); + else + return false; } } }