Dynamically configure inbox

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

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

@ -569,6 +569,7 @@ public class FragmentAccount extends FragmentBase {
result.idle = istore.hasCapability("IDLE");
boolean inbox = false;
boolean archive = false;
boolean drafts = false;
boolean trash = false;
@ -614,7 +615,9 @@ public class FragmentAccount extends FragmentBase {
if (folder.name.toLowerCase().contains("junk"))
altJunk = folder;
} else {
if (EntityFolder.ARCHIVE.equals(type))
if (EntityFolder.INBOX.equals(type))
inbox = true;
else if (EntityFolder.ARCHIVE.equals(type))
archive = true;
else if (EntityFolder.DRAFTS.equals(type))
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)
altArchive.type = EntityFolder.ARCHIVE;
if (!drafts && altDrafts != null)
@ -835,6 +840,7 @@ public class FragmentAccount extends FragmentBase {
last_connected = account.last_connected;
// Check IMAP server
EntityFolder inbox = null;
if (check) {
Properties props = MessageHelper.getSessionProperties(auth_type, realm, insecure);
Session isession = Session.getInstance(props, null);
@ -853,6 +859,26 @@ public class FragmentAccount extends FragmentBase {
throw ex;
}
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 {
if (istore != null)
istore.close();
@ -906,6 +932,7 @@ public class FragmentAccount extends FragmentBase {
db.account().updateAccount(account);
else
account.id = db.account().insertAccount(account);
EntityLog.log(context, (update ? "Updated" : "Added") + " account=" + account.name);
// Make sure the channel exists on commit
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
@ -918,16 +945,8 @@ public class FragmentAccount extends FragmentBase {
List<EntityFolder> folders = new ArrayList<>();
EntityFolder inbox = new EntityFolder();
inbox.name = "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 (inbox != null)
folders.add(inbox);
if (drafts != null) {
drafts.type = EntityFolder.DRAFTS;
@ -987,9 +1006,10 @@ public class FragmentAccount extends FragmentBase {
EntityFolder existing = db.folder().getFolderByName(account.id, folder.name);
if (existing == null) {
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);
} else {
EntityLog.log(context, "Updated folder=" + folder.name + " type=" + folder.type);
db.folder().setFolderType(existing.id, folder.type);
db.folder().setFolderLevel(existing.id, folder.level);
}

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

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

@ -254,7 +254,7 @@ public class Helper {
}
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);
else if ("OUTBOX".equals(name))
return context.getString(R.string.title_folder_outbox);

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

@ -231,6 +231,7 @@
<string name="title_no_host">Host name missing</string>
<string name="title_no_user">User name 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_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>

Loading…
Cancel
Save