1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-24 16:53:37 +00:00

Added option to prefer IPv4

This commit is contained in:
M66B 2020-10-27 13:22:23 +01:00
parent f58182f2a4
commit b051aaf41e
5 changed files with 37 additions and 3 deletions

View file

@ -431,6 +431,18 @@ public class EmailService implements AutoCloseable {
// new SocketConnectException("Debug", new IOException("Test"), host, port, 0));
main = InetAddress.getByName(host);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean prefer_ip4 = prefs.getBoolean("prefer_ip4", false);
if (prefer_ip4 && main instanceof Inet6Address) {
for (InetAddress iaddr : InetAddress.getAllByName(host))
if (iaddr instanceof Inet4Address) {
main = iaddr;
EntityLog.log(context, "Preferring=" + main);
break;
}
}
EntityLog.log(context, "Connecting to " + main);
_connect(main, port, require_id, user, authenticator, factory);
} catch (UnknownHostException ex) {

View file

@ -58,13 +58,14 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
private SwitchCompat swRoaming;
private SwitchCompat swRlah;
private EditText etTimeout;
private SwitchCompat swPreferIp4;
private SwitchCompat swSslHarden;
private Button btnManage;
private TextView tvConnectionType;
private TextView tvConnectionRoaming;
private final static String[] RESET_OPTIONS = new String[]{
"metered", "download", "roaming", "rlah", "timeout", "ssl_harden"
"metered", "download", "roaming", "rlah", "timeout", "prefer_ip4", "ssl_harden"
};
@Override
@ -82,6 +83,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
swRoaming = view.findViewById(R.id.swRoaming);
swRlah = view.findViewById(R.id.swRlah);
etTimeout = view.findViewById(R.id.etTimeout);
swPreferIp4 = view.findViewById(R.id.swPreferIp4);
swSslHarden = view.findViewById(R.id.swSslHarden);
btnManage = view.findViewById(R.id.btnManage);
@ -153,6 +155,13 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
}
});
swPreferIp4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("prefer_ip4", checked).apply();
}
});
swSslHarden.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -266,6 +275,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
etTimeout.setText(timeout == 0 ? null : Integer.toString(timeout));
etTimeout.setHint(Integer.toString(EmailService.DEFAULT_CONNECT_TIMEOUT));
swPreferIp4.setChecked(prefs.getBoolean("prefer_ip4", false));
swSslHarden.setChecked(prefs.getBoolean("ssl_harden", false));
}

View file

@ -134,7 +134,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
"sync_kept",
"sync_folders",
"sync_shared_folders",
"ssl_harden", // force reconnect
"prefer_ip4", "ssl_harden", // force reconnect
"badge", "unseen_ignored", // force update badge/widget
"protocol", "debug", // force reconnect
"auth_plain",

View file

@ -184,6 +184,17 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTimeoutHint" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swPreferIp4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_prefer_ip4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etTimeout"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSslHarden"
android:layout_width="0dp"
@ -193,7 +204,7 @@
android:text="@string/title_advanced_ssl_harden"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etTimeout"
app:layout_constraintTop_toBottomOf="@id/swPreferIp4"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView

View file

@ -328,6 +328,7 @@
<string name="title_advanced_roaming">Download messages and attachments while roaming</string>
<string name="title_advanced_rlah">Roam like at home</string>
<string name="title_advanced_timeout">Connection timeout (seconds)</string>
<string name="title_advanced_prefer_ip4">Prefer IPv4 over IPv6</string>
<string name="title_advanced_ssl_harden">Harden SSL connections</string>
<string name="title_advanced_manage_connectivity">Manage connectivity</string>