[geary/wip/768975-service-info: 4/4] Port AccountInformation over to ServiceInformation



commit c08ab44a4226ca9864f2dc4287cb82993fe6cbb3
Author: Oskar Viljasaar <oskar viljasaar gmail com>
Date:   Fri Jul 14 17:11:16 2017 +0200

    Port AccountInformation over to ServiceInformation
    
    This adds two ServiceInformation properties for IMAP and SMTP,
    and removes all separate properties in AccountInformation which
    are now redundant. No functional changes for now.

 src/client/accounts/account-dialog.vala            |    4 +-
 src/client/accounts/add-edit-page.vala             |   60 +++---
 src/client/application/geary-controller.vala       |    4 +-
 src/client/application/secret-mediator.vala        |    8 +-
 src/client/dialogs/password-dialog.vala            |   12 +-
 src/engine/api/geary-account-information.vala      |  229 +++++++-------------
 src/engine/api/geary-engine.vala                   |   12 +-
 src/engine/imap-db/imap-db-account.vala            |    2 +-
 src/engine/imap-db/outbox/smtp-outbox-folder.vala  |    6 +-
 .../imap-engine/imap-engine-generic-account.vala   |    2 +-
 src/engine/imap/api/imap-account.vala              |    4 +-
 .../transport/imap-client-session-manager.vala     |    2 +-
 12 files changed, 136 insertions(+), 209 deletions(-)
---
diff --git a/src/client/accounts/account-dialog.vala b/src/client/accounts/account-dialog.vala
index 7a7d965..833d888 100644
--- a/src/client/accounts/account-dialog.vala
+++ b/src/client/accounts/account-dialog.vala
@@ -168,8 +168,8 @@ public class AccountDialog : Gtk.Dialog {
             Geary.AccountInformation? real_info =
                 GearyApplication.instance.controller.get_real_account_information(info);
             if (real_info != null) {
-                validate_connection = !real_info.imap_credentials.equal_to(info.imap_credentials) ||
-                    (info.smtp_credentials != null && 
!real_info.smtp_credentials.equal_to(info.smtp_credentials));
+                validate_connection = !real_info.imap.credentials.equal_to(info.imap.credentials) ||
+                    (info.smtp.credentials != null && 
!real_info.smtp.credentials.equal_to(info.smtp.credentials));
             }
         }
         
