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
This commit is contained in:
parent
f2a11edd97
commit
ca846edf59
2 changed files with 60 additions and 6 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue