Repository: thundernest/k-9
Issue: crash when edit email setup details

**Describe the bug**
when email username or password is wrong, we click on edit details. then edit email password and click on next and suddenly app crashes

**To Reproduce**
Steps to reproduce the behavior:
1. open application
2. enter wrong email address or password
3. error dialog shows and we click on edit details
4. fix email address and password and click on next
5. app crash

**Expected behavior**
it should go to next step without any problem

**Screenshots**
...

**Environment (please complete the following information):**
- K-9 Mail version: 5.723-SNAPSHOT (debug)
- Android version: 7
- Device: Android emulator
- Account type: IMAP

**Additional context**
...

**Logs**
Please take some time to [retrieve logs](https://github.com/k9mail/k-9/wiki/LoggingErrors) and attach them here:

```
2020-10-27 14:24:33.556 4705-4705/com.fsck.k9.debug D/AndroidRuntime: Shutting down VM
2020-10-27 14:24:33.557 4705-4705/com.fsck.k9.debug E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.fsck.k9.debug, PID: 4705
    java.lang.IllegalStateException: Outbox folder was already set up
        at com.fsck.k9.mailstore.SpecialLocalFoldersCreator.createSpecialLocalFolders(SpecialLocalFoldersCreator.kt:13)
        at com.fsck.k9.activity.setup.AccountSetupBasics.finishAutoSetup(AccountSetupBasics.java:267)
        at com.fsck.k9.activity.setup.AccountSetupBasics.onNext(AccountSetupBasics.java:313)
        at com.fsck.k9.activity.setup.AccountSetupBasics.onClick(AccountSetupBasics.java:384)
        at android.view.View.performClick(View.java:5610)
        at android.view.View$PerformClick.run(View.java:22265)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6077)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
```

Changed files:
app/core/src/main/java/com/fsck/k9/mailstore/SpecialLocalFoldersCreator.kt

diff --git a/app/core/src/main/java/com/fsck/k9/mailstore/SpecialLocalFoldersCreator.kt b/app/core/src/main/java/com/fsck/k9/mailstore/SpecialLocalFoldersCreator.kt
index 0bc048962..ab05c3bcc 100644
--- a/app/core/src/main/java/com/fsck/k9/mailstore/SpecialLocalFoldersCreator.kt
+++ b/app/core/src/main/java/com/fsck/k9/mailstore/SpecialLocalFoldersCreator.kt
@@ -4,31 +4,46 @@ import com.fsck.k9.Account
 import com.fsck.k9.Account.SpecialFolderSelection
 import com.fsck.k9.Preferences
 import com.fsck.k9.mail.FolderType
+import timber.log.Timber
 
 class SpecialLocalFoldersCreator(
     private val preferences: Preferences,
     private val localStoreProvider: LocalStoreProvider
 ) {
+    // TODO: When rewriting the account setup code make sure this method is only called once. Until then this can be
+    //  called multiple times and we have to make sure folders are only created once.
     fun createSpecialLocalFolders(account: Account) {
-        check(account.outboxFolderId == null) { "Outbox folder was already set up" }
+        Timber.d("Creating special local folders")
 
         val localStore = localStoreProvider.getInstance(account)
 
-        account.outboxFolderId = localStore.createLocalFolder(OUTBOX_FOLDER_NAME, FolderType.OUTBOX)
+        if (account.outboxFolderId == null) {
+            account.outboxFolderId = localStore.createLocalFolder(OUTBOX_FOLDER_NAME, FolderType.OUTBOX)
+        } else {
+            Timber.d("Outbox folder was already set up")
+        }
 
         if (account.isPop3()) {
-            check(account.draftsFolderId == null) { "Drafts folder was already set up" }
-            check(account.sentFolderId == null) { "Sent folder was already set up" }
-            check(account.trashFolderId == null) { "Trash folder was already set up" }
-
-            val draftsFolderId = localStore.createLocalFolder(DRAFTS_FOLDER_NAME, FolderType.DRAFTS)
-            account.setDraftsFolderId(draftsFolderId, SpecialFolderSelection.MANUAL)
-
-            val sentFolderId = localStore.createLocalFolder(SENT_FOLDER_NAME, FolderType.SENT)
-            account.setSentFolderId(sentFolderId, SpecialFolderSelection.MANUAL)
-
-            val trashFolderId = localStore.createLocalFolder(TRASH_FOLDER_NAME, FolderType.TRASH)
-            account.setTrashFolderId(trashFolderId, SpecialFolderSelection.MANUAL)
+            if (account.draftsFolderId == null) {
+                val draftsFolderId = localStore.createLocalFolder(DRAFTS_FOLDER_NAME, FolderType.DRAFTS)
+                account.setDraftsFolderId(draftsFolderId, SpecialFolderSelection.MANUAL)
+            } else {
+                Timber.d("Drafts folder was already set up")
+            }
+
+            if (account.sentFolderId == null) {
+                val sentFolderId = localStore.createLocalFolder(SENT_FOLDER_NAME, FolderType.SENT)
+                account.setSentFolderId(sentFolderId, SpecialFolderSelection.MANUAL)
+            } else {
+                Timber.d("Sent folder was already set up")
+            }
+
+            if (account.trashFolderId == null) {
+                val trashFolderId = localStore.createLocalFolder(TRASH_FOLDER_NAME, FolderType.TRASH)
+                account.setTrashFolderId(trashFolderId, SpecialFolderSelection.MANUAL)
+            } else {
+                Timber.d("Trash folder was already set up")
+            }
         }
 
         preferences.saveAccount(account)