From 4ada1dba5d4ec15230dab4ff93f7cc6bc308357f Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 3 Aug 2018 17:09:12 +0000 Subject: [PATCH] Improved search for standard folders --- .../java/eu/faircode/email/EntityFolder.java | 6 +-- .../eu/faircode/email/FragmentAccount.java | 47 +++++++++++++------ .../eu/faircode/email/ServiceSynchronize.java | 2 +- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EntityFolder.java b/app/src/main/java/eu/faircode/email/EntityFolder.java index 7f70b745..587d3c45 100644 --- a/app/src/main/java/eu/faircode/email/EntityFolder.java +++ b/app/src/main/java/eu/faircode/email/EntityFolder.java @@ -54,20 +54,20 @@ public class EntityFolder { static final String TYPE_SENT = "Sent"; static final String TYPE_USER = "User"; - static final List STANDARD_FOLDER_ATTR = Arrays.asList( + static final List SYSTEM_FOLDER_ATTR = Arrays.asList( "All", "Drafts", "Trash", "Junk", "Sent" ); - static final List STANDARD_FOLDER_TYPE = Arrays.asList( + static final List SYSTEM_FOLDER_TYPE = Arrays.asList( TYPE_ARCHIVE, TYPE_DRAFTS, TYPE_TRASH, TYPE_JUNK, TYPE_SENT - ); // Must match STANDARD_FOLDER_ATTR + ); // Must match SYSTEM_FOLDER_ATTR static boolean isOutgoing(String type) { return (TYPE_OUTBOX.equals(type) || TYPE_DRAFTS.equals(type) || TYPE_SENT.equals(type)); diff --git a/app/src/main/java/eu/faircode/email/FragmentAccount.java b/app/src/main/java/eu/faircode/email/FragmentAccount.java index e07dcc2a..67f76711 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccount.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccount.java @@ -218,30 +218,49 @@ public class FragmentAccount extends Fragment { if (!istore.hasCapability("IDLE")) throw new MessagingException(getContext().getString(R.string.title_no_idle)); + // Find system folders boolean drafts = false; for (Folder ifolder : istore.getDefaultFolder().list("*")) { + String type = null; + + // First check folder attributes String[] attrs = ((IMAPFolder) ifolder).getAttributes(); for (String attr : attrs) { if (attr.startsWith("\\")) { - int index = EntityFolder.STANDARD_FOLDER_ATTR.indexOf(attr.substring(1)); + int index = EntityFolder.SYSTEM_FOLDER_ATTR.indexOf(attr.substring(1)); if (index >= 0) { - EntityFolder folder = new EntityFolder(); - folder.name = ifolder.getFullName(); - folder.type = EntityFolder.STANDARD_FOLDER_TYPE.get(index); - folder.synchronize = standard_sync.contains(folder.type); - folder.after = DEFAULT_STANDARD_SYNC; - folders.add(folder); - - Log.i(Helper.TAG, "Standard folder=" + folder.name + - " type=" + folder.type + " attr=" + TextUtils.join(",", attrs)); - - if (EntityFolder.TYPE_DRAFTS.equals(folder.type)) - drafts = true; - + type = EntityFolder.SYSTEM_FOLDER_TYPE.get(index); break; } } } + + // Next check folder full name + if (type == null) { + String fullname = ifolder.getFullName(); + for (String attr : EntityFolder.SYSTEM_FOLDER_ATTR) + if (attr.equals(fullname)) { + int index = EntityFolder.SYSTEM_FOLDER_ATTR.indexOf(attr); + type = EntityFolder.SYSTEM_FOLDER_TYPE.get(index); + break; + } + } + + if (type != null) { + EntityFolder folder = new EntityFolder(); + folder.name = ifolder.getFullName(); + folder.type = type; + folder.synchronize = standard_sync.contains(folder.type); + folder.after = DEFAULT_STANDARD_SYNC; + folders.add(folder); + + Log.i(Helper.TAG, account.name + + " system=" + folder.name + + " type=" + folder.type + " attr=" + TextUtils.join(",", attrs)); + + if (EntityFolder.TYPE_DRAFTS.equals(folder.type)) + drafts = true; + } } if (!drafts) { EntityFolder folder = new EntityFolder(); diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 904e47c9..b34bb24c 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -712,7 +712,7 @@ public class ServiceSynchronize extends LifecycleService { break; } if (attr.startsWith("\\")) - if (EntityFolder.STANDARD_FOLDER_ATTR.contains(attr.substring(1))) { + if (EntityFolder.SYSTEM_FOLDER_ATTR.contains(attr.substring(1))) { candidate = false; break; }