From 99acb26b69d34a3c9bfff49aa1534862ccf4d6c9 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 12 Nov 2021 12:19:38 +0100 Subject: [PATCH] Save/restore host/IP --- .../java/eu/faircode/email/EmailService.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EmailService.java b/app/src/main/java/eu/faircode/email/EmailService.java index dfe4c09fc3..32b5c1bc97 100644 --- a/app/src/main/java/eu/faircode/email/EmailService.java +++ b/app/src/main/java/eu/faircode/email/EmailService.java @@ -500,9 +500,22 @@ public class EmailService implements AutoCloseable { // throw new MailConnectException( // new SocketConnectException("Debug", new IOException("Test"), host, port, 0)); - main = InetAddress.getByName(host); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + + String key = "dns." + host; + try { + main = InetAddress.getByName(host); + prefs.edit().putString(key, main.getHostAddress()).apply(); + } catch (UnknownHostException ex) { + String last = prefs.getString(key, null); + if (TextUtils.isEmpty(last)) + throw new MessagingException(ex.getMessage(), ex); + else { + Log.w("Using " + key + "=" + last); + main = InetAddress.getByName(last); + } + } + boolean prefer_ip4 = prefs.getBoolean("prefer_ip4", true); if (prefer_ip4 && main instanceof Inet6Address)