2013-04-12 12:31:58 -07:00
|
|
|
/* Copyright 2011-2013 Yorba Foundation
|
2011-06-16 16:27:08 -07:00
|
|
|
*
|
|
|
|
|
* This software is licensed under the GNU Lesser General Public License
|
2013-04-12 12:31:58 -07:00
|
|
|
* (version 2.1 or later). See the COPYING file in this distribution.
|
2011-06-16 16:27:08 -07:00
|
|
|
*/
|
|
|
|
|
|
2012-08-27 12:08:58 -07:00
|
|
|
private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
|
2013-03-19 12:12:28 -07:00
|
|
|
private const int REFRESH_FOLDER_LIST_SEC = 10 * 60;
|
2013-02-25 20:18:37 -08:00
|
|
|
|
2012-06-22 14:42:51 -07:00
|
|
|
private static Geary.FolderPath? inbox_path = null;
|
|
|
|
|
private static Geary.FolderPath? outbox_path = null;
|
|
|
|
|
|
2012-03-14 11:05:32 -07:00
|
|
|
private Imap.Account remote;
|
Remove SQLHeavy: Closes #5034
It is done.
Initial implementation of the new database subsystem
These pieces represent the foundation for ticket #5034
Expanded transactions, added VersionedDatabase
Further expansions of the async code.
Moved async pool logic into Database, where it realistically
belongs.
Further improvements. Introduced geary-db-test.
Added SQL create and update files for Geary.Db
version-001 to version-003 are exact copies of the SQLHeavy scripts
to ensure no slight changes when migrating. version-004 upgrades
the database to remove the ImapFolderPropertiesTable and
ImapMessagePropertiesTable, now that the database code is pure
IMAP.
When we support other messaging systems (such as POP3), those
subsystems will need to code their own database layers OR rely on
the IMAP schema and simply ignore the IMAP-specific fields.
ImapDB.Account fleshed out
ImapDB.Folder is commented out, however. Need to port next.
ImapDB.Folder fleshed out
MessageTable, MessageLocationTable, and AttachementTable are now
handled inside ImapDB.Folder.
chmod -x imap-db-database.vala
OutboxEmailIdentifier/Properties -> SmtpOutboxEmailIdentifier/Properties
Moved SmtpOutboxFolderRoot into its own source file
SmtpOutboxFolder ported to new database code
Move Engine implementations to ImapDB.
Integration and cleanup of new database code with main source
This commit performs the final integration steps to move Geary
completely over to the new database model. This also cleans out
the old SQLHeavy-based code and fixes a handful of small bugs that
were detected during basic test runs.
Moved Outbox to ImapDB
As the Outbox is tied to the database that ImapDB runs, move the
Outbox code into that folder.
Outbox fixes and better parameter checking
Bumped Database thread pool count and made them exclusive
My reasoning is that there may be a need for a lot of threads at
once (when a big batch of commands comes in, especially at
startup). If performance looks ok, we might consider relaxing
this later.
2012-06-14 14:47:53 -07:00
|
|
|
private ImapDB.Account local;
|
|
|
|
|
private bool open = false;
|
2012-05-10 20:28:42 -07:00
|
|
|
private Gee.HashMap<FolderPath, Imap.FolderProperties> properties_map = new Gee.HashMap<
|
|
|
|
|
FolderPath, Imap.FolderProperties>(Hashable.hash_func, Equalable.equal_func);
|
2012-07-17 16:34:08 -07:00
|
|
|
private Gee.HashMap<FolderPath, GenericFolder> existing_folders = new Gee.HashMap<
|
|
|
|
|
FolderPath, GenericFolder>(Hashable.hash_func, Equalable.equal_func);
|
2013-01-17 12:50:30 -08:00
|
|
|
private Gee.HashMap<FolderPath, Folder> local_only = new Gee.HashMap<FolderPath, Folder>(
|
2012-06-22 14:42:51 -07:00
|
|
|
Hashable.hash_func, Equalable.equal_func);
|
2013-02-25 20:18:37 -08:00
|
|
|
private uint refresh_folder_timeout_id = 0;
|
|
|
|
|
private bool in_refresh_enumerate = false;
|
|
|
|
|
private Cancellable refresh_cancellable = new Cancellable();
|
2011-06-16 16:27:08 -07:00
|
|
|
|
2013-01-31 15:17:44 -08:00
|
|
|
public GenericAccount(string name, Geary.AccountInformation information, Imap.Account remote,
|
Remove SQLHeavy: Closes #5034
It is done.
Initial implementation of the new database subsystem
These pieces represent the foundation for ticket #5034
Expanded transactions, added VersionedDatabase
Further expansions of the async code.
Moved async pool logic into Database, where it realistically
belongs.
Further improvements. Introduced geary-db-test.
Added SQL create and update files for Geary.Db
version-001 to version-003 are exact copies of the SQLHeavy scripts
to ensure no slight changes when migrating. version-004 upgrades
the database to remove the ImapFolderPropertiesTable and
ImapMessagePropertiesTable, now that the database code is pure
IMAP.
When we support other messaging systems (such as POP3), those
subsystems will need to code their own database layers OR rely on
the IMAP schema and simply ignore the IMAP-specific fields.
ImapDB.Account fleshed out
ImapDB.Folder is commented out, however. Need to port next.
ImapDB.Folder fleshed out
MessageTable, MessageLocationTable, and AttachementTable are now
handled inside ImapDB.Folder.
chmod -x imap-db-database.vala
OutboxEmailIdentifier/Properties -> SmtpOutboxEmailIdentifier/Properties
Moved SmtpOutboxFolderRoot into its own source file
SmtpOutboxFolder ported to new database code
Move Engine implementations to ImapDB.
Integration and cleanup of new database code with main source
This commit performs the final integration steps to move Geary
completely over to the new database model. This also cleans out
the old SQLHeavy-based code and fixes a handful of small bugs that
were detected during basic test runs.
Moved Outbox to ImapDB
As the Outbox is tied to the database that ImapDB runs, move the
Outbox code into that folder.
Outbox fixes and better parameter checking
Bumped Database thread pool count and made them exclusive
My reasoning is that there may be a need for a lot of threads at
once (when a big batch of commands comes in, especially at
startup). If performance looks ok, we might consider relaxing
this later.
2012-06-14 14:47:53 -07:00
|
|
|
ImapDB.Account local) {
|
2013-01-31 15:17:44 -08:00
|
|
|
base (name, information);
|
2011-07-01 15:40:20 -07:00
|
|
|
|
2011-06-23 19:07:04 -07:00
|
|
|
this.remote = remote;
|
2011-06-16 16:27:08 -07:00
|
|
|
this.local = local;
|
2011-07-01 19:33:35 -07:00
|
|
|
|
2012-03-14 11:05:32 -07:00
|
|
|
this.remote.login_failed.connect(on_login_failed);
|
2012-06-25 16:30:23 -07:00
|
|
|
this.remote.email_sent.connect(on_email_sent);
|
2012-06-22 14:42:51 -07:00
|
|
|
|
|
|
|
|
if (inbox_path == null) {
|
|
|
|
|
inbox_path = new Geary.FolderRoot(Imap.Account.INBOX_NAME, Imap.Account.ASSUMED_SEPARATOR,
|
|
|
|
|
Imap.Folder.CASE_SENSITIVE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (outbox_path == null) {
|
|
|
|
|
outbox_path = new SmtpOutboxFolderRoot();
|
|
|
|
|
}
|
2011-06-16 16:27:08 -07:00
|
|
|
}
|
|
|
|
|
|
2012-05-10 20:28:42 -07:00
|
|
|
internal Imap.FolderProperties? get_properties_for_folder(FolderPath path) {
|
|
|
|
|
return properties_map.get(path);
|
|
|
|
|
}
|
|
|
|
|
|
Remove SQLHeavy: Closes #5034
It is done.
Initial implementation of the new database subsystem
These pieces represent the foundation for ticket #5034
Expanded transactions, added VersionedDatabase
Further expansions of the async code.
Moved async pool logic into Database, where it realistically
belongs.
Further improvements. Introduced geary-db-test.
Added SQL create and update files for Geary.Db
version-001 to version-003 are exact copies of the SQLHeavy scripts
to ensure no slight changes when migrating. version-004 upgrades
the database to remove the ImapFolderPropertiesTable and
ImapMessagePropertiesTable, now that the database code is pure
IMAP.
When we support other messaging systems (such as POP3), those
subsystems will need to code their own database layers OR rely on
the IMAP schema and simply ignore the IMAP-specific fields.
ImapDB.Account fleshed out
ImapDB.Folder is commented out, however. Need to port next.
ImapDB.Folder fleshed out
MessageTable, MessageLocationTable, and AttachementTable are now
handled inside ImapDB.Folder.
chmod -x imap-db-database.vala
OutboxEmailIdentifier/Properties -> SmtpOutboxEmailIdentifier/Properties
Moved SmtpOutboxFolderRoot into its own source file
SmtpOutboxFolder ported to new database code
Move Engine implementations to ImapDB.
Integration and cleanup of new database code with main source
This commit performs the final integration steps to move Geary
completely over to the new database model. This also cleans out
the old SQLHeavy-based code and fixes a handful of small bugs that
were detected during basic test runs.
Moved Outbox to ImapDB
As the Outbox is tied to the database that ImapDB runs, move the
Outbox code into that folder.
Outbox fixes and better parameter checking
Bumped Database thread pool count and made them exclusive
My reasoning is that there may be a need for a lot of threads at
once (when a big batch of commands comes in, especially at
startup). If performance looks ok, we might consider relaxing
this later.
2012-06-14 14:47:53 -07:00
|
|
|
private void check_open() throws EngineError {
|
|
|
|
|
if (!open)
|
|
|
|
|
throw new EngineError.OPEN_REQUIRED("Account %s not opened", to_string());
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-11 12:03:57 -07:00
|
|
|
public override async void open_async(Cancellable? cancellable = null) throws Error {
|
Remove SQLHeavy: Closes #5034
It is done.
Initial implementation of the new database subsystem
These pieces represent the foundation for ticket #5034
Expanded transactions, added VersionedDatabase
Further expansions of the async code.
Moved async pool logic into Database, where it realistically
belongs.
Further improvements. Introduced geary-db-test.
Added SQL create and update files for Geary.Db
version-001 to version-003 are exact copies of the SQLHeavy scripts
to ensure no slight changes when migrating. version-004 upgrades
the database to remove the ImapFolderPropertiesTable and
ImapMessagePropertiesTable, now that the database code is pure
IMAP.
When we support other messaging systems (such as POP3), those
subsystems will need to code their own database layers OR rely on
the IMAP schema and simply ignore the IMAP-specific fields.
ImapDB.Account fleshed out
ImapDB.Folder is commented out, however. Need to port next.
ImapDB.Folder fleshed out
MessageTable, MessageLocationTable, and AttachementTable are now
handled inside ImapDB.Folder.
chmod -x imap-db-database.vala
OutboxEmailIdentifier/Properties -> SmtpOutboxEmailIdentifier/Properties
Moved SmtpOutboxFolderRoot into its own source file
SmtpOutboxFolder ported to new database code
Move Engine implementations to ImapDB.
Integration and cleanup of new database code with main source
This commit performs the final integration steps to move Geary
completely over to the new database model. This also cleans out
the old SQLHeavy-based code and fixes a handful of small bugs that
were detected during basic test runs.
Moved Outbox to ImapDB
As the Outbox is tied to the database that ImapDB runs, move the
Outbox code into that folder.
Outbox fixes and better parameter checking
Bumped Database thread pool count and made them exclusive
My reasoning is that there may be a need for a lot of threads at
once (when a big batch of commands comes in, especially at
startup). If performance looks ok, we might consider relaxing
this later.
2012-06-14 14:47:53 -07:00
|
|
|
if (open)
|
|
|
|
|
throw new EngineError.ALREADY_OPEN("Account %s already opened", to_string());
|
|
|
|
|
|
2013-03-15 12:59:56 -07:00
|
|
|
// To prevent spurious connection failures, we make sure we have the
|
|
|
|
|
// IMAP password before attempting a connection. This might have to be
|
|
|
|
|
// reworked when we allow passwordless logins.
|
|
|
|
|
if (!information.imap_credentials.is_complete())
|
|
|
|
|
yield information.fetch_passwords_async(Geary.CredentialsMediator.ServiceFlag.IMAP);
|
|
|
|
|
|
2013-01-31 15:17:44 -08:00
|
|
|
yield local.open_async(information.settings_dir, Engine.instance.resource_dir.get_child("sql"), cancellable);
|
2012-08-27 12:08:58 -07:00
|
|
|
|
|
|
|
|
// outbox is now available
|
|
|
|
|
local.outbox.report_problem.connect(notify_report_problem);
|
2013-01-17 12:50:30 -08:00
|
|
|
local_only.set(outbox_path, local.outbox);
|
2012-06-11 12:03:57 -07:00
|
|
|
|
|
|
|
|
// need to back out local.open_async() if remote fails
|
|
|
|
|
try {
|
|
|
|
|
yield remote.open_async(cancellable);
|
|
|
|
|
} catch (Error err) {
|
|
|
|
|
// back out
|
|
|
|
|
try {
|
|
|
|
|
yield local.close_async(cancellable);
|
|
|
|
|
} catch (Error close_err) {
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw err;
|
|
|
|
|
}
|
|
|
|
|
|
Remove SQLHeavy: Closes #5034
It is done.
Initial implementation of the new database subsystem
These pieces represent the foundation for ticket #5034
Expanded transactions, added VersionedDatabase
Further expansions of the async code.
Moved async pool logic into Database, where it realistically
belongs.
Further improvements. Introduced geary-db-test.
Added SQL create and update files for Geary.Db
version-001 to version-003 are exact copies of the SQLHeavy scripts
to ensure no slight changes when migrating. version-004 upgrades
the database to remove the ImapFolderPropertiesTable and
ImapMessagePropertiesTable, now that the database code is pure
IMAP.
When we support other messaging systems (such as POP3), those
subsystems will need to code their own database layers OR rely on
the IMAP schema and simply ignore the IMAP-specific fields.
ImapDB.Account fleshed out
ImapDB.Folder is commented out, however. Need to port next.
ImapDB.Folder fleshed out
MessageTable, MessageLocationTable, and AttachementTable are now
handled inside ImapDB.Folder.
chmod -x imap-db-database.vala
OutboxEmailIdentifier/Properties -> SmtpOutboxEmailIdentifier/Properties
Moved SmtpOutboxFolderRoot into its own source file
SmtpOutboxFolder ported to new database code
Move Engine implementations to ImapDB.
Integration and cleanup of new database code with main source
This commit performs the final integration steps to move Geary
completely over to the new database model. This also cleans out
the old SQLHeavy-based code and fixes a handful of small bugs that
were detected during basic test runs.
Moved Outbox to ImapDB
As the Outbox is tied to the database that ImapDB runs, move the
Outbox code into that folder.
Outbox fixes and better parameter checking
Bumped Database thread pool count and made them exclusive
My reasoning is that there may be a need for a lot of threads at
once (when a big batch of commands comes in, especially at
startup). If performance looks ok, we might consider relaxing
this later.
2012-06-14 14:47:53 -07:00
|
|
|
open = true;
|
2012-06-11 12:03:57 -07:00
|
|
|
|
|
|
|
|
notify_opened();
|
2013-01-17 12:50:30 -08:00
|
|
|
|
|
|
|
|
notify_folders_available_unavailable(local_only.values, null);
|
2013-02-25 20:18:37 -08:00
|
|
|
|
|
|
|
|
// schedule an immediate sweep of the folders; once this is finished, folders will be
|
|
|
|
|
// regularly enumerated
|
|
|
|
|
reschedule_folder_refresh(true);
|
2012-06-11 12:03:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override async void close_async(Cancellable? cancellable = null) throws Error {
|
Remove SQLHeavy: Closes #5034
It is done.
Initial implementation of the new database subsystem
These pieces represent the foundation for ticket #5034
Expanded transactions, added VersionedDatabase
Further expansions of the async code.
Moved async pool logic into Database, where it realistically
belongs.
Further improvements. Introduced geary-db-test.
Added SQL create and update files for Geary.Db
version-001 to version-003 are exact copies of the SQLHeavy scripts
to ensure no slight changes when migrating. version-004 upgrades
the database to remove the ImapFolderPropertiesTable and
ImapMessagePropertiesTable, now that the database code is pure
IMAP.
When we support other messaging systems (such as POP3), those
subsystems will need to code their own database layers OR rely on
the IMAP schema and simply ignore the IMAP-specific fields.
ImapDB.Account fleshed out
ImapDB.Folder is commented out, however. Need to port next.
ImapDB.Folder fleshed out
MessageTable, MessageLocationTable, and AttachementTable are now
handled inside ImapDB.Folder.
chmod -x imap-db-database.vala
OutboxEmailIdentifier/Properties -> SmtpOutboxEmailIdentifier/Properties
Moved SmtpOutboxFolderRoot into its own source file
SmtpOutboxFolder ported to new database code
Move Engine implementations to ImapDB.
Integration and cleanup of new database code with main source
This commit performs the final integration steps to move Geary
completely over to the new database model. This also cleans out
the old SQLHeavy-based code and fixes a handful of small bugs that
were detected during basic test runs.
Moved Outbox to ImapDB
As the Outbox is tied to the database that ImapDB runs, move the
Outbox code into that folder.
Outbox fixes and better parameter checking
Bumped Database thread pool count and made them exclusive
My reasoning is that there may be a need for a lot of threads at
once (when a big batch of commands comes in, especially at
startup). If performance looks ok, we might consider relaxing
this later.
2012-06-14 14:47:53 -07:00
|
|
|
if (!open)
|
|
|
|
|
return;
|
2013-01-17 12:50:30 -08:00
|
|
|
|
|
|
|
|
notify_folders_available_unavailable(null, local_only.values);
|
|
|
|
|
notify_folders_available_unavailable(null, existing_folders.values);
|
Remove SQLHeavy: Closes #5034
It is done.
Initial implementation of the new database subsystem
These pieces represent the foundation for ticket #5034
Expanded transactions, added VersionedDatabase
Further expansions of the async code.
Moved async pool logic into Database, where it realistically
belongs.
Further improvements. Introduced geary-db-test.
Added SQL create and update files for Geary.Db
version-001 to version-003 are exact copies of the SQLHeavy scripts
to ensure no slight changes when migrating. version-004 upgrades
the database to remove the ImapFolderPropertiesTable and
ImapMessagePropertiesTable, now that the database code is pure
IMAP.
When we support other messaging systems (such as POP3), those
subsystems will need to code their own database layers OR rely on
the IMAP schema and simply ignore the IMAP-specific fields.
ImapDB.Account fleshed out
ImapDB.Folder is commented out, however. Need to port next.
ImapDB.Folder fleshed out
MessageTable, MessageLocationTable, and AttachementTable are now
handled inside ImapDB.Folder.
chmod -x imap-db-database.vala
OutboxEmailIdentifier/Properties -> SmtpOutboxEmailIdentifier/Properties
Moved SmtpOutboxFolderRoot into its own source file
SmtpOutboxFolder ported to new database code
Move Engine implementations to ImapDB.
Integration and cleanup of new database code with main source
This commit performs the final integration steps to move Geary
completely over to the new database model. This also cleans out
the old SQLHeavy-based code and fixes a handful of small bugs that
were detected during basic test runs.
Moved Outbox to ImapDB
As the Outbox is tied to the database that ImapDB runs, move the
Outbox code into that folder.
Outbox fixes and better parameter checking
Bumped Database thread pool count and made them exclusive
My reasoning is that there may be a need for a lot of threads at
once (when a big batch of commands comes in, especially at
startup). If performance looks ok, we might consider relaxing
this later.
2012-06-14 14:47:53 -07:00
|
|
|
|
2012-08-27 12:08:58 -07:00
|
|
|
local.outbox.report_problem.disconnect(notify_report_problem);
|
|
|
|
|
|
2012-06-11 12:03:57 -07:00
|
|
|
// attempt to close both regardless of errors
|
|
|
|
|
Error? local_err = null;
|
|
|
|
|
try {
|
|
|
|
|
yield local.close_async(cancellable);
|
|
|
|
|
} catch (Error lclose_err) {
|
|
|
|
|
local_err = lclose_err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Error? remote_err = null;
|
|
|
|
|
try {
|
|
|
|
|
yield remote.close_async(cancellable);
|
|
|
|
|
} catch (Error rclose_err) {
|
|
|
|
|
remote_err = rclose_err;
|
|
|
|
|
}
|
2013-01-17 12:50:30 -08:00
|
|
|
|
|
|
|
|
properties_map.clear();
|
|
|
|
|
existing_folders.clear();
|
|
|
|
|
local_only.clear();
|
2013-02-04 19:26:48 -08:00
|
|
|
open = false;
|
2012-06-11 12:03:57 -07:00
|
|
|
|
|
|
|
|
if (local_err != null)
|
|
|
|
|
throw local_err;
|
|
|
|
|
|
|
|
|
|
if (remote_err != null)
|
|
|
|
|
throw remote_err;
|
2011-06-23 19:07:04 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-04 19:26:48 -08:00
|
|
|
public override bool is_open() {
|
|
|
|
|
return open;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-17 16:34:08 -07:00
|
|
|
// Subclasses should implement this to return their flavor of a GenericFolder with the
|
2012-06-27 18:25:45 -07:00
|
|
|
// appropriate interfaces attached. The returned folder should have its SpecialFolderType
|
|
|
|
|
// set using either the properties from the local folder or its path.
|
2012-06-22 14:42:51 -07:00
|
|
|
//
|
2012-06-27 18:25:45 -07:00
|
|
|
// This won't be called to build the Outbox, but for all others (including Inbox) it will.
|
2012-07-17 16:34:08 -07:00
|
|
|
protected abstract GenericFolder new_folder(Geary.FolderPath path, Imap.Account remote_account,
|
Remove SQLHeavy: Closes #5034
It is done.
Initial implementation of the new database subsystem
These pieces represent the foundation for ticket #5034
Expanded transactions, added VersionedDatabase
Further expansions of the async code.
Moved async pool logic into Database, where it realistically
belongs.
Further improvements. Introduced geary-db-test.
Added SQL create and update files for Geary.Db
version-001 to version-003 are exact copies of the SQLHeavy scripts
to ensure no slight changes when migrating. version-004 upgrades
the database to remove the ImapFolderPropertiesTable and
ImapMessagePropertiesTable, now that the database code is pure
IMAP.
When we support other messaging systems (such as POP3), those
subsystems will need to code their own database layers OR rely on
the IMAP schema and simply ignore the IMAP-specific fields.
ImapDB.Account fleshed out
ImapDB.Folder is commented out, however. Need to port next.
ImapDB.Folder fleshed out
MessageTable, MessageLocationTable, and AttachementTable are now
handled inside ImapDB.Folder.
chmod -x imap-db-database.vala
OutboxEmailIdentifier/Properties -> SmtpOutboxEmailIdentifier/Properties
Moved SmtpOutboxFolderRoot into its own source file
SmtpOutboxFolder ported to new database code
Move Engine implementations to ImapDB.
Integration and cleanup of new database code with main source
This commit performs the final integration steps to move Geary
completely over to the new database model. This also cleans out
the old SQLHeavy-based code and fixes a handful of small bugs that
were detected during basic test runs.
Moved Outbox to ImapDB
As the Outbox is tied to the database that ImapDB runs, move the
Outbox code into that folder.
Outbox fixes and better parameter checking
Bumped Database thread pool count and made them exclusive
My reasoning is that there may be a need for a lot of threads at
once (when a big batch of commands comes in, especially at
startup). If performance looks ok, we might consider relaxing
this later.
2012-06-14 14:47:53 -07:00
|
|
|
ImapDB.Account local_account, ImapDB.Folder local_folder);
|
2012-06-22 14:42:51 -07:00
|
|
|
|
2012-07-17 16:34:08 -07:00
|
|
|
private GenericFolder build_folder(ImapDB.Folder local_folder) {
|
2013-01-17 12:50:30 -08:00
|
|
|
return Geary.Collection.get_first(build_folders(new Geary.Singleton<ImapDB.Folder>(local_folder)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Gee.Collection<GenericFolder> build_folders(Gee.Collection<ImapDB.Folder> local_folders) {
|
|
|
|
|
Gee.ArrayList<ImapDB.Folder> folders_to_build = new Gee.ArrayList<ImapDB.Folder>();
|
|
|
|
|
Gee.ArrayList<GenericFolder> built_folders = new Gee.ArrayList<GenericFolder>();
|
|
|
|
|
Gee.ArrayList<GenericFolder> return_folders = new Gee.ArrayList<GenericFolder>();
|
|
|
|
|
|
|
|
|
|
foreach(ImapDB.Folder local_folder in local_folders) {
|
|
|
|
|
if (existing_folders.has_key(local_folder.get_path()))
|
|
|
|
|
return_folders.add(existing_folders.get(local_folder.get_path()));
|
|
|
|
|
else
|
|
|
|
|
folders_to_build.add(local_folder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach(ImapDB.Folder folder_to_build in folders_to_build) {
|
|
|
|
|
GenericFolder folder = new_folder(folder_to_build.get_path(), remote, local, folder_to_build);
|
|
|
|
|
existing_folders.set(folder.get_path(), folder);
|
|
|
|
|
built_folders.add(folder);
|
|
|
|
|
return_folders.add(folder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (built_folders.size > 0)
|
|
|
|
|
notify_folders_available_unavailable(built_folders, null);
|
2013-02-25 20:18:37 -08:00
|
|
|
|
2013-01-17 12:50:30 -08:00
|
|
|
return return_folders;
|
2012-06-14 16:47:54 -07:00
|
|
|
}
|
|
|
|
|
|
2013-01-31 15:17:44 -08:00
|
|
|
public override Gee.Collection<Geary.Folder> list_matching_folders(
|
|
|
|
|
Geary.FolderPath? parent) throws Error {
|
|
|
|
|
check_open();
|
|
|
|
|
|
2013-01-17 12:50:30 -08:00
|
|
|
Gee.ArrayList<Geary.Folder> matches = new Gee.ArrayList<Geary.Folder>();
|
|
|
|
|
|
|
|
|
|
foreach(FolderPath path in existing_folders.keys) {
|
|
|
|
|
FolderPath? path_parent = path.get_parent();
|
|
|
|
|
if ((parent == null && path_parent == null) ||
|
|
|
|
|
(parent != null && path_parent != null && path_parent.equals(parent))) {
|
|
|
|
|
matches.add(existing_folders.get(path));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return matches;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-31 15:17:44 -08:00
|
|
|
public override Gee.Collection<Geary.Folder> list_folders() throws Error {
|
|
|
|
|
check_open();
|
2013-02-25 20:18:37 -08:00
|
|
|
|
2013-01-31 15:17:44 -08:00
|
|
|
return existing_folders.values;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-25 20:18:37 -08:00
|
|
|
private void reschedule_folder_refresh(bool immediate) {
|
|
|
|
|
if (in_refresh_enumerate)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
cancel_folder_refresh();
|
|
|
|
|
|
|
|
|
|
refresh_folder_timeout_id = immediate
|
|
|
|
|
? Idle.add(on_refresh_folders)
|
|
|
|
|
: Timeout.add_seconds(REFRESH_FOLDER_LIST_SEC, on_refresh_folders);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cancel_folder_refresh() {
|
|
|
|
|
if (refresh_folder_timeout_id != 0) {
|
|
|
|
|
Source.remove(refresh_folder_timeout_id);
|
|
|
|
|
refresh_folder_timeout_id = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool on_refresh_folders() {
|
|
|
|
|
in_refresh_enumerate = true;
|
|
|
|
|
enumerate_folders_async.begin(null, refresh_cancellable, on_refresh_completed);
|
|
|
|
|
|
|
|
|
|
refresh_folder_timeout_id = 0;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void on_refresh_completed(Object? source, AsyncResult result) {
|
|
|
|
|
try {
|
|
|
|
|
enumerate_folders_async.end(result);
|
|
|
|
|
} catch (Error err) {
|
|
|
|
|
if (!(err is IOError.CANCELLED))
|
|
|
|
|
debug("Refresh of account %s folders did not complete: %s", to_string(), err.message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
in_refresh_enumerate = false;
|
|
|
|
|
reschedule_folder_refresh(false);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-16 16:08:37 -07:00
|
|
|
private async void enumerate_folders_async(Geary.FolderPath? parent, Cancellable? cancellable = null)
|
2013-02-25 20:18:37 -08:00
|
|
|
throws Error {
|
Remove SQLHeavy: Closes #5034
It is done.
Initial implementation of the new database subsystem
These pieces represent the foundation for ticket #5034
Expanded transactions, added VersionedDatabase
Further expansions of the async code.
Moved async pool logic into Database, where it realistically
belongs.
Further improvements. Introduced geary-db-test.
Added SQL create and update files for Geary.Db
version-001 to version-003 are exact copies of the SQLHeavy scripts
to ensure no slight changes when migrating. version-004 upgrades
the database to remove the ImapFolderPropertiesTable and
ImapMessagePropertiesTable, now that the database code is pure
IMAP.
When we support other messaging systems (such as POP3), those
subsystems will need to code their own database layers OR rely on
the IMAP schema and simply ignore the IMAP-specific fields.
ImapDB.Account fleshed out
ImapDB.Folder is commented out, however. Need to port next.
ImapDB.Folder fleshed out
MessageTable, MessageLocationTable, and AttachementTable are now
handled inside ImapDB.Folder.
chmod -x imap-db-database.vala
OutboxEmailIdentifier/Properties -> SmtpOutboxEmailIdentifier/Properties
Moved SmtpOutboxFolderRoot into its own source file
SmtpOutboxFolder ported to new database code
Move Engine implementations to ImapDB.
Integration and cleanup of new database code with main source
This commit performs the final integration steps to move Geary
completely over to the new database model. This also cleans out
the old SQLHeavy-based code and fixes a handful of small bugs that
were detected during basic test runs.
Moved Outbox to ImapDB
As the Outbox is tied to the database that ImapDB runs, move the
Outbox code into that folder.
Outbox fixes and better parameter checking
Bumped Database thread pool count and made them exclusive
My reasoning is that there may be a need for a lot of threads at
once (when a big batch of commands comes in, especially at
startup). If performance looks ok, we might consider relaxing
this later.
2012-06-14 14:47:53 -07:00
|
|
|
check_open();
|
|
|
|
|
|
|
|
|
|
Gee.Collection<ImapDB.Folder>? local_list = null;
|
2011-07-01 15:40:20 -07:00
|
|
|
try {
|
|
|
|
|
local_list = yield local.list_folders_async(parent, cancellable);
|
|
|
|
|
} catch (EngineError err) {
|
|
|
|
|
// don't pass on NOT_FOUND's, that means we need to go to the server for more info
|
|
|
|
|
if (!(err is EngineError.NOT_FOUND))
|
|
|
|
|
throw err;
|
|
|
|
|
}
|
2011-06-16 16:27:08 -07:00
|
|
|
|
|
|
|
|
Gee.Collection<Geary.Folder> engine_list = new Gee.ArrayList<Geary.Folder>();
|
2011-07-01 15:40:20 -07:00
|
|
|
if (local_list != null && local_list.size > 0) {
|
2013-01-17 12:50:30 -08:00
|
|
|
engine_list.add_all(build_folders(local_list));
|
2011-07-01 15:40:20 -07:00
|
|
|
}
|
2011-06-16 16:27:08 -07:00
|
|
|
|
2013-01-17 12:50:30 -08:00
|
|
|
// Add local folders (assume that local-only folders always go in root)
|
2012-06-22 14:42:51 -07:00
|
|
|
if (parent == null)
|
2013-01-17 12:50:30 -08:00
|
|
|
engine_list.add_all(local_only.values);
|
2012-06-22 14:42:51 -07:00
|
|
|
|
2011-12-22 12:31:06 -08:00
|
|
|
background_update_folders.begin(parent, engine_list, cancellable);
|
2011-06-16 16:27:08 -07:00
|
|
|
}
|
|
|
|
|
|
2012-07-20 17:51:28 -07:00
|
|
|
public override Geary.ContactStore get_contact_store() {
|
|
|
|
|
return local.contact_store;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-04 13:54:00 -07:00
|
|
|
public override async bool folder_exists_async(Geary.FolderPath path,
|
|
|
|
|
Cancellable? cancellable = null) throws Error {
|
Remove SQLHeavy: Closes #5034
It is done.
Initial implementation of the new database subsystem
These pieces represent the foundation for ticket #5034
Expanded transactions, added VersionedDatabase
Further expansions of the async code.
Moved async pool logic into Database, where it realistically
belongs.
Further improvements. Introduced geary-db-test.
Added SQL create and update files for Geary.Db
version-001 to version-003 are exact copies of the SQLHeavy scripts
to ensure no slight changes when migrating. version-004 upgrades
the database to remove the ImapFolderPropertiesTable and
ImapMessagePropertiesTable, now that the database code is pure
IMAP.
When we support other messaging systems (such as POP3), those
subsystems will need to code their own database layers OR rely on
the IMAP schema and simply ignore the IMAP-specific fields.
ImapDB.Account fleshed out
ImapDB.Folder is commented out, however. Need to port next.
ImapDB.Folder fleshed out
MessageTable, MessageLocationTable, and AttachementTable are now
handled inside ImapDB.Folder.
chmod -x imap-db-database.vala
OutboxEmailIdentifier/Properties -> SmtpOutboxEmailIdentifier/Properties
Moved SmtpOutboxFolderRoot into its own source file
SmtpOutboxFolder ported to new database code
Move Engine implementations to ImapDB.
Integration and cleanup of new database code with main source
This commit performs the final integration steps to move Geary
completely over to the new database model. This also cleans out
the old SQLHeavy-based code and fixes a handful of small bugs that
were detected during basic test runs.
Moved Outbox to ImapDB
As the Outbox is tied to the database that ImapDB runs, move the
Outbox code into that folder.
Outbox fixes and better parameter checking
Bumped Database thread pool count and made them exclusive
My reasoning is that there may be a need for a lot of threads at
once (when a big batch of commands comes in, especially at
startup). If performance looks ok, we might consider relaxing
this later.
2012-06-14 14:47:53 -07:00
|
|
|
check_open();
|
|
|
|
|
|
2011-07-04 13:54:00 -07:00
|
|
|
if (yield local.folder_exists_async(path, cancellable))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return yield remote.folder_exists_async(path, cancellable);
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-21 19:17:05 -07:00
|
|
|
// TODO: This needs to be made into a single transaction
|
2011-07-01 15:40:20 -07:00
|
|
|
public override async Geary.Folder fetch_folder_async(Geary.FolderPath path,
|
2011-06-16 16:27:08 -07:00
|
|
|
Cancellable? cancellable = null) throws Error {
|
Remove SQLHeavy: Closes #5034
It is done.
Initial implementation of the new database subsystem
These pieces represent the foundation for ticket #5034
Expanded transactions, added VersionedDatabase
Further expansions of the async code.
Moved async pool logic into Database, where it realistically
belongs.
Further improvements. Introduced geary-db-test.
Added SQL create and update files for Geary.Db
version-001 to version-003 are exact copies of the SQLHeavy scripts
to ensure no slight changes when migrating. version-004 upgrades
the database to remove the ImapFolderPropertiesTable and
ImapMessagePropertiesTable, now that the database code is pure
IMAP.
When we support other messaging systems (such as POP3), those
subsystems will need to code their own database layers OR rely on
the IMAP schema and simply ignore the IMAP-specific fields.
ImapDB.Account fleshed out
ImapDB.Folder is commented out, however. Need to port next.
ImapDB.Folder fleshed out
MessageTable, MessageLocationTable, and AttachementTable are now
handled inside ImapDB.Folder.
chmod -x imap-db-database.vala
OutboxEmailIdentifier/Properties -> SmtpOutboxEmailIdentifier/Properties
Moved SmtpOutboxFolderRoot into its own source file
SmtpOutboxFolder ported to new database code
Move Engine implementations to ImapDB.
Integration and cleanup of new database code with main source
This commit performs the final integration steps to move Geary
completely over to the new database model. This also cleans out
the old SQLHeavy-based code and fixes a handful of small bugs that
were detected during basic test runs.
Moved Outbox to ImapDB
As the Outbox is tied to the database that ImapDB runs, move the
Outbox code into that folder.
Outbox fixes and better parameter checking
Bumped Database thread pool count and made them exclusive
My reasoning is that there may be a need for a lot of threads at
once (when a big batch of commands comes in, especially at
startup). If performance looks ok, we might consider relaxing
this later.
2012-06-14 14:47:53 -07:00
|
|
|
check_open();
|
2012-06-11 12:03:57 -07:00
|
|
|
|
2013-01-17 12:50:30 -08:00
|
|
|
if (local_only.has_key(path))
|
|
|
|
|
return local_only.get(path);
|
2012-06-11 12:03:57 -07:00
|
|
|
|
2011-07-04 13:54:00 -07:00
|
|
|
try {
|
Remove SQLHeavy: Closes #5034
It is done.
Initial implementation of the new database subsystem
These pieces represent the foundation for ticket #5034
Expanded transactions, added VersionedDatabase
Further expansions of the async code.
Moved async pool logic into Database, where it realistically
belongs.
Further improvements. Introduced geary-db-test.
Added SQL create and update files for Geary.Db
version-001 to version-003 are exact copies of the SQLHeavy scripts
to ensure no slight changes when migrating. version-004 upgrades
the database to remove the ImapFolderPropertiesTable and
ImapMessagePropertiesTable, now that the database code is pure
IMAP.
When we support other messaging systems (such as POP3), those
subsystems will need to code their own database layers OR rely on
the IMAP schema and simply ignore the IMAP-specific fields.
ImapDB.Account fleshed out
ImapDB.Folder is commented out, however. Need to port next.
ImapDB.Folder fleshed out
MessageTable, MessageLocationTable, and AttachementTable are now
handled inside ImapDB.Folder.
chmod -x imap-db-database.vala
OutboxEmailIdentifier/Properties -> SmtpOutboxEmailIdentifier/Properties
Moved SmtpOutboxFolderRoot into its own source file
SmtpOutboxFolder ported to new database code
Move Engine implementations to ImapDB.
Integration and cleanup of new database code with main source
This commit performs the final integration steps to move Geary
completely over to the new database model. This also cleans out
the old SQLHeavy-based code and fixes a handful of small bugs that
were detected during basic test runs.
Moved Outbox to ImapDB
As the Outbox is tied to the database that ImapDB runs, move the
Outbox code into that folder.
Outbox fixes and better parameter checking
Bumped Database thread pool count and made them exclusive
My reasoning is that there may be a need for a lot of threads at
once (when a big batch of commands comes in, especially at
startup). If performance looks ok, we might consider relaxing
this later.
2012-06-14 14:47:53 -07:00
|
|
|
return build_folder((ImapDB.Folder) yield local.fetch_folder_async(path, cancellable));
|
2011-07-04 13:54:00 -07:00
|
|
|
} catch (EngineError err) {
|
|
|
|
|
// don't thrown NOT_FOUND's, that means we need to fall through and clone from the
|
|
|
|
|
// server
|
|
|
|
|
if (!(err is EngineError.NOT_FOUND))
|
|
|
|
|
throw err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// clone the entire path
|
|
|
|
|
int length = path.get_path_length();
|
|
|
|
|
for (int ctr = 0; ctr < length; ctr++) {
|
|
|
|
|
Geary.FolderPath folder = path.get_folder_at(ctr);
|
|
|
|
|
|
|
|
|
|
if (yield local.folder_exists_async(folder))
|
|
|
|
|
continue;
|
|
|
|
|
|
2012-03-14 11:05:32 -07:00
|
|
|
Imap.Folder remote_folder = (Imap.Folder) yield remote.fetch_folder_async(folder,
|
2011-07-04 13:54:00 -07:00
|
|
|
cancellable);
|
|
|
|
|
|
|
|
|
|
yield local.clone_folder_async(remote_folder, cancellable);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-17 16:34:08 -07:00
|
|
|
// Fetch the local account's version of the folder for the GenericFolder
|
Remove SQLHeavy: Closes #5034
It is done.
Initial implementation of the new database subsystem
These pieces represent the foundation for ticket #5034
Expanded transactions, added VersionedDatabase
Further expansions of the async code.
Moved async pool logic into Database, where it realistically
belongs.
Further improvements. Introduced geary-db-test.
Added SQL create and update files for Geary.Db
version-001 to version-003 are exact copies of the SQLHeavy scripts
to ensure no slight changes when migrating. version-004 upgrades
the database to remove the ImapFolderPropertiesTable and
ImapMessagePropertiesTable, now that the database code is pure
IMAP.
When we support other messaging systems (such as POP3), those
subsystems will need to code their own database layers OR rely on
the IMAP schema and simply ignore the IMAP-specific fields.
ImapDB.Account fleshed out
ImapDB.Folder is commented out, however. Need to port next.
ImapDB.Folder fleshed out
MessageTable, MessageLocationTable, and AttachementTable are now
handled inside ImapDB.Folder.
chmod -x imap-db-database.vala
OutboxEmailIdentifier/Properties -> SmtpOutboxEmailIdentifier/Properties
Moved SmtpOutboxFolderRoot into its own source file
SmtpOutboxFolder ported to new database code
Move Engine implementations to ImapDB.
Integration and cleanup of new database code with main source
This commit performs the final integration steps to move Geary
completely over to the new database model. This also cleans out
the old SQLHeavy-based code and fixes a handful of small bugs that
were detected during basic test runs.
Moved Outbox to ImapDB
As the Outbox is tied to the database that ImapDB runs, move the
Outbox code into that folder.
Outbox fixes and better parameter checking
Bumped Database thread pool count and made them exclusive
My reasoning is that there may be a need for a lot of threads at
once (when a big batch of commands comes in, especially at
startup). If performance looks ok, we might consider relaxing
this later.
2012-06-14 14:47:53 -07:00
|
|
|
return build_folder((ImapDB.Folder) yield local.fetch_folder_async(path, cancellable));
|
2011-06-16 16:27:08 -07:00
|
|
|
}
|
|
|
|
|
|
2011-07-01 15:40:20 -07:00
|
|
|
private async void background_update_folders(Geary.FolderPath? parent,
|
2011-12-22 12:31:06 -08:00
|
|
|
Gee.Collection<Geary.Folder> engine_folders, Cancellable? cancellable) {
|
2012-03-14 11:05:32 -07:00
|
|
|
Gee.Collection<Geary.Imap.Folder> remote_folders;
|
2011-06-16 16:27:08 -07:00
|
|
|
try {
|
2011-12-22 12:31:06 -08:00
|
|
|
remote_folders = yield remote.list_folders_async(parent, cancellable);
|
2011-06-23 19:07:04 -07:00
|
|
|
} catch (Error remote_error) {
|
2012-04-18 19:52:13 -07:00
|
|
|
debug("Unable to retrieve folder list from server: %s", remote_error.message);
|
|
|
|
|
|
|
|
|
|
return;
|
2011-06-16 16:27:08 -07:00
|
|
|
}
|
|
|
|
|
|
2012-06-22 14:42:51 -07:00
|
|
|
// update all remote folders properties in the local store and active in the system
|
2013-02-25 20:18:37 -08:00
|
|
|
Gee.HashSet<Geary.FolderPath> altered_paths = new Gee.HashSet<Geary.FolderPath>(
|
|
|
|
|
Hashable.hash_func, Equalable.equal_func);
|
2012-06-22 14:42:51 -07:00
|
|
|
foreach (Imap.Folder remote_folder in remote_folders) {
|
2013-02-25 20:18:37 -08:00
|
|
|
// only worry about alterations if the remote is openable
|
|
|
|
|
if (remote_folder.get_properties().is_openable.is_possible()) {
|
|
|
|
|
ImapDB.Folder? local_folder = null;
|
|
|
|
|
try {
|
|
|
|
|
local_folder = yield local.fetch_folder_async(remote_folder.get_path(), cancellable);
|
|
|
|
|
} catch (Error err) {
|
2013-03-04 19:05:05 -08:00
|
|
|
if (!(err is EngineError.NOT_FOUND)) {
|
|
|
|
|
debug("Unable to fetch local folder for remote %s: %s", remote_folder.get_path().to_string(),
|
|
|
|
|
err.message);
|
|
|
|
|
}
|
2013-02-25 20:18:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (local_folder != null) {
|
|
|
|
|
if (remote_folder.get_properties().have_contents_changed(local_folder.get_properties()).is_possible())
|
|
|
|
|
altered_paths.add(remote_folder.get_path());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-22 14:42:51 -07:00
|
|
|
try {
|
|
|
|
|
yield local.update_folder_async(remote_folder, cancellable);
|
|
|
|
|
} catch (Error update_error) {
|
|
|
|
|
debug("Unable to update local folder %s with remote properties: %s",
|
|
|
|
|
remote_folder.to_string(), update_error.message);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-14 11:05:32 -07:00
|
|
|
|
2012-06-22 14:42:51 -07:00
|
|
|
// Get local paths of all engine (local) folders
|
|
|
|
|
Gee.Set<Geary.FolderPath> local_paths = new Gee.HashSet<Geary.FolderPath>(
|
|
|
|
|
Geary.Hashable.hash_func, Geary.Equalable.equal_func);
|
|
|
|
|
foreach (Geary.Folder local_folder in engine_folders)
|
|
|
|
|
local_paths.add(local_folder.get_path());
|
|
|
|
|
|
|
|
|
|
// Get remote paths of all remote folders
|
|
|
|
|
Gee.Set<Geary.FolderPath> remote_paths = new Gee.HashSet<Geary.FolderPath>(
|
|
|
|
|
Geary.Hashable.hash_func, Geary.Equalable.equal_func);
|
|
|
|
|
foreach (Geary.Imap.Folder remote_folder in remote_folders) {
|
|
|
|
|
remote_paths.add(remote_folder.get_path());
|
2012-05-10 20:28:42 -07:00
|
|
|
|
|
|
|
|
// use this iteration to add discovered properties to map
|
2012-06-22 14:42:51 -07:00
|
|
|
properties_map.set(remote_folder.get_path(), remote_folder.get_properties());
|
|
|
|
|
|
|
|
|
|
// also use this iteration to set the local folder's special type
|
2012-07-19 17:40:07 -07:00
|
|
|
// (but only promote, not demote, since getting the special folder type via its
|
|
|
|
|
// properties relies on the optional XLIST extension)
|
2012-07-17 16:34:08 -07:00
|
|
|
GenericFolder? local_folder = existing_folders.get(remote_folder.get_path());
|
2012-07-19 17:40:07 -07:00
|
|
|
if (local_folder != null && local_folder.get_special_folder_type() == SpecialFolderType.NONE)
|
2012-06-27 18:25:45 -07:00
|
|
|
local_folder.set_special_folder_type(remote_folder.get_properties().attrs.get_special_folder_type());
|
2012-05-10 20:28:42 -07:00
|
|
|
}
|
2011-06-16 16:27:08 -07:00
|
|
|
|
2012-06-22 14:42:51 -07:00
|
|
|
// If path in remote but not local, need to add it
|
2012-03-14 11:05:32 -07:00
|
|
|
Gee.List<Geary.Imap.Folder> to_add = new Gee.ArrayList<Geary.Imap.Folder>();
|
|
|
|
|
foreach (Geary.Imap.Folder folder in remote_folders) {
|
2012-06-22 14:42:51 -07:00
|
|
|
if (!local_paths.contains(folder.get_path()))
|
2012-03-14 11:05:32 -07:00
|
|
|
to_add.add(folder);
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-22 14:42:51 -07:00
|
|
|
// If path in local but not remote (and isn't local-only, i.e. the Outbox), need to remove
|
|
|
|
|
// it
|
2012-03-14 11:05:32 -07:00
|
|
|
Gee.List<Geary.Folder>? to_remove = new Gee.ArrayList<Geary.Imap.Folder>();
|
|
|
|
|
foreach (Geary.Folder folder in engine_folders) {
|
2013-01-17 12:50:30 -08:00
|
|
|
if (!remote_paths.contains(folder.get_path()) && !local_only.keys.contains(folder.get_path()))
|
2012-03-14 11:05:32 -07:00
|
|
|
to_remove.add(folder);
|
|
|
|
|
}
|
2011-06-16 16:27:08 -07:00
|
|
|
|
|
|
|
|
if (to_add.size == 0)
|
|
|
|
|
to_add = null;
|
|
|
|
|
|
|
|
|
|
if (to_remove.size == 0)
|
|
|
|
|
to_remove = null;
|
|
|
|
|
|
2012-06-22 14:42:51 -07:00
|
|
|
// For folders to add, clone them and their properties locally
|
2011-07-08 12:45:22 -07:00
|
|
|
if (to_add != null) {
|
2012-03-14 11:05:32 -07:00
|
|
|
foreach (Geary.Imap.Folder folder in to_add) {
|
2011-07-08 12:45:22 -07:00
|
|
|
try {
|
2011-12-22 12:31:06 -08:00
|
|
|
yield local.clone_folder_async(folder, cancellable);
|
2011-07-08 12:45:22 -07:00
|
|
|
} catch (Error err) {
|
|
|
|
|
debug("Unable to add/remove folder %s: %s", folder.get_path().to_string(),
|
|
|
|
|
err.message);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-06-16 16:27:08 -07:00
|
|
|
}
|
|
|
|
|
|
2012-06-22 14:42:51 -07:00
|
|
|
// Create Geary.Folder objects for all added folders
|
2011-06-16 16:27:08 -07:00
|
|
|
Gee.Collection<Geary.Folder> engine_added = null;
|
|
|
|
|
if (to_add != null) {
|
|
|
|
|
engine_added = new Gee.ArrayList<Geary.Folder>();
|
2013-01-17 12:50:30 -08:00
|
|
|
|
|
|
|
|
Gee.ArrayList<ImapDB.Folder> folders_to_build = new Gee.ArrayList<ImapDB.Folder>();
|
2012-03-14 11:05:32 -07:00
|
|
|
foreach (Geary.Imap.Folder remote_folder in to_add) {
|
2011-06-16 16:27:08 -07:00
|
|
|
try {
|
2013-01-17 12:50:30 -08:00
|
|
|
folders_to_build.add((ImapDB.Folder) yield local.fetch_folder_async(
|
|
|
|
|
remote_folder.get_path(), cancellable));
|
2011-06-16 16:27:08 -07:00
|
|
|
} catch (Error convert_err) {
|
2012-07-11 18:08:24 -07:00
|
|
|
// This isn't fatal, but irksome ... in the future, when local folders are
|
|
|
|
|
// removed, it's possible for one to disappear between cloning it and fetching
|
|
|
|
|
// it
|
|
|
|
|
debug("Unable to fetch local folder after cloning: %s", convert_err.message);
|
2011-06-16 16:27:08 -07:00
|
|
|
}
|
|
|
|
|
}
|
2013-01-17 12:50:30 -08:00
|
|
|
|
|
|
|
|
engine_added.add_all(build_folders(folders_to_build));
|
2011-06-16 16:27:08 -07:00
|
|
|
}
|
|
|
|
|
|
2012-06-22 14:42:51 -07:00
|
|
|
// TODO: Remove local folders no longer available remotely.
|
|
|
|
|
if (to_remove != null) {
|
|
|
|
|
foreach (Geary.Folder folder in to_remove) {
|
|
|
|
|
debug(@"Need to remove folder $folder");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-16 16:27:08 -07:00
|
|
|
if (engine_added != null)
|
|
|
|
|
notify_folders_added_removed(engine_added, null);
|
2013-02-25 20:18:37 -08:00
|
|
|
|
|
|
|
|
// report all altered folders
|
|
|
|
|
if (altered_paths.size > 0) {
|
|
|
|
|
Gee.ArrayList<Geary.Folder> altered = new Gee.ArrayList<Geary.Folder>();
|
|
|
|
|
foreach (Geary.FolderPath path in altered_paths) {
|
|
|
|
|
if (existing_folders.has_key(path))
|
|
|
|
|
altered.add(existing_folders.get(path));
|
|
|
|
|
else
|
|
|
|
|
debug("Unable to report %s altered: no local representation", path.to_string());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (altered.size > 0)
|
|
|
|
|
notify_folders_contents_altered(altered);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 14:25:03 +01:00
|
|
|
// enumerate children of each remote folder
|
2013-02-25 20:18:37 -08:00
|
|
|
foreach (Imap.Folder remote_folder in remote_folders) {
|
|
|
|
|
if (remote_folder.get_properties().has_children.is_possible()) {
|
|
|
|
|
try {
|
|
|
|
|
yield enumerate_folders_async(remote_folder.get_path(), cancellable);
|
|
|
|
|
} catch (Error err) {
|
|
|
|
|
debug("Unable to enumerate children of %s: %s", remote_folder.get_path().to_string(),
|
|
|
|
|
err.message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-06-16 16:27:08 -07:00
|
|
|
}
|
2011-07-01 19:33:35 -07:00
|
|
|
|
2012-06-11 12:03:57 -07:00
|
|
|
public override async void send_email_async(Geary.ComposedEmail composed,
|
|
|
|
|
Cancellable? cancellable = null) throws Error {
|
Remove SQLHeavy: Closes #5034
It is done.
Initial implementation of the new database subsystem
These pieces represent the foundation for ticket #5034
Expanded transactions, added VersionedDatabase
Further expansions of the async code.
Moved async pool logic into Database, where it realistically
belongs.
Further improvements. Introduced geary-db-test.
Added SQL create and update files for Geary.Db
version-001 to version-003 are exact copies of the SQLHeavy scripts
to ensure no slight changes when migrating. version-004 upgrades
the database to remove the ImapFolderPropertiesTable and
ImapMessagePropertiesTable, now that the database code is pure
IMAP.
When we support other messaging systems (such as POP3), those
subsystems will need to code their own database layers OR rely on
the IMAP schema and simply ignore the IMAP-specific fields.
ImapDB.Account fleshed out
ImapDB.Folder is commented out, however. Need to port next.
ImapDB.Folder fleshed out
MessageTable, MessageLocationTable, and AttachementTable are now
handled inside ImapDB.Folder.
chmod -x imap-db-database.vala
OutboxEmailIdentifier/Properties -> SmtpOutboxEmailIdentifier/Properties
Moved SmtpOutboxFolderRoot into its own source file
SmtpOutboxFolder ported to new database code
Move Engine implementations to ImapDB.
Integration and cleanup of new database code with main source
This commit performs the final integration steps to move Geary
completely over to the new database model. This also cleans out
the old SQLHeavy-based code and fixes a handful of small bugs that
were detected during basic test runs.
Moved Outbox to ImapDB
As the Outbox is tied to the database that ImapDB runs, move the
Outbox code into that folder.
Outbox fixes and better parameter checking
Bumped Database thread pool count and made them exclusive
My reasoning is that there may be a need for a lot of threads at
once (when a big batch of commands comes in, especially at
startup). If performance looks ok, we might consider relaxing
this later.
2012-06-14 14:47:53 -07:00
|
|
|
check_open();
|
|
|
|
|
|
2012-06-11 12:03:57 -07:00
|
|
|
Geary.RFC822.Message rfc822 = new Geary.RFC822.Message.from_composed_email(composed);
|
Remove SQLHeavy: Closes #5034
It is done.
Initial implementation of the new database subsystem
These pieces represent the foundation for ticket #5034
Expanded transactions, added VersionedDatabase
Further expansions of the async code.
Moved async pool logic into Database, where it realistically
belongs.
Further improvements. Introduced geary-db-test.
Added SQL create and update files for Geary.Db
version-001 to version-003 are exact copies of the SQLHeavy scripts
to ensure no slight changes when migrating. version-004 upgrades
the database to remove the ImapFolderPropertiesTable and
ImapMessagePropertiesTable, now that the database code is pure
IMAP.
When we support other messaging systems (such as POP3), those
subsystems will need to code their own database layers OR rely on
the IMAP schema and simply ignore the IMAP-specific fields.
ImapDB.Account fleshed out
ImapDB.Folder is commented out, however. Need to port next.
ImapDB.Folder fleshed out
MessageTable, MessageLocationTable, and AttachementTable are now
handled inside ImapDB.Folder.
chmod -x imap-db-database.vala
OutboxEmailIdentifier/Properties -> SmtpOutboxEmailIdentifier/Properties
Moved SmtpOutboxFolderRoot into its own source file
SmtpOutboxFolder ported to new database code
Move Engine implementations to ImapDB.
Integration and cleanup of new database code with main source
This commit performs the final integration steps to move Geary
completely over to the new database model. This also cleans out
the old SQLHeavy-based code and fixes a handful of small bugs that
were detected during basic test runs.
Moved Outbox to ImapDB
As the Outbox is tied to the database that ImapDB runs, move the
Outbox code into that folder.
Outbox fixes and better parameter checking
Bumped Database thread pool count and made them exclusive
My reasoning is that there may be a need for a lot of threads at
once (when a big batch of commands comes in, especially at
startup). If performance looks ok, we might consider relaxing
this later.
2012-06-14 14:47:53 -07:00
|
|
|
|
|
|
|
|
// don't use create_email_async() as that requires the folder be open to use
|
|
|
|
|
yield local.outbox.enqueue_email_async(rfc822, cancellable);
|
2011-09-30 17:29:03 -07:00
|
|
|
}
|
2012-06-25 16:30:23 -07:00
|
|
|
|
|
|
|
|
private void on_email_sent(Geary.RFC822.Message rfc822) {
|
|
|
|
|
notify_email_sent(rfc822);
|
|
|
|
|
}
|
2011-12-22 12:31:06 -08:00
|
|
|
|
2013-02-26 11:09:02 -08:00
|
|
|
public override async Gee.MultiMap<Geary.Email, Geary.FolderPath?>? local_search_message_id_async(
|
|
|
|
|
Geary.RFC822.MessageID message_id, Geary.Email.Field requested_fields, bool partial_ok,
|
2013-03-08 17:41:33 -08:00
|
|
|
Gee.Collection<Geary.FolderPath?>? folder_blacklist, Cancellable? cancellable = null) throws Error {
|
2013-02-26 11:09:02 -08:00
|
|
|
return yield local.search_message_id_async(
|
|
|
|
|
message_id, requested_fields, partial_ok, folder_blacklist, cancellable);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-08 17:41:33 -08:00
|
|
|
public override async Geary.Email local_fetch_email_async(Geary.EmailIdentifier email_id,
|
|
|
|
|
Geary.Email.Field required_fields, Cancellable? cancellable = null) throws Error {
|
|
|
|
|
return yield local.fetch_email_async(email_id, required_fields, cancellable);
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-14 11:05:32 -07:00
|
|
|
private void on_login_failed(Geary.Credentials? credentials) {
|
2013-01-31 15:17:44 -08:00
|
|
|
do_login_failed_async.begin(credentials);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void do_login_failed_async(Geary.Credentials? credentials) {
|
|
|
|
|
try {
|
|
|
|
|
if (yield information.fetch_passwords_async(CredentialsMediator.ServiceFlag.IMAP))
|
|
|
|
|
return;
|
|
|
|
|
} catch (Error e) {
|
|
|
|
|
debug("Error prompting for IMAP password: %s", e.message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
notify_report_problem(Geary.Account.Problem.RECV_EMAIL_LOGIN_FAILED, null);
|
2011-12-22 12:31:06 -08:00
|
|
|
}
|
2011-06-16 16:27:08 -07:00
|
|
|
}
|
|
|
|
|
|