/* imap-db-account.c generated by valac 0.56.19, the Vala compiler
 * generated from imap-db-account.vala, do not modify */

/*
 * Copyright 2016 Software Freedom Conservancy Inc.
 * Copyright 2019 Michael Gratton <mike@vee.net>.
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later). See the COPYING file in this distribution.
 */

#include "geary-engine.h"
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <gee.h>

#define GEARY_IMAP_DB_ACCOUNT_DB_FILENAME "geary.db"
#define GEARY_IMAP_DB_ACCOUNT_ATTACHMENTS_DIR "attachments"
#define GEARY_IMAP_DB_FOLDER_REQUIRED_FTS_FIELDS GEARY_EMAIL_REQUIRED_FOR_MESSAGE
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define GEARY_IMAP_DB_TYPE_ACCOUNT (geary_imap_db_account_get_type ())
#define GEARY_IMAP_DB_ACCOUNT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_DB_TYPE_ACCOUNT, GearyImapDBAccount))
#define GEARY_IMAP_DB_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_DB_TYPE_ACCOUNT, GearyImapDBAccountClass))
#define GEARY_IMAP_DB_IS_ACCOUNT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_DB_TYPE_ACCOUNT))
#define GEARY_IMAP_DB_IS_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_DB_TYPE_ACCOUNT))
#define GEARY_IMAP_DB_ACCOUNT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_DB_TYPE_ACCOUNT, GearyImapDBAccountClass))

typedef struct _GearyImapDBAccount GearyImapDBAccount;
typedef struct _GearyImapDBAccountClass GearyImapDBAccountClass;
typedef struct _GearyImapDBAccountPrivate GearyImapDBAccountPrivate;

#define GEARY_IMAP_DB_TYPE_DATABASE (geary_imap_db_database_get_type ())
#define GEARY_IMAP_DB_DATABASE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_DB_TYPE_DATABASE, GearyImapDBDatabase))
#define GEARY_IMAP_DB_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_DB_TYPE_DATABASE, GearyImapDBDatabaseClass))
#define GEARY_IMAP_DB_IS_DATABASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_DB_TYPE_DATABASE))
#define GEARY_IMAP_DB_IS_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_DB_TYPE_DATABASE))
#define GEARY_IMAP_DB_DATABASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_DB_TYPE_DATABASE, GearyImapDBDatabaseClass))

typedef struct _GearyImapDBDatabase GearyImapDBDatabase;
typedef struct _GearyImapDBDatabaseClass GearyImapDBDatabaseClass;

#define GEARY_IMAP_DB_ACCOUNT_TYPE_FOLDER_REFERENCE (geary_imap_db_account_folder_reference_get_type ())
#define GEARY_IMAP_DB_ACCOUNT_FOLDER_REFERENCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_DB_ACCOUNT_TYPE_FOLDER_REFERENCE, GearyImapDBAccountFolderReference))
#define GEARY_IMAP_DB_ACCOUNT_FOLDER_REFERENCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_DB_ACCOUNT_TYPE_FOLDER_REFERENCE, GearyImapDBAccountFolderReferenceClass))
#define GEARY_IMAP_DB_ACCOUNT_IS_FOLDER_REFERENCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_DB_ACCOUNT_TYPE_FOLDER_REFERENCE))
#define GEARY_IMAP_DB_ACCOUNT_IS_FOLDER_REFERENCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_DB_ACCOUNT_TYPE_FOLDER_REFERENCE))
#define GEARY_IMAP_DB_ACCOUNT_FOLDER_REFERENCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_DB_ACCOUNT_TYPE_FOLDER_REFERENCE, GearyImapDBAccountFolderReferenceClass))

typedef struct _GearyImapDBAccountFolderReference GearyImapDBAccountFolderReference;
typedef struct _GearyImapDBAccountFolderReferenceClass GearyImapDBAccountFolderReferenceClass;
enum  {
	GEARY_IMAP_DB_ACCOUNT_0_PROPERTY,
	GEARY_IMAP_DB_ACCOUNT_IMAP_FOLDER_ROOT_PROPERTY,
	GEARY_IMAP_DB_ACCOUNT_UPGRADE_MONITOR_PROPERTY,
	GEARY_IMAP_DB_ACCOUNT_VACUUM_MONITOR_PROPERTY,
	GEARY_IMAP_DB_ACCOUNT_DB_PROPERTY,
	GEARY_IMAP_DB_ACCOUNT_ACCOUNT_INFORMATION_PROPERTY,
	GEARY_IMAP_DB_ACCOUNT_NUM_PROPERTIES
};
static GParamSpec* geary_imap_db_account_properties[GEARY_IMAP_DB_ACCOUNT_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block33Data Block33Data;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _GearyImapDbAccountOpenAsyncData GearyImapDbAccountOpenAsyncData;
typedef struct _GearyImapDbAccountCloseAsyncData GearyImapDbAccountCloseAsyncData;

#define GEARY_IMAP_TYPE_FOLDER (geary_imap_folder_get_type ())
#define GEARY_IMAP_FOLDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_TYPE_FOLDER, GearyImapFolder))
#define GEARY_IMAP_FOLDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_TYPE_FOLDER, GearyImapFolderClass))
#define GEARY_IMAP_IS_FOLDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_TYPE_FOLDER))
#define GEARY_IMAP_IS_FOLDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_TYPE_FOLDER))
#define GEARY_IMAP_FOLDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_TYPE_FOLDER, GearyImapFolderClass))

typedef struct _GearyImapFolder GearyImapFolder;
typedef struct _GearyImapFolderClass GearyImapFolderClass;

#define GEARY_IMAP_DB_TYPE_FOLDER (geary_imap_db_folder_get_type ())
#define GEARY_IMAP_DB_FOLDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_DB_TYPE_FOLDER, GearyImapDBFolder))
#define GEARY_IMAP_DB_FOLDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_DB_TYPE_FOLDER, GearyImapDBFolderClass))
#define GEARY_IMAP_DB_IS_FOLDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_DB_TYPE_FOLDER))
#define GEARY_IMAP_DB_IS_FOLDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_DB_TYPE_FOLDER))
#define GEARY_IMAP_DB_FOLDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_DB_TYPE_FOLDER, GearyImapDBFolderClass))

typedef struct _GearyImapDBFolder GearyImapDBFolder;
typedef struct _GearyImapDBFolderClass GearyImapDBFolderClass;
typedef struct _Block34Data Block34Data;
typedef struct _GearyImapDbAccountCloneFolderAsyncData GearyImapDbAccountCloneFolderAsyncData;
typedef struct _Block35Data Block35Data;
typedef struct _GearyImapDbAccountDeleteFolderAsyncData GearyImapDbAccountDeleteFolderAsyncData;
typedef struct _Block36Data Block36Data;
typedef struct _GearyImapDbAccountListFoldersAsyncData GearyImapDbAccountListFoldersAsyncData;
typedef struct _Block37Data Block37Data;
typedef struct _GearyImapDbAccountFetchFolderAsyncData GearyImapDbAccountFetchFolderAsyncData;
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
typedef struct _Block38Data Block38Data;
typedef struct _GearyImapDbAccountFetchLastCleanupAsyncData GearyImapDbAccountFetchLastCleanupAsyncData;
typedef struct _Block39Data Block39Data;
typedef struct _GearyImapDbAccountSetLastCleanupAsyncData GearyImapDbAccountSetLastCleanupAsyncData;
typedef struct _GearyImapDBDatabasePrivate GearyImapDBDatabasePrivate;
typedef struct _GearyImapDBAccountFolderReferencePrivate GearyImapDBAccountFolderReferencePrivate;

#define GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER (geary_imap_db_email_identifier_get_type ())
#define GEARY_IMAP_DB_EMAIL_IDENTIFIER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, GearyImapDBEmailIdentifier))
#define GEARY_IMAP_DB_EMAIL_IDENTIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, GearyImapDBEmailIdentifierClass))
#define GEARY_IMAP_DB_IS_EMAIL_IDENTIFIER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER))
#define GEARY_IMAP_DB_IS_EMAIL_IDENTIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER))
#define GEARY_IMAP_DB_EMAIL_IDENTIFIER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, GearyImapDBEmailIdentifierClass))

typedef struct _GearyImapDBEmailIdentifier GearyImapDBEmailIdentifier;
typedef struct _GearyImapDBEmailIdentifierClass GearyImapDBEmailIdentifierClass;
typedef struct _Block40Data Block40Data;

#define GEARY_IMAP_DB_TYPE_MESSAGE_ROW (geary_imap_db_message_row_get_type ())
#define GEARY_IMAP_DB_MESSAGE_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_DB_TYPE_MESSAGE_ROW, GearyImapDBMessageRow))
#define GEARY_IMAP_DB_MESSAGE_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_DB_TYPE_MESSAGE_ROW, GearyImapDBMessageRowClass))
#define GEARY_IMAP_DB_IS_MESSAGE_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_DB_TYPE_MESSAGE_ROW))
#define GEARY_IMAP_DB_IS_MESSAGE_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_DB_TYPE_MESSAGE_ROW))
#define GEARY_IMAP_DB_MESSAGE_ROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_DB_TYPE_MESSAGE_ROW, GearyImapDBMessageRowClass))

typedef struct _GearyImapDBMessageRow GearyImapDBMessageRow;
typedef struct _GearyImapDBMessageRowClass GearyImapDBMessageRowClass;
#define _geary_imap_db_message_row_unref0(var) ((var == NULL) ? NULL : (var = (geary_imap_db_message_row_unref (var), NULL)))
typedef struct _GearyImapDbAccountSearchMessageIdAsyncData GearyImapDbAccountSearchMessageIdAsyncData;
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))

#define GEARY_TYPE_FTS_SEARCH_QUERY (geary_fts_search_query_get_type ())
#define GEARY_FTS_SEARCH_QUERY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_TYPE_FTS_SEARCH_QUERY, GearyFtsSearchQuery))
#define GEARY_FTS_SEARCH_QUERY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_TYPE_FTS_SEARCH_QUERY, GearyFtsSearchQueryClass))
#define GEARY_IS_FTS_SEARCH_QUERY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_TYPE_FTS_SEARCH_QUERY))
#define GEARY_IS_FTS_SEARCH_QUERY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_TYPE_FTS_SEARCH_QUERY))
#define GEARY_FTS_SEARCH_QUERY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_TYPE_FTS_SEARCH_QUERY, GearyFtsSearchQueryClass))

typedef struct _GearyFtsSearchQuery GearyFtsSearchQuery;
typedef struct _GearyFtsSearchQueryClass GearyFtsSearchQueryClass;
typedef struct _Block41Data Block41Data;
typedef struct _GearyImapDbAccountSearchAsyncData GearyImapDbAccountSearchAsyncData;
typedef struct _Block42Data Block42Data;
typedef struct _GearyImapDbAccountGetSearchMatchesAsyncData GearyImapDbAccountGetSearchMatchesAsyncData;
typedef struct _Block43Data Block43Data;
typedef struct _GearyImapDbAccountListEmailData GearyImapDbAccountListEmailData;
typedef struct _Block44Data Block44Data;
typedef struct _GearyImapDbAccountFetchEmailAsyncData GearyImapDbAccountFetchEmailAsyncData;
typedef struct _Block45Data Block45Data;
typedef struct _GearyImapDbAccountGetContainingFoldersAsyncData GearyImapDbAccountGetContainingFoldersAsyncData;
typedef struct _Block46Data Block46Data;
typedef struct _GearyImapDbAccountPopulateSearchTableData GearyImapDbAccountPopulateSearchTableData;
typedef struct _Block47Data Block47Data;
typedef struct _GearyImapDbAccountPopulateSearchTableBatchAsyncData GearyImapDbAccountPopulateSearchTableBatchAsyncData;
typedef struct _Block48Data Block48Data;
typedef struct _GearyImapDbAccountUpdateUnreadAsyncData GearyImapDbAccountUpdateUnreadAsyncData;
typedef struct _GearyImapDbAccountDeleteAllDataData GearyImapDbAccountDeleteAllDataData;
enum  {
	GEARY_IMAP_DB_ACCOUNT_FOLDER_REFERENCE_0_PROPERTY,
	GEARY_IMAP_DB_ACCOUNT_FOLDER_REFERENCE_NUM_PROPERTIES
};
static GParamSpec* geary_imap_db_account_folder_reference_properties[GEARY_IMAP_DB_ACCOUNT_FOLDER_REFERENCE_NUM_PROPERTIES];
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _GearyImapDBAccount {
	GearyBaseObject parent_instance;
	GearyImapDBAccountPrivate * priv;
};

struct _GearyImapDBAccountClass {
	GearyBaseObjectClass parent_class;
};

struct _GearyImapDBAccountPrivate {
	GearyImapFolderRoot* _imap_folder_root;
	GearySimpleProgressMonitor* _upgrade_monitor;
	GearySimpleProgressMonitor* _vacuum_monitor;
	GearyImapDBDatabase* _db;
	GearyAccountInformation* _account_information;
	gchar* name;
	GFile* db_file;
	GFile* attachments_dir;
	GeeHashMap* folder_refs;
	GCancellable* background_cancellable;
};

struct _Block33Data {
	int _ref_count_;
	GearyImapDBAccount* self;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbAccountOpenAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBAccount* self;
	GCancellable* cancellable;
	Block33Data* _data33_;
	GearyImapDBDatabase* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	GError* _tmp3_;
	GearyImapDBDatabase* _tmp4_;
	GError* err;
	GError* _tmp5_;
	const gchar* _tmp6_;
	GearyImapDBDatabase* _tmp7_;
	GError* _tmp8_;
	GError* _tmp9_;
	GearyImapDBDatabase* _tmp10_;
	GError* _vala1_err;
	GError* _tmp11_;
	const gchar* _tmp12_;
	GError* _tmp13_;
	GError* _tmp14_;
	GCancellable* _tmp15_;
	GError* _inner_error0_;
};

struct _GearyImapDbAccountCloseAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBAccount* self;
	GCancellable* cancellable;
	GearyImapDBDatabase* _tmp0_;
	GearyImapDBDatabase* _tmp1_;
	GError* _inner_error1_;
	GCancellable* _tmp2_;
	GeeHashMap* _tmp3_;
	GError* _inner_error0_;
};

struct _Block34Data {
	int _ref_count_;
	GearyImapDBAccount* self;
	GearyImapFolderProperties* properties;
	GearyFolderPath* path;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbAccountCloneFolderAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBAccount* self;
	GearyImapFolder* imap_folder;
	GCancellable* cancellable;
	GearyImapDBFolder* result;
	Block34Data* _data34_;
	GearyImapFolderProperties* _tmp0_;
	GearyImapFolderProperties* _tmp1_;
	GearyImapFolderProperties* _tmp2_;
	GearyFolderPath* _tmp3_;
	GearyFolderPath* _tmp4_;
	GearyFolderPath* _tmp5_;
	GearyImapDBFolder* folder;
	GearyFolderPath* _tmp6_;
	GearyImapDBFolder* _tmp7_;
	GearyImapDBFolder* _tmp8_;
	GearyFolderPath* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	GError* _tmp12_;
	GError* _tmp13_;
	gboolean _tmp14_;
	GearyFolderPath* _tmp15_;
	GearyFolderPath* _tmp16_;
	const gchar* _tmp17_;
	const gchar* _tmp18_;
	GearyFolderPath* _tmp19_;
	gchar* _tmp20_;
	gchar* _tmp21_;
	GError* _tmp22_;
	GError* _tmp23_;
	GearyImapDBDatabase* _tmp24_;
	GearyImapDBFolder* _tmp25_;
	GearyFolderPath* _tmp26_;
	GearyImapDBFolder* _tmp27_;
	GearyImapDBFolder* _tmp28_;
	GError* _inner_error0_;
};

struct _Block35Data {
	int _ref_count_;
	GearyImapDBAccount* self;
	GearyFolderPath* path;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbAccountDeleteFolderAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBAccount* self;
	GearyFolderPath* path;
	GCancellable* cancellable;
	Block35Data* _data35_;
	GearyImapDBDatabase* _tmp0_;
	GError* _inner_error0_;
};

struct _Block36Data {
	int _ref_count_;
	GearyImapDBAccount* self;
	GeeHashMap* id_map;
	GeeHashMap* prop_map;
	GearyFolderPath* parent;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbAccountListFoldersAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBAccount* self;
	GearyFolderPath* parent;
	GCancellable* cancellable;
	GeeCollection* result;
	Block36Data* _data36_;
	GeeHashMap* _tmp0_;
	GeeHashMap* _tmp1_;
	GearyImapDBDatabase* _tmp2_;
	GeeHashMap* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	GeeHashMap* _tmp6_;
	gint _tmp7_;
	gint _tmp8_;
	GeeHashMap* _tmp9_;
	gint _tmp10_;
	gint _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	GError* _tmp14_;
	GError* _tmp15_;
	GeeCollection* folders;
	GeeArrayList* _tmp16_;
	GeeIterator* _path_it;
	GeeHashMap* _tmp17_;
	GeeSet* _tmp18_;
	GeeSet* _tmp19_;
	GeeSet* _tmp20_;
	GeeIterator* _tmp21_;
	GeeIterator* _tmp22_;
	GeeIterator* _tmp23_;
	GearyFolderPath* path;
	GeeIterator* _tmp24_;
	gpointer _tmp25_;
	GearyImapDBFolder* folder;
	GearyFolderPath* _tmp26_;
	GearyImapDBFolder* _tmp27_;
	gboolean _tmp28_;
	gboolean _tmp29_;
	GearyImapDBFolder* _tmp30_;
	GeeHashMap* _tmp31_;
	GearyFolderPath* _tmp32_;
	GeeHashMap* _tmp33_;
	GearyFolderPath* _tmp34_;
	GearyImapDBFolder* _tmp35_;
	GearyFolderPath* _tmp36_;
	GeeHashMap* _tmp37_;
	GearyFolderPath* _tmp38_;
	gpointer _tmp39_;
	gint64* _tmp40_;
	GeeHashMap* _tmp41_;
	GearyFolderPath* _tmp42_;
	gpointer _tmp43_;
	GearyImapFolderProperties* _tmp44_;
	GearyImapDBFolder* _tmp45_;
	GearyImapDBFolder* _tmp46_;
	GearyImapDBFolder* _tmp47_;
	GeeCollection* _tmp48_;
	GearyImapDBFolder* _tmp49_;
	GError* _inner_error0_;
};

struct _Block37Data {
	int _ref_count_;
	GearyImapDBAccount* self;
	gint64 folder_id;
	GearyImapFolderProperties* properties;
	GearyFolderPath* path;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbAccountFetchFolderAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBAccount* self;
	GearyFolderPath* path;
	GCancellable* cancellable;
	GearyImapDBFolder* result;
	Block37Data* _data37_;
	GearyImapDBFolder* folder;
	GearyImapDBFolder* _tmp0_;
	GearyImapDBFolder* _tmp1_;
	GearyImapDBDatabase* _tmp2_;
	gboolean _tmp3_;
	GearyImapFolderProperties* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	GError* _tmp7_;
	GError* _tmp8_;
	GearyImapDBFolder* _tmp9_;
	GearyImapFolderProperties* _tmp10_;
	GearyImapDBFolder* _tmp11_;
	GearyImapDBFolder* _tmp12_;
	GError* _inner_error0_;
};

struct _Block38Data {
	int _ref_count_;
	GearyImapDBAccount* self;
	gint64 last_cleanup_time_t;
	gpointer _async_data_;
};

struct _GearyImapDbAccountFetchLastCleanupAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBAccount* self;
	GCancellable* cancellable;
	GDateTime* result;
	Block38Data* _data38_;
	GearyImapDBDatabase* _tmp0_;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	GDateTime* _tmp3_;
	GError* _inner_error0_;
};

struct _Block39Data {
	int _ref_count_;
	GearyImapDBAccount* self;
	GDateTime* dt;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbAccountSetLastCleanupAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBAccount* self;
	GDateTime* dt;
	GCancellable* cancellable;
	Block39Data* _data39_;
	GearyImapDBDatabase* _tmp0_;
	GError* _inner_error0_;
};

struct _GearyImapDBDatabase {
	GearyDbVersionedDatabase parent_instance;
	GFile* attachments_path;
	GearyImapDBDatabasePrivate * priv;
};

struct _GearyImapDBDatabaseClass {
	GearyDbVersionedDatabaseClass parent_class;
};

struct _GearyImapDBAccountFolderReference {
	GearySmartReference parent_instance;
	GearyFolderPath* path;
	GearyImapDBAccountFolderReferencePrivate * priv;
};

struct _GearyImapDBAccountFolderReferenceClass {
	GearySmartReferenceClass parent_class;
};

struct _Block40Data {
	int _ref_count_;
	GearyImapDBAccount* self;
	GeeHashMultiMap* messages;
	GearyRFC822MessageID* message_id;
	GearyEmailField requested_fields;
	gboolean partial_ok;
	GeeCollection* folder_blacklist;
	GearyEmailFlags* flag_blacklist;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbAccountSearchMessageIdAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBAccount* self;
	GearyRFC822MessageID* message_id;
	GearyEmailField requested_fields;
	gboolean partial_ok;
	GeeCollection* folder_blacklist;
	GearyEmailFlags* flag_blacklist;
	GCancellable* cancellable;
	GeeMultiMap* result;
	Block40Data* _data40_;
	GeeHashMultiMap* _tmp0_;
	GearyImapDBDatabase* _tmp1_;
	GeeHashMultiMap* _tmp2_;
	GeeHashMultiMap* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	GeeHashMultiMap* _tmp6_;
	GeeMultiMap* _tmp7_;
	GError* _inner_error0_;
};

struct _Block41Data {
	int _ref_count_;
	GearyImapDBAccount* self;
	GearyFtsSearchQuery* query;
	gchar* search_ids_sql;
	GeeList* matching_ids;
	GeeMap* search_matches;
	gint limit;
	gint offset;
	GeeCollection* excluded_folders;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbAccountSearchAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBAccount* self;
	GearySearchQuery* q;
	gint limit;
	gint offset;
	GeeCollection* excluded_folders;
	GeeCollection* search_ids;
	GCancellable* cancellable;
	GeeCollection* result;
	Block41Data* _data41_;
	gchar* _tmp0_;
	gchar* _tmp1_;
	GearyFtsSearchQuery* _tmp2_;
	gchar* _tmp3_;
	GeeLinkedList* _tmp4_;
	GearyImapDBDatabase* _tmp5_;
	GeeList* _tmp6_;
	gint _tmp7_;
	gint _tmp8_;
	GeeList* _tmp9_;
	GeeList* _tmp10_;
	gboolean _tmp11_;
	gboolean _tmp12_;
	GeeList* _tmp13_;
	GeeCollection* _tmp14_;
	GError* _inner_error0_;
};

struct _Block42Data {
	int _ref_count_;
	GearyImapDBAccount* self;
	GearyFtsSearchQuery* query;
	GeeSet* search_matches;
	GeeCollection* ids;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbAccountGetSearchMatchesAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBAccount* self;
	GearySearchQuery* q;
	GeeCollection* ids;
	GCancellable* cancellable;
	GeeSet* result;
	Block42Data* _data42_;
	GearyFtsSearchQuery* _tmp0_;
	GearyImapDBDatabase* _tmp1_;
	GeeSet* _tmp2_;
	GeeSet* _tmp3_;
	GError* _inner_error0_;
};

struct _Block43Data {
	int _ref_count_;
	GearyImapDBAccount* self;
	GeeArrayList* results;
	GeeCollection* ids;
	GearyEmailField required_fields;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbAccountListEmailData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBAccount* self;
	GeeCollection* ids;
	GearyEmailField required_fields;
	GCancellable* cancellable;
	GeeList* result;
	Block43Data* _data43_;
	GeeArrayList* _tmp0_;
	GearyImapDBDatabase* _tmp1_;
	GeeArrayList* _tmp2_;
	GeeList* _tmp3_;
	GError* _inner_error0_;
};

struct _Block44Data {
	int _ref_count_;
	GearyImapDBAccount* self;
	GearyEmail* email;
	GearyImapDBEmailIdentifier* email_id;
	GearyEmailField required_fields;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbAccountFetchEmailAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBAccount* self;
	GearyImapDBEmailIdentifier* email_id;
	GearyEmailField required_fields;
	GCancellable* cancellable;
	GearyEmail* result;
	Block44Data* _data44_;
	GearyImapDBDatabase* _tmp0_;
	GearyEmail* _tmp1_;
	GearyEmail* _tmp2_;
	GearyEmail* _tmp3_;
	GError* _inner_error0_;
};

struct _Block45Data {
	int _ref_count_;
	GearyImapDBAccount* self;
	GeeCollection* ids;
	GeeMultiMap* map;
	gpointer _async_data_;
};

struct _GearyImapDbAccountGetContainingFoldersAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBAccount* self;
	GeeCollection* ids;
	GeeMultiMap* map;
	GCancellable* cancellable;
	Block45Data* _data45_;
	GearyImapDBDatabase* _tmp0_;
	GError* _inner_error0_;
};

struct _Block46Data {
	int _ref_count_;
	GearyImapDBAccount* self;
	GeeHashSet* search_ids;
	GeeHashSet* message_ids;
	GeeHashSet* unindexed_message_ids;
	gpointer _async_data_;
};

struct _GearyImapDbAccountPopulateSearchTableData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBAccount* self;
	GCancellable* cancellable;
	Block46Data* _data46_;
	GearyAccountInformation* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	GeeHashSet* _tmp3_;
	GeeHashSet* _tmp4_;
	GeeHashSet* _tmp5_;
	GearyImapDBDatabase* _tmp6_;
	GearyNonblockingConcurrent* _tmp7_;
	GearyNonblockingConcurrent* _tmp8_;
	GearyAccountInformation* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	GeeHashSet* _tmp12_;
	gint _tmp13_;
	gint _tmp14_;
	GeeHashSet* _tmp15_;
	gboolean _tmp16_;
	gboolean _tmp17_;
	GeeHashSet* _tmp18_;
	GError* e;
	GearyAccountInformation* _tmp19_;
	const gchar* _tmp20_;
	const gchar* _tmp21_;
	GError* _tmp22_;
	const gchar* _tmp23_;
	GearyAccountInformation* _tmp24_;
	const gchar* _tmp25_;
	const gchar* _tmp26_;
	GError* _inner_error0_;
};

struct _Block47Data {
	int _ref_count_;
	GearyImapDBAccount* self;
	guint count;
	GeeIterator* iter;
	gint limit;
	gpointer _async_data_;
};

struct _GearyImapDbAccountPopulateSearchTableBatchAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBAccount* self;
	gint limit;
	GeeHashSet* unindexed_message_ids;
	GCancellable* cancellable;
	Block47Data* _data47_;
	GeeIterator* _tmp0_;
	GearyImapDBDatabase* _tmp1_;
	GCancellable* _tmp2_;
	GearyAccountInformation* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	GError* _inner_error0_;
};

struct _Block48Data {
	int _ref_count_;
	GearyImapDBAccount* self;
	GeeMap* unread_change;
	GearyImapDBFolder* source;
	GeeMap* unread_status;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbAccountUpdateUnreadAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBAccount* self;
	GearyImapDBFolder* source;
	GeeMap* unread_status;
	GCancellable* cancellable;
	Block48Data* _data48_;
	GeeHashMap* _tmp0_;
	GearyImapDBDatabase* _tmp1_;
	GeeIterator* _path_it;
	GeeMap* _tmp2_;
	GeeSet* _tmp3_;
	GeeSet* _tmp4_;
	GeeSet* _tmp5_;
	GeeIterator* _tmp6_;
	GeeIterator* _tmp7_;
	GeeIterator* _tmp8_;
	GearyFolderPath* path;
	GeeIterator* _tmp9_;
	gpointer _tmp10_;
	GearyImapDBFolder* folder;
	GearyFolderPath* _tmp11_;
	GearyImapDBFolder* _tmp12_;
	GearyImapDBFolder* _tmp13_;
	GearyImapDBFolder* _tmp14_;
	GearyImapFolderProperties* _tmp15_;
	GearyImapFolderProperties* _tmp16_;
	GearyImapDBFolder* _tmp17_;
	GearyImapFolderProperties* _tmp18_;
	GearyImapFolderProperties* _tmp19_;
	gint _tmp20_;
	gint _tmp21_;
	GeeMap* _tmp22_;
	GearyFolderPath* _tmp23_;
	gpointer _tmp24_;
	GError* _inner_error0_;
};

struct _GearyImapDbAccountDeleteAllDataData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBAccount* self;
	GCancellable* cancellable;
	GearyImapDBDatabase* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	GError* _tmp3_;
	gboolean _tmp4_;
	GFile* _tmp5_;
	const gchar* _tmp6_;
	GFile* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	GFile* _tmp10_;
	gboolean _tmp11_;
	GFile* _tmp12_;
	const gchar* _tmp13_;
	GFile* _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	GFile* _tmp17_;
	GError* _inner_error0_;
};

static gint GearyImapDBAccount_private_offset;
static gpointer geary_imap_db_account_parent_class = NULL;
static gpointer geary_imap_db_account_folder_reference_parent_class = NULL;

VALA_EXTERN GType geary_imap_db_account_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_db_database_get_type (void) G_GNUC_CONST ;
static GType geary_imap_db_account_folder_reference_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
VALA_EXTERN GearyImapFolderRoot* geary_imap_db_account_get_imap_folder_root (GearyImapDBAccount* self);
static void geary_imap_db_account_set_imap_folder_root (GearyImapDBAccount* self,
                                                 GearyImapFolderRoot* value);
VALA_EXTERN GearySimpleProgressMonitor* geary_imap_db_account_get_upgrade_monitor (GearyImapDBAccount* self);
static void geary_imap_db_account_set_upgrade_monitor (GearyImapDBAccount* self,
                                                GearySimpleProgressMonitor* value);
VALA_EXTERN GearySimpleProgressMonitor* geary_imap_db_account_get_vacuum_monitor (GearyImapDBAccount* self);
static void geary_imap_db_account_set_vacuum_monitor (GearyImapDBAccount* self,
                                               GearySimpleProgressMonitor* value);
VALA_EXTERN GearyImapDBDatabase* geary_imap_db_account_get_db (GearyImapDBAccount* self);
static void geary_imap_db_account_set_db (GearyImapDBAccount* self,
                                   GearyImapDBDatabase* value);
VALA_EXTERN GearyAccountInformation* geary_imap_db_account_get_account_information (GearyImapDBAccount* self);
static void geary_imap_db_account_set_account_information (GearyImapDBAccount* self,
                                                    GearyAccountInformation* value);
VALA_EXTERN GearyImapDBAccount* geary_imap_db_account_new (GearyAccountInformation* config,
                                               GFile* data_dir,
                                               GFile* schema_dir);
VALA_EXTERN GearyImapDBAccount* geary_imap_db_account_construct (GType object_type,
                                                     GearyAccountInformation* config,
                                                     GFile* data_dir,
                                                     GFile* schema_dir);
VALA_EXTERN GearyImapDBDatabase* geary_imap_db_database_new (GFile* db_file,
                                                 GFile* schema_dir,
                                                 GFile* attachments_path,
                                                 GearyProgressMonitor* upgrade_monitor,
                                                 GearyProgressMonitor* vacuum_monitor);
VALA_EXTERN GearyImapDBDatabase* geary_imap_db_database_construct (GType object_type,
                                                       GFile* db_file,
                                                       GFile* schema_dir,
                                                       GFile* attachments_path,
                                                       GearyProgressMonitor* upgrade_monitor,
                                                       GearyProgressMonitor* vacuum_monitor);
static void geary_imap_db_account_open_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_account_open_async (GearyImapDBAccount* self,
                                       GCancellable* cancellable,
                                       GAsyncReadyCallback _callback_,
                                       gpointer _user_data_);
VALA_EXTERN void geary_imap_db_account_open_finish (GearyImapDBAccount* self,
                                        GAsyncResult* _res_,
                                        GError** error);
static gboolean geary_imap_db_account_open_async_co (GearyImapDbAccountOpenAsyncData* _data_);
static Block33Data* block33_data_ref (Block33Data* _data33_);
static void block33_data_unref (void * _userdata_);
VALA_EXTERN void geary_imap_db_database_open (GearyImapDBDatabase* self,
                                  GearyDbDatabaseFlags flags,
                                  GCancellable* cancellable,
                                  GAsyncReadyCallback _callback_,
                                  gpointer _user_data_);
VALA_EXTERN void geary_imap_db_database_open_finish (GearyImapDBDatabase* self,
                                         GAsyncResult* _res_,
                                         GError** error);
static void geary_imap_db_account_open_async_ready (GObject* source_object,
                                             GAsyncResult* _res_,
                                             gpointer _user_data_);
static GearyDbTransactionOutcome ___lambda86_ (Block33Data* _data33_,
                                        GearyDbConnection* cx,
                                        GError** error);
static void geary_imap_db_account_do_delete_folder (GearyImapDBAccount* self,
                                             GearyDbConnection* cx,
                                             gint64 folder_id,
                                             GCancellable* cancellable,
                                             GError** error);
static GearyDbTransactionOutcome ____lambda86__geary_db_transaction_method (GearyDbConnection* cx,
                                                                     GCancellable* cancellable,
                                                                     gpointer self,
                                                                     GError** error);
static void geary_imap_db_account_close_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_account_close_async (GearyImapDBAccount* self,
                                        GCancellable* cancellable,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_);
VALA_EXTERN void geary_imap_db_account_close_finish (GearyImapDBAccount* self,
                                         GAsyncResult* _res_,
                                         GError** error);
static gboolean geary_imap_db_account_close_async_co (GearyImapDbAccountCloseAsyncData* _data_);
static void geary_imap_db_account_clone_folder_async_data_free (gpointer _data);
VALA_EXTERN GType geary_imap_folder_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_db_folder_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void geary_imap_db_account_clone_folder_async (GearyImapDBAccount* self,
                                               GearyImapFolder* imap_folder,
                                               GCancellable* cancellable,
                                               GAsyncReadyCallback _callback_,
                                               gpointer _user_data_);
VALA_EXTERN GearyImapDBFolder* geary_imap_db_account_clone_folder_finish (GearyImapDBAccount* self,
                                                              GAsyncResult* _res_,
                                                              GError** error);
static gboolean geary_imap_db_account_clone_folder_async_co (GearyImapDbAccountCloneFolderAsyncData* _data_);
static Block34Data* block34_data_ref (Block34Data* _data34_);
static void block34_data_unref (void * _userdata_);
static inline void geary_imap_db_account_check_open (GearyImapDBAccount* self,
                                       GError** error);
VALA_EXTERN GearyImapFolderProperties* geary_imap_folder_get_properties (GearyImapFolder* self);
VALA_EXTERN GearyFolderPath* geary_imap_folder_get_path (GearyImapFolder* self);
static GearyImapDBFolder* geary_imap_db_account_get_local_folder (GearyImapDBAccount* self,
                                                           GearyFolderPath* path);
static GearyDbTransactionOutcome __lambda87_ (Block34Data* _data34_,
                                       GearyDbConnection* cx,
                                       GError** error);
VALA_EXTERN gboolean geary_imap_db_account_do_fetch_parent_id (GearyImapDBAccount* self,
                                                   GearyDbConnection* cx,
                                                   GearyFolderPath* path,
                                                   gboolean create,
                                                   gint64* parent_id,
                                                   GCancellable* cancellable,
                                                   GError** error);
static GearyDbTransactionOutcome ___lambda87__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_account_clone_folder_async_ready (GObject* source_object,
                                                     GAsyncResult* _res_,
                                                     gpointer _user_data_);
VALA_EXTERN void geary_imap_db_account_fetch_folder_async (GearyImapDBAccount* self,
                                               GearyFolderPath* path,
                                               GCancellable* cancellable,
                                               GAsyncReadyCallback _callback_,
                                               gpointer _user_data_);
VALA_EXTERN GearyImapDBFolder* geary_imap_db_account_fetch_folder_finish (GearyImapDBAccount* self,
                                                              GAsyncResult* _res_,
                                                              GError** error);
static void geary_imap_db_account_delete_folder_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_account_delete_folder_async (GearyImapDBAccount* self,
                                                GearyFolderPath* path,
                                                GCancellable* cancellable,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_);
VALA_EXTERN void geary_imap_db_account_delete_folder_finish (GearyImapDBAccount* self,
                                                 GAsyncResult* _res_,
                                                 GError** error);
static gboolean geary_imap_db_account_delete_folder_async_co (GearyImapDbAccountDeleteFolderAsyncData* _data_);
static Block35Data* block35_data_ref (Block35Data* _data35_);
static void block35_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda90_ (Block35Data* _data35_,
                                       GearyDbConnection* cx,
                                       GError** error);
VALA_EXTERN gboolean geary_imap_db_account_do_fetch_folder_id (GearyImapDBAccount* self,
                                                   GearyDbConnection* cx,
                                                   GearyFolderPath* path,
                                                   gboolean create,
                                                   gint64* folder_id,
                                                   GCancellable* cancellable,
                                                   GError** error);
static gboolean geary_imap_db_account_do_has_children (GearyImapDBAccount* self,
                                                GearyDbConnection* cx,
                                                gint64 folder_id,
                                                GCancellable* cancellable,
                                                GError** error);
