From fce2d3c1db9e73f0207f5555526f1024a4af3f64 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 12 Sep 2019 17:44:36 +0200 Subject: [PATCH] Delete junk contacts --- app/src/main/java/eu/faircode/email/Core.java | 11 +++++++++++ app/src/main/java/eu/faircode/email/DaoContact.java | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 232037f629..299a9110b9 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -653,6 +653,17 @@ class Core { } ifolder.expunge(); } + + // Delete junk contacts + if (EntityFolder.JUNK.equals(target.type)) { + Address[] recipients = (message.reply != null ? message.reply : message.from); + if (recipients != null) + for (Address recipient : recipients) { + String email = ((InternetAddress) recipient).getAddress(); + int count = db.contact().deleteContact(target.account, EntityContact.TYPE_FROM, email); + Log.i("Deleted contact email=" + email + " count=" + count); + } + } } private static void onDelete(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, IMAPFolder ifolder) throws MessagingException { diff --git a/app/src/main/java/eu/faircode/email/DaoContact.java b/app/src/main/java/eu/faircode/email/DaoContact.java index fadeb099fb..aa42f895ff 100644 --- a/app/src/main/java/eu/faircode/email/DaoContact.java +++ b/app/src/main/java/eu/faircode/email/DaoContact.java @@ -79,6 +79,12 @@ public interface DaoContact { @Query("DELETE FROM contact WHERE id = :id") int deleteContact(long id); + @Query("DELETE FROM contact" + + " WHERE account = :account" + + " AND type = :type" + + " AND email = :email") + int deleteContact(long account, int type, String email); + @Query("UPDATE contact SET state = :state WHERE id = :id") int setContactState(long id, int state);