Loading mail/protocols/smtp/src/main/java/com/fsck/k9/mail/transport/smtp/SmtpTransport.kt +4 −3 Original line number Diff line number Diff line Loading @@ -130,15 +130,16 @@ class SmtpTransport( if (extensions.containsKey("STARTTLS")) { executeCommand("STARTTLS") this.socket = trustedSocketFactory.createSocket( val tlsSocket = trustedSocketFactory.createSocket( socket, host, port, clientCertificateAlias ) inputStream = PeekableInputStream(BufferedInputStream(socket.getInputStream(), 1024)) this.socket = tlsSocket inputStream = PeekableInputStream(BufferedInputStream(tlsSocket.getInputStream(), 1024)) responseParser = SmtpResponseParser(logger, inputStream!!) outputStream = BufferedOutputStream(socket.getOutputStream(), 1024) outputStream = BufferedOutputStream(tlsSocket.getOutputStream(), 1024) // Now resend the EHLO. Required by RFC2487 Sec. 5.2, and more specifically, Exim. extensions = sendHello(helloName) Loading mail/protocols/smtp/src/test/java/com/fsck/k9/mail/transport/mockServer/MockSmtpServer.java +10 −0 Original line number Diff line number Diff line Loading @@ -68,6 +68,11 @@ public class MockSmtpServer { interactions.add(new ExpectedCommand(command)); } public void startTls() { checkServerNotRunning(); interactions.add(new UpgradeToTls()); } public void closeConnection() { checkServerNotRunning(); interactions.add(new CloseConnection()); Loading Loading @@ -212,6 +217,9 @@ public class MockSmtpServer { } } private static class UpgradeToTls implements SmtpInteraction { } private static class CloseConnection implements SmtpInteraction { } Loading Loading @@ -303,6 +311,8 @@ public class MockSmtpServer { readExpectedCommand((ExpectedCommand) interaction); } else if (interaction instanceof CannedResponse) { writeCannedResponse((CannedResponse) interaction); } else if (interaction instanceof UpgradeToTls) { upgradeToTls(socket); } else if (interaction instanceof CloseConnection) { clientSocket.close(); } Loading mail/protocols/smtp/src/test/java/com/fsck/k9/mail/transport/smtp/SmtpTransportTest.kt +29 −0 Original line number Diff line number Diff line Loading @@ -567,6 +567,35 @@ class SmtpTransportTest { server.verifyInteractionCompleted() } @Test fun `open() with STARTTLS`() { val server = MockSmtpServer().apply { output("220 localhost Simple Mail Transfer Service Ready") expect("EHLO [127.0.0.1]") output("250-localhost Hello 127.0.0.1") output("250-STARTTLS") output("250 HELP") expect("STARTTLS") output("220 Ready to start TLS") startTls() expect("EHLO [127.0.0.1]") output("250-localhost Hello 127.0.0.1") output("250 AUTH PLAIN LOGIN") expect("AUTH PLAIN AHVzZXIAcGFzc3dvcmQ=") output("235 2.7.0 Authentication successful") } val transport = startServerAndCreateSmtpTransport( server, authenticationType = AuthType.PLAIN, connectionSecurity = ConnectionSecurity.STARTTLS_REQUIRED ) transport.open() server.verifyConnectionStillOpen() server.verifyInteractionCompleted() } @Test fun `sendMessage() without address to send to should not open connection`() { val message = MimeMessage() Loading Loading
mail/protocols/smtp/src/main/java/com/fsck/k9/mail/transport/smtp/SmtpTransport.kt +4 −3 Original line number Diff line number Diff line Loading @@ -130,15 +130,16 @@ class SmtpTransport( if (extensions.containsKey("STARTTLS")) { executeCommand("STARTTLS") this.socket = trustedSocketFactory.createSocket( val tlsSocket = trustedSocketFactory.createSocket( socket, host, port, clientCertificateAlias ) inputStream = PeekableInputStream(BufferedInputStream(socket.getInputStream(), 1024)) this.socket = tlsSocket inputStream = PeekableInputStream(BufferedInputStream(tlsSocket.getInputStream(), 1024)) responseParser = SmtpResponseParser(logger, inputStream!!) outputStream = BufferedOutputStream(socket.getOutputStream(), 1024) outputStream = BufferedOutputStream(tlsSocket.getOutputStream(), 1024) // Now resend the EHLO. Required by RFC2487 Sec. 5.2, and more specifically, Exim. extensions = sendHello(helloName) Loading
mail/protocols/smtp/src/test/java/com/fsck/k9/mail/transport/mockServer/MockSmtpServer.java +10 −0 Original line number Diff line number Diff line Loading @@ -68,6 +68,11 @@ public class MockSmtpServer { interactions.add(new ExpectedCommand(command)); } public void startTls() { checkServerNotRunning(); interactions.add(new UpgradeToTls()); } public void closeConnection() { checkServerNotRunning(); interactions.add(new CloseConnection()); Loading Loading @@ -212,6 +217,9 @@ public class MockSmtpServer { } } private static class UpgradeToTls implements SmtpInteraction { } private static class CloseConnection implements SmtpInteraction { } Loading Loading @@ -303,6 +311,8 @@ public class MockSmtpServer { readExpectedCommand((ExpectedCommand) interaction); } else if (interaction instanceof CannedResponse) { writeCannedResponse((CannedResponse) interaction); } else if (interaction instanceof UpgradeToTls) { upgradeToTls(socket); } else if (interaction instanceof CloseConnection) { clientSocket.close(); } Loading
mail/protocols/smtp/src/test/java/com/fsck/k9/mail/transport/smtp/SmtpTransportTest.kt +29 −0 Original line number Diff line number Diff line Loading @@ -567,6 +567,35 @@ class SmtpTransportTest { server.verifyInteractionCompleted() } @Test fun `open() with STARTTLS`() { val server = MockSmtpServer().apply { output("220 localhost Simple Mail Transfer Service Ready") expect("EHLO [127.0.0.1]") output("250-localhost Hello 127.0.0.1") output("250-STARTTLS") output("250 HELP") expect("STARTTLS") output("220 Ready to start TLS") startTls() expect("EHLO [127.0.0.1]") output("250-localhost Hello 127.0.0.1") output("250 AUTH PLAIN LOGIN") expect("AUTH PLAIN AHVzZXIAcGFzc3dvcmQ=") output("235 2.7.0 Authentication successful") } val transport = startServerAndCreateSmtpTransport( server, authenticationType = AuthType.PLAIN, connectionSecurity = ConnectionSecurity.STARTTLS_REQUIRED ) transport.open() server.verifyConnectionStillOpen() server.verifyInteractionCompleted() } @Test fun `sendMessage() without address to send to should not open connection`() { val message = MimeMessage() Loading