[geary/wip/714104-refine-account-dialog: 59/69] Implement ClientService for IMAP (2/3)



commit 62c90e40db335d07d9d0b999d5a5c90db4ad0c7b
Author: Michael Gratton <mike vee net>
Date:   Sun Nov 18 22:13:25 2018 +1100

    Implement ClientService for IMAP (2/3)
    
    Rename ClientSessionManager to ClientService, make it extend Geary.ClientService and implement
    its signauture. Use this as GenericAccount's incoming client service.
    
    Part two of a three part series.

 po/POTFILES.in                                     |   2 +-
 .../imap-engine/imap-engine-generic-account.vala   |  84 +++++-----
 .../imap-engine/imap-engine-minimal-folder.vala    |  12 +-
 .../imap-client-service.vala}                      | 171 ++++++++++-----------
 src/engine/meson.build                             |   2 +-
 5 files changed, 133 insertions(+), 138 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 543faa84..dd8898ca 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -187,6 +187,7 @@ src/engine/db/db-versioned-database.vala
 src/engine/imap/imap.vala
 src/engine/imap/imap-error.vala
 src/engine/imap/api/imap-account-session.vala
+src/engine/imap/api/imap-client-service.vala
 src/engine/imap/api/imap-email-flags.vala
 src/engine/imap/api/imap-email-properties.vala
 src/engine/imap/api/imap-folder.vala
@@ -329,7 +330,6 @@ src/engine/imap/response/imap-status-data.vala
 src/engine/imap/response/imap-status-response.vala
 src/engine/imap/response/imap-status.vala
 src/engine/imap/transport/imap-client-connection.vala
-src/engine/imap/transport/imap-client-session-manager.vala
 src/engine/imap/transport/imap-client-session.vala
 src/engine/imap/transport/imap-deserializer.vala
 src/engine/imap/transport/imap-serializer.vala
diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala 
b/src/engine/imap-engine/imap-engine-generic-account.vala
index c3ad84e7..9a198788 100644
--- a/src/engine/imap-engine/imap-engine-generic-account.vala
+++ b/src/engine/imap-engine/imap-engine-generic-account.vala
@@ -34,7 +34,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
     public override ClientService outgoing { get { return this.smtp; } }
 
     /** Service for incoming IMAP connections. */
-    public ClientService imap  { get; private set; }
+    public Imap.ClientService imap  { get; private set; }
 
     /** Service for outgoing SMTP connections. */
     public ClientService smtp { get; private set; }
@@ -42,9 +42,6 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
     /** Local database for the account. */
     public ImapDB.Account local { get; private set; }
 
-    /** This account's IMAP session pool. */
-    public Imap.ClientSessionManager session_pool { get; private set; }
-
     private bool open = false;
     private Cancellable? open_cancellable = null;
     private Nonblocking.Semaphore? remote_ready_lock = null;
@@ -70,16 +67,11 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
                           Geary.AccountInformation information,
                           ImapDB.Account local) {
         base(name, information);
-
-        this.session_pool = new Imap.ClientSessionManager(
-            this.information.id,
-            null, //this.information.imap.endpoint,
-            this.information.imap.credentials
-        );
-        this.session_pool.min_pool_size = IMAP_MIN_POOL_SIZE;
-        this.session_pool.ready.connect(on_pool_session_ready);
-        this.session_pool.connection_failed.connect(on_pool_connection_failed);
-        this.session_pool.login_failed.connect(on_pool_login_failed);
+        this.imap = new Imap.ClientService(information, information.imap);
+        this.imap.min_pool_size = IMAP_MIN_POOL_SIZE;
+        this.imap.ready.connect(on_pool_session_ready);
+        this.imap.connection_failed.connect(on_pool_connection_failed);
+        this.imap.login_failed.connect(on_pool_login_failed);
 
         this.local = local;
         this.local.contacts_loaded.connect(() => { contacts_loaded(); });
@@ -121,18 +113,6 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
         // Reset this so we start trying to authenticate again
         this.authentication_failures = 0;
 
-        // To prevent spurious connection failures, we make sure we
-        // have the IMAP password before attempting a connection.
-        if (yield this.information.load_imap_credentials(cancellable)) {
-            this.session_pool.credentials_updated(
-                this.information.imap.credentials
-            );
-        }
-
-        // This will cause the session manager to open at least one
-        // connection if we are online
-        yield this.session_pool.open_async(cancellable);
-
         this.processor = new AccountProcessor(this.to_string());
         this.processor.operation_error.connect(on_operation_error);
 
@@ -166,6 +146,11 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
         this.queue_operation(
             new LoadFolders(this, this.local, get_supported_special_folders())
         );
+
+        // To prevent spurious connection failures, we make sure we
+        // have passwords before attempting a connection.
+        yield this.information.load_imap_credentials(cancellable);
+        yield this.imap.start(cancellable);
     }
 
     public override async void close_async(Cancellable? cancellable = null) throws Error {
@@ -174,7 +159,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
 
         // Block obtaining and reusing IMAP server connections
         this.remote_ready_lock.reset();
-        this.session_pool.discard_returned_sessions = true;
+        this.imap.discard_returned_sessions = true;
 
         // Halt internal tasks early so they stop using local and
         // remote connections.
@@ -202,14 +187,13 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
             yield folder.wait_for_close_async();
         }
 
