Check with reduced timeout

pull/163/head
M66B 5 years ago
parent 064e6a53fc
commit 6e29e09de5

@ -241,7 +241,7 @@ public class ActivityEML extends ActivityBase {
Session isession = Session.getInstance(props, null);
MimeMessage imessage = new MimeMessage(isession, is);
try (MailService iservice = new MailService(context, account.getProtocol(), account.realm, account.insecure, true)) {
try (MailService iservice = new MailService(context, account.getProtocol(), account.realm, account.insecure, false, true)) {
iservice.setPartialFetch(account.partial_fetch);
iservice.setIgnoreBodyStructureSize(account.ignore_size);
iservice.setSeparateStoreConnection();

@ -252,7 +252,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
boolean debug = (prefs.getBoolean("debug", false) || BuildConfig.BETA_RELEASE);
Log.i("Boundary server connecting account=" + account.name);
state.iservice = new MailService(context, account.getProtocol(), account.realm, account.insecure, debug);
state.iservice = new MailService(context, account.getProtocol(), account.realm, account.insecure, false, debug);
state.iservice.setPartialFetch(account.partial_fetch);
state.iservice.setIgnoreBodyStructureSize(account.ignore_size);
state.iservice.setSeparateStoreConnection();

@ -552,7 +552,7 @@ public class FragmentAccount extends FragmentBase {
// Check IMAP server / get folders
String protocol = "imap" + (starttls ? "" : "s");
try (MailService iservice = new MailService(context, protocol, realm, insecure, true)) {
try (MailService iservice = new MailService(context, protocol, realm, insecure, true, true)) {
iservice.connect(host, Integer.parseInt(port), auth, user, password);
result.idle = iservice.hasCapability("IDLE");
@ -896,7 +896,7 @@ public class FragmentAccount extends FragmentBase {
EntityFolder inbox = null;
if (check) {
String protocol = "imap" + (starttls ? "" : "s");
try (MailService iservice = new MailService(context, protocol, realm, insecure, true)) {
try (MailService iservice = new MailService(context, protocol, realm, insecure, true, true)) {
iservice.connect(host, Integer.parseInt(port), auth, user, password);
for (Folder ifolder : iservice.getStore().getDefaultFolder().list("*")) {

@ -295,7 +295,7 @@ public class FragmentGmail extends FragmentBase {
String domain = user.split("@")[1];
String aprotocol = provider.imap.starttls ? "imap" : "imaps";
try (MailService iservice = new MailService(context, aprotocol, null, false, true)) {
try (MailService iservice = new MailService(context, aprotocol, null, false, true, true)) {
iservice.connect(provider.imap.host, provider.imap.port, MailService.AUTH_TYPE_GMAIL, user, password);
folders = iservice.getFolders();
@ -306,7 +306,7 @@ public class FragmentGmail extends FragmentBase {
}
String iprotocol = provider.smtp.starttls ? "smtp" : "smtps";
try (MailService iservice = new MailService(context, iprotocol, null, false, true)) {
try (MailService iservice = new MailService(context, iprotocol, null, false, true, true)) {
iservice.connect(provider.smtp.host, provider.smtp.port, MailService.AUTH_TYPE_GMAIL, user, password);
}

@ -698,7 +698,7 @@ public class FragmentIdentity extends FragmentBase {
if (check) {
// Create transport
String protocol = (starttls ? "smtp" : "smtps");
try (MailService iservice = new MailService(context, protocol, realm, insecure, true)) {
try (MailService iservice = new MailService(context, protocol, realm, insecure, true, true)) {
iservice.setUseIp(use_ip);
iservice.connect(host, Integer.parseInt(port), auth, user, password);
}

@ -271,7 +271,7 @@ public class FragmentPop extends FragmentBase {
// Check POP3 server
if (check) {
String protocol = "pop3" + (starttls ? "" : "s");
try (MailService iservice = new MailService(context, protocol, null, insecure, true)) {
try (MailService iservice = new MailService(context, protocol, null, insecure, true, true)) {
iservice.connect(host, Integer.parseInt(port), MailService.AUTH_TYPE_PASSWORD, user, password);
}
}

@ -245,7 +245,7 @@ public class FragmentQuickSetup extends FragmentBase {
List<EntityFolder> folders;
String aprotocol = provider.imap.starttls ? "imap" : "imaps";
try (MailService iservice = new MailService(context, aprotocol, null, false, true)) {
try (MailService iservice = new MailService(context, aprotocol, null, false, true, true)) {
try {
iservice.connect(provider.imap.host, provider.imap.port, MailService.AUTH_TYPE_PASSWORD, user, password);
} catch (AuthenticationFailedException ex) {
@ -267,7 +267,7 @@ public class FragmentQuickSetup extends FragmentBase {
}
String iprotocol = provider.smtp.starttls ? "smtp" : "smtps";
try (MailService iservice = new MailService(context, iprotocol, null, false, true)) {
try (MailService iservice = new MailService(context, iprotocol, null, false, true, true)) {
iservice.connect(provider.smtp.host, provider.smtp.port, MailService.AUTH_TYPE_PASSWORD, user, password);
}

@ -46,6 +46,7 @@ public class MailService implements AutoCloseable {
static final int AUTH_TYPE_PASSWORD = 1;
static final int AUTH_TYPE_GMAIL = 2;
private final static int CHECK_TIMEOUT = 15 * 1000; // milliseconds
private final static int CONNECT_TIMEOUT = 20 * 1000; // milliseconds
private final static int WRITE_TIMEOUT = 60 * 1000; // milliseconds
private final static int READ_TIMEOUT = 60 * 1000; // milliseconds
@ -57,7 +58,7 @@ public class MailService implements AutoCloseable {
private MailService() {
}
MailService(Context context, String protocol, String realm, boolean insecure, boolean debug) throws NoSuchProviderException {
MailService(Context context, String protocol, String realm, boolean insecure, boolean check, boolean debug) throws NoSuchProviderException {
this.context = context.getApplicationContext();
this.protocol = protocol;
this.debug = debug;
@ -70,6 +71,11 @@ public class MailService implements AutoCloseable {
properties.put("mail." + protocol + ".sasl.realm", realm == null ? "" : realm);
properties.put("mail." + protocol + ".auth.ntlm.domain", realm == null ? "" : realm);
// TODO: make timeouts configurable?
properties.put("mail." + protocol + ".connectiontimeout", Integer.toString(check ? CHECK_TIMEOUT : CONNECT_TIMEOUT));
properties.put("mail." + protocol + ".writetimeout", Integer.toString(check ? CHECK_TIMEOUT : WRITE_TIMEOUT)); // one thread overhead
properties.put("mail." + protocol + ".timeout", Integer.toString(check ? CHECK_TIMEOUT : READ_TIMEOUT));
if (debug && BuildConfig.DEBUG)
properties.put("mail.debug.auth", "true");
@ -85,11 +91,6 @@ public class MailService implements AutoCloseable {
properties.put("mail.pop3.starttls.enable", "true");
properties.put("mail.pop3.starttls.required", Boolean.toString(!insecure));
// TODO: make timeouts configurable?
properties.put("mail." + protocol + ".connectiontimeout", Integer.toString(CONNECT_TIMEOUT));
properties.put("mail." + protocol + ".writetimeout", Integer.toString(WRITE_TIMEOUT)); // one thread overhead
properties.put("mail." + protocol + ".timeout", Integer.toString(READ_TIMEOUT));
} else if ("imap".equals(protocol) || "imaps".equals(protocol)) {
// https://javaee.github.io/javamail/docs/api/com/sun/mail/imap/package-summary.html#properties
properties.put("mail." + protocol + ".ssl.checkserveridentity", Boolean.toString(!insecure));
@ -100,11 +101,6 @@ public class MailService implements AutoCloseable {
properties.put("mail.imap.starttls.enable", "true");
properties.put("mail.imap.starttls.required", Boolean.toString(!insecure));
// TODO: make timeouts configurable?
properties.put("mail." + protocol + ".connectiontimeout", Integer.toString(CONNECT_TIMEOUT));
properties.put("mail." + protocol + ".writetimeout", Integer.toString(WRITE_TIMEOUT)); // one thread overhead
properties.put("mail." + protocol + ".timeout", Integer.toString(READ_TIMEOUT));
properties.put("mail." + protocol + ".connectionpool.debug", "true");
properties.put("mail." + protocol + ".connectionpoolsize", "2");
properties.put("mail." + protocol + ".connectionpooltimeout", Integer.toString(POOL_TIMEOUT));
@ -135,10 +131,6 @@ public class MailService implements AutoCloseable {
properties.put("mail." + protocol + ".auth", "true");
properties.put("mail." + protocol + ".connectiontimeout", Integer.toString(CONNECT_TIMEOUT));
properties.put("mail." + protocol + ".writetimeout", Integer.toString(WRITE_TIMEOUT)); // one thread overhead
properties.put("mail." + protocol + ".timeout", Integer.toString(READ_TIMEOUT));
} else
throw new NoSuchProviderException(protocol);
}

@ -388,7 +388,7 @@ public class ServiceSend extends ServiceBase {
// Create transport
try (MailService iservice = new MailService(
this, ident.getProtocol(), ident.realm, ident.insecure, debug)) {
this, ident.getProtocol(), ident.realm, ident.insecure, false, debug)) {
iservice.setUseIp(ident.use_ip);
// Connect transport

@ -720,7 +720,7 @@ public class ServiceSynchronize extends ServiceBase {
boolean debug = (prefs.getBoolean("debug", false) || BuildConfig.DEBUG);
final MailService iservice = new MailService(
this, account.getProtocol(), account.realm, account.insecure, debug);
this, account.getProtocol(), account.realm, account.insecure, false, debug);
iservice.setPartialFetch(account.partial_fetch);
iservice.setIgnoreBodyStructureSize(account.ignore_size);
if (account.pop)

Loading…
Cancel
Save