From 2b8ec3d34226fcb22e9de44133735bdaba55d1e7 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 26 Jul 2019 17:57:40 +0200 Subject: [PATCH] Added setting to prefer IPv4 addresses --- .../java/eu/faircode/email/ApplicationEx.java | 2 +- .../faircode/email/FragmentOptionsMisc.java | 14 ++++++++++- .../java/eu/faircode/email/MessageHelper.java | 16 +++++++----- .../main/res/layout/fragment_options_misc.xml | 25 ++++++++++++++++++- app/src/main/res/values/strings.xml | 2 ++ 5 files changed, 50 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ApplicationEx.java b/app/src/main/java/eu/faircode/email/ApplicationEx.java index 207817fab4..8b1e6419e3 100644 --- a/app/src/main/java/eu/faircode/email/ApplicationEx.java +++ b/app/src/main/java/eu/faircode/email/ApplicationEx.java @@ -103,7 +103,7 @@ public class ApplicationEx extends Application { if (Helper.hasWebView(this)) CookieManager.getInstance().setAcceptCookie(false); - MessageHelper.setSystemProperties(); + MessageHelper.setSystemProperties(this); ContactInfo.init(this); try { diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index 449378747f..d1b764693f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -55,6 +55,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private SwitchCompat swDoubleBack; private SwitchCompat swEnglish; private SwitchCompat swWatchdog; + private SwitchCompat swPreferIp4; private SwitchCompat swUpdates; private SwitchCompat swCrashReports; private SwitchCompat swDebug; @@ -68,7 +69,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private Group grpDebug; private final static String[] RESET_OPTIONS = new String[]{ - "badge", "subscriptions", "subscribed_only", "biometrics_timeout", "double_back", "english", "watchdog", "updates", "crash_reports", "debug" + "badge", "subscriptions", "subscribed_only", "biometrics_timeout", "double_back", "english", "watchdog", "prefer_ip4", "updates", "crash_reports", "debug" }; private final static String[] RESET_QUESTIONS = new String[]{ @@ -93,6 +94,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swDoubleBack = view.findViewById(R.id.swDoubleBack); swEnglish = view.findViewById(R.id.swEnglish); swWatchdog = view.findViewById(R.id.swWatchdog); + swPreferIp4 = view.findViewById(R.id.swPreferIp4); swUpdates = view.findViewById(R.id.swUpdates); swCrashReports = view.findViewById(R.id.swCrashReports); swDebug = view.findViewById(R.id.swDebug); @@ -172,6 +174,15 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc } }); + swPreferIp4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("prefer_ip4", checked).apply(); + System.setProperty("java.net.preferIPv4Stack", Boolean.toString(checked)); + ServiceSynchronize.reload(getContext(), "prefer_ip4=" + checked); + } + }); + swUpdates.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -310,6 +321,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swDoubleBack.setChecked(prefs.getBoolean("double_back", true)); swEnglish.setChecked(prefs.getBoolean("english", false)); swWatchdog.setChecked(prefs.getBoolean("watchdog", true)); + swPreferIp4.setChecked(prefs.getBoolean("prefer_ip4", false)); swUpdates.setChecked(prefs.getBoolean("updates", true)); swUpdates.setVisibility(Helper.isPlayStoreInstall(getContext()) ? View.GONE : View.VISIBLE); swCrashReports.setChecked(prefs.getBoolean("crash_reports", false)); diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index d8b65fa2a8..269d23a30d 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -20,10 +20,13 @@ package eu.faircode.email; */ import android.content.Context; +import android.content.SharedPreferences; import android.net.MailTo; import android.text.TextUtils; import android.webkit.MimeTypeMap; +import androidx.preference.PreferenceManager; + import com.sun.mail.util.FolderClosedIOException; import com.sun.mail.util.MessageRemovedIOException; @@ -86,7 +89,7 @@ public class MessageHelper { static final int DEFAULT_ATTACHMENT_DOWNLOAD_SIZE = 256 * 1024; // bytes - static void setSystemProperties() { + static void setSystemProperties(Context context) { System.setProperty("mail.mime.decodetext.strict", "false"); System.setProperty("mail.mime.ignoreunknownencoding", "true"); // Content-Transfer-Encoding @@ -99,6 +102,12 @@ public class MessageHelper { // https://docs.oracle.com/javaee/6/api/javax/mail/internet/MimeMultipart.html System.setProperty("mail.mime.multipart.ignoremissingboundaryparameter", "true"); // javax.mail.internet.ParseException: In parameter list System.setProperty("mail.mime.multipart.ignoreexistingboundaryparameter", "true"); + + // https://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean prefer_ip4 = prefs.getBoolean("prefer_ip4", false); + Log.i("Prefer ip4=" + prefer_ip4); + System.setProperty("java.net.preferIPv4Stack", Boolean.toString(prefer_ip4)); } static Properties getSessionProperties(String realm, boolean insecure) { @@ -194,11 +203,6 @@ public class MessageHelper { props.put("mail.mime.allowutf8", "false"); // SMTPTransport, MimeMessage props.put("mail.mime.address.strict", "false"); - if (false) { - Log.i("Prefering IPv4"); - System.setProperty("java.net.preferIPv4Stack", "true"); - } - return props; } diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml index 296afd2506..e8580b0256 100644 --- a/app/src/main/res/layout/fragment_options_misc.xml +++ b/app/src/main/res/layout/fragment_options_misc.xml @@ -158,6 +158,29 @@ app:layout_constraintTop_toBottomOf="@id/tvEnglishHint" app:switchPadding="12dp" /> + + + + Double \'back\' to exit Force English language Periodically check if FairEmail is still active + Prefer IPv4 addresses Check for updates Send error reports Debug mode @@ -300,6 +301,7 @@ Only available on supported launchers Enabling this will delete all local folders without subscription This will restart the app + Enable this only if IPv6 connectivity does not work properly Enable extra logging and show debug information at various places This will delete all temporary files