[geary/geary-0.13] Merge branch 'wip/261-improve-service-label' into 'master'



commit 83838f5695a0ebcbaa7a84cd872910fdb84124e4
Author: Michael Gratton <mike vee net>
Date:   Fri Feb 22 06:14:41 2019 +0000

    Merge branch 'wip/261-improve-service-label' into 'master'
    
    Improve AccountInformation.service_label generation
    
    Closes #261
    
    See merge request GNOME/geary!137
    
    (cherry picked from commit 09881b5fa7997a2710d7781add129911027d9d2c)
    
    ca846edf Improve AccountInformation.service_label generation

 src/engine/api/geary-account-information.vala      | 18 +++++---
 .../engine/api/geary-account-information-test.vala | 48 ++++++++++++++++++++++
 2 files changed, 60 insertions(+), 6 deletions(-)
---
diff --git a/src/engine/api/geary-account-information.vala b/src/engine/api/geary-account-information.vala
index c0d0c74e..2d0a8ff1 100644
--- a/src/engine/api/geary-account-information.vala
+++ b/src/engine/api/geary-account-information.vala
@@ -60,13 +60,19 @@ public class Geary.AccountInformation : BaseObject {
         owned get {
             string? value = this._service_label;
             if (value == null) {
-                string[] host_parts = this.incoming.host.split(".");
-                if (host_parts.length > 1) {
-                    host_parts = host_parts[1:host_parts.length];
+                string email_domain = this.primary_mailbox.domain;
+                if (this.incoming.host.has_suffix(email_domain)) {
+                    value = email_domain;
+                } else {
+                    string[] host_parts = this.incoming.host.split(".");
+                    if (host_parts.length > 2) {
+                        host_parts = host_parts[1:host_parts.length];
+                    }
+                    value = string.joinv(".", host_parts);
                 }
-                // don't stash this in _service_label since we want it
-                // updated if the service host names change
-                value = string.joinv(".", host_parts);
+                // Don't stash the calculated value in _service_label
+                // since we want it updated if the service host names
+                // change
             }
             return value;
         }
diff --git a/test/engine/api/geary-account-information-test.vala 
b/test/engine/api/geary-account-information-test.vala
index 1323ffcf..12d733e0 100644
--- a/test/engine/api/geary-account-information-test.vala
+++ b/test/engine/api/geary-account-information-test.vala
@@ -12,6 +12,7 @@ class Geary.AccountInformationTest : TestCase {
         base("Geary.AccountInformationTest");
         add_test("test_save_sent_defaults", test_save_sent_defaults);
         add_test("test_sender_mailboxes", test_sender_mailboxes);
+        add_test("test_service_label", test_service_label);
     }
 
     public void test_save_sent_defaults() throws GLib.Error {
@@ -85,4 +86,51 @@ class Geary.AccountInformationTest : TestCase {
         );
     }
 
+    public void test_service_label() throws GLib.Error {
+        AccountInformation test = new_information();
+        assert_string("", test.service_label);
+
+        test = new_information();
+        test.incoming.host = "example.com";
+        assert_string(
+            "example.com", test.service_label, "Email domain equals host name"
+        );
+
+        test = new_information();
+        test.incoming.host = "test.example.com";
+        assert_string(
+            "example.com", test.service_label, "Email domain host name suffix"
+        );
+
+        test = new_information();
+        test.incoming.host = "other.com";
+        test.outgoing.host = "other.com";
+        assert_string("other.com", test.service_label);
+
+        test = new_information();
+        test.incoming.host = "mail.other.com";
+        test.outgoing.host = "mail.other.com";
+        assert_string("other.com", test.service_label);
+
+        test = new_information();
+        test.incoming.host = "imap.other.com";
+        test.outgoing.host = "smtp.other.com";
+        assert_string("other.com", test.service_label);
+
+        test = new_information();
+        test.incoming.host = "not-mail.other.com";
+        test.outgoing.host = "not-mail.other.com";
+        assert_string("other.com", test.service_label);
+    }
+
+    private AccountInformation new_information(ServiceProvider provider =
+                                               ServiceProvider.OTHER) {
+        return new AccountInformation(
+            "test",
+            provider,
+            new MockCredentialsMediator(),
+            new RFC822.MailboxAddress(null, "test1 example com")
+        );
+    }
+
 }


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