Increased search timeout

pull/174/head
M66B 6 years ago
parent 06f8be22f2
commit e1a785afc3

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

@ -303,7 +303,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
throw new IllegalStateException(context.getString(R.string.title_no_internet)); throw new IllegalStateException(context.getString(R.string.title_no_internet));
Log.i("Boundary server connecting account=" + account.name); Log.i("Boundary server connecting account=" + account.name);
state.iservice = new EmailService(context, account.getProtocol(), account.realm, account.insecure, false, debug); state.iservice = new EmailService(context, account.getProtocol(), account.realm, account.insecure, EmailService.PURPOSE_SEARCH, debug);
state.iservice.setPartialFetch(account.partial_fetch); state.iservice.setPartialFetch(account.partial_fetch);
state.iservice.setIgnoreBodyStructureSize(account.ignore_size); state.iservice.setIgnoreBodyStructureSize(account.ignore_size);
state.iservice.connect(account); state.iservice.connect(account);

@ -87,7 +87,12 @@ public class EmailService implements AutoCloseable {
static final int AUTH_TYPE_GMAIL = 2; static final int AUTH_TYPE_GMAIL = 2;
static final int AUTH_TYPE_OAUTH = 3; static final int AUTH_TYPE_OAUTH = 3;
static final int PURPOSE_CHECK = 1;
static final int PURPOSE_USE = 2;
static final int PURPOSE_SEARCH = 3;
private final static int CHECK_TIMEOUT = 20 * 1000; // milliseconds private final static int CHECK_TIMEOUT = 20 * 1000; // milliseconds
private final static int SEARCH_TIMEOUT = 2 * 60 * 1000; // milliseconds
private final static int CONNECT_TIMEOUT = 20 * 1000; // milliseconds private final static int CONNECT_TIMEOUT = 20 * 1000; // milliseconds
private final static int WRITE_TIMEOUT = 60 * 1000; // milliseconds private final static int WRITE_TIMEOUT = 60 * 1000; // milliseconds
private final static int READ_TIMEOUT = 60 * 1000; // milliseconds private final static int READ_TIMEOUT = 60 * 1000; // milliseconds
@ -104,7 +109,11 @@ public class EmailService implements AutoCloseable {
// Prevent instantiation // Prevent instantiation
} }
EmailService(Context context, String protocol, String realm, boolean insecure, boolean check, boolean debug) throws NoSuchProviderException { EmailService(Context context, String protocol, String realm, boolean insecure, boolean debug) throws NoSuchProviderException {
this(context, protocol, realm, insecure, PURPOSE_USE, debug);
}
EmailService(Context context, String protocol, String realm, boolean insecure, int purpose, boolean debug) throws NoSuchProviderException {
this.context = context.getApplicationContext(); this.context = context.getApplicationContext();
this.protocol = protocol; this.protocol = protocol;
this.insecure = insecure; this.insecure = insecure;
@ -141,9 +150,20 @@ public class EmailService implements AutoCloseable {
properties.put("mail." + protocol + ".auth.ntlm.domain", realm == null ? "" : realm); properties.put("mail." + protocol + ".auth.ntlm.domain", realm == null ? "" : realm);
// TODO: make timeouts configurable? // TODO: make timeouts configurable?
properties.put("mail." + protocol + ".connectiontimeout", Integer.toString(check ? CHECK_TIMEOUT : CONNECT_TIMEOUT)); // writetimeout: one thread overhead
properties.put("mail." + protocol + ".writetimeout", Integer.toString(check ? CHECK_TIMEOUT : WRITE_TIMEOUT)); // one thread overhead if (purpose == PURPOSE_CHECK) {
properties.put("mail." + protocol + ".timeout", Integer.toString(check ? CHECK_TIMEOUT : READ_TIMEOUT)); properties.put("mail." + protocol + ".connectiontimeout", Integer.toString(CHECK_TIMEOUT));
properties.put("mail." + protocol + ".writetimeout", Integer.toString(CHECK_TIMEOUT));
properties.put("mail." + protocol + ".timeout", Integer.toString(CHECK_TIMEOUT));
} else if (purpose == PURPOSE_SEARCH) {
properties.put("mail." + protocol + ".connectiontimeout", Integer.toString(SEARCH_TIMEOUT));
properties.put("mail." + protocol + ".writetimeout", Integer.toString(SEARCH_TIMEOUT));
properties.put("mail." + protocol + ".timeout", Integer.toString(SEARCH_TIMEOUT));
} else {
properties.put("mail." + protocol + ".connectiontimeout", Integer.toString(CONNECT_TIMEOUT));
properties.put("mail." + protocol + ".writetimeout", Integer.toString(WRITE_TIMEOUT));
properties.put("mail." + protocol + ".timeout", Integer.toString(READ_TIMEOUT));
}
if (debug && BuildConfig.DEBUG) if (debug && BuildConfig.DEBUG)
properties.put("mail.debug.auth", "true"); properties.put("mail.debug.auth", "true");

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

@ -310,7 +310,7 @@ public class FragmentGmail extends FragmentBase {
List<EntityFolder> folders; List<EntityFolder> folders;
String aprotocol = provider.imap.starttls ? "imap" : "imaps"; String aprotocol = provider.imap.starttls ? "imap" : "imaps";
try (EmailService iservice = new EmailService(context, aprotocol, null, false, true, true)) { try (EmailService iservice = new EmailService(context, aprotocol, null, false, EmailService.PURPOSE_CHECK, true)) {
iservice.connect(provider.imap.host, provider.imap.port, EmailService.AUTH_TYPE_GMAIL, null, user, password, null); iservice.connect(provider.imap.host, provider.imap.port, EmailService.AUTH_TYPE_GMAIL, null, user, password, null);
folders = iservice.getFolders(); folders = iservice.getFolders();
@ -320,7 +320,7 @@ public class FragmentGmail extends FragmentBase {
} }
String iprotocol = provider.smtp.starttls ? "smtp" : "smtps"; String iprotocol = provider.smtp.starttls ? "smtp" : "smtps";
try (EmailService iservice = new EmailService(context, iprotocol, null, false, true, true)) { try (EmailService iservice = new EmailService(context, iprotocol, null, false, EmailService.PURPOSE_CHECK, true)) {
iservice.connect(provider.smtp.host, provider.smtp.port, EmailService.AUTH_TYPE_GMAIL, null, user, password, null); iservice.connect(provider.smtp.host, provider.smtp.port, EmailService.AUTH_TYPE_GMAIL, null, user, password, null);
} }

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

@ -469,7 +469,7 @@ public class FragmentOAuth extends FragmentBase {
Log.i("OAuth checking IMAP provider=" + provider.id); Log.i("OAuth checking IMAP provider=" + provider.id);
String aprotocol = provider.imap.starttls ? "imap" : "imaps"; String aprotocol = provider.imap.starttls ? "imap" : "imaps";
try (EmailService iservice = new EmailService(context, aprotocol, null, false, true, true)) { try (EmailService iservice = new EmailService(context, aprotocol, null, false, EmailService.PURPOSE_CHECK, true)) {
iservice.connect(provider.imap.host, provider.imap.port, EmailService.AUTH_TYPE_OAUTH, provider.id, primaryEmail, state, null); iservice.connect(provider.imap.host, provider.imap.port, EmailService.AUTH_TYPE_OAUTH, provider.id, primaryEmail, state, null);
folders = iservice.getFolders(); folders = iservice.getFolders();
@ -480,7 +480,7 @@ public class FragmentOAuth extends FragmentBase {
Log.i("OAuth checking SMTP provider=" + provider.id); Log.i("OAuth checking SMTP provider=" + provider.id);
String iprotocol = provider.smtp.starttls ? "smtp" : "smtps"; String iprotocol = provider.smtp.starttls ? "smtp" : "smtps";
try (EmailService iservice = new EmailService(context, iprotocol, null, false, true, true)) { try (EmailService iservice = new EmailService(context, iprotocol, null, false, EmailService.PURPOSE_CHECK, true)) {
iservice.connect(provider.smtp.host, provider.smtp.port, EmailService.AUTH_TYPE_OAUTH, provider.id, primaryEmail, state, null); iservice.connect(provider.smtp.host, provider.smtp.port, EmailService.AUTH_TYPE_OAUTH, provider.id, primaryEmail, state, null);
} }

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

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

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

@ -801,7 +801,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
boolean debug = (prefs.getBoolean("debug", false) || BuildConfig.DEBUG); boolean debug = (prefs.getBoolean("debug", false) || BuildConfig.DEBUG);
final EmailService iservice = new EmailService( final EmailService iservice = new EmailService(
this, account.getProtocol(), account.realm, account.insecure, false, debug); this, account.getProtocol(), account.realm, account.insecure, debug);
iservice.setPartialFetch(account.partial_fetch); iservice.setPartialFetch(account.partial_fetch);
iservice.setIgnoreBodyStructureSize(account.ignore_size); iservice.setIgnoreBodyStructureSize(account.ignore_size);
if (account.protocol != EntityAccount.TYPE_IMAP) if (account.protocol != EntityAccount.TYPE_IMAP)

Loading…
Cancel
Save