mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-18 21:28:54 +00:00
Added get organization for email addresses
This commit is contained in:
parent
4ca69a0bd8
commit
581097d4ff
2 changed files with 22 additions and 3 deletions
|
@ -2197,8 +2197,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
@Override
|
||||
protected String onExecute(Context context, Bundle args) throws Throwable {
|
||||
Uri uri = args.getParcelable("uri");
|
||||
String host = uri.getHost();
|
||||
return (TextUtils.isEmpty(host) ? null : IPInfo.getOrganization(host));
|
||||
return IPInfo.getOrganization(uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,6 +19,10 @@ package eu.faircode.email;
|
|||
Copyright 2018-2019 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.net.MailTo;
|
||||
import android.net.ParseException;
|
||||
import android.net.Uri;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
@ -32,7 +36,23 @@ import javax.net.ssl.HttpsURLConnection;
|
|||
public class IPInfo {
|
||||
private static Map<String, String> hostOrganization = new HashMap<>();
|
||||
|
||||
static String getOrganization(String host) throws IOException {
|
||||
static String getOrganization(Uri uri) throws IOException, ParseException {
|
||||
if ("mailto".equals(uri.getScheme())) {
|
||||
MailTo email = MailTo.parse(uri.toString());
|
||||
String to = email.getTo();
|
||||
if (to == null || !to.contains("@"))
|
||||
return null;
|
||||
String host = to.substring(to.indexOf('@') + 1);
|
||||
return getOrganization(host);
|
||||
} else {
|
||||
String host = uri.getHost();
|
||||
if (host == null)
|
||||
return null;
|
||||
return getOrganization(host);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getOrganization(String host) throws IOException {
|
||||
synchronized (hostOrganization) {
|
||||
if (hostOrganization.containsKey(host))
|
||||
return hostOrganization.get(host);
|
||||
|
|
Loading…
Reference in a new issue