From 28b826a22caa4302aa420d602bffd76d51197482 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 10 Aug 2021 16:27:16 +0200 Subject: [PATCH] Guess URL scheme --- .../java/eu/faircode/email/AdapterMessage.java | 2 -- .../faircode/email/FragmentDialogOpenLink.java | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 9c101989cb..e1e7edd3dc 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -573,8 +573,6 @@ public class AdapterMessage extends RecyclerView.Adapter 0) { String url = link[0].getURL(); Uri uri = Uri.parse(url); - if (uri.getScheme() == null) - uri = Uri.parse("https://" + url); int start = buffer.getSpanStart(link[0]); int end = buffer.getSpanEnd(link[0]); diff --git a/app/src/main/java/eu/faircode/email/FragmentDialogOpenLink.java b/app/src/main/java/eu/faircode/email/FragmentDialogOpenLink.java index e0332da31b..30357c03a2 100644 --- a/app/src/main/java/eu/faircode/email/FragmentDialogOpenLink.java +++ b/app/src/main/java/eu/faircode/email/FragmentDialogOpenLink.java @@ -44,6 +44,7 @@ import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.inputmethod.EditorInfo; +import android.webkit.URLUtil; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; @@ -119,7 +120,7 @@ public class FragmentDialogOpenLink extends FragmentDialogBase { @NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { - final Uri uri = getArguments().getParcelable("uri"); + Uri _uri = getArguments().getParcelable("uri"); String _title = getArguments().getString("title"); if (_title != null) _title = _title.replace("\uFFFC", ""); // Object replacement character @@ -135,6 +136,20 @@ public class FragmentDialogOpenLink extends FragmentDialogBase { // Preload web view Helper.customTabsWarmup(context); + final Uri uri; + if (_uri.getScheme() == null) { + Uri g = Uri.parse(URLUtil.guessUrl(_uri.toString())); + String scheme = g.getScheme(); + if (scheme != null) { + if ("http".equals(scheme)) + scheme = "https"; + uri = Uri.parse(scheme + "://" + _uri.toString()); + } + else + uri = _uri; + } else + uri = _uri; + // Process link final Uri sanitized; if (uri.isOpaque())