[geary/wip/714104-refine-account-dialog: 13/15] Add ServiceInfo conveience properties for TLS and SMTP auth



commit e7d97b94b08df58a8539bda4cc2612d1570e2ca2
Author: Michael Gratton <mike vee net>
Date:   Sat Oct 20 10:40:28 2018 +1100

    Add ServiceInfo conveience properties for TLS and SMTP auth
    
    Since both transport security and STP auth prefs are currently denoted
    by two properties each, add covenience properties of type
    TlsNegotiationMethod and SmtpCredentials that define a standard
    interepretaion of both.
    
    Use these to tidy up Accounts.EditorAddPane a bit.

 src/client/accounts/accounts-editor-add-pane.vala | 10 +---
 src/engine/api/geary-service-information.vala     | 62 ++++++++++++++++++++++-
 2 files changed, 63 insertions(+), 9 deletions(-)
---
diff --git a/src/client/accounts/accounts-editor-add-pane.vala 
b/src/client/accounts/accounts-editor-add-pane.vala
index 6e130945..7d208b75 100644
--- a/src/client/accounts/accounts-editor-add-pane.vala
+++ b/src/client/accounts/accounts-editor-add-pane.vala
@@ -291,10 +291,7 @@ internal class Accounts.EditorAddPane : Gtk.Grid, EditorPane {
             GLib.NetworkAddress address = host.validated_address;
             service.host = address.hostname;
             service.port = (uint16) address.port;
-
-            Geary.TlsNegotiationMethod tls = this.imap_tls.value.method;
-            service.use_ssl = (tls == Geary.TlsNegotiationMethod.TRANSPORT);
-            service.use_starttls = (tls == Geary.TlsNegotiationMethod.START_TLS);
+            service.transport_security = this.imap_tls.value.method;
         } else {
             this.provider.setup_service(service);
             service.credentials = new Geary.Credentials(
@@ -341,10 +338,7 @@ internal class Accounts.EditorAddPane : Gtk.Grid, EditorPane {
 
             service.host = address.hostname;
             service.port = (uint16) address.port;
-
-            Geary.TlsNegotiationMethod tls = this.smtp_tls.value.method;
-            service.use_ssl = (tls == Geary.TlsNegotiationMethod.TRANSPORT);
-            service.use_starttls = (tls == Geary.TlsNegotiationMethod.START_TLS);
+            service.transport_security = this.smtp_tls.value.method;
 
             debug("SMTP service: TLS: %s, STARTTLS: %s",
                   service.use_ssl.to_string(), service.use_starttls.to_string());
diff --git a/src/engine/api/geary-service-information.vala b/src/engine/api/geary-service-information.vala
index e82cfbab..1c2315fa 100644
--- a/src/engine/api/geary-service-information.vala
+++ b/src/engine/api/geary-service-information.vala
@@ -60,7 +60,7 @@ public enum Geary.TlsNegotiationMethod {
 }
 
 
-/** The credentials used to negotiate SMTP authentication, if any. */
+/** The credential source used to negotiate SMTP authentication, if any. */
 public enum Geary.SmtpCredentials {
     /** No SMTP credentials are required. */
     NONE,
@@ -103,6 +103,35 @@ public abstract class Geary.ServiceInformation : GLib.Object {
     /** The server's port. */
     public uint16 port { get; set; }
 
+    /** The transport security method to use */
+    public TlsNegotiationMethod transport_security {
+        get {
+            if (this.use_ssl) {
+                return TlsNegotiationMethod.TRANSPORT;
+            } else if (this.use_starttls) {
+                return TlsNegotiationMethod.START_TLS;
+            } else {
+                return TlsNegotiationMethod.NONE;
+            }
+        }
+        set {
+            switch (value) {
+            case TlsNegotiationMethod.NONE:
+                this.use_starttls = false;
+                this.use_ssl = false;
+                break;
+            case TlsNegotiationMethod.START_TLS:
+                this.use_starttls = true;
+                this.use_ssl = false;
+                break;
+            case TlsNegotiationMethod.TRANSPORT:
+                this.use_starttls = false;
+                this.use_ssl = true;
+                break;
+            }
+        }
+    }
+
     /** Whether STARTTLS is used when connecting to the server. */
     public bool use_starttls { get; set; default = false; }
 
@@ -128,6 +157,37 @@ public abstract class Geary.ServiceInformation : GLib.Object {
      */
     public bool remember_password { get; set; default = true; }
 
+    /**
+     * Determines the source of auth credentials for SMTP services.
+     */
+    public SmtpCredentials smtp_credentials_source {
+        get {
+            if (this.smtp_use_imap_credentials) {
+                return SmtpCredentials.IMAP;
+            } else if (this.smtp_noauth) {
+                return SmtpCredentials.NONE;
+            } else {
+                return SmtpCredentials.CUSTOM;
+            }
+        }
+        set {
+            switch (value) {
+            case SmtpCredentials.NONE:
+                this.smtp_use_imap_credentials = false;
+                this.smtp_noauth = false;
+                break;
+            case SmtpCredentials.IMAP:
+                this.smtp_use_imap_credentials = true;
+                this.smtp_noauth = false;
+                break;
+            case SmtpCredentials.CUSTOM:
+                this.smtp_use_imap_credentials = false;
+                this.smtp_noauth = false;
+                break;
+            }
+        }
+    }
+
     /**
      * Whether we should NOT authenticate with the server.
      *


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