Merge pull request #6435 from thundernest/fix_getMessageServerId_crash
Don't throw when calling `MessageStore.getMessageServerId()`
This commit is contained in:
commit
54a7ee1c53
6 changed files with 21 additions and 16 deletions
|
@ -75,9 +75,11 @@ internal class DraftOperations(
|
|||
messagingController.queuePendingCommand(account, command)
|
||||
} else {
|
||||
val fakeMessageServerId = messageStore.getMessageServerId(messageId)
|
||||
if (fakeMessageServerId != null) {
|
||||
val command = PendingAppend.create(folderId, fakeMessageServerId)
|
||||
messagingController.queuePendingCommand(account, command)
|
||||
}
|
||||
}
|
||||
|
||||
messagingController.processPendingCommands(account)
|
||||
|
||||
|
|
|
@ -1615,11 +1615,13 @@ public class MessagingController {
|
|||
|
||||
if (!sentFolder.isLocalOnly()) {
|
||||
String destinationUid = messageStore.getMessageServerId(destinationMessageId);
|
||||
if (destinationUid != null) {
|
||||
PendingCommand command = PendingAppend.create(sentFolderId, destinationUid);
|
||||
queuePendingCommand(account, command);
|
||||
processPendingCommands(account);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (MessagingListener listener : getListeners()) {
|
||||
listener.folderStatusChanged(account, account.getOutboxFolderId());
|
||||
|
@ -1901,10 +1903,11 @@ public class MessagingController {
|
|||
|
||||
MessageStore messageStore = messageStoreManager.getMessageStore(account);
|
||||
String messageServerId = messageStore.getMessageServerId(messageId);
|
||||
if (messageServerId != null) {
|
||||
MessageReference messageReference = new MessageReference(account.getUuid(), folderId, messageServerId);
|
||||
|
||||
deleteMessage(messageReference);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteThreads(final List<MessageReference> messages) {
|
||||
actOnMessagesGroupedByAccountAndFolder(messages, (account, messageFolder, accountMessages) -> {
|
||||
|
|
|
@ -91,7 +91,7 @@ interface MessageStore {
|
|||
/**
|
||||
* Retrieve the server ID for a given message.
|
||||
*/
|
||||
fun getMessageServerId(messageId: Long): String
|
||||
fun getMessageServerId(messageId: Long): String?
|
||||
|
||||
/**
|
||||
* Retrieve the server IDs for the given messages.
|
||||
|
|
|
@ -78,7 +78,7 @@ class K9MessageStore(
|
|||
updateMessageOperations.clearNewMessageState()
|
||||
}
|
||||
|
||||
override fun getMessageServerId(messageId: Long): String {
|
||||
override fun getMessageServerId(messageId: Long): String? {
|
||||
return retrieveMessageOperations.getMessageServerId(messageId)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import androidx.core.database.getLongOrNull
|
|||
import com.fsck.k9.K9
|
||||
import com.fsck.k9.mail.Flag
|
||||
import com.fsck.k9.mail.Header
|
||||
import com.fsck.k9.mail.MessagingException
|
||||
import com.fsck.k9.mail.internet.MimeHeader
|
||||
import com.fsck.k9.mail.message.MessageHeaderParser
|
||||
import com.fsck.k9.mailstore.LockableDatabase
|
||||
|
@ -13,7 +12,7 @@ import java.util.Date
|
|||
|
||||
internal class RetrieveMessageOperations(private val lockableDatabase: LockableDatabase) {
|
||||
|
||||
fun getMessageServerId(messageId: Long): String {
|
||||
fun getMessageServerId(messageId: Long): String? {
|
||||
return lockableDatabase.execute(false) { database ->
|
||||
database.query(
|
||||
"messages",
|
||||
|
@ -25,7 +24,7 @@ internal class RetrieveMessageOperations(private val lockableDatabase: LockableD
|
|||
if (cursor.moveToFirst()) {
|
||||
cursor.getString(0)
|
||||
} else {
|
||||
throw MessagingException("Message [ID: $messageId] not found in database")
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.fsck.k9.storage.messages
|
|||
|
||||
import com.fsck.k9.mail.Flag
|
||||
import com.fsck.k9.mail.Header
|
||||
import com.fsck.k9.mail.MessagingException
|
||||
import com.fsck.k9.mail.crlf
|
||||
import com.fsck.k9.storage.RobolectricTest
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
|
@ -14,9 +13,11 @@ class RetrieveMessageOperationsTest : RobolectricTest() {
|
|||
private val lockableDatabase = createLockableDatabaseMock(sqliteDatabase)
|
||||
private val retrieveMessageOperations = RetrieveMessageOperations(lockableDatabase)
|
||||
|
||||
@Test(expected = MessagingException::class)
|
||||
@Test
|
||||
fun `get message server id of non-existent message`() {
|
||||
retrieveMessageOperations.getMessageServerId(42)
|
||||
val messageServerId = retrieveMessageOperations.getMessageServerId(42)
|
||||
|
||||
assertThat(messageServerId).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue