Loading k9mail-library/src/main/java/com/fsck/k9/mail/transport/SmtpTransport.java +65 −57 Original line number Diff line number Diff line Loading @@ -362,7 +362,8 @@ public class SmtpTransport extends Transport { } else if (authLoginSupported) { saslAuthLogin(mUsername, mPassword); } else { throw new MessagingException("Authentication methods SASL PLAIN and LOGIN are unavailable."); throw new MessagingException( "Authentication methods SASL PLAIN and LOGIN are unavailable."); } break; Loading Loading @@ -432,15 +433,22 @@ public class SmtpTransport extends Transport { break; default: throw new MessagingException("Unhandled authentication method found in the server settings (bug)."); throw new MessagingException( "Unhandled authentication method found in the server settings (bug)."); } } } catch (MessagingException e) { close(); throw e; } catch (SSLException e) { close(); throw new CertificateValidationException(e.getMessage(), e); } catch (GeneralSecurityException gse) { close(); throw new MessagingException( "Unable to open connection to SMTP server due to security error.", gse); } catch (IOException ioe) { close(); throw new MessagingException("Unable to open connection to SMTP server.", ioe); } } Loading k9mail-library/src/test/java/com/fsck/k9/mail/transport/SmtpTransportTest.java +24 −7 Original line number Diff line number Diff line Loading @@ -133,6 +133,8 @@ public class SmtpTransportTest { server.expect("EHLO localhost"); server.output("250-localhost Hello client.localhost"); server.output("250 AUTH"); server.expect("QUIT"); server.output("221 BYE"); SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.PLAIN, ConnectionSecurity.NONE); try { Loading Loading @@ -172,6 +174,8 @@ public class SmtpTransportTest { server.expect("EHLO localhost"); server.output("250-localhost Hello client.localhost"); server.output("250 AUTH PLAIN LOGIN"); server.expect("QUIT"); server.output("221 BYE"); SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.CRAM_MD5, ConnectionSecurity.NONE); try { Loading @@ -181,7 +185,7 @@ public class SmtpTransportTest { assertEquals("Authentication method CRAM-MD5 is unavailable.", e.getMessage()); } server.verifyConnectionStillOpen(); server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } Loading Loading @@ -214,6 +218,8 @@ public class SmtpTransportTest { server.expect(""); server.output("535-5.7.1 Username and Password not accepted. Learn more at"); server.output("535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 hx9sm5317360pbc.68"); server.expect("QUIT"); server.output("221 BYE"); SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.XOAUTH2, ConnectionSecurity.NONE); try { Loading @@ -228,7 +234,7 @@ public class SmtpTransportTest { InOrder inOrder = inOrder(oAuth2TokenProvider); inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyInt()); inOrder.verify(oAuth2TokenProvider).invalidateToken(USERNAME); server.verifyConnectionStillOpen(); server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } Loading Loading @@ -327,6 +333,9 @@ public class SmtpTransportTest { server.expect(""); server.output("535-5.7.1 Username and Password not accepted. Learn more at"); server.output("535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 hx9sm5317360pbc.68"); server.expect("QUIT"); server.output("221 BYE"); SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.XOAUTH2, ConnectionSecurity.NONE); try { Loading @@ -338,7 +347,7 @@ public class SmtpTransportTest { e.getMessage()); } server.verifyConnectionStillOpen(); server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } Loading @@ -349,6 +358,8 @@ public class SmtpTransportTest { server.expect("EHLO localhost"); server.output("250-localhost Hello client.localhost"); server.output("250 AUTH XOAUTH2"); server.expect("QUIT"); server.output("221 BYE"); when(oAuth2TokenProvider.getToken(anyString(), anyInt())).thenThrow(new AuthenticationFailedException("Failed to fetch token")); SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.XOAUTH2, ConnectionSecurity.NONE); Loading @@ -359,7 +370,7 @@ public class SmtpTransportTest { assertEquals("Failed to fetch token", e.getMessage()); } server.verifyConnectionStillOpen(); server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } Loading @@ -371,6 +382,8 @@ public class SmtpTransportTest { server.expect("EHLO localhost"); server.output("250-localhost Hello client.localhost"); server.output("250 AUTH PLAIN LOGIN"); server.expect("QUIT"); server.output("221 BYE"); SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.XOAUTH2, ConnectionSecurity.NONE); try { Loading @@ -380,7 +393,7 @@ public class SmtpTransportTest { assertEquals("Authentication method XOAUTH2 is unavailable.", e.getMessage()); } server.verifyConnectionStillOpen(); server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } Loading Loading @@ -408,6 +421,8 @@ public class SmtpTransportTest { server.expect("EHLO localhost"); server.output("250-localhost Hello client.localhost"); server.output("250 AUTH"); server.expect("QUIT"); server.output("221 BYE"); SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.EXTERNAL, ConnectionSecurity.NONE); try { Loading @@ -417,7 +432,7 @@ public class SmtpTransportTest { assertEquals(CertificateValidationException.Reason.MissingCapability, e.getReason()); } server.verifyConnectionStillOpen(); server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } Loading Loading @@ -449,6 +464,8 @@ public class SmtpTransportTest { server.expect("EHLO localhost"); server.output("250-localhost Hello client.localhost"); server.output("250 AUTH PLAIN LOGIN"); server.expect("QUIT"); server.output("221 BYE"); SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.AUTOMATIC, ConnectionSecurity.NONE); Loading @@ -460,7 +477,7 @@ public class SmtpTransportTest { e.getMessage()); } server.verifyConnectionStillOpen(); server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } Loading Loading
k9mail-library/src/main/java/com/fsck/k9/mail/transport/SmtpTransport.java +65 −57 Original line number Diff line number Diff line Loading @@ -362,7 +362,8 @@ public class SmtpTransport extends Transport { } else if (authLoginSupported) { saslAuthLogin(mUsername, mPassword); } else { throw new MessagingException("Authentication methods SASL PLAIN and LOGIN are unavailable."); throw new MessagingException( "Authentication methods SASL PLAIN and LOGIN are unavailable."); } break; Loading Loading @@ -432,15 +433,22 @@ public class SmtpTransport extends Transport { break; default: throw new MessagingException("Unhandled authentication method found in the server settings (bug)."); throw new MessagingException( "Unhandled authentication method found in the server settings (bug)."); } } } catch (MessagingException e) { close(); throw e; } catch (SSLException e) { close(); throw new CertificateValidationException(e.getMessage(), e); } catch (GeneralSecurityException gse) { close(); throw new MessagingException( "Unable to open connection to SMTP server due to security error.", gse); } catch (IOException ioe) { close(); throw new MessagingException("Unable to open connection to SMTP server.", ioe); } } Loading
k9mail-library/src/test/java/com/fsck/k9/mail/transport/SmtpTransportTest.java +24 −7 Original line number Diff line number Diff line Loading @@ -133,6 +133,8 @@ public class SmtpTransportTest { server.expect("EHLO localhost"); server.output("250-localhost Hello client.localhost"); server.output("250 AUTH"); server.expect("QUIT"); server.output("221 BYE"); SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.PLAIN, ConnectionSecurity.NONE); try { Loading Loading @@ -172,6 +174,8 @@ public class SmtpTransportTest { server.expect("EHLO localhost"); server.output("250-localhost Hello client.localhost"); server.output("250 AUTH PLAIN LOGIN"); server.expect("QUIT"); server.output("221 BYE"); SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.CRAM_MD5, ConnectionSecurity.NONE); try { Loading @@ -181,7 +185,7 @@ public class SmtpTransportTest { assertEquals("Authentication method CRAM-MD5 is unavailable.", e.getMessage()); } server.verifyConnectionStillOpen(); server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } Loading Loading @@ -214,6 +218,8 @@ public class SmtpTransportTest { server.expect(""); server.output("535-5.7.1 Username and Password not accepted. Learn more at"); server.output("535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 hx9sm5317360pbc.68"); server.expect("QUIT"); server.output("221 BYE"); SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.XOAUTH2, ConnectionSecurity.NONE); try { Loading @@ -228,7 +234,7 @@ public class SmtpTransportTest { InOrder inOrder = inOrder(oAuth2TokenProvider); inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyInt()); inOrder.verify(oAuth2TokenProvider).invalidateToken(USERNAME); server.verifyConnectionStillOpen(); server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } Loading Loading @@ -327,6 +333,9 @@ public class SmtpTransportTest { server.expect(""); server.output("535-5.7.1 Username and Password not accepted. Learn more at"); server.output("535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 hx9sm5317360pbc.68"); server.expect("QUIT"); server.output("221 BYE"); SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.XOAUTH2, ConnectionSecurity.NONE); try { Loading @@ -338,7 +347,7 @@ public class SmtpTransportTest { e.getMessage()); } server.verifyConnectionStillOpen(); server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } Loading @@ -349,6 +358,8 @@ public class SmtpTransportTest { server.expect("EHLO localhost"); server.output("250-localhost Hello client.localhost"); server.output("250 AUTH XOAUTH2"); server.expect("QUIT"); server.output("221 BYE"); when(oAuth2TokenProvider.getToken(anyString(), anyInt())).thenThrow(new AuthenticationFailedException("Failed to fetch token")); SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.XOAUTH2, ConnectionSecurity.NONE); Loading @@ -359,7 +370,7 @@ public class SmtpTransportTest { assertEquals("Failed to fetch token", e.getMessage()); } server.verifyConnectionStillOpen(); server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } Loading @@ -371,6 +382,8 @@ public class SmtpTransportTest { server.expect("EHLO localhost"); server.output("250-localhost Hello client.localhost"); server.output("250 AUTH PLAIN LOGIN"); server.expect("QUIT"); server.output("221 BYE"); SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.XOAUTH2, ConnectionSecurity.NONE); try { Loading @@ -380,7 +393,7 @@ public class SmtpTransportTest { assertEquals("Authentication method XOAUTH2 is unavailable.", e.getMessage()); } server.verifyConnectionStillOpen(); server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } Loading Loading @@ -408,6 +421,8 @@ public class SmtpTransportTest { server.expect("EHLO localhost"); server.output("250-localhost Hello client.localhost"); server.output("250 AUTH"); server.expect("QUIT"); server.output("221 BYE"); SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.EXTERNAL, ConnectionSecurity.NONE); try { Loading @@ -417,7 +432,7 @@ public class SmtpTransportTest { assertEquals(CertificateValidationException.Reason.MissingCapability, e.getReason()); } server.verifyConnectionStillOpen(); server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } Loading Loading @@ -449,6 +464,8 @@ public class SmtpTransportTest { server.expect("EHLO localhost"); server.output("250-localhost Hello client.localhost"); server.output("250 AUTH PLAIN LOGIN"); server.expect("QUIT"); server.output("221 BYE"); SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.AUTOMATIC, ConnectionSecurity.NONE); Loading @@ -460,7 +477,7 @@ public class SmtpTransportTest { e.getMessage()); } server.verifyConnectionStillOpen(); server.verifyConnectionClosed(); server.verifyInteractionCompleted(); } Loading