-        // Close remote infrastructure
+        // Close IMAP service manager
 
         try {
-            yield this.session_pool.close_async(cancellable);
+            yield this.imap.stop();
         } catch (Error err) {
-            debug("%s: Error closing IMAP session pool: %s",
-                  to_string(),
-                  this.session_pool.to_string()
+            debug(
+                "%s: Error stopping IMAP service: %s", to_string(), err.message
             );
         }
         this.remote_ready_lock = null;
@@ -295,7 +279,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
         debug("%s: Acquiring account session", this.to_string());
         yield this.remote_ready_lock.wait_async(cancellable);
         Imap.ClientSession client =
-            yield this.session_pool.claim_authorized_session_async(cancellable);
+            yield this.imap.claim_authorized_session_async(cancellable);
         return new Imap.AccountSession(this.information.id, client);
     }
 
@@ -306,11 +290,11 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
         debug("%s: Releasing account session", this.to_string());
         Imap.ClientSession? old_session = session.close();
         if (old_session != null) {
-            this.session_pool.release_session_async.begin(
+            this.imap.release_session_async.begin(
                 old_session,
                 (obj, res) => {
                     try {
-                        this.session_pool.release_session_async.end(res);
+                        this.imap.release_session_async.end(res);
                     } catch (Error err) {
                         debug("%s: Error releasing account session: %s",
                               to_string(),
@@ -344,7 +328,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
         // single session from the pool, not two.
 
         Imap.ClientSession? client =
-            yield this.session_pool.claim_authorized_session_async(cancellable);
+            yield this.imap.claim_authorized_session_async(cancellable);
         Imap.AccountSession account = new Imap.AccountSession(
             this.information.id, client
         );
@@ -372,7 +356,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
 
         if (folder_err != null) {
             try {
-                yield this.session_pool.release_session_async(client);
+                yield this.imap.release_session_async(client);
             } catch (Error release_err) {
                 debug("Error releasing folder session: %s", release_err.message);
             }
@@ -391,7 +375,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
         Imap.ClientSession? old_session = session.close();
         if (old_session != null) {
             try {
-                yield this.session_pool.release_session_async(old_session);
+                yield this.imap.release_session_async(old_session);
             } catch (Error err) {
                 debug("%s: Error releasing %s session: %s",
                       to_string(),
@@ -969,6 +953,26 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
             throw new EngineError.OPEN_REQUIRED("Account %s not opened", to_string());
     }
 
+    private async void restart_incoming_service() {
+        if (this.incoming.is_running) {
+            try {
+                yield this.incoming.stop(this.open_cancellable);
+            } catch (GLib.Error err) {
+                debug("%s: Failed to stop incoming mail service: %s",
+                      to_string(), err.message
+                );
+            }
+        }
+        try {
+            yield this.incoming.start(this.open_cancellable);
+        } catch (GLib.Error err) {
+            debug("%s: Failed to start incoming mail service: %s",
+                  to_string(), err.message
+            );
+        }
+
+    }
+
     private void on_operation_error(AccountOperation op, Error error) {
         if (error is ImapError) {
             notify_service_problem(
@@ -1046,9 +1050,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
                         try {
                             if (this.information.prompt_imap_credentials.end(ret)) {
                                 // Have a new password, so try that
-                                this.session_pool.credentials_updated(
-                                    this.information.imap.credentials
-                                );
+                                this.restart_incoming_service.begin();
                             } else {
                                 // User cancelled, so indicate a login problem
                                 notify_imap_problem(ProblemType.LOGIN_FAILED, null);
diff --git a/src/engine/imap-engine/imap-engine-minimal-folder.vala 
b/src/engine/imap-engine/imap-engine-minimal-folder.vala
index 05bc44d3..abbca331 100644
--- a/src/engine/imap-engine/imap-engine-minimal-folder.vala
+++ b/src/engine/imap-engine/imap-engine-minimal-folder.vala
@@ -776,12 +776,12 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
         // and close lots of folders, causing a lot of connection
         // setup and teardown
         //
-        // However, want to eventually open, otherwise if there's no
-        // user interaction (i.e. a second account Inbox they don't
+        // However, we want to eventually open, otherwise if there's
+        // no user interaction (i.e. a second account Inbox they don't
         // manipulate), no remote connection will ever be made,
         // meaning that folder normalization never happens and
         // unsolicited notifications never arrive
-        this._account.session_pool.ready.connect(on_remote_ready);
+        this._account.imap.ready.connect(on_remote_ready);
         if (open_flags.is_all_set(OpenFlags.NO_DELAY)) {
             this.open_remote_session.begin();
         } else {
@@ -822,7 +822,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
 
         // Ensure we don't attempt to start opening a remote while
         // closing
-        this._account.session_pool.ready.disconnect(on_remote_ready);
+        this._account.imap.ready.disconnect(on_remote_ready);
         this.remote_open_timer.reset();
 
         // Stop any internal tasks from running
@@ -906,7 +906,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
             // Ensure we are open already and guard against someone
             // else having called this just before we did.
             if (this.open_count > 0 &&
-                this._account.session_pool.is_ready &&
+                this._account.imap.is_ready &&
                 this.remote_session == null) {
 
                 this.opening_monitor.notify_start();
@@ -1547,7 +1547,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
                 // occurred, but the folder is still open and so is
                 // the pool, try re-establishing the connection.
                 if (is_error &&
-                    this._account.session_pool.is_ready &&
+                    this._account.imap.is_ready &&
                     !this.open_cancellable.is_cancelled()) {
                     this.open_remote_session.begin();
                 }
diff --git a/src/engine/imap/transport/imap-client-session-manager.vala 
b/src/engine/imap/api/imap-client-service.vala
similarity index 83%
rename from src/engine/imap/transport/imap-client-session-manager.vala
rename to src/engine/imap/api/imap-client-service.vala
index 4546d2c0..62fc66d3 100644
--- a/src/engine/imap/transport/imap-client-session-manager.vala
+++ b/src/engine/imap/api/imap-client-service.vala
@@ -3,23 +3,23 @@
  * Copyright 2017-2018 Michael Gratton <mike vee net>
  *
  * This software is licensed under the GNU Lesser General Public License
- * (version 2.1 or later).  See the COPYING file in this distribution.
+ * (version 2.1 or later). See the COPYING file in this distribution.
  */
 
 /**
  * Manages a pool of IMAP client sessions.
  *
- * When opened and when reachable, the manager will establish a pool
- * of {@link ClientSession} instances that are connected to the IMAP
- * endpoint of an account, ensuring there are at least {@link
- * min_pool_size} available. A connected, authorised client session
- * can be obtained from the connection pool by calling {@link
+ * When started and when the remote host is reachable, the manager
+ * will establish a pool of {@link ClientSession} instances that are
+ * connected to the service's endpoint, ensuring there are at least
+ * {@link min_pool_size} available. A connected, authorised client
+ * session can be obtained from the connection pool by calling {@link
  * claim_authorized_session_async}, and when finished with returned by
  * calling {@link release_session_async}.
  *
  * This class is not thread-safe.
  */
-public class Geary.Imap.ClientSessionManager : BaseObject {
+internal class Geary.Imap.ClientService : Geary.ClientService {
 
 
     private const int DEFAULT_MIN_POOL_SIZE = 1;
@@ -28,10 +28,6 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
     private const int POOL_STOP_TIMEOUT_SEC = 3;
     private const int CHECK_NOOP_THRESHOLD_SEC = 5;
 
-
-    /** Determines if the manager has been opened. */
-    public bool is_open { get; private set; default = false; }
-
     /**
      * Determines if the manager has a working connection.
      *
@@ -98,10 +94,6 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
      */
     public bool discard_returned_sessions = false;
 
-    private string id;
-    private Endpoint endpoint;
-    private Credentials credentials;
-
     private Nonblocking.Mutex sessions_mutex = new Nonblocking.Mutex();
     private Gee.Set<ClientSession> all_sessions =
         new Gee.HashSet<ClientSession>();
@@ -132,16 +124,9 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
     public signal void login_failed(StatusResponse? response);
 
 
-    public ClientSessionManager(string id,
-                                Endpoint imap_endpoint,
-                                Credentials imap_credentials) {
-        this.id = "%s:%s".printf(id, imap_endpoint.to_string());
-
-        this.endpoint = imap_endpoint;
-        this.endpoint.notify[Endpoint.PROP_TRUST_UNTRUSTED_HOST].connect(on_imap_trust_untrusted_host);
-        this.endpoint.untrusted_host.connect(on_imap_untrusted_host);
-
-        this.credentials = imap_credentials;
+    public ClientService(AccountInformation account,
+                         ServiceInformation service) {
+        base(account, service);
 
         this.pool_start = new TimeoutManager.seconds(
             POOL_START_TIMEOUT_SEC,
@@ -154,24 +139,31 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
         );
     }
 
-    ~ClientSessionManager() {
-        if (is_open)
-            warning("[%s] Destroying opened ClientSessionManager", this.id);
-
-        this.endpoint.untrusted_host.disconnect(on_imap_untrusted_host);
-        this.endpoint.notify[Endpoint.PROP_TRUST_UNTRUSTED_HOST].disconnect(on_imap_trust_untrusted_host);
-    }
-
-    public async void open_async(Cancellable? cancellable) throws Error {
-        if (is_open)
-            throw new EngineError.ALREADY_OPEN("ClientSessionManager already open");
+    /**
+     * Starts the manager opening IMAP client sessions.
+     */
+    public override async void start(GLib.Cancellable? cancellable = null)
+        throws GLib.Error {
+        if (this.is_running) {
+            throw new EngineError.ALREADY_OPEN(
+                "IMAP client service already open"
+            );
+        }
 
-        this.is_open = true;
+        this.is_running = true;
         this.authentication_failed = false;
         this.pool_cancellable = new Cancellable();
 
-               this.endpoint.connectivity.notify["is-reachable"].connect(on_connectivity_change);
-        this.endpoint.connectivity.address_error_reported.connect(on_connectivity_error);
+        this.endpoint.notify[Endpoint.PROP_TRUST_UNTRUSTED_HOST].connect(
+            on_imap_trust_untrusted_host
+        );
+        this.endpoint.untrusted_host.connect(on_imap_untrusted_host);
+               this.endpoint.connectivity.notify["is-reachable"].connect(
+            on_connectivity_change
+        );
+        this.endpoint.connectivity.address_error_reported.connect(
+            on_connectivity_error
+        );
         if (this.endpoint.connectivity.is_reachable.is_certain()) {
             this.check_pool.begin();
         } else {
@@ -179,24 +171,38 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
         }
     }
 
-    public async void close_async(Cancellable? cancellable) throws Error {
-        if (!is_open)
+    /**
+     * Stops the manager running, closing any existing sessions.
+     */
+    public override async void stop(GLib.Cancellable? cancellable = null)
+        throws GLib.Error {
+        if (!this.is_running) {
             return;
+        }
 
-        this.is_open = false;
+        this.is_running = false;
         this.pool_cancellable.cancel();
 
-               this.endpoint.connectivity.notify["is-reachable"].disconnect(on_connectivity_change);
-        this.endpoint.connectivity.address_error_reported.disconnect(on_connectivity_error);
+        this.endpoint.notify[Endpoint.PROP_TRUST_UNTRUSTED_HOST].disconnect(
+            on_imap_trust_untrusted_host
+        );
+        this.endpoint.untrusted_host.disconnect(on_imap_untrusted_host);
+               this.endpoint.connectivity.notify["is-reachable"].disconnect(
+            on_connectivity_change
+        );
+        this.endpoint.connectivity.address_error_reported.disconnect(
+            on_connectivity_error
+        );
 
         yield close_pool();
 
-        // TODO: This isn't the best (deterministic) way to deal with this, but it's easy and works
-        // for now
+        // TODO: This isn't the best (deterministic) way to deal with
+        // this, but it's easy and works for now
         int attempts = 0;
         while (this.all_sessions.size > 0) {
-            debug("[%s] Waiting for client sessions to disconnect...", this.id);
-            Timeout.add(250, close_async.callback);
+            debug("[%s] Waiting for client sessions to disconnect...",
+                  this.account.id);
+            Timeout.add(250, this.stop.callback);
             yield;
 
             // give up after three seconds
@@ -205,20 +211,6 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
         }
     }
 
-    /**
-     * Informs the manager that the account's IMAP credentials have changed.
-     *
-     * This will reset the manager's authentication state and if open,
-     * attempt to open a connection to the server.
-     */
-    public void credentials_updated(Credentials new_creds) {
-        this.authentication_failed = false;
-        this.credentials = new_creds;
-        if (this.is_open) {
-            this.check_pool.begin();
-        }
-    }
-
     /**
      * Claims a free session, blocking until one becomes available.
      *
@@ -240,7 +232,7 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
         throws Error {
         check_open();
         debug("[%s] Claiming session with %d of %d free",
-              this.id, this.free_queue.size, this.all_sessions.size);
+              this.account.id, this.free_queue.size, this.all_sessions.size);
 
         if (this.authentication_failed)
             throw new ImapError.UNAUTHENTICATED("Invalid ClientSessionManager credentials");
@@ -276,17 +268,17 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
     public async void release_session_async(ClientSession session)
         throws Error {
         // Don't check_open(), it's valid for this to be called when
-        // is_open is false, that happens during mop-up
+        // is_running is false, that happens during mop-up
 
         debug("[%s] Returning session with %d of %d free",
-              this.id, this.free_queue.size, this.all_sessions.size);
+              this.account.id, this.free_queue.size, this.all_sessions.size);
 
         bool too_many_free = (
             this.free_queue.size >= this.max_free_size &&
             this.all_sessions.size > this.min_pool_size
         );
 
-        if (!this.is_open || this.discard_returned_sessions || too_many_free) {
+        if (!this.is_running || this.discard_returned_sessions || too_many_free) {
             yield force_disconnect(session);
         } else if (yield check_session(session, false)) {
             bool free = true;
@@ -301,7 +293,7 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
                     yield session.close_mailbox_async(pool_cancellable);
                 } catch (ImapError imap_error) {
                     debug("[%s] Error attempting to close released session %s: %s",
-                          this.id, session.to_string(), imap_error.message);
+                          this.account.id, session.to_string(), imap_error.message);
                     free = false;
                 }
 
@@ -314,31 +306,28 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
             }
 
             if (free) {
-                debug("[%s] Unreserving session %s", this.id, session.to_string());
+                debug("[%s] Unreserving session %s",
+                      this.account.id, session.to_string());
                 this.free_queue.send(session);
             }
         }
     }
 
-    /**
-     * Returns a string representation of this object for debugging.
-     */
-    public string to_string() {
-        return this.id;
-    }
-
     private void check_open() throws Error {
-        if (!is_open)
-            throw new EngineError.OPEN_REQUIRED("ClientSessionManager is not open");
+        if (!this.is_running) {
+            throw new EngineError.OPEN_REQUIRED(
+                "IMAP client service is not running"
+            );
+        }
     }
 
     private async void check_pool(bool is_claiming = false) {
         debug("[%s] Checking session pool with %d of %d free",
-              this.id, this.free_queue.size, this.all_sessions.size);
+              this.account.id, this.free_queue.size, this.all_sessions.size);
 
         this.pool_start.reset();
 
-        if (this.is_open &&
+        if (this.is_running &&
             !this.authentication_failed &&
             !this.untrusted_host &&
             this.endpoint.connectivity.is_reachable.is_certain()) {
@@ -367,7 +356,7 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
             this.free_queue.send(free);
         } catch (Error err) {
             debug("[%s] Error adding new session to the pool: %s",
-                  this.id, err.message);
+                  this.account.id, err.message);
             this.close_pool.begin();
         }
     }
@@ -396,7 +385,7 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
                 yield remove_session_async(target);
             } catch (Error err) {
                 debug("[%s] Error removing unconnected session: %s",
-                      this.id, err.message);
+                      this.account.id, err.message);
             }
             break;
 
@@ -434,7 +423,7 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
     }
 
     private async ClientSession create_new_authorized_session(Cancellable? cancellable) throws Error {
-        debug("[%s] Opening new session", this.id);
+        debug("[%s] Opening new session", this.account.id);
         ClientSession new_session = new ClientSession(endpoint);
 
         // Listen for auth failures early so the client is notified if
@@ -452,7 +441,9 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
         }
 
         try {
-            yield new_session.initiate_session_async(this.credentials, cancellable);
+            yield new_session.initiate_session_async(
+                this.service.credentials, cancellable
+            );
         } catch (Error err) {
             if (!(err is IOError.CANCELLED)) {
                 connection_failed(err);
@@ -480,7 +471,7 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
         // We now have a good connection, so signal us as ready if not
         // already done so.
         if (!this.is_ready) {
-            debug("[%s] Became ready", this.id);
+            debug("[%s] Became ready", this.account.id);
             notify_ready(true);
         }
 
@@ -489,7 +480,7 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
 
     private async void close_pool() {
         debug("[%s] Closing the pool, disconnecting %d sessions",
-              this.id, this.all_sessions.size);
+              this.account.id, this.all_sessions.size);
 
         this.pool_start.reset();
         this.pool_stop.reset();
@@ -516,12 +507,13 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
     }
 
     private async void force_disconnect(ClientSession session) {
-        debug("[%s] Dropping session %s", this.id, session.to_string());
+        debug("[%s] Dropping session %s", this.account.id, session.to_string());
 
         try {
             yield remove_session_async(session);
         } catch (Error err) {
-            debug("[%s] Error removing session: %s", this.id, err.message);
+            debug("[%s] Error removing session: %s",
+                  this.account.id, err.message);
         }
 
         // Don't wait for this to finish because we don't want to
@@ -559,7 +551,7 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
                     this.remove_session_async.end(res);
                 } catch (Error err) {
                     debug("[%s] Error removing disconnected session: %s",
-                          this.id, err.message);
+                          this.account.id, err.message);
                 }
             }
         );
@@ -582,8 +574,9 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
         if (untrusted_host && endpoint.trust_untrusted_host == Trillian.TRUE) {
             untrusted_host = false;
 
-            if (is_open)
+            if (this.is_running) {
                 check_pool.begin();
+            }
         }
     }
 
diff --git a/src/engine/meson.build b/src/engine/meson.build
index f327c375..5f991e80 100644
--- a/src/engine/meson.build
+++ b/src/engine/meson.build
@@ -85,6 +85,7 @@ geary_engine_vala_sources = files(
   'imap/imap.vala',
   'imap/imap-error.vala',
   'imap/api/imap-account-session.vala',
+  'imap/api/imap-client-service.vala',
   'imap/api/imap-email-flags.vala',
   'imap/api/imap-email-properties.vala',
   'imap/api/imap-folder.vala',
@@ -164,7 +165,6 @@ geary_engine_vala_sources = files(
   'imap/response/imap-status-data.vala',
   'imap/response/imap-status-response.vala',
   'imap/transport/imap-client-connection.vala',
-  'imap/transport/imap-client-session-manager.vala',
   'imap/transport/imap-client-session.vala',
   'imap/transport/imap-deserializer.vala',
   'imap/transport/imap-serializer.vala',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]