Merge pull request #6238 from thundernest/cleanup

Small code cleanup
This commit is contained in:
cketti 2022-08-12 16:21:08 +02:00 committed by GitHub
commit 9cf73c99d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 24 deletions

View file

@ -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?

View file

@ -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() {
@ -549,7 +532,7 @@ internal class RealImapConnection(
}
private fun enableCompressionIfRequested() {
if (hasCapability(Capabilities.COMPRESS_DEFLATE) && settings.useCompression()) {
if (hasCapability(Capabilities.COMPRESS_DEFLATE) && settings.useCompression) {
enableCompression()
}
}

View file

@ -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

View file

@ -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