Merge pull request #4799 from k9mail/fix_local_outbox

Fix local outbox
This commit is contained in:
cketti 2020-05-29 22:07:34 +02:00 committed by GitHub
commit 19de9ff7b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 4 deletions

View file

@ -960,10 +960,14 @@ public class LocalStore {
}
public long createLocalFolder(String folderName, FolderType type) throws MessagingException {
return createLocalFolder(folderName, folderName, type);
}
public long createLocalFolder(String folderServerId, String folderName, FolderType type) throws MessagingException {
return database.execute(true, (DbCallback<Long>) db -> {
ContentValues values = new ContentValues();
values.put("name", folderName);
values.put("server_id", folderName);
values.put("server_id", folderServerId);
values.put("local_only", 1);
values.put("type", FolderTypeConverter.toDatabaseFolderType(type));
values.put("visible_limit", 0);

View file

@ -14,7 +14,7 @@ class SpecialLocalFoldersCreator(
val localStore = localStoreProvider.getInstance(account)
account.outboxFolderId = localStore.createLocalFolder(OUTBOX_FOLDER_NAME, FolderType.OUTBOX)
account.outboxFolderId = localStore.createLocalFolder(OUTBOX_SERVER_ID, OUTBOX_FOLDER_NAME, FolderType.OUTBOX)
if (account.isPop3()) {
check(account.draftsFolderId == null) { "Drafts folder was already set up" }
@ -37,6 +37,7 @@ class SpecialLocalFoldersCreator(
private fun Account.isPop3() = storeUri.startsWith("pop3")
companion object {
private const val OUTBOX_SERVER_ID = Account.OUTBOX
private const val OUTBOX_FOLDER_NAME = Account.OUTBOX_NAME
private const val DRAFTS_FOLDER_NAME = "Drafts"
private const val SENT_FOLDER_NAME = "Sent"

View file

@ -52,7 +52,7 @@ class JmapAccountCreator(
private fun createOutboxFolder(account: Account) {
val localStore = localStoreProvider.getInstance(account)
account.outboxFolderId = localStore.createLocalFolder(Account.OUTBOX_NAME, FolderType.OUTBOX)
account.outboxFolderId = localStore.createLocalFolder(Account.OUTBOX, Account.OUTBOX_NAME, FolderType.OUTBOX)
}
private fun fetchFolderList(account: Account) {

View file

@ -12,7 +12,7 @@ import timber.log.Timber;
class StoreSchemaDefinition implements SchemaDefinition {
static final int DB_VERSION = 76;
static final int DB_VERSION = 77;
private final MigrationsHelper migrationsHelper;

View file

@ -0,0 +1,17 @@
package com.fsck.k9.storage.migrations
import android.content.ContentValues
import android.database.sqlite.SQLiteDatabase
/**
* Make sure local Outbox folder has correct 'server_id' value
*/
internal class MigrationTo77(private val db: SQLiteDatabase) {
fun cleanUpOutboxServerId() {
val values = ContentValues().apply {
put("server_id", "K9MAIL_INTERNAL_OUTBOX")
}
db.update("folders", values, "name = 'Outbox' AND local_only = 1", null)
}
}

View file

@ -22,5 +22,6 @@ object Migrations {
if (oldVersion < 74) MigrationTo74(db, migrationsHelper.account).removeDeletedMessages()
if (oldVersion < 75) MigrationTo75(db, migrationsHelper).updateAccountWithSpecialFolderIds()
if (oldVersion < 76) MigrationTo76(db, migrationsHelper).cleanUpSpecialLocalFolders()
if (oldVersion < 77) MigrationTo77(db).cleanUpOutboxServerId()
}
}