Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c359a9dc authored by Fahim Salam Chowdhury's avatar Fahim Salam Chowdhury 👽
Browse files

Merge branch 'latest_upstream_tag_branch' into 524-update_with_upstream_v6.100

parents 30b04009 06a537b1
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
If the app is not behaving like it should, it's not necessarily a bug. Please consult the following resources before
submitting a new issue.

* [User Manual](https://k9mail.app/documentation/)
* [User Manual](https://docs.k9mail.app/)
* [Frequently Asked Questions](https://forum.k9mail.app/c/faq)
* [Support Forum](https://forum.k9mail.app/)

+1 −2
Original line number Diff line number Diff line
liberapay: k9mail
github: cketti
custom: "https://mzla.link/k9-give"
+1 −1
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ body:
    id: expected
    attributes:
      label: Expected behavior
      description: After following the steps, what did you think K-9 Mail would do?
      description: After following the steps, what did you think Mail would do?
    validations:
      required: true
  - type: textarea
+1 −1
Original line number Diff line number Diff line
@@ -4,5 +4,5 @@ import org.koin.dsl.module

val autodiscoveryProvidersXmlModule = module {
    factory { ProvidersXmlProvider(context = get()) }
    factory { ProvidersXmlDiscovery(xmlProvider = get()) }
    factory { ProvidersXmlDiscovery(xmlProvider = get(), oAuthConfigurationProvider = get()) }
}
+17 −23
Original line number Diff line number Diff line
@@ -9,14 +9,14 @@ import com.fsck.k9.autodiscovery.api.DiscoveryTarget
import com.fsck.k9.helper.EmailHelper
import com.fsck.k9.mail.AuthType
import com.fsck.k9.mail.ConnectionSecurity
import com.fsck.k9.mail.oauth.OAuth2Provider
import com.fsck.k9.oauth.OAuthConfigurationProvider
import com.fsck.k9.preferences.Protocols
import java.net.URI
import org.xmlpull.v1.XmlPullParser
import timber.log.Timber

class ProvidersXmlDiscovery(
    private val xmlProvider: ProvidersXmlProvider
    private val xmlProvider: ProvidersXmlProvider,
    private val oAuthConfigurationProvider: OAuthConfigurationProvider
) : ConnectionSettingsDiscovery {

    override fun discover(email: String, target: DiscoveryTarget): DiscoveryResults? {
@@ -92,20 +92,13 @@ class ProvidersXmlDiscovery(

        val username = incomingUsernameTemplate.fillInUsernameTemplate(email, user, domain)

        val xoauth2 = OAuth2Provider.isXOAuth2(domain)
        val xoauth2Label = if (xoauth2) AuthType.XOAUTH2.name else ""
        val xoauth2Colon = if (xoauth2) ":" else ""

        val security = when {
            incomingUriTemplate.startsWith("imap+ssl") -> ConnectionSecurity.SSL_TLS_REQUIRED
            incomingUriTemplate.startsWith("imap+tls") -> ConnectionSecurity.STARTTLS_REQUIRED
            else -> error("Connection security required")
        }

        val incomingUri = with(URI(incomingUriTemplate)) {
            URI(scheme, "$xoauth2Label$xoauth2Colon$username", host, port, null, null, null).toString()
        }
        val uri = Uri.parse(incomingUri)
        val uri = Uri.parse(incomingUriTemplate)
        val host = uri.host ?: error("Host name required")
        val port = if (uri.port == -1) {
            if (security == ConnectionSecurity.STARTTLS_REQUIRED) 143 else 993
@@ -113,19 +106,19 @@ class ProvidersXmlDiscovery(
            uri.port
        }

        val authType = if (xoauth2) AuthType.XOAUTH2 else AuthType.PLAIN
        val authType = if (oAuthConfigurationProvider.getConfiguration(host) != null) {
            AuthType.XOAUTH2
        } else {
            AuthType.PLAIN
        }

        return DiscoveredServerSettings(Protocols.IMAP, host, port, security, authType, username)
    }

    private fun Provider.toOutgoingServerSettings(email: String): DiscoveredServerSettings? {

        val user = EmailHelper.getLocalPartFromEmailAddress(email) ?: return null
        val domain = EmailHelper.getDomainFromEmailAddress(email) ?: return null

        val xoauth2 = OAuth2Provider.isXOAuth2(domain)
        val xoauth2Label = if (xoauth2) AuthType.XOAUTH2.name else ""
        val xoauth2Colon = if (xoauth2) ":" else ""

        val username = outgoingUsernameTemplate.fillInUsernameTemplate(email, user, domain)

        val security = when {
@@ -134,11 +127,7 @@ class ProvidersXmlDiscovery(
            else -> error("Connection security required")
        }

        val outgoingUri = with(URI(outgoingUriTemplate)) {
            URI(scheme, "$username$xoauth2Colon$xoauth2Label", host, port, null, null, null).toString()
        }

        val uri = Uri.parse(outgoingUri)
        val uri = Uri.parse(outgoingUriTemplate)
        val host = uri.host ?: error("Host name required")
        val port = if (uri.port == -1) {
            if (security == ConnectionSecurity.STARTTLS_REQUIRED) 587 else 465
@@ -146,7 +135,12 @@ class ProvidersXmlDiscovery(
            uri.port
        }

        val authType = if (xoauth2) AuthType.XOAUTH2 else AuthType.PLAIN
        val authType = if (oAuthConfigurationProvider.getConfiguration(host) != null) {
            AuthType.XOAUTH2
        } else {
            AuthType.PLAIN
        }

        return DiscoveredServerSettings(Protocols.SMTP, host, port, security, authType, username)
    }

Loading