[geary/wip/account-ux: 1/4] Convert from using AccountInformation.email to an id - engine changes.
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/account-ux: 1/4] Convert from using AccountInformation.email to an id - engine changes.
- Date: Tue, 19 Jul 2016 05:51:47 +0000 (UTC)
commit 302246746dcfe1a26bdef07da05f851fff4120f8
Author: Michael James Gratton <mike vee net>
Date: Thu Jul 14 01:24:59 2016 +1000
Convert from using AccountInformation.email to an id - engine changes.
* src/engine/api/geary-account-information.vala (AccountInformation): Add
an id property, replace the string email prop with a
RFC822.MailboxAddress primary_mailbox property. Fix all uses of `email`
to use either id or primary_mailbox instead. Tidy up the source a bit
while I'm here.
* src/engine/api/geary-engine.vala (Engine): Add ::get_account method
that throws an error when the account is not found.
(Engine::create_orphan_account): Updated to us `id` rather than `email`
to referr to an account.
src/engine/api/geary-account-information.vala | 318 +++++++++++----------
src/engine/api/geary-engine.vala | 94 ++++---
src/engine/imap-db/imap-db-account.vala | 20 +-
src/engine/imap-db/imap-db-database.vala | 2 +
src/engine/imap-db/imap-db-folder.vala | 1 +
src/engine/imap-db/outbox/smtp-outbox-folder.vala | 2 +-
src/engine/imap-engine/imap-engine.vala | 2 +-
7 files changed, 236 insertions(+), 203 deletions(-)
---
diff --git a/src/engine/api/geary-account-information.vala b/src/engine/api/geary-account-information.vala
index 1f4365c..f6fab31 100644
--- a/src/engine/api/geary-account-information.vala
+++ b/src/engine/api/geary-account-information.vala
@@ -67,7 +67,17 @@ public class Geary.AccountInformation : BaseObject {
//
// IMPORTANT: When adding new properties, be sure to add them to the copy method.
//
-
+
+ /**
+ * Unique identifier for this account.
+ *
+ * This string's value should be treated as an opaque, private
+ * implementation detail and not parsed at all. For older accounts
+ * it will be an email address, for newer accounts it will be
+ * something else.
+ */
+ public string id { get; private set; }
+
/**
* User's name for the {@link get_primary_mailbox_address}.
*/
@@ -77,18 +87,12 @@ public class Geary.AccountInformation : BaseObject {
* User label for primary account (not transmitted on wire or used in correspondence).
*/
public string nickname { get; set; }
-
+
/**
- * The primary email address for the account.
- *
- * This the RFC822 simple mailbox style, i.e. "jim example com".
- *
- * In general, it's better to use the result of {@link get_primary_mailbox_address}, as the
- * {@link Geary.RFC822.MailboxAddress} object is better suited for comparisons, Gee collections,
- * validation, composing quoted strings, and so forth.
+ * The default email address for the account.
*/
- public string email { get; set; }
-
+ public Geary.RFC822.MailboxAddress primary_mailbox { get; set; }
+
/**
* A list of additional email addresses this account accepts.
*
@@ -97,8 +101,8 @@ public class Geary.AccountInformation : BaseObject {
*
* @see get_all_mailboxes
*/
- public Gee.List<Geary.RFC822.MailboxAddress>? alternate_mailboxes { get; private set; }
-
+ public Gee.List<Geary.RFC822.MailboxAddress>? alternate_mailboxes { get; private set; default = null; }
+
public Geary.ServiceProvider service_provider { get; set; }
public int prefetch_period_days { get; set; }
@@ -169,6 +173,7 @@ public class Geary.AccountInformation : BaseObject {
// This constructor is used internally to load accounts from disk.
internal AccountInformation.from_file(File config_directory, File data_directory) {
+ this.id = config_directory.get_basename();
this.config_dir = config_directory;
this.data_dir = data_directory;
this.file = config_dir.get_child(SETTINGS_FILENAME);
@@ -181,76 +186,76 @@ public class Geary.AccountInformation : BaseObject {
} catch (KeyFileError err) {
// It's no big deal if we couldn't load the key file -- just means we give you the defaults.
} finally {
- real_name = get_string_value(key_file, GROUP, REAL_NAME_KEY);
- nickname = get_string_value(key_file, GROUP, NICKNAME_KEY);
- email = get_string_value(key_file, GROUP, PRIMARY_EMAIL_KEY);
-
+ this.real_name = get_string_value(key_file, GROUP, REAL_NAME_KEY);
+ this.nickname = get_string_value(key_file, GROUP, NICKNAME_KEY);
+
+ string primary_email = get_string_value(key_file, GROUP, PRIMARY_EMAIL_KEY);
+ this.primary_mailbox = new RFC822.MailboxAddress(this.real_name, primary_email);
+
// Store alternate emails in a list of case-insensitive strings
Gee.List<string> alt_email_list = get_string_list_value(key_file, GROUP, ALTERNATE_EMAILS_KEY);
- if (alt_email_list.size == 0) {
- alternate_mailboxes = null;
- } else {
+ if (alt_email_list.size != 0) {
foreach (string alt_email in alt_email_list) {
RFC822.MailboxAddresses mailboxes = new
RFC822.MailboxAddresses.from_rfc822_string(alt_email);
foreach (RFC822.MailboxAddress mailbox in mailboxes.get_all())
add_alternate_mailbox(mailbox);
}
}
-
- imap_credentials.user = get_string_value(key_file, GROUP, IMAP_USERNAME_KEY, email);
- imap_remember_password = get_bool_value(key_file, GROUP, IMAP_REMEMBER_PASSWORD_KEY, true);
- smtp_credentials.user = get_string_value(key_file, GROUP, SMTP_USERNAME_KEY, email);
- smtp_remember_password = get_bool_value(key_file, GROUP, SMTP_REMEMBER_PASSWORD_KEY, true);
- service_provider = Geary.ServiceProvider.from_string(get_string_value(key_file, GROUP,
+
+ this.imap_credentials.user = get_string_value(key_file, GROUP, IMAP_USERNAME_KEY, primary_email);
+ this.imap_remember_password = get_bool_value(key_file, GROUP, IMAP_REMEMBER_PASSWORD_KEY, true);
+ this.smtp_credentials.user = get_string_value(key_file, GROUP, SMTP_USERNAME_KEY, primary_email);
+ this.smtp_remember_password = get_bool_value(key_file, GROUP, SMTP_REMEMBER_PASSWORD_KEY, true);
+ this.service_provider = Geary.ServiceProvider.from_string(get_string_value(key_file, GROUP,
SERVICE_PROVIDER_KEY, Geary.ServiceProvider.GMAIL.to_string()));
- prefetch_period_days = get_int_value(key_file, GROUP, PREFETCH_PERIOD_DAYS_KEY,
+ this.prefetch_period_days = get_int_value(key_file, GROUP, PREFETCH_PERIOD_DAYS_KEY,
DEFAULT_PREFETCH_PERIOD_DAYS);
- save_sent_mail = get_bool_value(key_file, GROUP, SAVE_SENT_MAIL_KEY, true);
- ordinal = get_int_value(key_file, GROUP, ORDINAL_KEY, default_ordinal++);
- use_email_signature = get_bool_value(key_file, GROUP, USE_EMAIL_SIGNATURE_KEY);
- email_signature = get_escaped_string(key_file, GROUP, EMAIL_SIGNATURE_KEY);
-
- if (ordinal >= default_ordinal)
- default_ordinal = ordinal + 1;
-
+ this.save_sent_mail = get_bool_value(key_file, GROUP, SAVE_SENT_MAIL_KEY, true);
+ this.ordinal = get_int_value(key_file, GROUP, ORDINAL_KEY, AccountInformation.default_ordinal++);
+ this.use_email_signature = get_bool_value(key_file, GROUP, USE_EMAIL_SIGNATURE_KEY);
+ this.email_signature = get_escaped_string(key_file, GROUP, EMAIL_SIGNATURE_KEY);
+
+ if (this.ordinal >= AccountInformation.default_ordinal)
+ AccountInformation.default_ordinal = this.ordinal + 1;
+
if (service_provider == ServiceProvider.OTHER) {
- default_imap_server_host = get_string_value(key_file, GROUP, IMAP_HOST);
- default_imap_server_port = get_uint16_value(key_file, GROUP, IMAP_PORT,
+ this.default_imap_server_host = get_string_value(key_file, GROUP, IMAP_HOST);
+ this.default_imap_server_port = get_uint16_value(key_file, GROUP, IMAP_PORT,
Imap.ClientConnection.DEFAULT_PORT_SSL);
- default_imap_server_ssl = get_bool_value(key_file, GROUP, IMAP_SSL, true);
- default_imap_server_starttls = get_bool_value(key_file, GROUP, IMAP_STARTTLS, false);
-
- default_smtp_server_host = get_string_value(key_file, GROUP, SMTP_HOST);
- default_smtp_server_port = get_uint16_value(key_file, GROUP, SMTP_PORT,
+ this.default_imap_server_ssl = get_bool_value(key_file, GROUP, IMAP_SSL, true);
+ this.default_imap_server_starttls = get_bool_value(key_file, GROUP, IMAP_STARTTLS, false);
+
+ this.default_smtp_server_host = get_string_value(key_file, GROUP, SMTP_HOST);
+ this.default_smtp_server_port = get_uint16_value(key_file, GROUP, SMTP_PORT,
Geary.Smtp.ClientConnection.DEFAULT_PORT_SSL);
- default_smtp_server_ssl = get_bool_value(key_file, GROUP, SMTP_SSL, true);
- default_smtp_server_starttls = get_bool_value(key_file, GROUP, SMTP_STARTTLS, false);
- default_smtp_use_imap_credentials = get_bool_value(key_file, GROUP,
SMTP_USE_IMAP_CREDENTIALS, false);
- default_smtp_server_noauth = get_bool_value(key_file, GROUP, SMTP_NOAUTH, false);
-
+ this.default_smtp_server_ssl = get_bool_value(key_file, GROUP, SMTP_SSL, true);
+ this.default_smtp_server_starttls = get_bool_value(key_file, GROUP, SMTP_STARTTLS, false);
+ this.default_smtp_use_imap_credentials = get_bool_value(key_file, GROUP,
SMTP_USE_IMAP_CREDENTIALS, false);
+ this.default_smtp_server_noauth = get_bool_value(key_file, GROUP, SMTP_NOAUTH, false);
+
if (default_smtp_server_noauth) {
- smtp_credentials = null;
+ this.smtp_credentials = null;
} else if (default_smtp_use_imap_credentials) {
- smtp_credentials.user = imap_credentials.user;
- smtp_credentials.pass = imap_credentials.pass;
+ this.smtp_credentials.user = imap_credentials.user;
+ this.smtp_credentials.pass = imap_credentials.pass;
}
}
-
- drafts_folder_path = build_folder_path(get_string_list_value(
+
+ this.drafts_folder_path = build_folder_path(get_string_list_value(
key_file, GROUP, DRAFTS_FOLDER_KEY));
- sent_mail_folder_path = build_folder_path(get_string_list_value(
+ this.sent_mail_folder_path = build_folder_path(get_string_list_value(
key_file, GROUP, SENT_MAIL_FOLDER_KEY));
- spam_folder_path = build_folder_path(get_string_list_value(
+ this.spam_folder_path = build_folder_path(get_string_list_value(
key_file, GROUP, SPAM_FOLDER_KEY));
- trash_folder_path = build_folder_path(get_string_list_value(
+ this.trash_folder_path = build_folder_path(get_string_list_value(
key_file, GROUP, TRASH_FOLDER_KEY));
- archive_folder_path = build_folder_path(get_string_list_value(
+ this.archive_folder_path = build_folder_path(get_string_list_value(
key_file, GROUP, ARCHIVE_FOLDER_KEY));
-
- save_drafts = get_bool_value(key_file, GROUP, SAVE_DRAFTS_KEY, true);
+
+ this.save_drafts = get_bool_value(key_file, GROUP, SAVE_DRAFTS_KEY, true);
}
}
-
+
~AccountInformation() {
if (imap_endpoint != null)
imap_endpoint.untrusted_host.disconnect(on_imap_untrusted_host);
@@ -279,50 +284,50 @@ public class Geary.AccountInformation : BaseObject {
// Copies all data from the "from" object into this one.
public void copy_from(AccountInformation from) {
- real_name = from.real_name;
- nickname = from.nickname;
- email = from.email;
- alternate_mailboxes = null;
+ this.id = from.id;
+ this.real_name = from.real_name;
+ this.nickname = from.nickname;
+ this.primary_mailbox = from.primary_mailbox;
if (from.alternate_mailboxes != null) {
foreach (RFC822.MailboxAddress alternate_mailbox in from.alternate_mailboxes)
add_alternate_mailbox(alternate_mailbox);
}
- service_provider = from.service_provider;
- prefetch_period_days = from.prefetch_period_days;
- save_sent_mail = from.save_sent_mail;
- ordinal = from.ordinal;
- default_imap_server_host = from.default_imap_server_host;
- default_imap_server_port = from.default_imap_server_port;
- default_imap_server_ssl = from.default_imap_server_ssl;
- default_imap_server_starttls = from.default_imap_server_starttls;
- default_smtp_server_host = from.default_smtp_server_host;
- default_smtp_server_port = from.default_smtp_server_port;
- default_smtp_server_ssl = from.default_smtp_server_ssl;
- default_smtp_server_starttls = from.default_smtp_server_starttls;
- default_smtp_use_imap_credentials = from.default_smtp_use_imap_credentials;
- default_smtp_server_noauth = from.default_smtp_server_noauth;
- imap_credentials = from.imap_credentials;
- imap_remember_password = from.imap_remember_password;
- smtp_credentials = from.smtp_credentials;
- smtp_remember_password = from.smtp_remember_password;
- drafts_folder_path = from.drafts_folder_path;
- sent_mail_folder_path = from.sent_mail_folder_path;
- spam_folder_path = from.spam_folder_path;
- trash_folder_path = from.trash_folder_path;
- archive_folder_path = from.archive_folder_path;
- save_drafts = from.save_drafts;
- use_email_signature = from.use_email_signature;
- email_signature = from.email_signature;
+ this.service_provider = from.service_provider;
+ this.prefetch_period_days = from.prefetch_period_days;
+ this.save_sent_mail = from.save_sent_mail;
+ this.ordinal = from.ordinal;
+ this.default_imap_server_host = from.default_imap_server_host;
+ this.default_imap_server_port = from.default_imap_server_port;
+ this.default_imap_server_ssl = from.default_imap_server_ssl;
+ this.default_imap_server_starttls = from.default_imap_server_starttls;
+ this.default_smtp_server_host = from.default_smtp_server_host;
+ this.default_smtp_server_port = from.default_smtp_server_port;
+ this.default_smtp_server_ssl = from.default_smtp_server_ssl;
+ this.default_smtp_server_starttls = from.default_smtp_server_starttls;
+ this.default_smtp_use_imap_credentials = from.default_smtp_use_imap_credentials;
+ this.default_smtp_server_noauth = from.default_smtp_server_noauth;
+ this.imap_credentials = from.imap_credentials;
+ this.imap_remember_password = from.imap_remember_password;
+ this.smtp_credentials = from.smtp_credentials;
+ this.smtp_remember_password = from.smtp_remember_password;
+ this.drafts_folder_path = from.drafts_folder_path;
+ this.sent_mail_folder_path = from.sent_mail_folder_path;
+ this.spam_folder_path = from.spam_folder_path;
+ this.trash_folder_path = from.trash_folder_path;
+ this.archive_folder_path = from.archive_folder_path;
+ this.save_drafts = from.save_drafts;
+ this.use_email_signature = from.use_email_signature;
+ this.email_signature = from.email_signature;
}
-
+
/**
* Return a list of the primary and all alternate email addresses.
*/
public Gee.List<Geary.RFC822.MailboxAddress> get_all_mailboxes() {
Gee.ArrayList<RFC822.MailboxAddress> all = new Gee.ArrayList<RFC822.MailboxAddress>();
-
- all.add(get_primary_mailbox_address());
-
+
+ all.add(this.primary_mailbox);
+
if (alternate_mailboxes != null)
all.add_all(alternate_mailboxes);
@@ -790,8 +795,8 @@ public class Geary.AccountInformation : BaseObject {
try {
config_dir.make_directory_with_parents();
} catch (Error err) {
- error("Error creating configuration directory for email '%s': %s", email,
- err.message);
+ error("Error creating configuration directory for account '%s': %s",
+ this.id, err.message);
}
}
@@ -799,8 +804,8 @@ public class Geary.AccountInformation : BaseObject {
try {
data_dir.make_directory_with_parents();
} catch (Error err) {
- error("Error creating storage directory for email '%s': %s", email,
- err.message);
+ error("Error creating storage directory for account '%s': %s",
+ this.id, err.message);
}
}
@@ -811,61 +816,61 @@ public class Geary.AccountInformation : BaseObject {
debug("Error creating account info file: %s", err.message);
}
}
-
+
KeyFile key_file = new KeyFile();
-
- key_file.set_value(GROUP, REAL_NAME_KEY, real_name);
- key_file.set_value(GROUP, NICKNAME_KEY, nickname);
- key_file.set_value(GROUP, PRIMARY_EMAIL_KEY, email);
- key_file.set_value(GROUP, SERVICE_PROVIDER_KEY, service_provider.to_string());
- key_file.set_integer(GROUP, ORDINAL_KEY, ordinal);
- key_file.set_value(GROUP, IMAP_USERNAME_KEY, imap_credentials.user);
- key_file.set_boolean(GROUP, IMAP_REMEMBER_PASSWORD_KEY, imap_remember_password);
+
+ key_file.set_value(GROUP, REAL_NAME_KEY, this.real_name);
+ key_file.set_value(GROUP, NICKNAME_KEY, this.nickname);
+ key_file.set_value(GROUP, PRIMARY_EMAIL_KEY, this.primary_mailbox.to_rfc822_string());
+ key_file.set_value(GROUP, SERVICE_PROVIDER_KEY, this.service_provider.to_string());
+ key_file.set_integer(GROUP, ORDINAL_KEY, this.ordinal);
+ key_file.set_value(GROUP, IMAP_USERNAME_KEY, this.imap_credentials.user);
+ key_file.set_boolean(GROUP, IMAP_REMEMBER_PASSWORD_KEY, this.imap_remember_password);
if (smtp_credentials != null)
- key_file.set_value(GROUP, SMTP_USERNAME_KEY, smtp_credentials.user);
- key_file.set_boolean(GROUP, SMTP_REMEMBER_PASSWORD_KEY, smtp_remember_password);
- key_file.set_integer(GROUP, PREFETCH_PERIOD_DAYS_KEY, prefetch_period_days);
- key_file.set_boolean(GROUP, SAVE_SENT_MAIL_KEY, save_sent_mail);
- key_file.set_boolean(GROUP, USE_EMAIL_SIGNATURE_KEY, use_email_signature);
- key_file.set_string(GROUP, EMAIL_SIGNATURE_KEY, email_signature);
- if (alternate_mailboxes != null && alternate_mailboxes.size > 0) {
- string[] list = new string[alternate_mailboxes.size];
- for (int ctr = 0; ctr < alternate_mailboxes.size; ctr++)
- list[ctr] = alternate_mailboxes[ctr].to_rfc822_string();
-
+ key_file.set_value(GROUP, SMTP_USERNAME_KEY, this.smtp_credentials.user);
+ key_file.set_boolean(GROUP, SMTP_REMEMBER_PASSWORD_KEY, this.smtp_remember_password);
+ key_file.set_integer(GROUP, PREFETCH_PERIOD_DAYS_KEY, this.prefetch_period_days);
+ key_file.set_boolean(GROUP, SAVE_SENT_MAIL_KEY, this.save_sent_mail);
+ key_file.set_boolean(GROUP, USE_EMAIL_SIGNATURE_KEY, this.use_email_signature);
+ key_file.set_string(GROUP, EMAIL_SIGNATURE_KEY, this.email_signature);
+ if (alternate_mailboxes != null && this.alternate_mailboxes.size > 0) {
+ string[] list = new string[this.alternate_mailboxes.size];
+ for (int ctr = 0; ctr < this.alternate_mailboxes.size; ctr++)
+ list[ctr] = this.alternate_mailboxes[ctr].to_rfc822_string();
+
key_file.set_string_list(GROUP, ALTERNATE_EMAILS_KEY, list);
}
-
+
if (service_provider == ServiceProvider.OTHER) {
- key_file.set_value(GROUP, IMAP_HOST, default_imap_server_host);
- key_file.set_integer(GROUP, IMAP_PORT, default_imap_server_port);
- key_file.set_boolean(GROUP, IMAP_SSL, default_imap_server_ssl);
- key_file.set_boolean(GROUP, IMAP_STARTTLS, default_imap_server_starttls);
-
- key_file.set_value(GROUP, SMTP_HOST, default_smtp_server_host);
- key_file.set_integer(GROUP, SMTP_PORT, default_smtp_server_port);
- key_file.set_boolean(GROUP, SMTP_SSL, default_smtp_server_ssl);
- key_file.set_boolean(GROUP, SMTP_STARTTLS, default_smtp_server_starttls);
- key_file.set_boolean(GROUP, SMTP_USE_IMAP_CREDENTIALS, default_smtp_use_imap_credentials);
- key_file.set_boolean(GROUP, SMTP_NOAUTH, default_smtp_server_noauth);
+ key_file.set_value(GROUP, IMAP_HOST, this.default_imap_server_host);
+ key_file.set_integer(GROUP, IMAP_PORT, this.default_imap_server_port);
+ key_file.set_boolean(GROUP, IMAP_SSL, this.default_imap_server_ssl);
+ key_file.set_boolean(GROUP, IMAP_STARTTLS, this.default_imap_server_starttls);
+
+ key_file.set_value(GROUP, SMTP_HOST, this.default_smtp_server_host);
+ key_file.set_integer(GROUP, SMTP_PORT, this.default_smtp_server_port);
+ key_file.set_boolean(GROUP, SMTP_SSL, this.default_smtp_server_ssl);
+ key_file.set_boolean(GROUP, SMTP_STARTTLS, this.default_smtp_server_starttls);
+ key_file.set_boolean(GROUP, SMTP_USE_IMAP_CREDENTIALS, this.default_smtp_use_imap_credentials);
+ key_file.set_boolean(GROUP, SMTP_NOAUTH, this.default_smtp_server_noauth);
}
-
- key_file.set_string_list(GROUP, DRAFTS_FOLDER_KEY, (drafts_folder_path != null
- ? drafts_folder_path.as_list().to_array() : new string[] {}));
- key_file.set_string_list(GROUP, SENT_MAIL_FOLDER_KEY, (sent_mail_folder_path != null
- ? sent_mail_folder_path.as_list().to_array() : new string[] {}));
- key_file.set_string_list(GROUP, SPAM_FOLDER_KEY, (spam_folder_path != null
- ? spam_folder_path.as_list().to_array() : new string[] {}));
- key_file.set_string_list(GROUP, TRASH_FOLDER_KEY, (trash_folder_path != null
- ? trash_folder_path.as_list().to_array() : new string[] {}));
- key_file.set_string_list(GROUP, ARCHIVE_FOLDER_KEY, (archive_folder_path != null
- ? archive_folder_path.as_list().to_array() : new string[] {}));
-
- key_file.set_boolean(GROUP, SAVE_DRAFTS_KEY, save_drafts);
-
+
+ key_file.set_string_list(GROUP, DRAFTS_FOLDER_KEY, (this.drafts_folder_path != null
+ ? this.drafts_folder_path.as_list().to_array() : new string[] {}));
+ key_file.set_string_list(GROUP, SENT_MAIL_FOLDER_KEY, (this.sent_mail_folder_path != null
+ ? this.sent_mail_folder_path.as_list().to_array() : new string[] {}));
+ key_file.set_string_list(GROUP, SPAM_FOLDER_KEY, (this.spam_folder_path != null
+ ? this.spam_folder_path.as_list().to_array() : new string[] {}));
+ key_file.set_string_list(GROUP, TRASH_FOLDER_KEY, (this.trash_folder_path != null
+ ? this.trash_folder_path.as_list().to_array() : new string[] {}));
+ key_file.set_string_list(GROUP, ARCHIVE_FOLDER_KEY, (this.archive_folder_path != null
+ ? this.archive_folder_path.as_list().to_array() : new string[] {}));
+
+ key_file.set_boolean(GROUP, SAVE_DRAFTS_KEY, this.save_drafts);
+
string data = key_file.to_data();
string new_etag;
-
+
try {
yield file.replace_contents_async(data.data, null, false, FileCreateFlags.NONE,
cancellable, out new_etag);
@@ -924,21 +929,22 @@ public class Geary.AccountInformation : BaseObject {
}
/**
- * Returns a MailboxAddress object for this account.
- */
- public RFC822.MailboxAddress get_primary_mailbox_address() {
- return new RFC822.MailboxAddress(real_name, email);
- }
-
- /**
- * Returns MailboxAddresses with the primary mailbox address.
+ * Determines if this account contains a specific email address.
*
- * @see get_primary_mailbox_address
+ * Returns true if the address part of `email` is equal to (case
+ * insensitive) the address part of this account's primary mailbox
+ * or any of its secondary mailboxes.
*/
- public RFC822.MailboxAddresses get_primary_from() {
- return new RFC822.MailboxAddresses.single(get_primary_mailbox_address());
+ public bool has_email_address(Geary.RFC822.MailboxAddress email) {
+ return (
+ this.primary_mailbox.equal_to(email) ||
+ (this.alternate_mailboxes != null &&
+ this.alternate_mailboxes.fold<bool>((alt) => {
+ return alt.equal_to(email);
+ }, false))
+ );
}
-
+
public static int compare_ascending(AccountInformation a, AccountInformation b) {
int diff = a.ordinal - b.ordinal;
if (diff != 0)
diff --git a/src/engine/api/geary-engine.vala b/src/engine/api/geary-engine.vala
index 462bd9f..924f2a7 100644
--- a/src/engine/api/geary-engine.vala
+++ b/src/engine/api/geary-engine.vala
@@ -222,7 +222,25 @@ public class Geary.Engine : BaseObject {
}
/**
- * Returns the current accounts list as a map keyed by email address.
+ * Returns a current account given its id.
+ *
+ * Throws an error if the engine has not been opened or if the
+ * requested account does not exist.
+ */
+ public AccountInformation get_account(string id) throws Error {
+ check_opened();
+
+ AccountInformation? info = accounts.get(id);
+ if (info == null) {
+ throw new EngineError.NOT_FOUND("No such account: %s", id);
+ }
+ return info;
+ }
+
+ /**
+ * Returns the current accounts list as a map keyed by account id.
+ *
+ * Throws an error if the engine has not been opened.
*/
public Gee.Map<string, AccountInformation> get_accounts() throws Error {
check_opened();
@@ -231,18 +249,18 @@ public class Geary.Engine : BaseObject {
}
/**
- * Returns a new account for the given email address not yet stored on disk.
+ * Returns a new account for the given account id not yet stored on disk.
*/
- public AccountInformation create_orphan_account(string email) throws Error {
+ public AccountInformation create_orphan_account(string id) throws Error {
check_opened();
- if (accounts.has_key(email))
- throw new EngineError.ALREADY_EXISTS("Account %s already exists", email);
+ if (accounts.has_key(id))
+ throw new EngineError.ALREADY_EXISTS("Account %s already exists", id);
- return new AccountInformation.from_file(user_config_dir.get_child(email),
- user_data_dir.get_child(email));
+ return new AccountInformation.from_file(user_config_dir.get_child(id),
+ user_data_dir.get_child(id));
}
-
+
/**
* Returns whether the account information "validates." If validate_connection is true,
* we check if we can connect to the endpoints and authenticate using the supplied credentials.
@@ -255,11 +273,15 @@ public class Geary.Engine : BaseObject {
// Make sure the account nickname and email is not in use.
foreach (AccountInformation a in get_accounts().values) {
- if (account.email != a.email && Geary.String.stri_equal(account.nickname, a.nickname))
+ // Don't need to check a's alternate_emails since they
+ // can't be set at account creation time
+ bool has_email = account.has_email_address(a.primary_mailbox);
+
+ if (!has_email && Geary.String.stri_equal(account.nickname, a.nickname))
error_code |= ValidationResult.INVALID_NICKNAME;
-
+
// if creating a new Account, don't allow an existing email address
- if (!options.is_all_set(ValidationOption.UPDATING_EXISTING) && account.email == a.email)
+ if (!options.is_all_set(ValidationOption.UPDATING_EXISTING) && has_email)
error_code |= ValidationResult.EMAIL_EXISTS;
}
@@ -335,43 +357,43 @@ public class Geary.Engine : BaseObject {
public Geary.Account get_account_instance(AccountInformation account_information)
throws Error {
check_opened();
-
- if (account_instances.has_key(account_information.email))
- return account_instances.get(account_information.email);
-
+
+ if (account_instances.has_key(account_information.id))
+ return account_instances.get(account_information.id);
+
ImapDB.Account local_account = new ImapDB.Account(account_information);
Imap.Account remote_account = new Imap.Account(account_information);
-
+
Geary.Account account;
switch (account_information.service_provider) {
case ServiceProvider.GMAIL:
- account = new ImapEngine.GmailAccount("Gmail:%s".printf(account_information.email),
+ account = new ImapEngine.GmailAccount("Gmail:%s".printf(account_information.id),
account_information, remote_account, local_account);
break;
-
+
case ServiceProvider.YAHOO:
- account = new ImapEngine.YahooAccount("Yahoo:%s".printf(account_information.email),
+ account = new ImapEngine.YahooAccount("Yahoo:%s".printf(account_information.id),
account_information, remote_account, local_account);
break;
-
+
case ServiceProvider.OUTLOOK:
- account = new ImapEngine.OutlookAccount("Outlook:%s".printf(account_information.email),
+ account = new ImapEngine.OutlookAccount("Outlook:%s".printf(account_information.id),
account_information, remote_account, local_account);
break;
-
+
case ServiceProvider.OTHER:
- account = new ImapEngine.OtherAccount("Other:%s".printf(account_information.email),
+ account = new ImapEngine.OtherAccount("Other:%s".printf(account_information.id),
account_information, remote_account, local_account);
break;
-
+
default:
assert_not_reached();
}
-
- account_instances.set(account_information.email, account);
+
+ account_instances.set(account_information.id, account);
return account;
}
-
+
/**
* Adds the account to be tracked by the engine. Should only be called from
* AccountInformation.store_async() and this class.
@@ -379,9 +401,9 @@ public class Geary.Engine : BaseObject {
internal void add_account(AccountInformation account, bool created = false) throws Error {
check_opened();
- bool already_added = accounts.has_key(account.email);
+ bool already_added = accounts.has_key(account.id);
- accounts.set(account.email, account);
+ accounts.set(account.id, account);
if (!already_added) {
account.untrusted_host.connect(on_untrusted_host);
@@ -401,14 +423,14 @@ public class Geary.Engine : BaseObject {
check_opened();
// Ensure account is closed.
- if (account_instances.has_key(account.email) && account_instances.get(account.email).is_open()) {
+ if (account_instances.has_key(account.id) && account_instances.get(account.id).is_open()) {
throw new EngineError.CLOSE_REQUIRED("Account %s must be closed before removal",
- account.email);
+ account.id);
}
-
- if (accounts.unset(account.email)) {
+
+ if (accounts.unset(account.id)) {
account.untrusted_host.disconnect(on_untrusted_host);
-
+
// Removal *MUST* be done in the following order:
// 1. Send the account-unavailable signal.
account_unavailable(account);
@@ -420,10 +442,10 @@ public class Geary.Engine : BaseObject {
account_removed(account);
// 4. Remove the account data from the engine.
- account_instances.unset(account.email);
+ account_instances.unset(account.id);
}
}
-
+
private void on_untrusted_host(AccountInformation account_information, Endpoint endpoint,
Endpoint.SecurityType security, TlsConnection cx, Service service) {
untrusted_host(account_information, endpoint, security, cx, service);
diff --git a/src/engine/imap-db/imap-db-account.vala b/src/engine/imap-db/imap-db-account.vala
index 75f75b3..3078648 100644
--- a/src/engine/imap-db/imap-db-account.vala
+++ b/src/engine/imap-db/imap-db-account.vala
@@ -261,7 +261,7 @@ private class Geary.ImapDB.Account : BaseObject {
throw new EngineError.ALREADY_OPEN("IMAP database already open");
db = new ImapDB.Database(user_data_dir, schema_dir, upgrade_monitor, vacuum_monitor,
- account_information.email);
+ account_information.primary_mailbox.address);
try {
yield db.open_async(
@@ -797,7 +797,7 @@ private class Geary.ImapDB.Account : BaseObject {
}
// create folder
- folder = new Geary.ImapDB.Folder(db, path, contact_store, account_information.email, folder_id,
+ folder = new Geary.ImapDB.Folder(db, path, contact_store,
account_information.primary_mailbox.address, folder_id,
properties);
// build a reference to it
@@ -898,10 +898,12 @@ private class Geary.ImapDB.Account : BaseObject {
}
} else if (field == SEARCH_OP_FROM &&
parts[1].down() in search_op_from_me_values) {
- token = account_information.email;
+ // Search for all addresses on the account. Bug 768779
+ token = account_information.primary_mailbox.address;
} else if (field in SEARCH_OP_TO_ME_FIELDS &&
parts[1].down() in search_op_to_me_values) {
- token = account_information.email;
+ // Search for all addresses on the account. Bug 768779
+ token = account_information.primary_mailbox.address;
} else if (field != null) {
token = parts[1];
}
@@ -1580,7 +1582,7 @@ private class Geary.ImapDB.Account : BaseObject {
}
private async void populate_search_table_async(Cancellable? cancellable) {
- debug("%s: Populating search table", account_information.email);
+ debug("%s: Populating search table", account_information.id);
try {
while (!yield populate_search_table_batch_async(50, cancellable)) {
// With multiple accounts, meaning multiple background threads
@@ -1591,13 +1593,13 @@ private class Geary.ImapDB.Account : BaseObject {
yield Geary.Scheduler.sleep_ms_async(50);
}
} catch (Error e) {
- debug("Error populating %s search table: %s", account_information.email, e.message);
+ debug("Error populating %s search table: %s", account_information.id, e.message);
}
if (search_index_monitor.is_in_progress)
search_index_monitor.notify_finish();
- debug("%s: Done populating search table", account_information.email);
+ debug("%s: Done populating search table", account_information.id);
}
private static Gee.HashSet<int64?> do_build_rowid_set(Db.Result result, Cancellable? cancellable)
@@ -1614,7 +1616,7 @@ private class Geary.ImapDB.Account : BaseObject {
private async bool populate_search_table_batch_async(int limit, Cancellable? cancellable)
throws Error {
- debug("%s: Searching for up to %d missing indexed messages...", account_information.email,
+ debug("%s: Searching for up to %d missing indexed messages...", account_information.id,
limit);
int count = 0, total_unindexed = 0;
@@ -1685,7 +1687,7 @@ private class Geary.ImapDB.Account : BaseObject {
if (count > 0) {
debug("%s: Found %d/%d missing indexed messages, %d remaining...",
- account_information.email, count, limit, total_unindexed);
+ account_information.id, count, limit, total_unindexed);
if (!search_index_monitor.is_in_progress) {
search_index_monitor.set_interval(0, total_unindexed);
diff --git a/src/engine/imap-db/imap-db-database.vala b/src/engine/imap-db/imap-db-database.vala
index 8fff480..3e2b50a 100644
--- a/src/engine/imap-db/imap-db-database.vala
+++ b/src/engine/imap-db/imap-db-database.vala
@@ -22,6 +22,8 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase {
this.upgrade_monitor = upgrade_monitor;
this.vacuum_monitor = vacuum_monitor;
+
+ // Update to use all addresses on the account. Bug 768779
this.account_owner_email = account_owner_email;
}
diff --git a/src/engine/imap-db/imap-db-folder.vala b/src/engine/imap-db/imap-db-folder.vala
index a38318d..81e963a 100644
--- a/src/engine/imap-db/imap-db-folder.vala
+++ b/src/engine/imap-db/imap-db-folder.vala
@@ -100,6 +100,7 @@ private class Geary.ImapDB.Folder : BaseObject, Geary.ReferenceSemantics {
this.db = db;
this.path = path;
this.contact_store = contact_store;
+ // Update to use all addresses on the account. Bug 768779
this.account_owner_email = account_owner_email;
this.folder_id = folder_id;
this.properties = properties;
diff --git a/src/engine/imap-db/outbox/smtp-outbox-folder.vala
b/src/engine/imap-db/outbox/smtp-outbox-folder.vala
index da79dbc..7c38aac 100644
--- a/src/engine/imap-db/outbox/smtp-outbox-folder.vala
+++ b/src/engine/imap-db/outbox/smtp-outbox-folder.vala
@@ -634,7 +634,7 @@ private class Geary.SmtpOutboxFolder : Geary.AbstractLocalFolder, Geary.FolderSu
if (smtp_err == null) {
try {
- yield smtp.send_email_async(_account.information.get_primary_mailbox_address(),
+ yield smtp.send_email_async(_account.information.primary_mailbox,
rfc822, cancellable);
} catch (Error send_err) {
debug("SMTP send mail error: %s", send_err.message);
diff --git a/src/engine/imap-engine/imap-engine.vala b/src/engine/imap-engine/imap-engine.vala
index 967d778..c5b2fd4 100644
--- a/src/engine/imap-engine/imap-engine.vala
+++ b/src/engine/imap-engine/imap-engine.vala
@@ -24,7 +24,7 @@ private GenericAccount? get_imap_account(AccountInformation account_info) {
try {
return Engine.instance.get_account_instance(account_info) as GenericAccount;
} catch (Error err) {
- debug("Unable to get account instance %s: %s", account_info.email, err.message);
+ debug("Unable to get account instance %s: %s", account_info.id, err.message);
}
return null;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]