mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-30 13:12:25 -05:00
update issue 2744
try all addresses of a host. (Fix is required for proper operation in IPv4-only/IPv6-only networks for IPv4/IPv6 dual-stack mail-hosts)
This commit is contained in:
parent
034f83e522
commit
ba24fdc742
@ -30,6 +30,7 @@ import org.apache.commons.codec.binary.Hex;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SmtpTransport extends Transport
|
public class SmtpTransport extends Transport
|
||||||
@ -152,25 +153,37 @@ public class SmtpTransport extends Transport
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SocketAddress socketAddress = new InetSocketAddress(mHost, mPort);
|
InetAddress[] addresses = InetAddress.getAllByName(mHost);
|
||||||
if (mConnectionSecurity == CONNECTION_SECURITY_SSL_REQUIRED ||
|
for (int i = 0; i < addresses.length; i++) {
|
||||||
mConnectionSecurity == CONNECTION_SECURITY_SSL_OPTIONAL)
|
try {
|
||||||
{
|
SocketAddress socketAddress = new InetSocketAddress(addresses[i], mPort);
|
||||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
if (mConnectionSecurity == CONNECTION_SECURITY_SSL_REQUIRED ||
|
||||||
boolean secure = mConnectionSecurity == CONNECTION_SECURITY_SSL_REQUIRED;
|
mConnectionSecurity == CONNECTION_SECURITY_SSL_OPTIONAL)
|
||||||
sslContext.init(null, new TrustManager[]
|
{
|
||||||
{
|
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||||
TrustManagerFactory.get(mHost, secure)
|
boolean secure = mConnectionSecurity == CONNECTION_SECURITY_SSL_REQUIRED;
|
||||||
}, new SecureRandom());
|
sslContext.init(null, new TrustManager[]
|
||||||
mSocket = sslContext.getSocketFactory().createSocket();
|
{
|
||||||
mSocket.connect(socketAddress, SOCKET_CONNECT_TIMEOUT);
|
TrustManagerFactory.get(mHost, secure)
|
||||||
mSecure = true;
|
}, new SecureRandom());
|
||||||
}
|
mSocket = sslContext.getSocketFactory().createSocket();
|
||||||
else
|
mSocket.connect(socketAddress, SOCKET_CONNECT_TIMEOUT);
|
||||||
{
|
mSecure = true;
|
||||||
mSocket = new Socket();
|
}
|
||||||
mSocket.connect(socketAddress, SOCKET_CONNECT_TIMEOUT);
|
else
|
||||||
}
|
{
|
||||||
|
mSocket = new Socket();
|
||||||
|
mSocket.connect(socketAddress, SOCKET_CONNECT_TIMEOUT);
|
||||||
|
}
|
||||||
|
} catch (ConnectException e) {
|
||||||
|
if (i < (addresses.length - 1)) {
|
||||||
|
// there are still other addresses for that host to try
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
throw new MessagingException("Cannot connect to host", e);
|
||||||
|
}
|
||||||
|
break; // connection success
|
||||||
|
}
|
||||||
|
|
||||||
// RFC 1047
|
// RFC 1047
|
||||||
mSocket.setSoTimeout(SOCKET_READ_TIMEOUT);
|
mSocket.setSoTimeout(SOCKET_READ_TIMEOUT);
|
||||||
|
Loading…
Reference in New Issue
Block a user