From 89d3df091fda2a035f7dbf6e5ab11af4aee49a6e Mon Sep 17 00:00:00 2001 From: cketti Date: Fri, 12 Aug 2022 09:34:01 +0200 Subject: [PATCH 1/2] Change `ImapSettings.useCompression` to a property --- .../main/java/com/fsck/k9/mail/store/imap/ImapSettings.kt | 2 +- .../java/com/fsck/k9/mail/store/imap/RealImapConnection.kt | 2 +- .../main/java/com/fsck/k9/mail/store/imap/RealImapStore.kt | 5 ++--- .../java/com/fsck/k9/mail/store/imap/SimpleImapSettings.kt | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapSettings.kt b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapSettings.kt index b5cf30197..03e7582b5 100644 --- a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapSettings.kt +++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapSettings.kt @@ -14,7 +14,7 @@ internal interface ImapSettings { val username: String val password: String? val clientCertificateAlias: String? - fun useCompression(): Boolean + val useCompression: Boolean var pathPrefix: String? var pathDelimiter: String? diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapConnection.kt b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapConnection.kt index 8798a230d..71c8d8632 100644 --- a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapConnection.kt +++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapConnection.kt @@ -549,7 +549,7 @@ internal class RealImapConnection( } private fun enableCompressionIfRequested() { - if (hasCapability(Capabilities.COMPRESS_DEFLATE) && settings.useCompression()) { + if (hasCapability(Capabilities.COMPRESS_DEFLATE) && settings.useCompression) { enableCompression() } } diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapStore.kt b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapStore.kt index 9d67714a2..08a907e8e 100644 --- a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapStore.kt +++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapStore.kt @@ -296,9 +296,8 @@ internal open class RealImapStore( override val password: String? = serverSettings.password override val clientCertificateAlias: String? = serverSettings.clientCertificateAlias - override fun useCompression(): Boolean { - return this@RealImapStore.config.useCompression() - } + override val useCompression: Boolean + get() = this@RealImapStore.config.useCompression() override var pathPrefix: String? get() = this@RealImapStore.pathPrefix diff --git a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/SimpleImapSettings.kt b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/SimpleImapSettings.kt index 5a74db0b9..5e75c230d 100644 --- a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/SimpleImapSettings.kt +++ b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/SimpleImapSettings.kt @@ -10,10 +10,9 @@ internal class SimpleImapSettings( override val authType: AuthType, override val username: String, override val password: String? = null, - private val useCompression: Boolean = false + override val useCompression: Boolean = false ) : ImapSettings { override val clientCertificateAlias: String? = null - override fun useCompression(): Boolean = useCompression override var pathPrefix: String? = null override var pathDelimiter: String? = null From ec76473a1c20367e01c1e2168e6497f0502cddcc Mon Sep 17 00:00:00 2001 From: cketti Date: Fri, 12 Aug 2022 09:39:01 +0200 Subject: [PATCH 2/2] Remove `RealImapConnection.handleConnectException()` --- .../k9/mail/store/imap/RealImapConnection.kt | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapConnection.kt b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapConnection.kt index 71c8d8632..363640466 100644 --- a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapConnection.kt +++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapConnection.kt @@ -23,7 +23,6 @@ import java.io.BufferedOutputStream import java.io.IOException import java.io.InputStream import java.io.OutputStream -import java.net.ConnectException import java.net.InetAddress import java.net.InetSocketAddress import java.net.Socket @@ -101,8 +100,6 @@ internal class RealImapConnection( retrievePathDelimiterIfNecessary() } catch (e: SSLException) { handleSslException(e) - } catch (e: ConnectException) { - handleConnectException(e) } catch (e: GeneralSecurityException) { throw MessagingException("Unable to open connection to IMAP server due to security error.", e) } finally { @@ -121,20 +118,6 @@ internal class RealImapConnection( } } - // TODO: Remove this. There is no documentation on why this was added, there are no tests, and this is unlikely to - // still work. - private fun handleConnectException(e: ConnectException) { - val message = e.message ?: throw e - - val tokens = message.split("-") - if (tokens.size > 1) { - Timber.e(e, "Stripping host/port from ConnectionException for %s", logId) - throw ConnectException(tokens[1].trim()) - } else { - throw e - } - } - @get:Synchronized override val isConnected: Boolean get() {