static GearyDbTransactionOutcome ___lambda90__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_account_delete_folder_async_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_);
static void geary_imap_db_account_list_folders_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_account_list_folders_async (GearyImapDBAccount* self,
                                               GearyFolderPath* parent,
                                               GCancellable* cancellable,
                                               GAsyncReadyCallback _callback_,
                                               gpointer _user_data_);
VALA_EXTERN GeeCollection* geary_imap_db_account_list_folders_finish (GearyImapDBAccount* self,
                                                          GAsyncResult* _res_,
                                                          GError** error);
static gboolean geary_imap_db_account_list_folders_async_co (GearyImapDbAccountListFoldersAsyncData* _data_);
static Block36Data* block36_data_ref (Block36Data* _data36_);
static void block36_data_unref (void * _userdata_);
static gint64* _int64_dup (gint64* self);
static GearyDbTransactionOutcome __lambda91_ (Block36Data* _data36_,
                                       GearyDbConnection* cx,
                                       GError** error);
VALA_EXTERN GearyImapFolderProperties* geary_imap_folder_properties_new_from_imapdb (GearyImapMailboxAttributes* attrs,
                                                                         gint email_total,
                                                                         gint email_unread,
                                                                         GearyImapUIDValidity* uid_validity,
                                                                         GearyImapUID* uid_next);
VALA_EXTERN GearyImapFolderProperties* geary_imap_folder_properties_construct_from_imapdb (GType object_type,
                                                                               GearyImapMailboxAttributes* attrs,
                                                                               gint email_total,
                                                                               gint email_unread,
                                                                               GearyImapUIDValidity* uid_validity,
                                                                               GearyImapUID* uid_next);
static GearyDbTransactionOutcome ___lambda91__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_account_list_folders_async_ready (GObject* source_object,
                                                     GAsyncResult* _res_,
                                                     gpointer _user_data_);
static GearyImapDBFolder* geary_imap_db_account_create_local_folder (GearyImapDBAccount* self,
                                                              GearyFolderPath* path,
                                                              gint64 folder_id,
                                                              GearyImapFolderProperties* properties,
                                                              GError** error);
static void geary_imap_db_account_fetch_folder_async_data_free (gpointer _data);
static gboolean geary_imap_db_account_fetch_folder_async_co (GearyImapDbAccountFetchFolderAsyncData* _data_);
static Block37Data* block37_data_ref (Block37Data* _data37_);
static void block37_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda88_ (Block37Data* _data37_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GearyDbTransactionOutcome ___lambda88__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_account_fetch_folder_async_ready (GObject* source_object,
                                                     GAsyncResult* _res_,
                                                     gpointer _user_data_);
static void geary_imap_db_account_fetch_last_cleanup_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_account_fetch_last_cleanup_async (GearyImapDBAccount* self,
                                                     GCancellable* cancellable,
                                                     GAsyncReadyCallback _callback_,
                                                     gpointer _user_data_);
VALA_EXTERN GDateTime* geary_imap_db_account_fetch_last_cleanup_finish (GearyImapDBAccount* self,
                                                            GAsyncResult* _res_,
                                                            GError** error);
static gboolean geary_imap_db_account_fetch_last_cleanup_async_co (GearyImapDbAccountFetchLastCleanupAsyncData* _data_);
static Block38Data* block38_data_ref (Block38Data* _data38_);
static void block38_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda92_ (Block38Data* _data38_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GearyDbTransactionOutcome ___lambda92__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_account_fetch_last_cleanup_async_ready (GObject* source_object,
                                                           GAsyncResult* _res_,
                                                           gpointer _user_data_);
static void geary_imap_db_account_set_last_cleanup_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_account_set_last_cleanup_async (GearyImapDBAccount* self,
                                                   GDateTime* dt,
                                                   GCancellable* cancellable,
                                                   GAsyncReadyCallback _callback_,
                                                   gpointer _user_data_);
VALA_EXTERN void geary_imap_db_account_set_last_cleanup_finish (GearyImapDBAccount* self,
                                                    GAsyncResult* _res_,
                                                    GError** error);
static gboolean geary_imap_db_account_set_last_cleanup_async_co (GearyImapDbAccountSetLastCleanupAsyncData* _data_);
static Block39Data* block39_data_ref (Block39Data* _data39_);
static void block39_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda93_ (Block39Data* _data39_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GearyDbTransactionOutcome ___lambda93__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_account_set_last_cleanup_async_ready (GObject* source_object,
                                                         GAsyncResult* _res_,
                                                         gpointer _user_data_);
VALA_EXTERN void geary_imap_db_folder_set_properties (GearyImapDBFolder* self,
                                          GearyImapFolderProperties* properties);
VALA_EXTERN GearyImapDBFolder* geary_imap_db_folder_new (GearyDbDatabase* db,
                                             GearyFolderPath* path,
                                             GFile* attachments_path,
                                             const gchar* account_owner_email,
                                             gint64 folder_id,
                                             GearyImapFolderProperties* properties);
VALA_EXTERN GearyImapDBFolder* geary_imap_db_folder_construct (GType object_type,
                                                   GearyDbDatabase* db,
                                                   GearyFolderPath* path,
                                                   GFile* attachments_path,
                                                   const gchar* account_owner_email,
                                                   gint64 folder_id,
                                                   GearyImapFolderProperties* properties);
static GearyImapDBAccountFolderReference* geary_imap_db_account_folder_reference_new (GearyImapDBFolder* folder,
                                                                               GearyFolderPath* path);
static GearyImapDBAccountFolderReference* geary_imap_db_account_folder_reference_construct (GType object_type,
                                                                                     GearyImapDBFolder* folder,
                                                                                     GearyFolderPath* path);
static void geary_imap_db_account_on_folder_reference_broken (GearyImapDBAccount* self,
                                                       GearySmartReference* reference);
static void _geary_imap_db_account_on_folder_reference_broken_geary_smart_reference_reference_broken (GearySmartReference* _sender,
                                                                                               gpointer self);
VALA_EXTERN GType geary_imap_db_email_identifier_get_type (void) G_GNUC_CONST ;
static void geary_imap_db_account_on_unread_updated (GearyImapDBAccount* self,
                                              GearyImapDBFolder* source,
                                              GeeMap* unread_status);
static void _geary_imap_db_account_on_unread_updated_geary_imap_db_folder_unread_updated (GearyImapDBFolder* _sender,
                                                                                   GeeMap* unread_status,
                                                                                   gpointer self);
static void geary_imap_db_account_search_message_id_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_account_search_message_id_async (GearyImapDBAccount* self,
                                                    GearyRFC822MessageID* message_id,
                                                    GearyEmailField requested_fields,
                                                    gboolean partial_ok,
                                                    GeeCollection* folder_blacklist,
                                                    GearyEmailFlags* flag_blacklist,
                                                    GCancellable* cancellable,
                                                    GAsyncReadyCallback _callback_,
                                                    gpointer _user_data_);
VALA_EXTERN GeeMultiMap* geary_imap_db_account_search_message_id_finish (GearyImapDBAccount* self,
                                                             GAsyncResult* _res_,
                                                             GError** error);
static gboolean geary_imap_db_account_search_message_id_async_co (GearyImapDbAccountSearchMessageIdAsyncData* _data_);
static Block40Data* block40_data_ref (Block40Data* _data40_);
static void block40_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda94_ (Block40Data* _data40_,
                                       GearyDbConnection* cx,
                                       GError** error);
VALA_EXTERN gpointer geary_imap_db_message_row_ref (gpointer instance);
VALA_EXTERN void geary_imap_db_message_row_unref (gpointer instance);
VALA_EXTERN GParamSpec* geary_imap_db_param_spec_message_row (const gchar* name,
                                                  const gchar* nick,
                                                  const gchar* blurb,
                                                  GType object_type,
                                                  GParamFlags flags);
VALA_EXTERN void geary_imap_db_value_set_message_row (GValue* value,
                                          gpointer v_object);
VALA_EXTERN void geary_imap_db_value_take_message_row (GValue* value,
                                           gpointer v_object);
VALA_EXTERN gpointer geary_imap_db_value_get_message_row (const GValue* value);
VALA_EXTERN GType geary_imap_db_message_row_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GearyImapDBMessageRow* geary_imap_db_folder_do_fetch_message_row (GearyDbConnection* cx,
                                                                  gint64 message_id,
                                                                  GearyEmailField requested_fields,
                                                                  GearyEmailField* db_fields,
                                                                  GCancellable* cancellable,
                                                                  GError** error);
VALA_EXTERN GearyEmailField geary_imap_db_message_row_get_fields (GearyImapDBMessageRow* self);
VALA_EXTERN GearyEmail* geary_imap_db_message_row_to_email (GearyImapDBMessageRow* self,
                                                GearyImapDBEmailIdentifier* id,
                                                GError** error);
VALA_EXTERN GearyImapDBEmailIdentifier* geary_imap_db_email_identifier_new (gint64 message_id,
                                                                GearyImapUID* uid);
VALA_EXTERN GearyImapDBEmailIdentifier* geary_imap_db_email_identifier_construct (GType object_type,
                                                                      gint64 message_id,
                                                                      GearyImapUID* uid);
VALA_EXTERN void geary_imap_db_attachment_add_attachments (GearyDbConnection* cx,
                                               GFile* attachments_path,
                                               GearyEmail* email,
                                               gint64 message_id,
                                               GCancellable* cancellable,
                                               GError** error);
static GeeSet* geary_imap_db_account_do_find_email_folders (GearyImapDBAccount* self,
                                                     GearyDbConnection* cx,
                                                     gint64 message_id,
                                                     gboolean include_removed,
                                                     GCancellable* cancellable,
                                                     GError** error);
static GearyDbTransactionOutcome ___lambda94__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_account_search_message_id_async_ready (GObject* source_object,
                                                          GAsyncResult* _res_,
                                                          gpointer _user_data_);
static void geary_imap_db_account_sql_append_ids (GearyImapDBAccount* self,
                                           GString* s,
                                           GeeIterable* ids);
static gchar* geary_imap_db_account_get_search_ids_sql (GearyImapDBAccount* self,
                                                 GeeCollection* search_ids,
                                                 GError** error);
VALA_EXTERN gint64 geary_imap_db_email_identifier_get_message_id (GearyImapDBEmailIdentifier* self);
static void geary_imap_db_account_search_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_account_search_async (GearyImapDBAccount* self,
                                         GearySearchQuery* q,
                                         gint limit,
                                         gint offset,
                                         GeeCollection* excluded_folders,
                                         GeeCollection* search_ids,
                                         GCancellable* cancellable,
                                         GAsyncReadyCallback _callback_,
                                         gpointer _user_data_);
VALA_EXTERN GeeCollection* geary_imap_db_account_search_finish (GearyImapDBAccount* self,
                                                    GAsyncResult* _res_,
                                                    GError** error);
static gboolean geary_imap_db_account_search_async_co (GearyImapDbAccountSearchAsyncData* _data_);
VALA_EXTERN GType geary_fts_search_query_get_type (void) G_GNUC_CONST ;
static Block41Data* block41_data_ref (Block41Data* _data41_);
static void block41_data_unref (void * _userdata_);
static GearyFtsSearchQuery* geary_imap_db_account_check_search_query (GearyImapDBAccount* self,
                                                               GearySearchQuery* q,
                                                               GError** error);
static GearyDbTransactionOutcome __lambda95_ (Block41Data* _data41_,
                                       GearyDbConnection* cx,
                                       GError** error);
static gchar* geary_imap_db_account_do_get_excluded_folder_ids (GearyImapDBAccount* self,
                                                         GeeCollection* excluded_folder,
                                                         GearyDbConnection* cx,
                                                         gboolean* exclude_folderless,
                                                         GCancellable* cancellable,
                                                         GError** error);
static guint _geary_collection_int64_hash_func_gee_hash_data_func (gconstpointer v,
                                                            gpointer self);
static gboolean _geary_collection_int64_equal_func_gee_equal_data_func (gconstpointer a,
                                                                 gconstpointer b,
                                                                 gpointer self);
VALA_EXTERN GearyDbStatement* geary_fts_search_query_get_search_query (GearyFtsSearchQuery* self,
                                                           GearyDbConnection* cx,
                                                           const gchar* search_ids_sql,
                                                           const gchar* excluded_folder_ids_sql,
                                                           gboolean exclude_folderless,
                                                           gint limit,
                                                           gint offset,
                                                           GError** error);
VALA_EXTERN gboolean geary_fts_search_query_get_has_stemmed_terms (GearyFtsSearchQuery* self);
VALA_EXTERN GeeMap* geary_imap_db_account_do_get_search_matches (GearyImapDBAccount* self,
                                                     GearyDbConnection* cx,
                                                     GearyFtsSearchQuery* query,
                                                     GeeMap* id_map,
                                                     GCancellable* cancellable,
                                                     GError** error);
static GearyDbTransactionOutcome ___lambda95__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_account_search_async_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_);
static void geary_imap_db_account_get_search_matches_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_account_get_search_matches_async (GearyImapDBAccount* self,
                                                     GearySearchQuery* q,
                                                     GeeCollection* ids,
                                                     GCancellable* cancellable,
                                                     GAsyncReadyCallback _callback_,
                                                     gpointer _user_data_);
VALA_EXTERN GeeSet* geary_imap_db_account_get_search_matches_finish (GearyImapDBAccount* self,
                                                         GAsyncResult* _res_,
                                                         GError** error);
static gboolean geary_imap_db_account_get_search_matches_async_co (GearyImapDbAccountGetSearchMatchesAsyncData* _data_);
static Block42Data* block42_data_ref (Block42Data* _data42_);
static void block42_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda96_ (Block42Data* _data42_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GearyDbTransactionOutcome ___lambda96__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_account_get_search_matches_async_ready (GObject* source_object,
                                                           GAsyncResult* _res_,
                                                           gpointer _user_data_);
static void geary_imap_db_account_list_email_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_account_list_email (GearyImapDBAccount* self,
                                       GeeCollection* ids,
                                       GearyEmailField required_fields,
                                       GCancellable* cancellable,
                                       GAsyncReadyCallback _callback_,
                                       gpointer _user_data_);
VALA_EXTERN GeeList* geary_imap_db_account_list_email_finish (GearyImapDBAccount* self,
                                                  GAsyncResult* _res_,
                                                  GError** error);
static gboolean geary_imap_db_account_list_email_co (GearyImapDbAccountListEmailData* _data_);
static Block43Data* block43_data_ref (Block43Data* _data43_);
static void block43_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda97_ (Block43Data* _data43_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GearyDbTransactionOutcome ___lambda97__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_account_list_email_ready (GObject* source_object,
                                             GAsyncResult* _res_,
                                             gpointer _user_data_);
static void geary_imap_db_account_fetch_email_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_account_fetch_email_async (GearyImapDBAccount* self,
                                              GearyImapDBEmailIdentifier* email_id,
                                              GearyEmailField required_fields,
                                              GCancellable* cancellable,
                                              GAsyncReadyCallback _callback_,
                                              gpointer _user_data_);
VALA_EXTERN GearyEmail* geary_imap_db_account_fetch_email_finish (GearyImapDBAccount* self,
                                                      GAsyncResult* _res_,
                                                      GError** error);
static gboolean geary_imap_db_account_fetch_email_async_co (GearyImapDbAccountFetchEmailAsyncData* _data_);
static Block44Data* block44_data_ref (Block44Data* _data44_);
static void block44_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda98_ (Block44Data* _data44_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GearyDbTransactionOutcome ___lambda98__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_account_fetch_email_async_ready (GObject* source_object,
                                                    GAsyncResult* _res_,
                                                    gpointer _user_data_);
static void geary_imap_db_account_get_containing_folders_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_account_get_containing_folders_async (GearyImapDBAccount* self,
                                                         GeeCollection* ids,
                                                         GeeMultiMap* map,
                                                         GCancellable* cancellable,
                                                         GAsyncReadyCallback _callback_,
                                                         gpointer _user_data_);
VALA_EXTERN void geary_imap_db_account_get_containing_folders_finish (GearyImapDBAccount* self,
                                                          GAsyncResult* _res_,
                                                          GError** error);
static gboolean geary_imap_db_account_get_containing_folders_async_co (GearyImapDbAccountGetContainingFoldersAsyncData* _data_);
static Block45Data* block45_data_ref (Block45Data* _data45_);
static void block45_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda99_ (Block45Data* _data45_,
                                       GearyDbConnection* cx,
                                       GCancellable* cancellable,
                                       GError** error);
static GearyDbTransactionOutcome ___lambda99__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_account_get_containing_folders_async_ready (GObject* source_object,
                                                               GAsyncResult* _res_,
                                                               gpointer _user_data_);
static void geary_imap_db_account_populate_search_table_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_account_populate_search_table (GearyImapDBAccount* self,
                                                  GCancellable* cancellable,
                                                  GAsyncReadyCallback _callback_,
                                                  gpointer _user_data_);
VALA_EXTERN void geary_imap_db_account_populate_search_table_finish (GearyImapDBAccount* self,
                                                         GAsyncResult* _res_);
static gboolean geary_imap_db_account_populate_search_table_co (GearyImapDbAccountPopulateSearchTableData* _data_);
static Block46Data* block46_data_ref (Block46Data* _data46_);
static void block46_data_unref (void * _userdata_);
static GearyDbTransactionOutcome ___lambda100_ (Block46Data* _data46_,
                                         GearyDbConnection* cx,
                                         GCancellable* cancellable,
                                         GError** error);
static GearyDbTransactionOutcome ____lambda100__geary_db_transaction_method (GearyDbConnection* cx,
                                                                      GCancellable* cancellable,
                                                                      gpointer self,
                                                                      GError** error);
static void geary_imap_db_account_populate_search_table_ready (GObject* source_object,
                                                        GAsyncResult* _res_,
                                                        gpointer _user_data_);
static void ___lambda101_ (Block46Data* _data46_,
                    GError** error);
static void ____lambda101__geary_nonblocking_concurrent_concurrent_callback (GCancellable* cancellable,
                                                                      gpointer self,
                                                                      GError** error);
static void geary_imap_db_account_populate_search_table_batch_async (GearyImapDBAccount* self,
                                                              gint limit,
                                                              GeeHashSet* unindexed_message_ids,
                                                              GCancellable* cancellable,
                                                              GAsyncReadyCallback _callback_,
                                                              gpointer _user_data_);
static void geary_imap_db_account_populate_search_table_batch_finish (GearyImapDBAccount* self,
                                                               GAsyncResult* _res_,
                                                               GError** error);
static void geary_imap_db_account_populate_search_table_batch_async_data_free (gpointer _data);
static gboolean geary_imap_db_account_populate_search_table_batch_async_co (GearyImapDbAccountPopulateSearchTableBatchAsyncData* _data_);
static Block47Data* block47_data_ref (Block47Data* _data47_);
static void block47_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda102_ (Block47Data* _data47_,
                                        GearyDbConnection* cx,
                                        GCancellable* cancellable,
                                        GError** error);
VALA_EXTERN void geary_imap_db_folder_do_add_email_to_search_table (GearyDbConnection* cx,
                                                        gint64 message_id,
                                                        GearyEmail* email,
                                                        GCancellable* cancellable,
                                                        GError** error);
static GearyDbTransactionOutcome ___lambda102__geary_db_transaction_method (GearyDbConnection* cx,
                                                                     GCancellable* cancellable,
                                                                     gpointer self,
                                                                     GError** error);
static void geary_imap_db_account_populate_search_table_batch_async_ready (GObject* source_object,
                                                                    GAsyncResult* _res_,
                                                                    gpointer _user_data_);
static GearyFolderPath* geary_imap_db_account_do_find_folder_path (GearyImapDBAccount* self,
                                                            GearyDbConnection* cx,
                                                            gint64 folder_id,
                                                            GCancellable* cancellable,
                                                            GError** error);
static void geary_imap_db_account_update_unread_async (GearyImapDBAccount* self,
                                                GearyImapDBFolder* source,
                                                GeeMap* unread_status,
                                                GCancellable* cancellable,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_);
static void geary_imap_db_account_update_unread_finish (GearyImapDBAccount* self,
                                                 GAsyncResult* _res_,
                                                 GError** error);
static void geary_imap_db_account_update_unread_async_data_free (gpointer _data);
static gboolean geary_imap_db_account_update_unread_async_co (GearyImapDbAccountUpdateUnreadAsyncData* _data_);
static Block48Data* block48_data_ref (Block48Data* _data48_);
static void block48_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda89_ (Block48Data* _data48_,
                                       GearyDbConnection* cx,
                                       GError** error);
VALA_EXTERN GearyFolderPath* geary_imap_db_folder_get_path (GearyImapDBFolder* self);
VALA_EXTERN void geary_imap_db_folder_do_add_to_unread_count (GearyImapDBFolder* self,
                                                  GearyDbConnection* cx,
                                                  gint to_add,
                                                  GCancellable* cancellable,
                                                  GError** error);
static GearyDbTransactionOutcome ___lambda89__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_account_update_unread_async_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_);
VALA_EXTERN GearyImapFolderProperties* geary_imap_db_folder_get_properties (GearyImapDBFolder* self);
VALA_EXTERN GearyDbStatement* geary_fts_search_query_get_match_query (GearyFtsSearchQuery* self,
                                                          GearyDbConnection* cx,
                                                          const gchar* search_ids_sql,
                                                          GError** error);
static void geary_imap_db_account_delete_all_data_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_account_delete_all_data (GearyImapDBAccount* self,
                                            GCancellable* cancellable,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_);
VALA_EXTERN void geary_imap_db_account_delete_all_data_finish (GearyImapDBAccount* self,
                                                   GAsyncResult* _res_,
                                                   GError** error);
static gboolean geary_imap_db_account_delete_all_data_co (GearyImapDbAccountDeleteAllDataData* _data_);
static void geary_imap_db_account_delete_all_data_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_);
static void geary_imap_db_account_folder_reference_finalize (GObject * obj);
static GType geary_imap_db_account_folder_reference_get_type_once (void);
static void geary_imap_db_account_finalize (GObject * obj);
static GType geary_imap_db_account_get_type_once (void);
static void _vala_geary_imap_db_account_get_property (GObject * object,
                                               guint property_id,
                                               GValue * value,
                                               GParamSpec * pspec);
static void _vala_geary_imap_db_account_set_property (GObject * object,
                                               guint property_id,
                                               const GValue * value,
                                               GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static gssize _vala_array_length (gpointer array);

static inline gpointer
geary_imap_db_account_get_instance_private (GearyImapDBAccount* self)
{
	return G_STRUCT_MEMBER_P (self, GearyImapDBAccount_private_offset);
}

GearyImapFolderRoot*
geary_imap_db_account_get_imap_folder_root (GearyImapDBAccount* self)
{
	GearyImapFolderRoot* result;
	GearyImapFolderRoot* _tmp0_;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self), NULL);
	_tmp0_ = self->priv->_imap_folder_root;
	result = _tmp0_;
	return result;
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static void
geary_imap_db_account_set_imap_folder_root (GearyImapDBAccount* self,
                                            GearyImapFolderRoot* value)
{
	GearyImapFolderRoot* old_value;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	old_value = geary_imap_db_account_get_imap_folder_root (self);
	if (old_value != value) {
		GearyImapFolderRoot* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_imap_folder_root);
		self->priv->_imap_folder_root = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_db_account_properties[GEARY_IMAP_DB_ACCOUNT_IMAP_FOLDER_ROOT_PROPERTY]);
	}
}

GearySimpleProgressMonitor*
geary_imap_db_account_get_upgrade_monitor (GearyImapDBAccount* self)
{
	GearySimpleProgressMonitor* result;
	GearySimpleProgressMonitor* _tmp0_;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self), NULL);
	_tmp0_ = self->priv->_upgrade_monitor;
	result = _tmp0_;
	return result;
}

static void
geary_imap_db_account_set_upgrade_monitor (GearyImapDBAccount* self,
                                           GearySimpleProgressMonitor* value)
{
	GearySimpleProgressMonitor* old_value;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	old_value = geary_imap_db_account_get_upgrade_monitor (self);
	if (old_value != value) {
		GearySimpleProgressMonitor* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_upgrade_monitor);
		self->priv->_upgrade_monitor = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_db_account_properties[GEARY_IMAP_DB_ACCOUNT_UPGRADE_MONITOR_PROPERTY]);
	}
}

GearySimpleProgressMonitor*
geary_imap_db_account_get_vacuum_monitor (GearyImapDBAccount* self)
{
	GearySimpleProgressMonitor* result;
	GearySimpleProgressMonitor* _tmp0_;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self), NULL);
	_tmp0_ = self->priv->_vacuum_monitor;
	result = _tmp0_;
	return result;
}

static void
geary_imap_db_account_set_vacuum_monitor (GearyImapDBAccount* self,
                                          GearySimpleProgressMonitor* value)
{
	GearySimpleProgressMonitor* old_value;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	old_value = geary_imap_db_account_get_vacuum_monitor (self);
	if (old_value != value) {
		GearySimpleProgressMonitor* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_vacuum_monitor);
		self->priv->_vacuum_monitor = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_db_account_properties[GEARY_IMAP_DB_ACCOUNT_VACUUM_MONITOR_PROPERTY]);
	}
}

GearyImapDBDatabase*
geary_imap_db_account_get_db (GearyImapDBAccount* self)
{
	GearyImapDBDatabase* result;
	GearyImapDBDatabase* _tmp0_;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self), NULL);
	_tmp0_ = self->priv->_db;
	result = _tmp0_;
	return result;
}

static void
geary_imap_db_account_set_db (GearyImapDBAccount* self,
                              GearyImapDBDatabase* value)
{
	GearyImapDBDatabase* old_value;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	old_value = geary_imap_db_account_get_db (self);
	if (old_value != value) {
		GearyImapDBDatabase* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_db);
		self->priv->_db = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_db_account_properties[GEARY_IMAP_DB_ACCOUNT_DB_PROPERTY]);
	}
}

GearyAccountInformation*
geary_imap_db_account_get_account_information (GearyImapDBAccount* self)
{
	GearyAccountInformation* result;
	GearyAccountInformation* _tmp0_;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self), NULL);
	_tmp0_ = self->priv->_account_information;
	result = _tmp0_;
	return result;
}

static void
geary_imap_db_account_set_account_information (GearyImapDBAccount* self,
                                               GearyAccountInformation* value)
{
	GearyAccountInformation* old_value;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	old_value = geary_imap_db_account_get_account_information (self);
	if (old_value != value) {
		GearyAccountInformation* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_account_information);
		self->priv->_account_information = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_db_account_properties[GEARY_IMAP_DB_ACCOUNT_ACCOUNT_INFORMATION_PROPERTY]);
	}
}

GearyImapDBAccount*
geary_imap_db_account_construct (GType object_type,
                                 GearyAccountInformation* config,
                                 GFile* data_dir,
                                 GFile* schema_dir)
{
	GearyImapDBAccount * self = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	GFile* _tmp3_;
	GFile* _tmp4_;
	GFile* _tmp5_;
	GFile* _tmp6_;
	GearySimpleProgressMonitor* _tmp7_;
	GearySimpleProgressMonitor* _tmp8_;
	GearyImapDBDatabase* _tmp9_;
	GearyImapDBDatabase* _tmp10_;
	g_return_val_if_fail (GEARY_IS_ACCOUNT_INFORMATION (config), NULL);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (data_dir, g_file_get_type ()), NULL);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (schema_dir, g_file_get_type ()), NULL);
	self = (GearyImapDBAccount*) geary_base_object_construct (object_type);
	geary_imap_db_account_set_account_information (self, config);
	_tmp0_ = geary_account_information_get_id (config);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strconcat (_tmp1_, ":db", NULL);
	_g_free0 (self->priv->name);
	self->priv->name = _tmp2_;
	_tmp3_ = g_file_get_child (data_dir, GEARY_IMAP_DB_ACCOUNT_DB_FILENAME);
	_g_object_unref0 (self->priv->db_file);
	self->priv->db_file = _tmp3_;
	_tmp4_ = g_file_get_child (data_dir, GEARY_IMAP_DB_ACCOUNT_ATTACHMENTS_DIR);
	_g_object_unref0 (self->priv->attachments_dir);
	self->priv->attachments_dir = _tmp4_;
	_tmp5_ = self->priv->db_file;
	_tmp6_ = self->priv->attachments_dir;
	_tmp7_ = self->priv->_upgrade_monitor;
	_tmp8_ = self->priv->_vacuum_monitor;
	_tmp9_ = geary_imap_db_database_new (_tmp5_, schema_dir, _tmp6_, G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, GEARY_TYPE_PROGRESS_MONITOR, GearyProgressMonitor), G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, GEARY_TYPE_PROGRESS_MONITOR, GearyProgressMonitor));
	_tmp10_ = _tmp9_;
	geary_imap_db_account_set_db (self, _tmp10_);
	_g_object_unref0 (_tmp10_);
	return self;
}

GearyImapDBAccount*
geary_imap_db_account_new (GearyAccountInformation* config,
                           GFile* data_dir,
                           GFile* schema_dir)
{
	return geary_imap_db_account_construct (GEARY_IMAP_DB_TYPE_ACCOUNT, config, data_dir, schema_dir);
}

static void
geary_imap_db_account_open_async_data_free (gpointer _data)
{
	GearyImapDbAccountOpenAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbAccountOpenAsyncData, _data_);
}

void
geary_imap_db_account_open_async (GearyImapDBAccount* self,
                                  GCancellable* cancellable,
                                  GAsyncReadyCallback _callback_,
                                  gpointer _user_data_)
{
	GearyImapDbAccountOpenAsyncData* _data_;
	GearyImapDBAccount* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbAccountOpenAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_account_open_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_db_account_open_async_co (_data_);
}

void
geary_imap_db_account_open_finish (GearyImapDBAccount* self,
                                   GAsyncResult* _res_,
                                   GError** error)
{
	GearyImapDbAccountOpenAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static Block33Data*
block33_data_ref (Block33Data* _data33_)
{
	g_atomic_int_inc (&_data33_->_ref_count_);
	return _data33_;
}

static void
block33_data_unref (void * _userdata_)
{
	Block33Data* _data33_;
	_data33_ = (Block33Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data33_->_ref_count_)) {
		GearyImapDBAccount* self;
		self = _data33_->self;
		_g_object_unref0 (_data33_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block33Data, _data33_);
	}
}

static void
geary_imap_db_account_open_async_ready (GObject* source_object,
                                        GAsyncResult* _res_,
                                        gpointer _user_data_)
{
	GearyImapDbAccountOpenAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_account_open_async_co (_data_);
}

static gpointer
_g_error_copy0 (gpointer self)
{
	return self ? g_error_copy (self) : NULL;
}

static GearyDbTransactionOutcome
___lambda86_ (Block33Data* _data33_,
              GearyDbConnection* cx,
              GError** error)
{
	GearyImapDBAccount* self;
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbResult* results = NULL;
	GearyDbStatement* _tmp1_;
	GearyDbResult* _tmp2_;
	gboolean found = FALSE;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data33_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_db_connection_prepare (cx, "\n" \
"                    SELECT id, name\n" \
"                    FROM FolderTable\n" \
"                    WHERE parent_id IS NULL\n" \
"                    ORDER BY id\n" \
"                ", &_inner_error0_);
	stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp1_ = stmt;
	_tmp2_ = geary_db_statement_exec (_tmp1_, _data33_->cancellable, &_inner_error0_);
	results = _tmp2_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	found = FALSE;
	while (TRUE) {
		GearyDbResult* _tmp3_;
		gboolean _tmp4_;
		gboolean _tmp5_;
		gchar* name = NULL;
		GearyDbResult* _tmp6_;
		const gchar* _tmp7_;
		gchar* _tmp8_;
		const gchar* _tmp9_;
		GearyDbResult* _tmp16_;
		_tmp3_ = results;
		_tmp4_ = geary_db_result_get_finished (_tmp3_);
		_tmp5_ = _tmp4_;
		if (!(!_tmp5_)) {
			break;
		}
		_tmp6_ = results;
		_tmp7_ = geary_db_result_string_for (_tmp6_, "name", &_inner_error0_);
		_tmp8_ = g_strdup (_tmp7_);
		name = _tmp8_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp9_ = name;
		if (geary_imap_mailbox_specifier_is_inbox_name (_tmp9_)) {
			gboolean _tmp10_ = FALSE;
			if (!found) {
				const gchar* _tmp11_;
				_tmp11_ = name;
				_tmp10_ = geary_imap_mailbox_specifier_is_canonical_inbox_name (_tmp11_);
			} else {
				_tmp10_ = FALSE;
			}
			if (_tmp10_) {
				found = TRUE;
			} else {
				const gchar* _tmp12_;
				const gchar* _tmp13_;
				gint64 _tmp14_ = 0LL;
				GearyDbResult* _tmp15_;
				_tmp12_ = self->priv->name;
				_tmp13_ = name;
				g_warning ("imap-db-account.vala:121: %s: Removing duplicate INBOX \"%s\"", _tmp12_, _tmp13_);
				_tmp15_ = results;
				_tmp14_ = geary_db_result_rowid_for (_tmp15_, "id", &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					g_propagate_error (error, _inner_error0_);
					_g_free0 (name);
					_g_object_unref0 (results);
					_g_object_unref0 (stmt);
					return 0;
				}
				geary_imap_db_account_do_delete_folder (self, cx, _tmp14_, _data33_->cancellable, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					g_propagate_error (error, _inner_error0_);
					_g_free0 (name);
					_g_object_unref0 (results);
					_g_object_unref0 (stmt);
					return 0;
				}
			}
		}
		_tmp16_ = results;
		geary_db_result_next (_tmp16_, _data33_->cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_free0 (name);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			return 0;
		}
		_g_free0 (name);
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_COMMIT;
	_g_object_unref0 (results);
	_g_object_unref0 (stmt);
	return result;
}

static GearyDbTransactionOutcome
____lambda86__geary_db_transaction_method (GearyDbConnection* cx,
                                           GCancellable* cancellable,
                                           gpointer self,
                                           GError** error)
{
	GearyDbTransactionOutcome result;
	result = ___lambda86_ (self, cx, error);
	return result;
}

static gboolean
geary_imap_db_account_open_async_co (GearyImapDbAccountOpenAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data33_ = g_slice_new0 (Block33Data);
	_data_->_data33_->_ref_count_ = 1;
	_data_->_data33_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data33_->cancellable);
	_data_->_data33_->cancellable = _data_->cancellable;
	_data_->_data33_->_async_data_ = _data_;
	_data_->_tmp0_ = _data_->self->priv->_db;
	_data_->_tmp1_ = geary_db_database_get_is_open (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase));
	_data_->_tmp2_ = _data_->_tmp1_;
	if (_data_->_tmp2_) {
		_data_->_tmp3_ = g_error_new_literal (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_ALREADY_OPEN, "IMAP database already open");
		_data_->_inner_error0_ = _data_->_tmp3_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block33_data_unref (_data_->_data33_);
		_data_->_data33_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	{
		_data_->_tmp4_ = _data_->self->priv->_db;
		_data_->_state_ = 1;
		geary_imap_db_database_open (_data_->_tmp4_, (GEARY_DB_DATABASE_FLAGS_CREATE_DIRECTORY | GEARY_DB_DATABASE_FLAGS_CREATE_FILE) | GEARY_DB_DATABASE_FLAGS_CHECK_CORRUPTION, _data_->_data33_->cancellable, geary_imap_db_account_open_async_ready, _data_);
		return FALSE;
		_state_1:
		geary_imap_db_database_open_finish (_data_->_tmp4_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->err = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp5_ = _data_->err;
		_data_->_tmp6_ = _data_->_tmp5_->message;
		g_warning ("imap-db-account.vala:87: Unable to open database: %s", _data_->_tmp6_);
		_data_->_tmp7_ = _data_->self->priv->_db;
		geary_db_database_close (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp7_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), NULL, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_error_free0 (_data_->err);
			goto __finally0;
		}
		_data_->_tmp8_ = _data_->err;
		_data_->_tmp9_ = _g_error_copy0 (_data_->_tmp8_);
		_data_->_inner_error0_ = _data_->_tmp9_;
		_g_error_free0 (_data_->err);
		goto __finally0;
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block33_data_unref (_data_->_data33_);
		_data_->_data33_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	{
		_data_->_tmp10_ = _data_->self->priv->_db;
		_data_->_state_ = 2;
		geary_db_database_exec_transaction_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp10_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), GEARY_DB_TRANSACTION_TYPE_RW, ____lambda86__geary_db_transaction_method, _data_->_data33_, _data_->_data33_->cancellable, geary_imap_db_account_open_async_ready, _data_);
		return FALSE;
		_state_2:
		geary_db_database_exec_transaction_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp10_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch1_g_error;
		}
	}
	goto __finally1;
	__catch1_g_error:
	{
		_data_->_vala1_err = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp11_ = _data_->_vala1_err;
		_data_->_tmp12_ = _data_->_tmp11_->message;
		g_debug ("imap-db-account.vala:135: Error trimming duplicate INBOX from database" \
": %s", _data_->_tmp12_);
		geary_imap_db_account_set_db (_data_->self, NULL);
		_data_->_tmp13_ = _data_->_vala1_err;
		_data_->_tmp14_ = _g_error_copy0 (_data_->_tmp13_);
		_data_->_inner_error0_ = _data_->_tmp14_;
		_g_error_free0 (_data_->_vala1_err);
		goto __finally1;
	}
	__finally1:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block33_data_unref (_data_->_data33_);
		_data_->_data33_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp15_ = g_cancellable_new ();
	_g_object_unref0 (_data_->self->priv->background_cancellable);
	_data_->self->priv->background_cancellable = _data_->_tmp15_;
	block33_data_unref (_data_->_data33_);
	_data_->_data33_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_db_account_close_async_data_free (gpointer _data)
{
	GearyImapDbAccountCloseAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbAccountCloseAsyncData, _data_);
}