diff --git a/src/client/accounts/add-edit-page.vala b/src/client/accounts/add-edit-page.vala
index ce06c93..1d301af 100644
--- a/src/client/accounts/add-edit-page.vala
+++ b/src/client/accounts/add-edit-page.vala
@@ -365,24 +365,24 @@ public class AddEditPage : Gtk.Box {
             info.primary_mailbox.name,
             info.nickname,
             info.primary_mailbox.address,
-            info.imap_credentials.user,
-            info.imap_credentials.pass,
-            info.imap_remember_password && info.smtp_remember_password,
-            info.smtp_credentials != null ? info.smtp_credentials.user : null,
-            info.smtp_credentials != null ? info.smtp_credentials.pass : null,
+            info.imap.credentials.user,
+            info.imap.credentials.pass,
+            info.imap.remember_password && info.smtp.remember_password,
+            info.smtp.credentials != null ? info.smtp.credentials.user : null,
+            info.smtp.credentials != null ? info.smtp.credentials.pass : null,
             info.service_provider,
             info.save_sent_mail,
             info.allow_save_sent_mail(),
-            info.default_imap_server_host,
-            info.default_imap_server_port,
-            info.default_imap_server_ssl,
-            info.default_imap_server_starttls,
-            info.default_smtp_server_host,
-            info.default_smtp_server_port,
-            info.default_smtp_server_ssl,
-            info.default_smtp_server_starttls,
-            info.default_smtp_use_imap_credentials,
-            info.default_smtp_server_noauth,
+            info.imap.host,
+            info.imap.port,
+            info.imap.use_ssl,
+            info.imap.use_starttls,
+            info.smtp.host,
+            info.smtp.port,
+            info.smtp.use_ssl,
+            info.smtp.use_starttls,
+            info.smtp.smtp_use_imap_credentials,
+            info.smtp.smtp_noauth,
             info.prefetch_period_days,
             info.save_drafts,
             info.use_email_signature,
@@ -690,29 +690,29 @@ public class AddEditPage : Gtk.Box {
                 this.real_name.strip(), this.email_address.strip()
             );
             info.nickname = this.nickname.strip();
-            info.imap_credentials = imap_credentials;
-            info.smtp_credentials = smtp_credentials;
-            info.imap_remember_password = this.remember_password;
-            info.smtp_remember_password = this.remember_password;
+            info.imap.credentials = imap_credentials;
+            info.smtp.credentials = smtp_credentials;
+            info.imap.remember_password = this.remember_password;
+            info.smtp.remember_password = this.remember_password;
             info.service_provider = this.get_service_provider();
             info.save_sent_mail = this.save_sent_mail;
-            info.default_imap_server_host = this.imap_host;
-            info.default_imap_server_port = this.imap_port;
-            info.default_imap_server_ssl = this.imap_ssl;
-            info.default_imap_server_starttls = this.imap_starttls;
-            info.default_smtp_server_host = this.smtp_host.strip();
-            info.default_smtp_server_port = this.smtp_port;
-            info.default_smtp_server_ssl = this.smtp_ssl;
-            info.default_smtp_server_starttls = this.smtp_starttls;
-            info.default_smtp_use_imap_credentials = this.smtp_use_imap_credentials;
-            info.default_smtp_server_noauth = this.smtp_noauth;
+            info.imap.host = this.imap_host;
+            info.imap.port = this.imap_port;
+            info.imap.use_ssl = this.imap_ssl;
+            info.imap.use_starttls = this.imap_starttls;
+            info.smtp.host = this.smtp_host.strip();
+            info.smtp.port = this.smtp_port;
+            info.smtp.use_ssl = this.smtp_ssl;
+            info.smtp.use_starttls = this.smtp_starttls;
+            info.smtp.smtp_use_imap_credentials = this.smtp_use_imap_credentials;
+            info.smtp.smtp_noauth = this.smtp_noauth;
             info.prefetch_period_days = get_storage_length();
             info.save_drafts = this.save_drafts;
             info.use_email_signature = this.use_email_signature;
             info.email_signature = this.email_signature;
 
             if (smtp_noauth)
-                info.smtp_credentials = null;
+                info.smtp.credentials = null;
 
             on_changed();
         }
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 72ce93d..b83e3a2 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -988,8 +988,8 @@ public class GearyController : Geary.BaseObject {
             login_dialog.show_spinner(true);
             new_info = login_dialog.get_account_information();
             
-            if ((!new_info.default_imap_server_ssl && !new_info.default_imap_server_starttls)
-                || (!new_info.default_smtp_server_ssl && !new_info.default_smtp_server_starttls)) {
+            if ((!new_info.imap.use_ssl && !new_info.imap.use_starttls)
+                || (!new_info.smtp.use_ssl && !new_info.smtp.use_starttls)) {
                 ConfirmationDialog security_dialog = new ConfirmationDialog(main_window,
                     _("Your settings are insecure"),
                     _("Your IMAP and/or SMTP settings do not specify SSL or TLS.  This means your username 
and password could be read by another person on the network.  Are you sure you want to do this?"),
diff --git a/src/client/application/secret-mediator.vala b/src/client/application/secret-mediator.vala
index f9bbc34..e96a1bb 100644
--- a/src/client/application/secret-mediator.vala
+++ b/src/client/application/secret-mediator.vala
@@ -155,12 +155,12 @@ public class SecretMediator : Geary.CredentialsMediator, Object {
         string host = "";
         switch (service) {
         case Geary.Service.IMAP:
-            login = account.imap_credentials.user;
+            login = account.imap.credentials.user;
             host = account.get_imap_endpoint().remote_address.get_hostname();
             break;
 
         case Geary.Service.SMTP:
-            login = account.smtp_credentials.user;
+            login = account.smtp.credentials.user;
             host = account.get_smtp_endpoint().remote_address.get_hostname();
             break;
 
@@ -179,10 +179,10 @@ public class SecretMediator : Geary.CredentialsMediator, Object {
     private Geary.Credentials get_credentials(Geary.Service service, Geary.AccountInformation account) {
         switch (service) {
         case Geary.Service.IMAP:
-            return account.imap_credentials;
+            return account.imap.credentials;
 
         case Geary.Service.SMTP:
-            return account.smtp_credentials;
+            return account.smtp.credentials;
 
         default:
             assert_not_reached();
diff --git a/src/client/dialogs/password-dialog.vala b/src/client/dialogs/password-dialog.vala
index bed58ce..811426c 100644
--- a/src/client/dialogs/password-dialog.vala
+++ b/src/client/dialogs/password-dialog.vala
@@ -43,14 +43,14 @@ public class PasswordDialog {
         primary_text_label.set_markup(PRIMARY_TEXT_MARKUP.printf(PRIMARY_TEXT_FIRST_TRY));
 
         if (smtp) {
-            label_username.set_text(account_information.smtp_credentials.user ?? "");
-            entry_password.set_text(account_information.smtp_credentials.pass ?? "");
+            label_username.set_text(account_information.smtp.credentials.user ?? "");
+            entry_password.set_text(account_information.smtp.credentials.pass ?? "");
         } else {
-            label_username.set_text(account_information.imap_credentials.user ?? "");
-            entry_password.set_text(account_information.imap_credentials.pass ?? "");
+            label_username.set_text(account_information.imap.credentials.user ?? "");
+            entry_password.set_text(account_information.imap.credentials.pass ?? "");
         }
-        check_remember_password.active = (smtp ? account_information.smtp_remember_password
-            : account_information.imap_remember_password);
+        check_remember_password.active = (smtp ? account_information.smtp.remember_password
+            : account_information.imap.remember_password);
         if (smtp)
             label_smtp.show();
         
diff --git a/src/engine/api/geary-account-information.vala b/src/engine/api/geary-account-information.vala
index ae7a873..ccee59d 100644
--- a/src/engine/api/geary-account-information.vala
+++ b/src/engine/api/geary-account-information.vala
@@ -116,29 +116,14 @@ public class Geary.AccountInformation : BaseObject {
         get; set; default = AccountInformation.default_ordinal++;
     }
 
+    /* Information related to the account's server-side authentication
+     * and configuration. */
+    public ServiceInformation imap { get; private set; }
+    public ServiceInformation smtp { get; private set; }
+
     // These properties are only used if the service provider's
     // account type does not override them.
 
-    public string default_imap_server_host {
-        get; set; default = "";
-    }
-    public uint16 default_imap_server_port {
-        get; set; default = Imap.ClientConnection.DEFAULT_PORT_SSL;
-    }
-    public bool default_imap_server_ssl { get; set; default = true; }
-    public bool default_imap_server_starttls { get; set; default = false; }
-
-    public string default_smtp_server_host {
-        get; set; default = "";
-    }
-    public uint16 default_smtp_server_port {
-        get; set; default = Geary.Smtp.ClientConnection.DEFAULT_PORT_SSL;
-    }
-    public bool default_smtp_server_ssl { get; set; default = true; }
-    public bool default_smtp_server_starttls { get; set; default = false; }
-    public bool default_smtp_use_imap_credentials { get; set; default = false; }
-    public bool default_smtp_server_noauth { get; set; default = false; }
-
     public bool use_email_signature { get; set; default = false; }
     public string email_signature { get; set; default = ""; }
 
@@ -148,11 +133,6 @@ public class Geary.AccountInformation : BaseObject {
     public Geary.FolderPath? trash_folder_path { get; set; default = null; }
     public Geary.FolderPath? archive_folder_path { get; set; default = null; }
 
-    public Geary.Credentials imap_credentials { get; set; default = new Geary.Credentials(null, null); }
-    public bool imap_remember_password { get; set; default = true; }
-    public Geary.Credentials? smtp_credentials { get; set; default = new Geary.Credentials(null, null); }
-    public bool smtp_remember_password { get; set; default = true; }
-    
     public bool save_drafts { get; set; default = true; }
 
     private bool _save_sent_mail = true;
@@ -179,11 +159,16 @@ public class Geary.AccountInformation : BaseObject {
     /**
      * Creates a new, empty account info file.
      */
-    public AccountInformation(string id, File config_directory, File data_directory) {
+    public AccountInformation(string id,
+                              File config_directory,
+                              File data_directory,
+                              Geary.ServiceInformation? imap, Geary.ServiceInformation? smtp) {
         this.id = id;
         this.config_dir = config_directory;
         this.data_dir = data_directory;
         this.file = config_dir.get_child(SETTINGS_FILENAME);
+        this.imap = imap;
+        this.smtp = smtp;
     }
 
     /**
@@ -194,9 +179,11 @@ public class Geary.AccountInformation : BaseObject {
      */
     internal AccountInformation.from_file(string id,
                                           File config_directory,
-                                          File data_directory)
+                                          File data_directory,
+                                          Geary.ServiceInformation? imap,
+                                          Geary.ServiceInformation? smtp)
         throws Error {
-        this(id, config_directory, data_directory);
+        this(id, config_directory, data_directory, imap, smtp);
 
         KeyFile key_file = new KeyFile();
         key_file.load_from_file(file.get_path() ?? "", KeyFileFlags.NONE);
@@ -218,14 +205,9 @@ public class Geary.AccountInformation : BaseObject {
             }
         }
 
-        this.imap_credentials.user = Config.get_string_value(
-            key_file, Config.GROUP, Config.IMAP_USERNAME_KEY, primary_email);
-        this.imap_remember_password = Config.get_bool_value(
-            key_file, Config.GROUP, Config.IMAP_REMEMBER_PASSWORD_KEY, this.imap_remember_password);
-        this.smtp_credentials.user = Config.get_string_value(
-            key_file, Config.GROUP, Config.SMTP_USERNAME_KEY, primary_email);
-        this.smtp_remember_password = Config.get_bool_value(
-            key_file, Config.GROUP, Config.SMTP_REMEMBER_PASSWORD_KEY, this.smtp_remember_password);
+        this.imap.load_credentials(key_file);
+        this.smtp.load_credentials(key_file);
+
         this.service_provider = Geary.ServiceProvider.from_string(
             Config.get_string_value(
                 key_file, Config.GROUP, Config.SERVICE_PROVIDER_KEY, 
Geary.ServiceProvider.GMAIL.to_string()));
@@ -244,33 +226,12 @@ public class Geary.AccountInformation : BaseObject {
             AccountInformation.default_ordinal = this.ordinal + 1;
 
         if (service_provider == ServiceProvider.OTHER) {
-            this.default_imap_server_host = Config.get_string_value(
-                key_file, Config.GROUP, Config.IMAP_HOST, this.default_imap_server_host);
-            this.default_imap_server_port = Config.get_uint16_value(
-                key_file, Config.GROUP, Config.IMAP_PORT, this.default_imap_server_port);
-            this.default_imap_server_ssl = Config.get_bool_value(
-                key_file, Config.GROUP, Config.IMAP_SSL, this.default_imap_server_ssl);
-            this.default_imap_server_starttls = Config.get_bool_value(
-                key_file, Config.GROUP, Config.IMAP_STARTTLS, this.default_imap_server_starttls);
-
-            this.default_smtp_server_host = Config.get_string_value(
-                key_file, Config.GROUP, Config.SMTP_HOST, this.default_smtp_server_host);
-            this.default_smtp_server_port = Config.get_uint16_value(
-                key_file, Config.GROUP, Config.SMTP_PORT, this.default_smtp_server_port);
-            this.default_smtp_server_ssl = Config.get_bool_value(
-                key_file, Config.GROUP, Config.SMTP_SSL, this.default_smtp_server_ssl);
-            this.default_smtp_server_starttls = Config.get_bool_value(
-                key_file, Config.GROUP, Config.SMTP_STARTTLS, this.default_smtp_server_starttls);
-            this.default_smtp_use_imap_credentials = Config.get_bool_value(
-                key_file, Config.GROUP, Config.SMTP_USE_IMAP_CREDENTIALS, 
this.default_smtp_use_imap_credentials);
-            this.default_smtp_server_noauth = Config.get_bool_value(
-                key_file, Config.GROUP, Config.SMTP_NOAUTH, this.default_smtp_server_noauth);
-
-            if (default_smtp_server_noauth) {
-                this.smtp_credentials = null;
-            } else if (default_smtp_use_imap_credentials) {
-                this.smtp_credentials.user = imap_credentials.user;
-                this.smtp_credentials.pass = imap_credentials.pass;
+            this.imap.load_settings(key_file);
+            this.smtp.load_settings(key_file);
+
+            if (this.smtp.smtp_use_imap_credentials) {
+                this.smtp.credentials.user = this.imap.credentials.user;
+                this.smtp.credentials.pass = this.imap.credentials.pass;
             }
         }
 
@@ -327,20 +288,8 @@ public class Geary.AccountInformation : BaseObject {
         this.prefetch_period_days = from.prefetch_period_days;
         this.save_sent_mail = from.save_sent_mail;
         this.ordinal = from.ordinal;
-        this.default_imap_server_host = from.default_imap_server_host;
-        this.default_imap_server_port = from.default_imap_server_port;
-        this.default_imap_server_ssl = from.default_imap_server_ssl;
-        this.default_imap_server_starttls = from.default_imap_server_starttls;
-        this.default_smtp_server_host = from.default_smtp_server_host;
-        this.default_smtp_server_port = from.default_smtp_server_port;
-        this.default_smtp_server_ssl = from.default_smtp_server_ssl;
-        this.default_smtp_server_starttls = from.default_smtp_server_starttls;
-        this.default_smtp_use_imap_credentials = from.default_smtp_use_imap_credentials;
-        this.default_smtp_server_noauth = from.default_smtp_server_noauth;
-        this.imap_credentials = from.imap_credentials;
-        this.imap_remember_password = from.imap_remember_password;
-        this.smtp_credentials = from.smtp_credentials;
-        this.smtp_remember_password = from.smtp_remember_password;
+        this.imap.copy_from(from.imap);
+        this.smtp.copy_from(from.smtp);
         this.drafts_folder_path = from.drafts_folder_path;
         this.sent_mail_folder_path = from.sent_mail_folder_path;
         this.spam_folder_path = from.spam_folder_path;
@@ -481,27 +430,27 @@ public class Geary.AccountInformation : BaseObject {
         if (force_request) {
             // Delete the current password(s).
             if (services.has_imap()) {
-                yield Geary.Engine.instance.authentication_mediator.clear_password_async(
+                yield this.imap.mediator.clear_password_async(
                     Service.IMAP, this);
 
-                if (imap_credentials != null)
-                    imap_credentials.pass = null;
+                if (this.imap.credentials != null)
+                    this.imap.credentials.pass = null;
             } else if (services.has_smtp()) {
-                yield Geary.Engine.instance.authentication_mediator.clear_password_async(
+                yield this.smtp.mediator.clear_password_async(
                     Service.SMTP, this);
 
-                if (smtp_credentials != null)
-                    smtp_credentials.pass = null;
+                if (this.smtp.credentials != null)
+                    this.smtp.credentials.pass = null;
             }
         }
         
         // Only call get_passwords on anything that hasn't been set
         // (incorrectly) previously.
         ServiceFlag get_services = 0;
-        if (services.has_imap() && !imap_credentials.is_complete())
+        if (services.has_imap() && !this.imap.credentials.is_complete())
             get_services |= ServiceFlag.IMAP;
         
-        if (services.has_smtp() && smtp_credentials != null && !smtp_credentials.is_complete())
+        if (services.has_smtp() && this.smtp.credentials != null && !this.smtp.credentials.is_complete())
             get_services |= ServiceFlag.SMTP;
 
         ServiceFlag unset_services = services;
@@ -517,20 +466,9 @@ public class Geary.AccountInformation : BaseObject {
     }
 
     private void check_mediator_instance() throws EngineError {
-        if (Geary.Engine.instance.authentication_mediator == null)
+        if (this.imap.mediator == null || this.smtp.mediator == null)
             throw new EngineError.OPEN_REQUIRED(
-                "Geary.Engine instance needs to be open with a valid Geary.CredentialsMediator");
-    }
-    
-    private void set_imap_password(string imap_password) {
-        // Don't just update the pass field, because we need imap_credentials
-        // itself to change so callers can bind to its changed signal.
-        imap_credentials = new Credentials(imap_credentials.user, imap_password);
-    }
-    
-    private void set_smtp_password(string smtp_password) {
-        // See above.  Same argument.
-        smtp_credentials = new Credentials(smtp_credentials.user, smtp_password);
+                "Account %s needs to be open with valid Geary.CredentialsMediators".printf(this.id));
     }
 
     /**
@@ -544,23 +482,22 @@ public class Geary.AccountInformation : BaseObject {
     public async ServiceFlag get_passwords_async(ServiceFlag services) throws Error {
         check_mediator_instance();
 
-        CredentialsMediator mediator = Geary.Engine.instance.authentication_mediator;
         ServiceFlag failed_services = 0;
 
         if (services.has_imap()) {
-            string? imap_password = yield mediator.get_password_async(Service.IMAP, this);
+            string? imap_password = yield this.imap.mediator.get_password_async(Service.IMAP, this);
 
             if (imap_password != null)
-                set_imap_password(imap_password);
+                this.imap.set_password(imap_password, this.imap.remember_password);
              else
                 failed_services |= ServiceFlag.IMAP;
         }
         
-        if (services.has_smtp() && smtp_credentials != null) {
-            string? smtp_password = yield mediator.get_password_async(Service.SMTP, this);
+        if (services.has_smtp() && this.smtp.credentials != null) {
+            string? smtp_password = yield this.smtp.mediator.get_password_async(Service.SMTP, this);
 
             if (smtp_password != null)
-                set_smtp_password(smtp_password);
+                this.smtp.set_password(smtp_password, this.smtp.remember_password);
             else
                 failed_services |= ServiceFlag.SMTP;
         }
@@ -582,22 +519,24 @@ public class Geary.AccountInformation : BaseObject {
         string? imap_password, smtp_password;
         bool imap_remember_password, smtp_remember_password;
 
-        if (smtp_credentials == null)
+        /* This is a workaround. Assume IMAP and SMTP use the same mediator so
+         * as to minimize code refactoring for now.
+         */
+
+        if (this.smtp.credentials == null)
             services &= ~ServiceFlag.SMTP;
 
-        if (!yield Geary.Engine.instance.authentication_mediator.prompt_passwords_async(
+        if (!yield this.imap.mediator.prompt_passwords_async(
             services, this, out imap_password, out smtp_password,
             out imap_remember_password, out smtp_remember_password))
             return false;
 
         if (services.has_imap()) {
-            set_imap_password(imap_password);
-            this.imap_remember_password = imap_remember_password;
+            imap.set_password(imap_password, imap_remember_password);
         }
 
         if (services.has_smtp()) {
-            set_smtp_password(smtp_password);
-            this.smtp_remember_password = smtp_remember_password;
+            smtp.set_password(smtp_password, smtp_remember_password);
         }
 
         yield update_stored_passwords_async(services);
@@ -612,20 +551,19 @@ public class Geary.AccountInformation : BaseObject {
     public async void update_stored_passwords_async(ServiceFlag services) throws Error {
         check_mediator_instance();
 
-        CredentialsMediator mediator = Geary.Engine.instance.authentication_mediator;
 
         if (services.has_imap()) {
-            if (imap_remember_password)
-                yield mediator.set_password_async(Service.IMAP, this);
+            if (this.imap.remember_password)
+                yield this.imap.mediator.set_password_async(Service.IMAP, this);
             else
-                yield mediator.clear_password_async(Service.IMAP, this);
+                yield this.imap.mediator.clear_password_async(Service.IMAP, this);
         }
 
-        if (services.has_smtp() && smtp_credentials != null) {
-            if (smtp_remember_password)
-                yield mediator.set_password_async(Service.SMTP, this);
+        if (services.has_smtp() && this.smtp.credentials != null) {
+            if (this.smtp.remember_password)
+                yield this.smtp.mediator.set_password_async(Service.SMTP, this);
             else
-                yield mediator.clear_password_async(Service.SMTP, this);
+                yield this.smtp.mediator.clear_password_async(Service.SMTP, this);
         }
     }
 
@@ -655,12 +593,12 @@ public class Geary.AccountInformation : BaseObject {
 
             case ServiceProvider.OTHER:
                 Endpoint.Flags imap_flags = Endpoint.Flags.NONE;
-                if (default_imap_server_ssl)
+                if (this.imap.use_ssl)
                     imap_flags |= Endpoint.Flags.SSL;
-                if (default_imap_server_starttls)
+                if (this.imap.use_starttls)
                     imap_flags |= Endpoint.Flags.STARTTLS;
 
-                imap_endpoint = new Endpoint(default_imap_server_host, default_imap_server_port,
+                imap_endpoint = new Endpoint(this.imap.host, this.imap.port,
                     imap_flags, Imap.ClientConnection.RECOMMENDED_TIMEOUT_SEC);
             break;
             
@@ -709,12 +647,12 @@ public class Geary.AccountInformation : BaseObject {
 
             case ServiceProvider.OTHER:
                 Endpoint.Flags smtp_flags = Endpoint.Flags.NONE;
-                if (default_smtp_server_ssl)
+                if (this.smtp.use_ssl)
                     smtp_flags |= Endpoint.Flags.SSL;
-                if (default_smtp_server_starttls)
+                if (this.smtp.use_starttls)
                     smtp_flags |= Endpoint.Flags.STARTTLS;
 
-                smtp_endpoint = new Endpoint(default_smtp_server_host, default_smtp_server_port,
+                smtp_endpoint = new Endpoint(this.smtp.host, this.smtp.port,
                     smtp_flags, Smtp.ClientConnection.DEFAULT_TIMEOUT_SEC);
             break;
 
@@ -794,20 +732,15 @@ public class Geary.AccountInformation : BaseObject {
 
         KeyFile key_file = new KeyFile();
 
-        key_file.set_value(Config.GROUP, Config.REAL_NAME_KEY, this.primary_mailbox.name);
-        key_file.set_value(Config.GROUP, Config.PRIMARY_EMAIL_KEY, this.primary_mailbox.address);
-        key_file.set_value(Config.GROUP, Config.NICKNAME_KEY, this.nickname);
-        key_file.set_value(Config.GROUP, Config.SERVICE_PROVIDER_KEY, this.service_provider.to_string());
-        key_file.set_integer(Config.GROUP, Config.ORDINAL_KEY, this.ordinal);
-        key_file.set_value(Config.GROUP, Config.IMAP_USERNAME_KEY, this.imap_credentials.user);
-        key_file.set_boolean(Config.GROUP, Config.IMAP_REMEMBER_PASSWORD_KEY, this.imap_remember_password);
-        if (smtp_credentials != null)
-            key_file.set_value(Config.GROUP, Config.SMTP_USERNAME_KEY, this.smtp_credentials.user);
-        key_file.set_boolean(Config.GROUP, Config.SMTP_REMEMBER_PASSWORD_KEY, this.smtp_remember_password);
-        key_file.set_integer(Config.GROUP, Config.PREFETCH_PERIOD_DAYS_KEY, this.prefetch_period_days);
-        key_file.set_boolean(Config.GROUP, Config.SAVE_SENT_MAIL_KEY, this.save_sent_mail);
-        key_file.set_boolean(Config.GROUP, Config.USE_EMAIL_SIGNATURE_KEY, this.use_email_signature);
-        key_file.set_string(Config.GROUP, Config.EMAIL_SIGNATURE_KEY, this.email_signature);
+        key_file.set_value(Geary.Config.GROUP, Geary.Config.REAL_NAME_KEY, this.primary_mailbox.name);
+        key_file.set_value(Geary.Config.GROUP, Geary.Config.PRIMARY_EMAIL_KEY, this.primary_mailbox.address);
+        key_file.set_value(Geary.Config.GROUP, Geary.Config.NICKNAME_KEY, this.nickname);
+        key_file.set_value(Geary.Config.GROUP, Geary.Config.SERVICE_PROVIDER_KEY, 
this.service_provider.to_string());
+        key_file.set_integer(Geary.Config.GROUP, Geary.Config.ORDINAL_KEY, this.ordinal);
+        key_file.set_integer(Geary.Config.GROUP, Geary.Config.PREFETCH_PERIOD_DAYS_KEY, 
this.prefetch_period_days);
+        key_file.set_boolean(Geary.Config.GROUP, Geary.Config.SAVE_SENT_MAIL_KEY, this.save_sent_mail);
+        key_file.set_boolean(Geary.Config.GROUP, Geary.Config.USE_EMAIL_SIGNATURE_KEY, 
this.use_email_signature);
+        key_file.set_string(Geary.Config.GROUP, Geary.Config.EMAIL_SIGNATURE_KEY, this.email_signature);
         if (alternate_mailboxes != null && this.alternate_mailboxes.size > 0) {
             string[] list = new string[this.alternate_mailboxes.size];
             for (int ctr = 0; ctr < this.alternate_mailboxes.size; ctr++)
@@ -817,17 +750,8 @@ public class Geary.AccountInformation : BaseObject {
         }
 
         if (service_provider == ServiceProvider.OTHER) {
-            key_file.set_value(Config.GROUP, Config.IMAP_HOST, this.default_imap_server_host);
-            key_file.set_integer(Config.GROUP, Config.IMAP_PORT, this.default_imap_server_port);
-            key_file.set_boolean(Config.GROUP, Config.IMAP_SSL, this.default_imap_server_ssl);
-            key_file.set_boolean(Config.GROUP, Config.IMAP_STARTTLS, this.default_imap_server_starttls);
-
-            key_file.set_value(Config.GROUP, Config.SMTP_HOST, this.default_smtp_server_host);
-            key_file.set_integer(Config.GROUP, Config.SMTP_PORT, this.default_smtp_server_port);
-            key_file.set_boolean(Config.GROUP, Config.SMTP_SSL, this.default_smtp_server_ssl);
-            key_file.set_boolean(Config.GROUP, Config.SMTP_STARTTLS, this.default_smtp_server_starttls);
-            key_file.set_boolean(Config.GROUP, Config.SMTP_USE_IMAP_CREDENTIALS, 
this.default_smtp_use_imap_credentials);
-            key_file.set_boolean(Config.GROUP, Config.SMTP_NOAUTH, this.default_smtp_server_noauth);
+            this.imap.save_settings(key_file);
+            this.smtp.save_settings(key_file);
         }
 
         key_file.set_string_list(Config.GROUP, Config.DRAFTS_FOLDER_KEY, (this.drafts_folder_path != null
@@ -859,18 +783,17 @@ public class Geary.AccountInformation : BaseObject {
     public async void clear_stored_passwords_async(ServiceFlag services) throws Error {
         Error? return_error = null;
         check_mediator_instance();
-        CredentialsMediator mediator = Geary.Engine.instance.authentication_mediator;
 
         try {
             if (services.has_imap())
-                yield mediator.clear_password_async(Service.IMAP, this);
+                yield this.imap.mediator.clear_password_async(Service.IMAP, this);
         } catch (Error e) {
             return_error = e;
         }
 
         try {
-            if (services.has_smtp() && smtp_credentials != null)
-                yield mediator.clear_password_async(Service.SMTP, this);
+            if (services.has_smtp() && this.smtp.credentials != null)
+                yield this.smtp.mediator.clear_password_async(Service.SMTP, this);
         } catch (Error e) {
             return_error = e;
         }
diff --git a/src/engine/api/geary-engine.vala b/src/engine/api/geary-engine.vala
index d25feff..c56e8fc 100644
--- a/src/engine/api/geary-engine.vala
+++ b/src/engine/api/geary-engine.vala
@@ -198,7 +198,9 @@ public class Geary.Engine : BaseObject {
                         new AccountInformation.from_file(
                             id,
                             user_config_dir.get_child(id),
-                            user_data_dir.get_child(id)
+                            user_data_dir.get_child(id),
+                            new Geary.LocalServiceInformation(Service.IMAP, user_config_dir.get_child(id), 
this.authentication_mediator),
+                            new Geary.LocalServiceInformation(Service.SMTP, user_config_dir.get_child(id), 
this.authentication_mediator)
                         )
                     );
                 } catch (Error err) {
@@ -294,7 +296,9 @@ public class Geary.Engine : BaseObject {
             throw new EngineError.ALREADY_EXISTS("Account %s already exists", id);
 
         return new AccountInformation(
-            id, user_config_dir.get_child(id), user_data_dir.get_child(id)
+            id, user_config_dir.get_child(id), user_data_dir.get_child(id),
+                new LocalServiceInformation(Service.IMAP, user_config_dir.get_child(id), 
this.authentication_mediator),
+                new LocalServiceInformation(Service.SMTP, user_config_dir.get_child(id), 
this.authentication_mediator)
         );
     }
 
@@ -339,7 +343,7 @@ public class Geary.Engine : BaseObject {
         
         if (!error_code.is_all_set(ValidationResult.IMAP_CONNECTION_FAILED)) {
             try {
-                yield imap_session.initiate_session_async(account.imap_credentials, cancellable);
+                yield imap_session.initiate_session_async(account.imap.credentials, cancellable);
                 
                 // Connected and initiated, still need to be sure connection authorized
                 Imap.MailboxSpecifier current_mailbox;
@@ -365,7 +369,7 @@ public class Geary.Engine : BaseObject {
         // SMTP is simpler, merely see if login works and done (throws an SmtpError if not)
         Geary.Smtp.ClientSession? smtp_session = new Geary.Smtp.ClientSession(account.get_smtp_endpoint());
         try {
-            yield smtp_session.login_async(account.smtp_credentials, cancellable);
+            yield smtp_session.login_async(account.smtp.credentials, cancellable);
         } catch (Error err) {
             debug("Error validating SMTP account info: %s", err.message);
             if (err is SmtpError.AUTHENTICATION_FAILED)
diff --git a/src/engine/imap-db/imap-db-account.vala b/src/engine/imap-db/imap-db-account.vala
index 86ce37c..b8d6ed2 100644
--- a/src/engine/imap-db/imap-db-account.vala
+++ b/src/engine/imap-db/imap-db-account.vala
@@ -233,7 +233,7 @@ private class Geary.ImapDB.Account : BaseObject {
         this.account_information = account_information;
         contact_store = new ImapEngine.ContactStore(this);
         
-        name = "IMAP database account for %s".printf(account_information.imap_credentials.user);
+        name = "IMAP database account for %s".printf(account_information.imap.credentials.user);
     }
     
     private void check_open() throws Error {
diff --git a/src/engine/imap-db/outbox/smtp-outbox-folder.vala 
b/src/engine/imap-db/outbox/smtp-outbox-folder.vala
index 7c38aac..e06671b 100644
--- a/src/engine/imap-db/outbox/smtp-outbox-folder.vala
+++ b/src/engine/imap-db/outbox/smtp-outbox-folder.vala
@@ -194,8 +194,8 @@ private class Geary.SmtpOutboxFolder : Geary.AbstractLocalFolder, Geary.FolderSu
             // Get SMTP password if we haven't loaded it yet and the account needs credentials.
             // If the account needs a password but it's not set or incorrect in the keyring, we'll
             // prompt below after getting an AUTHENTICATION_FAILED error.
-            if (_account.information.smtp_credentials != null &&
-                !_account.information.smtp_credentials.is_complete()) {
+            if (_account.information.smtp.credentials != null &&
+                !_account.information.smtp.credentials.is_complete()) {
                 try {
                     yield _account.information.get_passwords_async(ServiceFlag.SMTP);
                 } catch (Error e) {
@@ -626,7 +626,7 @@ private class Geary.SmtpOutboxFolder : Geary.AbstractLocalFolder, Geary.FolderSu
         
         Error? smtp_err = null;
         try {
-            yield smtp.login_async(_account.information.smtp_credentials, cancellable);
+            yield smtp.login_async(_account.information.smtp.credentials, cancellable);
         } catch (Error login_err) {
             debug("SMTP login error: %s", login_err.message);
             smtp_err = login_err;
diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala 
b/src/engine/imap-engine/imap-engine-generic-account.vala
index 5625c26..be2ccda 100644
--- a/src/engine/imap-engine/imap-engine-generic-account.vala
+++ b/src/engine/imap-engine/imap-engine-generic-account.vala
@@ -157,7 +157,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
         // To prevent spurious connection failures, we make sure we have the
         // IMAP password before attempting a connection.  This might have to be
         // reworked when we allow passwordless logins.
-        if (!information.imap_credentials.is_complete())
+        if (!information.imap.credentials.is_complete())
             yield information.fetch_passwords_async(ServiceFlag.IMAP);
         
         // need to back out local.open_async() if remote fails
diff --git a/src/engine/imap/api/imap-account.vala b/src/engine/imap/api/imap-account.vala
index 6f44c23..4647b0b 100644
--- a/src/engine/imap/api/imap-account.vala
+++ b/src/engine/imap/api/imap-account.vala
@@ -40,7 +40,7 @@ private class Geary.Imap.Account : BaseObject {
     public signal void login_failed(Geary.Credentials? cred, StatusResponse? response);
     
     public Account(Geary.AccountInformation account_information) {
-        name = "IMAP Account for %s".printf(account_information.imap_credentials.to_string());
+        name = "IMAP Account for %s".printf(account_information.imap.credentials.to_string());
         this.account_information = account_information;
         this.session_mgr = new ClientSessionManager(account_information);
         
@@ -604,7 +604,7 @@ private class Geary.Imap.Account : BaseObject {
     }
     
     private void on_login_failed(StatusResponse? response) {
-        login_failed(account_information.imap_credentials, response);
+        login_failed(account_information.imap.credentials, response);
     }
     
     public string to_string() {
diff --git a/src/engine/imap/transport/imap-client-session-manager.vala 
b/src/engine/imap/transport/imap-client-session-manager.vala
index 6bba536..3722dbe 100644
--- a/src/engine/imap/transport/imap-client-session-manager.vala
+++ b/src/engine/imap/transport/imap-client-session-manager.vala
@@ -242,7 +242,7 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
         }
         
         try {
-            yield new_session.initiate_session_async(account_information.imap_credentials, cancellable);
+            yield new_session.initiate_session_async(account_information.imap.credentials, cancellable);
         } catch (Error err) {
             debug("[%s] Initiate session failure: %s", new_session.to_string(), err.message);
             



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