Browse Source

Improved search for standard folders

main
M66B 6 years ago
parent
commit
4ada1dba5d
3 changed files with 37 additions and 18 deletions
  1. +3
    -3
      app/src/main/java/eu/faircode/email/EntityFolder.java
  2. +33
    -14
      app/src/main/java/eu/faircode/email/FragmentAccount.java
  3. +1
    -1
      app/src/main/java/eu/faircode/email/ServiceSynchronize.java

+ 3
- 3
app/src/main/java/eu/faircode/email/EntityFolder.java View File

@ -54,20 +54,20 @@ public class EntityFolder {
static final String TYPE_SENT = "Sent";
static final String TYPE_USER = "User";
static final List<String> STANDARD_FOLDER_ATTR = Arrays.asList(
static final List<String> SYSTEM_FOLDER_ATTR = Arrays.asList(
"All",
"Drafts",
"Trash",
"Junk",
"Sent"
);
static final List<String> STANDARD_FOLDER_TYPE = Arrays.asList(
static final List<String> 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));


+ 33
- 14
app/src/main/java/eu/faircode/email/FragmentAccount.java View File

@ -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();


+ 1
- 1
app/src/main/java/eu/faircode/email/ServiceSynchronize.java View File

@ -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;
}


Loading…
Cancel
Save