Dynamically configure inbox

pull/147/head
M66B 7 years ago
parent 8bef85df9e
commit c023af093c

@ -143,6 +143,7 @@ public class EntityFolder implements Serializable {
static final int DEFAULT_KEEP = 30; // days static final int DEFAULT_KEEP = 30; // days
static final List<String> SYSTEM_FOLDER_SYNC = Arrays.asList( static final List<String> SYSTEM_FOLDER_SYNC = Arrays.asList(
INBOX,
DRAFTS, DRAFTS,
SENT, SENT,
ARCHIVE, ARCHIVE,
@ -150,6 +151,7 @@ public class EntityFolder implements Serializable {
JUNK JUNK
); );
static final List<Boolean> SYSTEM_FOLDER_DOWNLOAD = Arrays.asList( static final List<Boolean> SYSTEM_FOLDER_DOWNLOAD = Arrays.asList(
true, // inbox
true, // drafts true, // drafts
false, // sent false, // sent
false, // archive false, // archive

@ -569,6 +569,7 @@ public class FragmentAccount extends FragmentBase {
result.idle = istore.hasCapability("IDLE"); result.idle = istore.hasCapability("IDLE");
boolean inbox = false;
boolean archive = false; boolean archive = false;
boolean drafts = false; boolean drafts = false;
boolean trash = false; boolean trash = false;
@ -614,7 +615,9 @@ public class FragmentAccount extends FragmentBase {
if (folder.name.toLowerCase().contains("junk")) if (folder.name.toLowerCase().contains("junk"))
altJunk = folder; altJunk = folder;
} else { } else {
if (EntityFolder.ARCHIVE.equals(type)) if (EntityFolder.INBOX.equals(type))
inbox = true;
else if (EntityFolder.ARCHIVE.equals(type))
archive = true; archive = true;
else if (EntityFolder.DRAFTS.equals(type)) else if (EntityFolder.DRAFTS.equals(type))
drafts = true; drafts = true;
@ -631,6 +634,8 @@ public class FragmentAccount extends FragmentBase {
} }
} }
if (!inbox)
throw new IllegalArgumentException(getString(R.string.title_no_inbox));
if (!archive && altArchive != null) if (!archive && altArchive != null)
altArchive.type = EntityFolder.ARCHIVE; altArchive.type = EntityFolder.ARCHIVE;
if (!drafts && altDrafts != null) if (!drafts && altDrafts != null)
@ -835,6 +840,7 @@ public class FragmentAccount extends FragmentBase {
last_connected = account.last_connected; last_connected = account.last_connected;
// Check IMAP server // Check IMAP server
EntityFolder inbox = null;
if (check) { if (check) {
Properties props = MessageHelper.getSessionProperties(auth_type, realm, insecure); Properties props = MessageHelper.getSessionProperties(auth_type, realm, insecure);
Session isession = Session.getInstance(props, null); Session isession = Session.getInstance(props, null);
@ -853,6 +859,26 @@ public class FragmentAccount extends FragmentBase {
throw ex; throw ex;
} }
separator = istore.getDefaultFolder().getSeparator(); separator = istore.getDefaultFolder().getSeparator();
for (Folder ifolder : istore.getDefaultFolder().list("*")) {
// Check folder attributes
String fullName = ifolder.getFullName();
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
Log.i(fullName + " attrs=" + TextUtils.join(" ", attrs));
String type = EntityFolder.getType(attrs, fullName);
if (EntityFolder.INBOX.equals(type)) {
inbox = new EntityFolder();
inbox.name = fullName;
inbox.type = type;
inbox.synchronize = true;
inbox.unified = true;
inbox.notify = true;
inbox.sync_days = EntityFolder.DEFAULT_SYNC;
inbox.keep_days = EntityFolder.DEFAULT_KEEP;
}
}
} finally { } finally {
if (istore != null) if (istore != null)
istore.close(); istore.close();
@ -906,6 +932,7 @@ public class FragmentAccount extends FragmentBase {
db.account().updateAccount(account); db.account().updateAccount(account);
else else
account.id = db.account().insertAccount(account); account.id = db.account().insertAccount(account);
EntityLog.log(context, (update ? "Updated" : "Added") + " account=" + account.name);
// Make sure the channel exists on commit // Make sure the channel exists on commit
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
@ -918,16 +945,8 @@ public class FragmentAccount extends FragmentBase {
List<EntityFolder> folders = new ArrayList<>(); List<EntityFolder> folders = new ArrayList<>();
EntityFolder inbox = new EntityFolder(); if (inbox != null)
inbox.name = "INBOX"; folders.add(inbox);
inbox.type = EntityFolder.INBOX;
inbox.synchronize = true;
inbox.unified = true;
inbox.notify = true;
inbox.sync_days = EntityFolder.DEFAULT_SYNC;
inbox.keep_days = EntityFolder.DEFAULT_KEEP;
folders.add(inbox);
if (drafts != null) { if (drafts != null) {
drafts.type = EntityFolder.DRAFTS; drafts.type = EntityFolder.DRAFTS;
@ -987,9 +1006,10 @@ public class FragmentAccount extends FragmentBase {
EntityFolder existing = db.folder().getFolderByName(account.id, folder.name); EntityFolder existing = db.folder().getFolderByName(account.id, folder.name);
if (existing == null) { if (existing == null) {
folder.account = account.id; folder.account = account.id;
Log.i("Creating folder=" + folder.name + " (" + folder.type + ")"); EntityLog.log(context, "Added folder=" + folder.name + " type=" + folder.type);
folder.id = db.folder().insertFolder(folder); folder.id = db.folder().insertFolder(folder);
} else { } else {
EntityLog.log(context, "Updated folder=" + folder.name + " type=" + folder.type);
db.folder().setFolderType(existing.id, folder.type); db.folder().setFolderType(existing.id, folder.type);
db.folder().setFolderLevel(existing.id, folder.level); db.folder().setFolderLevel(existing.id, folder.level);
} }

@ -640,6 +640,8 @@ public class FragmentIdentity extends FragmentBase {
db.identity().updateIdentity(identity); db.identity().updateIdentity(identity);
else else
identity.id = db.identity().insertIdentity(identity); identity.id = db.identity().insertIdentity(identity);
EntityLog.log(context, (update ? "Updated" : "Added") +
" identity=" + identity.name + " email=" + identity.email);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {

@ -202,17 +202,6 @@ public class FragmentQuickSetup extends FragmentBase {
List<EntityFolder> folders = new ArrayList<>(); List<EntityFolder> folders = new ArrayList<>();
EntityFolder inbox = new EntityFolder();
inbox.name = "INBOX";
inbox.type = EntityFolder.INBOX;
inbox.level = 0;
inbox.synchronize = true;
inbox.unified = true;
inbox.notify = true;
inbox.sync_days = EntityFolder.DEFAULT_SYNC;
inbox.keep_days = EntityFolder.DEFAULT_KEEP;
folders.add(inbox);
{ {
Properties props = MessageHelper.getSessionProperties(auth_type, null, false); Properties props = MessageHelper.getSessionProperties(auth_type, null, false);
Session isession = Session.getInstance(props, null); Session isession = Session.getInstance(props, null);
@ -224,6 +213,7 @@ public class FragmentQuickSetup extends FragmentBase {
separator = istore.getDefaultFolder().getSeparator(); separator = istore.getDefaultFolder().getSeparator();
boolean inbox = false;
boolean drafts = false; boolean drafts = false;
for (Folder ifolder : istore.getDefaultFolder().list("*")) { for (Folder ifolder : istore.getDefaultFolder().list("*")) {
String fullName = ifolder.getFullName(); String fullName = ifolder.getFullName();
@ -232,7 +222,7 @@ public class FragmentQuickSetup extends FragmentBase {
Log.i(fullName + " attrs=" + TextUtils.join(" ", attrs) + " type=" + type); Log.i(fullName + " attrs=" + TextUtils.join(" ", attrs) + " type=" + type);
if (type != null) { if (type != null && !EntityFolder.USER.equals(type)) {
int sync = EntityFolder.SYSTEM_FOLDER_SYNC.indexOf(type); int sync = EntityFolder.SYSTEM_FOLDER_SYNC.indexOf(type);
EntityFolder folder = new EntityFolder(); EntityFolder folder = new EntityFolder();
folder.name = fullName; folder.name = fullName;
@ -244,12 +234,14 @@ public class FragmentQuickSetup extends FragmentBase {
folder.keep_days = EntityFolder.DEFAULT_KEEP; folder.keep_days = EntityFolder.DEFAULT_KEEP;
folders.add(folder); folders.add(folder);
if (EntityFolder.INBOX.equals(type))
inbox = true;
if (EntityFolder.DRAFTS.equals(type)) if (EntityFolder.DRAFTS.equals(type))
drafts = true; drafts = true;
} }
} }
if (!drafts) if (!inbox || !drafts)
throw new IllegalArgumentException( throw new IllegalArgumentException(
context.getString(R.string.title_setup_no_settings, dparts[1])); context.getString(R.string.title_setup_no_settings, dparts[1]));
} finally { } finally {
@ -301,11 +293,13 @@ public class FragmentQuickSetup extends FragmentBase {
account.last_connected = now; account.last_connected = now;
account.id = db.account().insertAccount(account); account.id = db.account().insertAccount(account);
EntityLog.log(context, "Quick added account=" + account.name);
// Create folders // Create folders
for (EntityFolder folder : folders) { for (EntityFolder folder : folders) {
folder.account = account.id; folder.account = account.id;
folder.id = db.folder().insertFolder(folder); folder.id = db.folder().insertFolder(folder);
EntityLog.log(context, "Quick added folder=" + folder.name + " type=" + folder.type);
} }
// Set swipe left/right folder // Set swipe left/right folder
@ -349,6 +343,7 @@ public class FragmentQuickSetup extends FragmentBase {
identity.error = null; identity.error = null;
identity.id = db.identity().insertIdentity(identity); identity.id = db.identity().insertIdentity(identity);
EntityLog.log(context, "Quick added identity=" + identity.name + " email=" + identity.email);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {

@ -254,7 +254,7 @@ public class Helper {
} }
static String localizeFolderName(Context context, String name) { static String localizeFolderName(Context context, String name) {
if ("INBOX".equals(name)) if (name != null && "INBOX".equals(name.toUpperCase()))
return context.getString(R.string.title_folder_inbox); return context.getString(R.string.title_folder_inbox);
else if ("OUTBOX".equals(name)) else if ("OUTBOX".equals(name))
return context.getString(R.string.title_folder_outbox); return context.getString(R.string.title_folder_outbox);

@ -2222,9 +2222,9 @@ public class ServiceSynchronize extends LifecycleService {
folder.sync_days = EntityFolder.DEFAULT_SYNC; folder.sync_days = EntityFolder.DEFAULT_SYNC;
folder.keep_days = EntityFolder.DEFAULT_KEEP; folder.keep_days = EntityFolder.DEFAULT_KEEP;
db.folder().insertFolder(folder); db.folder().insertFolder(folder);
Log.i(folder.name + " added"); Log.i(folder.name + " added type=" + folder.type);
} else { } else {
Log.i(folder.name + " exists"); Log.i(folder.name + " exists type=" + folder.type);
if (folder.display == null) { if (folder.display == null) {
if (display != null) { if (display != null) {

@ -231,6 +231,7 @@
<string name="title_no_host">Host name missing</string> <string name="title_no_host">Host name missing</string>
<string name="title_no_user">User name missing</string> <string name="title_no_user">User name missing</string>
<string name="title_no_password">Password missing</string> <string name="title_no_password">Password missing</string>
<string name="title_no_inbox">Inbox not found</string>
<string name="title_no_drafts">No drafts folder selected</string> <string name="title_no_drafts">No drafts folder selected</string>
<string name="title_no_primary_drafts">No primary account or no drafts folder</string> <string name="title_no_primary_drafts">No primary account or no drafts folder</string>
<string name="title_no_idle">This provider does not support push messages. This will delay reception of new messages and increase battery usage.</string> <string name="title_no_idle">This provider does not support push messages. This will delay reception of new messages and increase battery usage.</string>

Loading…
Cancel
Save