Improved search for standard folders

This commit is contained in:
M66B 2018-08-03 17:09:12 +00:00
parent cf73512897
commit 4ada1dba5d
3 changed files with 37 additions and 18 deletions

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

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

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