1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-28 02:37:16 +00:00

Added fail-safe

This commit is contained in:
M66B 2021-08-24 13:30:14 +02:00
parent 5a2c9878cc
commit f393c889ef

View file

@ -2041,47 +2041,51 @@ class Core {
" fetched in " + duration + " ms"); " fetched in " + duration + " ms");
// Check if system folders were renamed // Check if system folders were renamed
for (Folder ifolder : ifolders) { try {
String fullName = ifolder.getFullName(); for (Folder ifolder : ifolders) {
if (TextUtils.isEmpty(fullName)) String fullName = ifolder.getFullName();
continue; if (TextUtils.isEmpty(fullName))
continue;
String[] attrs = ((IMAPFolder) ifolder).getAttributes(); String[] attrs = ((IMAPFolder) ifolder).getAttributes();
String type = EntityFolder.getType(attrs, fullName, false); String type = EntityFolder.getType(attrs, fullName, false);
if (type != null && if (type != null &&
!EntityFolder.USER.equals(type) && !EntityFolder.USER.equals(type) &&
!EntityFolder.SYSTEM.equals(type)) { !EntityFolder.SYSTEM.equals(type)) {
for (EntityFolder folder : new ArrayList<>(local.values())) for (EntityFolder folder : new ArrayList<>(local.values()))
if (type.equals(folder.type) && if (type.equals(folder.type) &&
!fullName.equals(folder.name) && !fullName.equals(folder.name) &&
!local.containsKey(fullName) && !local.containsKey(fullName) &&
!istore.getFolder(folder.name).exists()) { !istore.getFolder(folder.name).exists()) {
Log.e(account.host + Log.e(account.host +
" renaming " + type + " folder" + " renaming " + type + " folder" +
" from " + folder.name + " to " + fullName); " from " + folder.name + " to " + fullName);
local.remove(folder.name); local.remove(folder.name);
local.put(fullName, folder); local.put(fullName, folder);
folder.name = fullName; folder.name = fullName;
db.folder().setFolderName(folder.id, fullName); db.folder().setFolderName(folder.id, fullName);
} }
// Reselect Gmail archive folder // Reselect Gmail archive folder
if (EntityFolder.ARCHIVE.equals(type) && account.isGmail()) { if (EntityFolder.ARCHIVE.equals(type) && account.isGmail()) {
boolean gmail_archive_fixed = prefs.getBoolean("gmail_archive_fixed", false); boolean gmail_archive_fixed = prefs.getBoolean("gmail_archive_fixed", false);
if (!gmail_archive_fixed) { if (!gmail_archive_fixed) {
prefs.edit().putBoolean("gmail_archive_fixed", true).apply(); prefs.edit().putBoolean("gmail_archive_fixed", true).apply();
EntityFolder archive = db.folder().getFolderByType(account.id, EntityFolder.ARCHIVE); EntityFolder archive = db.folder().getFolderByType(account.id, EntityFolder.ARCHIVE);
if (archive == null) { if (archive == null) {
archive = db.folder().getFolderByName(account.id, fullName); archive = db.folder().getFolderByName(account.id, fullName);
if (archive != null) { if (archive != null) {
Log.e("Reselecting Gmail archive=" + fullName); Log.e("Reselecting Gmail archive=" + fullName);
archive.type = EntityFolder.ARCHIVE; archive.type = EntityFolder.ARCHIVE;
db.folder().setFolderType(archive.id, archive.type); db.folder().setFolderType(archive.id, archive.type);
}
} }
} }
} }
} }
} }
} catch (Throwable ex) {
Log.e(ex);
} }
Map<String, EntityFolder> nameFolder = new HashMap<>(); Map<String, EntityFolder> nameFolder = new HashMap<>();