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

Commit 769d658e authored by cketti's avatar cketti
Browse files

Correctly persist message download state

Add the flag X_DOWNLOADED_FULL when the message has been downloaded completely, the flag X_DOWNLOADED_PARTIAL when only the text of a message has been downloaded, and set no additional flag when only the envelope and structure of the message has been downloaded. The latter happens when we fetch remote search results.
parent a3d6fd7a
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -7,6 +7,7 @@ import com.fsck.k9.controller.MessagingControllerCommands.PendingAppend
import com.fsck.k9.controller.MessagingControllerCommands.PendingReplace
import com.fsck.k9.controller.MessagingControllerCommands.PendingReplace
import com.fsck.k9.mail.FetchProfile
import com.fsck.k9.mail.FetchProfile
import com.fsck.k9.mail.Message
import com.fsck.k9.mail.Message
import com.fsck.k9.mail.MessageDownloadState
import com.fsck.k9.mail.MessagingException
import com.fsck.k9.mail.MessagingException
import com.fsck.k9.mailstore.LocalFolder
import com.fsck.k9.mailstore.LocalFolder
import com.fsck.k9.mailstore.LocalMessage
import com.fsck.k9.mailstore.LocalMessage
@@ -164,6 +165,6 @@ internal class DraftOperations(
    }
    }


    private fun Message.toSaveMessageData(subject: String?): SaveMessageData {
    private fun Message.toSaveMessageData(subject: String?): SaveMessageData {
        return saveMessageDataCreator.createSaveMessageData(this, partialMessage = false, subject)
        return saveMessageDataCreator.createSaveMessageData(this, MessageDownloadState.FULL, subject)
    }
    }
}
}
+3 −1
Original line number Original line Diff line number Diff line
@@ -67,6 +67,7 @@ import com.fsck.k9.mailstore.LocalFolder;
import com.fsck.k9.mailstore.LocalMessage;
import com.fsck.k9.mailstore.LocalMessage;
import com.fsck.k9.mailstore.LocalStore;
import com.fsck.k9.mailstore.LocalStore;
import com.fsck.k9.mailstore.LocalStoreProvider;
import com.fsck.k9.mailstore.LocalStoreProvider;
import com.fsck.k9.mail.MessageDownloadState;
import com.fsck.k9.mailstore.MessageStore;
import com.fsck.k9.mailstore.MessageStore;
import com.fsck.k9.mailstore.MessageStoreManager;
import com.fsck.k9.mailstore.MessageStoreManager;
import com.fsck.k9.mailstore.OutboxState;
import com.fsck.k9.mailstore.OutboxState;
@@ -1375,7 +1376,8 @@ public class MessagingController {
            message.setFlag(Flag.SEEN, true);
            message.setFlag(Flag.SEEN, true);


            MessageStore messageStore = messageStoreManager.getMessageStore(account);
            MessageStore messageStore = messageStoreManager.getMessageStore(account);
            SaveMessageData messageData = saveMessageDataCreator.createSaveMessageData(message, false, plaintextSubject);
            SaveMessageData messageData = saveMessageDataCreator.createSaveMessageData(
                    message, MessageDownloadState.FULL, plaintextSubject);
            long messageId = messageStore.saveLocalMessage(outboxFolderId, messageData, null);
            long messageId = messageStore.saveLocalMessage(outboxFolderId, messageData, null);


            LocalStore localStore = localStoreProvider.getInstance(account);
            LocalStore localStore = localStoreProvider.getInstance(account);
+3 −10
Original line number Original line Diff line number Diff line
@@ -4,6 +4,7 @@ import com.fsck.k9.backend.api.BackendFolder
import com.fsck.k9.backend.api.BackendFolder.MoreMessages
import com.fsck.k9.backend.api.BackendFolder.MoreMessages
import com.fsck.k9.mail.Flag
import com.fsck.k9.mail.Flag
import com.fsck.k9.mail.Message
import com.fsck.k9.mail.Message
import com.fsck.k9.mail.MessageDownloadState
import java.util.Date
import java.util.Date
import com.fsck.k9.mailstore.MoreMessages as StoreMoreMessages
import com.fsck.k9.mailstore.MoreMessages as StoreMoreMessages


@@ -85,18 +86,10 @@ class K9BackendFolder(
        messageStore.setMessageFlag(folderId, messageServerId, flag, value)
        messageStore.setMessageFlag(folderId, messageServerId, flag, value)
    }
    }


    override fun saveCompleteMessage(message: Message) {
    override fun saveMessage(message: Message, downloadState: MessageDownloadState) {
        saveMessage(message, partialMessage = false)
    }

    override fun savePartialMessage(message: Message) {
        saveMessage(message, partialMessage = true)
    }

    private fun saveMessage(message: Message, partialMessage: Boolean) {
        requireMessageServerId(message)
        requireMessageServerId(message)


        val messageData = saveMessageDataCreator.createSaveMessageData(message, partialMessage)
        val messageData = saveMessageDataCreator.createSaveMessageData(message, downloadState)
        messageStore.saveRemoteMessage(folderId, message.uid, messageData)
        messageStore.saveRemoteMessage(folderId, message.uid, messageData)
    }
    }


