Repository: thundernest/k-9
Issue: K-9 fails to import settings and then crashes

### Checklist

- [X] I have used the search function to see if someone else has already submitted the same bug report.
- [X] I will describe the problem with as much detail as possible.

### App version

5.914 (git 0e78b8aae6bda14aca094298813b50759b50e8cb)

### Where did you get the app from?

Built from source 

### Android version

API level 29

### Device model

Emulator

### Steps to reproduce

Export settings and immediately re-import. You get a toast "import failed".
Clearing the app data and trying to import the settings file also fails.


There is nothing particularly interesting about the settings, it's a standard IMAP/SMTP setup. The emulator is a bit slow due to RAM constraints so I'm wondering if there is a race when writing the newly created accounts to storage.

### Expected behavior

K-9 should import the settings

### Actual behavior

K-9 fails to import the settings with an error message. If you keep trying to import, K-9 completely crashes.

### Logs

logcat says
```
2022-04-04 16:32:55.897 7076-7076/com.fsck.k9.debug E/SettingsImportViewModel$startImportSettings: Error importing settings
    com.fsck.k9.preferences.SettingsImportExportException: java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter account
        at com.fsck.k9.preferences.SettingsImporter.importSettings(SettingsImporter.java:298)
        at com.fsck.k9.ui.settings.import.SettingsImportViewModel.importSettings(SettingsImportViewModel.kt:363)
        at com.fsck.k9.ui.settings.import.SettingsImportViewModel.access$importSettings(SettingsImportViewModel.kt:28)
        at com.fsck.k9.ui.settings.import.SettingsImportViewModel$startImportSettings$1$1$1.invokeSuspend(SettingsImportViewModel.kt:282)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:39)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
     Caused by: java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter account
        at com.fsck.k9.mailstore.SpecialLocalFoldersCreator.createSpecialLocalFolders(Unknown Source:2)
        at com.fsck.k9.preferences.SettingsImporter.importSettings(SettingsImporter.java:287)
        at com.fsck.k9.ui.settings.import.SettingsImportViewModel.importSettings(SettingsImportViewModel.kt:363) 
        at com.fsck.k9.ui.settings.import.SettingsImportViewModel.access$importSettings(SettingsImportViewModel.kt:28) 
        at com.fsck.k9.ui.settings.import.SettingsImportViewModel$startImportSettings$1$1$1.invokeSuspend(SettingsImportViewModel.kt:282) 
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) 
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) 
        at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:39) 
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95) 
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571) 
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750) 
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678) 
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665) 
```

Changed files:
app/core/src/main/java/com/fsck/k9/preferences/SettingsImporter.java

diff --git a/app/core/src/main/java/com/fsck/k9/preferences/SettingsImporter.java b/app/core/src/main/java/com/fsck/k9/preferences/SettingsImporter.java
index 1b28729f3..661ab013c 100644
--- a/app/core/src/main/java/com/fsck/k9/preferences/SettingsImporter.java
+++ b/app/core/src/main/java/com/fsck/k9/preferences/SettingsImporter.java
@@ -229,7 +229,7 @@ public class SettingsImporter {
                                         editor = preferences.createStorageEditor();
 
                                         String newUuid = importResult.imported.uuid;
-                                        String oldAccountUuids = storage.getString("accountUuids", "");
+                                        String oldAccountUuids = preferences.getStorage().getString("accountUuids", "");
                                         String newAccountUuids = (oldAccountUuids.length() > 0) ?
                                                 oldAccountUuids + "," + newUuid : newUuid;