diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 764f1467f4..9300b691d9 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -1968,7 +1968,7 @@ public class AdapterMessage extends RecyclerView.Adapter hostOrganization = new HashMap<>(); - static final int NOTIFICATION_SYNCHRONIZE = 1; static final int NOTIFICATION_SEND = 2; static final int NOTIFICATION_EXTERNAL = 3; @@ -896,29 +890,6 @@ public class Helper { return (name == null ? null : name.replaceAll("[^a-zA-Z0-9\\.\\-]", "_")); } - static String getOrganization(String host) throws IOException { - synchronized (hostOrganization) { - if (hostOrganization.containsKey(host)) - return hostOrganization.get(host); - } - InetAddress address = InetAddress.getByName(host); - URL url = new URL("https://ipinfo.io/" + address.getHostAddress() + "/org"); - Log.i("GET " + url); - HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - connection.setReadTimeout(15 * 1000); - connection.connect(); - try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { - String organization = reader.readLine(); - if ("undefined".equals(organization)) - organization = null; - synchronized (hostOrganization) { - hostOrganization.put(host, organization); - } - return organization; - } - } - static int getSize(Bundle bundle) { Parcel p = Parcel.obtain(); bundle.writeToParcel(p, 0); diff --git a/app/src/main/java/eu/faircode/email/IPInfo.java b/app/src/main/java/eu/faircode/email/IPInfo.java new file mode 100644 index 0000000000..7422a6a147 --- /dev/null +++ b/app/src/main/java/eu/faircode/email/IPInfo.java @@ -0,0 +1,38 @@ +package eu.faircode.email; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.InetAddress; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import javax.net.ssl.HttpsURLConnection; + +public class IPInfo { + private static Map hostOrganization = new HashMap<>(); + + static String getOrganization(String host) throws IOException { + synchronized (hostOrganization) { + if (hostOrganization.containsKey(host)) + return hostOrganization.get(host); + } + InetAddress address = InetAddress.getByName(host); + URL url = new URL("https://ipinfo.io/" + address.getHostAddress() + "/org"); + Log.i("GET " + url); + HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setReadTimeout(15 * 1000); + connection.connect(); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { + String organization = reader.readLine(); + if ("undefined".equals(organization)) + organization = null; + synchronized (hostOrganization) { + hostOrganization.put(host, organization); + } + return organization; + } + } +}