Fixed folder level

pull/146/head
M66B 6 years ago
parent fb3ece2bf7
commit 721cc115f5

@ -149,6 +149,15 @@ public class EntityFolder implements Serializable {
return DRAFTS.equals(type) || OUTBOX.equals(type) || SENT.equals(type);
}
static int getLevel(Character separator, String name) {
int level = 0;
if (separator != null)
for (int i = 0; i < name.length(); i++)
if (name.charAt(i) == separator)
level++;
return level;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof EntityFolder) {
@ -195,6 +204,8 @@ public class EntityFolder implements Serializable {
if (json.has("level"))
folder.level = json.getInt("level");
else
folder.level = 0;
folder.synchronize = json.getBoolean("synchronize");

@ -666,6 +666,7 @@ public class FragmentAccount extends FragmentEx {
color = null;
long now = new Date().getTime();
Character separator = null;
DB db = DB.getInstance(context);
EntityAccount account = db.account().getAccount(id);
@ -677,8 +678,10 @@ public class FragmentAccount extends FragmentEx {
// Check IMAP server
if (check) {
Session isession = Session.getInstance(MessageHelper.getSessionProperties(auth_type, insecure), null);
Properties props = MessageHelper.getSessionProperties(auth_type, insecure);
Session isession = Session.getInstance(props, null);
isession.setDebug(true);
IMAPStore istore = null;
try {
istore = (IMAPStore) isession.getStore(starttls ? "imap" : "imaps");
@ -692,6 +695,7 @@ public class FragmentAccount extends FragmentEx {
throw ex;
}
} finally {
separator = istore.getDefaultFolder().getSeparator();
if (istore != null)
istore.close();
}
@ -780,13 +784,16 @@ public class FragmentAccount extends FragmentEx {
db.folder().setFoldersUser(account.id);
for (EntityFolder folder : folders) {
folder.level = EntityFolder.getLevel(separator, folder.name);
EntityFolder existing = db.folder().getFolderByName(account.id, folder.name);
if (existing == null) {
folder.account = account.id;
Log.i(Helper.TAG, "Creating folder=" + folder.name + " (" + folder.type + ")");
folder.id = db.folder().insertFolder(folder);
} else
} else {
db.folder().setFolderType(existing.id, folder.type);
db.folder().setFolderLevel(existing.id, folder.level);
}
}
db.setTransactionSuccessful();

@ -148,6 +148,7 @@ public class FragmentFolder extends FragmentEx {
Session isession = Session.getInstance(props, null);
istore = (IMAPStore) isession.getStore(account.starttls ? "imap" : "imaps");
Helper.connect(context, istore, account);
char separator = istore.getDefaultFolder().getSeparator();
if (folder == null) {
Log.i(Helper.TAG, "Creating folder=" + name);
@ -160,6 +161,7 @@ public class FragmentFolder extends FragmentEx {
EntityFolder create = new EntityFolder();
create.account = aid;
create.name = name;
create.level = EntityFolder.getLevel(separator, name);
create.display = display;
create.hide = hide;
create.type = EntityFolder.USER;

@ -313,6 +313,7 @@ public class FragmentSetup extends FragmentEx {
outbox = new EntityFolder();
outbox.name = "OUTBOX";
outbox.type = EntityFolder.OUTBOX;
outbox.level = 0;
outbox.synchronize = false;
outbox.sync_days = 0;
outbox.keep_days = 0;

@ -1806,27 +1806,22 @@ public class ServiceSynchronize extends LifecycleService {
if (selectable) {
String fullName = ifolder.getFullName();
int level = 0;
for (int i = 0; i < fullName.length(); i++)
if (fullName.charAt(i) == separator)
level++;
int level = EntityFolder.getLevel(separator, fullName);
EntityFolder folder = db.folder().getFolderByName(account.id, fullName);
if (folder == null) {
folder = new EntityFolder();
folder.account = account.id;
folder.name = ifolder.getFullName();
folder.name = fullName;
folder.type = EntityFolder.USER;
folder.level = level;
folder.synchronize = false;
folder.sync_days = EntityFolder.DEFAULT_USER_SYNC;
folder.keep_days = EntityFolder.DEFAULT_USER_SYNC;
db.folder().insertFolder(folder);
Log.i(Helper.TAG, folder.name + " added level=" + level);
Log.i(Helper.TAG, folder.name + " added");
} else {
names.remove(folder.name);
Log.i(Helper.TAG, folder.name + " exists level=" + level);
Log.i(Helper.TAG, folder.name + " exists");
db.folder().setFolderLevel(folder.id, level);
}
}

Loading…
Cancel
Save