+2 −1
Original line number Original line Diff line number Diff line
package com.fsck.k9.mailstore
package com.fsck.k9.mailstore


import com.fsck.k9.mail.Message
import com.fsck.k9.mail.Message
import com.fsck.k9.mail.MessageDownloadState
import com.fsck.k9.message.extractors.PreviewResult
import com.fsck.k9.message.extractors.PreviewResult


data class SaveMessageData(
data class SaveMessageData(
@@ -8,7 +9,7 @@ data class SaveMessageData(
    val subject: String?,
    val subject: String?,
    val date: Long,
    val date: Long,
    val internalDate: Long,
    val internalDate: Long,
    val partialMessage: Boolean,
    val downloadState: MessageDownloadState,
    val attachmentCount: Int,
    val attachmentCount: Int,
    val previewResult: PreviewResult,
    val previewResult: PreviewResult,
    val textForSearchIndex: String? = null,
    val textForSearchIndex: String? = null,
+8 −3
Original line number Original line Diff line number Diff line
@@ -2,6 +2,7 @@ package com.fsck.k9.mailstore


import com.fsck.k9.crypto.EncryptionExtractor
import com.fsck.k9.crypto.EncryptionExtractor
import com.fsck.k9.mail.Message
import com.fsck.k9.mail.Message
import com.fsck.k9.mail.MessageDownloadState
import com.fsck.k9.message.extractors.AttachmentCounter
import com.fsck.k9.message.extractors.AttachmentCounter
import com.fsck.k9.message.extractors.MessageFulltextCreator
import com.fsck.k9.message.extractors.MessageFulltextCreator
import com.fsck.k9.message.extractors.MessagePreviewCreator
import com.fsck.k9.message.extractors.MessagePreviewCreator
@@ -12,7 +13,11 @@ class SaveMessageDataCreator(
    private val messageFulltextCreator: MessageFulltextCreator,
    private val messageFulltextCreator: MessageFulltextCreator,
    private val attachmentCounter: AttachmentCounter
    private val attachmentCounter: AttachmentCounter
) {
) {
    fun createSaveMessageData(message: Message, partialMessage: Boolean, subject: String? = null): SaveMessageData {
    fun createSaveMessageData(
        message: Message,
        downloadState: MessageDownloadState,
        subject: String? = null
    ): SaveMessageData {
        val now = System.currentTimeMillis()
        val now = System.currentTimeMillis()
        val date = message.sentDate?.time ?: now
        val date = message.sentDate?.time ?: now
        val internalDate = message.internalDate?.time ?: now
        val internalDate = message.internalDate?.time ?: now
@@ -25,7 +30,7 @@ class SaveMessageDataCreator(
                subject = displaySubject,
                subject = displaySubject,
                date = date,
                date = date,
                internalDate = internalDate,
                internalDate = internalDate,
                partialMessage = partialMessage,
                downloadState = downloadState,
                attachmentCount = encryptionResult.attachmentCount,
                attachmentCount = encryptionResult.attachmentCount,
                previewResult = encryptionResult.previewResult,
                previewResult = encryptionResult.previewResult,
                textForSearchIndex = encryptionResult.textForSearchIndex,
                textForSearchIndex = encryptionResult.textForSearchIndex,
@@ -37,7 +42,7 @@ class SaveMessageDataCreator(
                subject = displaySubject,
                subject = displaySubject,
                date = date,
                date = date,
                internalDate = internalDate,
                internalDate = internalDate,
                partialMessage = partialMessage,
                downloadState = downloadState,
                attachmentCount = attachmentCounter.getAttachmentCount(message),
                attachmentCount = attachmentCounter.getAttachmentCount(message),
                previewResult = messagePreviewCreator.createPreview(message),
                previewResult = messagePreviewCreator.createPreview(message),
                textForSearchIndex = messageFulltextCreator.createFulltext(message),
                textForSearchIndex = messageFulltextCreator.createFulltext(message),
Loading