mirror of https://github.com/M66B/FairEmail.git
Refactoring
This commit is contained in:
parent
60ad445c6a
commit
8bef85df9e
|
@ -105,7 +105,7 @@ public class EntityFolder implements Serializable {
|
|||
static final String USER = "User";
|
||||
|
||||
// https://www.iana.org/assignments/imap-mailbox-name-attributes/imap-mailbox-name-attributes.xhtml
|
||||
static final List<String> SYSTEM_FOLDER_ATTR = Arrays.asList(
|
||||
private static final List<String> SYSTEM_FOLDER_ATTR = Arrays.asList(
|
||||
"All",
|
||||
"Archive",
|
||||
"Drafts",
|
||||
|
@ -115,7 +115,7 @@ public class EntityFolder implements Serializable {
|
|||
"Important",
|
||||
"Flagged"
|
||||
);
|
||||
static final List<String> SYSTEM_FOLDER_TYPE = Arrays.asList(
|
||||
private static final List<String> SYSTEM_FOLDER_TYPE = Arrays.asList(
|
||||
ARCHIVE,
|
||||
ARCHIVE,
|
||||
DRAFTS,
|
||||
|
@ -184,6 +184,25 @@ public class EntityFolder implements Serializable {
|
|||
return DRAFTS.equals(type) || OUTBOX.equals(type) || SENT.equals(type);
|
||||
}
|
||||
|
||||
static String getType(String[] attrs, String fullName) {
|
||||
for (String attr : attrs) {
|
||||
if ("\\Noselect".equals(attr) || "\\NonExistent".equals(attr))
|
||||
return null;
|
||||
|
||||
if (attr.startsWith("\\")) {
|
||||
int index = SYSTEM_FOLDER_ATTR.indexOf(attr.substring(1));
|
||||
if (index >= 0)
|
||||
return SYSTEM_FOLDER_TYPE.get(index);
|
||||
}
|
||||
}
|
||||
|
||||
// https://tools.ietf.org/html/rfc3501#section-5.1
|
||||
if ("INBOX".equals(fullName.toUpperCase()))
|
||||
return INBOX;
|
||||
|
||||
return USER;
|
||||
}
|
||||
|
||||
static int getLevel(Character separator, String name) {
|
||||
int level = 0;
|
||||
if (separator != null) {
|
||||
|
|
|
@ -582,30 +582,19 @@ public class FragmentAccount extends FragmentBase {
|
|||
|
||||
for (Folder ifolder : istore.getDefaultFolder().list("*")) {
|
||||
// Check folder attributes
|
||||
String type = null;
|
||||
boolean selectable = true;
|
||||
String fullName = ifolder.getFullName();
|
||||
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
|
||||
Log.i(ifolder.getFullName() + " attrs=" + TextUtils.join(" ", attrs));
|
||||
for (String attr : attrs) {
|
||||
if ("\\Noselect".equals(attr) || "\\NonExistent".equals(attr))
|
||||
selectable = false;
|
||||
if (attr.startsWith("\\")) {
|
||||
int index = EntityFolder.SYSTEM_FOLDER_ATTR.indexOf(attr.substring(1));
|
||||
if (index >= 0) {
|
||||
type = EntityFolder.SYSTEM_FOLDER_TYPE.get(index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.i(fullName + " attrs=" + TextUtils.join(" ", attrs));
|
||||
String type = EntityFolder.getType(attrs, fullName);
|
||||
|
||||
if (selectable) {
|
||||
if (type != null) {
|
||||
// Create entry
|
||||
EntityFolder folder = db.folder().getFolderByName(id, ifolder.getFullName());
|
||||
EntityFolder folder = db.folder().getFolderByName(id, fullName);
|
||||
if (folder == null) {
|
||||
int sync = EntityFolder.SYSTEM_FOLDER_SYNC.indexOf(type);
|
||||
folder = new EntityFolder();
|
||||
folder.name = ifolder.getFullName();
|
||||
folder.type = (type == null ? EntityFolder.USER : type);
|
||||
folder.name = fullName;
|
||||
folder.type = type;
|
||||
folder.synchronize = (sync >= 0);
|
||||
folder.download = (sync < 0 ? true : EntityFolder.SYSTEM_FOLDER_DOWNLOAD.get(sync));
|
||||
folder.sync_days = EntityFolder.DEFAULT_SYNC;
|
||||
|
@ -613,7 +602,7 @@ public class FragmentAccount extends FragmentBase {
|
|||
}
|
||||
result.folders.add(folder);
|
||||
|
||||
if (type == null) {
|
||||
if (EntityFolder.USER.equals(type)) {
|
||||
if (folder.name.toLowerCase().contains("archive"))
|
||||
altArchive = folder;
|
||||
if (folder.name.toLowerCase().contains("draft"))
|
||||
|
|
|
@ -226,26 +226,16 @@ public class FragmentQuickSetup extends FragmentBase {
|
|||
|
||||
boolean drafts = false;
|
||||
for (Folder ifolder : istore.getDefaultFolder().list("*")) {
|
||||
String type = null;
|
||||
boolean selectable = true;
|
||||
String fullName = ifolder.getFullName();
|
||||
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
|
||||
Log.i(ifolder.getFullName() + " attrs=" + TextUtils.join(" ", attrs));
|
||||
for (String attr : attrs) {
|
||||
if ("\\Noselect".equals(attr) || "\\NonExistent".equals(attr))
|
||||
selectable = false;
|
||||
if (attr.startsWith("\\")) {
|
||||
int index = EntityFolder.SYSTEM_FOLDER_ATTR.indexOf(attr.substring(1));
|
||||
if (index >= 0) {
|
||||
type = EntityFolder.SYSTEM_FOLDER_TYPE.get(index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
String type = EntityFolder.getType(attrs, fullName);
|
||||
|
||||
if (selectable && type != null) {
|
||||
Log.i(fullName + " attrs=" + TextUtils.join(" ", attrs) + " type=" + type);
|
||||
|
||||
if (type != null) {
|
||||
int sync = EntityFolder.SYSTEM_FOLDER_SYNC.indexOf(type);
|
||||
EntityFolder folder = new EntityFolder();
|
||||
folder.name = ifolder.getFullName();
|
||||
folder.name = fullName;
|
||||
folder.type = type;
|
||||
folder.level = EntityFolder.getLevel(separator, folder.name);
|
||||
folder.synchronize = (sync >= 0);
|
||||
|
|
|
@ -2195,30 +2195,13 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
|
||||
for (Folder ifolder : ifolders) {
|
||||
String fullName = ifolder.getFullName();
|
||||
|
||||
String type = null;
|
||||
boolean selectable = true;
|
||||
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
|
||||
String type = EntityFolder.getType(attrs, fullName);
|
||||
|
||||
EntityLog.log(this, account.name + ":" + fullName +
|
||||
" attrs=" + TextUtils.join(" ", attrs));
|
||||
for (String attr : attrs) {
|
||||
if ("\\Noselect".equals(attr) || "\\NonExistent".equals(attr))
|
||||
selectable = false;
|
||||
" attrs=" + TextUtils.join(" ", attrs) + " type=" + type);
|
||||
|
||||
if (attr.startsWith("\\")) {
|
||||
int index = EntityFolder.SYSTEM_FOLDER_ATTR.indexOf(attr.substring(1));
|
||||
if (index >= 0) {
|
||||
type = EntityFolder.SYSTEM_FOLDER_TYPE.get(index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://tools.ietf.org/html/rfc3501#section-5.1
|
||||
if ("INBOX".equals(fullName.toUpperCase()))
|
||||
type = EntityFolder.INBOX;
|
||||
|
||||
if (selectable) {
|
||||
if (type != null) {
|
||||
names.remove(fullName);
|
||||
|
||||
int level = EntityFolder.getLevel(separator, fullName);
|
||||
|
@ -2232,7 +2215,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
folder.account = account.id;
|
||||
folder.name = fullName;
|
||||
folder.display = display;
|
||||
folder.type = (type == null ? EntityFolder.USER : type);
|
||||
folder.type = EntityFolder.USER;
|
||||
folder.level = level;
|
||||
folder.synchronize = false;
|
||||
folder.poll = ("imap.gmail.com".equals(account.host));
|
||||
|
|
Loading…
Reference in New Issue