diff --git a/legacy/core/src/main/java/com/fsck/k9/preferences/SettingsImporter.kt b/legacy/core/src/main/java/com/fsck/k9/preferences/SettingsImporter.kt index dfe5c6d6494..b9851e6edc9 100644 --- a/legacy/core/src/main/java/com/fsck/k9/preferences/SettingsImporter.kt +++ b/legacy/core/src/main/java/com/fsck/k9/preferences/SettingsImporter.kt @@ -46,7 +46,10 @@ class SettingsImporter internal constructor( ) } - // TODO: throw exception if neither global settings nor account settings could be found + val hasAccountsWithSettings = imported.accounts.any { it.settings != null } + if(!globalSettings && !hasAccountsWithSettings) + throw SettingsImportExportException("Neither global settings nor account settings could be found") + return ImportContents(globalSettings, accounts) } catch (e: SettingsImportExportException) { throw e diff --git a/legacy/core/src/test/java/com/fsck/k9/preferences/SettingsImporterTest.kt b/legacy/core/src/test/java/com/fsck/k9/preferences/SettingsImporterTest.kt index 292521897f8..79fcb3b1fd0 100644 --- a/legacy/core/src/test/java/com/fsck/k9/preferences/SettingsImporterTest.kt +++ b/legacy/core/src/test/java/com/fsck/k9/preferences/SettingsImporterTest.kt @@ -269,6 +269,9 @@ class SettingsImporterTest : K9RobolectricTest() { user@gmail.com + + b + @@ -302,6 +305,9 @@ class SettingsImporterTest : K9RobolectricTest() { user@gmail.com + + b + @@ -320,4 +326,29 @@ class SettingsImporterTest : K9RobolectricTest() { } } } + + @Test + fun `getImportStreamContents() should throw when no setting is present in inputStream`() { + val accountUuid = UUID.randomUUID().toString() + val inputStream = + """ + + + + + + + user@gmail.com + + + + + + """.trimIndent().byteInputStream() + + assertFailure { + settingsImporter.getImportStreamContents(inputStream) + }.isInstanceOf() + + } }