[geary/wip/261-improve-service-label] Improve AccountInformation.service_label generation
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/261-improve-service-label] Improve AccountInformation.service_label generation
- Date: Fri, 22 Feb 2019 05:59:54 +0000 (UTC)
commit ca846edf591558757d38d1478686b7e5c169981d
Author: Michael Gratton <mike vee net>
Date: Fri Feb 22 16:56:32 2019 +1100
Improve AccountInformation.service_label generation
If the primary email address matches the incoming host name, use that.
Else use a prefix of the hostname but only if it is more that two domain
parts long. E.g. don't shorten "other.com" to "com".
Fixes #261
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]