void
geary_imap_db_account_close_async (GearyImapDBAccount* self,
                                   GCancellable* cancellable,
                                   GAsyncReadyCallback _callback_,
                                   gpointer _user_data_)
{
	GearyImapDbAccountCloseAsyncData* _data_;
	GearyImapDBAccount* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbAccountCloseAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_account_close_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_db_account_close_async_co (_data_);
}

void
geary_imap_db_account_close_finish (GearyImapDBAccount* self,
                                    GAsyncResult* _res_,
                                    GError** error)
{
	GearyImapDbAccountCloseAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static gboolean
geary_imap_db_account_close_async_co (GearyImapDbAccountCloseAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->_db;
	if (_data_->_tmp0_ == NULL) {
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	{
		_data_->_tmp1_ = _data_->self->priv->_db;
		geary_db_database_close (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), _data_->cancellable, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __finally0;
		}
	}
	__finally0:
	{
		geary_imap_db_account_set_db (_data_->self, NULL);
	}
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp2_ = _data_->self->priv->background_cancellable;
	g_cancellable_cancel (_data_->_tmp2_);
	_g_object_unref0 (_data_->self->priv->background_cancellable);
	_data_->self->priv->background_cancellable = NULL;
	_data_->_tmp3_ = _data_->self->priv->folder_refs;
	gee_abstract_map_clear (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp3_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap));
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_db_account_clone_folder_async_data_free (gpointer _data)
{
	GearyImapDbAccountCloneFolderAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->imap_folder);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbAccountCloneFolderAsyncData, _data_);
}

void
geary_imap_db_account_clone_folder_async (GearyImapDBAccount* self,
                                          GearyImapFolder* imap_folder,
                                          GCancellable* cancellable,
                                          GAsyncReadyCallback _callback_,
                                          gpointer _user_data_)
{
	GearyImapDbAccountCloneFolderAsyncData* _data_;
	GearyImapDBAccount* _tmp0_;
	GearyImapFolder* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail (GEARY_IMAP_IS_FOLDER (imap_folder));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbAccountCloneFolderAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_account_clone_folder_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (imap_folder);
	_g_object_unref0 (_data_->imap_folder);
	_data_->imap_folder = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_account_clone_folder_async_co (_data_);
}

GearyImapDBFolder*
geary_imap_db_account_clone_folder_finish (GearyImapDBAccount* self,
                                           GAsyncResult* _res_,
                                           GError** error)
{
	GearyImapDBFolder* result;
	GearyImapDbAccountCloneFolderAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block34Data*
block34_data_ref (Block34Data* _data34_)
{
	g_atomic_int_inc (&_data34_->_ref_count_);
	return _data34_;
}

static void
block34_data_unref (void * _userdata_)
{
	Block34Data* _data34_;
	_data34_ = (Block34Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data34_->_ref_count_)) {
		GearyImapDBAccount* self;
		self = _data34_->self;
		_g_object_unref0 (_data34_->path);
		_g_object_unref0 (_data34_->properties);
		_g_object_unref0 (_data34_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block34Data, _data34_);
	}
}

static GearyDbTransactionOutcome
__lambda87_ (Block34Data* _data34_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBAccount* self;
	gint64 parent_id = 0LL;
	gboolean _tmp0_ = FALSE;
	GearyFolderPath* _tmp1_;
	gint64 _tmp2_ = 0LL;
	gboolean _tmp3_;
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp7_;
	GearyDbStatement* _tmp8_;
	GearyFolderPath* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	GearyDbStatement* _tmp12_;
	GearyDbStatement* _tmp13_;
	GearyDbStatement* _tmp14_;
	GearyDbStatement* _tmp15_;
	GearyDbStatement* _tmp16_;
	GearyDbStatement* _tmp17_;
	GearyImapFolderProperties* _tmp18_;
	gint _tmp19_;
	gint _tmp20_;
	GearyDbStatement* _tmp21_;
	GearyDbStatement* _tmp22_;
	GearyDbStatement* _tmp23_;
	GearyImapFolderProperties* _tmp24_;
	gint _tmp25_;
	gint _tmp26_;
	GearyDbStatement* _tmp27_;
	GearyDbStatement* _tmp28_;
	gint64 _tmp29_ = 0LL;
	GearyImapFolderProperties* _tmp30_;
	GearyImapUIDValidity* _tmp31_;
	GearyImapUIDValidity* _tmp32_;
	GearyDbStatement* _tmp38_;
	GearyDbStatement* _tmp39_;
	GearyDbStatement* _tmp40_;
	gint64 _tmp41_ = 0LL;
	GearyImapFolderProperties* _tmp42_;
	GearyImapUID* _tmp43_;
	GearyImapUID* _tmp44_;
	GearyDbStatement* _tmp50_;
	GearyDbStatement* _tmp51_;
	GearyDbStatement* _tmp52_;
	GearyDbStatement* _tmp53_;
	GearyImapFolderProperties* _tmp54_;
	GearyImapMailboxAttributes* _tmp55_;
	GearyImapMailboxAttributes* _tmp56_;
	gchar* _tmp57_;
	gchar* _tmp58_;
	GearyDbStatement* _tmp59_;
	GearyDbStatement* _tmp60_;
	GearyDbStatement* _tmp61_;
	GearyImapFolderProperties* _tmp62_;
	gint _tmp63_;
	gint _tmp64_;
	GearyDbStatement* _tmp65_;
	GearyDbStatement* _tmp66_;
	GearyDbStatement* _tmp67_;
	GearyDbResult* _tmp68_;
	GearyDbResult* _tmp69_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data34_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	parent_id = GEARY_DB_INVALID_ROWID;
	_tmp1_ = _data34_->path;
	_tmp3_ = geary_imap_db_account_do_fetch_parent_id (self, cx, _tmp1_, TRUE, &_tmp2_, _data34_->cancellable, &_inner_error0_);
	parent_id = _tmp2_;
	_tmp0_ = _tmp3_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	if (!_tmp0_) {
		GearyFolderPath* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp4_ = _data34_->path;
		_tmp5_ = geary_folder_path_to_string (_tmp4_);
		_tmp6_ = _tmp5_;
		g_debug ("imap-db-account.vala:192: Unable to find parent ID to %s clone folder", _tmp6_);
		_g_free0 (_tmp6_);
		result = GEARY_DB_TRANSACTION_OUTCOME_ROLLBACK;
		return result;
	}
	_tmp7_ = geary_db_connection_prepare (cx, "INSERT INTO FolderTable (name, parent_id, last_seen_total, last_seen_s" \
"tatus_total, " "uid_validity, uid_next, attributes, unread_count) VALUES (?, ?, ?, ?, " \
"?, ?, ?, ?)", &_inner_error0_);
	stmt = _tmp7_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp8_ = stmt;
	_tmp9_ = _data34_->path;
	_tmp10_ = geary_folder_path_get_name (_tmp9_);
	_tmp11_ = _tmp10_;
	_tmp12_ = geary_db_statement_bind_string (_tmp8_, 0, _tmp11_, &_inner_error0_);
	_tmp13_ = _tmp12_;
	_g_object_unref0 (_tmp13_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp14_ = stmt;
	_tmp15_ = geary_db_statement_bind_rowid (_tmp14_, 1, parent_id, &_inner_error0_);
	_tmp16_ = _tmp15_;
	_g_object_unref0 (_tmp16_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp17_ = stmt;
	_tmp18_ = _data34_->properties;
	_tmp19_ = geary_imap_folder_properties_get_select_examine_messages (_tmp18_);
	_tmp20_ = _tmp19_;
	_tmp21_ = geary_db_statement_bind_int (_tmp17_, 2, geary_numeric_int_floor (_tmp20_, 0), &_inner_error0_);
	_tmp22_ = _tmp21_;
	_g_object_unref0 (_tmp22_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp23_ = stmt;
	_tmp24_ = _data34_->properties;
	_tmp25_ = geary_imap_folder_properties_get_status_messages (_tmp24_);
	_tmp26_ = _tmp25_;
	_tmp27_ = geary_db_statement_bind_int (_tmp23_, 3, geary_numeric_int_floor (_tmp26_, 0), &_inner_error0_);
	_tmp28_ = _tmp27_;
	_g_object_unref0 (_tmp28_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp30_ = _data34_->properties;
	_tmp31_ = geary_imap_folder_properties_get_uid_validity (_tmp30_);
	_tmp32_ = _tmp31_;
	if (_tmp32_ != NULL) {
		GearyImapFolderProperties* _tmp33_;
		GearyImapUIDValidity* _tmp34_;
		GearyImapUIDValidity* _tmp35_;
		gint64 _tmp36_;
		gint64 _tmp37_;
		_tmp33_ = _data34_->properties;
		_tmp34_ = geary_imap_folder_properties_get_uid_validity (_tmp33_);
		_tmp35_ = _tmp34_;
		_tmp36_ = geary_message_data_int64_message_data_get_value (G_TYPE_CHECK_INSTANCE_CAST (_tmp35_, GEARY_MESSAGE_DATA_TYPE_INT64_MESSAGE_DATA, GearyMessageDataInt64MessageData));
		_tmp37_ = _tmp36_;
		_tmp29_ = _tmp37_;
	} else {
		_tmp29_ = GEARY_IMAP_UID_VALIDITY_INVALID;
	}
	_tmp38_ = stmt;
	_tmp39_ = geary_db_statement_bind_int64 (_tmp38_, 4, _tmp29_, &_inner_error0_);
	_tmp40_ = _tmp39_;
	_g_object_unref0 (_tmp40_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp42_ = _data34_->properties;
	_tmp43_ = geary_imap_folder_properties_get_uid_next (_tmp42_);
	_tmp44_ = _tmp43_;
	if (_tmp44_ != NULL) {
		GearyImapFolderProperties* _tmp45_;
		GearyImapUID* _tmp46_;
		GearyImapUID* _tmp47_;
		gint64 _tmp48_;
		gint64 _tmp49_;
		_tmp45_ = _data34_->properties;
		_tmp46_ = geary_imap_folder_properties_get_uid_next (_tmp45_);
		_tmp47_ = _tmp46_;
		_tmp48_ = geary_message_data_int64_message_data_get_value (G_TYPE_CHECK_INSTANCE_CAST (_tmp47_, GEARY_MESSAGE_DATA_TYPE_INT64_MESSAGE_DATA, GearyMessageDataInt64MessageData));
		_tmp49_ = _tmp48_;
		_tmp41_ = _tmp49_;
	} else {
		_tmp41_ = GEARY_IMAP_UID_INVALID;
	}
	_tmp50_ = stmt;
	_tmp51_ = geary_db_statement_bind_int64 (_tmp50_, 5, _tmp41_, &_inner_error0_);
	_tmp52_ = _tmp51_;
	_g_object_unref0 (_tmp52_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp53_ = stmt;
	_tmp54_ = _data34_->properties;
	_tmp55_ = geary_imap_folder_properties_get_attrs (_tmp54_);
	_tmp56_ = _tmp55_;
	_tmp57_ = geary_imap_flags_serialize (G_TYPE_CHECK_INSTANCE_CAST (_tmp56_, GEARY_IMAP_TYPE_FLAGS, GearyImapFlags));
	_tmp58_ = _tmp57_;
	_tmp59_ = geary_db_statement_bind_string (_tmp53_, 6, _tmp58_, &_inner_error0_);
	_tmp60_ = _tmp59_;
	_g_object_unref0 (_tmp60_);
	_g_free0 (_tmp58_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp61_ = stmt;
	_tmp62_ = _data34_->properties;
	_tmp63_ = geary_folder_properties_get_email_unread (G_TYPE_CHECK_INSTANCE_CAST (_tmp62_, GEARY_TYPE_FOLDER_PROPERTIES, GearyFolderProperties));
	_tmp64_ = _tmp63_;
	_tmp65_ = geary_db_statement_bind_int (_tmp61_, 7, _tmp64_, &_inner_error0_);
	_tmp66_ = _tmp65_;
	_g_object_unref0 (_tmp66_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp67_ = stmt;
	_tmp68_ = geary_db_statement_exec (_tmp67_, _data34_->cancellable, &_inner_error0_);
	_tmp69_ = _tmp68_;
	_g_object_unref0 (_tmp69_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_COMMIT;
	_g_object_unref0 (stmt);
	return result;
}

static GearyDbTransactionOutcome
___lambda87__geary_db_transaction_method (GearyDbConnection* cx,
                                          GCancellable* cancellable,
                                          gpointer self,
                                          GError** error)
{
	GearyDbTransactionOutcome result;
	result = __lambda87_ (self, cx, error);
	return result;
}

static void
geary_imap_db_account_clone_folder_async_ready (GObject* source_object,
                                                GAsyncResult* _res_,
                                                gpointer _user_data_)
{
	GearyImapDbAccountCloneFolderAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_account_clone_folder_async_co (_data_);
}

static gboolean
geary_imap_db_account_clone_folder_async_co (GearyImapDbAccountCloneFolderAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data34_ = g_slice_new0 (Block34Data);
	_data_->_data34_->_ref_count_ = 1;
	_data_->_data34_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data34_->cancellable);
	_data_->_data34_->cancellable = _data_->cancellable;
	_data_->_data34_->_async_data_ = _data_;
	geary_imap_db_account_check_open (_data_->self, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block34_data_unref (_data_->_data34_);
		_data_->_data34_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp0_ = geary_imap_folder_get_properties (_data_->imap_folder);
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = _g_object_ref0 (_data_->_tmp1_);
	_data_->_data34_->properties = _data_->_tmp2_;
	_data_->_tmp3_ = geary_imap_folder_get_path (_data_->imap_folder);
	_data_->_tmp4_ = _data_->_tmp3_;
	_data_->_tmp5_ = _g_object_ref0 (_data_->_tmp4_);
	_data_->_data34_->path = _data_->_tmp5_;
	_data_->_tmp6_ = _data_->_data34_->path;
	_data_->_tmp7_ = geary_imap_db_account_get_local_folder (_data_->self, _data_->_tmp6_);
	_data_->folder = _data_->_tmp7_;
	_data_->_tmp8_ = _data_->folder;
	if (_data_->_tmp8_ != NULL) {
		_data_->_tmp9_ = _data_->_data34_->path;
		_data_->_tmp10_ = geary_folder_path_to_string (_data_->_tmp9_);
		_data_->_tmp11_ = _data_->_tmp10_;
		_data_->_tmp12_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_ALREADY_EXISTS, "Folder with path already exists: %s", _data_->_tmp11_);
		_data_->_tmp13_ = _data_->_tmp12_;
		_g_free0 (_data_->_tmp11_);
		_data_->_inner_error0_ = _data_->_tmp13_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->folder);
		block34_data_unref (_data_->_data34_);
		_data_->_data34_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp15_ = _data_->_data34_->path;
	if (geary_imap_mailbox_specifier_folder_path_is_inbox (_data_->_tmp15_)) {
		_data_->_tmp16_ = _data_->_data34_->path;
		_data_->_tmp17_ = geary_folder_path_get_name (_data_->_tmp16_);
		_data_->_tmp18_ = _data_->_tmp17_;
		_data_->_tmp14_ = !geary_imap_mailbox_specifier_is_canonical_inbox_name (_data_->_tmp18_);
	} else {
		_data_->_tmp14_ = FALSE;
	}
	if (_data_->_tmp14_) {
		_data_->_tmp19_ = _data_->_data34_->path;
		_data_->_tmp20_ = geary_folder_path_to_string (_data_->_tmp19_);
		_data_->_tmp21_ = _data_->_tmp20_;
		_data_->_tmp22_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_NOT_SUPPORTED, "Inbox has : %s", _data_->_tmp21_);
		_data_->_tmp23_ = _data_->_tmp22_;
		_g_free0 (_data_->_tmp21_);
		_data_->_inner_error0_ = _data_->_tmp23_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->folder);
		block34_data_unref (_data_->_data34_);
		_data_->_data34_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp24_ = _data_->self->priv->_db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp24_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), GEARY_DB_TRANSACTION_TYPE_RW, ___lambda87__geary_db_transaction_method, _data_->_data34_, _data_->_data34_->cancellable, geary_imap_db_account_clone_folder_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp24_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->folder);
		block34_data_unref (_data_->_data34_);
		_data_->_data34_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp26_ = _data_->_data34_->path;
	_data_->_state_ = 2;
	geary_imap_db_account_fetch_folder_async (_data_->self, _data_->_tmp26_, _data_->_data34_->cancellable, geary_imap_db_account_clone_folder_async_ready, _data_);
	return FALSE;
	_state_2:
	_data_->_tmp27_ = geary_imap_db_account_fetch_folder_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp25_ = _data_->_tmp27_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->folder);
		block34_data_unref (_data_->_data34_);
		_data_->_data34_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp28_ = _data_->_tmp25_;
	_data_->_tmp25_ = NULL;
	_data_->result = _data_->_tmp28_;
	_g_object_unref0 (_data_->_tmp25_);
	_g_object_unref0 (_data_->folder);
	block34_data_unref (_data_->_data34_);
	_data_->_data34_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_db_account_delete_folder_async_data_free (gpointer _data)
{
	GearyImapDbAccountDeleteFolderAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbAccountDeleteFolderAsyncData, _data_);
}

void
geary_imap_db_account_delete_folder_async (GearyImapDBAccount* self,
                                           GearyFolderPath* path,
                                           GCancellable* cancellable,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_)
{
	GearyImapDbAccountDeleteFolderAsyncData* _data_;
	GearyImapDBAccount* _tmp0_;
	GearyFolderPath* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail (GEARY_IS_FOLDER_PATH (path));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbAccountDeleteFolderAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_account_delete_folder_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (path);
	_g_object_unref0 (_data_->path);
	_data_->path = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_account_delete_folder_async_co (_data_);
}

void
geary_imap_db_account_delete_folder_finish (GearyImapDBAccount* self,
                                            GAsyncResult* _res_,
                                            GError** error)
{
	GearyImapDbAccountDeleteFolderAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static Block35Data*
block35_data_ref (Block35Data* _data35_)
{
	g_atomic_int_inc (&_data35_->_ref_count_);
	return _data35_;
}

static void
block35_data_unref (void * _userdata_)
{
	Block35Data* _data35_;
	_data35_ = (Block35Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data35_->_ref_count_)) {
		GearyImapDBAccount* self;
		self = _data35_->self;
		_g_object_unref0 (_data35_->path);
		_g_object_unref0 (_data35_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block35Data, _data35_);
	}
}

static GearyDbTransactionOutcome
__lambda90_ (Block35Data* _data35_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBAccount* self;
	gint64 folder_id = 0LL;
	gint64 _tmp0_ = 0LL;
	gboolean _tmp5_ = FALSE;
	GeeHashMap* _tmp10_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data35_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	geary_imap_db_account_do_fetch_folder_id (self, cx, _data35_->path, FALSE, &_tmp0_, _data35_->cancellable, &_inner_error0_);
	folder_id = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	if (folder_id == GEARY_DB_INVALID_ROWID) {
		gchar* _tmp1_;
		gchar* _tmp2_;
		GError* _tmp3_;
		GError* _tmp4_;
		_tmp1_ = geary_folder_path_to_string (_data35_->path);
		_tmp2_ = _tmp1_;
		_tmp3_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_NOT_FOUND, "Folder not found: %s", _tmp2_);
		_tmp4_ = _tmp3_;
		_g_free0 (_tmp2_);
		_inner_error0_ = _tmp4_;
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp5_ = geary_imap_db_account_do_has_children (self, cx, folder_id, _data35_->cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	if (_tmp5_) {
		gchar* _tmp6_;
		gchar* _tmp7_;
		GError* _tmp8_;
		GError* _tmp9_;
		_tmp6_ = geary_folder_path_to_string (_data35_->path);
		_tmp7_ = _tmp6_;
		_tmp8_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_NOT_SUPPORTED, "Folder has children: %s", _tmp7_);
		_tmp9_ = _tmp8_;
		_g_free0 (_tmp7_);
		_inner_error0_ = _tmp9_;
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	geary_imap_db_account_do_delete_folder (self, cx, folder_id, _data35_->cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp10_ = self->priv->folder_refs;
	gee_abstract_map_unset (G_TYPE_CHECK_INSTANCE_CAST (_tmp10_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _data35_->path, NULL);
	result = GEARY_DB_TRANSACTION_OUTCOME_COMMIT;
	return result;
}

static GearyDbTransactionOutcome
___lambda90__geary_db_transaction_method (GearyDbConnection* cx,
                                          GCancellable* cancellable,
                                          gpointer self,
                                          GError** error)
{
	GearyDbTransactionOutcome result;
	result = __lambda90_ (self, cx, error);
	return result;
}

static void
geary_imap_db_account_delete_folder_async_ready (GObject* source_object,
                                                 GAsyncResult* _res_,
                                                 gpointer _user_data_)
{
	GearyImapDbAccountDeleteFolderAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_account_delete_folder_async_co (_data_);
}

static gboolean
geary_imap_db_account_delete_folder_async_co (GearyImapDbAccountDeleteFolderAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data35_ = g_slice_new0 (Block35Data);
	_data_->_data35_->_ref_count_ = 1;
	_data_->_data35_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data35_->path);
	_data_->_data35_->path = _data_->path;
	_g_object_unref0 (_data_->_data35_->cancellable);
	_data_->_data35_->cancellable = _data_->cancellable;
	_data_->_data35_->_async_data_ = _data_;
	geary_imap_db_account_check_open (_data_->self, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block35_data_unref (_data_->_data35_);
		_data_->_data35_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp0_ = _data_->self->priv->_db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), GEARY_DB_TRANSACTION_TYPE_RW, ___lambda90__geary_db_transaction_method, _data_->_data35_, _data_->_data35_->cancellable, geary_imap_db_account_delete_folder_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block35_data_unref (_data_->_data35_);
		_data_->_data35_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	block35_data_unref (_data_->_data35_);
	_data_->_data35_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_db_account_list_folders_async_data_free (gpointer _data)
{
	GearyImapDbAccountListFoldersAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbAccountListFoldersAsyncData, _data_);
}

void
geary_imap_db_account_list_folders_async (GearyImapDBAccount* self,
                                          GearyFolderPath* parent,
                                          GCancellable* cancellable,
                                          GAsyncReadyCallback _callback_,
                                          gpointer _user_data_)
{
	GearyImapDbAccountListFoldersAsyncData* _data_;
	GearyImapDBAccount* _tmp0_;
	GearyFolderPath* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail (GEARY_IS_FOLDER_PATH (parent));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbAccountListFoldersAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_account_list_folders_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (parent);
	_g_object_unref0 (_data_->parent);
	_data_->parent = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_account_list_folders_async_co (_data_);
}

GeeCollection*
geary_imap_db_account_list_folders_finish (GearyImapDBAccount* self,
                                           GAsyncResult* _res_,
                                           GError** error)
{
	GeeCollection* result;
	GearyImapDbAccountListFoldersAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

/**
     * Lists all children of a given folder.
     *
     * To list all top-level folders, pass in {@link imap_folder_root}
     * as the parent.
     */
static Block36Data*
block36_data_ref (Block36Data* _data36_)
{
	g_atomic_int_inc (&_data36_->_ref_count_);
	return _data36_;
}

static void
block36_data_unref (void * _userdata_)
{
	Block36Data* _data36_;
	_data36_ = (Block36Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data36_->_ref_count_)) {
		GearyImapDBAccount* self;
		self = _data36_->self;
		_g_object_unref0 (_data36_->prop_map);
		_g_object_unref0 (_data36_->id_map);
		_g_object_unref0 (_data36_->parent);
		_g_object_unref0 (_data36_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block36Data, _data36_);
	}
}

static gint64*
_int64_dup (gint64* self)
{
	gint64* dup;
	dup = g_new0 (gint64, 1);
	memcpy (dup, self, sizeof (gint64));
	return dup;
}

static GearyDbTransactionOutcome
__lambda91_ (Block36Data* _data36_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBAccount* self;
	gint64 parent_id = 0LL;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_;
	gboolean _tmp2_;
	GearyDbStatement* stmt = NULL;
	GearyDbResult* _result_ = NULL;
	GearyDbStatement* _tmp17_;
	GearyDbResult* _tmp18_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data36_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	parent_id = GEARY_DB_INVALID_ROWID;
	_tmp1_ = geary_folder_path_get_is_root (_data36_->parent);
	_tmp2_ = _tmp1_;
	if (!_tmp2_) {
		gboolean _tmp3_ = FALSE;
		gint64 _tmp4_ = 0LL;
		gboolean _tmp5_;
		_tmp5_ = geary_imap_db_account_do_fetch_folder_id (self, cx, _data36_->parent, FALSE, &_tmp4_, _data36_->cancellable, &_inner_error0_);
		parent_id = _tmp4_;
		_tmp3_ = _tmp5_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			return 0;
		}
		_tmp0_ = !_tmp3_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gchar* _tmp6_;
		gchar* _tmp7_;
		_tmp6_ = geary_folder_path_to_string (_data36_->parent);
		_tmp7_ = _tmp6_;
		g_debug ("imap-db-account.vala:271: Unable to find folder ID for \"%s\" to list " \
"folders", _tmp7_);
		_g_free0 (_tmp7_);
		result = GEARY_DB_TRANSACTION_OUTCOME_ROLLBACK;
		return result;
	}
	if (parent_id != GEARY_DB_INVALID_ROWID) {
		GearyDbStatement* _tmp8_ = NULL;
		GearyDbStatement* _tmp9_;
		GearyDbStatement* _tmp10_;
		GearyDbStatement* _tmp11_;
		GearyDbStatement* _tmp12_;
		GearyDbStatement* _tmp13_;
		_tmp9_ = geary_db_connection_prepare (cx, "SELECT id, name, last_seen_total, unread_count, last_seen_status_total" \
", " "uid_validity, uid_next, attributes FROM FolderTable WHERE parent_id=?", &_inner_error0_);
		_tmp8_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp10_ = _tmp8_;
		_tmp8_ = NULL;
		_g_object_unref0 (stmt);
		stmt = _tmp10_;
		_tmp11_ = stmt;
		_tmp12_ = geary_db_statement_bind_rowid (_tmp11_, 0, parent_id, &_inner_error0_);
		_tmp13_ = _tmp12_;
		_g_object_unref0 (_tmp13_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (_tmp8_);
			_g_object_unref0 (stmt);
			return 0;
		}
		_g_object_unref0 (_tmp8_);
	} else {
		GearyDbStatement* _tmp14_ = NULL;
		GearyDbStatement* _tmp15_;
		GearyDbStatement* _tmp16_;
		_tmp15_ = geary_db_connection_prepare (cx, "SELECT id, name, last_seen_total, unread_count, last_seen_status_total" \
", " "uid_validity, uid_next, attributes FROM FolderTable WHERE parent_id IS" \
" NULL", &_inner_error0_);
		_tmp14_ = _tmp15_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp16_ = _tmp14_;
		_tmp14_ = NULL;
		_g_object_unref0 (stmt);
		stmt = _tmp16_;
		_g_object_unref0 (_tmp14_);
	}
	_tmp17_ = stmt;
	_tmp18_ = geary_db_statement_exec (_tmp17_, _data36_->cancellable, &_inner_error0_);
	_result_ = _tmp18_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	while (TRUE) {
		GearyDbResult* _tmp19_;
		gboolean _tmp20_;
		gboolean _tmp21_;
		gchar* basename = NULL;
		GearyDbResult* _tmp22_;
		const gchar* _tmp23_;
		gchar* _tmp24_;
		GearyFolderPath* path = NULL;
		const gchar* _tmp25_;
		GearyFolderPath* _tmp26_;
		const gchar* _tmp27_ = NULL;
		GearyDbResult* _tmp28_;
		const gchar* _tmp29_;
		gint _tmp30_ = 0;
		GearyDbResult* _tmp31_;
		gint _tmp32_ = 0;
		GearyDbResult* _tmp33_;
		gint64 _tmp34_ = 0LL;
		GearyDbResult* _tmp35_;
		gint64 _tmp36_ = 0LL;
		GearyDbResult* _tmp37_;
		GearyImapFolderProperties* properties = NULL;
		GearyImapMailboxAttributes* _tmp38_;
		GearyImapMailboxAttributes* _tmp39_;
		GearyImapUIDValidity* _tmp40_;
		GearyImapUIDValidity* _tmp41_;
		GearyImapUID* _tmp42_;
		GearyImapUID* _tmp43_;
		GearyImapFolderProperties* _tmp44_;
		GearyImapFolderProperties* _tmp45_;
		gint _tmp46_ = 0;
		GearyDbResult* _tmp47_;
		GearyImapFolderProperties* _tmp48_;
		GearyImapFolderProperties* _tmp49_;
		gint _tmp50_;
		gint _tmp51_;
		gint64 _tmp52_ = 0LL;
		GearyDbResult* _tmp53_;
		GeeHashMap* _tmp54_;
		GearyFolderPath* _tmp55_;
		GeeHashMap* _tmp56_;
		GearyFolderPath* _tmp57_;
		GearyImapFolderProperties* _tmp58_;
		GearyDbResult* _tmp59_;
		_tmp19_ = _result_;
		_tmp20_ = geary_db_result_get_finished (_tmp19_);
		_tmp21_ = _tmp20_;
		if (!(!_tmp21_)) {
			break;
		}
		_tmp22_ = _result_;
		_tmp23_ = geary_db_result_string_for (_tmp22_, "name", &_inner_error0_);
		_tmp24_ = g_strdup (_tmp23_);
		basename = _tmp24_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (_result_);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp25_ = basename;
		_tmp26_ = geary_folder_path_get_child (_data36_->parent, _tmp25_, GEARY_TRILLIAN_UNKNOWN);
		path = _tmp26_;
		_tmp28_ = _result_;
		_tmp29_ = geary_db_result_string_for (_tmp28_, "attributes", &_inner_error0_);
		_tmp27_ = _tmp29_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (path);
			_g_free0 (basename);
			_g_object_unref0 (_result_);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp31_ = _result_;
		_tmp30_ = geary_db_result_int_for (_tmp31_, "last_seen_total", &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (path);
			_g_free0 (basename);
			_g_object_unref0 (_result_);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp33_ = _result_;
		_tmp32_ = geary_db_result_int_for (_tmp33_, "unread_count", &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (path);
			_g_free0 (basename);
			_g_object_unref0 (_result_);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp35_ = _result_;
		_tmp34_ = geary_db_result_int64_for (_tmp35_, "uid_validity", &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (path);
			_g_free0 (basename);
			_g_object_unref0 (_result_);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp37_ = _result_;
		_tmp36_ = geary_db_result_int64_for (_tmp37_, "uid_next", &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (path);
			_g_free0 (basename);
			_g_object_unref0 (_result_);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp38_ = geary_imap_mailbox_attributes_deserialize (_tmp27_);
		_tmp39_ = _tmp38_;
		_tmp40_ = geary_imap_uid_validity_new (_tmp34_);
		_tmp41_ = _tmp40_;
		_tmp42_ = geary_imap_uid_new (_tmp36_);
		_tmp43_ = _tmp42_;
		_tmp44_ = geary_imap_folder_properties_new_from_imapdb (_tmp39_, _tmp30_, _tmp32_, _tmp41_, _tmp43_);
		_tmp45_ = _tmp44_;
		_g_object_unref0 (_tmp43_);
		_g_object_unref0 (_tmp41_);
		_g_object_unref0 (_tmp39_);
		properties = _tmp45_;
		_tmp47_ = _result_;
		_tmp46_ = geary_db_result_int_for (_tmp47_, "last_seen_status_total", &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (properties);
			_g_object_unref0 (path);
			_g_free0 (basename);
			_g_object_unref0 (_result_);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp48_ = properties;
		_tmp49_ = properties;
		_tmp50_ = geary_imap_folder_properties_get_select_examine_messages (_tmp49_);
		_tmp51_ = _tmp50_;
		geary_imap_folder_properties_set_status_message_count (_tmp48_, _tmp46_, _tmp51_ == 0);
		_tmp53_ = _result_;
		_tmp52_ = geary_db_result_rowid_for (_tmp53_, "id", &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (properties);
			_g_object_unref0 (path);
			_g_free0 (basename);
			_g_object_unref0 (_result_);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp54_ = _data36_->id_map;
		_tmp55_ = path;
		gee_abstract_map_set (G_TYPE_CHECK_INSTANCE_CAST (_tmp54_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _tmp55_, &_tmp52_);
		_tmp56_ = _data36_->prop_map;
		_tmp57_ = path;
		_tmp58_ = properties;
		gee_abstract_map_set (G_TYPE_CHECK_INSTANCE_CAST (_tmp56_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _tmp57_, _tmp58_);
		_tmp59_ = _result_;
		geary_db_result_next (_tmp59_, _data36_->cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (properties);
			_g_object_unref0 (path);
			_g_free0 (basename);
			_g_object_unref0 (_result_);
			_g_object_unref0 (stmt);
			return 0;
		}
		_g_object_unref0 (properties);
		_g_object_unref0 (path);
		_g_free0 (basename);
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	_g_object_unref0 (_result_);
	_g_object_unref0 (stmt);
	return result;
}

static GearyDbTransactionOutcome
___lambda91__geary_db_transaction_method (GearyDbConnection* cx,
                                          GCancellable* cancellable,
                                          gpointer self,
                                          GError** error)
{
	GearyDbTransactionOutcome result;
	result = __lambda91_ (self, cx, error);
	return result;
}

static void
geary_imap_db_account_list_folders_async_ready (GObject* source_object,
                                                GAsyncResult* _res_,
                                                gpointer _user_data_)
{
	GearyImapDbAccountListFoldersAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_account_list_folders_async_co (_data_);
}

static gboolean
geary_imap_db_account_list_folders_async_co (GearyImapDbAccountListFoldersAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data36_ = g_slice_new0 (Block36Data);
	_data_->_data36_->_ref_count_ = 1;
	_data_->_data36_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data36_->parent);
	_data_->_data36_->parent = _data_->parent;
	_g_object_unref0 (_data_->_data36_->cancellable);
	_data_->_data36_->cancellable = _data_->cancellable;
	_data_->_data36_->_async_data_ = _data_;
	geary_imap_db_account_check_open (_data_->self, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block36_data_unref (_data_->_data36_);
		_data_->_data36_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp0_ = gee_hash_map_new (GEARY_TYPE_FOLDER_PATH, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, G_TYPE_INT64, (GBoxedCopyFunc) _int64_dup, (GDestroyNotify) g_free, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->_data36_->id_map = _data_->_tmp0_;
	_data_->_tmp1_ = gee_hash_map_new (GEARY_TYPE_FOLDER_PATH, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEARY_IMAP_TYPE_FOLDER_PROPERTIES, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->_data36_->prop_map = _data_->_tmp1_;
	_data_->_tmp2_ = _data_->self->priv->_db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), GEARY_DB_TRANSACTION_TYPE_RO, ___lambda91__geary_db_transaction_method, _data_->_data36_, _data_->_data36_->cancellable, geary_imap_db_account_list_folders_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block36_data_unref (_data_->_data36_);
		_data_->_data36_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp3_ = _data_->_data36_->id_map;
	_data_->_tmp4_ = gee_abstract_map_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp3_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap));
	_data_->_tmp5_ = _data_->_tmp4_;
	_data_->_tmp6_ = _data_->_data36_->prop_map;
	_data_->_tmp7_ = gee_abstract_map_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp6_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap));
	_data_->_tmp8_ = _data_->_tmp7_;
	_vala_assert (_data_->_tmp5_ == _data_->_tmp8_, "id_map.size == prop_map.size");
	_data_->_tmp9_ = _data_->_data36_->id_map;
	_data_->_tmp10_ = gee_abstract_map_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp9_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap));
	_data_->_tmp11_ = _data_->_tmp10_;
	if (_data_->_tmp11_ == 0) {
		_data_->_tmp12_ = geary_folder_path_to_string (_data_->_data36_->parent);
		_data_->_tmp13_ = _data_->_tmp12_;
		_data_->_tmp14_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_NOT_FOUND, "No local folders under \"%s\"", _data_->_tmp13_);
		_data_->_tmp15_ = _data_->_tmp14_;
		_g_free0 (_data_->_tmp13_);
		_data_->_inner_error0_ = _data_->_tmp15_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block36_data_unref (_data_->_data36_);
		_data_->_data36_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp16_ = gee_array_list_new (GEARY_IMAP_DB_TYPE_FOLDER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data_->folders = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp16_, GEE_TYPE_COLLECTION, GeeCollection);
	{
		_data_->_tmp17_ = _data_->_data36_->id_map;
		_data_->_tmp18_ = gee_abstract_map_get_keys (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp17_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap));
		_data_->_tmp19_ = _data_->_tmp18_;
		_data_->_tmp20_ = _data_->_tmp19_;
		_data_->_tmp21_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp20_, GEE_TYPE_ITERABLE, GeeIterable));
		_data_->_tmp22_ = _data_->_tmp21_;
		_g_object_unref0 (_data_->_tmp20_);
		_data_->_path_it = _data_->_tmp22_;
		while (TRUE) {
			_data_->_tmp23_ = _data_->_path_it;
			if (!gee_iterator_next (_data_->_tmp23_)) {
				break;
			}
			_data_->_tmp24_ = _data_->_path_it;
			_data_->_tmp25_ = gee_iterator_get (_data_->_tmp24_);
			_data_->path = (GearyFolderPath*) _data_->_tmp25_;
			_data_->_tmp26_ = _data_->path;
			_data_->_tmp27_ = geary_imap_db_account_get_local_folder (_data_->self, _data_->_tmp26_);
			_data_->folder = _data_->_tmp27_;
			_data_->_tmp30_ = _data_->folder;
			if (_data_->_tmp30_ == NULL) {
				_data_->_tmp31_ = _data_->_data36_->id_map;
				_data_->_tmp32_ = _data_->path;
				_data_->_tmp29_ = gee_abstract_map_has_key (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp31_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _data_->_tmp32_);
			} else {
				_data_->_tmp29_ = FALSE;
			}
			if (_data_->_tmp29_) {
				_data_->_tmp33_ = _data_->_data36_->prop_map;
				_data_->_tmp34_ = _data_->path;
				_data_->_tmp28_ = gee_abstract_map_has_key (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp33_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _data_->_tmp34_);
			} else {
				_data_->_tmp28_ = FALSE;
			}
			if (_data_->_tmp28_) {
				_data_->_tmp36_ = _data_->path;
				_data_->_tmp37_ = _data_->_data36_->id_map;
				_data_->_tmp38_ = _data_->path;
				_data_->_tmp39_ = gee_abstract_map_get (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp37_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _data_->_tmp38_);
				_data_->_tmp40_ = (gint64*) _data_->_tmp39_;
				_data_->_tmp41_ = _data_->_data36_->prop_map;
				_data_->_tmp42_ = _data_->path;
				_data_->_tmp43_ = gee_abstract_map_get (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp41_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _data_->_tmp42_);
				_data_->_tmp44_ = (GearyImapFolderProperties*) _data_->_tmp43_;
				_data_->_tmp45_ = geary_imap_db_account_create_local_folder (_data_->self, _data_->_tmp36_, *_data_->_tmp40_, _data_->_tmp44_, &_data_->_inner_error0_);
				_data_->_tmp46_ = _data_->_tmp45_;
				_g_object_unref0 (_data_->_tmp44_);
				_g_free0 (_data_->_tmp40_);
				_data_->_tmp35_ = _data_->_tmp46_;
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
					_g_object_unref0 (_data_->folder);
					_g_object_unref0 (_data_->path);
					_g_object_unref0 (_data_->_path_it);
					_g_object_unref0 (_data_->folders);
					block36_data_unref (_data_->_data36_);
					_data_->_data36_ = NULL;
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
				_data_->_tmp47_ = _data_->_tmp35_;
				_data_->_tmp35_ = NULL;
				_g_object_unref0 (_data_->folder);
				_data_->folder = _data_->_tmp47_;
				_g_object_unref0 (_data_->_tmp35_);
			}
			_data_->_tmp48_ = _data_->folders;
			_data_->_tmp49_ = _data_->folder;
			gee_collection_add (_data_->_tmp48_, _data_->_tmp49_);
			_g_object_unref0 (_data_->folder);
			_g_object_unref0 (_data_->path);
		}
		_g_object_unref0 (_data_->_path_it);
	}
	_data_->result = _data_->folders;
	block36_data_unref (_data_->_data36_);
	_data_->_data36_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_db_account_fetch_folder_async_data_free (gpointer _data)
{
	GearyImapDbAccountFetchFolderAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbAccountFetchFolderAsyncData, _data_);
}

void
geary_imap_db_account_fetch_folder_async (GearyImapDBAccount* self,
                                          GearyFolderPath* path,
                                          GCancellable* cancellable,
                                          GAsyncReadyCallback _callback_,
                                          gpointer _user_data_)
{
	GearyImapDbAccountFetchFolderAsyncData* _data_;
	GearyImapDBAccount* _tmp0_;
	GearyFolderPath* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail (GEARY_IS_FOLDER_PATH (path));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbAccountFetchFolderAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_account_fetch_folder_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (path);
	_g_object_unref0 (_data_->path);
	_data_->path = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_account_fetch_folder_async_co (_data_);
}

GearyImapDBFolder*
geary_imap_db_account_fetch_folder_finish (GearyImapDBAccount* self,
                                           GAsyncResult* _res_,
                                           GError** error)
{
	GearyImapDBFolder* result;
	GearyImapDbAccountFetchFolderAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block37Data*
block37_data_ref (Block37Data* _data37_)
{
	g_atomic_int_inc (&_data37_->_ref_count_);
	return _data37_;
}

static void
block37_data_unref (void * _userdata_)
{
	Block37Data* _data37_;
	_data37_ = (Block37Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data37_->_ref_count_)) {
		GearyImapDBAccount* self;
		self = _data37_->self;
		_g_object_unref0 (_data37_->properties);
		_g_object_unref0 (_data37_->path);
		_g_object_unref0 (_data37_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block37Data, _data37_);
	}
}

static GearyDbTransactionOutcome
__lambda88_ (Block37Data* _data37_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBAccount* self;
	gboolean _tmp0_ = FALSE;
	gint64 _tmp1_ = 0LL;
	gboolean _tmp2_;
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbStatement* _tmp5_;
	GearyDbStatement* _tmp6_;
	GearyDbResult* results = NULL;
	GearyDbStatement* _tmp7_;
	GearyDbResult* _tmp8_;
	GearyDbResult* _tmp9_;
	gboolean _tmp10_;
	gboolean _tmp11_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data37_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp2_ = geary_imap_db_account_do_fetch_folder_id (self, cx, _data37_->path, FALSE, &_tmp1_, _data37_->cancellable, &_inner_error0_);
	_data37_->folder_id = _tmp1_;
	_tmp0_ = _tmp2_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	if (!_tmp0_) {
		result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
		return result;
	}
	if (_data37_->folder_id == GEARY_DB_INVALID_ROWID) {
		result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
		return result;
	}
	_tmp3_ = geary_db_connection_prepare (cx, "SELECT last_seen_total, unread_count, last_seen_status_total, uid_vali" \
"dity, uid_next, " "attributes FROM FolderTable WHERE id=?", &_inner_error0_);
	stmt = _tmp3_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp4_ = stmt;
	_tmp5_ = geary_db_statement_bind_rowid (_tmp4_, 0, _data37_->folder_id, &_inner_error0_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp6_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp7_ = stmt;
	_tmp8_ = geary_db_statement_exec (_tmp7_, _data37_->cancellable, &_inner_error0_);
	results = _tmp8_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp9_ = results;
	_tmp10_ = geary_db_result_get_finished (_tmp9_);
	_tmp11_ = _tmp10_;
	if (!_tmp11_) {
		const gchar* _tmp12_ = NULL;
		GearyDbResult* _tmp13_;
		const gchar* _tmp14_;
		gint _tmp15_ = 0;
		GearyDbResult* _tmp16_;
		gint _tmp17_ = 0;
		GearyDbResult* _tmp18_;
		gint64 _tmp19_ = 0LL;
		GearyDbResult* _tmp20_;
		gint64 _tmp21_ = 0LL;
		GearyDbResult* _tmp22_;
		GearyImapMailboxAttributes* _tmp23_;
		GearyImapMailboxAttributes* _tmp24_;
		GearyImapUIDValidity* _tmp25_;
		GearyImapUIDValidity* _tmp26_;
		GearyImapUID* _tmp27_;
		GearyImapUID* _tmp28_;
		GearyImapFolderProperties* _tmp29_;
		gint _tmp30_ = 0;
		GearyDbResult* _tmp31_;
		GearyImapFolderProperties* _tmp32_;
		GearyImapFolderProperties* _tmp33_;
		gint _tmp34_;
		gint _tmp35_;
		_tmp13_ = results;
		_tmp14_ = geary_db_result_string_for (_tmp13_, "attributes", &_inner_error0_);
		_tmp12_ = _tmp14_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp16_ = results;
		_tmp15_ = geary_db_result_int_for (_tmp16_, "last_seen_total", &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp18_ = results;
		_tmp17_ = geary_db_result_int_for (_tmp18_, "unread_count", &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp20_ = results;
		_tmp19_ = geary_db_result_int64_for (_tmp20_, "uid_validity", &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp22_ = results;
		_tmp21_ = geary_db_result_int64_for (_tmp22_, "uid_next", &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp23_ = geary_imap_mailbox_attributes_deserialize (_tmp12_);
		_tmp24_ = _tmp23_;
		_tmp25_ = geary_imap_uid_validity_new (_tmp19_);
		_tmp26_ = _tmp25_;
		_tmp27_ = geary_imap_uid_new (_tmp21_);
		_tmp28_ = _tmp27_;
		_tmp29_ = geary_imap_folder_properties_new_from_imapdb (_tmp24_, _tmp15_, _tmp17_, _tmp26_, _tmp28_);
		_g_object_unref0 (_data37_->properties);
		_data37_->properties = _tmp29_;
		_g_object_unref0 (_tmp28_);
		_g_object_unref0 (_tmp26_);
		_g_object_unref0 (_tmp24_);
		_tmp31_ = results;
		_tmp30_ = geary_db_result_int_for (_tmp31_, "last_seen_status_total", &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp32_ = _data37_->properties;
		_tmp33_ = _data37_->properties;
		_tmp34_ = geary_imap_folder_properties_get_select_examine_messages (_tmp33_);
		_tmp35_ = _tmp34_;
		geary_imap_folder_properties_set_status_message_count (_tmp32_, _tmp30_, _tmp35_ == 0);
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	_g_object_unref0 (results);
	_g_object_unref0 (stmt);
	return result;
}

static GearyDbTransactionOutcome
___lambda88__geary_db_transaction_method (GearyDbConnection* cx,
                                          GCancellable* cancellable,
                                          gpointer self,
                                          GError** error)
{
	GearyDbTransactionOutcome result;
	result = __lambda88_ (self, cx, error);
	return result;
}

static void
geary_imap_db_account_fetch_folder_async_ready (GObject* source_object,
                                                GAsyncResult* _res_,
                                                gpointer _user_data_)
{
	GearyImapDbAccountFetchFolderAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_account_fetch_folder_async_co (_data_);
}

static gboolean
geary_imap_db_account_fetch_folder_async_co (GearyImapDbAccountFetchFolderAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data37_ = g_slice_new0 (Block37Data);
	_data_->_data37_->_ref_count_ = 1;
	_data_->_data37_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data37_->path);
	_data_->_data37_->path = _data_->path;
	_g_object_unref0 (_data_->_data37_->cancellable);
	_data_->_data37_->cancellable = _data_->cancellable;
	_data_->_data37_->_async_data_ = _data_;
	geary_imap_db_account_check_open (_data_->self, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block37_data_unref (_data_->_data37_);
		_data_->_data37_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp0_ = geary_imap_db_account_get_local_folder (_data_->self, _data_->_data37_->path);
	_data_->folder = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->folder;
	if (_data_->_tmp1_ != NULL) {
		_data_->result = _data_->folder;
		block37_data_unref (_data_->_data37_);
		_data_->_data37_ = NULL;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_data37_->folder_id = GEARY_DB_INVALID_ROWID;
	_data_->_data37_->properties = NULL;
	_data_->_tmp2_ = _data_->self->priv->_db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), GEARY_DB_TRANSACTION_TYPE_RO, ___lambda88__geary_db_transaction_method, _data_->_data37_, _data_->_data37_->cancellable, geary_imap_db_account_fetch_folder_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->folder);
		block37_data_unref (_data_->_data37_);
		_data_->_data37_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (_data_->_data37_->folder_id == GEARY_DB_INVALID_ROWID) {
		_data_->_tmp3_ = TRUE;
	} else {
		_data_->_tmp4_ = _data_->_data37_->properties;
		_data_->_tmp3_ = _data_->_tmp4_ == NULL;
	}
	if (_data_->_tmp3_) {
		_data_->_tmp5_ = geary_folder_path_to_string (_data_->_data37_->path);
		_data_->_tmp6_ = _data_->_tmp5_;
		_data_->_tmp7_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_NOT_FOUND, "%s not found in local database", _data_->_tmp6_);
		_data_->_tmp8_ = _data_->_tmp7_;
		_g_free0 (_data_->_tmp6_);
		_data_->_inner_error0_ = _data_->_tmp8_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->folder);
		block37_data_unref (_data_->_data37_);
		_data_->_data37_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp10_ = _data_->_data37_->properties;
	_data_->_tmp11_ = geary_imap_db_account_create_local_folder (_data_->self, _data_->_data37_->path, _data_->_data37_->folder_id, _data_->_tmp10_, &_data_->_inner_error0_);
	_data_->_tmp9_ = _data_->_tmp11_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->folder);
		block37_data_unref (_data_->_data37_);
		_data_->_data37_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp12_ = _data_->_tmp9_;
	_data_->_tmp9_ = NULL;
	_data_->result = _data_->_tmp12_;
	_g_object_unref0 (_data_->_tmp9_);
	_g_object_unref0 (_data_->folder);
	block37_data_unref (_data_->_data37_);
	_data_->_data37_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_db_account_fetch_last_cleanup_async_data_free (gpointer _data)
{
	GearyImapDbAccountFetchLastCleanupAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cancellable);
	_g_date_time_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbAccountFetchLastCleanupAsyncData, _data_);
}

void
geary_imap_db_account_fetch_last_cleanup_async (GearyImapDBAccount* self,
                                                GCancellable* cancellable,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_)
{
	GearyImapDbAccountFetchLastCleanupAsyncData* _data_;
	GearyImapDBAccount* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbAccountFetchLastCleanupAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_account_fetch_last_cleanup_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_db_account_fetch_last_cleanup_async_co (_data_);
}

GDateTime*
geary_imap_db_account_fetch_last_cleanup_finish (GearyImapDBAccount* self,
                                                 GAsyncResult* _res_,
                                                 GError** error)
{
	GDateTime* result;
	GearyImapDbAccountFetchLastCleanupAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

/**
     * Fetch the last time the account cleanup was run.
     */
static Block38Data*
block38_data_ref (Block38Data* _data38_)
{
	g_atomic_int_inc (&_data38_->_ref_count_);
	return _data38_;
}

static void
block38_data_unref (void * _userdata_)
{
	Block38Data* _data38_;
	_data38_ = (Block38Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data38_->_ref_count_)) {
		GearyImapDBAccount* self;
		self = _data38_->self;
		_g_object_unref0 (self);
		g_slice_free (Block38Data, _data38_);
	}
}

static GearyDbTransactionOutcome
__lambda92_ (Block38Data* _data38_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBAccount* self;
	GearyDbResult* _result_ = NULL;
	GearyDbResult* _tmp0_;
	GearyDbResult* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	gint64 _tmp4_ = 0LL;
	gboolean _tmp5_ = FALSE;
	GearyDbResult* _tmp6_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data38_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_db_connection_query (cx, "\n" \
"                SELECT last_cleanup_time_t\n" \
"                FROM GarbageCollectionTable\n" \
"                WHERE id = 0\n" \
"            ", NULL, &_inner_error0_);
	_result_ = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp1_ = _result_;
	_tmp2_ = geary_db_result_get_finished (_tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_) {
		result = GEARY_DB_TRANSACTION_OUTCOME_FAILURE;
		_g_object_unref0 (_result_);
		return result;
	}
	_tmp6_ = _result_;
	_tmp5_ = geary_db_result_is_null_at (_tmp6_, 0, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_result_);
		return 0;
	}
	if (!_tmp5_) {
		GearyDbResult* _tmp7_;
		_tmp7_ = _result_;
		_tmp4_ = geary_db_result_int64_at (_tmp7_, 0, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (_result_);
			return 0;
		}
	} else {
		_tmp4_ = (gint64) -1;
	}
	_data38_->last_cleanup_time_t = _tmp4_;
	result = GEARY_DB_TRANSACTION_OUTCOME_SUCCESS;
	_g_object_unref0 (_result_);
	return result;
}

static GearyDbTransactionOutcome
___lambda92__geary_db_transaction_method (GearyDbConnection* cx,
                                          GCancellable* cancellable,
                                          gpointer self,
                                          GError** error)
{
	GearyDbTransactionOutcome result;
	result = __lambda92_ (self, cx, error);
	return result;
}

static void
geary_imap_db_account_fetch_last_cleanup_async_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_)
{
	GearyImapDbAccountFetchLastCleanupAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_account_fetch_last_cleanup_async_co (_data_);
}

static gboolean
geary_imap_db_account_fetch_last_cleanup_async_co (GearyImapDbAccountFetchLastCleanupAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data38_ = g_slice_new0 (Block38Data);
	_data_->_data38_->_ref_count_ = 1;
	_data_->_data38_->self = g_object_ref (_data_->self);
	_data_->_data38_->_async_data_ = _data_;
	geary_imap_db_account_check_open (_data_->self, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block38_data_unref (_data_->_data38_);
		_data_->_data38_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_data38_->last_cleanup_time_t = (gint64) -1;
	_data_->_tmp0_ = _data_->self->priv->_db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), GEARY_DB_TRANSACTION_TYPE_RO, ___lambda92__geary_db_transaction_method, _data_->_data38_, _data_->cancellable, geary_imap_db_account_fetch_last_cleanup_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block38_data_unref (_data_->_data38_);
		_data_->_data38_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (_data_->_data38_->last_cleanup_time_t >= ((gint64) 0)) {
		_data_->_tmp2_ = g_date_time_new_from_unix_local (_data_->_data38_->last_cleanup_time_t);
		_g_date_time_unref0 (_data_->_tmp1_);
		_data_->_tmp1_ = _data_->_tmp2_;
	} else {
		_g_date_time_unref0 (_data_->_tmp1_);
		_data_->_tmp1_ = NULL;
	}
	_data_->_tmp3_ = _data_->_tmp1_;
	_data_->_tmp1_ = NULL;
	_data_->result = _data_->_tmp3_;
	_g_date_time_unref0 (_data_->_tmp1_);
	block38_data_unref (_data_->_data38_);
	_data_->_data38_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_db_account_set_last_cleanup_async_data_free (gpointer _data)
{
	GearyImapDbAccountSetLastCleanupAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbAccountSetLastCleanupAsyncData, _data_);
}

static gpointer
_g_date_time_ref0 (gpointer self)
{
	return self ? g_date_time_ref (self) : NULL;
}

void
geary_imap_db_account_set_last_cleanup_async (GearyImapDBAccount* self,
                                              GDateTime* dt,
                                              GCancellable* cancellable,
                                              GAsyncReadyCallback _callback_,
                                              gpointer _user_data_)
{
	GearyImapDbAccountSetLastCleanupAsyncData* _data_;
	GearyImapDBAccount* _tmp0_;
	GDateTime* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbAccountSetLastCleanupAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_account_set_last_cleanup_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_date_time_ref0 (dt);
	_g_date_time_unref0 (_data_->dt);
	_data_->dt = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_account_set_last_cleanup_async_co (_data_);
}

void
geary_imap_db_account_set_last_cleanup_finish (GearyImapDBAccount* self,
                                               GAsyncResult* _res_,
                                               GError** error)
{
	GearyImapDbAccountSetLastCleanupAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

/**
     * Set the last time the account cleanup was run.
     */
static Block39Data*
block39_data_ref (Block39Data* _data39_)
{
	g_atomic_int_inc (&_data39_->_ref_count_);
	return _data39_;
}

static void
block39_data_unref (void * _userdata_)
{
	Block39Data* _data39_;
	_data39_ = (Block39Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data39_->_ref_count_)) {
		GearyImapDBAccount* self;
		self = _data39_->self;
		_g_date_time_unref0 (_data39_->dt);
		_g_object_unref0 (_data39_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block39Data, _data39_);
	}
}

static GearyDbTransactionOutcome
__lambda93_ (Block39Data* _data39_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBAccount* self;
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp7_;
	GearyDbResult* _tmp8_;
	GearyDbResult* _tmp9_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data39_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_db_connection_prepare (cx, "\n" \
"                UPDATE GarbageCollectionTable\n" \
"                SET last_cleanup_time_t = ?\n" \
"                WHERE id = 0\n" \
"            ", &_inner_error0_);
	stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	if (_data39_->dt != NULL) {
		GearyDbStatement* _tmp1_;
		GearyDbStatement* _tmp2_;
		GearyDbStatement* _tmp3_;
		_tmp1_ = stmt;
		_tmp2_ = geary_db_statement_bind_int64 (_tmp1_, 0, g_date_time_to_unix (_data39_->dt), &_inner_error0_);
		_tmp3_ = _tmp2_;
		_g_object_unref0 (_tmp3_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return 0;
		}
	} else {
		GearyDbStatement* _tmp4_;
		GearyDbStatement* _tmp5_;
		GearyDbStatement* _tmp6_;
		_tmp4_ = stmt;
		_tmp5_ = geary_db_statement_bind_null (_tmp4_, 0, &_inner_error0_);
		_tmp6_ = _tmp5_;
		_g_object_unref0 (_tmp6_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return 0;
		}
	}
	_tmp7_ = stmt;
	_tmp8_ = geary_db_statement_exec (_tmp7_, _data39_->cancellable, &_inner_error0_);
	_tmp9_ = _tmp8_;
	_g_object_unref0 (_tmp9_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_COMMIT;
	_g_object_unref0 (stmt);
	return result;
}

static GearyDbTransactionOutcome
___lambda93__geary_db_transaction_method (GearyDbConnection* cx,
                                          GCancellable* cancellable,
                                          gpointer self,
                                          GError** error)
{
	GearyDbTransactionOutcome result;
	result = __lambda93_ (self, cx, error);
	return result;
}

static void
geary_imap_db_account_set_last_cleanup_async_ready (GObject* source_object,
                                                    GAsyncResult* _res_,
                                                    gpointer _user_data_)
{
	GearyImapDbAccountSetLastCleanupAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_account_set_last_cleanup_async_co (_data_);
}

static gboolean
geary_imap_db_account_set_last_cleanup_async_co (GearyImapDbAccountSetLastCleanupAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data39_ = g_slice_new0 (Block39Data);
	_data_->_data39_->_ref_count_ = 1;
	_data_->_data39_->self = g_object_ref (_data_->self);
	_g_date_time_unref0 (_data_->_data39_->dt);
	_data_->_data39_->dt = _data_->dt;
	_g_object_unref0 (_data_->_data39_->cancellable);
	_data_->_data39_->cancellable = _data_->cancellable;
	_data_->_data39_->_async_data_ = _data_;
	geary_imap_db_account_check_open (_data_->self, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block39_data_unref (_data_->_data39_);
		_data_->_data39_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp0_ = _data_->self->priv->_db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), GEARY_DB_TRANSACTION_TYPE_WO, ___lambda93__geary_db_transaction_method, _data_->_data39_, _data_->_data39_->cancellable, geary_imap_db_account_set_last_cleanup_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block39_data_unref (_data_->_data39_);
		_data_->_data39_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	block39_data_unref (_data_->_data39_);
	_data_->_data39_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static GearyImapDBFolder*
geary_imap_db_account_get_local_folder (GearyImapDBAccount* self,
                                        GearyFolderPath* path)
{
	GearyImapDBAccountFolderReference* folder_ref = NULL;
	GeeHashMap* _tmp0_;
	gpointer _tmp1_;
	GearyImapDBAccountFolderReference* _tmp2_;
	GearyImapDBFolder* folder = NULL;
	GearyImapDBAccountFolderReference* _tmp3_;
	GearyReferenceSemantics* _tmp4_;
	GearyImapDBFolder* _tmp5_;
	GearyImapDBFolder* result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self), NULL);
	g_return_val_if_fail (GEARY_IS_FOLDER_PATH (path), NULL);
	_tmp0_ = self->priv->folder_refs;
	_tmp1_ = gee_abstract_map_get (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), path);
	folder_ref = (GearyImapDBAccountFolderReference*) _tmp1_;
	_tmp2_ = folder_ref;
	if (_tmp2_ == NULL) {
		result = NULL;
		_g_object_unref0 (folder_ref);
		return result;
	}
	_tmp3_ = folder_ref;
	_tmp4_ = geary_smart_reference_get_reference (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, GEARY_TYPE_SMART_REFERENCE, GearySmartReference));
	folder = G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, GEARY_IMAP_DB_TYPE_FOLDER, GearyImapDBFolder);
	_tmp5_ = folder;
	if (_tmp5_ == NULL) {
		result = NULL;
		_g_object_unref0 (folder);
		_g_object_unref0 (folder_ref);
		return result;
	}
	result = folder;
	_g_object_unref0 (folder_ref);
	return result;
}

static void
_geary_imap_db_account_on_folder_reference_broken_geary_smart_reference_reference_broken (GearySmartReference* _sender,
                                                                                          gpointer self)
{
	geary_imap_db_account_on_folder_reference_broken ((GearyImapDBAccount*) self, _sender);
}

static void
_geary_imap_db_account_on_unread_updated_geary_imap_db_folder_unread_updated (GearyImapDBFolder* _sender,
                                                                              GeeMap* unread_status,
                                                                              gpointer self)
{
	geary_imap_db_account_on_unread_updated ((GearyImapDBAccount*) self, _sender, unread_status);
}

static GearyImapDBFolder*
geary_imap_db_account_create_local_folder (GearyImapDBAccount* self,
                                           GearyFolderPath* path,
                                           gint64 folder_id,
                                           GearyImapFolderProperties* properties,
                                           GError** error)
{
	GearyImapDBFolder* folder = NULL;
	GearyImapDBFolder* _tmp0_;
	GearyImapDBFolder* _tmp1_;
	GearyImapDBFolder* result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self), NULL);
	g_return_val_if_fail (GEARY_IS_FOLDER_PATH (path), NULL);
	g_return_val_if_fail (GEARY_IMAP_IS_FOLDER_PROPERTIES (properties), NULL);
	_tmp0_ = geary_imap_db_account_get_local_folder (self, path);
	folder = _tmp0_;
	_tmp1_ = folder;
	if (_tmp1_ != NULL) {
		GearyImapDBFolder* _tmp2_;
		_tmp2_ = folder;
		geary_imap_db_folder_set_properties (_tmp2_, properties);
	} else {
		GearyImapDBDatabase* _tmp3_;
		GearyImapDBDatabase* _tmp4_;
		GFile* _tmp5_;
		GearyAccountInformation* _tmp6_;
		GearyRFC822MailboxAddress* _tmp7_;
		GearyRFC822MailboxAddress* _tmp8_;
		GearyRFC822MailboxAddress* _tmp9_;
		const gchar* _tmp10_;
		const gchar* _tmp11_;
		GearyImapDBFolder* _tmp12_;
		GearyImapDBAccountFolderReference* folder_ref = NULL;
		GearyImapDBFolder* _tmp13_;
		GearyImapDBAccountFolderReference* _tmp14_;
		GearyImapDBAccountFolderReference* _tmp15_;
		GeeHashMap* _tmp16_;
		GearyImapDBAccountFolderReference* _tmp17_;
		GearyFolderPath* _tmp18_;
		GearyImapDBAccountFolderReference* _tmp19_;
		GearyImapDBFolder* _tmp20_;
		_tmp3_ = self->priv->_db;
		_tmp4_ = self->priv->_db;
		_tmp5_ = _tmp4_->attachments_path;
		_tmp6_ = self->priv->_account_information;
		_tmp7_ = geary_account_information_get_primary_mailbox (_tmp6_);
		_tmp8_ = _tmp7_;
		_tmp9_ = _tmp8_;
		_tmp10_ = geary_rf_c822_mailbox_address_get_address (_tmp9_);
		_tmp11_ = _tmp10_;
		_tmp12_ = geary_imap_db_folder_new (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), path, _tmp5_, _tmp11_, folder_id, properties);
		_g_object_unref0 (folder);
		folder = _tmp12_;
		_g_object_unref0 (_tmp9_);
		_tmp13_ = folder;
		_tmp14_ = geary_imap_db_account_folder_reference_new (_tmp13_, path);
		folder_ref = _tmp14_;
		_tmp15_ = folder_ref;
		g_signal_connect_object (G_TYPE_CHECK_INSTANCE_CAST (_tmp15_, GEARY_TYPE_SMART_REFERENCE, GearySmartReference), "reference-broken", (GCallback) _geary_imap_db_account_on_folder_reference_broken_geary_smart_reference_reference_broken, self, 0);
		_tmp16_ = self->priv->folder_refs;
		_tmp17_ = folder_ref;
		_tmp18_ = _tmp17_->path;
		_tmp19_ = folder_ref;
		gee_abstract_map_set (G_TYPE_CHECK_INSTANCE_CAST (_tmp16_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _tmp18_, _tmp19_);
		_tmp20_ = folder;
		g_signal_connect_object (_tmp20_, "unread-updated", (GCallback) _geary_imap_db_account_on_unread_updated_geary_imap_db_folder_unread_updated, self, 0);
		_g_object_unref0 (folder_ref);
	}
	result = folder;
	return result;
}

static void
geary_imap_db_account_on_folder_reference_broken (GearyImapDBAccount* self,
                                                  GearySmartReference* reference)
{
	GearyImapDBAccountFolderReference* folder_ref = NULL;
	GearyImapDBAccountFolderReference* _tmp0_;
	GeeHashMap* _tmp1_;
	GearyFolderPath* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail (GEARY_IS_SMART_REFERENCE (reference));
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (reference, GEARY_IMAP_DB_ACCOUNT_TYPE_FOLDER_REFERENCE, GearyImapDBAccountFolderReference));
	folder_ref = _tmp0_;
	_tmp1_ = self->priv->folder_refs;
	_tmp2_ = folder_ref->path;
	gee_abstract_map_unset (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _tmp2_, NULL);
	_g_object_unref0 (folder_ref);
}

static void
geary_imap_db_account_search_message_id_async_data_free (gpointer _data)
{
	GearyImapDbAccountSearchMessageIdAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbAccountSearchMessageIdAsyncData, _data_);
}

