Commit a5e7f928 authored by Michael Gratton's avatar Michael Gratton 🤞

Merge branch 'wip/244-save-sent-ui-missing' into 'master'

Add save sent email account pref UI back

Closes #244

See merge request !120

(cherry picked from commit 5e886534)

54752902 Allow both accounts and services to have provider-specific defaults
4d57ab9b Default Outlook accounts to not save sent mail
45f53ef3 Add save sent email account option when needed
parent 1124f2d5
Pipeline #60834 failed with stages
in 17 minutes and 53 seconds
......@@ -309,8 +309,9 @@ internal class Accounts.EditorAddPane : Gtk.Grid, EditorPane {
}
private Geary.ServiceInformation new_imap_service() {
Geary.ServiceInformation service =
new Geary.ServiceInformation(Geary.Protocol.IMAP);
Geary.ServiceInformation service = new Geary.ServiceInformation(
Geary.Protocol.IMAP, this.provider
);
if (this.provider == Geary.ServiceProvider.OTHER) {
service.credentials = new Geary.Credentials(
......@@ -331,7 +332,6 @@ internal class Accounts.EditorAddPane : Gtk.Grid, EditorPane {
service.port = service.get_default_port();
}
} else {
this.provider.setup_service(service);
service.credentials = new Geary.Credentials(
Geary.Credentials.Method.PASSWORD,
this.email.value.get_text().strip(),
......@@ -343,8 +343,9 @@ internal class Accounts.EditorAddPane : Gtk.Grid, EditorPane {
}
private Geary.ServiceInformation new_smtp_service() {
Geary.ServiceInformation service =
new Geary.ServiceInformation(Geary.Protocol.SMTP);
Geary.ServiceInformation service = new Geary.ServiceInformation(
Geary.Protocol.SMTP, this.provider
);
if (this.provider == Geary.ServiceProvider.OTHER) {
service.credentials_requirement = this.smtp_auth.value.source;
......@@ -369,8 +370,6 @@ internal class Accounts.EditorAddPane : Gtk.Grid, EditorPane {
if (service.port == 0) {
service.port = service.get_default_port();
}
} else {
this.provider.setup_service(service);
}
return service;
......
......@@ -77,6 +77,7 @@ internal class Accounts.EditorServersPane :
private Gtk.Spinner apply_spinner;
private SaveDraftsRow save_drafts;
private SaveSentRow save_sent;
private ServiceLoginRow incoming_login;
private ServicePasswordRow incoming_password;
......@@ -118,6 +119,16 @@ internal class Accounts.EditorServersPane :
);
add_row(this.details_list, this.save_drafts);
this.save_sent = new SaveSentRow(
this.account, this.commands, this.op_cancellable
);
switch (account.service_provider) {
case YAHOO:
case OTHER:
add_row(this.details_list, this.save_sent);
break;
}
// Receiving
this.receiving_list.set_header_func(Editor.seperator_headers);
......@@ -263,6 +274,10 @@ internal class Accounts.EditorServersPane :
has_changed = true;
}
if (this.save_sent.value_changed) {
has_changed = true;
}
if (has_changed) {
this.account.changed();
}
......@@ -274,9 +289,10 @@ internal class Accounts.EditorServersPane :
// change something to re-enable it
this.apply_button.set_sensitive(true);
// Undo save_drafts manually since it would have been
// updated already by the command
// Undo these manually since it would have been updated
// already by the command
this.account.save_drafts = this.save_drafts.initial_value;
this.account.save_sent = this.save_sent.initial_value;
}
}
......@@ -626,6 +642,61 @@ private class Accounts.SaveDraftsRow :
}
private class Accounts.SaveSentRow :
AccountRow<EditorServersPane,Gtk.Switch> {
public bool value_changed {
get { return this.initial_value != this.value.state; }
}
public bool initial_value { get; private set; }
private Application.CommandStack commands;
private GLib.Cancellable? cancellable;
public SaveSentRow(Geary.AccountInformation account,
Application.CommandStack commands,
GLib.Cancellable? cancellable) {
Gtk.Switch value = new Gtk.Switch();
base(
account,
// Translators: This label describes an account
// preference.
_("Save sent email on server"),
value
);
update();
this.commands = commands;
this.cancellable = cancellable;
this.activatable = false;
this.initial_value = this.account.save_sent;
this.account.notify["save-sent"].connect(on_account_changed);
this.value.notify["active"].connect(on_activate);
}
public override void update() {
this.value.state = this.account.save_sent;
}
private void on_activate() {
if (this.value.state != this.account.save_sent) {
this.commands.execute.begin(
new Application.PropertyCommand<bool>(
this.account, "save_sent", this.value.state
),
this.cancellable
);
}
}
private void on_account_changed() {
update();
}
}
private class Accounts.ServiceHostRow :
ServiceRow<EditorServersPane,Gtk.Entry>, ValidatingRow {
......
......@@ -602,9 +602,6 @@ public class Accounts.Manager : GLib.Object {
} catch (GLib.KeyFileError err) {
throw new ConfigError.SYNTAX(err.message);
}
account.service_provider.setup_service(account.incoming);
account.service_provider.setup_service(account.outgoing);
} else {
account.service_label = goa_mediator.get_service_label();
try {
......
......@@ -127,18 +127,18 @@ public class Geary.AccountInformation : BaseObject {
get; set; default = DEFAULT_PREFETCH_PERIOD_DAYS;
}
/**
* Specifies if the user has requested that sent mail be saved.
*
* Note that Geary will only actively push sent mail when this AND
* {@link allow_save_sent} are both true.
*/
/** Specifies if sent email should be saved to the Sent folder. */
public bool save_sent {
// If we aren't allowed to save sent mail due to account type, we want
// to return true here on the assumption that the account will save
// sent mail for us, and thus the user can't disable sent mail from
// being saved.
get { return (allow_save_sent() ? this._save_sent : true); }
get {
bool save = _save_sent;
switch (this.service_provider) {
case GMAIL:
case OUTLOOK:
save = false;
break;
}
return save;
}
set { this._save_sent = value; }
}
private bool _save_sent = true;
......@@ -152,16 +152,10 @@ public class Geary.AccountInformation : BaseObject {
public CredentialsMediator mediator { get; private set; }
/* Incoming email service configuration. */
public ServiceInformation incoming {
get; set;
default = new ServiceInformation(Protocol.IMAP);
}
public ServiceInformation incoming { get; set; }
/* Outgoing email service configuration. */
public ServiceInformation outgoing {
get; set;
default = new ServiceInformation(Protocol.SMTP);
}
public ServiceInformation outgoing { get; set; }
/** A lock that can be used to ensure saving is serialised. */
public Nonblocking.Mutex write_lock {
......@@ -253,6 +247,11 @@ public class Geary.AccountInformation : BaseObject {
this.id = id;
this.mediator = mediator;
this.service_provider = provider;
this.incoming = new ServiceInformation(Protocol.IMAP, provider);
this.outgoing = new ServiceInformation(Protocol.SMTP, provider);
provider.set_account_defaults(this);
append_sender(primary_mailbox);
}
......@@ -356,18 +355,6 @@ public class Geary.AccountInformation : BaseObject {
return removed;
}
/**
* Determines if {@link save_sent} property can be set.
*
* If not, that property will always be true and setting it will
* be ignored.
*/
public bool allow_save_sent() {
// We should never push mail to Gmail, since its servers
// automatically push sent mail to the sent mail folder.
return this.service_provider != ServiceProvider.GMAIL;
}
/**
* Returns the configured path for a special folder type.
*
......
......@@ -116,7 +116,7 @@ public class Geary.ServiceInformation : GLib.Object {
/**
* Constructs a new configuration for a specific service.
*/
public ServiceInformation(Protocol proto) {
public ServiceInformation(Protocol proto, ServiceProvider provider) {
this.protocol = proto;
// Prefer TLS by RFC 8314, but use START_TLS for SMTP for the
// moment while its still more widely deployed.
......@@ -126,13 +126,16 @@ public class Geary.ServiceInformation : GLib.Object {
this.credentials_requirement = (proto == Protocol.SMTP)
? Credentials.Requirement.USE_INCOMING
: Credentials.Requirement.CUSTOM;
provider.set_service_defaults(this);
}
/**
* Constructs a copy of the given service configuration.
*/
public ServiceInformation.copy(ServiceInformation other) {
this(other.protocol);
// Use OTHER here to get blank defaults
this(other.protocol, ServiceInformation.OTHER);
this.host = other.host;
this.port = other.port;
this.transport_security = other.transport_security;
......
......@@ -29,7 +29,22 @@ public enum Geary.ServiceProvider {
);
}
public void setup_service(ServiceInformation service) {
internal void set_account_defaults(AccountInformation service) {
switch (this) {
case GMAIL:
ImapEngine.GmailAccount.setup_account(service);
break;
case YAHOO:
ImapEngine.YahooAccount.setup_account(service);
break;
case OUTLOOK:
ImapEngine.OutlookAccount.setup_account(service);
break;
}
}
internal void set_service_defaults(ServiceInformation service) {
switch (this) {
case GMAIL:
ImapEngine.GmailAccount.setup_service(service);
......
......@@ -17,6 +17,10 @@ private class Geary.ImapEngine.GmailAccount : Geary.ImapEngine.GenericAccount {
};
public static void setup_account(AccountInformation account) {
account.save_sent = false;
}
public static void setup_service(ServiceInformation service) {
switch (service.protocol) {
case Protocol.IMAP:
......
......@@ -9,6 +9,10 @@
private class Geary.ImapEngine.OutlookAccount : Geary.ImapEngine.GenericAccount {
public static void setup_account(AccountInformation account) {
account.save_sent = false;
}
public static void setup_service(ServiceInformation service) {
switch (service.protocol) {
case Protocol.IMAP:
......
......@@ -9,6 +9,10 @@
private class Geary.ImapEngine.YahooAccount : Geary.ImapEngine.GenericAccount {
public static void setup_account(AccountInformation account) {
// noop
}
public static void setup_service(ServiceInformation service) {
switch (service.protocol) {
case Protocol.IMAP:
......
......@@ -10,9 +10,45 @@ class Geary.AccountInformationTest : TestCase {
public AccountInformationTest() {
base("Geary.AccountInformationTest");
add_test("test_save_sent_defaults", test_save_sent_defaults);
add_test("test_sender_mailboxes", test_sender_mailboxes);
}
public void test_save_sent_defaults() throws GLib.Error {
assert_true(
new AccountInformation(
"test",
ServiceProvider.OTHER,
new MockCredentialsMediator(),
new RFC822.MailboxAddress(null, "test1@example.com")
).save_sent
);
assert_false(
new AccountInformation(
"test",
ServiceProvider.GMAIL,
new MockCredentialsMediator(),
new RFC822.MailboxAddress(null, "test1@example.com")
).save_sent
);
assert_false(
new AccountInformation(
"test",
ServiceProvider.OUTLOOK,
new MockCredentialsMediator(),
new RFC822.MailboxAddress(null, "test1@example.com")
).save_sent
);
assert_true(
new AccountInformation(
"test",
ServiceProvider.YAHOO,
new MockCredentialsMediator(),
new RFC822.MailboxAddress(null, "test1@example.com")
).save_sent
);
}
public void test_sender_mailboxes() throws GLib.Error {
AccountInformation test = new AccountInformation(
"test",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment