From 0da464588aedaacd0d2812a2f457b493c5476fac Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 26 May 2019 14:07:10 +0200 Subject: [PATCH] Faster folder sync --- app/src/main/java/eu/faircode/email/Core.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index b34845ed7d..679994a255 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -798,21 +798,37 @@ class Core { EntityLog.log(context, account.name + " folder separator=" + separator); // Get remote folders + long start = new Date().getTime(); Folder[] ifolders = (subscribed_only ? defaultFolder.listSubscribed("*") : defaultFolder.list("*")); + + // Get subscribed folders + List subscription = new ArrayList<>(); + try { + Folder[] isubscribed = (subscribed_only ? ifolders : defaultFolder.listSubscribed("*")); + for (Folder ifolder : isubscribed) + subscription.add(ifolder.getFullName()); + } catch (MessagingException ex) { + Log.e(ex); + } + if (subscribed_only && ifolders.length == 0) { Log.i("No subscribed folders"); ifolders = defaultFolder.list("*"); } + long duration = new Date().getTime() - start; - Log.i("Remote folder count=" + ifolders.length + " separator=" + separator); + Log.i("Remote folder count=" + ifolders.length + + " subscribed=" + subscription.size() + + " separator=" + separator + + " fetched in " + duration + " ms"); Map nameFolder = new HashMap<>(); Map> parentFolders = new HashMap<>(); for (Folder ifolder : ifolders) { String fullName = ifolder.getFullName(); - boolean subscribed = ifolder.isSubscribed(); + boolean subscribed = subscription.contains(fullName); String[] attr = ((IMAPFolder) ifolder).getAttributes(); String type = EntityFolder.getType(attr, fullName);