void
geary_imap_db_account_search_message_id_async (GearyImapDBAccount* self,
                                               GearyRFC822MessageID* message_id,
                                               GearyEmailField requested_fields,
                                               gboolean partial_ok,
                                               GeeCollection* folder_blacklist,
                                               GearyEmailFlags* flag_blacklist,
                                               GCancellable* cancellable,
                                               GAsyncReadyCallback _callback_,
                                               gpointer _user_data_)
{
	GearyImapDbAccountSearchMessageIdAsyncData* _data_;
	GearyImapDBAccount* _tmp0_;
	GearyRFC822MessageID* _tmp1_;
	GeeCollection* _tmp2_;
	GearyEmailFlags* _tmp3_;
	GCancellable* _tmp4_;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail (GEARY_RF_C822_IS_MESSAGE_ID (message_id));
	g_return_if_fail ((folder_blacklist == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (folder_blacklist, GEE_TYPE_COLLECTION));
	g_return_if_fail ((flag_blacklist == NULL) || GEARY_IS_EMAIL_FLAGS (flag_blacklist));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbAccountSearchMessageIdAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_account_search_message_id_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (message_id);
	_g_object_unref0 (_data_->message_id);
	_data_->message_id = _tmp1_;
	_data_->requested_fields = requested_fields;
	_data_->partial_ok = partial_ok;
	_tmp2_ = _g_object_ref0 (folder_blacklist);
	_g_object_unref0 (_data_->folder_blacklist);
	_data_->folder_blacklist = _tmp2_;
	_tmp3_ = _g_object_ref0 (flag_blacklist);
	_g_object_unref0 (_data_->flag_blacklist);
	_data_->flag_blacklist = _tmp3_;
	_tmp4_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp4_;
	geary_imap_db_account_search_message_id_async_co (_data_);
}

GeeMultiMap*
geary_imap_db_account_search_message_id_finish (GearyImapDBAccount* self,
                                                GAsyncResult* _res_,
                                                GError** error)
{
	GeeMultiMap* result;
	GearyImapDbAccountSearchMessageIdAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block40Data*
block40_data_ref (Block40Data* _data40_)
{
	g_atomic_int_inc (&_data40_->_ref_count_);
	return _data40_;
}

static void
block40_data_unref (void * _userdata_)
{
	Block40Data* _data40_;
	_data40_ = (Block40Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data40_->_ref_count_)) {
		GearyImapDBAccount* self;
		self = _data40_->self;
		_g_object_unref0 (_data40_->messages);
		_g_object_unref0 (_data40_->message_id);
		_g_object_unref0 (_data40_->folder_blacklist);
		_g_object_unref0 (_data40_->flag_blacklist);
		_g_object_unref0 (_data40_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block40Data, _data40_);
	}
}

static GearyDbTransactionOutcome
__lambda94_ (Block40Data* _data40_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBAccount* self;
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbStatement* _tmp5_;
	GearyDbStatement* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	GearyDbStatement* _tmp9_;
	GearyDbStatement* _tmp10_;
	GearyDbResult* _result_ = NULL;
	GearyDbStatement* _tmp11_;
	GearyDbResult* _tmp12_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data40_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_db_connection_prepare (cx, "SELECT id FROM MessageTable WHERE message_id = ? OR in_reply_to = ?", &_inner_error0_);
	stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp1_ = stmt;
	_tmp2_ = geary_rf_c822_decoded_message_data_to_rfc822_string (G_TYPE_CHECK_INSTANCE_CAST (_data40_->message_id, GEARY_RF_C822_TYPE_DECODED_MESSAGE_DATA, GearyRFC822DecodedMessageData));
	_tmp3_ = _tmp2_;
	_tmp4_ = geary_db_statement_bind_string (_tmp1_, 0, _tmp3_, &_inner_error0_);
	_tmp5_ = _tmp4_;
	_g_object_unref0 (_tmp5_);
	_g_free0 (_tmp3_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp6_ = stmt;
	_tmp7_ = geary_rf_c822_decoded_message_data_to_rfc822_string (G_TYPE_CHECK_INSTANCE_CAST (_data40_->message_id, GEARY_RF_C822_TYPE_DECODED_MESSAGE_DATA, GearyRFC822DecodedMessageData));
	_tmp8_ = _tmp7_;
	_tmp9_ = geary_db_statement_bind_string (_tmp6_, 1, _tmp8_, &_inner_error0_);
	_tmp10_ = _tmp9_;
	_g_object_unref0 (_tmp10_);
	_g_free0 (_tmp8_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp11_ = stmt;
	_tmp12_ = geary_db_statement_exec (_tmp11_, _data40_->cancellable, &_inner_error0_);
	_result_ = _tmp12_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	while (TRUE) {
		GearyDbResult* _tmp13_;
		gboolean _tmp14_;
		gboolean _tmp15_;
		gint64 id = 0LL;
		GearyDbResult* _tmp16_;
		GearyEmailField db_fields = 0;
		GearyImapDBMessageRow* row = NULL;
		GearyEmailField _tmp17_ = 0;
		GearyImapDBMessageRow* _tmp18_;
		gboolean _tmp19_ = FALSE;
		GearyDbResult* _tmp58_;
		_tmp13_ = _result_;
		_tmp14_ = geary_db_result_get_finished (_tmp13_);
		_tmp15_ = _tmp14_;
		if (!(!_tmp15_)) {
			break;
		}
		_tmp16_ = _result_;
		id = geary_db_result_int64_at (_tmp16_, 0, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (_result_);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp18_ = geary_imap_db_folder_do_fetch_message_row (cx, id, _data40_->requested_fields, &_tmp17_, _data40_->cancellable, &_inner_error0_);
		db_fields = _tmp17_;
		row = _tmp18_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (_result_);
			_g_object_unref0 (stmt);
			return 0;
		}
		if (_data40_->partial_ok) {
			_tmp19_ = TRUE;
		} else {
			GearyImapDBMessageRow* _tmp20_;
			GearyEmailField _tmp21_;
			GearyEmailField _tmp22_;
			_tmp20_ = row;
			_tmp21_ = geary_imap_db_message_row_get_fields (_tmp20_);
			_tmp22_ = _tmp21_;
			_tmp19_ = geary_email_field_fulfills (_tmp22_, _data40_->requested_fields);
		}
		if (_tmp19_) {
			GearyEmail* email = NULL;
			GearyImapDBMessageRow* _tmp23_;
			GearyImapDBEmailIdentifier* _tmp24_;
			GearyImapDBEmailIdentifier* _tmp25_;
			GearyEmail* _tmp26_;
			GearyEmail* _tmp27_;
			GearyImapDBDatabase* _tmp28_;
			GFile* _tmp29_;
			GearyEmail* _tmp30_;
			GeeSet* folders = NULL;
			GeeSet* _tmp31_;
			GeeSet* _tmp32_;
			gboolean _tmp48_ = FALSE;
			gboolean _tmp49_ = FALSE;
			_tmp23_ = row;
			_tmp24_ = geary_imap_db_email_identifier_new (id, NULL);
			_tmp25_ = _tmp24_;
			_tmp26_ = geary_imap_db_message_row_to_email (_tmp23_, _tmp25_, &_inner_error0_);
			_tmp27_ = _tmp26_;
			_g_object_unref0 (_tmp25_);
			email = _tmp27_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_geary_imap_db_message_row_unref0 (row);
				_g_object_unref0 (_result_);
				_g_object_unref0 (stmt);
				return 0;
			}
			_tmp28_ = self->priv->_db;
			_tmp29_ = _tmp28_->attachments_path;
			_tmp30_ = email;
			geary_imap_db_attachment_add_attachments (cx, _tmp29_, _tmp30_, id, _data40_->cancellable, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (email);
				_geary_imap_db_message_row_unref0 (row);
				_g_object_unref0 (_result_);
				_g_object_unref0 (stmt);
				return 0;
			}
			_tmp31_ = geary_imap_db_account_do_find_email_folders (self, cx, id, TRUE, _data40_->cancellable, &_inner_error0_);
			folders = _tmp31_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (email);
				_geary_imap_db_message_row_unref0 (row);
				_g_object_unref0 (_result_);
				_g_object_unref0 (stmt);
				return 0;
			}
			_tmp32_ = folders;
			if (_tmp32_ == NULL) {
				gboolean _tmp33_ = FALSE;
				if (_data40_->folder_blacklist == NULL) {
					_tmp33_ = TRUE;
				} else {
					_tmp33_ = !gee_collection_contains (_data40_->folder_blacklist, NULL);
				}
				if (_tmp33_) {
					GeeHashMultiMap* _tmp34_;
					GearyEmail* _tmp35_;
					_tmp34_ = _data40_->messages;
					_tmp35_ = email;
					gee_multi_map_set (G_TYPE_CHECK_INSTANCE_CAST (_tmp34_, GEE_TYPE_MULTI_MAP, GeeMultiMap), _tmp35_, NULL);
				}
			} else {
				{
					GeeIterator* _path_it = NULL;
					GeeSet* _tmp36_;
					GeeIterator* _tmp37_;
					_tmp36_ = folders;
					_tmp37_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp36_, GEE_TYPE_ITERABLE, GeeIterable));
					_path_it = _tmp37_;
					while (TRUE) {
						GeeIterator* _tmp38_;
						GearyFolderPath* path = NULL;
						GeeIterator* _tmp39_;
						gpointer _tmp40_;
						gboolean _tmp41_ = FALSE;
						_tmp38_ = _path_it;
						if (!gee_iterator_next (_tmp38_)) {
							break;
						}
						_tmp39_ = _path_it;
						_tmp40_ = gee_iterator_get (_tmp39_);
						path = (GearyFolderPath*) _tmp40_;
						if (_data40_->folder_blacklist != NULL) {
							GearyFolderPath* _tmp42_;
							_tmp42_ = path;
							_tmp41_ = gee_collection_contains (_data40_->folder_blacklist, _tmp42_);
						} else {
							_tmp41_ = FALSE;
						}
						if (_tmp41_) {
							GeeHashMultiMap* _tmp43_;
							GearyEmail* _tmp44_;
							_tmp43_ = _data40_->messages;
							_tmp44_ = email;
							gee_multi_map_remove_all (G_TYPE_CHECK_INSTANCE_CAST (_tmp43_, GEE_TYPE_MULTI_MAP, GeeMultiMap), _tmp44_);
							_g_object_unref0 (path);
							break;
						} else {
							GeeHashMultiMap* _tmp45_;
							GearyEmail* _tmp46_;
							GearyFolderPath* _tmp47_;
							_tmp45_ = _data40_->messages;
							_tmp46_ = email;
							_tmp47_ = path;
							gee_multi_map_set (G_TYPE_CHECK_INSTANCE_CAST (_tmp45_, GEE_TYPE_MULTI_MAP, GeeMultiMap), _tmp46_, _tmp47_);
						}
						_g_object_unref0 (path);
					}
					_g_object_unref0 (_path_it);
				}
			}
			if (_data40_->flag_blacklist != NULL) {
				GearyEmail* _tmp50_;
				GearyEmailFlags* _tmp51_;
				GearyEmailFlags* _tmp52_;
				_tmp50_ = email;
				_tmp51_ = geary_email_get_email_flags (_tmp50_);
				_tmp52_ = _tmp51_;
				_tmp49_ = _tmp52_ != NULL;
			} else {
				_tmp49_ = FALSE;
			}
			if (_tmp49_) {
				GearyEmail* _tmp53_;
				GearyEmailFlags* _tmp54_;
				GearyEmailFlags* _tmp55_;
				_tmp53_ = email;
				_tmp54_ = geary_email_get_email_flags (_tmp53_);
				_tmp55_ = _tmp54_;
				_tmp48_ = geary_named_flags_contains_any (G_TYPE_CHECK_INSTANCE_CAST (_tmp55_, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags), G_TYPE_CHECK_INSTANCE_CAST (_data40_->flag_blacklist, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags));
			} else {
				_tmp48_ = FALSE;
			}
			if (_tmp48_) {
				GeeHashMultiMap* _tmp56_;
				GearyEmail* _tmp57_;
				_tmp56_ = _data40_->messages;
				_tmp57_ = email;
				gee_multi_map_remove_all (G_TYPE_CHECK_INSTANCE_CAST (_tmp56_, GEE_TYPE_MULTI_MAP, GeeMultiMap), _tmp57_);
			}
			_g_object_unref0 (folders);
			_g_object_unref0 (email);
		}
		_tmp58_ = _result_;
		geary_db_result_next (_tmp58_, _data40_->cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_geary_imap_db_message_row_unref0 (row);
			_g_object_unref0 (_result_);
			_g_object_unref0 (stmt);
			return 0;
		}
		_geary_imap_db_message_row_unref0 (row);
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	_g_object_unref0 (_result_);
	_g_object_unref0 (stmt);
	return result;
}

