Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit a00d69cf authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #5241 from k9mail/BackendStorage_to_MessageStore

parents 24f25ca1 3a86cc63
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -51,15 +51,13 @@ class K9BackendFolder(
        return messageStore.getAllMessagesAndEffectiveDates(folderId)
    }

    // TODO: Move implementation from LocalFolder to this class
    override fun destroyMessages(messageServerIds: List<String>) {
        val localMessages = localFolder.getMessagesByUids(messageServerIds)
        localFolder.destroyMessages(localMessages)
        messageStore.destroyMessages(folderId, messageServerIds)
    }

    override fun clearAllMessages() {
        val messageServerIds = getMessageServerIds().toList()
        destroyMessages(messageServerIds)
        val messageServerIds = messageStore.getMessageServerIds(folderId)
        messageStore.destroyMessages(folderId, messageServerIds)
    }

    override fun getMoreMessages(): MoreMessages {
+1 −16
Original line number Diff line number Diff line
@@ -1587,23 +1587,8 @@ public class LocalFolder {
        }
    }

    /**
     * Delete a message from the 'messages' and 'threads' tables.
     *
     * @param db
     *         {@link SQLiteDatabase} instance to access the database.
     * @param messageId
     *         The database ID of the message to delete.
     */
    private void deleteMessageRow(SQLiteDatabase db, long messageId) {
        String[] idArg = { Long.toString(messageId) };

        // Delete the message
        db.delete("messages", "id = ?", idArg);

        // Delete row in 'threads' table
        // TODO: create trigger for 'messages' table to get rid of the row in 'threads' table
        db.delete("threads", "message_id = ?", idArg);
        db.delete("messages", "id = ?", new String[] { Long.toString(messageId) });
    }

    void deleteFulltextIndexEntry(SQLiteDatabase db, long messageId) {
+5 −0
Original line number Diff line number Diff line
@@ -71,6 +71,11 @@ interface MessageStore {
     */
    fun getLastUid(folderId: Long): Long?

    /**
     * Remove messages from the store.
     */
    fun destroyMessages(folderId: Long, messageServerIds: Collection<String>)

    /**
     * Create folders.
     */
+2 −1
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ import timber.log.Timber;


class StoreSchemaDefinition implements SchemaDefinition {
    static final int DB_VERSION = 78;
    static final int DB_VERSION = 79;

    private final MigrationsHelper migrationsHelper;

@@ -243,6 +243,7 @@ class StoreSchemaDefinition implements SchemaDefinition {
                "BEGIN " +
                "DELETE FROM message_parts WHERE root = OLD.message_part_id; " +
                "DELETE FROM messages_fulltext WHERE docid = OLD.id; " +
                "DELETE FROM threads WHERE message_id = OLD.id; " +
                "END");

        db.execSQL("DROP TABLE IF EXISTS messages_fulltext");
+24 −0
Original line number Diff line number Diff line
package com.fsck.k9.storage.messages

import com.fsck.k9.K9
import com.fsck.k9.mailstore.StorageManager
import com.fsck.k9.mailstore.StorageManager.InternalStorageProvider
import java.io.File
import timber.log.Timber

class AttachmentFileManager(
    private val storageManager: StorageManager,
    private val accountUuid: String
) {
    fun deleteFile(messagePartId: Long) {
        val file = getAttachmentFile(messagePartId.toString())
        if (file.exists() && !file.delete() && K9.isDebugLoggingEnabled) {
            Timber.w("Couldn't delete message part file: %s", file.absolutePath)
        }
    }

    private fun getAttachmentFile(messagePartId: String): File {
        val attachmentDirectory = storageManager.getAttachmentDirectory(accountUuid, InternalStorageProvider.ID)
        return File(attachmentDirectory, messagePartId)
    }
}
Loading