diff --git a/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java b/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java index 9996054bfb8..620cf0cf937 100644 --- a/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java +++ b/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java @@ -1886,8 +1886,13 @@ public void expunge(Account account, long folderId) { public void deleteDraft(final Account account, long id) { LocalFolder localFolder = null; try { + Long folderId = account.getDraftsFolderId(); + if (folderId == null) { + Timber.w("No Drafts folder configured. Can't delete draft."); + return; + } + LocalStore localStore = localStoreProvider.getInstance(account); - long folderId = account.getDraftsFolderId(); localFolder = localStore.getFolder(folderId); localFolder.open(); String uid = localFolder.getMessageUidById(id); @@ -2135,8 +2140,13 @@ public void emptyTrash(final Account account, MessagingListener listener) { public void run() { LocalFolder localFolder = null; try { + Long trashFolderId = account.getTrashFolderId(); + if (trashFolderId == null) { + Timber.w("No Trash folder configured. Can't empty trash."); + return; + } + LocalStore localStore = localStoreProvider.getInstance(account); - long trashFolderId = account.getTrashFolderId(); localFolder = localStore.getFolder(trashFolderId); localFolder.open(); String trashFolderServerId = localFolder.getServerId(); @@ -2567,8 +2577,13 @@ public void deleteAccount(Account account) { public Message saveDraft(final Account account, final Message message, long existingDraftId, String plaintextSubject, boolean saveRemotely) { LocalMessage localMessage = null; try { + Long draftsFolderId = account.getDraftsFolderId(); + if (draftsFolderId == null) { + throw new IllegalStateException("No Drafts folder configured"); + } + LocalStore localStore = localStoreProvider.getInstance(account); - LocalFolder localFolder = localStore.getFolder(account.getDraftsFolderId()); + LocalFolder localFolder = localStore.getFolder(draftsFolderId); localFolder.open(); if (existingDraftId != INVALID_MESSAGE_ID) { diff --git a/app/core/src/main/java/com/fsck/k9/search/AccountSearchConditions.kt b/app/core/src/main/java/com/fsck/k9/search/AccountSearchConditions.kt index 70c5731ecc7..bf19c3d3d2d 100644 --- a/app/core/src/main/java/com/fsck/k9/search/AccountSearchConditions.kt +++ b/app/core/src/main/java/com/fsck/k9/search/AccountSearchConditions.kt @@ -75,7 +75,9 @@ class AccountSearchConditions { excludeSpecialFolder(search, account.spamFolderId) excludeSpecialFolder(search, account.outboxFolderId) excludeSpecialFolder(search, account.sentFolderId) - search.or(SearchCondition(SearchField.FOLDER, Attribute.EQUALS, account.inboxFolderId!!.toString())) + account.inboxFolderId?.let { inboxFolderId -> + search.or(SearchCondition(SearchField.FOLDER, Attribute.EQUALS, inboxFolderId.toString())) + } } /** @@ -97,7 +99,9 @@ class AccountSearchConditions { excludeSpecialFolder(search, account.trashFolderId) excludeSpecialFolder(search, account.spamFolderId) excludeSpecialFolder(search, account.outboxFolderId) - search.or(SearchCondition(SearchField.FOLDER, Attribute.EQUALS, account.inboxFolderId.toString())) + account.inboxFolderId?.let { inboxFolderId -> + search.or(SearchCondition(SearchField.FOLDER, Attribute.EQUALS, inboxFolderId.toString())) + } } private fun excludeSpecialFolder(search: LocalSearch, folderId: Long?) { diff --git a/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java b/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java index 05340c0c7e2..38ce2a50123 100644 --- a/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java +++ b/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java @@ -1244,7 +1244,8 @@ public void openMessage(MessageReference messageReference) { Account account = preferences.getAccount(messageReference.getAccountUuid()); long folderId = messageReference.getFolderId(); - if (folderId == account.getDraftsFolderId()) { + Long draftsFolderId = account.getDraftsFolderId(); + if (draftsFolderId != null && folderId == draftsFolderId) { MessageActions.actionEditDraft(this, messageReference); } else { if (messageListFragment != null) { diff --git a/app/ui/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.java b/app/ui/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.java index 012bbdfc9b3..45e7efee619 100644 --- a/app/ui/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.java +++ b/app/ui/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.java @@ -321,8 +321,8 @@ private void delete() { } } - public void onRefile(long dstFolderId) { - if (!mController.isMoveCapable(mAccount)) { + public void onRefile(Long dstFolderId) { + if (dstFolderId == null || !mController.isMoveCapable(mAccount)) { return; } if (!mController.isMoveCapable(mMessageReference)) { @@ -331,7 +331,7 @@ public void onRefile(long dstFolderId) { return; } - if (dstFolderId == mAccount.getSpamFolderId() && K9.isConfirmSpam()) { + if (dstFolderId.equals(mAccount.getSpamFolderId()) && K9.isConfirmSpam()) { destinationFolderId = dstFolderId; showDialog(R.id.dialog_confirm_spam); } else {