static GearyDbTransactionOutcome
___lambda94__geary_db_transaction_method (GearyDbConnection* cx,
                                          GCancellable* cancellable,
                                          gpointer self,
                                          GError** error)
{
	GearyDbTransactionOutcome result;
	result = __lambda94_ (self, cx, error);
	return result;
}

static void
geary_imap_db_account_search_message_id_async_ready (GObject* source_object,
                                                     GAsyncResult* _res_,
                                                     gpointer _user_data_)
{
	GearyImapDbAccountSearchMessageIdAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_account_search_message_id_async_co (_data_);
}

static gboolean
geary_imap_db_account_search_message_id_async_co (GearyImapDbAccountSearchMessageIdAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data40_ = g_slice_new0 (Block40Data);
	_data_->_data40_->_ref_count_ = 1;
	_data_->_data40_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data40_->message_id);
	_data_->_data40_->message_id = _data_->message_id;
	_data_->_data40_->requested_fields = _data_->requested_fields;
	_data_->_data40_->partial_ok = _data_->partial_ok;
	_g_object_unref0 (_data_->_data40_->folder_blacklist);
	_data_->_data40_->folder_blacklist = _data_->folder_blacklist;
	_g_object_unref0 (_data_->_data40_->flag_blacklist);
	_data_->_data40_->flag_blacklist = _data_->flag_blacklist;
	_g_object_unref0 (_data_->_data40_->cancellable);
	_data_->_data40_->cancellable = _data_->cancellable;
	_data_->_data40_->_async_data_ = _data_;
	geary_imap_db_account_check_open (_data_->self, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block40_data_unref (_data_->_data40_);
		_data_->_data40_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp0_ = gee_hash_multi_map_new (GEARY_TYPE_EMAIL, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEARY_TYPE_FOLDER_PATH, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->_data40_->messages = _data_->_tmp0_;
	if (_data_->_data40_->flag_blacklist != NULL) {
		_data_->_data40_->requested_fields = _data_->_data40_->requested_fields | GEARY_EMAIL_FIELD_FLAGS;
	}
	_data_->_tmp1_ = _data_->self->priv->_db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), GEARY_DB_TRANSACTION_TYPE_RO, ___lambda94__geary_db_transaction_method, _data_->_data40_, _data_->_data40_->cancellable, geary_imap_db_account_search_message_id_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block40_data_unref (_data_->_data40_);
		_data_->_data40_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp3_ = _data_->_data40_->messages;
	_data_->_tmp4_ = gee_multi_map_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp3_, GEE_TYPE_MULTI_MAP, GeeMultiMap));
	_data_->_tmp5_ = _data_->_tmp4_;
	if (_data_->_tmp5_ == 0) {
		_data_->_tmp2_ = NULL;
	} else {
		_data_->_tmp6_ = _data_->_data40_->messages;
		_data_->_tmp2_ = _data_->_tmp6_;
	}
	_data_->_tmp7_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, GEE_TYPE_MULTI_MAP, GeeMultiMap));
	_data_->result = _data_->_tmp7_;
	block40_data_unref (_data_->_data40_);
	_data_->_data40_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_db_account_sql_append_ids (GearyImapDBAccount* self,
                                      GString* s,
                                      GeeIterable* ids)
{
	gboolean first = FALSE;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail (s != NULL);
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_ITERABLE));
	first = TRUE;
	{
		GeeIterator* _id_it = NULL;
		GeeIterator* _tmp0_;
		_tmp0_ = gee_iterable_iterator (ids);
		_id_it = _tmp0_;
		while (TRUE) {
			GeeIterator* _tmp1_;
			gint64* id = NULL;
			GeeIterator* _tmp2_;
			gpointer _tmp3_;
			gint64* _tmp4_;
			gint64* _tmp5_;
			gchar* _tmp6_;
			gchar* _tmp7_;
			_tmp1_ = _id_it;
			if (!gee_iterator_next (_tmp1_)) {
				break;
			}
			_tmp2_ = _id_it;
			_tmp3_ = gee_iterator_get (_tmp2_);
			id = (gint64*) _tmp3_;
			_tmp4_ = id;
			_vala_assert (_tmp4_ != NULL, "id != null");
			if (!first) {
				g_string_append (s, ", ");
			}
			_tmp5_ = id;
			_tmp6_ = g_strdup_printf ("%" G_GINT64_FORMAT, *_tmp5_);
			_tmp7_ = _tmp6_;
			g_string_append (s, _tmp7_);
			_g_free0 (_tmp7_);
			first = FALSE;
			_g_free0 (id);
		}
		_g_object_unref0 (_id_it);
	}
}

static gchar*
geary_imap_db_account_get_search_ids_sql (GearyImapDBAccount* self,
                                          GeeCollection* search_ids,
                                          GError** error)
{
	GeeArrayList* ids = NULL;
	GeeArrayList* _tmp0_;
	GString* sql = NULL;
	GString* _tmp13_;
	GString* _tmp14_;
	GeeArrayList* _tmp15_;
	GString* _tmp16_;
	const gchar* _tmp17_;
	gchar* _tmp18_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self), NULL);
	g_return_val_if_fail ((search_ids == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (search_ids, GEE_TYPE_COLLECTION), NULL);
	if (search_ids == NULL) {
		result = NULL;
		return result;
	}
	_tmp0_ = gee_array_list_new (G_TYPE_INT64, (GBoxedCopyFunc) _int64_dup, (GDestroyNotify) g_free, NULL, NULL, NULL);
	ids = _tmp0_;
	{
		GeeIterator* _id_it = NULL;
		GeeIterator* _tmp1_;
		_tmp1_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (search_ids, GEE_TYPE_ITERABLE, GeeIterable));
		_id_it = _tmp1_;
		while (TRUE) {
			GeeIterator* _tmp2_;
			GearyEmailIdentifier* id = NULL;
			GeeIterator* _tmp3_;
			gpointer _tmp4_;
			GearyImapDBEmailIdentifier* imapdb_id = NULL;
			GearyEmailIdentifier* _tmp5_;
			GearyImapDBEmailIdentifier* _tmp6_;
			GearyImapDBEmailIdentifier* _tmp7_;
			GeeArrayList* _tmp9_;
			GearyImapDBEmailIdentifier* _tmp10_;
			gint64 _tmp11_;
			gint64 _tmp12_;
			_tmp2_ = _id_it;
			if (!gee_iterator_next (_tmp2_)) {
				break;
			}
			_tmp3_ = _id_it;
			_tmp4_ = gee_iterator_get (_tmp3_);
			id = (GearyEmailIdentifier*) _tmp4_;
			_tmp5_ = id;
			_tmp6_ = _g_object_ref0 (GEARY_IMAP_DB_IS_EMAIL_IDENTIFIER (_tmp5_) ? ((GearyImapDBEmailIdentifier*) _tmp5_) : NULL);
			imapdb_id = _tmp6_;
			_tmp7_ = imapdb_id;
			if (_tmp7_ == NULL) {
				GError* _tmp8_;
				_tmp8_ = g_error_new_literal (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_BAD_PARAMETERS, "search_ids must contain only Geary.ImapDB.EmailIdentifiers");
				_inner_error0_ = _tmp8_;
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (imapdb_id);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				_g_object_unref0 (ids);
				return NULL;
			}
			_tmp9_ = ids;
			_tmp10_ = imapdb_id;
			_tmp11_ = geary_imap_db_email_identifier_get_message_id (_tmp10_);
			_tmp12_ = _tmp11_;
			gee_abstract_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp9_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection), &_tmp12_);
			_g_object_unref0 (imapdb_id);
			_g_object_unref0 (id);
		}
		_g_object_unref0 (_id_it);
	}
	_tmp13_ = g_string_new ("");
	sql = _tmp13_;
	_tmp14_ = sql;
	_tmp15_ = ids;
	geary_imap_db_account_sql_append_ids (self, _tmp14_, G_TYPE_CHECK_INSTANCE_CAST (_tmp15_, GEE_TYPE_ITERABLE, GeeIterable));
	_tmp16_ = sql;
	_tmp17_ = _tmp16_->str;
	_tmp18_ = g_strdup (_tmp17_);
	result = _tmp18_;
	_g_string_free0 (sql);
	_g_object_unref0 (ids);
	return result;
}

static void
geary_imap_db_account_search_async_data_free (gpointer _data)
{
	GearyImapDbAccountSearchAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->q);
	_g_object_unref0 (_data_->search_ids);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbAccountSearchAsyncData, _data_);
}

void
geary_imap_db_account_search_async (GearyImapDBAccount* self,
                                    GearySearchQuery* q,
                                    gint limit,
                                    gint offset,
                                    GeeCollection* excluded_folders,
                                    GeeCollection* search_ids,
                                    GCancellable* cancellable,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_)
{
	GearyImapDbAccountSearchAsyncData* _data_;
	GearyImapDBAccount* _tmp0_;
	GearySearchQuery* _tmp1_;
	GeeCollection* _tmp2_;
	GeeCollection* _tmp3_;
	GCancellable* _tmp4_;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail (GEARY_IS_SEARCH_QUERY (q));
	g_return_if_fail ((excluded_folders == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (excluded_folders, GEE_TYPE_COLLECTION));
	g_return_if_fail ((search_ids == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (search_ids, GEE_TYPE_COLLECTION));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbAccountSearchAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_account_search_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (q);
	_g_object_unref0 (_data_->q);
	_data_->q = _tmp1_;
	_data_->limit = limit;
	_data_->offset = offset;
	_tmp2_ = _g_object_ref0 (excluded_folders);
	_g_object_unref0 (_data_->excluded_folders);
	_data_->excluded_folders = _tmp2_;
	_tmp3_ = _g_object_ref0 (search_ids);
	_g_object_unref0 (_data_->search_ids);
	_data_->search_ids = _tmp3_;
	_tmp4_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp4_;
	geary_imap_db_account_search_async_co (_data_);
}

GeeCollection*
geary_imap_db_account_search_finish (GearyImapDBAccount* self,
                                     GAsyncResult* _res_,
                                     GError** error)
{
	GeeCollection* result;
	GearyImapDbAccountSearchAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block41Data*
block41_data_ref (Block41Data* _data41_)
{
	g_atomic_int_inc (&_data41_->_ref_count_);
	return _data41_;
}

static void
block41_data_unref (void * _userdata_)
{
	Block41Data* _data41_;
	_data41_ = (Block41Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data41_->_ref_count_)) {
		GearyImapDBAccount* self;
		self = _data41_->self;
		_g_object_unref0 (_data41_->search_matches);
		_g_object_unref0 (_data41_->matching_ids);
		_g_free0 (_data41_->search_ids_sql);
		_g_object_unref0 (_data41_->query);
		_g_object_unref0 (_data41_->excluded_folders);
		_g_object_unref0 (_data41_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block41Data, _data41_);
	}
}

static guint
_geary_collection_int64_hash_func_gee_hash_data_func (gconstpointer v,
                                                      gpointer self)
{
	guint result;
	result = geary_collection_int64_hash_func ((gint64*) v);
	return result;
}

static gboolean
_geary_collection_int64_equal_func_gee_equal_data_func (gconstpointer a,
                                                        gconstpointer b,
                                                        gpointer self)
{
	gboolean result;
	result = geary_collection_int64_equal_func ((gint64*) a, (gint64*) b);
	return result;
}

static GearyDbTransactionOutcome
__lambda95_ (Block41Data* _data41_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBAccount* self;
	gchar* excluded_folder_ids_sql = NULL;
	gboolean exclude_folderless = FALSE;
	GeeHashMap* id_map = NULL;
	GeeHashMap* _tmp4_;
	GearyDbStatement* stmt = NULL;
	GearyFtsSearchQuery* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	GearyDbStatement* _tmp8_;
	GearyDbStatement* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	GearyDbResult* _result_ = NULL;
	GearyDbStatement* _tmp12_;
	GearyDbResult* _tmp13_;
	gboolean _tmp24_ = FALSE;
	GearyFtsSearchQuery* _tmp25_;
	gboolean _tmp26_;
	gboolean _tmp27_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data41_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	excluded_folder_ids_sql = NULL;
	exclude_folderless = FALSE;
	if (_data41_->excluded_folders != NULL) {
		gchar* _tmp0_ = NULL;
		gboolean _tmp1_ = FALSE;
		gchar* _tmp2_;
		gchar* _tmp3_;
		_tmp2_ = geary_imap_db_account_do_get_excluded_folder_ids (self, _data41_->excluded_folders, cx, &_tmp1_, _data41_->cancellable, &_inner_error0_);
		exclude_folderless = _tmp1_;
		_tmp0_ = _tmp2_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_free0 (excluded_folder_ids_sql);
			return 0;
		}
		_tmp3_ = _tmp0_;
		_tmp0_ = NULL;
		_g_free0 (excluded_folder_ids_sql);
		excluded_folder_ids_sql = _tmp3_;
		_g_free0 (_tmp0_);
	}
	_tmp4_ = gee_hash_map_new (G_TYPE_INT64, (GBoxedCopyFunc) _int64_dup, (GDestroyNotify) g_free, GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _geary_collection_int64_hash_func_gee_hash_data_func, NULL, NULL, _geary_collection_int64_equal_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	id_map = _tmp4_;
	_tmp5_ = _data41_->query;
	_tmp6_ = _data41_->search_ids_sql;
	_tmp7_ = excluded_folder_ids_sql;
	_tmp8_ = geary_fts_search_query_get_search_query (_tmp5_, cx, _tmp6_, _tmp7_, exclude_folderless, _data41_->limit, _data41_->offset, &_inner_error0_);
	stmt = _tmp8_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (id_map);
		_g_free0 (excluded_folder_ids_sql);
		return 0;
	}
	_tmp9_ = stmt;
	_tmp10_ = geary_db_statement_get_expanded_sql (_tmp9_);
	_tmp11_ = _tmp10_;
	g_debug ("imap-db-account.vala:615: Search SQL: %s", _tmp11_);
	_g_free0 (_tmp11_);
	_tmp12_ = stmt;
	_tmp13_ = geary_db_statement_exec (_tmp12_, _data41_->cancellable, &_inner_error0_);
	_result_ = _tmp13_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_object_unref0 (id_map);
		_g_free0 (excluded_folder_ids_sql);
		return 0;
	}
	while (TRUE) {
		GearyDbResult* _tmp14_;
		gboolean _tmp15_;
		gboolean _tmp16_;
		gint64 message_id = 0LL;
		GearyDbResult* _tmp17_;
		GearyImapDBEmailIdentifier* id = NULL;
		GearyImapDBEmailIdentifier* _tmp18_;
		GeeList* _tmp19_;
		GearyImapDBEmailIdentifier* _tmp20_;
		GeeHashMap* _tmp21_;
		GearyImapDBEmailIdentifier* _tmp22_;
		GearyDbResult* _tmp23_;
		_tmp14_ = _result_;
		_tmp15_ = geary_db_result_get_finished (_tmp14_);
		_tmp16_ = _tmp15_;
		if (!(!_tmp16_)) {
			break;
		}
		_tmp17_ = _result_;
		message_id = geary_db_result_int64_at (_tmp17_, 0, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (_result_);
			_g_object_unref0 (stmt);
			_g_object_unref0 (id_map);
			_g_free0 (excluded_folder_ids_sql);
			return 0;
		}
		_tmp18_ = geary_imap_db_email_identifier_new (message_id, NULL);
		id = _tmp18_;
		_tmp19_ = _data41_->matching_ids;
		_tmp20_ = id;
		gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp19_, GEE_TYPE_COLLECTION, GeeCollection), _tmp20_);
		_tmp21_ = id_map;
		_tmp22_ = id;
		gee_abstract_map_set (G_TYPE_CHECK_INSTANCE_CAST (_tmp21_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), &message_id, _tmp22_);
		_tmp23_ = _result_;
		geary_db_result_next (_tmp23_, _data41_->cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (id);
			_g_object_unref0 (_result_);
			_g_object_unref0 (stmt);
			_g_object_unref0 (id_map);
			_g_free0 (excluded_folder_ids_sql);
			return 0;
		}
		_g_object_unref0 (id);
	}
	_tmp25_ = _data41_->query;
	_tmp26_ = geary_fts_search_query_get_has_stemmed_terms (_tmp25_);
	_tmp27_ = _tmp26_;
	if (_tmp27_) {
		GeeHashMap* _tmp28_;
		gboolean _tmp29_;
		gboolean _tmp30_;
		_tmp28_ = id_map;
		_tmp29_ = gee_map_get_is_empty (G_TYPE_CHECK_INSTANCE_CAST (_tmp28_, GEE_TYPE_MAP, GeeMap));
		_tmp30_ = _tmp29_;
		_tmp24_ = !_tmp30_;
	} else {
		_tmp24_ = FALSE;
	}
	if (_tmp24_) {
		GeeMap* _tmp31_ = NULL;
		GearyFtsSearchQuery* _tmp32_;
		GeeHashMap* _tmp33_;
		GeeMap* _tmp34_;
		GeeMap* _tmp35_;
		_tmp32_ = _data41_->query;
		_tmp33_ = id_map;
		_tmp34_ = geary_imap_db_account_do_get_search_matches (self, cx, _tmp32_, G_TYPE_CHECK_INSTANCE_CAST (_tmp33_, GEE_TYPE_MAP, GeeMap), _data41_->cancellable, &_inner_error0_);
		_tmp31_ = _tmp34_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (_result_);
			_g_object_unref0 (stmt);
			_g_object_unref0 (id_map);
			_g_free0 (excluded_folder_ids_sql);
			return 0;
		}
		_tmp35_ = _tmp31_;
		_tmp31_ = NULL;
		_g_object_unref0 (_data41_->search_matches);
		_data41_->search_matches = _tmp35_;
		_g_object_unref0 (_tmp31_);
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	_g_object_unref0 (_result_);
	_g_object_unref0 (stmt);
	_g_object_unref0 (id_map);
	_g_free0 (excluded_folder_ids_sql);
	return result;
}

static GearyDbTransactionOutcome
___lambda95__geary_db_transaction_method (GearyDbConnection* cx,
                                          GCancellable* cancellable,
                                          gpointer self,
                                          GError** error)
{
	GearyDbTransactionOutcome result;
	result = __lambda95_ (self, cx, error);
	return result;
}

static void
geary_imap_db_account_search_async_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_)
{
	GearyImapDbAccountSearchAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_account_search_async_co (_data_);
}

static gboolean
geary_imap_db_account_search_async_co (GearyImapDbAccountSearchAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data41_ = g_slice_new0 (Block41Data);
	_data_->_data41_->_ref_count_ = 1;
	_data_->_data41_->self = g_object_ref (_data_->self);
	_data_->_data41_->limit = _data_->limit;
	_data_->_data41_->offset = _data_->offset;
	_g_object_unref0 (_data_->_data41_->excluded_folders);
	_data_->_data41_->excluded_folders = _data_->excluded_folders;
	_g_object_unref0 (_data_->_data41_->cancellable);
	_data_->_data41_->cancellable = _data_->cancellable;
	_data_->_data41_->_async_data_ = _data_;
	_data_->_tmp0_ = geary_search_query_to_string (_data_->q);
	_data_->_tmp1_ = _data_->_tmp0_;
	g_debug ("imap-db-account.vala:585: Search query: %s", _data_->_tmp1_);
	_g_free0 (_data_->_tmp1_);
	geary_imap_db_account_check_open (_data_->self, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block41_data_unref (_data_->_data41_);
		_data_->_data41_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp2_ = geary_imap_db_account_check_search_query (_data_->self, _data_->q, &_data_->_inner_error0_);
	_data_->_data41_->query = _data_->_tmp2_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block41_data_unref (_data_->_data41_);
		_data_->_data41_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp3_ = geary_imap_db_account_get_search_ids_sql (_data_->self, _data_->search_ids, &_data_->_inner_error0_);
	_data_->_data41_->search_ids_sql = _data_->_tmp3_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block41_data_unref (_data_->_data41_);
		_data_->_data41_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp4_ = gee_linked_list_new (GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data_->_data41_->matching_ids = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp4_, GEE_TYPE_LIST, GeeList);
	_data_->_data41_->search_matches = NULL;
	_data_->_tmp5_ = _data_->self->priv->_db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp5_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), GEARY_DB_TRANSACTION_TYPE_RO, ___lambda95__geary_db_transaction_method, _data_->_data41_, _data_->_data41_->cancellable, geary_imap_db_account_search_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp5_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block41_data_unref (_data_->_data41_);
		_data_->_data41_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp6_ = _data_->_data41_->matching_ids;
	_data_->_tmp7_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp6_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp8_ = _data_->_tmp7_;
	g_debug ("imap-db-account.vala:635: Matching emails found: %d", _data_->_tmp8_);
	_data_->_tmp10_ = _data_->_data41_->matching_ids;
	_data_->_tmp11_ = gee_collection_get_is_empty (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp10_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp12_ = _data_->_tmp11_;
	if (_data_->_tmp12_) {
		_data_->_tmp9_ = NULL;
	} else {
		_data_->_tmp13_ = _data_->_data41_->matching_ids;
		_data_->_tmp9_ = _data_->_tmp13_;
	}
	_data_->_tmp14_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp9_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->result = _data_->_tmp14_;
	block41_data_unref (_data_->_data41_);
	_data_->_data41_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_db_account_get_search_matches_async_data_free (gpointer _data)
{
	GearyImapDbAccountGetSearchMatchesAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->q);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbAccountGetSearchMatchesAsyncData, _data_);
}

void
geary_imap_db_account_get_search_matches_async (GearyImapDBAccount* self,
                                                GearySearchQuery* q,
                                                GeeCollection* ids,
                                                GCancellable* cancellable,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_)
{
	GearyImapDbAccountGetSearchMatchesAsyncData* _data_;
	GearyImapDBAccount* _tmp0_;
	GearySearchQuery* _tmp1_;
	GeeCollection* _tmp2_;
	GCancellable* _tmp3_;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail (GEARY_IS_SEARCH_QUERY (q));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbAccountGetSearchMatchesAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_account_get_search_matches_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (q);
	_g_object_unref0 (_data_->q);
	_data_->q = _tmp1_;
	_tmp2_ = _g_object_ref0 (ids);
	_g_object_unref0 (_data_->ids);
	_data_->ids = _tmp2_;
	_tmp3_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp3_;
	geary_imap_db_account_get_search_matches_async_co (_data_);
}

GeeSet*
geary_imap_db_account_get_search_matches_finish (GearyImapDBAccount* self,
                                                 GAsyncResult* _res_,
                                                 GError** error)
{
	GeeSet* result;
	GearyImapDbAccountGetSearchMatchesAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block42Data*
block42_data_ref (Block42Data* _data42_)
{
	g_atomic_int_inc (&_data42_->_ref_count_);
	return _data42_;
}

static void
block42_data_unref (void * _userdata_)
{
	Block42Data* _data42_;
	_data42_ = (Block42Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data42_->_ref_count_)) {
		GearyImapDBAccount* self;
		self = _data42_->self;
		_g_object_unref0 (_data42_->search_matches);
		_g_object_unref0 (_data42_->query);
		_g_object_unref0 (_data42_->ids);
		_g_object_unref0 (_data42_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block42Data, _data42_);
	}
}

static GearyDbTransactionOutcome
__lambda96_ (Block42Data* _data42_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBAccount* self;
	GeeHashMap* id_map = NULL;
	GeeHashMap* _tmp0_;
	GeeMap* match_map = NULL;
	GeeHashMap* _tmp10_;
	gboolean _tmp11_;
	gboolean _tmp12_;
	gboolean _tmp18_ = FALSE;
	GeeMap* _tmp19_;
	GeeHashSet* _tmp23_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data42_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = gee_hash_map_new (G_TYPE_INT64, (GBoxedCopyFunc) _int64_dup, (GDestroyNotify) g_free, GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _geary_collection_int64_hash_func_gee_hash_data_func, NULL, NULL, _geary_collection_int64_equal_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	id_map = _tmp0_;
	{
		GeeIterator* _id_it = NULL;
		GeeIterator* _tmp1_;
		_tmp1_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_data42_->ids, GEE_TYPE_ITERABLE, GeeIterable));
		_id_it = _tmp1_;
		while (TRUE) {
			GeeIterator* _tmp2_;
			GearyImapDBEmailIdentifier* id = NULL;
			GeeIterator* _tmp3_;
			gpointer _tmp4_;
			GeeHashMap* _tmp5_;
			GearyImapDBEmailIdentifier* _tmp6_;
			gint64 _tmp7_;
			gint64 _tmp8_;
			GearyImapDBEmailIdentifier* _tmp9_;
			_tmp2_ = _id_it;
			if (!gee_iterator_next (_tmp2_)) {
				break;
			}
			_tmp3_ = _id_it;
			_tmp4_ = gee_iterator_get (_tmp3_);
			id = (GearyImapDBEmailIdentifier*) _tmp4_;
			_tmp5_ = id_map;
			_tmp6_ = id;
			_tmp7_ = geary_imap_db_email_identifier_get_message_id (_tmp6_);
			_tmp8_ = _tmp7_;
			_tmp9_ = id;
			gee_abstract_map_set (G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), &_tmp8_, _tmp9_);
			_g_object_unref0 (id);
		}
		_g_object_unref0 (_id_it);
	}
	match_map = NULL;
	_tmp10_ = id_map;
	_tmp11_ = gee_map_get_is_empty (G_TYPE_CHECK_INSTANCE_CAST (_tmp10_, GEE_TYPE_MAP, GeeMap));
	_tmp12_ = _tmp11_;
	if (!_tmp12_) {
		GeeMap* _tmp13_ = NULL;
		GearyFtsSearchQuery* _tmp14_;
		GeeHashMap* _tmp15_;
		GeeMap* _tmp16_;
		GeeMap* _tmp17_;
		_tmp14_ = _data42_->query;
		_tmp15_ = id_map;
		_tmp16_ = geary_imap_db_account_do_get_search_matches (self, cx, _tmp14_, G_TYPE_CHECK_INSTANCE_CAST (_tmp15_, GEE_TYPE_MAP, GeeMap), _data42_->cancellable, &_inner_error0_);
		_tmp13_ = _tmp16_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (match_map);
			_g_object_unref0 (id_map);
			return 0;
		}
		_tmp17_ = _tmp13_;
		_tmp13_ = NULL;
		_g_object_unref0 (match_map);
		match_map = _tmp17_;
		_g_object_unref0 (_tmp13_);
	}
	_tmp19_ = match_map;
	if (_tmp19_ == NULL) {
		_tmp18_ = TRUE;
	} else {
		GeeMap* _tmp20_;
		gint _tmp21_;
		gint _tmp22_;
		_tmp20_ = match_map;
		_tmp21_ = gee_map_get_size (_tmp20_);
		_tmp22_ = _tmp21_;
		_tmp18_ = _tmp22_ == 0;
	}
	if (_tmp18_) {
		result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
		_g_object_unref0 (match_map);
		_g_object_unref0 (id_map);
		return result;
	}
	_tmp23_ = gee_hash_set_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL, NULL, NULL, NULL);
	_g_object_unref0 (_data42_->search_matches);
	_data42_->search_matches = G_TYPE_CHECK_INSTANCE_CAST (_tmp23_, GEE_TYPE_SET, GeeSet);
	{
		GeeIterator* _matches_it = NULL;
		GeeMap* _tmp24_;
		GeeCollection* _tmp25_;
		GeeCollection* _tmp26_;
		GeeCollection* _tmp27_;
		GeeIterator* _tmp28_;
		GeeIterator* _tmp29_;
		_tmp24_ = match_map;
		_tmp25_ = gee_map_get_values (_tmp24_);
		_tmp26_ = _tmp25_;
		_tmp27_ = _tmp26_;
		_tmp28_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp27_, GEE_TYPE_ITERABLE, GeeIterable));
		_tmp29_ = _tmp28_;
		_g_object_unref0 (_tmp27_);
		_matches_it = _tmp29_;
		while (TRUE) {
			GeeIterator* _tmp30_;
			GeeSet* matches = NULL;
			GeeIterator* _tmp31_;
			gpointer _tmp32_;
			GeeSet* _tmp33_;
			GeeSet* _tmp34_;
			_tmp30_ = _matches_it;
			if (!gee_iterator_next (_tmp30_)) {
				break;
			}
			_tmp31_ = _matches_it;
			_tmp32_ = gee_iterator_get (_tmp31_);
			matches = (GeeSet*) _tmp32_;
			_tmp33_ = _data42_->search_matches;
			_tmp34_ = matches;
			gee_collection_add_all (G_TYPE_CHECK_INSTANCE_CAST (_tmp33_, GEE_TYPE_COLLECTION, GeeCollection), G_TYPE_CHECK_INSTANCE_CAST (_tmp34_, GEE_TYPE_COLLECTION, GeeCollection));
			_g_object_unref0 (matches);
		}
		_g_object_unref0 (_matches_it);
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	_g_object_unref0 (match_map);
	_g_object_unref0 (id_map);
	return result;
}

static GearyDbTransactionOutcome
___lambda96__geary_db_transaction_method (GearyDbConnection* cx,
                                          GCancellable* cancellable,
                                          gpointer self,
                                          GError** error)
{
	GearyDbTransactionOutcome result;
	result = __lambda96_ (self, cx, error);
	return result;
}

static void
geary_imap_db_account_get_search_matches_async_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_)
{
	GearyImapDbAccountGetSearchMatchesAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_account_get_search_matches_async_co (_data_);
}

static gboolean
geary_imap_db_account_get_search_matches_async_co (GearyImapDbAccountGetSearchMatchesAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data42_ = g_slice_new0 (Block42Data);
	_data_->_data42_->_ref_count_ = 1;
	_data_->_data42_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data42_->ids);
	_data_->_data42_->ids = _data_->ids;
	_g_object_unref0 (_data_->_data42_->cancellable);
	_data_->_data42_->cancellable = _data_->cancellable;
	_data_->_data42_->_async_data_ = _data_;
	geary_imap_db_account_check_open (_data_->self, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block42_data_unref (_data_->_data42_);
		_data_->_data42_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp0_ = geary_imap_db_account_check_search_query (_data_->self, _data_->q, &_data_->_inner_error0_);
	_data_->_data42_->query = _data_->_tmp0_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block42_data_unref (_data_->_data42_);
		_data_->_data42_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_data42_->search_matches = NULL;
	_data_->_tmp1_ = _data_->self->priv->_db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), GEARY_DB_TRANSACTION_TYPE_RO, ___lambda96__geary_db_transaction_method, _data_->_data42_, _data_->_data42_->cancellable, geary_imap_db_account_get_search_matches_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block42_data_unref (_data_->_data42_);
		_data_->_data42_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp2_ = _data_->_data42_->search_matches;
	_data_->_tmp3_ = _g_object_ref0 (_data_->_tmp2_);
	_data_->result = _data_->_tmp3_;
	block42_data_unref (_data_->_data42_);
	_data_->_data42_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_db_account_list_email_data_free (gpointer _data)
{
	GearyImapDbAccountListEmailData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbAccountListEmailData, _data_);
}

void
geary_imap_db_account_list_email (GearyImapDBAccount* self,
                                  GeeCollection* ids,
                                  GearyEmailField required_fields,
                                  GCancellable* cancellable,
                                  GAsyncReadyCallback _callback_,
                                  gpointer _user_data_)
{
	GearyImapDbAccountListEmailData* _data_;
	GearyImapDBAccount* _tmp0_;
	GeeCollection* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbAccountListEmailData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_account_list_email_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (ids);
	_g_object_unref0 (_data_->ids);
	_data_->ids = _tmp1_;
	_data_->required_fields = required_fields;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_account_list_email_co (_data_);
}

