Loading k9mail-library/src/main/java/com/fsck/k9/mail/transport/SmtpTransport.java +7 −1 Original line number Diff line number Diff line package com.fsck.k9.mail.transport; import android.support.annotation.VisibleForTesting; import android.util.Log; import com.fsck.k9.mail.*; Loading Loading @@ -241,7 +242,7 @@ public class SmtpTransport extends Transport { executeSimpleCommand(null); InetAddress localAddress = mSocket.getLocalAddress(); String localHost = localAddress.getCanonicalHostName(); String localHost = getCanonicalHostName(localAddress); String ipAddr = localAddress.getHostAddress(); if (localHost.equals("") || localHost.equals(ipAddr) || localHost.contains("_")) { Loading Loading @@ -761,6 +762,11 @@ public class SmtpTransport extends Transport { Base64.encode(username)), false); } @VisibleForTesting protected String getCanonicalHostName(InetAddress localAddress) { return localAddress.getCanonicalHostName(); } /** * Exception that is thrown when the server sends a negative reply (reply codes 4xx or 5xx). */ Loading k9mail-library/src/test/java/com/fsck/k9/mail/transport/SmtpTransportTest.java +16 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ package com.fsck.k9.mail.transport; import java.io.IOException; import java.net.InetAddress; import com.fsck.k9.mail.AuthType; import com.fsck.k9.mail.CertificateValidationException; Loading Loading @@ -33,6 +34,7 @@ import static org.mockito.Mockito.when; @RunWith(RobolectricTestRunner.class) @Config(manifest = Config.NONE, sdk = 21) public class SmtpTransportTest { private static final String LOCALHOST_NAME = "localhost"; private static final String USERNAME = "user"; private static final String PASSWORD = "password"; private static final String CLIENT_CERTIFICATE_ALIAS = null; Loading Loading @@ -411,7 +413,7 @@ public class SmtpTransportTest { String uri = SmtpTransport.createUri(serverSettings); StoreConfig storeConfig = createStoreConfigWithTransportUri(uri); return new SmtpTransport(storeConfig, socketFactory); return new TestSmtpTransport(storeConfig, socketFactory); } private StoreConfig createStoreConfigWithTransportUri(String value) { Loading Loading @@ -447,4 +449,17 @@ public class SmtpTransportTest { return server; } static class TestSmtpTransport extends SmtpTransport { TestSmtpTransport(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory) throws MessagingException { super(storeConfig, trustedSocketFactory); } @Override protected String getCanonicalHostName(InetAddress localAddress) { return LOCALHOST_NAME; } } } Loading
k9mail-library/src/main/java/com/fsck/k9/mail/transport/SmtpTransport.java +7 −1 Original line number Diff line number Diff line package com.fsck.k9.mail.transport; import android.support.annotation.VisibleForTesting; import android.util.Log; import com.fsck.k9.mail.*; Loading Loading @@ -241,7 +242,7 @@ public class SmtpTransport extends Transport { executeSimpleCommand(null); InetAddress localAddress = mSocket.getLocalAddress(); String localHost = localAddress.getCanonicalHostName(); String localHost = getCanonicalHostName(localAddress); String ipAddr = localAddress.getHostAddress(); if (localHost.equals("") || localHost.equals(ipAddr) || localHost.contains("_")) { Loading Loading @@ -761,6 +762,11 @@ public class SmtpTransport extends Transport { Base64.encode(username)), false); } @VisibleForTesting protected String getCanonicalHostName(InetAddress localAddress) { return localAddress.getCanonicalHostName(); } /** * Exception that is thrown when the server sends a negative reply (reply codes 4xx or 5xx). */ Loading
k9mail-library/src/test/java/com/fsck/k9/mail/transport/SmtpTransportTest.java +16 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ package com.fsck.k9.mail.transport; import java.io.IOException; import java.net.InetAddress; import com.fsck.k9.mail.AuthType; import com.fsck.k9.mail.CertificateValidationException; Loading Loading @@ -33,6 +34,7 @@ import static org.mockito.Mockito.when; @RunWith(RobolectricTestRunner.class) @Config(manifest = Config.NONE, sdk = 21) public class SmtpTransportTest { private static final String LOCALHOST_NAME = "localhost"; private static final String USERNAME = "user"; private static final String PASSWORD = "password"; private static final String CLIENT_CERTIFICATE_ALIAS = null; Loading Loading @@ -411,7 +413,7 @@ public class SmtpTransportTest { String uri = SmtpTransport.createUri(serverSettings); StoreConfig storeConfig = createStoreConfigWithTransportUri(uri); return new SmtpTransport(storeConfig, socketFactory); return new TestSmtpTransport(storeConfig, socketFactory); } private StoreConfig createStoreConfigWithTransportUri(String value) { Loading Loading @@ -447,4 +449,17 @@ public class SmtpTransportTest { return server; } static class TestSmtpTransport extends SmtpTransport { TestSmtpTransport(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory) throws MessagingException { super(storeConfig, trustedSocketFactory); } @Override protected String getCanonicalHostName(InetAddress localAddress) { return LOCALHOST_NAME; } } }