From 322c8be4ae6f27f2ceb3b3c88b18547c2780f95b Mon Sep 17 00:00:00 2001 From: cketti Date: Mon, 21 Mar 2022 18:45:45 +0100 Subject: [PATCH] Avoid crash when trying to open non-existent folder For now we load the default folder instead. --- .../java/com/fsck/k9/activity/MessageList.kt | 5 ++++ .../fsck/k9/fragment/MessageListFragment.kt | 26 +++++++++++-------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt index da6bce71a..df2d18090 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt @@ -1639,6 +1639,11 @@ open class MessageList : permissionUiHelper.requestPermission(permission) } + override fun onFolderNotFoundError() { + val defaultFolderId = defaultFolderProvider.getDefaultFolder(account!!) + openFolderImmediately(defaultFolderId) + } + private enum class DisplayMode { MESSAGE_LIST, MESSAGE_VIEW, SPLIT_VIEW } diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/fragment/MessageListFragment.kt b/app/ui/legacy/src/main/java/com/fsck/k9/fragment/MessageListFragment.kt index c1cc821f1..237a6a408 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/fragment/MessageListFragment.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/fragment/MessageListFragment.kt @@ -147,7 +147,7 @@ class MessageListFragment : super.onCreate(savedInstanceState) restoreInstanceState(savedInstanceState) - decodeArguments() + decodeArguments() ?: return viewModel.getMessageListLiveData().observe(this) { messageListInfo: MessageListInfo -> setMessageList(messageListInfo) @@ -177,7 +177,7 @@ class MessageListFragment : listView.onRestoreInstanceState(savedListState) } - private fun decodeArguments() { + private fun decodeArguments(): MessageListFragment? { val arguments = requireArguments() showingThreadedList = arguments.getBoolean(ARG_THREADED_LIST, false) isThreadDisplay = arguments.getBoolean(ARG_IS_THREAD_DISPLAY, false) @@ -198,10 +198,17 @@ class MessageListFragment : isSingleFolderMode = false if (isSingleAccountMode && localSearch.folderIds.size == 1) { - isSingleFolderMode = true - val folderId = localSearch.folderIds[0] - currentFolder = getFolderInfoHolder(folderId, account!!) + try { + val folderId = localSearch.folderIds[0] + currentFolder = getFolderInfoHolder(folderId, account!!) + isSingleFolderMode = true + } catch (e: MessagingException) { + fragmentListener.onFolderNotFoundError() + return null + } } + + return this } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -458,12 +465,8 @@ class MessageListFragment : ) private fun getFolderInfoHolder(folderId: Long, account: Account): FolderInfoHolder { - return try { - val localFolder = MlfUtils.getOpenFolder(folderId, account) - FolderInfoHolder(folderNameFormatter, localFolder, account) - } catch (e: MessagingException) { - throw RuntimeException(e) - } + val localFolder = MlfUtils.getOpenFolder(folderId, account) + return FolderInfoHolder(folderNameFormatter, localFolder, account) } override fun onResume() { @@ -1926,6 +1929,7 @@ class MessageListFragment : fun remoteSearchStarted() fun goBack() fun updateMenu() + fun onFolderNotFoundError() companion object { const val MAX_PROGRESS = 10000