Skip to content

Commit

Permalink
Add "demo" backend
Browse files Browse the repository at this point in the history
  • Loading branch information
cketti committed Sep 23, 2021
1 parent 8350a62 commit eae910f
Show file tree
Hide file tree
Showing 31 changed files with 1,025 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/k9mail/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {
implementation project(":backend:imap")
implementation project(":backend:pop3")
implementation project(":backend:webdav")
debugImplementation project(":backend:demo")

implementation "androidx.appcompat:appcompat:${versions.androidxAppCompat}"
implementation "androidx.core:core-ktx:${versions.androidxCore}"
Expand Down
12 changes: 12 additions & 0 deletions app/k9mail/src/debug/java/app/k9mail/dev/DebugConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package app.k9mail.dev

import org.koin.core.module.Module
import org.koin.core.scope.Scope

fun Scope.developmentBackends() = mapOf(
"demo" to get<DemoBackendFactory>()
)

fun Module.developmentModuleAdditions() {
single { DemoBackendFactory(backendStorageFactory = get()) }
}
14 changes: 14 additions & 0 deletions app/k9mail/src/debug/java/app/k9mail/dev/DemoBackendFactory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package app.k9mail.dev

import app.k9mail.backend.demo.DemoBackend
import com.fsck.k9.Account
import com.fsck.k9.backend.BackendFactory
import com.fsck.k9.backend.api.Backend
import com.fsck.k9.mailstore.K9BackendStorageFactory

class DemoBackendFactory(private val backendStorageFactory: K9BackendStorageFactory) : BackendFactory {
override fun createBackend(account: Account): Backend {
val backendStorage = backendStorageFactory.createBackendStorage(account)
return DemoBackend(backendStorage)
}
}
6 changes: 5 additions & 1 deletion app/k9mail/src/main/java/com/fsck/k9/backends/KoinModule.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.fsck.k9.backends

import app.k9mail.dev.developmentBackends
import app.k9mail.dev.developmentModuleAdditions
import com.fsck.k9.backend.BackendManager
import com.fsck.k9.backend.imap.BackendIdleRefreshManager
import com.fsck.k9.backend.imap.SystemAlarmManager
Expand All @@ -13,7 +15,7 @@ val backendsModule = module {
"imap" to get<ImapBackendFactory>(),
"pop3" to get<Pop3BackendFactory>(),
"webdav" to get<WebDavBackendFactory>()
)
) + developmentBackends()
)
}
single {
Expand All @@ -30,4 +32,6 @@ val backendsModule = module {
single<IdleRefreshManager> { BackendIdleRefreshManager(alarmManager = get()) }
single { Pop3BackendFactory(get(), get()) }
single { WebDavBackendFactory(get(), get(), get()) }

developmentModuleAdditions()
}
9 changes: 9 additions & 0 deletions app/k9mail/src/release/java/app/k9mail/dev/ReleaseConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package app.k9mail.dev

import com.fsck.k9.backend.BackendFactory
import org.koin.core.module.Module
import org.koin.core.scope.Scope

fun Scope.developmentBackends() = emptyMap<String, BackendFactory>()

fun Module.developmentModuleAdditions() = Unit
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.fsck.k9.ui.settings

import com.fsck.k9.mail.AuthType
import com.fsck.k9.mail.ConnectionSecurity
import com.fsck.k9.mail.ServerSettings
import com.fsck.k9.ui.ConnectionSettings

object ExtraAccountDiscovery {
@JvmStatic
fun discover(email: String): ConnectionSettings? {
return if (email.endsWith("@k9mail.example")) {
val serverSettings = ServerSettings(
type = "demo",
host = "irrelevant",
port = 23,
connectionSecurity = ConnectionSecurity.SSL_TLS_REQUIRED,
authenticationType = AuthType.AUTOMATIC,
username = "irrelevant",
password = "irrelevant",
clientCertificateAlias = null
)
ConnectionSettings(incoming = serverSettings, outgoing = serverSettings)
} else {
null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class AccountCreator(private val preferences: Preferences, private val resources
Protocols.IMAP -> DeletePolicy.ON_DELETE
Protocols.POP3 -> DeletePolicy.NEVER
Protocols.WEBDAV -> DeletePolicy.ON_DELETE
"demo" -> DeletePolicy.ON_DELETE
else -> throw AssertionError("Unhandled case: $type")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.fsck.k9.mailstore.SpecialLocalFoldersCreator;
import com.fsck.k9.ui.R;
import com.fsck.k9.ui.ConnectionSettings;
import com.fsck.k9.ui.settings.ExtraAccountDiscovery;
import com.fsck.k9.view.ClientCertificateSpinner;
import com.fsck.k9.view.ClientCertificateSpinner.OnClientCertificateChangedListener;
import com.google.android.material.textfield.TextInputEditText;
Expand Down Expand Up @@ -280,6 +281,12 @@ private void onNext() {

String email = mEmailView.getText().toString();

ConnectionSettings extraConnectionSettings = ExtraAccountDiscovery.discover(email);
if (extraConnectionSettings != null) {
finishAutoSetup(extraConnectionSettings);
return;
}

ConnectionSettings connectionSettings = providersXmlDiscoveryDiscover(email, DiscoveryTarget.INCOMING_AND_OUTGOING);
if (connectionSettings != null) {
finishAutoSetup(connectionSettings);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.fsck.k9.ui.settings

import com.fsck.k9.ui.ConnectionSettings

object ExtraAccountDiscovery {
@JvmStatic
fun discover(email: String): ConnectionSettings? = null
}
50 changes: 50 additions & 0 deletions backend/demo/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apply plugin: 'com.android.library'
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: 'kotlin-kapt'

if (rootProject.testCoverage) {
apply plugin: 'jacoco'
}

dependencies {
api project(":backend:api")

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${versions.kotlinCoroutines}"
implementation "com.jakewharton.timber:timber:${versions.timber}"
implementation "com.squareup.moshi:moshi:${versions.moshi}"
kapt "com.squareup.moshi:moshi-kotlin-codegen:${versions.moshi}"

testImplementation project(":mail:testing")
testImplementation "junit:junit:${versions.junit}"
testImplementation "org.mockito:mockito-core:${versions.mockito}"
testImplementation "com.google.truth:truth:${versions.truth}"
}

android {
compileSdkVersion buildConfig.compileSdk
buildToolsVersion buildConfig.buildTools

defaultConfig {
minSdkVersion buildConfig.minSdk
}

buildTypes {
debug {
testCoverageEnabled rootProject.testCoverage
}
}

lintOptions {
abortOnError false
lintConfig file("$rootProject.projectDir/config/lint/lint.xml")
}

compileOptions {
sourceCompatibility javaVersion
targetCompatibility javaVersion
}

kotlinOptions {
jvmTarget = kotlinJvmVersion
}
}
2 changes: 2 additions & 0 deletions backend/demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="app.k9mail.backend.demo" />
Loading

0 comments on commit eae910f

Please sign in to comment.