mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-05 16:43:26 +02:00
Bring back polling
This commit is contained in:
@@ -110,6 +110,7 @@ public class FragmentAccount extends FragmentEx {
|
||||
private ImageButton ibPro;
|
||||
private CheckBox cbSynchronize;
|
||||
private CheckBox cbPrimary;
|
||||
private EditText etInterval;
|
||||
private Button btnCheck;
|
||||
|
||||
private ProgressBar pbCheck;
|
||||
@@ -173,6 +174,7 @@ public class FragmentAccount extends FragmentEx {
|
||||
|
||||
cbSynchronize = view.findViewById(R.id.cbSynchronize);
|
||||
cbPrimary = view.findViewById(R.id.cbPrimary);
|
||||
etInterval = view.findViewById(R.id.etInterval);
|
||||
|
||||
btnCheck = view.findViewById(R.id.btnCheck);
|
||||
pbCheck = view.findViewById(R.id.pbCheck);
|
||||
@@ -429,9 +431,6 @@ public class FragmentAccount extends FragmentEx {
|
||||
throw ex;
|
||||
}
|
||||
|
||||
if (!istore.hasCapability("IDLE"))
|
||||
throw new MessagingException(getContext().getString(R.string.title_no_idle));
|
||||
|
||||
if (!istore.hasCapability("UIDPLUS"))
|
||||
throw new MessagingException(getContext().getString(R.string.title_no_uidplus));
|
||||
|
||||
@@ -567,6 +566,7 @@ public class FragmentAccount extends FragmentEx {
|
||||
args.putInt("color", color);
|
||||
args.putString("signature", Html.toHtml(etSignature.getText()));
|
||||
args.putBoolean("primary", cbPrimary.isChecked());
|
||||
args.putString("interval", etInterval.getText().toString());
|
||||
|
||||
args.putParcelable("drafts", drafts);
|
||||
args.putParcelable("sent", sent);
|
||||
@@ -588,6 +588,7 @@ public class FragmentAccount extends FragmentEx {
|
||||
String signature = args.getString("signature");
|
||||
boolean synchronize = args.getBoolean("synchronize");
|
||||
boolean primary = args.getBoolean("primary");
|
||||
String interval = args.getString("interval");
|
||||
|
||||
EntityFolder drafts = args.getParcelable("drafts");
|
||||
EntityFolder sent = args.getParcelable("sent");
|
||||
@@ -603,6 +604,8 @@ public class FragmentAccount extends FragmentEx {
|
||||
throw new Throwable(getContext().getString(R.string.title_no_user));
|
||||
if (TextUtils.isEmpty(password))
|
||||
throw new Throwable(getContext().getString(R.string.title_no_password));
|
||||
if (TextUtils.isEmpty(interval))
|
||||
interval = "9";
|
||||
if (synchronize && drafts == null)
|
||||
throw new Throwable(getContext().getString(R.string.title_no_drafts));
|
||||
|
||||
@@ -653,7 +656,7 @@ public class FragmentAccount extends FragmentEx {
|
||||
account.synchronize = synchronize;
|
||||
account.primary = (account.synchronize && primary);
|
||||
account.store_sent = false;
|
||||
account.poll_interval = 9;
|
||||
account.poll_interval = Integer.parseInt(interval);
|
||||
|
||||
if (!synchronize)
|
||||
account.error = null;
|
||||
@@ -874,6 +877,7 @@ public class FragmentAccount extends FragmentEx {
|
||||
|
||||
cbSynchronize.setChecked(account == null ? true : account.synchronize);
|
||||
cbPrimary.setChecked(account == null ? true : account.primary);
|
||||
etInterval.setText(Long.toString(account == null ? 9 : account.poll_interval));
|
||||
|
||||
color = (account == null || account.color == null ? Color.TRANSPARENT : account.color);
|
||||
|
||||
|
||||
@@ -642,6 +642,8 @@ public class ServiceSynchronize extends LifecycleService {
|
||||
db.folder().setFolderState(folder.id, null);
|
||||
db.account().setAccountState(account.id, "connecting");
|
||||
Helper.connect(this, istore, account);
|
||||
final boolean capIdle = istore.hasCapability("IDLE");
|
||||
Log.i(Helper.TAG, account.name + " idle=" + capIdle);
|
||||
db.account().setAccountState(account.id, "connected");
|
||||
db.account().setAccountError(account.id, null);
|
||||
|
||||
@@ -813,15 +815,18 @@ public class ServiceSynchronize extends LifecycleService {
|
||||
try {
|
||||
Thread.sleep(account.poll_interval * 60 * 1000L);
|
||||
|
||||
Log.i(Helper.TAG, folder.name + " request NOOP");
|
||||
ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
|
||||
public Object doCommand(IMAPProtocol p) throws ProtocolException {
|
||||
Log.i(Helper.TAG, ifolder.getName() + " start NOOP");
|
||||
p.simpleCommand("NOOP", null);
|
||||
Log.i(Helper.TAG, ifolder.getName() + " end NOOP");
|
||||
return null;
|
||||
}
|
||||
});
|
||||
if (capIdle) {
|
||||
Log.i(Helper.TAG, folder.name + " request NOOP");
|
||||
ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
|
||||
public Object doCommand(IMAPProtocol p) throws ProtocolException {
|
||||
Log.i(Helper.TAG, ifolder.getName() + " start NOOP");
|
||||
p.simpleCommand("NOOP", null);
|
||||
Log.i(Helper.TAG, ifolder.getName() + " end NOOP");
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} else
|
||||
synchronizeMessages(account, folder, ifolder, state);
|
||||
|
||||
} catch (InterruptedException ex) {
|
||||
Log.w(Helper.TAG, folder.name + " noop " + ex.toString());
|
||||
@@ -845,32 +850,34 @@ public class ServiceSynchronize extends LifecycleService {
|
||||
noops.add(noop);
|
||||
|
||||
// Receive folder events
|
||||
Thread idle = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Log.i(Helper.TAG, folder.name + " start idle");
|
||||
while (state.running && ifolder.isOpen()) {
|
||||
//Log.i(Helper.TAG, folder.name + " do idle");
|
||||
ifolder.idle(false);
|
||||
//Log.i(Helper.TAG, folder.name + " done idle");
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.e(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));
|
||||
reportError(account.name, folder.name, ex);
|
||||
if (capIdle) {
|
||||
Thread idle = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Log.i(Helper.TAG, folder.name + " start idle");
|
||||
while (state.running && ifolder.isOpen()) {
|
||||
Log.i(Helper.TAG, folder.name + " do idle");
|
||||
ifolder.idle(false);
|
||||
//Log.i(Helper.TAG, folder.name + " done idle");
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.e(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));
|
||||
reportError(account.name, folder.name, ex);
|
||||
|
||||
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex));
|
||||
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex));
|
||||
|
||||
synchronized (state) {
|
||||
state.notifyAll();
|
||||
synchronized (state) {
|
||||
state.notifyAll();
|
||||
}
|
||||
} finally {
|
||||
Log.i(Helper.TAG, folder.name + " end idle");
|
||||
}
|
||||
} finally {
|
||||
Log.i(Helper.TAG, folder.name + " end idle");
|
||||
}
|
||||
}
|
||||
}, "sync.idle." + folder.id);
|
||||
idle.start();
|
||||
idlers.add(idle);
|
||||
}, "sync.idle." + folder.id);
|
||||
idle.start();
|
||||
idlers.add(idle);
|
||||
}
|
||||
}
|
||||
|
||||
backoff = CONNECT_BACKOFF_START;
|
||||
|
||||
Reference in New Issue
Block a user