From 0dad70121017c22e36e38fb585f3e5850f2c4f63 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 24 Feb 2021 08:32:49 +0100 Subject: [PATCH] Use IPv6 address if resolving fails --- .../java/eu/faircode/email/EmailService.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EmailService.java b/app/src/main/java/eu/faircode/email/EmailService.java index 2baabd79d6..a77fb16a94 100644 --- a/app/src/main/java/eu/faircode/email/EmailService.java +++ b/app/src/main/java/eu/faircode/email/EmailService.java @@ -462,14 +462,18 @@ public class EmailService implements AutoCloseable { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean prefer_ip4 = prefs.getBoolean("prefer_ip4", true); - if (prefer_ip4 && main instanceof Inet6Address) { - for (InetAddress iaddr : InetAddress.getAllByName(host)) - if (iaddr instanceof Inet4Address) { - main = iaddr; - EntityLog.log(context, "Preferring=" + main); - break; - } - } + if (prefer_ip4 && + main instanceof Inet6Address) + try { + for (InetAddress iaddr : InetAddress.getAllByName(host)) + if (iaddr instanceof Inet4Address) { + main = iaddr; + EntityLog.log(context, "Preferring=" + main); + break; + } + } catch (UnknownHostException ex) { + Log.w(ex); + } EntityLog.log(context, "Connecting to " + main); _connect(main, port, require_id, user, authenticator, factory);