GeeList*
geary_imap_db_account_list_email_finish (GearyImapDBAccount* self,
                                         GAsyncResult* _res_,
                                         GError** error)
{
	GeeList* result;
	GearyImapDbAccountListEmailData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block43Data*
block43_data_ref (Block43Data* _data43_)
{
	g_atomic_int_inc (&_data43_->_ref_count_);
	return _data43_;
}

static void
block43_data_unref (void * _userdata_)
{
	Block43Data* _data43_;
	_data43_ = (Block43Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data43_->_ref_count_)) {
		GearyImapDBAccount* self;
		self = _data43_->self;
		_g_object_unref0 (_data43_->results);
		_g_object_unref0 (_data43_->ids);
		_g_object_unref0 (_data43_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block43Data, _data43_);
	}
}

static GearyDbTransactionOutcome
__lambda97_ (Block43Data* _data43_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBAccount* self;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data43_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	{
		GeeIterator* _id_it = NULL;
		GeeIterator* _tmp0_;
		_tmp0_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_data43_->ids, GEE_TYPE_ITERABLE, GeeIterable));
		_id_it = _tmp0_;
		while (TRUE) {
			GeeIterator* _tmp1_;
			GearyImapDBEmailIdentifier* id = NULL;
			GeeIterator* _tmp2_;
			gpointer _tmp3_;
			GearyEmailField db_fields = 0;
			GearyImapDBMessageRow* row = NULL;
			GearyImapDBEmailIdentifier* _tmp4_;
			gint64 _tmp5_;
			gint64 _tmp6_;
			GearyEmailField _tmp7_ = 0;
			GearyImapDBMessageRow* _tmp8_;
			GearyImapDBMessageRow* _tmp9_;
			GearyEmailField _tmp10_;
			GearyEmailField _tmp11_;
			GearyEmail* email = NULL;
			GearyImapDBMessageRow* _tmp20_;
			GearyImapDBEmailIdentifier* _tmp21_;
			GearyEmail* _tmp22_;
			GearyImapDBDatabase* _tmp23_;
			GFile* _tmp24_;
			GearyEmail* _tmp25_;
			GearyImapDBEmailIdentifier* _tmp26_;
			gint64 _tmp27_;
			gint64 _tmp28_;
			GeeArrayList* _tmp29_;
			GearyEmail* _tmp30_;
			_tmp1_ = _id_it;
			if (!gee_iterator_next (_tmp1_)) {
				break;
			}
			_tmp2_ = _id_it;
			_tmp3_ = gee_iterator_get (_tmp2_);
			id = (GearyImapDBEmailIdentifier*) _tmp3_;
			_tmp4_ = id;
			_tmp5_ = geary_imap_db_email_identifier_get_message_id (_tmp4_);
			_tmp6_ = _tmp5_;
			_tmp8_ = geary_imap_db_folder_do_fetch_message_row (cx, _tmp6_, _data43_->required_fields, &_tmp7_, _data43_->cancellable, &_inner_error0_);
			db_fields = _tmp7_;
			row = _tmp8_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				return 0;
			}
			_tmp9_ = row;
			_tmp10_ = geary_imap_db_message_row_get_fields (_tmp9_);
			_tmp11_ = _tmp10_;
			if (!geary_email_field_fulfills (_tmp11_, _data43_->required_fields)) {
				GearyImapDBEmailIdentifier* _tmp12_;
				gchar* _tmp13_;
				gchar* _tmp14_;
				GearyImapDBMessageRow* _tmp15_;
				GearyEmailField _tmp16_;
				GearyEmailField _tmp17_;
				GError* _tmp18_;
				GError* _tmp19_;
				_tmp12_ = id;
				_tmp13_ = geary_email_identifier_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp12_, GEARY_TYPE_EMAIL_IDENTIFIER, GearyEmailIdentifier));
				_tmp14_ = _tmp13_;
				_tmp15_ = row;
				_tmp16_ = geary_imap_db_message_row_get_fields (_tmp15_);
				_tmp17_ = _tmp16_;
				_tmp18_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_INCOMPLETE_MESSAGE, "Message %s only fulfills %Xh fields (required: %Xh)", _tmp14_, (guint) _tmp17_, (guint) _data43_->required_fields);
				_tmp19_ = _tmp18_;
				_g_free0 (_tmp14_);
				_inner_error0_ = _tmp19_;
				g_propagate_error (error, _inner_error0_);
				_geary_imap_db_message_row_unref0 (row);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				return 0;
			}
			_tmp20_ = row;
			_tmp21_ = id;
			_tmp22_ = geary_imap_db_message_row_to_email (_tmp20_, _tmp21_, &_inner_error0_);
			email = _tmp22_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_geary_imap_db_message_row_unref0 (row);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				return 0;
			}
			_tmp23_ = self->priv->_db;
			_tmp24_ = _tmp23_->attachments_path;
			_tmp25_ = email;
			_tmp26_ = id;
			_tmp27_ = geary_imap_db_email_identifier_get_message_id (_tmp26_);
			_tmp28_ = _tmp27_;
			geary_imap_db_attachment_add_attachments (cx, _tmp24_, _tmp25_, _tmp28_, _data43_->cancellable, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (email);
				_geary_imap_db_message_row_unref0 (row);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				return 0;
			}
			_tmp29_ = _data43_->results;
			_tmp30_ = email;
			gee_abstract_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp29_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection), _tmp30_);
			_g_object_unref0 (email);
			_geary_imap_db_message_row_unref0 (row);
			_g_object_unref0 (id);
		}
		_g_object_unref0 (_id_it);
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	return result;
}

static GearyDbTransactionOutcome
___lambda97__geary_db_transaction_method (GearyDbConnection* cx,
                                          GCancellable* cancellable,
                                          gpointer self,
                                          GError** error)
{
	GearyDbTransactionOutcome result;
	result = __lambda97_ (self, cx, error);
	return result;
}

static void
geary_imap_db_account_list_email_ready (GObject* source_object,
                                        GAsyncResult* _res_,
                                        gpointer _user_data_)
{
	GearyImapDbAccountListEmailData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_account_list_email_co (_data_);
}

static gboolean
geary_imap_db_account_list_email_co (GearyImapDbAccountListEmailData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data43_ = g_slice_new0 (Block43Data);
	_data_->_data43_->_ref_count_ = 1;
	_data_->_data43_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data43_->ids);
	_data_->_data43_->ids = _data_->ids;
	_data_->_data43_->required_fields = _data_->required_fields;
	_g_object_unref0 (_data_->_data43_->cancellable);
	_data_->_data43_->cancellable = _data_->cancellable;
	_data_->_data43_->_async_data_ = _data_;
	geary_imap_db_account_check_open (_data_->self, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block43_data_unref (_data_->_data43_);
		_data_->_data43_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp0_ = gee_array_list_new (GEARY_TYPE_EMAIL, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data_->_data43_->results = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->self->priv->_db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), GEARY_DB_TRANSACTION_TYPE_RO, ___lambda97__geary_db_transaction_method, _data_->_data43_, _data_->_data43_->cancellable, geary_imap_db_account_list_email_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block43_data_unref (_data_->_data43_);
		_data_->_data43_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp2_ = _data_->_data43_->results;
	_data_->_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, GEE_TYPE_LIST, GeeList));
	_data_->result = _data_->_tmp3_;
	block43_data_unref (_data_->_data43_);
	_data_->_data43_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_db_account_fetch_email_async_data_free (gpointer _data)
{
	GearyImapDbAccountFetchEmailAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbAccountFetchEmailAsyncData, _data_);
}

void
geary_imap_db_account_fetch_email_async (GearyImapDBAccount* self,
                                         GearyImapDBEmailIdentifier* email_id,
                                         GearyEmailField required_fields,
                                         GCancellable* cancellable,
                                         GAsyncReadyCallback _callback_,
                                         gpointer _user_data_)
{
	GearyImapDbAccountFetchEmailAsyncData* _data_;
	GearyImapDBAccount* _tmp0_;
	GearyImapDBEmailIdentifier* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail (GEARY_IMAP_DB_IS_EMAIL_IDENTIFIER (email_id));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbAccountFetchEmailAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_account_fetch_email_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (email_id);
	_g_object_unref0 (_data_->email_id);
	_data_->email_id = _tmp1_;
	_data_->required_fields = required_fields;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_account_fetch_email_async_co (_data_);
}

GearyEmail*
geary_imap_db_account_fetch_email_finish (GearyImapDBAccount* self,
                                          GAsyncResult* _res_,
                                          GError** error)
{
	GearyEmail* result;
	GearyImapDbAccountFetchEmailAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block44Data*
block44_data_ref (Block44Data* _data44_)
{
	g_atomic_int_inc (&_data44_->_ref_count_);
	return _data44_;
}

static void
block44_data_unref (void * _userdata_)
{
	Block44Data* _data44_;
	_data44_ = (Block44Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data44_->_ref_count_)) {
		GearyImapDBAccount* self;
		self = _data44_->self;
		_g_object_unref0 (_data44_->email);
		_g_object_unref0 (_data44_->email_id);
		_g_object_unref0 (_data44_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block44Data, _data44_);
	}
}

static GearyDbTransactionOutcome
__lambda98_ (Block44Data* _data44_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBAccount* self;
	GearyEmailField db_fields = 0;
	GearyImapDBMessageRow* row = NULL;
	gint64 _tmp0_;
	gint64 _tmp1_;
	GearyEmailField _tmp2_ = 0;
	GearyImapDBMessageRow* _tmp3_;
	GearyImapDBMessageRow* _tmp4_;
	GearyEmailField _tmp5_;
	GearyEmailField _tmp6_;
	GearyEmail* _tmp14_ = NULL;
	GearyImapDBMessageRow* _tmp15_;
	GearyEmail* _tmp16_;
	GearyEmail* _tmp17_;
	GearyImapDBDatabase* _tmp18_;
	GFile* _tmp19_;
	GearyEmail* _tmp20_;
	gint64 _tmp21_;
	gint64 _tmp22_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data44_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_imap_db_email_identifier_get_message_id (_data44_->email_id);
	_tmp1_ = _tmp0_;
	_tmp3_ = geary_imap_db_folder_do_fetch_message_row (cx, _tmp1_, _data44_->required_fields, &_tmp2_, _data44_->cancellable, &_inner_error0_);
	db_fields = _tmp2_;
	row = _tmp3_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp4_ = row;
	_tmp5_ = geary_imap_db_message_row_get_fields (_tmp4_);
	_tmp6_ = _tmp5_;
	if (!geary_email_field_fulfills (_tmp6_, _data44_->required_fields)) {
		gchar* _tmp7_;
		gchar* _tmp8_;
		GearyImapDBMessageRow* _tmp9_;
		GearyEmailField _tmp10_;
		GearyEmailField _tmp11_;
		GError* _tmp12_;
		GError* _tmp13_;
		_tmp7_ = geary_email_identifier_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data44_->email_id, GEARY_TYPE_EMAIL_IDENTIFIER, GearyEmailIdentifier));
		_tmp8_ = _tmp7_;
		_tmp9_ = row;
		_tmp10_ = geary_imap_db_message_row_get_fields (_tmp9_);
		_tmp11_ = _tmp10_;
		_tmp12_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_INCOMPLETE_MESSAGE, "Message %s only fulfills %Xh fields (required: %Xh)", _tmp8_, (guint) _tmp11_, (guint) _data44_->required_fields);
		_tmp13_ = _tmp12_;
		_g_free0 (_tmp8_);
		_inner_error0_ = _tmp13_;
		g_propagate_error (error, _inner_error0_);
		_geary_imap_db_message_row_unref0 (row);
		return 0;
	}
	_tmp15_ = row;
	_tmp16_ = geary_imap_db_message_row_to_email (_tmp15_, _data44_->email_id, &_inner_error0_);
	_tmp14_ = _tmp16_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_geary_imap_db_message_row_unref0 (row);
		return 0;
	}
	_tmp17_ = _tmp14_;
	_tmp14_ = NULL;
	_g_object_unref0 (_data44_->email);
	_data44_->email = _tmp17_;
	_tmp18_ = self->priv->_db;
	_tmp19_ = _tmp18_->attachments_path;
	_tmp20_ = _data44_->email;
	_tmp21_ = geary_imap_db_email_identifier_get_message_id (_data44_->email_id);
	_tmp22_ = _tmp21_;
	geary_imap_db_attachment_add_attachments (cx, _tmp19_, _tmp20_, _tmp22_, _data44_->cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp14_);
		_geary_imap_db_message_row_unref0 (row);
		return 0;
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	_g_object_unref0 (_tmp14_);
	_geary_imap_db_message_row_unref0 (row);
	return result;
}

static GearyDbTransactionOutcome
___lambda98__geary_db_transaction_method (GearyDbConnection* cx,
                                          GCancellable* cancellable,
                                          gpointer self,
                                          GError** error)
{
	GearyDbTransactionOutcome result;
	result = __lambda98_ (self, cx, error);
	return result;
}

static void
geary_imap_db_account_fetch_email_async_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_)
{
	GearyImapDbAccountFetchEmailAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_account_fetch_email_async_co (_data_);
}

static gboolean
geary_imap_db_account_fetch_email_async_co (GearyImapDbAccountFetchEmailAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data44_ = g_slice_new0 (Block44Data);
	_data_->_data44_->_ref_count_ = 1;
	_data_->_data44_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data44_->email_id);
	_data_->_data44_->email_id = _data_->email_id;
	_data_->_data44_->required_fields = _data_->required_fields;
	_g_object_unref0 (_data_->_data44_->cancellable);
	_data_->_data44_->cancellable = _data_->cancellable;
	_data_->_data44_->_async_data_ = _data_;
	geary_imap_db_account_check_open (_data_->self, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block44_data_unref (_data_->_data44_);
		_data_->_data44_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_data44_->email = NULL;
	_data_->_tmp0_ = _data_->self->priv->_db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), GEARY_DB_TRANSACTION_TYPE_RO, ___lambda98__geary_db_transaction_method, _data_->_data44_, _data_->_data44_->cancellable, geary_imap_db_account_fetch_email_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block44_data_unref (_data_->_data44_);
		_data_->_data44_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp1_ = _data_->_data44_->email;
	_vala_assert (_data_->_tmp1_ != NULL, "email != null");
	_data_->_tmp2_ = _data_->_data44_->email;
	_data_->_tmp3_ = _g_object_ref0 (_data_->_tmp2_);
	_data_->result = _data_->_tmp3_;
	block44_data_unref (_data_->_data44_);
	_data_->_data44_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_db_account_get_containing_folders_async_data_free (gpointer _data)
{
	GearyImapDbAccountGetContainingFoldersAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbAccountGetContainingFoldersAsyncData, _data_);
}

void
geary_imap_db_account_get_containing_folders_async (GearyImapDBAccount* self,
                                                    GeeCollection* ids,
                                                    GeeMultiMap* map,
                                                    GCancellable* cancellable,
                                                    GAsyncReadyCallback _callback_,
                                                    gpointer _user_data_)
{
	GearyImapDbAccountGetContainingFoldersAsyncData* _data_;
	GearyImapDBAccount* _tmp0_;
	GeeCollection* _tmp1_;
	GeeMultiMap* _tmp2_;
	GCancellable* _tmp3_;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION));
	g_return_if_fail ((map == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (map, GEE_TYPE_MULTI_MAP));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbAccountGetContainingFoldersAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_account_get_containing_folders_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (ids);
	_g_object_unref0 (_data_->ids);
	_data_->ids = _tmp1_;
	_tmp2_ = _g_object_ref0 (map);
	_g_object_unref0 (_data_->map);
	_data_->map = _tmp2_;
	_tmp3_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp3_;
	geary_imap_db_account_get_containing_folders_async_co (_data_);
}

void
geary_imap_db_account_get_containing_folders_finish (GearyImapDBAccount* self,
                                                     GAsyncResult* _res_,
                                                     GError** error)
{
	GearyImapDbAccountGetContainingFoldersAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

/**
     * Return a map of each passed-in email identifier to the set of folders
     * that contain it.  If an email id doesn't appear in the resulting map,
     * it isn't contained in any folders.  Return null if the resulting map
     * would be empty.  Only throw database errors et al., not errors due to
     * the email id not being found.
     */
static Block45Data*
block45_data_ref (Block45Data* _data45_)
{
	g_atomic_int_inc (&_data45_->_ref_count_);
	return _data45_;
}

static void
block45_data_unref (void * _userdata_)
{
	Block45Data* _data45_;
	_data45_ = (Block45Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data45_->_ref_count_)) {
		GearyImapDBAccount* self;
		self = _data45_->self;
		_g_object_unref0 (_data45_->ids);
		_g_object_unref0 (_data45_->map);
		_g_object_unref0 (self);
		g_slice_free (Block45Data, _data45_);
	}
}

static GearyDbTransactionOutcome
__lambda99_ (Block45Data* _data45_,
             GearyDbConnection* cx,
             GCancellable* cancellable,
             GError** error)
{
	GearyImapDBAccount* self;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data45_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), 0);
	{
		GeeIterator* _id_it = NULL;
		GeeIterator* _tmp0_;
		_tmp0_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_data45_->ids, GEE_TYPE_ITERABLE, GeeIterable));
		_id_it = _tmp0_;
		while (TRUE) {
			GeeIterator* _tmp1_;
			GearyEmailIdentifier* id = NULL;
			GeeIterator* _tmp2_;
			gpointer _tmp3_;
			GearyImapDBEmailIdentifier* imap_db_id = NULL;
			GearyEmailIdentifier* _tmp4_;
			GearyImapDBEmailIdentifier* _tmp5_;
			GearyImapDBEmailIdentifier* _tmp6_;
			GeeSet* folders = NULL;
			GearyImapDBEmailIdentifier* _tmp7_;
			gint64 _tmp8_;
			gint64 _tmp9_;
			GeeSet* _tmp10_;
			GeeSet* _tmp11_;
			_tmp1_ = _id_it;
			if (!gee_iterator_next (_tmp1_)) {
				break;
			}
			_tmp2_ = _id_it;
			_tmp3_ = gee_iterator_get (_tmp2_);
			id = (GearyEmailIdentifier*) _tmp3_;
			_tmp4_ = id;
			_tmp5_ = _g_object_ref0 (GEARY_IMAP_DB_IS_EMAIL_IDENTIFIER (_tmp4_) ? ((GearyImapDBEmailIdentifier*) _tmp4_) : NULL);
			imap_db_id = _tmp5_;
			_tmp6_ = imap_db_id;
			if (_tmp6_ == NULL) {
				_g_object_unref0 (imap_db_id);
				_g_object_unref0 (id);
				continue;
			}
			_tmp7_ = imap_db_id;
			_tmp8_ = geary_imap_db_email_identifier_get_message_id (_tmp7_);
			_tmp9_ = _tmp8_;
			_tmp10_ = geary_imap_db_account_do_find_email_folders (self, cx, _tmp9_, FALSE, cancellable, &_inner_error0_);
			folders = _tmp10_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (imap_db_id);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				return 0;
			}
			_tmp11_ = folders;
			if (_tmp11_ != NULL) {
				GearyEmailIdentifier* _tmp12_;
				GeeSet* _tmp13_;
				_tmp12_ = id;
				_tmp13_ = folders;
				geary_collection_multi_map_set_all (GEARY_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEARY_TYPE_FOLDER_PATH, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data45_->map, _tmp12_, G_TYPE_CHECK_INSTANCE_CAST (_tmp13_, GEE_TYPE_COLLECTION, GeeCollection));
			}
			_g_object_unref0 (folders);
			_g_object_unref0 (imap_db_id);
			_g_object_unref0 (id);
		}
		_g_object_unref0 (_id_it);
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	return result;
}

static GearyDbTransactionOutcome
___lambda99__geary_db_transaction_method (GearyDbConnection* cx,
                                          GCancellable* cancellable,
                                          gpointer self,
                                          GError** error)
{
	GearyDbTransactionOutcome result;
	result = __lambda99_ (self, cx, cancellable, error);
	return result;
}

static void
geary_imap_db_account_get_containing_folders_async_ready (GObject* source_object,
                                                          GAsyncResult* _res_,
                                                          gpointer _user_data_)
{
	GearyImapDbAccountGetContainingFoldersAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_account_get_containing_folders_async_co (_data_);
}

static gboolean
geary_imap_db_account_get_containing_folders_async_co (GearyImapDbAccountGetContainingFoldersAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data45_ = g_slice_new0 (Block45Data);
	_data_->_data45_->_ref_count_ = 1;
	_data_->_data45_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data45_->ids);
	_data_->_data45_->ids = _data_->ids;
	_g_object_unref0 (_data_->_data45_->map);
	_data_->_data45_->map = _data_->map;
	_data_->_data45_->_async_data_ = _data_;
	geary_imap_db_account_check_open (_data_->self, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block45_data_unref (_data_->_data45_);
		_data_->_data45_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp0_ = _data_->self->priv->_db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), GEARY_DB_TRANSACTION_TYPE_RO, ___lambda99__geary_db_transaction_method, _data_->_data45_, _data_->cancellable, geary_imap_db_account_get_containing_folders_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block45_data_unref (_data_->_data45_);
		_data_->_data45_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	block45_data_unref (_data_->_data45_);
	_data_->_data45_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_db_account_populate_search_table_data_free (gpointer _data)
{
	GearyImapDbAccountPopulateSearchTableData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbAccountPopulateSearchTableData, _data_);
}

void
geary_imap_db_account_populate_search_table (GearyImapDBAccount* self,
                                             GCancellable* cancellable,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_)
{
	GearyImapDbAccountPopulateSearchTableData* _data_;
	GearyImapDBAccount* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbAccountPopulateSearchTableData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_account_populate_search_table_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_db_account_populate_search_table_co (_data_);
}

void
geary_imap_db_account_populate_search_table_finish (GearyImapDBAccount* self,
                                                    GAsyncResult* _res_)
{
	GearyImapDbAccountPopulateSearchTableData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return;
	}
}

static Block46Data*
block46_data_ref (Block46Data* _data46_)
{
	g_atomic_int_inc (&_data46_->_ref_count_);
	return _data46_;
}

static void
block46_data_unref (void * _userdata_)
{
	Block46Data* _data46_;
	_data46_ = (Block46Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data46_->_ref_count_)) {
		GearyImapDBAccount* self;
		self = _data46_->self;
		_g_object_unref0 (_data46_->unindexed_message_ids);
		_g_object_unref0 (_data46_->message_ids);
		_g_object_unref0 (_data46_->search_ids);
		_g_object_unref0 (self);
		g_slice_free (Block46Data, _data46_);
	}
}

static GearyDbTransactionOutcome
___lambda100_ (Block46Data* _data46_,
               GearyDbConnection* cx,
               GCancellable* cancellable,
               GError** error)
{
	GearyImapDBAccount* self;
	GearyDbStatement* _tmp0_ = NULL;
	GearyDbStatement* _tmp1_;
	GearyDbResult* _result_ = NULL;
	GearyDbResult* _tmp2_;
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp10_;
	GearyDbStatement* _tmp11_;
	GearyDbStatement* _tmp12_;
	GearyDbStatement* _tmp13_;
	GearyDbStatement* _tmp14_;
	GearyDbStatement* _tmp15_;
	GearyDbStatement* _tmp16_;
	GearyDbResult* _tmp17_ = NULL;
	GearyDbStatement* _tmp18_;
	GearyDbResult* _tmp19_;
	GearyDbResult* _tmp20_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data46_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), 0);
	_tmp1_ = geary_db_connection_prepare (cx, "SELECT rowid FROM MessageSearchTable", &_inner_error0_);
	_tmp0_ = _tmp1_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp2_ = geary_db_statement_exec (_tmp0_, cancellable, &_inner_error0_);
	_result_ = _tmp2_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp0_);
		return 0;
	}
	while (TRUE) {
		GearyDbResult* _tmp3_;
		gboolean _tmp4_;
		gboolean _tmp5_;
		gint64 _tmp6_ = 0LL;
		GearyDbResult* _tmp7_;
		GeeHashSet* _tmp8_;
		GearyDbResult* _tmp9_;
		_tmp3_ = _result_;
		_tmp4_ = geary_db_result_get_finished (_tmp3_);
		_tmp5_ = _tmp4_;
		if (!(!_tmp5_)) {
			break;
		}
		_tmp7_ = _result_;
		_tmp6_ = geary_db_result_rowid_at (_tmp7_, 0, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (_result_);
			_g_object_unref0 (_tmp0_);
			return 0;
		}
		_tmp8_ = _data46_->search_ids;
		gee_abstract_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection), &_tmp6_);
		_tmp9_ = _result_;
		geary_db_result_next (_tmp9_, cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (_result_);
			_g_object_unref0 (_tmp0_);
			return 0;
		}
	}
	_tmp10_ = geary_db_connection_prepare (cx, "SELECT id FROM MessageTable WHERE (fields & ?) = ?", &_inner_error0_);
	stmt = _tmp10_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_result_);
		_g_object_unref0 (_tmp0_);
		return 0;
	}
	_tmp11_ = stmt;
	_tmp12_ = geary_db_statement_bind_uint (_tmp11_, 0, (guint) GEARY_IMAP_DB_FOLDER_REQUIRED_FTS_FIELDS, &_inner_error0_);
	_tmp13_ = _tmp12_;
	_g_object_unref0 (_tmp13_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_object_unref0 (_result_);
		_g_object_unref0 (_tmp0_);
		return 0;
	}
	_tmp14_ = stmt;
	_tmp15_ = geary_db_statement_bind_uint (_tmp14_, 1, (guint) GEARY_IMAP_DB_FOLDER_REQUIRED_FTS_FIELDS, &_inner_error0_);
	_tmp16_ = _tmp15_;
	_g_object_unref0 (_tmp16_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_object_unref0 (_result_);
		_g_object_unref0 (_tmp0_);
		return 0;
	}
	_tmp18_ = stmt;
	_tmp19_ = geary_db_statement_exec (_tmp18_, cancellable, &_inner_error0_);
	_tmp17_ = _tmp19_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_object_unref0 (_result_);
		_g_object_unref0 (_tmp0_);
		return 0;
	}
	_tmp20_ = _tmp17_;
	_tmp17_ = NULL;
	_g_object_unref0 (_result_);
	_result_ = _tmp20_;
	while (TRUE) {
		GearyDbResult* _tmp21_;
		gboolean _tmp22_;
		gboolean _tmp23_;
		gint64 _tmp24_ = 0LL;
		GearyDbResult* _tmp25_;
		GeeHashSet* _tmp26_;
		GearyDbResult* _tmp27_;
		_tmp21_ = _result_;
		_tmp22_ = geary_db_result_get_finished (_tmp21_);
		_tmp23_ = _tmp22_;
		if (!(!_tmp23_)) {
			break;
		}
		_tmp25_ = _result_;
		_tmp24_ = geary_db_result_rowid_at (_tmp25_, 0, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (_tmp17_);
			_g_object_unref0 (stmt);
			_g_object_unref0 (_result_);
			_g_object_unref0 (_tmp0_);
			return 0;
		}
		_tmp26_ = _data46_->message_ids;
		gee_abstract_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp26_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection), &_tmp24_);
		_tmp27_ = _result_;
		geary_db_result_next (_tmp27_, cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (_tmp17_);
			_g_object_unref0 (stmt);
			_g_object_unref0 (_result_);
			_g_object_unref0 (_tmp0_);
			return 0;
		}
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	_g_object_unref0 (_tmp17_);
	_g_object_unref0 (stmt);
	_g_object_unref0 (_result_);
	_g_object_unref0 (_tmp0_);
	return result;
}

static GearyDbTransactionOutcome
____lambda100__geary_db_transaction_method (GearyDbConnection* cx,
                                            GCancellable* cancellable,
                                            gpointer self,
                                            GError** error)
{
	GearyDbTransactionOutcome result;
	result = ___lambda100_ (self, cx, cancellable, error);
	return result;
}

static void
geary_imap_db_account_populate_search_table_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_)
{
	GearyImapDbAccountPopulateSearchTableData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_account_populate_search_table_co (_data_);
}

static void
___lambda101_ (Block46Data* _data46_,
               GError** error)
{
	GearyImapDBAccount* self;
	self = _data46_->self;
	{
		GeeIterator* _message_id_it = NULL;
		GeeHashSet* _tmp0_;
		GeeIterator* _tmp1_;
		_tmp0_ = _data46_->message_ids;
		_tmp1_ = gee_abstract_collection_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection));
		_message_id_it = _tmp1_;
		while (TRUE) {
			GeeIterator* _tmp2_;
			gint64 message_id = 0LL;
			GeeIterator* _tmp3_;
			gpointer _tmp4_;
			gint64* _tmp5_;
			gint64 _tmp6_;
			GeeHashSet* _tmp7_;
			_tmp2_ = _message_id_it;
			if (!gee_iterator_next (_tmp2_)) {
				break;
			}
			_tmp3_ = _message_id_it;
			_tmp4_ = gee_iterator_get (_tmp3_);
			_tmp5_ = (gint64*) _tmp4_;
			_tmp6_ = *_tmp5_;
			_g_free0 (_tmp5_);
			message_id = _tmp6_;
			_tmp7_ = _data46_->search_ids;
			if (!gee_abstract_collection_contains (G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection), &message_id)) {
				GeeHashSet* _tmp8_;
				_tmp8_ = _data46_->unindexed_message_ids;
				gee_abstract_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection), &message_id);
			}
		}
		_g_object_unref0 (_message_id_it);
	}
}

static void
____lambda101__geary_nonblocking_concurrent_concurrent_callback (GCancellable* cancellable,
                                                                 gpointer self,
                                                                 GError** error)
{
	___lambda101_ (self, error);
}

static gboolean
geary_imap_db_account_populate_search_table_co (GearyImapDbAccountPopulateSearchTableData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		case 4:
		goto _state_4;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data46_ = g_slice_new0 (Block46Data);
	_data_->_data46_->_ref_count_ = 1;
	_data_->_data46_->self = g_object_ref (_data_->self);
	_data_->_data46_->_async_data_ = _data_;
	_data_->_tmp0_ = _data_->self->priv->_account_information;
	_data_->_tmp1_ = geary_account_information_get_id (_data_->_tmp0_);
	_data_->_tmp2_ = _data_->_tmp1_;
	g_debug ("imap-db-account.vala:773: %s: Populating search table", _data_->_tmp2_);
	_data_->_tmp3_ = gee_hash_set_new (G_TYPE_INT64, (GBoxedCopyFunc) _int64_dup, (GDestroyNotify) g_free, _geary_collection_int64_hash_func_gee_hash_data_func, NULL, NULL, _geary_collection_int64_equal_func_gee_equal_data_func, NULL, NULL);
	_data_->_data46_->search_ids = _data_->_tmp3_;
	_data_->_tmp4_ = gee_hash_set_new (G_TYPE_INT64, (GBoxedCopyFunc) _int64_dup, (GDestroyNotify) g_free, _geary_collection_int64_hash_func_gee_hash_data_func, NULL, NULL, _geary_collection_int64_equal_func_gee_equal_data_func, NULL, NULL);
	_data_->_data46_->message_ids = _data_->_tmp4_;
	_data_->_tmp5_ = gee_hash_set_new (G_TYPE_INT64, (GBoxedCopyFunc) _int64_dup, (GDestroyNotify) g_free, _geary_collection_int64_hash_func_gee_hash_data_func, NULL, NULL, _geary_collection_int64_equal_func_gee_equal_data_func, NULL, NULL);
	_data_->_data46_->unindexed_message_ids = _data_->_tmp5_;
	{
		_data_->_tmp6_ = _data_->self->priv->_db;
		_data_->_state_ = 1;
		geary_db_database_exec_transaction_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp6_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), GEARY_DB_TRANSACTION_TYPE_RO, ____lambda100__geary_db_transaction_method, _data_->_data46_, _data_->cancellable, geary_imap_db_account_populate_search_table_ready, _data_);
		return FALSE;
		_state_1:
		geary_db_database_exec_transaction_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp6_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp7_ = geary_nonblocking_concurrent_get_global ();
		_data_->_tmp8_ = _data_->_tmp7_;
		_data_->_state_ = 2;
		geary_nonblocking_concurrent_schedule_async (_data_->_tmp8_, ____lambda101__geary_nonblocking_concurrent_concurrent_callback, _data_->_data46_, _data_->cancellable, geary_imap_db_account_populate_search_table_ready, _data_);
		return FALSE;
		_state_2:
		geary_nonblocking_concurrent_schedule_finish (_data_->_tmp8_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp9_ = _data_->self->priv->_account_information;
		_data_->_tmp10_ = geary_account_information_get_id (_data_->_tmp9_);
		_data_->_tmp11_ = _data_->_tmp10_;
		_data_->_tmp12_ = _data_->_data46_->unindexed_message_ids;
		_data_->_tmp13_ = gee_abstract_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp12_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection));
		_data_->_tmp14_ = _data_->_tmp13_;
		g_debug ("imap-db-account.vala:835: %s: Found %d missing messages to populate", _data_->_tmp11_, _data_->_tmp14_);
		while (TRUE) {
			_data_->_tmp15_ = _data_->_data46_->unindexed_message_ids;
			_data_->_tmp16_ = gee_collection_get_is_empty (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp15_, GEE_TYPE_COLLECTION, GeeCollection));
			_data_->_tmp17_ = _data_->_tmp16_;
			if (!(!_data_->_tmp17_)) {
				break;
			}
			_data_->_tmp18_ = _data_->_data46_->unindexed_message_ids;
			_data_->_state_ = 3;
			geary_imap_db_account_populate_search_table_batch_async (_data_->self, 50, _data_->_tmp18_, _data_->cancellable, geary_imap_db_account_populate_search_table_ready, _data_);
			return FALSE;
			_state_3:
			geary_imap_db_account_populate_search_table_batch_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_data_->_state_ = 4;
			geary_scheduler_sleep_ms_async ((guint) 50, geary_imap_db_account_populate_search_table_ready, _data_);
			return FALSE;
			_state_4:
			geary_scheduler_sleep_ms_finish (_data_->_res_);
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp19_ = _data_->self->priv->_account_information;
		_data_->_tmp20_ = geary_account_information_get_id (_data_->_tmp19_);
		_data_->_tmp21_ = _data_->_tmp20_;
		_data_->_tmp22_ = _data_->e;
		_data_->_tmp23_ = _data_->_tmp22_->message;
		g_debug ("imap-db-account.vala:854: %s: Error populating search table: %s", _data_->_tmp21_, _data_->_tmp23_);
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		block46_data_unref (_data_->_data46_);
		_data_->_data46_ = NULL;
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp24_ = _data_->self->priv->_account_information;
	_data_->_tmp25_ = geary_account_information_get_id (_data_->_tmp24_);
	_data_->_tmp26_ = _data_->_tmp25_;
	g_debug ("imap-db-account.vala:857: %s: Done populating search table", _data_->_tmp26_);
	block46_data_unref (_data_->_data46_);
	_data_->_data46_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_db_account_populate_search_table_batch_async_data_free (gpointer _data)
{
	GearyImapDbAccountPopulateSearchTableBatchAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->unindexed_message_ids);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbAccountPopulateSearchTableBatchAsyncData, _data_);
}

static void
geary_imap_db_account_populate_search_table_batch_async (GearyImapDBAccount* self,
                                                         gint limit,
                                                         GeeHashSet* unindexed_message_ids,
                                                         GCancellable* cancellable,
                                                         GAsyncReadyCallback _callback_,
                                                         gpointer _user_data_)
{
	GearyImapDbAccountPopulateSearchTableBatchAsyncData* _data_;
	GearyImapDBAccount* _tmp0_;
	GeeHashSet* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (unindexed_message_ids, GEE_TYPE_HASH_SET));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbAccountPopulateSearchTableBatchAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_account_populate_search_table_batch_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->limit = limit;
	_tmp1_ = _g_object_ref0 (unindexed_message_ids);
	_g_object_unref0 (_data_->unindexed_message_ids);
	_data_->unindexed_message_ids = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_account_populate_search_table_batch_async_co (_data_);
}

static void
geary_imap_db_account_populate_search_table_batch_finish (GearyImapDBAccount* self,
                                                          GAsyncResult* _res_,
                                                          GError** error)
{
	GearyImapDbAccountPopulateSearchTableBatchAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static Block47Data*
block47_data_ref (Block47Data* _data47_)
{
	g_atomic_int_inc (&_data47_->_ref_count_);
	return _data47_;
}

static void
block47_data_unref (void * _userdata_)
{
	Block47Data* _data47_;
	_data47_ = (Block47Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data47_->_ref_count_)) {
		GearyImapDBAccount* self;
		self = _data47_->self;
		_g_object_unref0 (_data47_->iter);
		_g_object_unref0 (self);
		g_slice_free (Block47Data, _data47_);
	}
}

