[geary/wip/26-proton-mail-bridge] Ensure IDLE is not sent after is it is disabled for a connection.
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/26-proton-mail-bridge] Ensure IDLE is not sent after is it is disabled for a connection.
- Date: Fri, 13 Jul 2018 00:59:10 +0000 (UTC)
commit 2e26d5b4723d286b7000e160df4f66ea29e68e2d
Author: Michael James Gratton <mike vee net>
Date: Fri Jul 13 10:58:29 2018 +1000
Ensure IDLE is not sent after is it is disabled for a connection.
Since the idle timer was not being cancelled, when idle_when_quiet was
set to false the connection would still send IDLE. This also removes the
need to send a NOOP to get in/out of IDLE.
.../imap/transport/imap-client-connection.vala | 45 +++++++++++++++-------
src/engine/imap/transport/imap-client-session.vala | 11 ++----
2 files changed, 36 insertions(+), 20 deletions(-)
---
diff --git a/src/engine/imap/transport/imap-client-connection.vala
b/src/engine/imap/transport/imap-client-connection.vala
index 3e4e4429..bde973d1 100644
--- a/src/engine/imap/transport/imap-client-connection.vala
+++ b/src/engine/imap/transport/imap-client-connection.vala
@@ -64,14 +64,8 @@ public class Geary.Imap.ClientConnection : BaseObject {
* resorting to NOOP keepalives. (Note that keepalives are still
* required to hold the connection open, according to the IMAP
* specification.)
- *
- * Note that setting this false will *not* break a connection out
- * of IDLE state alone; a command needs to be flushed down the
- * pipe to do that. (NOOP would be a good choice.) Nor will this
- * initiate an IDLE command either; it can only do that after
- * sending a command (again, NOOP would be a good choice).
*/
- public bool idle_when_quiet = false;
+ public bool idle_when_quiet { get; private set; default = false; }
private Geary.Endpoint endpoint;
private SocketConnection? cx = null;
@@ -198,6 +192,28 @@ public class Geary.Imap.ClientConnection : BaseObject {
return (this.current_command is IdleCommand);
}
+ /**
+ * Sets whether this connection should automatically IDLE.
+ *
+ * If true, this will cause the connection to send an IDLE command
+ * when no other commands have been sent after a short period of
+ * time
+ *
+ * If false, any existing IDLE command will be cancelled, and the
+ * connection will no longer be automatically sent.
+ */
+ public void enable_idle_when_quiet(bool do_idle) {
+ this.idle_when_quiet = do_idle;
+ if (do_idle) {
+ if (!this.idle_timer.is_running) {
+ this.idle_timer.start();
+ }
+ } else {
+ this.idle_timer.reset();
+ exit_idle();
+ }
+ }
+
/**
* Returns silently if a connection is already established.
*/
@@ -302,12 +318,8 @@ public class Geary.Imap.ClientConnection : BaseObject {
this.pending_queue.send(new_command);
- // If the current command is an IDLE, tell it to exit so we
- // can get on with life.
- IdleCommand? idle = this.current_command as IdleCommand;
- if (idle != null) {
- idle.exit_idle();
- }
+ // Exit IDLE so we can get on with life
+ exit_idle();
}
public string to_string() {
@@ -374,6 +386,13 @@ public class Geary.Imap.ClientConnection : BaseObject {
}
}
+ private inline void exit_idle() {
+ IdleCommand? idle = this.current_command as IdleCommand;
+ if (idle != null) {
+ idle.exit_idle();
+ }
+ }
+
// Generates a unique tag for the IMAP connection in the form of
// "<a-z><000-999>".
private Tag generate_tag() {
diff --git a/src/engine/imap/transport/imap-client-session.vala
b/src/engine/imap/transport/imap-client-session.vala
index 239c48c7..b65b357a 100644
--- a/src/engine/imap/transport/imap-client-session.vala
+++ b/src/engine/imap/transport/imap-client-session.vala
@@ -1129,8 +1129,7 @@ public class Geary.Imap.ClientSession : BaseObject {
case ProtocolState.AUTHORIZED:
case ProtocolState.SELECTED:
case ProtocolState.SELECTING:
- this.cx.idle_when_quiet = true;
- yield send_command_async(new NoopCommand(), cancellable);
+ this.cx.enable_idle_when_quiet(true);
break;
default:
@@ -1403,9 +1402,7 @@ public class Geary.Imap.ClientSession : BaseObject {
debug("[%s]: Unable to SELECT/EXAMINE: %s", to_string(), completion_response.to_string());
// turn off IDLE, client should request it again if desired.
- if (cx.idle_when_quiet) {
- cx.idle_when_quiet = false;
- }
+ this.cx.enable_idle_when_quiet(false);
return State.AUTHORIZED;
}
@@ -1439,7 +1436,7 @@ public class Geary.Imap.ClientSession : BaseObject {
return state;
// returning to AUTHORIZED state, turn off IDLE
- cx.idle_when_quiet = false;
+ this.cx.enable_idle_when_quiet(false);
return State.CLOSING_MAILBOX;
}
@@ -1496,7 +1493,7 @@ public class Geary.Imap.ClientSession : BaseObject {
return state;
// Leaving AUTHORIZED state, turn off IDLE
- cx.idle_when_quiet = false;
+ this.cx.enable_idle_when_quiet(false);
return State.LOGGING_OUT;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]