From 8a0ac170c673c960584d863bc6d958d08abafe9e Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 18 Mar 2019 09:52:20 +0000 Subject: [PATCH] Update local contacts after account creation only This is to prevent double counts after importing settings --- app/src/main/java/eu/faircode/email/Core.java | 9 ++++++--- .../main/java/eu/faircode/email/ServiceSynchronize.java | 6 ++++-- app/src/main/java/eu/faircode/email/ViewModelBrowse.java | 7 +++++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index f6940f90b3..dc52f7054d 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -985,7 +985,8 @@ class Core { db.beginTransaction(); EntityMessage message = synchronizeMessage( context, - folder, ifolder, (IMAPMessage) isub[j], + account, folder, + ifolder, (IMAPMessage) isub[j], false, rules); ids[from + j] = message.id; @@ -1075,7 +1076,8 @@ class Core { static EntityMessage synchronizeMessage( Context context, - EntityFolder folder, IMAPFolder ifolder, IMAPMessage imessage, + EntityAccount account, EntityFolder folder, + IMAPFolder ifolder, IMAPMessage imessage, boolean browsed, List rules) throws MessagingException, IOException { long uid = ifolder.getUID(imessage); @@ -1239,7 +1241,8 @@ class Core { attachment.id = db.attachment().insertAttachment(attachment); } - if (!EntityFolder.ARCHIVE.equals(folder.type) && + if (message.received > account.created && + !EntityFolder.ARCHIVE.equals(folder.type) && !EntityFolder.TRASH.equals(folder.type) && !EntityFolder.JUNK.equals(folder.type)) { int type = (folder.isOutgoing() ? EntityContact.TYPE_TO : EntityContact.TYPE_FROM); diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 675e1519fc..85028e376c 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -668,7 +668,8 @@ public class ServiceSynchronize extends LifecycleService { db.beginTransaction(); message = Core.synchronizeMessage( ServiceSynchronize.this, - folder, (IMAPFolder) ifolder, (IMAPMessage) imessage, + account, folder, + (IMAPFolder) ifolder, (IMAPMessage) imessage, false, db.rule().getEnabledRules(folder.id)); db.setTransactionSuccessful(); @@ -757,7 +758,8 @@ public class ServiceSynchronize extends LifecycleService { db.beginTransaction(); message = Core.synchronizeMessage( ServiceSynchronize.this, - folder, (IMAPFolder) ifolder, (IMAPMessage) e.getMessage(), + account, folder, + (IMAPFolder) ifolder, (IMAPMessage) e.getMessage(), false, db.rule().getEnabledRules(folder.id)); db.setTransactionSuccessful(); diff --git a/app/src/main/java/eu/faircode/email/ViewModelBrowse.java b/app/src/main/java/eu/faircode/email/ViewModelBrowse.java index bd42e8303d..8f9b17740b 100644 --- a/app/src/main/java/eu/faircode/email/ViewModelBrowse.java +++ b/app/src/main/java/eu/faircode/email/ViewModelBrowse.java @@ -151,9 +151,11 @@ public class ViewModelBrowse extends ViewModel { final EntityFolder folder = db.folder().getBrowsableFolder(state.fid, state.search != null); if (folder == null) return local; + EntityAccount account = db.account().getAccount(folder.account); + if (account == null) + return local; if (state.imessages == null) { - EntityAccount account = db.account().getAccount(folder.account); try { // Check connectivity @@ -323,7 +325,8 @@ public class ViewModelBrowse extends ViewModel { EntityMessage message = db.message().getMessageByUid(folder.id, uid); if (message == null) { message = Core.synchronizeMessage(state.context, - folder, state.ifolder, (IMAPMessage) isub[j], + account, folder, + state.ifolder, (IMAPMessage) isub[j], true, new ArrayList()); remote++;