static GearyDbTransactionOutcome
__lambda102_ (Block47Data* _data47_,
              GearyDbConnection* cx,
              GCancellable* cancellable,
              GError** error)
{
	GearyImapDBAccount* self;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data47_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), 0);
	while (TRUE) {
		gboolean _tmp0_ = FALSE;
		GeeIterator* _tmp1_;
		GeeIterator* _tmp2_;
		gint64 message_id = 0LL;
		GeeIterator* _tmp3_;
		gpointer _tmp4_;
		gint64* _tmp5_;
		gint64 _tmp6_;
		GeeIterator* _tmp22_;
		guint _tmp23_;
		_tmp1_ = _data47_->iter;
		if (gee_iterator_has_next (_tmp1_)) {
			_tmp0_ = _data47_->count < ((guint) _data47_->limit);
		} else {
			_tmp0_ = FALSE;
		}
		if (!_tmp0_) {
			break;
		}
		_tmp2_ = _data47_->iter;
		gee_iterator_next (_tmp2_);
		_tmp3_ = _data47_->iter;
		_tmp4_ = gee_iterator_get (_tmp3_);
		_tmp5_ = (gint64*) _tmp4_;
		_tmp6_ = *_tmp5_;
		_g_free0 (_tmp5_);
		message_id = _tmp6_;
		{
			GearyEmailField search_fields = 0;
			GearyEmailField db_fields = 0;
			GearyImapDBMessageRow* row = NULL;
			GearyEmailField _tmp7_ = 0;
			GearyImapDBMessageRow* _tmp8_;
			GearyEmail* email = NULL;
			GearyImapDBMessageRow* _tmp9_;
			GearyImapDBEmailIdentifier* _tmp10_;
			GearyImapDBEmailIdentifier* _tmp11_;
			GearyEmail* _tmp12_;
			GearyEmail* _tmp13_;
			GearyImapDBDatabase* _tmp14_;
			GFile* _tmp15_;
			GearyEmail* _tmp16_;
			GearyEmail* _tmp17_;
			search_fields = (((GEARY_EMAIL_REQUIRED_FOR_MESSAGE | GEARY_EMAIL_FIELD_ORIGINATORS) | GEARY_EMAIL_FIELD_RECEIVERS) | GEARY_EMAIL_FIELD_SUBJECT) | GEARY_EMAIL_FIELD_FLAGS;
			_tmp8_ = geary_imap_db_folder_do_fetch_message_row (cx, message_id, search_fields, &_tmp7_, cancellable, &_inner_error0_);
			db_fields = _tmp7_;
			row = _tmp8_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_tmp9_ = row;
			_tmp10_ = geary_imap_db_email_identifier_new (message_id, NULL);
			_tmp11_ = _tmp10_;
			_tmp12_ = geary_imap_db_message_row_to_email (_tmp9_, _tmp11_, &_inner_error0_);
			_tmp13_ = _tmp12_;
			_g_object_unref0 (_tmp11_);
			email = _tmp13_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_geary_imap_db_message_row_unref0 (row);
				goto __catch0_g_error;
			}
			_tmp14_ = self->priv->_db;
			_tmp15_ = _tmp14_->attachments_path;
			_tmp16_ = email;
			geary_imap_db_attachment_add_attachments (cx, _tmp15_, _tmp16_, message_id, cancellable, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_object_unref0 (email);
				_geary_imap_db_message_row_unref0 (row);
				goto __catch0_g_error;
			}
			_tmp17_ = email;
			geary_imap_db_folder_do_add_email_to_search_table (cx, message_id, _tmp17_, cancellable, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_object_unref0 (email);
				_geary_imap_db_message_row_unref0 (row);
				goto __catch0_g_error;
			}
			_g_object_unref0 (email);
			_geary_imap_db_message_row_unref0 (row);
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			gchar* _tmp18_;
			gchar* _tmp19_;
			GError* _tmp20_;
			const gchar* _tmp21_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp18_ = g_strdup_printf ("%" G_GINT64_FORMAT, message_id);
			_tmp19_ = _tmp18_;
			_tmp20_ = e;
			_tmp21_ = _tmp20_->message;
			g_warning ("imap-db-account.vala:901: Error populating message %s for indexing: %s", _tmp19_, _tmp21_);
			_g_free0 (_tmp19_);
			_g_error_free0 (e);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			return 0;
		}
		_tmp22_ = _data47_->iter;
		gee_iterator_remove (_tmp22_);
		_data47_->count = _data47_->count + 1;
		_tmp23_ = _data47_->count;
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_COMMIT;
	return result;
}

static GearyDbTransactionOutcome
___lambda102__geary_db_transaction_method (GearyDbConnection* cx,
                                           GCancellable* cancellable,
                                           gpointer self,
                                           GError** error)
{
	GearyDbTransactionOutcome result;
	result = __lambda102_ (self, cx, cancellable, error);
	return result;
}

static void
geary_imap_db_account_populate_search_table_batch_async_ready (GObject* source_object,
                                                               GAsyncResult* _res_,
                                                               gpointer _user_data_)
{
	GearyImapDbAccountPopulateSearchTableBatchAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_account_populate_search_table_batch_async_co (_data_);
}

static gboolean
geary_imap_db_account_populate_search_table_batch_async_co (GearyImapDbAccountPopulateSearchTableBatchAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data47_ = g_slice_new0 (Block47Data);
	_data_->_data47_->_ref_count_ = 1;
	_data_->_data47_->self = g_object_ref (_data_->self);
	_data_->_data47_->limit = _data_->limit;
	_data_->_data47_->_async_data_ = _data_;
	geary_imap_db_account_check_open (_data_->self, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block47_data_unref (_data_->_data47_);
		_data_->_data47_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_data47_->count = (guint) 0;
	_data_->_tmp0_ = gee_abstract_collection_iterator (G_TYPE_CHECK_INSTANCE_CAST (_data_->unindexed_message_ids, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection));
	_data_->_data47_->iter = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->self->priv->_db;
	_data_->_tmp2_ = _data_->cancellable;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), GEARY_DB_TRANSACTION_TYPE_RW, ___lambda102__geary_db_transaction_method, _data_->_data47_, _data_->_tmp2_, geary_imap_db_account_populate_search_table_batch_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block47_data_unref (_data_->_data47_);
		_data_->_data47_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (_data_->_data47_->count > ((guint) 0)) {
		_data_->_tmp3_ = _data_->self->priv->_account_information;
		_data_->_tmp4_ = geary_account_information_get_id (_data_->_tmp3_);
		_data_->_tmp5_ = _data_->_tmp4_;
		g_debug ("imap-db-account.vala:916: %s: Populated %u missing indexed messages...", _data_->_tmp5_, _data_->_data47_->count);
	}
	block47_data_unref (_data_->_data47_);
	_data_->_data47_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_db_account_do_delete_folder (GearyImapDBAccount* self,
                                        GearyDbConnection* cx,
                                        gint64 folder_id,
                                        GCancellable* cancellable,
                                        GError** error)
{
	GearyDbStatement* msg_loc_stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp1_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbResult* _tmp5_;
	GearyDbResult* _tmp6_;
	GearyDbStatement* folder_stmt = NULL;
	GearyDbStatement* _tmp7_;
	GearyDbStatement* _tmp8_;
	GearyDbStatement* _tmp9_;
	GearyDbStatement* _tmp10_;
	GearyDbStatement* _tmp11_;
	GearyDbResult* _tmp12_;
	GearyDbResult* _tmp13_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail (GEARY_DB_IS_CONNECTION (cx));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_tmp0_ = geary_db_connection_prepare (cx, "\n" \
"            DELETE FROM MessageLocationTable\n" \
"            WHERE folder_id = ?\n" \
"        ", &_inner_error0_);
	msg_loc_stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	_tmp1_ = msg_loc_stmt;
	_tmp2_ = geary_db_statement_bind_rowid (_tmp1_, 0, folder_id, &_inner_error0_);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp3_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (msg_loc_stmt);
		return;
	}
	_tmp4_ = msg_loc_stmt;
	_tmp5_ = geary_db_statement_exec (_tmp4_, cancellable, &_inner_error0_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp6_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (msg_loc_stmt);
		return;
	}
	_tmp7_ = geary_db_connection_prepare (cx, "\n" \
"            DELETE FROM FolderTable\n" \
"            WHERE id = ?\n" \
"        ", &_inner_error0_);
	folder_stmt = _tmp7_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (msg_loc_stmt);
		return;
	}
	_tmp8_ = folder_stmt;
	_tmp9_ = geary_db_statement_bind_rowid (_tmp8_, 0, folder_id, &_inner_error0_);
	_tmp10_ = _tmp9_;
	_g_object_unref0 (_tmp10_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (folder_stmt);
		_g_object_unref0 (msg_loc_stmt);
		return;
	}
	_tmp11_ = folder_stmt;
	_tmp12_ = geary_db_statement_exec (_tmp11_, cancellable, &_inner_error0_);
	_tmp13_ = _tmp12_;
	_g_object_unref0 (_tmp13_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (folder_stmt);
		_g_object_unref0 (msg_loc_stmt);
		return;
	}
	_g_object_unref0 (folder_stmt);
	_g_object_unref0 (msg_loc_stmt);
}

gboolean
geary_imap_db_account_do_fetch_folder_id (GearyImapDBAccount* self,
                                          GearyDbConnection* cx,
                                          GearyFolderPath* path,
                                          gboolean create,
                                          gint64* folder_id,
                                          GCancellable* cancellable,
                                          GError** error)
{
	gint64 _vala_folder_id = 0LL;
	gboolean _tmp0_;
	gboolean _tmp1_;
	gchar** parts = NULL;
	gint _tmp4_ = 0;
	gchar** _tmp5_;
	gint parts_length1;
	gint _parts_size_;
	gint64 parent_id = 0LL;
	gchar** _tmp6_;
	gint _tmp6__length1;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self), FALSE);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), FALSE);
	g_return_val_if_fail (GEARY_IS_FOLDER_PATH (path), FALSE);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), FALSE);
	_tmp0_ = geary_folder_path_get_is_root (path);
	_tmp1_ = _tmp0_;
	if (_tmp1_) {
		GError* _tmp2_;
		gboolean _tmp3_ = FALSE;
		_tmp2_ = g_error_new_literal (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_BAD_PARAMETERS, "Cannot fetch folder for root path");
		_inner_error0_ = _tmp2_;
		g_propagate_error (error, _inner_error0_);
		return _tmp3_;
	}
	_tmp5_ = geary_folder_path_as_array (path, &_tmp4_);
	parts = _tmp5_;
	parts_length1 = _tmp4_;
	_parts_size_ = parts_length1;
	parent_id = GEARY_DB_INVALID_ROWID;
	_vala_folder_id = GEARY_DB_INVALID_ROWID;
	_tmp6_ = parts;
	_tmp6__length1 = parts_length1;
	{
		gchar** basename_collection = NULL;
		gint basename_collection_length1 = 0;
		gint _basename_collection_size_ = 0;
		gint basename_it = 0;
		basename_collection = _tmp6_;
		basename_collection_length1 = _tmp6__length1;
		for (basename_it = 0; basename_it < basename_collection_length1; basename_it = basename_it + 1) {
			gchar* _tmp7_;
			gchar* basename = NULL;
			_tmp7_ = g_strdup (basename_collection[basename_it]);
			basename = _tmp7_;
			{
				GearyDbStatement* stmt = NULL;
				gint64 id = 0LL;
				GearyDbResult* _result_ = NULL;
				GearyDbStatement* _tmp30_;
				GearyDbResult* _tmp31_;
				GearyDbResult* _tmp33_;
				gboolean _tmp34_;
				gboolean _tmp35_;
				if (parent_id != GEARY_DB_INVALID_ROWID) {
					GearyDbStatement* _tmp8_ = NULL;
					GearyDbStatement* _tmp9_;
					GearyDbStatement* _tmp11_;
					GearyDbStatement* _tmp12_;
					GearyDbStatement* _tmp13_;
					GearyDbStatement* _tmp14_;
					GearyDbStatement* _tmp16_;
					const gchar* _tmp17_;
					GearyDbStatement* _tmp18_;
					GearyDbStatement* _tmp19_;
					_tmp9_ = geary_db_connection_prepare (cx, "SELECT id FROM FolderTable WHERE parent_id=? AND name=?", &_inner_error0_);
					_tmp8_ = _tmp9_;
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						gboolean _tmp10_ = FALSE;
						g_propagate_error (error, _inner_error0_);
						_g_object_unref0 (stmt);
						_g_free0 (basename);
						parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
						return _tmp10_;
					}
					_tmp11_ = _tmp8_;
					_tmp8_ = NULL;
					_g_object_unref0 (stmt);
					stmt = _tmp11_;
					_tmp12_ = stmt;
					_tmp13_ = geary_db_statement_bind_rowid (_tmp12_, 0, parent_id, &_inner_error0_);
					_tmp14_ = _tmp13_;
					_g_object_unref0 (_tmp14_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						gboolean _tmp15_ = FALSE;
						g_propagate_error (error, _inner_error0_);
						_g_object_unref0 (_tmp8_);
						_g_object_unref0 (stmt);
						_g_free0 (basename);
						parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
						return _tmp15_;
					}
					_tmp16_ = stmt;
					_tmp17_ = basename;
					_tmp18_ = geary_db_statement_bind_string (_tmp16_, 1, _tmp17_, &_inner_error0_);
					_tmp19_ = _tmp18_;
					_g_object_unref0 (_tmp19_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						gboolean _tmp20_ = FALSE;
						g_propagate_error (error, _inner_error0_);
						_g_object_unref0 (_tmp8_);
						_g_object_unref0 (stmt);
						_g_free0 (basename);
						parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
						return _tmp20_;
					}
					_g_object_unref0 (_tmp8_);
				} else {
					GearyDbStatement* _tmp21_ = NULL;
					GearyDbStatement* _tmp22_;
					GearyDbStatement* _tmp24_;
					GearyDbStatement* _tmp25_;
					const gchar* _tmp26_;
					GearyDbStatement* _tmp27_;
					GearyDbStatement* _tmp28_;
					_tmp22_ = geary_db_connection_prepare (cx, "SELECT id FROM FolderTable WHERE parent_id IS NULL AND name=?", &_inner_error0_);
					_tmp21_ = _tmp22_;
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						gboolean _tmp23_ = FALSE;
						g_propagate_error (error, _inner_error0_);
						_g_object_unref0 (stmt);
						_g_free0 (basename);
						parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
						return _tmp23_;
					}
					_tmp24_ = _tmp21_;
					_tmp21_ = NULL;
					_g_object_unref0 (stmt);
					stmt = _tmp24_;
					_tmp25_ = stmt;
					_tmp26_ = basename;
					_tmp27_ = geary_db_statement_bind_string (_tmp25_, 0, _tmp26_, &_inner_error0_);
					_tmp28_ = _tmp27_;
					_g_object_unref0 (_tmp28_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						gboolean _tmp29_ = FALSE;
						g_propagate_error (error, _inner_error0_);
						_g_object_unref0 (_tmp21_);
						_g_object_unref0 (stmt);
						_g_free0 (basename);
						parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
						return _tmp29_;
					}
					_g_object_unref0 (_tmp21_);
				}
				id = GEARY_DB_INVALID_ROWID;
				_tmp30_ = stmt;
				_tmp31_ = geary_db_statement_exec (_tmp30_, cancellable, &_inner_error0_);
				_result_ = _tmp31_;
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					gboolean _tmp32_ = FALSE;
					g_propagate_error (error, _inner_error0_);
					_g_object_unref0 (stmt);
					_g_free0 (basename);
					parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
					return _tmp32_;
				}
				_tmp33_ = _result_;
				_tmp34_ = geary_db_result_get_finished (_tmp33_);
				_tmp35_ = _tmp34_;
				if (!_tmp35_) {
					gint64 _tmp36_ = 0LL;
					GearyDbResult* _tmp37_;
					_tmp37_ = _result_;
					_tmp36_ = geary_db_result_rowid_at (_tmp37_, 0, &_inner_error0_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						gboolean _tmp38_ = FALSE;
						g_propagate_error (error, _inner_error0_);
						_g_object_unref0 (_result_);
						_g_object_unref0 (stmt);
						_g_free0 (basename);
						parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
						return _tmp38_;
					}
					id = _tmp36_;
				} else {
					if (!create) {
						result = FALSE;
						_g_object_unref0 (_result_);
						_g_object_unref0 (stmt);
						_g_free0 (basename);
						parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
						if (folder_id) {
							*folder_id = _vala_folder_id;
						}
						return result;
					} else {
						GearyDbStatement* create_stmt = NULL;
						GearyDbStatement* _tmp39_;
						GearyDbStatement* _tmp41_;
						const gchar* _tmp42_;
						GearyDbStatement* _tmp43_;
						GearyDbStatement* _tmp44_;
						GearyDbStatement* _tmp46_;
						GearyDbStatement* _tmp47_;
						GearyDbStatement* _tmp48_;
						gint64 _tmp50_ = 0LL;
						GearyDbStatement* _tmp51_;
						_tmp39_ = geary_db_connection_prepare (cx, "INSERT INTO FolderTable (name, parent_id) VALUES (?, ?)", &_inner_error0_);
						create_stmt = _tmp39_;
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							gboolean _tmp40_ = FALSE;
							g_propagate_error (error, _inner_error0_);
							_g_object_unref0 (_result_);
							_g_object_unref0 (stmt);
							_g_free0 (basename);
							parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
							return _tmp40_;
						}
						_tmp41_ = create_stmt;
						_tmp42_ = basename;
						_tmp43_ = geary_db_statement_bind_string (_tmp41_, 0, _tmp42_, &_inner_error0_);
						_tmp44_ = _tmp43_;
						_g_object_unref0 (_tmp44_);
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							gboolean _tmp45_ = FALSE;
							g_propagate_error (error, _inner_error0_);
							_g_object_unref0 (create_stmt);
							_g_object_unref0 (_result_);
							_g_object_unref0 (stmt);
							_g_free0 (basename);
							parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
							return _tmp45_;
						}
						_tmp46_ = create_stmt;
						_tmp47_ = geary_db_statement_bind_rowid (_tmp46_, 1, parent_id, &_inner_error0_);
						_tmp48_ = _tmp47_;
						_g_object_unref0 (_tmp48_);
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							gboolean _tmp49_ = FALSE;
							g_propagate_error (error, _inner_error0_);
							_g_object_unref0 (create_stmt);
							_g_object_unref0 (_result_);
							_g_object_unref0 (stmt);
							_g_free0 (basename);
							parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
							return _tmp49_;
						}
						_tmp51_ = create_stmt;
						_tmp50_ = geary_db_statement_exec_insert (_tmp51_, cancellable, &_inner_error0_);
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							gboolean _tmp52_ = FALSE;
							g_propagate_error (error, _inner_error0_);
							_g_object_unref0 (create_stmt);
							_g_object_unref0 (_result_);
							_g_object_unref0 (stmt);
							_g_free0 (basename);
							parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
							return _tmp52_;
						}
						id = _tmp50_;
						_g_object_unref0 (create_stmt);
					}
				}
				if (id == parent_id) {
					gchar* _tmp53_;
					gchar* _tmp54_;
					gchar* _tmp55_;
					gchar* _tmp56_;
					_tmp53_ = g_strdup_printf ("%" G_GINT64_FORMAT, parent_id);
					_tmp54_ = _tmp53_;
					_tmp55_ = g_strdup_printf ("%" G_GINT64_FORMAT, id);
					_tmp56_ = _tmp55_;
					g_warning ("imap-db-account.vala:995: Loop found in database: parent of %s is %s i" \
"n FolderTable", _tmp54_, _tmp56_);
					_g_free0 (_tmp56_);
					_g_free0 (_tmp54_);
					result = FALSE;
					_g_object_unref0 (_result_);
					_g_object_unref0 (stmt);
					_g_free0 (basename);
					parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
					if (folder_id) {
						*folder_id = _vala_folder_id;
					}
					return result;
				}
				parent_id = id;
				_g_object_unref0 (_result_);
				_g_object_unref0 (stmt);
				_g_free0 (basename);
			}
		}
	}
	_vala_folder_id = parent_id;
	result = TRUE;
	parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
	if (folder_id) {
		*folder_id = _vala_folder_id;
	}
	return result;
}

gboolean
geary_imap_db_account_do_fetch_parent_id (GearyImapDBAccount* self,
                                          GearyDbConnection* cx,
                                          GearyFolderPath* path,
                                          gboolean create,
                                          gint64* parent_id,
                                          GCancellable* cancellable,
                                          GError** error)
{
	gint64 _vala_parent_id = 0LL;
	gboolean ret = FALSE;
	gboolean _tmp0_;
	gboolean _tmp1_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self), FALSE);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), FALSE);
	g_return_val_if_fail (GEARY_IS_FOLDER_PATH (path), FALSE);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), FALSE);
	ret = TRUE;
	_tmp0_ = geary_folder_path_get_is_top_level (path);
	_tmp1_ = _tmp0_;
	if (_tmp1_) {
		_vala_parent_id = GEARY_DB_INVALID_ROWID;
	} else {
		gboolean _tmp2_ = FALSE;
		GearyFolderPath* _tmp3_;
		GearyFolderPath* _tmp4_;
		gint64 _tmp5_ = 0LL;
		gboolean _tmp6_;
		_tmp3_ = geary_folder_path_get_parent (path);
		_tmp4_ = _tmp3_;
		_tmp6_ = geary_imap_db_account_do_fetch_folder_id (self, cx, _tmp4_, create, &_tmp5_, cancellable, &_inner_error0_);
		_vala_parent_id = _tmp5_;
		_tmp2_ = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp7_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			return _tmp7_;
		}
		ret = _tmp2_;
	}
	result = ret;
	if (parent_id) {
		*parent_id = _vala_parent_id;
	}
	return result;
}

static gboolean
geary_imap_db_account_do_has_children (GearyImapDBAccount* self,
                                       GearyDbConnection* cx,
                                       gint64 folder_id,
                                       GCancellable* cancellable,
                                       GError** error)
{
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbResult* _result_ = NULL;
	GearyDbStatement* _tmp6_;
	GearyDbResult* _tmp7_;
	GearyDbResult* _tmp9_;
	gboolean _tmp10_;
	gboolean _tmp11_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self), FALSE);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), FALSE);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), FALSE);
	_tmp0_ = geary_db_connection_prepare (cx, "SELECT 1 FROM FolderTable WHERE parent_id = ?", &_inner_error0_);
	stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp1_ = FALSE;
		g_propagate_error (error, _inner_error0_);
		return _tmp1_;
	}
	_tmp2_ = stmt;
	_tmp3_ = geary_db_statement_bind_rowid (_tmp2_, 0, folder_id, &_inner_error0_);
	_tmp4_ = _tmp3_;
	_g_object_unref0 (_tmp4_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp5_ = FALSE;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return _tmp5_;
	}
	_tmp6_ = stmt;
	_tmp7_ = geary_db_statement_exec (_tmp6_, cancellable, &_inner_error0_);
	_result_ = _tmp7_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp8_ = FALSE;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return _tmp8_;
	}
	_tmp9_ = _result_;
	_tmp10_ = geary_db_result_get_finished (_tmp9_);
	_tmp11_ = _tmp10_;
	result = !_tmp11_;
	_g_object_unref0 (_result_);
	_g_object_unref0 (stmt);
	return result;
}

static GeeSet*
geary_imap_db_account_do_find_email_folders (GearyImapDBAccount* self,
                                             GearyDbConnection* cx,
                                             gint64 message_id,
                                             gboolean include_removed,
                                             GCancellable* cancellable,
                                             GError** error)
{
	gchar* sql = NULL;
	gchar* _tmp0_;
	GearyDbStatement* stmt = NULL;
	const gchar* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbStatement* _tmp5_;
	GearyDbStatement* _tmp6_;
	GearyDbStatement* _tmp7_;
	GearyDbResult* _result_ = NULL;
	GearyDbStatement* _tmp8_;
	GearyDbResult* _tmp9_;
	GearyDbResult* _tmp10_;
	gboolean _tmp11_;
	gboolean _tmp12_;
	GeeHashSet* folder_paths = NULL;
	GeeHashSet* _tmp13_;
	GeeHashSet* _tmp23_ = NULL;
	GeeHashSet* _tmp24_;
	gint _tmp25_;
	gint _tmp26_;
	GeeSet* _tmp28_;
	GError* _inner_error0_ = NULL;
	GeeSet* result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self), NULL);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), NULL);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), NULL);
	_tmp0_ = g_strdup ("SELECT folder_id FROM MessageLocationTable WHERE message_id=?");
	sql = _tmp0_;
	if (!include_removed) {
		const gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = sql;
		_tmp2_ = g_strconcat (_tmp1_, " AND remove_marker=0", NULL);
		_g_free0 (sql);
		sql = _tmp2_;
	}
	_tmp3_ = sql;
	_tmp4_ = geary_db_connection_prepare (cx, _tmp3_, &_inner_error0_);
	stmt = _tmp4_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_free0 (sql);
		return NULL;
	}
	_tmp5_ = stmt;
	_tmp6_ = geary_db_statement_bind_int64 (_tmp5_, 0, message_id, &_inner_error0_);
	_tmp7_ = _tmp6_;
	_g_object_unref0 (_tmp7_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_free0 (sql);
		return NULL;
	}
	_tmp8_ = stmt;
	_tmp9_ = geary_db_statement_exec (_tmp8_, cancellable, &_inner_error0_);
	_result_ = _tmp9_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_free0 (sql);
		return NULL;
	}
	_tmp10_ = _result_;
	_tmp11_ = geary_db_result_get_finished (_tmp10_);
	_tmp12_ = _tmp11_;
	if (_tmp12_) {
		result = NULL;
		_g_object_unref0 (_result_);
		_g_object_unref0 (stmt);
		_g_free0 (sql);
		return result;
	}
	_tmp13_ = gee_hash_set_new (GEARY_TYPE_FOLDER_PATH, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL);
	folder_paths = _tmp13_;
	while (TRUE) {
		GearyDbResult* _tmp14_;
		gboolean _tmp15_;
		gboolean _tmp16_;
		gint64 folder_id = 0LL;
		GearyDbResult* _tmp17_;
		GearyFolderPath* path = NULL;
		GearyFolderPath* _tmp18_;
		GearyFolderPath* _tmp19_;
		GearyDbResult* _tmp22_;
		_tmp14_ = _result_;
		_tmp15_ = geary_db_result_get_finished (_tmp14_);
		_tmp16_ = _tmp15_;
		if (!(!_tmp16_)) {
			break;
		}
		_tmp17_ = _result_;
		folder_id = geary_db_result_int64_at (_tmp17_, 0, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (folder_paths);
			_g_object_unref0 (_result_);
			_g_object_unref0 (stmt);
			_g_free0 (sql);
			return NULL;
		}
		_tmp18_ = geary_imap_db_account_do_find_folder_path (self, cx, folder_id, cancellable, &_inner_error0_);
		path = _tmp18_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (folder_paths);
			_g_object_unref0 (_result_);
			_g_object_unref0 (stmt);
			_g_free0 (sql);
			return NULL;
		}
		_tmp19_ = path;
		if (_tmp19_ != NULL) {
			GeeHashSet* _tmp20_;
			GearyFolderPath* _tmp21_;
			_tmp20_ = folder_paths;
			_tmp21_ = path;
			gee_abstract_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp20_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection), _tmp21_);
		}
		_tmp22_ = _result_;
		geary_db_result_next (_tmp22_, cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (path);
			_g_object_unref0 (folder_paths);
			_g_object_unref0 (_result_);
			_g_object_unref0 (stmt);
			_g_free0 (sql);
			return NULL;
		}
		_g_object_unref0 (path);
	}
	_tmp24_ = folder_paths;
	_tmp25_ = gee_abstract_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp24_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection));
	_tmp26_ = _tmp25_;
	if (_tmp26_ == 0) {
		_tmp23_ = NULL;
	} else {
		GeeHashSet* _tmp27_;
		_tmp27_ = folder_paths;
		_tmp23_ = _tmp27_;
	}
	_tmp28_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp23_, GEE_TYPE_SET, GeeSet));
	result = _tmp28_;
	_g_object_unref0 (folder_paths);
	_g_object_unref0 (_result_);
	_g_object_unref0 (stmt);
	_g_free0 (sql);
	return result;
}

static GearyFolderPath*
geary_imap_db_account_do_find_folder_path (GearyImapDBAccount* self,
                                           GearyDbConnection* cx,
                                           gint64 folder_id,
                                           GCancellable* cancellable,
                                           GError** error)
{
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp1_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbResult* _result_ = NULL;
	GearyDbStatement* _tmp4_;
	GearyDbResult* _tmp5_;
	GearyDbResult* _tmp6_;
	gboolean _tmp7_;
	gboolean _tmp8_;
	gint64 parent_id = 0LL;
	GearyDbResult* _tmp9_;
	gchar* name = NULL;
	GearyDbResult* _tmp10_;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	GearyFolderPath* path = NULL;
	GError* _inner_error0_ = NULL;
	GearyFolderPath* result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self), NULL);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), NULL);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), NULL);
	_tmp0_ = geary_db_connection_prepare (cx, "SELECT parent_id, name FROM FolderTable WHERE id=?", &_inner_error0_);
	stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return NULL;
	}
	_tmp1_ = stmt;
	_tmp2_ = geary_db_statement_bind_int64 (_tmp1_, 0, folder_id, &_inner_error0_);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp3_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp4_ = stmt;
	_tmp5_ = geary_db_statement_exec (_tmp4_, cancellable, &_inner_error0_);
	_result_ = _tmp5_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp6_ = _result_;
	_tmp7_ = geary_db_result_get_finished (_tmp6_);
	_tmp8_ = _tmp7_;
	if (_tmp8_) {
		result = NULL;
		_g_object_unref0 (_result_);
		_g_object_unref0 (stmt);
		return result;
	}
	_tmp9_ = _result_;
	parent_id = geary_db_result_int64_at (_tmp9_, 0, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_result_);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp10_ = _result_;
	_tmp11_ = geary_db_result_nonnull_string_at (_tmp10_, 1, &_inner_error0_);
	_tmp12_ = g_strdup (_tmp11_);
	name = _tmp12_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_result_);
		_g_object_unref0 (stmt);
		return NULL;
	}
	if (folder_id == parent_id) {
		gchar* _tmp13_;
		gchar* _tmp14_;
		gchar* _tmp15_;
		gchar* _tmp16_;
		_tmp13_ = g_strdup_printf ("%" G_GINT64_FORMAT, folder_id);
		_tmp14_ = _tmp13_;
		_tmp15_ = g_strdup_printf ("%" G_GINT64_FORMAT, parent_id);
		_tmp16_ = _tmp15_;
		g_warning ("imap-db-account.vala:1090: Loop found in database: parent of %s is %s " \
"in FolderTable", _tmp14_, _tmp16_);
		_g_free0 (_tmp16_);
		_g_free0 (_tmp14_);
		result = NULL;
		_g_free0 (name);
		_g_object_unref0 (_result_);
		_g_object_unref0 (stmt);
		return result;
	}
	path = NULL;
	if (parent_id <= ((gint64) 0)) {
		GearyImapFolderRoot* _tmp17_;
		const gchar* _tmp18_;
		GearyFolderPath* _tmp19_;
		_tmp17_ = self->priv->_imap_folder_root;
		_tmp18_ = name;
		_tmp19_ = geary_folder_path_get_child (G_TYPE_CHECK_INSTANCE_CAST (_tmp17_, GEARY_TYPE_FOLDER_PATH, GearyFolderPath), _tmp18_, GEARY_TRILLIAN_UNKNOWN);
		_g_object_unref0 (path);
		path = _tmp19_;
	} else {
		GearyFolderPath* parent_path = NULL;
		GearyFolderPath* _tmp20_;
		GearyFolderPath* _tmp21_;
		_tmp20_ = geary_imap_db_account_do_find_folder_path (self, cx, parent_id, cancellable, &_inner_error0_);
		parent_path = _tmp20_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (path);
			_g_free0 (name);
			_g_object_unref0 (_result_);
			_g_object_unref0 (stmt);
			return NULL;
		}
		_tmp21_ = parent_path;
		if (_tmp21_ != NULL) {
			GearyFolderPath* _tmp22_;
			const gchar* _tmp23_;
			GearyFolderPath* _tmp24_;
			_tmp22_ = parent_path;
			_tmp23_ = name;
			_tmp24_ = geary_folder_path_get_child (_tmp22_, _tmp23_, GEARY_TRILLIAN_UNKNOWN);
			_g_object_unref0 (path);
			path = _tmp24_;
		}
		_g_object_unref0 (parent_path);
	}
	result = path;
	_g_free0 (name);
	_g_object_unref0 (_result_);
	_g_object_unref0 (stmt);
	return result;
}

static void
geary_imap_db_account_on_unread_updated (GearyImapDBAccount* self,
                                         GearyImapDBFolder* source,
                                         GeeMap* unread_status)
{
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (source));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (unread_status, GEE_TYPE_MAP));
	geary_imap_db_account_update_unread_async (self, source, unread_status, NULL, NULL, NULL);
}

static void
geary_imap_db_account_update_unread_async_data_free (gpointer _data)
{
	GearyImapDbAccountUpdateUnreadAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbAccountUpdateUnreadAsyncData, _data_);
}

static void
geary_imap_db_account_update_unread_async (GearyImapDBAccount* self,
                                           GearyImapDBFolder* source,
                                           GeeMap* unread_status,
                                           GCancellable* cancellable,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_)
{
	GearyImapDbAccountUpdateUnreadAsyncData* _data_;
	GearyImapDBAccount* _tmp0_;
	GearyImapDBFolder* _tmp1_;
	GeeMap* _tmp2_;
	GCancellable* _tmp3_;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (source));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (unread_status, GEE_TYPE_MAP));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbAccountUpdateUnreadAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_account_update_unread_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (source);
	_g_object_unref0 (_data_->source);
	_data_->source = _tmp1_;
	_tmp2_ = _g_object_ref0 (unread_status);
	_g_object_unref0 (_data_->unread_status);
	_data_->unread_status = _tmp2_;
	_tmp3_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp3_;
	geary_imap_db_account_update_unread_async_co (_data_);
}

static void
geary_imap_db_account_update_unread_finish (GearyImapDBAccount* self,
                                            GAsyncResult* _res_,
                                            GError** error)
{
	GearyImapDbAccountUpdateUnreadAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static Block48Data*
block48_data_ref (Block48Data* _data48_)
{
	g_atomic_int_inc (&_data48_->_ref_count_);
	return _data48_;
}

static void
block48_data_unref (void * _userdata_)
{
	Block48Data* _data48_;
	_data48_ = (Block48Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data48_->_ref_count_)) {
		GearyImapDBAccount* self;
		self = _data48_->self;
		_g_object_unref0 (_data48_->unread_change);
		_g_object_unref0 (_data48_->source);
		_g_object_unref0 (_data48_->unread_status);
		_g_object_unref0 (_data48_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block48Data, _data48_);
	}
}

