From 971fa5f0ef6bdafb9efeb88cd2d6bffa72f3b95f Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 4 Apr 2019 18:18:13 +0200 Subject: [PATCH] Split local/remote folder sync --- app/src/main/java/eu/faircode/email/Core.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 217d42c27f..af277ed4f8 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -653,10 +653,21 @@ class Core { static void onSynchronizeFolders(Context context, EntityAccount account, Store istore, State state) throws MessagingException { DB db = DB.getInstance(context); try { - db.beginTransaction(); - Log.i("Start sync folders account=" + account.name); + // Get remote folders + Folder defaultFolder = istore.getDefaultFolder(); + char separator = defaultFolder.getSeparator(); + EntityLog.log(context, account.name + " folder separator=" + separator); + + Folder[] ifolders = defaultFolder.list("*"); + Map attrs = new HashMap<>(); + for (Folder ifolder : ifolders) + attrs.put(ifolder, ((IMAPFolder) ifolder).getAttributes()); + Log.i("Remote folder count=" + ifolders.length + " separator=" + separator); + + db.beginTransaction(); + List names = new ArrayList<>(); for (EntityFolder folder : db.folder().getFolders(account.id)) if (folder.tbc != null) { @@ -675,22 +686,15 @@ class Core { names.add(folder.name); Log.i("Local folder count=" + names.size()); - Folder defaultFolder = istore.getDefaultFolder(); - char separator = defaultFolder.getSeparator(); - EntityLog.log(context, account.name + " folder separator=" + separator); - - Folder[] ifolders = defaultFolder.list("*"); - Log.i("Remote folder count=" + ifolders.length + " separator=" + separator); - Map nameFolder = new HashMap<>(); Map> parentFolders = new HashMap<>(); for (Folder ifolder : ifolders) { String fullName = ifolder.getFullName(); - String[] attrs = ((IMAPFolder) ifolder).getAttributes(); - String type = EntityFolder.getType(attrs, fullName); + String[] attr = attrs.get(ifolder); + String type = EntityFolder.getType(attr, fullName); EntityLog.log(context, account.name + ":" + fullName + - " attrs=" + TextUtils.join(" ", attrs) + " type=" + type); + " attrs=" + TextUtils.join(" ", attr) + " type=" + type); if (type != null) { names.remove(fullName);