mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-05 00:23:09 +02:00
Refactoring
This commit is contained in:
@@ -2518,7 +2518,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
}
|
||||
} else {
|
||||
ssb.append(personal);
|
||||
if (!Helper.isSingleScript(personal)) {
|
||||
if (!TextHelper.isSingleScript(personal)) {
|
||||
int start = ssb.length() - personal.length();
|
||||
ssb.setSpan(new StrikethroughSpan(), start, ssb.length(), 0);
|
||||
ssb.setSpan(new ForegroundColorSpan(colorError), start, ssb.length(), 0);
|
||||
|
||||
@@ -538,7 +538,7 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
|
||||
} else {
|
||||
etLink.setText(format(uri, context));
|
||||
tvLink.setText(null);
|
||||
tvSuspicious.setVisibility(Helper.isSingleScript(host) ? View.GONE : View.VISIBLE);
|
||||
tvSuspicious.setVisibility(TextHelper.isSingleScript(host) ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
if (check_links_dbl &&
|
||||
|
||||
@@ -2448,32 +2448,6 @@ public class Helper {
|
||||
return false;
|
||||
}
|
||||
|
||||
static boolean isSingleScript(String s) {
|
||||
// https://en.wikipedia.org/wiki/IDN_homograph_attack
|
||||
|
||||
if (TextUtils.isEmpty(s))
|
||||
return true;
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
|
||||
return true;
|
||||
|
||||
int codepoint;
|
||||
Character.UnicodeScript us;
|
||||
Character.UnicodeScript script = null;
|
||||
for (int i = 0; i < s.length(); ) {
|
||||
codepoint = s.codePointAt(i);
|
||||
i += Character.charCount(codepoint);
|
||||
us = Character.UnicodeScript.of(codepoint);
|
||||
if (us.equals(Character.UnicodeScript.COMMON))
|
||||
continue;
|
||||
if (script == null)
|
||||
script = us;
|
||||
else if (!us.equals(script))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static Integer parseInt(String text) {
|
||||
if (TextUtils.isEmpty(text))
|
||||
return null;
|
||||
|
||||
@@ -128,6 +128,32 @@ public class TextHelper {
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isSingleScript(String s) {
|
||||
// https://en.wikipedia.org/wiki/IDN_homograph_attack
|
||||
|
||||
if (TextUtils.isEmpty(s))
|
||||
return true;
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
|
||||
return true;
|
||||
|
||||
int codepoint;
|
||||
Character.UnicodeScript us;
|
||||
Character.UnicodeScript script = null;
|
||||
for (int i = 0; i < s.length(); ) {
|
||||
codepoint = s.codePointAt(i);
|
||||
i += Character.charCount(codepoint);
|
||||
us = Character.UnicodeScript.of(codepoint);
|
||||
if (us.equals(Character.UnicodeScript.COMMON))
|
||||
continue;
|
||||
if (script == null)
|
||||
script = us;
|
||||
else if (!us.equals(script))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static String normalizeNotification(Context context, String text) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean notify_transliterate = prefs.getBoolean("notify_transliterate", false);
|
||||
|
||||
Reference in New Issue
Block a user