static GearyDbTransactionOutcome
__lambda89_ (Block48Data* _data48_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBAccount* self;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data48_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	{
		GeeIterator* _id_it = NULL;
		GeeSet* _tmp0_;
		GeeSet* _tmp1_;
		GeeSet* _tmp2_;
		GeeIterator* _tmp3_;
		GeeIterator* _tmp4_;
		_tmp0_ = gee_map_get_keys (_data48_->unread_status);
		_tmp1_ = _tmp0_;
		_tmp2_ = _tmp1_;
		_tmp3_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, GEE_TYPE_ITERABLE, GeeIterable));
		_tmp4_ = _tmp3_;
		_g_object_unref0 (_tmp2_);
		_id_it = _tmp4_;
		while (TRUE) {
			GeeIterator* _tmp5_;
			GearyImapDBEmailIdentifier* id = NULL;
			GeeIterator* _tmp6_;
			gpointer _tmp7_;
			GeeSet* paths = NULL;
			GearyImapDBEmailIdentifier* _tmp8_;
			gint64 _tmp9_;
			gint64 _tmp10_;
			GeeSet* _tmp11_;
			GeeSet* _tmp12_;
			GeeSet* _tmp13_;
			GearyFolderPath* _tmp14_;
			GeeSet* _tmp15_;
			gint _tmp16_;
			gint _tmp17_;
			_tmp5_ = _id_it;
			if (!gee_iterator_next (_tmp5_)) {
				break;
			}
			_tmp6_ = _id_it;
			_tmp7_ = gee_iterator_get (_tmp6_);
			id = (GearyImapDBEmailIdentifier*) _tmp7_;
			_tmp8_ = id;
			_tmp9_ = geary_imap_db_email_identifier_get_message_id (_tmp8_);
			_tmp10_ = _tmp9_;
			_tmp11_ = geary_imap_db_account_do_find_email_folders (self, cx, _tmp10_, TRUE, _data48_->cancellable, &_inner_error0_);
			paths = _tmp11_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				return 0;
			}
			_tmp12_ = paths;
			if (_tmp12_ == NULL) {
				_g_object_unref0 (paths);
				_g_object_unref0 (id);
				continue;
			}
			_tmp13_ = paths;
			_tmp14_ = geary_imap_db_folder_get_path (_data48_->source);
			gee_collection_remove (G_TYPE_CHECK_INSTANCE_CAST (_tmp13_, GEE_TYPE_COLLECTION, GeeCollection), _tmp14_);
			_tmp15_ = paths;
			_tmp16_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp15_, GEE_TYPE_COLLECTION, GeeCollection));
			_tmp17_ = _tmp16_;
			if (_tmp17_ == 0) {
				_g_object_unref0 (paths);
				_g_object_unref0 (id);
				continue;
			}
			{
				GeeIterator* _path_it = NULL;
				GeeSet* _tmp18_;
				GeeIterator* _tmp19_;
				_tmp18_ = paths;
				_tmp19_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp18_, GEE_TYPE_ITERABLE, GeeIterable));
				_path_it = _tmp19_;
				while (TRUE) {
					GeeIterator* _tmp20_;
					GearyFolderPath* path = NULL;
					GeeIterator* _tmp21_;
					gpointer _tmp22_;
					gint _tmp23_ = 0;
					GeeMap* _tmp24_;
					GearyFolderPath* _tmp25_;
					gint current_unread = 0;
					gint _tmp29_ = 0;
					GearyImapDBEmailIdentifier* _tmp30_;
					gpointer _tmp31_;
					GeeMap* _tmp32_;
					GearyFolderPath* _tmp33_;
					_tmp20_ = _path_it;
					if (!gee_iterator_next (_tmp20_)) {
						break;
					}
					_tmp21_ = _path_it;
					_tmp22_ = gee_iterator_get (_tmp21_);
					path = (GearyFolderPath*) _tmp22_;
					_tmp24_ = _data48_->unread_change;
					_tmp25_ = path;
					if (gee_map_has_key (_tmp24_, _tmp25_)) {
						GeeMap* _tmp26_;
						GearyFolderPath* _tmp27_;
						gpointer _tmp28_;
						_tmp26_ = _data48_->unread_change;
						_tmp27_ = path;
						_tmp28_ = gee_map_get (_tmp26_, _tmp27_);
						_tmp23_ = (gint) ((gintptr) _tmp28_);
					} else {
						_tmp23_ = 0;
					}
					current_unread = _tmp23_;
					_tmp30_ = id;
					_tmp31_ = gee_map_get (_data48_->unread_status, _tmp30_);
					if ((gboolean) ((gintptr) _tmp31_)) {
						_tmp29_ = 1;
					} else {
						_tmp29_ = -1;
					}
					current_unread += _tmp29_;
					_tmp32_ = _data48_->unread_change;
					_tmp33_ = path;
					gee_map_set (_tmp32_, _tmp33_, (gpointer) ((gintptr) current_unread));
					_g_object_unref0 (path);
				}
				_g_object_unref0 (_path_it);
			}
			_g_object_unref0 (paths);
			_g_object_unref0 (id);
		}
		_g_object_unref0 (_id_it);
	}
	{
		GeeIterator* _path_it = NULL;
		GeeMap* _tmp34_;
		GeeSet* _tmp35_;
		GeeSet* _tmp36_;
		GeeSet* _tmp37_;
		GeeIterator* _tmp38_;
		GeeIterator* _tmp39_;
		_tmp34_ = _data48_->unread_change;
		_tmp35_ = gee_map_get_keys (_tmp34_);
		_tmp36_ = _tmp35_;
		_tmp37_ = _tmp36_;
		_tmp38_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp37_, GEE_TYPE_ITERABLE, GeeIterable));
		_tmp39_ = _tmp38_;
		_g_object_unref0 (_tmp37_);
		_path_it = _tmp39_;
		while (TRUE) {
			GeeIterator* _tmp40_;
			GearyFolderPath* path = NULL;
			GeeIterator* _tmp41_;
			gpointer _tmp42_;
			GearyImapDBFolder* folder = NULL;
			GearyFolderPath* _tmp43_;
			GearyImapDBFolder* _tmp44_;
			GearyImapDBFolder* _tmp45_;
			GearyImapDBFolder* _tmp46_;
			GeeMap* _tmp47_;
			GearyFolderPath* _tmp48_;
			gpointer _tmp49_;
			_tmp40_ = _path_it;
			if (!gee_iterator_next (_tmp40_)) {
				break;
			}
			_tmp41_ = _path_it;
			_tmp42_ = gee_iterator_get (_tmp41_);
			path = (GearyFolderPath*) _tmp42_;
			_tmp43_ = path;
			_tmp44_ = geary_imap_db_account_get_local_folder (self, _tmp43_);
			folder = _tmp44_;
			_tmp45_ = folder;
			if (_tmp45_ == NULL) {
				_g_object_unref0 (folder);
				_g_object_unref0 (path);
				continue;
			}
			_tmp46_ = folder;
			_tmp47_ = _data48_->unread_change;
			_tmp48_ = path;
			_tmp49_ = gee_map_get (_tmp47_, _tmp48_);
			geary_imap_db_folder_do_add_to_unread_count (_tmp46_, cx, (gint) ((gintptr) _tmp49_), _data48_->cancellable, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (folder);
				_g_object_unref0 (path);
				_g_object_unref0 (_path_it);
				return 0;
			}
			_g_object_unref0 (folder);
			_g_object_unref0 (path);
		}
		_g_object_unref0 (_path_it);
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_SUCCESS;
	return result;
}

static GearyDbTransactionOutcome
___lambda89__geary_db_transaction_method (GearyDbConnection* cx,
                                          GCancellable* cancellable,
                                          gpointer self,
                                          GError** error)
{
	GearyDbTransactionOutcome result;
	result = __lambda89_ (self, cx, error);
	return result;
}

static void
geary_imap_db_account_update_unread_async_ready (GObject* source_object,
                                                 GAsyncResult* _res_,
                                                 gpointer _user_data_)
{
	GearyImapDbAccountUpdateUnreadAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_account_update_unread_async_co (_data_);
}

static gboolean
geary_imap_db_account_update_unread_async_co (GearyImapDbAccountUpdateUnreadAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data48_ = g_slice_new0 (Block48Data);
	_data_->_data48_->_ref_count_ = 1;
	_data_->_data48_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data48_->source);
	_data_->_data48_->source = _data_->source;
	_g_object_unref0 (_data_->_data48_->unread_status);
	_data_->_data48_->unread_status = _data_->unread_status;
	_g_object_unref0 (_data_->_data48_->cancellable);
	_data_->_data48_->cancellable = _data_->cancellable;
	_data_->_data48_->_async_data_ = _data_;
	_data_->_tmp0_ = gee_hash_map_new (GEARY_TYPE_FOLDER_PATH, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, G_TYPE_INT, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->_data48_->unread_change = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEE_TYPE_MAP, GeeMap);
	_data_->_tmp1_ = _data_->self->priv->_db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), GEARY_DB_TRANSACTION_TYPE_RW, ___lambda89__geary_db_transaction_method, _data_->_data48_, _data_->_data48_->cancellable, geary_imap_db_account_update_unread_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase), _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block48_data_unref (_data_->_data48_);
		_data_->_data48_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	{
		_data_->_tmp2_ = _data_->_data48_->unread_change;
		_data_->_tmp3_ = gee_map_get_keys (_data_->_tmp2_);
		_data_->_tmp4_ = _data_->_tmp3_;
		_data_->_tmp5_ = _data_->_tmp4_;
		_data_->_tmp6_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp5_, GEE_TYPE_ITERABLE, GeeIterable));
		_data_->_tmp7_ = _data_->_tmp6_;
		_g_object_unref0 (_data_->_tmp5_);
		_data_->_path_it = _data_->_tmp7_;
		while (TRUE) {
			_data_->_tmp8_ = _data_->_path_it;
			if (!gee_iterator_next (_data_->_tmp8_)) {
				break;
			}
			_data_->_tmp9_ = _data_->_path_it;
			_data_->_tmp10_ = gee_iterator_get (_data_->_tmp9_);
			_data_->path = (GearyFolderPath*) _data_->_tmp10_;
			_data_->_tmp11_ = _data_->path;
			_data_->_tmp12_ = geary_imap_db_account_get_local_folder (_data_->self, _data_->_tmp11_);
			_data_->folder = _data_->_tmp12_;
			_data_->_tmp13_ = _data_->folder;
			if (_data_->_tmp13_ == NULL) {
				_g_object_unref0 (_data_->folder);
				_g_object_unref0 (_data_->path);
				continue;
			}
			_data_->_tmp14_ = _data_->folder;
			_data_->_tmp15_ = geary_imap_db_folder_get_properties (_data_->_tmp14_);
			_data_->_tmp16_ = _data_->_tmp15_;
			_data_->_tmp17_ = _data_->folder;
			_data_->_tmp18_ = geary_imap_db_folder_get_properties (_data_->_tmp17_);
			_data_->_tmp19_ = _data_->_tmp18_;
			_data_->_tmp20_ = geary_folder_properties_get_email_unread (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp19_, GEARY_TYPE_FOLDER_PROPERTIES, GearyFolderProperties));
			_data_->_tmp21_ = _data_->_tmp20_;
			_data_->_tmp22_ = _data_->_data48_->unread_change;
			_data_->_tmp23_ = _data_->path;
			_data_->_tmp24_ = gee_map_get (_data_->_tmp22_, _data_->_tmp23_);
			geary_imap_folder_properties_set_status_unseen (_data_->_tmp16_, _data_->_tmp21_ + ((gint) ((gintptr) _data_->_tmp24_)));
			_g_object_unref0 (_data_->_tmp19_);
			_g_object_unref0 (_data_->_tmp16_);
			_g_object_unref0 (_data_->folder);
			_g_object_unref0 (_data_->path);
		}
		_g_object_unref0 (_data_->_path_it);
	}
	block48_data_unref (_data_->_data48_);
	_data_->_data48_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

GeeMap*
geary_imap_db_account_do_get_search_matches (GearyImapDBAccount* self,
                                             GearyDbConnection* cx,
                                             GearyFtsSearchQuery* query,
                                             GeeMap* id_map,
                                             GCancellable* cancellable,
                                             GError** error)
{
	GString* search_ids_sql = NULL;
	GString* _tmp0_;
	GString* _tmp1_;
	GeeSet* _tmp2_;
	GeeSet* _tmp3_;
	GeeSet* _tmp4_;
	GeeHashMap* search_matches = NULL;
	GeeHashMap* _tmp5_;
	GearyDbStatement* _tmp6_ = NULL;
	GString* _tmp7_;
	const gchar* _tmp8_;
	GearyDbStatement* _tmp9_;
	GearyDbResult* _result_ = NULL;
	GearyDbResult* _tmp10_;
	GeeHashMap* _tmp39_ = NULL;
	GeeHashMap* _tmp40_;
	gint _tmp41_;
	gint _tmp42_;
	GeeMap* _tmp44_;
	GError* _inner_error0_ = NULL;
	GeeMap* result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self), NULL);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), NULL);
	g_return_val_if_fail (GEARY_IS_FTS_SEARCH_QUERY (query), NULL);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (id_map, GEE_TYPE_MAP), NULL);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), NULL);
	_tmp0_ = g_string_new ("");
	search_ids_sql = _tmp0_;
	_tmp1_ = search_ids_sql;
	_tmp2_ = gee_map_get_keys (id_map);
	_tmp3_ = _tmp2_;
	_tmp4_ = _tmp3_;
	geary_imap_db_account_sql_append_ids (self, _tmp1_, G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, GEE_TYPE_ITERABLE, GeeIterable));
	_g_object_unref0 (_tmp4_);
	_tmp5_ = gee_hash_map_new (GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEE_TYPE_SET, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	search_matches = _tmp5_;
	_tmp7_ = search_ids_sql;
	_tmp8_ = _tmp7_->str;
	_tmp9_ = geary_fts_search_query_get_match_query (query, cx, _tmp8_, &_inner_error0_);
	_tmp6_ = _tmp9_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (search_matches);
		_g_string_free0 (search_ids_sql);
		return NULL;
	}
	_tmp10_ = geary_db_statement_exec (_tmp6_, cancellable, &_inner_error0_);
	_result_ = _tmp10_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp6_);
		_g_object_unref0 (search_matches);
		_g_string_free0 (search_ids_sql);
		return NULL;
	}
	while (TRUE) {
		GearyDbResult* _tmp11_;
		gboolean _tmp12_;
		gboolean _tmp13_;
		gint64 docid = 0LL;
		GearyDbResult* _tmp14_;
		GearyImapDBEmailIdentifier* id = NULL;
		gpointer _tmp15_;
		const gchar* _tmp16_ = NULL;
		GearyDbResult* _tmp17_;
		const gchar* _tmp18_;
		GeeHashSet* matches = NULL;
		GeeHashSet* _tmp20_;
		const gchar* _tmp21_ = NULL;
		GearyDbResult* _tmp22_;
		const gchar* _tmp23_;
		GeeHashSet* _tmp24_;
		gchar** _tmp25_;
		gchar** _tmp26_;
		gchar** _tmp27_;
		gint _tmp27__length1;
		GeeHashMap* _tmp28_;
		GearyImapDBEmailIdentifier* _tmp29_;
		GeeHashMap* _tmp35_;
		GearyImapDBEmailIdentifier* _tmp36_;
		GeeHashSet* _tmp37_;
		GearyDbResult* _tmp38_;
		_tmp11_ = _result_;
		_tmp12_ = geary_db_result_get_finished (_tmp11_);
		_tmp13_ = _tmp12_;
		if (!(!_tmp13_)) {
			break;
		}
		_tmp14_ = _result_;
		docid = geary_db_result_rowid_at (_tmp14_, 0, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (_result_);
			_g_object_unref0 (_tmp6_);
			_g_object_unref0 (search_matches);
			_g_string_free0 (search_ids_sql);
			return NULL;
		}
		_tmp15_ = gee_map_get (id_map, &docid);
		id = (GearyImapDBEmailIdentifier*) _tmp15_;
		_tmp17_ = _result_;
		_tmp18_ = geary_db_result_string_at (_tmp17_, 1, &_inner_error0_);
		_tmp16_ = _tmp18_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (id);
			_g_object_unref0 (_result_);
			_g_object_unref0 (_tmp6_);
			_g_object_unref0 (search_matches);
			_g_string_free0 (search_ids_sql);
			return NULL;
		}
		if (_tmp16_ == NULL) {
			GearyDbResult* _tmp19_;
			g_debug ("imap-db-account.vala:1184: Avoiding a crash from 'database disk image " \
"is malformed' error");
			_tmp19_ = _result_;
			geary_db_result_next (_tmp19_, cancellable, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (id);
				_g_object_unref0 (_result_);
				_g_object_unref0 (_tmp6_);
				_g_object_unref0 (search_matches);
				_g_string_free0 (search_ids_sql);
				return NULL;
			}
			_g_object_unref0 (id);
			continue;
		}
		_tmp20_ = gee_hash_set_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL, NULL, NULL, NULL);
		matches = _tmp20_;
		_tmp22_ = _result_;
		_tmp23_ = geary_db_result_nonnull_string_at (_tmp22_, 1, &_inner_error0_);
		_tmp21_ = _tmp23_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (matches);
			_g_object_unref0 (id);
			_g_object_unref0 (_result_);
			_g_object_unref0 (_tmp6_);
			_g_object_unref0 (search_matches);
			_g_string_free0 (search_ids_sql);
			return NULL;
		}
		_tmp24_ = matches;
		_tmp26_ = _tmp25_ = g_strsplit (_tmp21_, ",", 0);
		_tmp27_ = _tmp26_;
		_tmp27__length1 = _vala_array_length (_tmp25_);
		gee_collection_add_all_array (G_TYPE_CHECK_INSTANCE_CAST (_tmp24_, GEE_TYPE_COLLECTION, GeeCollection), _tmp27_, (gint) _vala_array_length (_tmp25_));
		_tmp27_ = (_vala_array_free (_tmp27_, _tmp27__length1, (GDestroyNotify) g_free), NULL);
		_tmp28_ = search_matches;
		_tmp29_ = id;
		if (gee_abstract_map_has_key (G_TYPE_CHECK_INSTANCE_CAST (_tmp28_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _tmp29_)) {
			GeeHashSet* _tmp30_;
			GeeHashMap* _tmp31_;
			GearyImapDBEmailIdentifier* _tmp32_;
			gpointer _tmp33_;
			GeeSet* _tmp34_;
			_tmp30_ = matches;
			_tmp31_ = search_matches;
			_tmp32_ = id;
			_tmp33_ = gee_abstract_map_get (G_TYPE_CHECK_INSTANCE_CAST (_tmp31_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _tmp32_);
			_tmp34_ = (GeeSet*) _tmp33_;
			gee_collection_add_all (G_TYPE_CHECK_INSTANCE_CAST (_tmp30_, GEE_TYPE_COLLECTION, GeeCollection), G_TYPE_CHECK_INSTANCE_CAST (_tmp34_, GEE_TYPE_COLLECTION, GeeCollection));
			_g_object_unref0 (_tmp34_);
		}
		_tmp35_ = search_matches;
		_tmp36_ = id;
		_tmp37_ = matches;
		gee_abstract_map_set (G_TYPE_CHECK_INSTANCE_CAST (_tmp35_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _tmp36_, G_TYPE_CHECK_INSTANCE_CAST (_tmp37_, GEE_TYPE_SET, GeeSet));
		_tmp38_ = _result_;
		geary_db_result_next (_tmp38_, cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (matches);
			_g_object_unref0 (id);
			_g_object_unref0 (_result_);
			_g_object_unref0 (_tmp6_);
			_g_object_unref0 (search_matches);
			_g_string_free0 (search_ids_sql);
			return NULL;
		}
		_g_object_unref0 (matches);
		_g_object_unref0 (id);
	}
	_tmp40_ = search_matches;
	_tmp41_ = gee_abstract_map_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp40_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap));
	_tmp42_ = _tmp41_;
	if (_tmp42_ > 0) {
		GeeHashMap* _tmp43_;
		_tmp43_ = search_matches;
		_tmp39_ = _tmp43_;
	} else {
		_tmp39_ = NULL;
	}
	_tmp44_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp39_, GEE_TYPE_MAP, GeeMap));
	result = _tmp44_;
	_g_object_unref0 (_result_);
	_g_object_unref0 (_tmp6_);
	_g_object_unref0 (search_matches);
	_g_string_free0 (search_ids_sql);
	return result;
}

static void
geary_imap_db_account_delete_all_data_data_free (gpointer _data)
{
	GearyImapDbAccountDeleteAllDataData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbAccountDeleteAllDataData, _data_);
}

void
geary_imap_db_account_delete_all_data (GearyImapDBAccount* self,
                                       GCancellable* cancellable,
                                       GAsyncReadyCallback _callback_,
                                       gpointer _user_data_)
{
	GearyImapDbAccountDeleteAllDataData* _data_;
	GearyImapDBAccount* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbAccountDeleteAllDataData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_account_delete_all_data_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_db_account_delete_all_data_co (_data_);
}

void
geary_imap_db_account_delete_all_data_finish (GearyImapDBAccount* self,
                                              GAsyncResult* _res_,
                                              GError** error)
{
	GearyImapDbAccountDeleteAllDataData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

/** Removes database file and attachments directory. */
static void
geary_imap_db_account_delete_all_data_ready (GObject* source_object,
                                             GAsyncResult* _res_,
                                             gpointer _user_data_)
{
	GearyImapDbAccountDeleteAllDataData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_account_delete_all_data_co (_data_);
}

static gboolean
geary_imap_db_account_delete_all_data_co (GearyImapDbAccountDeleteAllDataData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		case 4:
		goto _state_4;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->_db;
	_data_->_tmp1_ = geary_db_database_get_is_open (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase));
	_data_->_tmp2_ = _data_->_tmp1_;
	if (_data_->_tmp2_) {
		_data_->_tmp3_ = g_error_new_literal (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_ALREADY_OPEN, "Account cannot be open during rebuild");
		_data_->_inner_error0_ = _data_->_tmp3_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp5_ = _data_->self->priv->db_file;
	_data_->_state_ = 1;
	geary_files_query_exists_async (_data_->_tmp5_, _data_->cancellable, geary_imap_db_account_delete_all_data_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp4_ = geary_files_query_exists_finish (_data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (_data_->_tmp4_) {
		_data_->_tmp6_ = _data_->self->priv->name;
		_data_->_tmp7_ = _data_->self->priv->db_file;
		_data_->_tmp8_ = g_file_get_path (_data_->_tmp7_);
		_data_->_tmp9_ = _data_->_tmp8_;
		g_message ("imap-db-account.vala:1213: %s: Deleting database file %s...", _data_->_tmp6_, _data_->_tmp9_);
		_g_free0 (_data_->_tmp9_);
		_data_->_tmp10_ = _data_->self->priv->db_file;
		_data_->_state_ = 2;
		g_file_delete_async (_data_->_tmp10_, G_PRIORITY_DEFAULT, _data_->cancellable, geary_imap_db_account_delete_all_data_ready, _data_);
		return FALSE;
		_state_2:
		g_file_delete_finish (_data_->_tmp10_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->_tmp12_ = _data_->self->priv->attachments_dir;
	_data_->_state_ = 3;
	geary_files_query_exists_async (_data_->_tmp12_, _data_->cancellable, geary_imap_db_account_delete_all_data_ready, _data_);
	return FALSE;
	_state_3:
	_data_->_tmp11_ = geary_files_query_exists_finish (_data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (_data_->_tmp11_) {
		_data_->_tmp13_ = _data_->self->priv->name;
		_data_->_tmp14_ = _data_->self->priv->attachments_dir;
		_data_->_tmp15_ = g_file_get_path (_data_->_tmp14_);
		_data_->_tmp16_ = _data_->_tmp15_;
		g_message ("imap-db-account.vala:1221: %s: Deleting attachments directory %s...", _data_->_tmp13_, _data_->_tmp16_);
		_g_free0 (_data_->_tmp16_);
		_data_->_tmp17_ = _data_->self->priv->attachments_dir;
		_data_->_state_ = 4;
		geary_files_recursive_delete_async (_data_->_tmp17_, G_PRIORITY_DEFAULT, _data_->cancellable, geary_imap_db_account_delete_all_data_ready, _data_);
		return FALSE;
		_state_4:
		geary_files_recursive_delete_finish (_data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static gchar*
geary_imap_db_account_do_get_excluded_folder_ids (GearyImapDBAccount* self,
                                                  GeeCollection* excluded_folder,
                                                  GearyDbConnection* cx,
                                                  gboolean* exclude_folderless,
                                                  GCancellable* cancellable,
                                                  GError** error)
{
	gboolean _vala_exclude_folderless = FALSE;
	GString* ids = NULL;
	GString* _tmp0_;
	gboolean is_first = FALSE;
	GString* _tmp12_;
	const gchar* _tmp13_;
	gchar* _tmp14_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self), NULL);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (excluded_folder, GEE_TYPE_COLLECTION), NULL);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), NULL);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), NULL);
	_vala_exclude_folderless = FALSE;
	_tmp0_ = g_string_new ("");
	ids = _tmp0_;
	is_first = TRUE;
	{
		GeeIterator* _folder_path_it = NULL;
		GeeIterator* _tmp1_;
		_tmp1_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (excluded_folder, GEE_TYPE_ITERABLE, GeeIterable));
		_folder_path_it = _tmp1_;
		while (TRUE) {
			GeeIterator* _tmp2_;
			GearyFolderPath* folder_path = NULL;
			GeeIterator* _tmp3_;
			gpointer _tmp4_;
			GearyFolderPath* _tmp5_;
			_tmp2_ = _folder_path_it;
			if (!gee_iterator_next (_tmp2_)) {
				break;
			}
			_tmp3_ = _folder_path_it;
			_tmp4_ = gee_iterator_get (_tmp3_);
			folder_path = (GearyFolderPath*) _tmp4_;
			_tmp5_ = folder_path;
			if (_tmp5_ == NULL) {
				_vala_exclude_folderless = TRUE;
			} else {
				gint64 id = 0LL;
				GearyFolderPath* _tmp6_;
				gint64 _tmp7_ = 0LL;
				_tmp6_ = folder_path;
				geary_imap_db_account_do_fetch_folder_id (self, cx, _tmp6_, TRUE, &_tmp7_, cancellable, &_inner_error0_);
				id = _tmp7_;
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					g_propagate_error (error, _inner_error0_);
					_g_object_unref0 (folder_path);
					_g_object_unref0 (_folder_path_it);
					_g_string_free0 (ids);
					return NULL;
				}
				if (id != GEARY_DB_INVALID_ROWID) {
					GString* _tmp9_;
					gchar* _tmp10_;
					gchar* _tmp11_;
					if (!is_first) {
						GString* _tmp8_;
						_tmp8_ = ids;
						g_string_append_c (_tmp8_, ',');
					}
					_tmp9_ = ids;
					_tmp10_ = g_strdup_printf ("%" G_GINT64_FORMAT, id);
					_tmp11_ = _tmp10_;
					g_string_append (_tmp9_, _tmp11_);
					_g_free0 (_tmp11_);
					is_first = FALSE;
				}
			}
			_g_object_unref0 (folder_path);
		}
		_g_object_unref0 (_folder_path_it);
	}
	_tmp12_ = ids;
	_tmp13_ = _tmp12_->str;
	_tmp14_ = g_strdup (_tmp13_);
	result = _tmp14_;
	_g_string_free0 (ids);
	if (exclude_folderless) {
		*exclude_folderless = _vala_exclude_folderless;
	}
	return result;
}

static inline void
geary_imap_db_account_check_open (GearyImapDBAccount* self,
                                  GError** error)
{
	GearyImapDBDatabase* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self));
	_tmp0_ = self->priv->_db;
	_tmp1_ = geary_db_database_get_is_open (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase));
	_tmp2_ = _tmp1_;
	if (!_tmp2_) {
		GError* _tmp3_;
		_tmp3_ = g_error_new_literal (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_OPEN_REQUIRED, "Database not open");
		_inner_error0_ = _tmp3_;
		g_propagate_error (error, _inner_error0_);
		return;
	}
}

static GearyFtsSearchQuery*
geary_imap_db_account_check_search_query (GearyImapDBAccount* self,
                                          GearySearchQuery* q,
                                          GError** error)
{
	GearyFtsSearchQuery* query = NULL;
	GearyFtsSearchQuery* _tmp0_;
	GearyFtsSearchQuery* _tmp1_;
	GError* _inner_error0_ = NULL;
	GearyFtsSearchQuery* result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (self), NULL);
	g_return_val_if_fail (GEARY_IS_SEARCH_QUERY (q), NULL);
	_tmp0_ = _g_object_ref0 (GEARY_IS_FTS_SEARCH_QUERY (q) ? ((GearyFtsSearchQuery*) q) : NULL);
	query = _tmp0_;
	_tmp1_ = query;
	if (_tmp1_ == NULL) {
		const gchar* _tmp2_;
		GError* _tmp3_;
		_tmp2_ = self->priv->name;
		_tmp3_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_BAD_PARAMETERS, "Geary.SearchQuery not associated with %s", _tmp2_);
		_inner_error0_ = _tmp3_;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (query);
		return NULL;
	}
	result = query;
	return result;
}

static GearyImapDBAccountFolderReference*
geary_imap_db_account_folder_reference_construct (GType object_type,
                                                  GearyImapDBFolder* folder,
                                                  GearyFolderPath* path)
{
	GearyImapDBAccountFolderReference * self = NULL;
	GearyFolderPath* _tmp0_;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_FOLDER (folder), NULL);
	g_return_val_if_fail (GEARY_IS_FOLDER_PATH (path), NULL);
	self = (GearyImapDBAccountFolderReference*) geary_smart_reference_construct (object_type, G_TYPE_CHECK_INSTANCE_CAST (folder, GEARY_TYPE_REFERENCE_SEMANTICS, GearyReferenceSemantics));
	_tmp0_ = _g_object_ref0 (path);
	_g_object_unref0 (self->path);
	self->path = _tmp0_;
	return self;
}

static GearyImapDBAccountFolderReference*
geary_imap_db_account_folder_reference_new (GearyImapDBFolder* folder,
                                            GearyFolderPath* path)
{
	return geary_imap_db_account_folder_reference_construct (GEARY_IMAP_DB_ACCOUNT_TYPE_FOLDER_REFERENCE, folder, path);
}

static void
geary_imap_db_account_folder_reference_class_init (GearyImapDBAccountFolderReferenceClass * klass,
                                                   gpointer klass_data)
{
	geary_imap_db_account_folder_reference_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = geary_imap_db_account_folder_reference_finalize;
}

static void
geary_imap_db_account_folder_reference_instance_init (GearyImapDBAccountFolderReference * self,
                                                      gpointer klass)
{
}

static void
geary_imap_db_account_folder_reference_finalize (GObject * obj)
{
	GearyImapDBAccountFolderReference * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_IMAP_DB_ACCOUNT_TYPE_FOLDER_REFERENCE, GearyImapDBAccountFolderReference);
	_g_object_unref0 (self->path);
	G_OBJECT_CLASS (geary_imap_db_account_folder_reference_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
geary_imap_db_account_folder_reference_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapDBAccountFolderReferenceClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_db_account_folder_reference_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapDBAccountFolderReference), 0, (GInstanceInitFunc) geary_imap_db_account_folder_reference_instance_init, NULL };
	GType geary_imap_db_account_folder_reference_type_id;
	geary_imap_db_account_folder_reference_type_id = g_type_register_static (GEARY_TYPE_SMART_REFERENCE, "GearyImapDBAccountFolderReference", &g_define_type_info, 0);
	return geary_imap_db_account_folder_reference_type_id;
}

static GType
geary_imap_db_account_folder_reference_get_type (void)
{
	static gsize geary_imap_db_account_folder_reference_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_db_account_folder_reference_type_id__once)) {
		GType geary_imap_db_account_folder_reference_type_id;
		geary_imap_db_account_folder_reference_type_id = geary_imap_db_account_folder_reference_get_type_once ();
		g_once_init_leave (&geary_imap_db_account_folder_reference_type_id__once, geary_imap_db_account_folder_reference_type_id);
	}
	return geary_imap_db_account_folder_reference_type_id__once;
}

static void
geary_imap_db_account_class_init (GearyImapDBAccountClass * klass,
                                  gpointer klass_data)
{
	geary_imap_db_account_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GearyImapDBAccount_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_geary_imap_db_account_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_geary_imap_db_account_set_property;
	G_OBJECT_CLASS (klass)->finalize = geary_imap_db_account_finalize;
	/**
	     * The root path for all remote IMAP folders.
	     *
	     * No folder exists for this path locally or on the remote server,
	     * it merely exists to provide a common root for the paths of all
	     * IMAP folders.
	     *
	     * @see list_folders_async
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_DB_ACCOUNT_IMAP_FOLDER_ROOT_PROPERTY, geary_imap_db_account_properties[GEARY_IMAP_DB_ACCOUNT_IMAP_FOLDER_ROOT_PROPERTY] = g_param_spec_object ("imap-folder-root", "imap-folder-root", "imap-folder-root", GEARY_IMAP_TYPE_FOLDER_ROOT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_DB_ACCOUNT_UPGRADE_MONITOR_PROPERTY, geary_imap_db_account_properties[GEARY_IMAP_DB_ACCOUNT_UPGRADE_MONITOR_PROPERTY] = g_param_spec_object ("upgrade-monitor", "upgrade-monitor", "upgrade-monitor", GEARY_TYPE_SIMPLE_PROGRESS_MONITOR, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_DB_ACCOUNT_VACUUM_MONITOR_PROPERTY, geary_imap_db_account_properties[GEARY_IMAP_DB_ACCOUNT_VACUUM_MONITOR_PROPERTY] = g_param_spec_object ("vacuum-monitor", "vacuum-monitor", "vacuum-monitor", GEARY_TYPE_SIMPLE_PROGRESS_MONITOR, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** The backing database for the account. */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_DB_ACCOUNT_DB_PROPERTY, geary_imap_db_account_properties[GEARY_IMAP_DB_ACCOUNT_DB_PROPERTY] = g_param_spec_object ("db", "db", "db", GEARY_IMAP_DB_TYPE_DATABASE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_DB_ACCOUNT_ACCOUNT_INFORMATION_PROPERTY, geary_imap_db_account_properties[GEARY_IMAP_DB_ACCOUNT_ACCOUNT_INFORMATION_PROPERTY] = g_param_spec_object ("account-information", "account-information", "account-information", GEARY_TYPE_ACCOUNT_INFORMATION, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
geary_imap_db_account_instance_init (GearyImapDBAccount * self,
                                     gpointer klass)
{
	GearyImapFolderRoot* _tmp0_;
	GearySimpleProgressMonitor* _tmp1_;
	GearySimpleProgressMonitor* _tmp2_;
	GeeHashMap* _tmp3_;
	self->priv = geary_imap_db_account_get_instance_private (self);
	_tmp0_ = geary_imap_folder_root_new ("$geary-imap");
	self->priv->_imap_folder_root = _tmp0_;
	_tmp1_ = geary_simple_progress_monitor_new (GEARY_PROGRESS_TYPE_DB_UPGRADE);
	self->priv->_upgrade_monitor = _tmp1_;
	_tmp2_ = geary_simple_progress_monitor_new (GEARY_PROGRESS_TYPE_DB_VACUUM);
	self->priv->_vacuum_monitor = _tmp2_;
	_tmp3_ = gee_hash_map_new (GEARY_TYPE_FOLDER_PATH, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEARY_IMAP_DB_ACCOUNT_TYPE_FOLDER_REFERENCE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->folder_refs = _tmp3_;
	self->priv->background_cancellable = NULL;
}

static void
geary_imap_db_account_finalize (GObject * obj)
{
	GearyImapDBAccount * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_IMAP_DB_TYPE_ACCOUNT, GearyImapDBAccount);
	_g_object_unref0 (self->priv->_imap_folder_root);
	_g_object_unref0 (self->priv->_upgrade_monitor);
	_g_object_unref0 (self->priv->_vacuum_monitor);
	_g_object_unref0 (self->priv->_db);
	_g_object_unref0 (self->priv->_account_information);
	_g_free0 (self->priv->name);
	_g_object_unref0 (self->priv->db_file);
	_g_object_unref0 (self->priv->attachments_dir);
	_g_object_unref0 (self->priv->folder_refs);
	_g_object_unref0 (self->priv->background_cancellable);
	G_OBJECT_CLASS (geary_imap_db_account_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
geary_imap_db_account_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapDBAccountClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_db_account_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapDBAccount), 0, (GInstanceInitFunc) geary_imap_db_account_instance_init, NULL };
	GType geary_imap_db_account_type_id;
	geary_imap_db_account_type_id = g_type_register_static (GEARY_TYPE_BASE_OBJECT, "GearyImapDBAccount", &g_define_type_info, 0);
	GearyImapDBAccount_private_offset = g_type_add_instance_private (geary_imap_db_account_type_id, sizeof (GearyImapDBAccountPrivate));
	return geary_imap_db_account_type_id;
}

GType
geary_imap_db_account_get_type (void)
{
	static gsize geary_imap_db_account_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_db_account_type_id__once)) {
		GType geary_imap_db_account_type_id;
		geary_imap_db_account_type_id = geary_imap_db_account_get_type_once ();
		g_once_init_leave (&geary_imap_db_account_type_id__once, geary_imap_db_account_type_id);
	}
	return geary_imap_db_account_type_id__once;
}

static void
_vala_geary_imap_db_account_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec)
{
	GearyImapDBAccount * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_DB_TYPE_ACCOUNT, GearyImapDBAccount);
	switch (property_id) {
		case GEARY_IMAP_DB_ACCOUNT_IMAP_FOLDER_ROOT_PROPERTY:
		g_value_set_object (value, geary_imap_db_account_get_imap_folder_root (self));
		break;
		case GEARY_IMAP_DB_ACCOUNT_UPGRADE_MONITOR_PROPERTY:
		g_value_set_object (value, geary_imap_db_account_get_upgrade_monitor (self));
		break;
		case GEARY_IMAP_DB_ACCOUNT_VACUUM_MONITOR_PROPERTY:
		g_value_set_object (value, geary_imap_db_account_get_vacuum_monitor (self));
		break;
		case GEARY_IMAP_DB_ACCOUNT_DB_PROPERTY:
		g_value_set_object (value, geary_imap_db_account_get_db (self));
		break;
		case GEARY_IMAP_DB_ACCOUNT_ACCOUNT_INFORMATION_PROPERTY:
		g_value_set_object (value, geary_imap_db_account_get_account_information (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_geary_imap_db_account_set_property (GObject * object,
                                          guint property_id,
                                          const GValue * value,
                                          GParamSpec * pspec)
{
	GearyImapDBAccount * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_DB_TYPE_ACCOUNT, GearyImapDBAccount);
	switch (property_id) {
		case GEARY_IMAP_DB_ACCOUNT_IMAP_FOLDER_ROOT_PROPERTY:
		geary_imap_db_account_set_imap_folder_root (self, g_value_get_object (value));
		break;
		case GEARY_IMAP_DB_ACCOUNT_UPGRADE_MONITOR_PROPERTY:
		geary_imap_db_account_set_upgrade_monitor (self, g_value_get_object (value));
		break;
		case GEARY_IMAP_DB_ACCOUNT_VACUUM_MONITOR_PROPERTY:
		geary_imap_db_account_set_vacuum_monitor (self, g_value_get_object (value));
		break;
		case GEARY_IMAP_DB_ACCOUNT_DB_PROPERTY:
		geary_imap_db_account_set_db (self, g_value_get_object (value));
		break;
		case GEARY_IMAP_DB_ACCOUNT_ACCOUNT_INFORMATION_PROPERTY:
		geary_imap_db_account_set_account_information (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

