Loading app/core/src/main/java/com/fsck/k9/Account.java +91 −5 Original line number Diff line number Diff line Loading @@ -172,6 +172,11 @@ public class Account implements BaseAccount, StoreConfig { private String trashFolder; private String archiveFolder; private String spamFolder; private SpecialFolderSelection draftsFolderSelection; private SpecialFolderSelection sentFolderSelection; private SpecialFolderSelection trashFolderSelection; private SpecialFolderSelection archiveFolderSelection; private SpecialFolderSelection spamFolderSelection; private String autoExpandFolder; private FolderMode folderDisplayMode; private FolderMode folderSyncMode; Loading Loading @@ -244,6 +249,11 @@ public class Account implements BaseAccount, StoreConfig { NONE, ALL, FIRST_CLASS, FIRST_AND_SECOND_CLASS, NOT_SECOND_CLASS } public enum SpecialFolderSelection { AUTOMATIC, MANUAL } public enum ShowPictures { NEVER, ALWAYS, ONLY_FROM_CONTACTS } Loading Loading @@ -311,6 +321,11 @@ public class Account implements BaseAccount, StoreConfig { sentFolder = null; spamFolder = null; trashFolder = null; archiveFolderSelection = SpecialFolderSelection.AUTOMATIC; draftsFolderSelection = SpecialFolderSelection.AUTOMATIC; sentFolderSelection = SpecialFolderSelection.AUTOMATIC; spamFolderSelection = SpecialFolderSelection.AUTOMATIC; trashFolderSelection = SpecialFolderSelection.AUTOMATIC; searchableFolders = Searchable.ALL; Loading Loading @@ -371,6 +386,17 @@ public class Account implements BaseAccount, StoreConfig { trashFolder = storage.getString(accountUuid + ".trashFolderName", null); archiveFolder = storage.getString(accountUuid + ".archiveFolderName", null); spamFolder = storage.getString(accountUuid + ".spamFolderName", null); archiveFolderSelection = getEnumStringPref(storage, accountUuid + ".archiveFolderSelection", SpecialFolderSelection.AUTOMATIC); draftsFolderSelection = getEnumStringPref(storage, accountUuid + ".draftsFolderSelection", SpecialFolderSelection.AUTOMATIC); sentFolderSelection = getEnumStringPref(storage, accountUuid + ".sentFolderSelection", SpecialFolderSelection.AUTOMATIC); spamFolderSelection = getEnumStringPref(storage, accountUuid + ".spamFolderSelection", SpecialFolderSelection.AUTOMATIC); trashFolderSelection = getEnumStringPref(storage, accountUuid + ".trashFolderSelection", SpecialFolderSelection.AUTOMATIC); expungePolicy = getEnumStringPref(storage, accountUuid + ".expungePolicy", Expunge.EXPUNGE_IMMEDIATELY); syncRemoteDeletions = storage.getBoolean(accountUuid + ".syncRemoteDeletions", true); Loading Loading @@ -491,6 +517,11 @@ public class Account implements BaseAccount, StoreConfig { editor.remove(accountUuid + ".trashFolderName"); editor.remove(accountUuid + ".archiveFolderName"); editor.remove(accountUuid + ".spamFolderName"); editor.remove(accountUuid + ".archiveFolderSelection"); editor.remove(accountUuid + ".draftsFolderSelection"); editor.remove(accountUuid + ".sentFolderSelection"); editor.remove(accountUuid + ".spamFolderSelection"); editor.remove(accountUuid + ".trashFolderSelection"); editor.remove(accountUuid + ".autoExpandFolderName"); editor.remove(accountUuid + ".accountNumber"); editor.remove(accountUuid + ".vibrate"); Loading Loading @@ -665,6 +696,11 @@ public class Account implements BaseAccount, StoreConfig { editor.putString(accountUuid + ".trashFolderName", trashFolder); editor.putString(accountUuid + ".archiveFolderName", archiveFolder); editor.putString(accountUuid + ".spamFolderName", spamFolder); editor.putString(accountUuid + ".archiveFolderSelection", archiveFolderSelection.name()); editor.putString(accountUuid + ".draftsFolderSelection", draftsFolderSelection.name()); editor.putString(accountUuid + ".sentFolderSelection", sentFolderSelection.name()); editor.putString(accountUuid + ".spamFolderSelection", spamFolderSelection.name()); editor.putString(accountUuid + ".trashFolderSelection", trashFolderSelection.name()); editor.putString(accountUuid + ".autoExpandFolderName", autoExpandFolder); editor.putInt(accountUuid + ".accountNumber", accountNumber); editor.putString(accountUuid + ".sortTypeEnum", sortType.name()); Loading Loading @@ -937,8 +973,9 @@ public class Account implements BaseAccount, StoreConfig { return draftsFolder; } public synchronized void setDraftsFolder(String name) { public synchronized void setDraftsFolder(String name, SpecialFolderSelection selection) { draftsFolder = name; draftsFolderSelection = selection; } /** Loading @@ -953,8 +990,9 @@ public class Account implements BaseAccount, StoreConfig { return sentFolder; } public synchronized void setSentFolder(String name) { public synchronized void setSentFolder(String name, SpecialFolderSelection selection) { sentFolder = name; sentFolderSelection = selection; } /** Loading @@ -970,8 +1008,9 @@ public class Account implements BaseAccount, StoreConfig { return trashFolder; } public synchronized void setTrashFolder(String name) { public synchronized void setTrashFolder(String name, SpecialFolderSelection selection) { trashFolder = name; trashFolderSelection = selection; } /** Loading @@ -986,8 +1025,9 @@ public class Account implements BaseAccount, StoreConfig { return archiveFolder; } public synchronized void setArchiveFolder(String archiveFolder) { public synchronized void setArchiveFolder(String archiveFolder, SpecialFolderSelection selection) { this.archiveFolder = archiveFolder; archiveFolderSelection = selection; } /** Loading @@ -1002,8 +1042,9 @@ public class Account implements BaseAccount, StoreConfig { return spamFolder; } public synchronized void setSpamFolder(String name) { public synchronized void setSpamFolder(String name, SpecialFolderSelection selection) { spamFolder = name; spamFolderSelection = selection; } /** Loading @@ -1014,6 +1055,26 @@ public class Account implements BaseAccount, StoreConfig { return spamFolder != null; } public SpecialFolderSelection getDraftsFolderSelection() { return draftsFolderSelection; } public synchronized SpecialFolderSelection getSentFolderSelection() { return sentFolderSelection; } public synchronized SpecialFolderSelection getTrashFolderSelection() { return trashFolderSelection; } public synchronized SpecialFolderSelection getArchiveFolderSelection() { return archiveFolderSelection; } public synchronized SpecialFolderSelection getSpamFolderSelection() { return spamFolderSelection; } public String getOutboxFolder() { return OUTBOX; } Loading Loading @@ -1784,4 +1845,29 @@ public class Account implements BaseAccount, StoreConfig { localKeyStore.deleteCertificate(uri.getHost(), uri.getPort()); } } @Override public void setArchiveFolder(String name) { setArchiveFolder(name, SpecialFolderSelection.AUTOMATIC); } @Override public void setDraftsFolder(String name) { setDraftsFolder(name, SpecialFolderSelection.AUTOMATIC); } @Override public void setTrashFolder(String name) { setTrashFolder(name, SpecialFolderSelection.AUTOMATIC); } @Override public void setSpamFolder(String name) { setSpamFolder(name, SpecialFolderSelection.AUTOMATIC); } @Override public void setSentFolder(String name) { setSentFolder(name, SpecialFolderSelection.AUTOMATIC); } } app/core/src/main/java/com/fsck/k9/preferences/Storage.java +23 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ import com.fsck.k9.helper.Utility; import com.fsck.k9.preferences.migrations.StorageMigrations; import com.fsck.k9.preferences.migrations.StorageMigrationsHelper; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import timber.log.Timber; public class Storage { Loading @@ -25,7 +26,7 @@ public class Storage { private volatile ConcurrentMap<String, String> storage = new ConcurrentHashMap<>(); private static final int DB_VERSION = 3; private static final int DB_VERSION = 4; private static final String DB_NAME = "preferences_storage"; private ThreadLocal<ConcurrentMap<String, String>> workingStorage = new ThreadLocal<>(); Loading Loading @@ -280,6 +281,22 @@ public class Storage { } } private void insertValue(SQLiteDatabase mDb, String key, String value) { if (value == null) { return; } ContentValues cv = new ContentValues(); cv.put("primkey", key); cv.put("value", value); long result = mDb.insert("preferences_storage", null, cv); if (result == -1) { Timber.e("Error writing key '%s', value = '%s'", key, value); } } private StorageMigrationsHelper migrationsHelper = new StorageMigrationsHelper() { @Override public void writeValue(@NotNull SQLiteDatabase db, @NotNull String key, String value) { Loading @@ -290,5 +307,10 @@ public class Storage { public String readValue(@NotNull SQLiteDatabase db, @NotNull String key) { return Storage.this.readValue(db, key); } @Override public void insertValue(@NotNull SQLiteDatabase db, @NotNull String key, @Nullable String value) { Storage.this.insertValue(db, key, value); } }; } app/core/src/main/java/com/fsck/k9/preferences/migrations/StorageMigrationTo4.kt 0 → 100644 +31 −0 Original line number Diff line number Diff line package com.fsck.k9.preferences.migrations import android.database.sqlite.SQLiteDatabase /** * Add `*FolderSelection` values of "MANUAL" for existing accounts (default for new accounts is "AUTOMATIC"). */ class StorageMigrationTo4( private val db: SQLiteDatabase, private val migrationsHelper: StorageMigrationsHelper ) { fun insertSpecialFolderSelectionValues() { val accountUuidsListValue = migrationsHelper.readValue(db, "accountUuids") if (accountUuidsListValue == null || accountUuidsListValue.isEmpty()) { return } val accountUuids = accountUuidsListValue.split(",") for (accountUuid in accountUuids) { insertSpecialFolderSelectionValues(accountUuid) } } private fun insertSpecialFolderSelectionValues(accountUuid: String) { migrationsHelper.insertValue(db, "$accountUuid.archiveFolderSelection", "MANUAL") migrationsHelper.insertValue(db, "$accountUuid.draftsFolderSelection", "MANUAL") migrationsHelper.insertValue(db, "$accountUuid.sentFolderSelection", "MANUAL") migrationsHelper.insertValue(db, "$accountUuid.spamFolderSelection", "MANUAL") migrationsHelper.insertValue(db, "$accountUuid.trashFolderSelection", "MANUAL") } } app/core/src/main/java/com/fsck/k9/preferences/migrations/StorageMigrations.kt +1 −0 Original line number Diff line number Diff line Loading @@ -9,5 +9,6 @@ internal object StorageMigrations { if (oldVersion <= 1) StorageMigrationTo2.urlEncodeUserNameAndPassword(db, migrationsHelper) if (oldVersion <= 2) StorageMigrationTo3(db, migrationsHelper).rewriteFolderNone() if (oldVersion <= 3) StorageMigrationTo4(db, migrationsHelper).insertSpecialFolderSelectionValues() } } app/core/src/main/java/com/fsck/k9/preferences/migrations/StorageMigrationsHelper.kt +1 −0 Original line number Diff line number Diff line Loading @@ -5,4 +5,5 @@ import android.database.sqlite.SQLiteDatabase interface StorageMigrationsHelper { fun readValue(db: SQLiteDatabase, key: String): String? fun writeValue(db: SQLiteDatabase, key: String, value: String?) fun insertValue(db: SQLiteDatabase, key: String, value: String?) } Loading
app/core/src/main/java/com/fsck/k9/Account.java +91 −5 Original line number Diff line number Diff line Loading @@ -172,6 +172,11 @@ public class Account implements BaseAccount, StoreConfig { private String trashFolder; private String archiveFolder; private String spamFolder; private SpecialFolderSelection draftsFolderSelection; private SpecialFolderSelection sentFolderSelection; private SpecialFolderSelection trashFolderSelection; private SpecialFolderSelection archiveFolderSelection; private SpecialFolderSelection spamFolderSelection; private String autoExpandFolder; private FolderMode folderDisplayMode; private FolderMode folderSyncMode; Loading Loading @@ -244,6 +249,11 @@ public class Account implements BaseAccount, StoreConfig { NONE, ALL, FIRST_CLASS, FIRST_AND_SECOND_CLASS, NOT_SECOND_CLASS } public enum SpecialFolderSelection { AUTOMATIC, MANUAL } public enum ShowPictures { NEVER, ALWAYS, ONLY_FROM_CONTACTS } Loading Loading @@ -311,6 +321,11 @@ public class Account implements BaseAccount, StoreConfig { sentFolder = null; spamFolder = null; trashFolder = null; archiveFolderSelection = SpecialFolderSelection.AUTOMATIC; draftsFolderSelection = SpecialFolderSelection.AUTOMATIC; sentFolderSelection = SpecialFolderSelection.AUTOMATIC; spamFolderSelection = SpecialFolderSelection.AUTOMATIC; trashFolderSelection = SpecialFolderSelection.AUTOMATIC; searchableFolders = Searchable.ALL; Loading Loading @@ -371,6 +386,17 @@ public class Account implements BaseAccount, StoreConfig { trashFolder = storage.getString(accountUuid + ".trashFolderName", null); archiveFolder = storage.getString(accountUuid + ".archiveFolderName", null); spamFolder = storage.getString(accountUuid + ".spamFolderName", null); archiveFolderSelection = getEnumStringPref(storage, accountUuid + ".archiveFolderSelection", SpecialFolderSelection.AUTOMATIC); draftsFolderSelection = getEnumStringPref(storage, accountUuid + ".draftsFolderSelection", SpecialFolderSelection.AUTOMATIC); sentFolderSelection = getEnumStringPref(storage, accountUuid + ".sentFolderSelection", SpecialFolderSelection.AUTOMATIC); spamFolderSelection = getEnumStringPref(storage, accountUuid + ".spamFolderSelection", SpecialFolderSelection.AUTOMATIC); trashFolderSelection = getEnumStringPref(storage, accountUuid + ".trashFolderSelection", SpecialFolderSelection.AUTOMATIC); expungePolicy = getEnumStringPref(storage, accountUuid + ".expungePolicy", Expunge.EXPUNGE_IMMEDIATELY); syncRemoteDeletions = storage.getBoolean(accountUuid + ".syncRemoteDeletions", true); Loading Loading @@ -491,6 +517,11 @@ public class Account implements BaseAccount, StoreConfig { editor.remove(accountUuid + ".trashFolderName"); editor.remove(accountUuid + ".archiveFolderName"); editor.remove(accountUuid + ".spamFolderName"); editor.remove(accountUuid + ".archiveFolderSelection"); editor.remove(accountUuid + ".draftsFolderSelection"); editor.remove(accountUuid + ".sentFolderSelection"); editor.remove(accountUuid + ".spamFolderSelection"); editor.remove(accountUuid + ".trashFolderSelection"); editor.remove(accountUuid + ".autoExpandFolderName"); editor.remove(accountUuid + ".accountNumber"); editor.remove(accountUuid + ".vibrate"); Loading Loading @@ -665,6 +696,11 @@ public class Account implements BaseAccount, StoreConfig { editor.putString(accountUuid + ".trashFolderName", trashFolder); editor.putString(accountUuid + ".archiveFolderName", archiveFolder); editor.putString(accountUuid + ".spamFolderName", spamFolder); editor.putString(accountUuid + ".archiveFolderSelection", archiveFolderSelection.name()); editor.putString(accountUuid + ".draftsFolderSelection", draftsFolderSelection.name()); editor.putString(accountUuid + ".sentFolderSelection", sentFolderSelection.name()); editor.putString(accountUuid + ".spamFolderSelection", spamFolderSelection.name()); editor.putString(accountUuid + ".trashFolderSelection", trashFolderSelection.name()); editor.putString(accountUuid + ".autoExpandFolderName", autoExpandFolder); editor.putInt(accountUuid + ".accountNumber", accountNumber); editor.putString(accountUuid + ".sortTypeEnum", sortType.name()); Loading Loading @@ -937,8 +973,9 @@ public class Account implements BaseAccount, StoreConfig { return draftsFolder; } public synchronized void setDraftsFolder(String name) { public synchronized void setDraftsFolder(String name, SpecialFolderSelection selection) { draftsFolder = name; draftsFolderSelection = selection; } /** Loading @@ -953,8 +990,9 @@ public class Account implements BaseAccount, StoreConfig { return sentFolder; } public synchronized void setSentFolder(String name) { public synchronized void setSentFolder(String name, SpecialFolderSelection selection) { sentFolder = name; sentFolderSelection = selection; } /** Loading @@ -970,8 +1008,9 @@ public class Account implements BaseAccount, StoreConfig { return trashFolder; } public synchronized void setTrashFolder(String name) { public synchronized void setTrashFolder(String name, SpecialFolderSelection selection) { trashFolder = name; trashFolderSelection = selection; } /** Loading @@ -986,8 +1025,9 @@ public class Account implements BaseAccount, StoreConfig { return archiveFolder; } public synchronized void setArchiveFolder(String archiveFolder) { public synchronized void setArchiveFolder(String archiveFolder, SpecialFolderSelection selection) { this.archiveFolder = archiveFolder; archiveFolderSelection = selection; } /** Loading @@ -1002,8 +1042,9 @@ public class Account implements BaseAccount, StoreConfig { return spamFolder; } public synchronized void setSpamFolder(String name) { public synchronized void setSpamFolder(String name, SpecialFolderSelection selection) { spamFolder = name; spamFolderSelection = selection; } /** Loading @@ -1014,6 +1055,26 @@ public class Account implements BaseAccount, StoreConfig { return spamFolder != null; } public SpecialFolderSelection getDraftsFolderSelection() { return draftsFolderSelection; } public synchronized SpecialFolderSelection getSentFolderSelection() { return sentFolderSelection; } public synchronized SpecialFolderSelection getTrashFolderSelection() { return trashFolderSelection; } public synchronized SpecialFolderSelection getArchiveFolderSelection() { return archiveFolderSelection; } public synchronized SpecialFolderSelection getSpamFolderSelection() { return spamFolderSelection; } public String getOutboxFolder() { return OUTBOX; } Loading Loading @@ -1784,4 +1845,29 @@ public class Account implements BaseAccount, StoreConfig { localKeyStore.deleteCertificate(uri.getHost(), uri.getPort()); } } @Override public void setArchiveFolder(String name) { setArchiveFolder(name, SpecialFolderSelection.AUTOMATIC); } @Override public void setDraftsFolder(String name) { setDraftsFolder(name, SpecialFolderSelection.AUTOMATIC); } @Override public void setTrashFolder(String name) { setTrashFolder(name, SpecialFolderSelection.AUTOMATIC); } @Override public void setSpamFolder(String name) { setSpamFolder(name, SpecialFolderSelection.AUTOMATIC); } @Override public void setSentFolder(String name) { setSentFolder(name, SpecialFolderSelection.AUTOMATIC); } }
app/core/src/main/java/com/fsck/k9/preferences/Storage.java +23 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ import com.fsck.k9.helper.Utility; import com.fsck.k9.preferences.migrations.StorageMigrations; import com.fsck.k9.preferences.migrations.StorageMigrationsHelper; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import timber.log.Timber; public class Storage { Loading @@ -25,7 +26,7 @@ public class Storage { private volatile ConcurrentMap<String, String> storage = new ConcurrentHashMap<>(); private static final int DB_VERSION = 3; private static final int DB_VERSION = 4; private static final String DB_NAME = "preferences_storage"; private ThreadLocal<ConcurrentMap<String, String>> workingStorage = new ThreadLocal<>(); Loading Loading @@ -280,6 +281,22 @@ public class Storage { } } private void insertValue(SQLiteDatabase mDb, String key, String value) { if (value == null) { return; } ContentValues cv = new ContentValues(); cv.put("primkey", key); cv.put("value", value); long result = mDb.insert("preferences_storage", null, cv); if (result == -1) { Timber.e("Error writing key '%s', value = '%s'", key, value); } } private StorageMigrationsHelper migrationsHelper = new StorageMigrationsHelper() { @Override public void writeValue(@NotNull SQLiteDatabase db, @NotNull String key, String value) { Loading @@ -290,5 +307,10 @@ public class Storage { public String readValue(@NotNull SQLiteDatabase db, @NotNull String key) { return Storage.this.readValue(db, key); } @Override public void insertValue(@NotNull SQLiteDatabase db, @NotNull String key, @Nullable String value) { Storage.this.insertValue(db, key, value); } }; }
app/core/src/main/java/com/fsck/k9/preferences/migrations/StorageMigrationTo4.kt 0 → 100644 +31 −0 Original line number Diff line number Diff line package com.fsck.k9.preferences.migrations import android.database.sqlite.SQLiteDatabase /** * Add `*FolderSelection` values of "MANUAL" for existing accounts (default for new accounts is "AUTOMATIC"). */ class StorageMigrationTo4( private val db: SQLiteDatabase, private val migrationsHelper: StorageMigrationsHelper ) { fun insertSpecialFolderSelectionValues() { val accountUuidsListValue = migrationsHelper.readValue(db, "accountUuids") if (accountUuidsListValue == null || accountUuidsListValue.isEmpty()) { return } val accountUuids = accountUuidsListValue.split(",") for (accountUuid in accountUuids) { insertSpecialFolderSelectionValues(accountUuid) } } private fun insertSpecialFolderSelectionValues(accountUuid: String) { migrationsHelper.insertValue(db, "$accountUuid.archiveFolderSelection", "MANUAL") migrationsHelper.insertValue(db, "$accountUuid.draftsFolderSelection", "MANUAL") migrationsHelper.insertValue(db, "$accountUuid.sentFolderSelection", "MANUAL") migrationsHelper.insertValue(db, "$accountUuid.spamFolderSelection", "MANUAL") migrationsHelper.insertValue(db, "$accountUuid.trashFolderSelection", "MANUAL") } }
app/core/src/main/java/com/fsck/k9/preferences/migrations/StorageMigrations.kt +1 −0 Original line number Diff line number Diff line Loading @@ -9,5 +9,6 @@ internal object StorageMigrations { if (oldVersion <= 1) StorageMigrationTo2.urlEncodeUserNameAndPassword(db, migrationsHelper) if (oldVersion <= 2) StorageMigrationTo3(db, migrationsHelper).rewriteFolderNone() if (oldVersion <= 3) StorageMigrationTo4(db, migrationsHelper).insertSpecialFolderSelectionValues() } }
app/core/src/main/java/com/fsck/k9/preferences/migrations/StorageMigrationsHelper.kt +1 −0 Original line number Diff line number Diff line Loading @@ -5,4 +5,5 @@ import android.database.sqlite.SQLiteDatabase interface StorageMigrationsHelper { fun readValue(db: SQLiteDatabase, key: String): String? fun writeValue(db: SQLiteDatabase, key: String, value: String?) fun insertValue(db: SQLiteDatabase, key: String, value: String?) }