Use IPv6 address if resolving fails

This commit is contained in:
M66B 2021-02-24 08:32:49 +01:00
parent 4b0155ac08
commit 0dad701210
1 changed files with 12 additions and 8 deletions

View File

@ -462,14 +462,18 @@ public class EmailService implements AutoCloseable {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean prefer_ip4 = prefs.getBoolean("prefer_ip4", true); boolean prefer_ip4 = prefs.getBoolean("prefer_ip4", true);
if (prefer_ip4 && main instanceof Inet6Address) { if (prefer_ip4 &&
for (InetAddress iaddr : InetAddress.getAllByName(host)) main instanceof Inet6Address)
if (iaddr instanceof Inet4Address) { try {
main = iaddr; for (InetAddress iaddr : InetAddress.getAllByName(host))
EntityLog.log(context, "Preferring=" + main); if (iaddr instanceof Inet4Address) {
break; main = iaddr;
} EntityLog.log(context, "Preferring=" + main);
} break;
}
} catch (UnknownHostException ex) {
Log.w(ex);
}
EntityLog.log(context, "Connecting to " + main); EntityLog.log(context, "Connecting to " + main);
_connect(main, port, require_id, user, authenticator, factory); _connect(main, port, require_id, user, authenticator, factory);