Browse Source

Prevent renaming system folders

Fixes #123
main
M66B 6 years ago
parent
commit
f74adb7b25
4 changed files with 24 additions and 7 deletions
  1. +8
    -2
      app/src/main/java/eu/faircode/email/EntityFolder.java
  2. +1
    -0
      app/src/main/java/eu/faircode/email/FragmentFolder.java
  3. +14
    -5
      app/src/main/java/eu/faircode/email/ServiceSynchronize.java
  4. +1
    -0
      app/src/main/res/values/strings.xml

+ 8
- 2
app/src/main/java/eu/faircode/email/EntityFolder.java View File

@ -76,6 +76,7 @@ public class EntityFolder implements Parcelable {
static final String TRASH = "Trash";
static final String JUNK = "Junk";
static final String SENT = "Sent";
static final String SYSTEM = "System";
static final String USER = "User";
static final List<String> SYSTEM_FOLDER_ATTR = Arrays.asList(
@ -83,14 +84,18 @@ public class EntityFolder implements Parcelable {
"Drafts",
"Trash",
"Junk",
"Sent"
"Sent",
"Important",
"Flagged"
);
static final List<String> SYSTEM_FOLDER_TYPE = Arrays.asList(
ARCHIVE,
DRAFTS,
TRASH,
JUNK,
SENT
SENT,
SYSTEM,
SYSTEM
); // MUST match SYSTEM_FOLDER_ATTR
static final List<String> FOLDER_SORT_ORDER = Arrays.asList(
@ -101,6 +106,7 @@ public class EntityFolder implements Parcelable {
ARCHIVE,
TRASH,
JUNK,
SYSTEM,
USER
);


+ 1
- 0
app/src/main/java/eu/faircode/email/FragmentFolder.java View File

@ -310,6 +310,7 @@ public class FragmentFolder extends FragmentEx {
// Consider previous save as cancelled
pbWait.setVisibility(View.GONE);
Helper.setViewsEnabled(view, true);
etRename.setEnabled(folder == null || EntityFolder.USER.equals(folder.type));
btnSave.setEnabled(true);
ibDelete.setEnabled(true);
ibDelete.setVisibility(folder == null ? View.GONE : View.VISIBLE);


+ 14
- 5
app/src/main/java/eu/faircode/email/ServiceSynchronize.java View File

@ -1239,17 +1239,23 @@ public class ServiceSynchronize extends LifecycleService {
for (Folder ifolder : ifolders) {
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
boolean system = false;
boolean selectable = true;
for (String attr : attrs) {
if ("\\Noselect".equals(attr)) { // TODO: is this attribute correct?
selectable = false;
break;
}
if (attr.startsWith("\\"))
if (EntityFolder.SYSTEM_FOLDER_ATTR.contains(attr.substring(1))) {
selectable = false;
if (attr.startsWith("\\")) {
attr = attr.substring(1);
if (EntityFolder.SYSTEM_FOLDER_ATTR.contains(attr)) {
int index = EntityFolder.SYSTEM_FOLDER_ATTR.indexOf(attr);
system = EntityFolder.SYSTEM.equals(EntityFolder.SYSTEM_FOLDER_TYPE.get(index));
if (!system)
selectable = false;
break;
}
}
}
if (selectable) {
@ -1259,13 +1265,16 @@ public class ServiceSynchronize extends LifecycleService {
folder = new EntityFolder();
folder.account = account.id;
folder.name = ifolder.getFullName();
folder.type = EntityFolder.USER;
folder.type = (system ? EntityFolder.SYSTEM : EntityFolder.USER);
folder.synchronize = false;
folder.after = EntityFolder.DEFAULT_USER_SYNC;
db.folder().insertFolder(folder);
Log.i(Helper.TAG, folder.name + " added");
} else
} else {
if (system)
db.folder().setFolderType(folder.id, EntityFolder.SYSTEM);
names.remove(folder.name);
}
}
}


+ 1
- 0
app/src/main/res/values/strings.xml View File

@ -145,6 +145,7 @@
<string name="title_folder_trash">Trash</string>
<string name="title_folder_junk">Spam</string>
<string name="title_folder_sent">Sent</string>
<string name="title_folder_system">System</string>
<string name="title_folder_user">User</string>
<string name="title_folder_primary">Folders primary account</string>
<string name="title_folder_thread">Conversation</string>


Loading…
Cancel
Save