mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-10 11:03:41 +02:00
Show organization for host
This commit is contained in:
@@ -1704,18 +1704,58 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
}
|
||||
}
|
||||
|
||||
private void onOpenLink(Uri uri) {
|
||||
private void onOpenLink(final Uri uri) {
|
||||
if (BuildConfig.APPLICATION_ID.equals(uri.getHost()) && "/activate/".equals(uri.getPath())) {
|
||||
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
||||
lbm.sendBroadcast(
|
||||
new Intent(ActivityView.ACTION_ACTIVATE_PRO)
|
||||
.putExtra("uri", uri));
|
||||
} else {
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.dialog_link, null);
|
||||
final EditText etLink = view.findViewById(R.id.etLink);
|
||||
final CheckBox cbOrganization = view.findViewById(R.id.cbOrganization);
|
||||
TextView tvInsecure = view.findViewById(R.id.tvInsecure);
|
||||
|
||||
cbOrganization.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
prefs.edit().putBoolean("show_organization", isChecked).apply();
|
||||
if (isChecked) {
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable("uri", uri);
|
||||
|
||||
new SimpleTask<String>() {
|
||||
@Override
|
||||
protected void onPreExecute(Bundle args) {
|
||||
cbOrganization.setText("…");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String onExecute(Context context, Bundle args) throws Throwable {
|
||||
Uri uri = args.getParcelable("uri");
|
||||
String host = uri.getHost();
|
||||
return (TextUtils.isEmpty(host) ? null : Helper.getOrganization(host));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, String organization) {
|
||||
cbOrganization.setText(organization == null ? "?" : organization);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
cbOrganization.setText(ex.getMessage());
|
||||
}
|
||||
}.execute(context, owner, args, "link:domain");
|
||||
} else
|
||||
cbOrganization.setText(R.string.title_show_organization);
|
||||
}
|
||||
});
|
||||
|
||||
etLink.setText(uri.toString());
|
||||
cbOrganization.setChecked(prefs.getBoolean("show_organization", true));
|
||||
tvInsecure.setVisibility("http".equals(uri.getScheme()) ? View.VISIBLE : View.GONE);
|
||||
|
||||
new DialogBuilderLifecycle(context, owner)
|
||||
|
||||
@@ -123,7 +123,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
||||
"notify_preview", "search_local", "light", "sound",
|
||||
"updates", "debug",
|
||||
"first", "why", "last_update_check", "app_support", "message_swipe", "message_select", "folder_actions", "folder_sync",
|
||||
"edit_ref_confirmed", "show_html_confirmed", "show_images_confirmed", "print_html_confirmed"
|
||||
"edit_ref_confirmed", "show_html_confirmed", "show_images_confirmed", "print_html_confirmed", "show_organization"
|
||||
};
|
||||
|
||||
@Override
|
||||
|
||||
@@ -73,6 +73,8 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@@ -93,6 +95,7 @@ import javax.mail.MessageRemovedException;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Store;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.browser.customtabs.CustomTabsIntent;
|
||||
@@ -1000,4 +1003,19 @@ public class Helper {
|
||||
static String sanitizeFilename(String name) {
|
||||
return (name == null ? null : name.replaceAll("[^a-zA-Z0-9\\.\\-]", "_"));
|
||||
}
|
||||
|
||||
static String getOrganization(String host) throws IOException {
|
||||
InetAddress address = InetAddress.getByName(host);
|
||||
URL url = new URL("https://ipinfo.io/" + address.getHostAddress() + "/org");
|
||||
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;
|
||||
return organization;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user