Removed prefer IPv4 settings, refactoring

This commit is contained in:
M66B
2019-07-27 16:40:51 +02:00
parent 4a72f7ff90
commit f661a7c09b
11 changed files with 29 additions and 62 deletions

View File

@@ -282,7 +282,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
Log.i("Boundary server connecting account=" + account.name);
istore = (IMAPStore) isession.getStore(protocol);
ConnectionHelper.connect(context, istore, account);
ConnectionHelper.connect(context, isession, istore, account);
Log.i("Boundary server opening folder=" + browsable.name);
ifolder = (IMAPFolder) istore.getFolder(browsable.name);

View File

@@ -32,6 +32,8 @@ import java.util.Map;
import javax.mail.Address;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
public class ConnectionHelper {
@@ -254,8 +256,16 @@ public class ConnectionHelper {
return true;
}
static void connect(Context context, IMAPStore istore, EntityAccount account) throws MessagingException {
istore.connect(account.host, account.port, account.user, account.password);
static void connect(Context context, Session isession, IMAPStore istore, EntityAccount account) throws MessagingException {
connect(context, isession, istore, account.host, account.port, account.user, account.password);
}
static void connect(Context context, Session isession, Transport itransport, EntityIdentity identity) throws MessagingException {
connect(context, isession, itransport, identity.host, identity.port, identity.user, identity.password);
}
static void connect(Context context, Session isession, IMAPStore istore, String host, int port, String user, String password) throws MessagingException {
istore.connect(host, port, user, password);
// https://www.ietf.org/rfc/rfc2971.txt
if (istore.hasCapability("ID"))
@@ -277,6 +287,10 @@ public class ConnectionHelper {
}
}
static void connect(Context context, Session isession, Transport itransport, String host, int port, String user, String password) throws MessagingException {
itransport.connect(host, port, user, password);
}
static boolean airplaneMode(Context context) {
return Settings.System.getInt(context.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0) != 0;

View File

@@ -72,7 +72,6 @@ import java.util.Properties;
import javax.mail.Folder;
import javax.mail.Session;
import javax.mail.Store;
import static android.app.Activity.RESULT_OK;
import static com.google.android.material.textfield.TextInputLayout.END_ICON_NONE;
@@ -536,10 +535,10 @@ public class FragmentAccount extends FragmentBase {
Properties props = MessageHelper.getSessionProperties(realm, insecure);
Session isession = Session.getInstance(props, null);
isession.setDebug(true);
try (Store istore = isession.getStore("imap" + (starttls ? "" : "s"))) {
istore.connect(host, Integer.parseInt(port), user, password);
try (IMAPStore istore = (IMAPStore) isession.getStore("imap" + (starttls ? "" : "s"))) {
ConnectionHelper.connect(context, isession, istore, host, Integer.parseInt(port), user, password);
result.idle = ((IMAPStore) istore).hasCapability("IDLE");
result.idle = istore.hasCapability("IDLE");
boolean inbox = false;
boolean archive = false;
@@ -893,8 +892,8 @@ public class FragmentAccount extends FragmentBase {
Session isession = Session.getInstance(props, null);
isession.setDebug(true);
try (Store istore = isession.getStore("imap" + (starttls ? "" : "s"))) {
istore.connect(host, Integer.parseInt(port), user, password);
try (IMAPStore istore = (IMAPStore) isession.getStore("imap" + (starttls ? "" : "s"))) {
ConnectionHelper.connect(context, isession, istore, host, Integer.parseInt(port), user, password);
for (Folder ifolder : istore.getDefaultFolder().list("*")) {
// Check folder attributes

View File

@@ -703,7 +703,7 @@ public class FragmentIdentity extends FragmentBase {
// Create transport
try (Transport itransport = isession.getTransport(protocol)) {
itransport.connect(host, Integer.parseInt(port), user, password);
ConnectionHelper.connect(context, isession, itransport, host, Integer.parseInt(port), user, password);
}
}

View File

@@ -55,7 +55,6 @@ 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;
@@ -69,7 +68,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", "prefer_ip4", "updates", "crash_reports", "debug"
"badge", "subscriptions", "subscribed_only", "biometrics_timeout", "double_back", "english", "watchdog", "updates", "crash_reports", "debug"
};
private final static String[] RESET_QUESTIONS = new String[]{
@@ -94,7 +93,6 @@ 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);
@@ -174,15 +172,6 @@ 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) {
@@ -321,7 +310,6 @@ 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));

View File

@@ -243,7 +243,7 @@ public class FragmentQuickSetup extends FragmentBase {
Session isession = Session.getInstance(props, null);
isession.setDebug(true);
try (IMAPStore istore = (IMAPStore) isession.getStore(provider.imap_starttls ? "imap" : "imaps")) {
istore.connect(provider.imap_host, provider.imap_port, user, password);
ConnectionHelper.connect(context, isession, istore, provider.imap_host, provider.imap_port, user, password);
boolean inbox = false;
boolean drafts = false;
@@ -307,7 +307,7 @@ public class FragmentQuickSetup extends FragmentBase {
Session isession = Session.getInstance(props, null);
isession.setDebug(true);
try (Transport itransport = isession.getTransport(provider.smtp_starttls ? "smtp" : "smtps")) {
itransport.connect(provider.smtp_host, provider.smtp_port, user, password);
ConnectionHelper.connect(context, isession, itransport, provider.smtp_host, provider.smtp_port, user, password);
}
}

View File

@@ -20,13 +20,10 @@ 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;
@@ -102,12 +99,6 @@ 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) {

View File

@@ -367,7 +367,7 @@ public class ServiceSend extends ServiceBase {
try (Transport itransport = isession.getTransport(protocol)) {
// Connect transport
db.identity().setIdentityState(ident.id, "connecting");
itransport.connect(ident.host, ident.port, ident.user, ident.password);
ConnectionHelper.connect(this, isession, itransport, ident);
db.identity().setIdentityState(ident.id, "connected");
// Send message

View File

@@ -730,7 +730,7 @@ public class ServiceSynchronize extends ServiceBase {
db.account().setAccountState(account.id, "connecting");
try {
ConnectionHelper.connect(this, istore, account);
ConnectionHelper.connect(this, isession, istore, account);
} catch (Throwable ex) {
if (ex instanceof AuthenticationFailedException) {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);