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

Unverified Commit 7ec2a0b9 authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #6454 from thundernest/fix_connect_errors

Don't wrap exceptions when trying to connect to IMAP/SMTP servers
parents c3b25d51 1570c238
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import java.net.InetAddress
import java.net.InetSocketAddress
import java.net.Socket
import java.net.SocketAddress
import java.net.UnknownHostException
import java.security.GeneralSecurityException
import java.security.Security
import java.security.cert.CertificateException
@@ -154,7 +155,7 @@ internal class RealImapConnection(
            }
        }

        throw MessagingException("Cannot connect to host", connectException)
        throw connectException ?: UnknownHostException()
    }

    private fun connectToAddress(address: InetAddress): Socket {
+2 −8
Original line number Diff line number Diff line
@@ -640,18 +640,12 @@ class RealImapConnectionTest {
        server.verifyInteractionCompleted()
    }

    @Test
    @Test(expected = IOException::class)
    fun `open() with connection error should throw`() {
        val settings = createImapSettings(host = "127.1.2.3")
        val imapConnection = createImapConnection(settings, socketFactory, oAuth2TokenProvider)

        try {
        imapConnection.open()
            fail("Expected exception")
        } catch (e: MessagingException) {
            assertThat(e).hasMessageThat().isEqualTo("Cannot connect to host")
            assertThat(e).hasCauseThat().isInstanceOf(IOException::class.java)
        }
    }

    @Test
+8 −2
Original line number Diff line number Diff line
@@ -32,7 +32,9 @@ import java.net.Inet6Address
import java.net.InetAddress
import java.net.InetSocketAddress
import java.net.Socket
import java.net.UnknownHostException
import java.security.GeneralSecurityException
import java.security.cert.CertificateException
import java.util.Locale
import javax.net.ssl.SSLException
import org.apache.commons.io.IOUtils
@@ -229,7 +231,11 @@ class SmtpTransport(
            throw e
        } catch (e: SSLException) {
            close()
            if (e.cause is CertificateException) {
                throw CertificateValidationException(e.message, e)
            } else {
                throw e
            }
        } catch (e: GeneralSecurityException) {
            close()
            throw MessagingException("Unable to open connection to SMTP server due to security error.", e)
@@ -252,7 +258,7 @@ class SmtpTransport(
            }
        }

        throw MessagingException("Cannot connect to host", connectException)
        throw connectException ?: UnknownHostException()
    }

    private fun connectToAddress(address: InetAddress): Socket {