/* outbox-folder.c generated by valac 0.56.3, the Vala compiler
 * generated from outbox-folder.vala, do not modify */

/*
 * Copyright 2016 Software Freedom Conservancy Inc.
 * Copyright 2017-2018 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 <glib.h>
#include <gio/gio.h>
#include <gee.h>
#include <stdlib.h>
#include <string.h>
#include <gobject/gvaluecollector.h>

#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;

#define GEARY_OUTBOX_TYPE_FOLDER_PROPERTIES (geary_outbox_folder_properties_get_type ())
#define GEARY_OUTBOX_FOLDER_PROPERTIES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_OUTBOX_TYPE_FOLDER_PROPERTIES, GearyOutboxFolderProperties))
#define GEARY_OUTBOX_FOLDER_PROPERTIES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_OUTBOX_TYPE_FOLDER_PROPERTIES, GearyOutboxFolderPropertiesClass))
#define GEARY_OUTBOX_IS_FOLDER_PROPERTIES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_OUTBOX_TYPE_FOLDER_PROPERTIES))
#define GEARY_OUTBOX_IS_FOLDER_PROPERTIES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_OUTBOX_TYPE_FOLDER_PROPERTIES))
#define GEARY_OUTBOX_FOLDER_PROPERTIES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_OUTBOX_TYPE_FOLDER_PROPERTIES, GearyOutboxFolderPropertiesClass))

typedef struct _GearyOutboxFolderProperties GearyOutboxFolderProperties;
typedef struct _GearyOutboxFolderPropertiesClass GearyOutboxFolderPropertiesClass;
enum  {
	GEARY_OUTBOX_FOLDER_0_PROPERTY,
	GEARY_OUTBOX_FOLDER_ACCOUNT_PROPERTY,
	GEARY_OUTBOX_FOLDER_PROPERTIES_PROPERTY,
	GEARY_OUTBOX_FOLDER_PATH_PROPERTY,
	GEARY_OUTBOX_FOLDER_USED_AS_PROPERTY,
	GEARY_OUTBOX_FOLDER_NUM_PROPERTIES
};
static GParamSpec* geary_outbox_folder_properties[GEARY_OUTBOX_FOLDER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#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;
typedef struct _GearyOutboxFolderOpenAsyncData GearyOutboxFolderOpenAsyncData;
typedef struct _GearyOutboxFolderCloseAsyncData GearyOutboxFolderCloseAsyncData;
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))

#define GEARY_OUTBOX_FOLDER_TYPE_OUTBOX_ROW (geary_outbox_folder_outbox_row_get_type ())
#define GEARY_OUTBOX_FOLDER_OUTBOX_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_OUTBOX_FOLDER_TYPE_OUTBOX_ROW, GearyOutboxFolderOutboxRow))
#define GEARY_OUTBOX_FOLDER_OUTBOX_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_OUTBOX_FOLDER_TYPE_OUTBOX_ROW, GearyOutboxFolderOutboxRowClass))
#define GEARY_OUTBOX_FOLDER_IS_OUTBOX_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_OUTBOX_FOLDER_TYPE_OUTBOX_ROW))
#define GEARY_OUTBOX_FOLDER_IS_OUTBOX_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_OUTBOX_FOLDER_TYPE_OUTBOX_ROW))
#define GEARY_OUTBOX_FOLDER_OUTBOX_ROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_OUTBOX_FOLDER_TYPE_OUTBOX_ROW, GearyOutboxFolderOutboxRowClass))

typedef struct _GearyOutboxFolderOutboxRow GearyOutboxFolderOutboxRow;
typedef struct _GearyOutboxFolderOutboxRowClass GearyOutboxFolderOutboxRowClass;
typedef struct _Block104Data Block104Data;
#define _geary_outbox_folder_outbox_row_unref0(var) ((var == NULL) ? NULL : (var = (geary_outbox_folder_outbox_row_unref (var), NULL)))

#define GEARY_OUTBOX_TYPE_EMAIL_IDENTIFIER (geary_outbox_email_identifier_get_type ())
#define GEARY_OUTBOX_EMAIL_IDENTIFIER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_OUTBOX_TYPE_EMAIL_IDENTIFIER, GearyOutboxEmailIdentifier))
#define GEARY_OUTBOX_EMAIL_IDENTIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_OUTBOX_TYPE_EMAIL_IDENTIFIER, GearyOutboxEmailIdentifierClass))
#define GEARY_OUTBOX_IS_EMAIL_IDENTIFIER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_OUTBOX_TYPE_EMAIL_IDENTIFIER))
#define GEARY_OUTBOX_IS_EMAIL_IDENTIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_OUTBOX_TYPE_EMAIL_IDENTIFIER))
#define GEARY_OUTBOX_EMAIL_IDENTIFIER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_OUTBOX_TYPE_EMAIL_IDENTIFIER, GearyOutboxEmailIdentifierClass))

typedef struct _GearyOutboxEmailIdentifier GearyOutboxEmailIdentifier;
typedef struct _GearyOutboxEmailIdentifierClass GearyOutboxEmailIdentifierClass;
typedef struct _GearyOutboxFolderOutboxRowPrivate GearyOutboxFolderOutboxRowPrivate;
typedef struct _GearyOutboxFolderCreateEmailAsyncData GearyOutboxFolderCreateEmailAsyncData;
typedef struct _Block105Data Block105Data;
typedef struct _Block106Data Block106Data;
typedef struct _GearyOutboxFolderMarkEmailAsyncData GearyOutboxFolderMarkEmailAsyncData;
typedef struct _Block107Data Block107Data;
typedef struct _GearyOutboxFolderRemoveEmailAsyncData GearyOutboxFolderRemoveEmailAsyncData;
typedef struct _Block108Data Block108Data;
typedef struct _GearyOutboxFolderContainsIdentifiersData GearyOutboxFolderContainsIdentifiersData;
typedef struct _Block109Data Block109Data;
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _GearyOutboxFolderListEmailByIdAsyncData GearyOutboxFolderListEmailByIdAsyncData;
typedef struct _Block110Data Block110Data;
typedef struct _GearyOutboxFolderListEmailBySparseIdAsyncData GearyOutboxFolderListEmailBySparseIdAsyncData;
typedef struct _Block111Data Block111Data;
typedef struct _GearyOutboxFolderFetchEmailAsyncData GearyOutboxFolderFetchEmailAsyncData;

#define GEARY_OUTBOX_TYPE_EMAIL_PROPERTIES (geary_outbox_email_properties_get_type ())
#define GEARY_OUTBOX_EMAIL_PROPERTIES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_OUTBOX_TYPE_EMAIL_PROPERTIES, GearyOutboxEmailProperties))
#define GEARY_OUTBOX_EMAIL_PROPERTIES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_OUTBOX_TYPE_EMAIL_PROPERTIES, GearyOutboxEmailPropertiesClass))
#define GEARY_OUTBOX_IS_EMAIL_PROPERTIES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_OUTBOX_TYPE_EMAIL_PROPERTIES))
#define GEARY_OUTBOX_IS_EMAIL_PROPERTIES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_OUTBOX_TYPE_EMAIL_PROPERTIES))
#define GEARY_OUTBOX_EMAIL_PROPERTIES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_OUTBOX_TYPE_EMAIL_PROPERTIES, GearyOutboxEmailPropertiesClass))

typedef struct _GearyOutboxEmailProperties GearyOutboxEmailProperties;
typedef struct _GearyOutboxEmailPropertiesClass GearyOutboxEmailPropertiesClass;
typedef struct _Block112Data Block112Data;
typedef struct _GearyOutboxFolderGetEmailCountAsyncData GearyOutboxFolderGetEmailCountAsyncData;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _GearyOutboxFolderParamSpecOutboxRow GearyOutboxFolderParamSpecOutboxRow;
#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 _GearyOutboxFolderPrivate {
	GearyFolderPath* _path;
	GearyAccount* _account;
	GearyImapDBAccount* local;
	GearyDbDatabase* db;
	GearyOutboxFolderProperties* _properties;
	gint64 next_ordering;
	GRecMutex __lock_next_ordering;
};

struct _GearyOutboxFolderOpenAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyOutboxFolder* self;
	GearyFolderOpenFlags open_flags;
	GCancellable* cancellable;
	gboolean result;
	gboolean opened;
	GearyImapDBAccount* _tmp0_;
	GearyImapDBDatabase* _tmp1_;
	GearyImapDBDatabase* _tmp2_;
	GearyDbDatabase* _tmp3_;
	GError* _inner_error0_;
};

struct _GearyOutboxFolderCloseAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyOutboxFolder* self;
	GCancellable* cancellable;
	gboolean result;
	gboolean closed;
	GError* _inner_error0_;
};

struct _Block104Data {
	int _ref_count_;
	GearyOutboxFolder* self;
	gint email_count;
	GearyOutboxFolderOutboxRow* row;
	GearyRFC822Message* rfc822;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyOutboxFolderOutboxRow {
	GTypeInstance parent_instance;
	volatile int ref_count;
	gint64 id;
	gint position;
	gint64 ordering;
	gboolean sent;
	GearyMemoryBuffer* message;
	GearyOutboxEmailIdentifier* outbox_id;
	GearyOutboxFolderOutboxRowPrivate * priv;
};

struct _GearyOutboxFolderOutboxRowClass {
	GTypeClass parent_class;
	void (*finalize) (GearyOutboxFolderOutboxRow *self);
};

struct _GearyOutboxFolderCreateEmailAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyOutboxFolder* self;
	GearyRFC822Message* rfc822;
	GearyEmailFlags* flags;
	GDateTime* date_received;
	GCancellable* cancellable;
	GearyEmailIdentifier* result;
	Block104Data* _data104_;
	GearyDbDatabase* _tmp0_;
	gint _tmp1_;
	GearyOutboxFolderProperties* _tmp2_;
	GeeList* list;
	GeeArrayList* _tmp3_;
	GeeList* _tmp4_;
	GearyOutboxFolderOutboxRow* _tmp5_;
	GearyOutboxEmailIdentifier* _tmp6_;
	GeeList* _tmp7_;
	GeeList* _tmp8_;
	GearyOutboxFolderOutboxRow* _tmp9_;
	GearyOutboxEmailIdentifier* _tmp10_;
	GearyEmailIdentifier* _tmp11_;
	GError* _inner_error0_;
};

struct _Block105Data {
	int _ref_count_;
	GearyOutboxFolder* self;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _Block106Data {
	int _ref_count_;
	Block105Data * _data105_;
	GearyOutboxEmailIdentifier* outbox_id;
};

struct _GearyOutboxFolderMarkEmailAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyOutboxFolder* self;
	GeeCollection* to_mark;
	GearyEmailFlags* flags_to_add;
	GearyEmailFlags* flags_to_remove;
	GCancellable* cancellable;
	Block105Data* _data105_;
	GeeMap* changed;
	GeeHashMap* _tmp0_;
	GeeIterator* _id_it;
	GeeIterator* _tmp1_;
	Block106Data* _data106_;
	GeeIterator* _tmp2_;
	GearyEmailIdentifier* id;
	GeeIterator* _tmp3_;
	gpointer _tmp4_;
	GearyEmailIdentifier* _tmp5_;
	GearyOutboxEmailIdentifier* _tmp6_;
	GearyOutboxEmailIdentifier* _tmp7_;
	GearyDbDatabase* _tmp8_;
	GeeMap* _tmp9_;
	GearyEmailIdentifier* _tmp10_;
	GeeMap* _tmp11_;
	GError* _inner_error0_;
};

struct _Block107Data {
	int _ref_count_;
	GearyOutboxFolder* self;
	GeeList* removed;
	gint final_count;
	GeeCollection* email_ids;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyOutboxFolderRemoveEmailAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyOutboxFolder* self;
	GeeCollection* email_ids;
	GCancellable* cancellable;
	Block107Data* _data107_;
	GeeArrayList* _tmp0_;
	GearyDbDatabase* _tmp1_;
	GeeList* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	GearyOutboxFolderProperties* _tmp5_;
	GeeList* _tmp6_;
	GError* _inner_error0_;
};

struct _Block108Data {
	int _ref_count_;
	GearyOutboxFolder* self;
	GeeHashSet* contains;
	GeeCollection* ids;
	gpointer _async_data_;
};

struct _GearyOutboxFolderContainsIdentifiersData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyOutboxFolder* self;
	GeeCollection* ids;
	GCancellable* cancellable;
	GeeCollection* result;
	Block108Data* _data108_;
	GeeHashSet* _tmp0_;
	GearyDbDatabase* _tmp1_;
	GeeHashSet* _tmp2_;
	GeeCollection* _tmp3_;
	GError* _inner_error0_;
};

struct _Block109Data {
	int _ref_count_;
	GearyOutboxFolder* self;
	GearyOutboxEmailIdentifier* initial_id;
	gboolean list_all;
	gchar* select;
	GeeList* list;
	gint count;
	GearyFolderListFlags flags;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyOutboxFolderListEmailByIdAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyOutboxFolder* self;
	GearyEmailIdentifier* _initial_id;
	gint count;
	GearyEmailField required_fields;
	GearyFolderListFlags flags;
	GCancellable* cancellable;
	GeeList* result;
	Block109Data* _data109_;
	GearyOutboxEmailIdentifier* _tmp0_;
	gboolean _tmp1_;
	GearyOutboxEmailIdentifier* _tmp2_;
	GearyOutboxEmailIdentifier* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GError* _tmp6_;
	GError* _tmp7_;
	gchar* _tmp8_;
	const gchar* _tmp9_;
	gchar* _tmp10_;
	GearyDbDatabase* _tmp11_;
	GeeList* _tmp12_;
	GeeList* _tmp13_;
	GError* _inner_error0_;
};

struct _Block110Data {
	int _ref_count_;
	GearyOutboxFolder* self;
	GeeList* list;
	GeeCollection* ids;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyOutboxFolderListEmailBySparseIdAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyOutboxFolder* self;
	GeeCollection* ids;
	GearyEmailField required_fields;
	GearyFolderListFlags flags;
	GCancellable* cancellable;
	GeeList* result;
	Block110Data* _data110_;
	GeeArrayList* _tmp0_;
	GearyDbDatabase* _tmp1_;
	GeeList* _tmp2_;
	GeeList* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	GeeList* _tmp6_;
	GeeList* _tmp7_;
	GError* _inner_error0_;
};

struct _Block111Data {
	int _ref_count_;
	GearyOutboxFolder* self;
	GearyOutboxEmailIdentifier* outbox_id;
	GearyOutboxFolderOutboxRow* row;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyOutboxFolderFetchEmailAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyOutboxFolder* self;
	GearyEmailIdentifier* id;
	GearyEmailField required_fields;
	GearyFolderListFlags flags;
	GCancellable* cancellable;
	GearyEmail* result;
	Block111Data* _data111_;
	GearyOutboxEmailIdentifier* _tmp0_;
	GearyOutboxEmailIdentifier* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	GError* _tmp4_;
	GError* _tmp5_;
	GearyDbDatabase* _tmp6_;
	GearyOutboxFolderOutboxRow* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	GError* _tmp10_;
	GError* _tmp11_;
	GearyEmail* _tmp12_;
	GearyOutboxFolderOutboxRow* _tmp13_;
	GearyEmail* _tmp14_;
	GearyEmail* _tmp15_;
	GError* _inner_error0_;
};

struct _Block112Data {
	int _ref_count_;
	GearyOutboxFolder* self;
	gint count;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyOutboxFolderGetEmailCountAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyOutboxFolder* self;
	GCancellable* cancellable;
	gint result;
	Block112Data* _data112_;
	GearyDbDatabase* _tmp0_;
	GError* _inner_error0_;
};

struct _GearyOutboxFolderParamSpecOutboxRow {
	GParamSpec parent_instance;
};

static gint GearyOutboxFolder_private_offset;
static gpointer geary_outbox_folder_parent_class = NULL;
static gpointer geary_outbox_folder_outbox_row_parent_class = NULL;
static GearyFolderSupportCreateIface * geary_outbox_folder_geary_folder_support_create_parent_iface = NULL;
static GearyFolderSupportMarkIface * geary_outbox_folder_geary_folder_support_mark_parent_iface = NULL;
static GearyFolderSupportRemoveIface * geary_outbox_folder_geary_folder_support_remove_parent_iface = NULL;

VALA_EXTERN GType geary_imap_db_account_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_outbox_folder_properties_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GearyOutboxFolderProperties* geary_outbox_folder_properties_new (gint total,
                                                                 gint unread);
VALA_EXTERN GearyOutboxFolderProperties* geary_outbox_folder_properties_construct (GType object_type,
                                                                       gint total,
                                                                       gint unread);
VALA_EXTERN GearyOutboxFolder* geary_outbox_folder_new (GearyAccount* account,
                                            GearyFolderRoot* root,
                                            GearyImapDBAccount* local);
VALA_EXTERN GearyOutboxFolder* geary_outbox_folder_construct (GType object_type,
                                                  GearyAccount* account,
                                                  GearyFolderRoot* root,
                                                  GearyImapDBAccount* local);
static void geary_outbox_folder_real_open_async_data_free (gpointer _data);
static void geary_outbox_folder_real_open_async (GearyFolder* base,
                                          GearyFolderOpenFlags open_flags,
                                          GCancellable* cancellable,
                                          GAsyncReadyCallback _callback_,
                                          gpointer _user_data_);
static gboolean geary_outbox_folder_real_open_async_co (GearyOutboxFolderOpenAsyncData* _data_);
static void geary_outbox_folder_open_async_ready (GObject* source_object,
                                           GAsyncResult* _res_,
                                           gpointer _user_data_);
VALA_EXTERN GType geary_imap_db_database_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GearyImapDBDatabase* geary_imap_db_account_get_db (GearyImapDBAccount* self);
static void geary_outbox_folder_real_close_async_data_free (gpointer _data);
static void geary_outbox_folder_real_close_async (GearyFolder* base,
                                           GCancellable* cancellable,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_);
static gboolean geary_outbox_folder_real_close_async_co (GearyOutboxFolderCloseAsyncData* _data_);
static void geary_outbox_folder_close_async_ready (GObject* source_object,
                                            GAsyncResult* _res_,
                                            gpointer _user_data_);
static void geary_outbox_folder_real_create_email_async_data_free (gpointer _data);
static void geary_outbox_folder_real_create_email_async (GearyOutboxFolder* self,
                                                  GearyRFC822Message* rfc822,
                                                  GearyEmailFlags* flags,
                                                  GDateTime* date_received,
                                                  GCancellable* cancellable,
                                                  GAsyncReadyCallback _callback_,
                                                  gpointer _user_data_);
static gboolean geary_outbox_folder_real_create_email_async_co (GearyOutboxFolderCreateEmailAsyncData* _data_);
static gpointer geary_outbox_folder_outbox_row_ref (gpointer instance);
static void geary_outbox_folder_outbox_row_unref (gpointer instance);
static GParamSpec* geary_outbox_folder_param_spec_outbox_row (const gchar* name,
                                                       const gchar* nick,
                                                       const gchar* blurb,
                                                       GType object_type,
                                                       GParamFlags flags) G_GNUC_UNUSED ;
static void geary_outbox_folder_value_set_outbox_row (GValue* value,
                                               gpointer v_object) G_GNUC_UNUSED ;
static void geary_outbox_folder_value_take_outbox_row (GValue* value,
                                                gpointer v_object) G_GNUC_UNUSED ;
static gpointer geary_outbox_folder_value_get_outbox_row (const GValue* value) G_GNUC_UNUSED ;
static GType geary_outbox_folder_outbox_row_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static Block104Data* block104_data_ref (Block104Data* _data104_);
static void block104_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda117_ (Block104Data* _data104_,
                                        GearyDbConnection* cx,
                                        GError** error);
static gint64 geary_outbox_folder_do_get_next_ordering (GearyOutboxFolder* self,
                                                 GearyDbConnection* cx,
                                                 GCancellable* cancellable,
                                                 GError** error);
static gint geary_outbox_folder_do_get_position_by_ordering (GearyOutboxFolder* self,
                                                      GearyDbConnection* cx,
                                                      gint64 ordering,
                                                      GCancellable* cancellable,
                                                      GError** error);
static GearyOutboxFolderOutboxRow* geary_outbox_folder_outbox_row_new (gint64 id,
                                                                gint position,
                                                                gint64 ordering,
                                                                gboolean sent,
                                                                GearyMemoryBuffer* message);
static GearyOutboxFolderOutboxRow* geary_outbox_folder_outbox_row_construct (GType object_type,
                                                                      gint64 id,
                                                                      gint position,
                                                                      gint64 ordering,
                                                                      gboolean sent,
                                                                      GearyMemoryBuffer* message);
static gint geary_outbox_folder_do_get_email_count (GearyOutboxFolder* self,
                                             GearyDbConnection* cx,
                                             GCancellable* cancellable,
                                             GError** error);
static GearyDbTransactionOutcome ___lambda117__geary_db_transaction_method (GearyDbConnection* cx,
                                                                     GCancellable* cancellable,
                                                                     gpointer self,
                                                                     GError** error);
static void geary_outbox_folder_create_email_async_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_);
static void geary_outbox_folder_get_email_count_async (GearyOutboxFolder* self,
                                                GCancellable* cancellable,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_);
static gint geary_outbox_folder_get_email_count_finish (GearyOutboxFolder* self,
                                                 GAsyncResult* _res_,
                                                 GError** error);
VALA_EXTERN void geary_outbox_folder_properties_set_total (GearyOutboxFolderProperties* self,
                                               gint total);
VALA_EXTERN GType geary_outbox_email_identifier_get_type (void) G_GNUC_CONST ;
static void geary_outbox_folder_real_mark_email_async_data_free (gpointer _data);
static void geary_outbox_folder_real_mark_email_async (GearyOutboxFolder* self,
                                                GeeCollection* to_mark,
                                                GearyEmailFlags* flags_to_add,
                                                GearyEmailFlags* flags_to_remove,
                                                GCancellable* cancellable,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_);
static gboolean geary_outbox_folder_real_mark_email_async_co (GearyOutboxFolderMarkEmailAsyncData* _data_);
static Block105Data* block105_data_ref (Block105Data* _data105_);
static void block105_data_unref (void * _userdata_);
static Block106Data* block106_data_ref (Block106Data* _data106_);
static void block106_data_unref (void * _userdata_);
static GearyDbTransactionOutcome _____lambda119_ (Block106Data* _data106_,
                                           GearyDbConnection* cx,
                                           GError** error);
static void geary_outbox_folder_do_mark_email_as_sent (GearyOutboxFolder* self,
                                                GearyDbConnection* cx,
                                                GearyOutboxEmailIdentifier* id,
                                                GCancellable* cancellable,
                                                GError** error);
static GearyDbTransactionOutcome ______lambda119__geary_db_transaction_method (GearyDbConnection* cx,
                                                                        GCancellable* cancellable,
                                                                        gpointer self,
                                                                        GError** error);
static void geary_outbox_folder_mark_email_async_ready (GObject* source_object,
                                                 GAsyncResult* _res_,
                                                 gpointer _user_data_);
static void geary_outbox_folder_real_remove_email_async_data_free (gpointer _data);
static void geary_outbox_folder_real_remove_email_async (GearyOutboxFolder* self,
                                                  GeeCollection* email_ids,
                                                  GCancellable* cancellable,
                                                  GAsyncReadyCallback _callback_,
                                                  gpointer _user_data_);
static gboolean geary_outbox_folder_real_remove_email_async_co (GearyOutboxFolderRemoveEmailAsyncData* _data_);
static Block107Data* block107_data_ref (Block107Data* _data107_);
static void block107_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda120_ (Block107Data* _data107_,
                                        GearyDbConnection* cx,
                                        GError** error);
static gboolean geary_outbox_folder_do_remove_email (GearyOutboxFolder* self,
                                              GearyDbConnection* cx,
                                              GearyOutboxEmailIdentifier* id,
                                              GCancellable* cancellable,
                                              GError** error);
static GearyDbTransactionOutcome ___lambda120__geary_db_transaction_method (GearyDbConnection* cx,
                                                                     GCancellable* cancellable,
                                                                     gpointer self,
                                                                     GError** error);
static void geary_outbox_folder_remove_email_async_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_);
static void geary_outbox_folder_real_contains_identifiers_data_free (gpointer _data);
static void geary_outbox_folder_real_contains_identifiers (GearyFolder* base,
                                                    GeeCollection* ids,
                                                    GCancellable* cancellable,
                                                    GAsyncReadyCallback _callback_,
                                                    gpointer _user_data_);
static gboolean geary_outbox_folder_real_contains_identifiers_co (GearyOutboxFolderContainsIdentifiersData* _data_);
static Block108Data* block108_data_ref (Block108Data* _data108_);
static void block108_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda121_ (Block108Data* _data108_,
                                        GearyDbConnection* cx,
                                        GCancellable* cancellable,
                                        GError** error);
static GearyOutboxFolderOutboxRow* geary_outbox_folder_do_fetch_row_by_ordering (GearyOutboxFolder* self,
                                                                          GearyDbConnection* cx,
                                                                          gint64 ordering,
                                                                          GCancellable* cancellable,
                                                                          GError** error);
VALA_EXTERN gint64 geary_outbox_email_identifier_get_ordering (GearyOutboxEmailIdentifier* self);
static GearyDbTransactionOutcome ___lambda121__geary_db_transaction_method (GearyDbConnection* cx,
                                                                     GCancellable* cancellable,
                                                                     gpointer self,
                                                                     GError** error);
static void geary_outbox_folder_contains_identifiers_ready (GObject* source_object,
                                                     GAsyncResult* _res_,
                                                     gpointer _user_data_);
static void geary_outbox_folder_real_list_email_by_id_async_data_free (gpointer _data);
static void geary_outbox_folder_real_list_email_by_id_async (GearyFolder* base,
                                                      GearyEmailIdentifier* _initial_id,
                                                      gint count,
                                                      GearyEmailField required_fields,
                                                      GearyFolderListFlags flags,
                                                      GCancellable* cancellable,
                                                      GAsyncReadyCallback _callback_,
                                                      gpointer _user_data_);
static gboolean geary_outbox_folder_real_list_email_by_id_async_co (GearyOutboxFolderListEmailByIdAsyncData* _data_);
static Block109Data* block109_data_ref (Block109Data* _data109_);
static void block109_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda122_ (Block109Data* _data109_,
                                        GearyDbConnection* cx,
                                        GError** error);
static GearyEmail* geary_outbox_folder_row_to_email (GearyOutboxFolder* self,
                                              GearyOutboxFolderOutboxRow* row,
                                              GError** error);
static GearyDbTransactionOutcome ___lambda122__geary_db_transaction_method (GearyDbConnection* cx,
                                                                     GCancellable* cancellable,
                                                                     gpointer self,
                                                                     GError** error);
static void geary_outbox_folder_list_email_by_id_async_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_);
static void geary_outbox_folder_real_list_email_by_sparse_id_async_data_free (gpointer _data);
static void geary_outbox_folder_real_list_email_by_sparse_id_async (GearyFolder* base,
                                                             GeeCollection* ids,
                                                             GearyEmailField required_fields,
                                                             GearyFolderListFlags flags,
                                                             GCancellable* cancellable,
                                                             GAsyncReadyCallback _callback_,
                                                             gpointer _user_data_);
static gboolean geary_outbox_folder_real_list_email_by_sparse_id_async_co (GearyOutboxFolderListEmailBySparseIdAsyncData* _data_);
static Block110Data* block110_data_ref (Block110Data* _data110_);
static void block110_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda123_ (Block110Data* _data110_,
                                        GearyDbConnection* cx,
                                        GError** error);
static GearyDbTransactionOutcome ___lambda123__geary_db_transaction_method (GearyDbConnection* cx,
                                                                     GCancellable* cancellable,
                                                                     gpointer self,
                                                                     GError** error);
static void geary_outbox_folder_list_email_by_sparse_id_async_ready (GObject* source_object,
                                                              GAsyncResult* _res_,
                                                              gpointer _user_data_);
static void geary_outbox_folder_real_fetch_email_async_data_free (gpointer _data);
static void geary_outbox_folder_real_fetch_email_async (GearyFolder* base,
                                                 GearyEmailIdentifier* id,
                                                 GearyEmailField required_fields,
                                                 GearyFolderListFlags flags,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
static gboolean geary_outbox_folder_real_fetch_email_async_co (GearyOutboxFolderFetchEmailAsyncData* _data_);
static Block111Data* block111_data_ref (Block111Data* _data111_);
static void block111_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda124_ (Block111Data* _data111_,
                                        GearyDbConnection* cx,
                                        GError** error);
static GearyDbTransactionOutcome ___lambda124__geary_db_transaction_method (GearyDbConnection* cx,
                                                                     GCancellable* cancellable,
                                                                     gpointer self,
                                                                     GError** error);
static void geary_outbox_folder_fetch_email_async_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_);
static void geary_outbox_folder_real_set_used_as_custom (GearyFolder* base,
                                                  gboolean enabled,
                                                  GError** error);
VALA_EXTERN GearyOutboxEmailProperties* geary_outbox_email_properties_new (GDateTime* date_received,
                                                               glong total_bytes);
VALA_EXTERN GearyOutboxEmailProperties* geary_outbox_email_properties_construct (GType object_type,
                                                                     GDateTime* date_received,
                                                                     glong total_bytes);
VALA_EXTERN GType geary_outbox_email_properties_get_type (void) G_GNUC_CONST ;
static void geary_outbox_folder_get_email_count_async_data_free (gpointer _data);
static gboolean geary_outbox_folder_get_email_count_async_co (GearyOutboxFolderGetEmailCountAsyncData* _data_);
static Block112Data* block112_data_ref (Block112Data* _data112_);
static void block112_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda118_ (Block112Data* _data112_,
                                        GearyDbConnection* cx,
                                        GError** error);
static GearyDbTransactionOutcome ___lambda118__geary_db_transaction_method (GearyDbConnection* cx,
                                                                     GCancellable* cancellable,
                                                                     gpointer self,
                                                                     GError** error);
static void geary_outbox_folder_get_email_count_async_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_);
VALA_EXTERN GearyOutboxEmailIdentifier* geary_outbox_email_identifier_new (gint64 message_id,
                                                               gint64 ordering);
VALA_EXTERN GearyOutboxEmailIdentifier* geary_outbox_email_identifier_construct (GType object_type,
                                                                     gint64 message_id,
                                                                     gint64 ordering);
static void geary_outbox_folder_outbox_row_finalize (GearyOutboxFolderOutboxRow * obj);
static GType geary_outbox_folder_outbox_row_get_type_once (void);
static void geary_outbox_folder_finalize (GObject * obj);
static GType geary_outbox_folder_get_type_once (void);
static void _vala_geary_outbox_folder_get_property (GObject * object,
                                             guint property_id,
                                             GValue * value,
                                             GParamSpec * pspec);

static inline gpointer
geary_outbox_folder_get_instance_private (GearyOutboxFolder* self)
{
	return G_STRUCT_MEMBER_P (self, GearyOutboxFolder_private_offset);
}

static GearyAccount*
geary_outbox_folder_real_get_account (GearyFolder* base)
{
	GearyAccount* result;
	GearyOutboxFolder* self;
	GearyAccount* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_OUTBOX_TYPE_FOLDER, GearyOutboxFolder);
	_tmp0_ = self->priv->_account;
	result = _tmp0_;
	return result;
}

static GearyFolderProperties*
geary_outbox_folder_real_get_properties (GearyFolder* base)
{
	GearyFolderProperties* result;
	GearyOutboxFolder* self;
	GearyOutboxFolderProperties* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_OUTBOX_TYPE_FOLDER, GearyOutboxFolder);
	_tmp0_ = self->priv->_properties;
	result = G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEARY_TYPE_FOLDER_PROPERTIES, GearyFolderProperties);
	return result;
}

static GearyFolderPath*
geary_outbox_folder_real_get_path (GearyFolder* base)
{
	GearyFolderPath* result;
	GearyOutboxFolder* self;
	GearyFolderPath* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_OUTBOX_TYPE_FOLDER, GearyOutboxFolder);
	_tmp0_ = self->priv->_path;
	result = _tmp0_;
	return result;
}

static GearyFolderSpecialUse
geary_outbox_folder_real_get_used_as (GearyFolder* base)
{
	GearyFolderSpecialUse result;
	GearyOutboxFolder* self;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_OUTBOX_TYPE_FOLDER, GearyOutboxFolder);
	result = GEARY_FOLDER_SPECIAL_USE_OUTBOX;
	return result;
}

GearyOutboxFolder*
geary_outbox_folder_construct (GType object_type,
                               GearyAccount* account,
                               GearyFolderRoot* root,
                               GearyImapDBAccount* local)
{
	GearyOutboxFolder * self = NULL;
	GearyFolderPath* _tmp0_;
	g_return_val_if_fail (GEARY_IS_ACCOUNT (account), NULL);
	g_return_val_if_fail (GEARY_IS_FOLDER_ROOT (root), NULL);
	g_return_val_if_fail (GEARY_IMAP_DB_IS_ACCOUNT (local), NULL);
	self = (GearyOutboxFolder*) geary_abstract_local_folder_construct (object_type);
	self->priv->_account = account;
	_tmp0_ = geary_folder_path_get_child (G_TYPE_CHECK_INSTANCE_CAST (root, GEARY_TYPE_FOLDER_PATH, GearyFolderPath), GEARY_OUTBOX_FOLDER_MAGIC_BASENAME, GEARY_TRILLIAN_TRUE);
	_g_object_unref0 (self->priv->_path);
	self->priv->_path = _tmp0_;
	self->priv->local = local;
	return self;
}

GearyOutboxFolder*
geary_outbox_folder_new (GearyAccount* account,
                         GearyFolderRoot* root,
                         GearyImapDBAccount* local)
{
	return geary_outbox_folder_construct (GEARY_OUTBOX_TYPE_FOLDER, account, root, local);
}

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

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

static void
geary_outbox_folder_real_open_async (GearyFolder* base,
                                     GearyFolderOpenFlags open_flags,
                                     GCancellable* cancellable,
                                     GAsyncReadyCallback _callback_,
                                     gpointer _user_data_)
{
	GearyOutboxFolder * self;
	GearyOutboxFolderOpenAsyncData* _data_;
	GearyOutboxFolder* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_OUTBOX_TYPE_FOLDER, GearyOutboxFolder);
	_data_ = g_slice_new0 (GearyOutboxFolderOpenAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_outbox_folder_real_open_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->open_flags = open_flags;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_outbox_folder_real_open_async_co (_data_);
}

static gboolean
geary_outbox_folder_open_finish (GearyFolder* base,
                                 GAsyncResult* _res_,
                                 GError** error)
{
	gboolean result;
	GearyOutboxFolderOpenAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		gboolean _tmp0_ = FALSE;
		return _tmp0_;
	}
	result = _data_->result;
	return result;
}

static void
geary_outbox_folder_open_async_ready (GObject* source_object,
                                      GAsyncResult* _res_,
                                      gpointer _user_data_)
{
	GearyOutboxFolderOpenAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_outbox_folder_real_open_async_co (_data_);
}

static gboolean
geary_outbox_folder_real_open_async_co (GearyOutboxFolderOpenAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_state_ = 1;
	GEARY_FOLDER_CLASS (geary_outbox_folder_parent_class)->open_async (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_ABSTRACT_LOCAL_FOLDER, GearyAbstractLocalFolder), GEARY_TYPE_FOLDER, GearyFolder), _data_->open_flags, _data_->cancellable, geary_outbox_folder_open_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->opened = GEARY_FOLDER_CLASS (geary_outbox_folder_parent_class)->open_finish (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_ABSTRACT_LOCAL_FOLDER, GearyAbstractLocalFolder), GEARY_TYPE_FOLDER, GearyFolder), _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_->opened) {
		_data_->_tmp0_ = _data_->self->priv->local;
		_data_->_tmp1_ = geary_imap_db_account_get_db (_data_->_tmp0_);
		_data_->_tmp2_ = _data_->_tmp1_;
		_data_->_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, GEARY_DB_TYPE_DATABASE, GearyDbDatabase));
		_g_object_unref0 (_data_->self->priv->db);
		_data_->self->priv->db = _data_->_tmp3_;
	}
	_data_->result = _data_->opened;
	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_outbox_folder_real_close_async_data_free (gpointer _data)
{
	GearyOutboxFolderCloseAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyOutboxFolderCloseAsyncData, _data_);
}

static void
geary_outbox_folder_real_close_async (GearyFolder* base,
                                      GCancellable* cancellable,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_)
{
	GearyOutboxFolder * self;
	GearyOutboxFolderCloseAsyncData* _data_;
	GearyOutboxFolder* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_OUTBOX_TYPE_FOLDER, GearyOutboxFolder);
	_data_ = g_slice_new0 (GearyOutboxFolderCloseAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_outbox_folder_real_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_outbox_folder_real_close_async_co (_data_);
}

static gboolean
geary_outbox_folder_close_finish (GearyFolder* base,
                                  GAsyncResult* _res_,
                                  GError** error)
{
	gboolean result;
	GearyOutboxFolderCloseAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		gboolean _tmp0_ = FALSE;
		return _tmp0_;
	}
	result = _data_->result;
	return result;
}

static void
geary_outbox_folder_close_async_ready (GObject* source_object,
                                       GAsyncResult* _res_,
                                       gpointer _user_data_)
{
	GearyOutboxFolderCloseAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_outbox_folder_real_close_async_co (_data_);
}

static gboolean
geary_outbox_folder_real_close_async_co (GearyOutboxFolderCloseAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_state_ = 1;
	GEARY_FOLDER_CLASS (geary_outbox_folder_parent_class)->close_async (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_ABSTRACT_LOCAL_FOLDER, GearyAbstractLocalFolder), GEARY_TYPE_FOLDER, GearyFolder), _data_->cancellable, geary_outbox_folder_close_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->closed = GEARY_FOLDER_CLASS (geary_outbox_folder_parent_class)->close_finish (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_ABSTRACT_LOCAL_FOLDER, GearyAbstractLocalFolder), GEARY_TYPE_FOLDER, GearyFolder), _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_->closed) {
		_g_object_unref0 (_data_->self->priv->db);
		_data_->self->priv->db = NULL;
	}
	_data_->result = _data_->closed;
	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_outbox_folder_real_create_email_async_data_free (gpointer _data)
{
	GearyOutboxFolderCreateEmailAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->flags);
	_g_date_time_unref0 (_data_->date_received);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyOutboxFolderCreateEmailAsyncData, _data_);
}

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

static void
geary_outbox_folder_real_create_email_async (GearyOutboxFolder* self,
                                             GearyRFC822Message* rfc822,
                                             GearyEmailFlags* flags,
                                             GDateTime* date_received,
                                             GCancellable* cancellable,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_)
{
	GearyOutboxFolderCreateEmailAsyncData* _data_;
	GearyOutboxFolder* _tmp0_;
	GearyRFC822Message* _tmp1_;
	GearyEmailFlags* _tmp2_;
	GDateTime* _tmp3_;
	GCancellable* _tmp4_;
	g_return_if_fail (GEARY_RF_C822_IS_MESSAGE (rfc822));
	g_return_if_fail ((flags == NULL) || GEARY_IS_EMAIL_FLAGS (flags));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyOutboxFolderCreateEmailAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_outbox_folder_real_create_email_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (rfc822);
	_g_object_unref0 (_data_->rfc822);
	_data_->rfc822 = _tmp1_;
	_tmp2_ = _g_object_ref0 (flags);
	_g_object_unref0 (_data_->flags);
	_data_->flags = _tmp2_;
	_tmp3_ = _g_date_time_ref0 (date_received);
	_g_date_time_unref0 (_data_->date_received);
	_data_->date_received = _tmp3_;
	_tmp4_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp4_;
	geary_outbox_folder_real_create_email_async_co (_data_);
}

static GearyEmailIdentifier*
geary_outbox_folder_real_create_email_finish (GearyOutboxFolder* self,
                                              GAsyncResult* _res_,
                                              GError** error)
{
	GearyEmailIdentifier* result;
	GearyOutboxFolderCreateEmailAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block104Data*
block104_data_ref (Block104Data* _data104_)
{
	g_atomic_int_inc (&_data104_->_ref_count_);
	return _data104_;
}

static void
block104_data_unref (void * _userdata_)
{
	Block104Data* _data104_;
	_data104_ = (Block104Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data104_->_ref_count_)) {
		GearyOutboxFolder* self;
		self = _data104_->self;
		_geary_outbox_folder_outbox_row_unref0 (_data104_->row);
		_g_object_unref0 (_data104_->rfc822);
		_g_object_unref0 (_data104_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block104Data, _data104_);
	}
}

static GearyDbTransactionOutcome
__lambda117_ (Block104Data* _data104_,
              GearyDbConnection* cx,
              GError** error)
{
	GearyOutboxFolder* self;
	gint64 ordering = 0LL;
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyMemoryBuffer* _tmp1_ = NULL;
	GearyMemoryBuffer* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbStatement* _tmp5_;
	GearyDbStatement* _tmp6_;
	GearyDbStatement* _tmp7_;
	GearyDbStatement* _tmp8_;
	gint64 new_id = 0LL;
	GearyDbStatement* _tmp9_;
	gint position = 0;
	GearyOutboxFolderOutboxRow* _tmp10_;
	gint _tmp11_ = 0;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data104_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	ordering = geary_outbox_folder_do_get_next_ordering (self, cx, _data104_->cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp0_ = geary_db_connection_prepare (cx, "INSERT INTO SmtpOutboxTable (message, ordering) VALUES (?, ?)", &_inner_error0_);
	stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp2_ = geary_rf_c822_message_get_rfc822_buffer (_data104_->rfc822, GEARY_RF_C822_MESSAGE_RF_C822_FORMAT_OPTIONS_NONE, &_inner_error0_);
	_tmp1_ = _tmp2_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp3_ = stmt;
	_tmp4_ = geary_db_statement_bind_string_buffer (_tmp3_, 0, _tmp1_, &_inner_error0_);
	_tmp5_ = _tmp4_;
	_g_object_unref0 (_tmp5_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp1_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp6_ = stmt;
	_tmp7_ = geary_db_statement_bind_int64 (_tmp6_, 1, ordering, &_inner_error0_);
	_tmp8_ = _tmp7_;
	_g_object_unref0 (_tmp8_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp1_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp9_ = stmt;
	new_id = geary_db_statement_exec_insert (_tmp9_, _data104_->cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp1_);
		_g_object_unref0 (stmt);
		return 0;
	}
	position = geary_outbox_folder_do_get_position_by_ordering (self, cx, ordering, _data104_->cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp1_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp10_ = geary_outbox_folder_outbox_row_new (new_id, position, ordering, FALSE, NULL);
	_geary_outbox_folder_outbox_row_unref0 (_data104_->row);
	_data104_->row = _tmp10_;
	_tmp11_ = geary_outbox_folder_do_get_email_count (self, cx, _data104_->cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp1_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_data104_->email_count = _tmp11_;
	result = GEARY_DB_TRANSACTION_OUTCOME_COMMIT;
	_g_object_unref0 (_tmp1_);
	_g_object_unref0 (stmt);
	return result;
}

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

static void
geary_outbox_folder_create_email_async_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_)
{
	GearyOutboxFolderCreateEmailAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_outbox_folder_real_create_email_async_co (_data_);
}

static gboolean
geary_outbox_folder_real_create_email_async_co (GearyOutboxFolderCreateEmailAsyncData* _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_->_data104_ = g_slice_new0 (Block104Data);
	_data_->_data104_->_ref_count_ = 1;
	_data_->_data104_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data104_->rfc822);
	_data_->_data104_->rfc822 = _data_->rfc822;
	_g_object_unref0 (_data_->_data104_->cancellable);
	_data_->_data104_->cancellable = _data_->cancellable;
	_data_->_data104_->_async_data_ = _data_;
	geary_abstract_local_folder_check_open (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_ABSTRACT_LOCAL_FOLDER, GearyAbstractLocalFolder), &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block104_data_unref (_data_->_data104_);
		_data_->_data104_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_data104_->email_count = 0;
	_data_->_data104_->row = NULL;
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_WR, ___lambda117__geary_db_transaction_method, _data_->_data104_, _data_->_data104_->cancellable, geary_outbox_folder_create_email_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (_data_->_tmp0_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block104_data_unref (_data_->_data104_);
		_data_->_data104_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_state_ = 2;
	geary_outbox_folder_get_email_count_async (_data_->self, _data_->_data104_->cancellable, geary_outbox_folder_create_email_async_ready, _data_);
	return FALSE;
	_state_2:
	_data_->_tmp1_ = geary_outbox_folder_get_email_count_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block104_data_unref (_data_->_data104_);
		_data_->_data104_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp2_ = _data_->self->priv->_properties;
	geary_outbox_folder_properties_set_total (_data_->_tmp2_, _data_->_tmp1_);
	_data_->_tmp3_ = gee_array_list_new (GEARY_OUTBOX_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data_->list = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp3_, GEE_TYPE_LIST, GeeList);
	_data_->_tmp4_ = _data_->list;
	_data_->_tmp5_ = _data_->_data104_->row;
	_data_->_tmp6_ = _data_->_tmp5_->outbox_id;
	gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp4_, GEE_TYPE_COLLECTION, GeeCollection), _data_->_tmp6_);
	_data_->_tmp7_ = _data_->list;
	geary_folder_notify_email_appended (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_FOLDER, GearyFolder), G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp7_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp8_ = _data_->list;
	geary_folder_notify_email_locally_appended (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_FOLDER, GearyFolder), G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp8_, GEE_TYPE_COLLECTION, GeeCollection));
	geary_folder_notify_email_count_changed (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_FOLDER, GearyFolder), _data_->_data104_->email_count, GEARY_FOLDER_COUNT_CHANGE_REASON_APPENDED);
	_data_->_tmp9_ = _data_->_data104_->row;
	_data_->_tmp10_ = _data_->_tmp9_->outbox_id;
	_data_->_tmp11_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp10_, GEARY_TYPE_EMAIL_IDENTIFIER, GearyEmailIdentifier));
	_data_->result = _data_->_tmp11_;
	_g_object_unref0 (_data_->list);
	block104_data_unref (_data_->_data104_);
	_data_->_data104_ = 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;
}

void
geary_outbox_folder_create_email_async (GearyOutboxFolder* self,
                                        GearyRFC822Message* rfc822,
                                        GearyEmailFlags* flags,
                                        GDateTime* date_received,
                                        GCancellable* cancellable,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_)
{
	GearyOutboxFolderClass* _klass_;
	_klass_ = GEARY_OUTBOX_FOLDER_GET_CLASS (self);
	if (_klass_->create_email_async) {
		_klass_->create_email_async (self, rfc822, flags, date_received, cancellable, _callback_, _user_data_);
	}
}

GearyEmailIdentifier*
geary_outbox_folder_create_email_finish (GearyOutboxFolder* self,
                                         GAsyncResult* _res_,
                                         GError** error)
{
	GearyOutboxFolderClass* _klass_;
	_klass_ = GEARY_OUTBOX_FOLDER_GET_CLASS (self);
	if (_klass_->create_email_finish) {
		return _klass_->create_email_finish (self, _res_, error);
	}
	return NULL;
}

static void
geary_outbox_folder_real_mark_email_async_data_free (gpointer _data)
{
	GearyOutboxFolderMarkEmailAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->to_mark);
	_g_object_unref0 (_data_->flags_to_add);
	_g_object_unref0 (_data_->flags_to_remove);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyOutboxFolderMarkEmailAsyncData, _data_);
}

static void
geary_outbox_folder_real_mark_email_async (GearyOutboxFolder* self,
                                           GeeCollection* to_mark,
                                           GearyEmailFlags* flags_to_add,
                                           GearyEmailFlags* flags_to_remove,
                                           GCancellable* cancellable,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_)
{
	GearyOutboxFolderMarkEmailAsyncData* _data_;
	GearyOutboxFolder* _tmp0_;
	GeeCollection* _tmp1_;
	GearyEmailFlags* _tmp2_;
	GearyEmailFlags* _tmp3_;
	GCancellable* _tmp4_;
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (to_mark, GEE_TYPE_COLLECTION));
	g_return_if_fail ((flags_to_add == NULL) || GEARY_IS_EMAIL_FLAGS (flags_to_add));
	g_return_if_fail ((flags_to_remove == NULL) || GEARY_IS_EMAIL_FLAGS (flags_to_remove));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyOutboxFolderMarkEmailAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_outbox_folder_real_mark_email_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (to_mark);
	_g_object_unref0 (_data_->to_mark);
	_data_->to_mark = _tmp1_;
	_tmp2_ = _g_object_ref0 (flags_to_add);
	_g_object_unref0 (_data_->flags_to_add);
	_data_->flags_to_add = _tmp2_;
	_tmp3_ = _g_object_ref0 (flags_to_remove);
	_g_object_unref0 (_data_->flags_to_remove);
	_data_->flags_to_remove = _tmp3_;
	_tmp4_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp4_;
	geary_outbox_folder_real_mark_email_async_co (_data_);
}

static void
geary_outbox_folder_real_mark_email_finish (GearyOutboxFolder* self,
                                            GAsyncResult* _res_,
                                            GError** error)
{
	GearyOutboxFolderMarkEmailAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static Block105Data*
block105_data_ref (Block105Data* _data105_)
{
	g_atomic_int_inc (&_data105_->_ref_count_);
	return _data105_;
}

static void
block105_data_unref (void * _userdata_)
{
	Block105Data* _data105_;
	_data105_ = (Block105Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data105_->_ref_count_)) {
		GearyOutboxFolder* self;
		self = _data105_->self;
		_g_object_unref0 (_data105_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block105Data, _data105_);
	}
}

static Block106Data*
block106_data_ref (Block106Data* _data106_)
{
	g_atomic_int_inc (&_data106_->_ref_count_);
	return _data106_;
}

static void
block106_data_unref (void * _userdata_)
{
	Block106Data* _data106_;
	_data106_ = (Block106Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data106_->_ref_count_)) {
		GearyOutboxFolder* self;
		self = _data106_->_data105_->self;
		_g_object_unref0 (_data106_->outbox_id);
		block105_data_unref (_data106_->_data105_);
		_data106_->_data105_ = NULL;
		g_slice_free (Block106Data, _data106_);
	}
}

static GearyDbTransactionOutcome
_____lambda119_ (Block106Data* _data106_,
                 GearyDbConnection* cx,
                 GError** error)
{
	Block105Data* _data105_;
	GearyOutboxFolder* self;
	GearyOutboxEmailIdentifier* _tmp0_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	_data105_ = _data106_->_data105_;
	self = _data105_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = _data106_->outbox_id;
	geary_outbox_folder_do_mark_email_as_sent (self, cx, _tmp0_, _data105_->cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_COMMIT;
	return result;
}

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

static void
geary_outbox_folder_mark_email_async_ready (GObject* source_object,
                                            GAsyncResult* _res_,
                                            gpointer _user_data_)
{
	GearyOutboxFolderMarkEmailAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_outbox_folder_real_mark_email_async_co (_data_);
}

static gboolean
geary_outbox_folder_real_mark_email_async_co (GearyOutboxFolderMarkEmailAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data105_ = g_slice_new0 (Block105Data);
	_data_->_data105_->_ref_count_ = 1;
	_data_->_data105_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data105_->cancellable);
	_data_->_data105_->cancellable = _data_->cancellable;
	_data_->_data105_->_async_data_ = _data_;
	geary_abstract_local_folder_check_open (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_ABSTRACT_LOCAL_FOLDER, GearyAbstractLocalFolder), &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block105_data_unref (_data_->_data105_);
		_data_->_data105_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp0_ = gee_hash_map_new (GEARY_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEARY_TYPE_EMAIL_FLAGS, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->changed = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEE_TYPE_MAP, GeeMap);
	{
		_data_->_tmp1_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_data_->to_mark, GEE_TYPE_ITERABLE, GeeIterable));
		_data_->_id_it = _data_->_tmp1_;
		while (TRUE) {
			_data_->_data106_ = g_slice_new0 (Block106Data);
			_data_->_data106_->_ref_count_ = 1;
			_data_->_data106_->_data105_ = block105_data_ref (_data_->_data105_);
			_data_->_tmp2_ = _data_->_id_it;
			if (!gee_iterator_next (_data_->_tmp2_)) {
				block106_data_unref (_data_->_data106_);
				_data_->_data106_ = NULL;
				break;
			}
			_data_->_tmp3_ = _data_->_id_it;
			_data_->_tmp4_ = gee_iterator_get (_data_->_tmp3_);
			_data_->id = (GearyEmailIdentifier*) _data_->_tmp4_;
			_data_->_tmp5_ = _data_->id;
			_data_->_tmp6_ = _g_object_ref0 (GEARY_OUTBOX_IS_EMAIL_IDENTIFIER (_data_->_tmp5_) ? ((GearyOutboxEmailIdentifier*) _data_->_tmp5_) : NULL);
			_data_->_data106_->outbox_id = _data_->_tmp6_;
			_data_->_tmp7_ = _data_->_data106_->outbox_id;
			if (_data_->_tmp7_ != NULL) {
				_data_->_tmp8_ = _data_->self->priv->db;
				_data_->_state_ = 1;
				geary_db_database_exec_transaction_async (_data_->_tmp8_, GEARY_DB_TRANSACTION_TYPE_WR, ______lambda119__geary_db_transaction_method, _data_->_data106_, _data_->_data105_->cancellable, geary_outbox_folder_mark_email_async_ready, _data_);
				return FALSE;
				_state_1:
				geary_db_database_exec_transaction_finish (_data_->_tmp8_, _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_->id);
					block106_data_unref (_data_->_data106_);
					_data_->_data106_ = NULL;
					_g_object_unref0 (_data_->_id_it);
					_g_object_unref0 (_data_->changed);
					block105_data_unref (_data_->_data105_);
					_data_->_data105_ = NULL;
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
				_data_->_tmp9_ = _data_->changed;
				_data_->_tmp10_ = _data_->id;
				gee_map_set (_data_->_tmp9_, _data_->_tmp10_, _data_->flags_to_add);
			}
			_g_object_unref0 (_data_->id);
			block106_data_unref (_data_->_data106_);
			_data_->_data106_ = NULL;
		}
		_g_object_unref0 (_data_->_id_it);
	}
	_data_->_tmp11_ = _data_->changed;
	geary_folder_notify_email_flags_changed (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_FOLDER, GearyFolder), _data_->_tmp11_);
	_g_object_unref0 (_data_->changed);
	block105_data_unref (_data_->_data105_);
	_data_->_data105_ = 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;
}

void
geary_outbox_folder_mark_email_async (GearyOutboxFolder* self,
                                      GeeCollection* to_mark,
                                      GearyEmailFlags* flags_to_add,
                                      GearyEmailFlags* flags_to_remove,
                                      GCancellable* cancellable,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_)
{
	GearyOutboxFolderClass* _klass_;
	_klass_ = GEARY_OUTBOX_FOLDER_GET_CLASS (self);
	if (_klass_->mark_email_async) {
		_klass_->mark_email_async (self, to_mark, flags_to_add, flags_to_remove, cancellable, _callback_, _user_data_);
	}
}

void
geary_outbox_folder_mark_email_finish (GearyOutboxFolder* self,
                                       GAsyncResult* _res_,
                                       GError** error)
{
	GearyOutboxFolderClass* _klass_;
	_klass_ = GEARY_OUTBOX_FOLDER_GET_CLASS (self);
	if (_klass_->mark_email_finish) {
		_klass_->mark_email_finish (self, _res_, error);
	}
}

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

static void
geary_outbox_folder_real_remove_email_async (GearyOutboxFolder* self,
                                             GeeCollection* email_ids,
                                             GCancellable* cancellable,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_)
{
	GearyOutboxFolderRemoveEmailAsyncData* _data_;
	GearyOutboxFolder* _tmp0_;
	GeeCollection* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (email_ids, GEE_TYPE_COLLECTION));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyOutboxFolderRemoveEmailAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_outbox_folder_real_remove_email_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (email_ids);
	_g_object_unref0 (_data_->email_ids);
	_data_->email_ids = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_outbox_folder_real_remove_email_async_co (_data_);
}

static void
geary_outbox_folder_real_remove_email_finish (GearyOutboxFolder* self,
                                              GAsyncResult* _res_,
                                              GError** error)
{
	GearyOutboxFolderRemoveEmailAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static Block107Data*
block107_data_ref (Block107Data* _data107_)
{
	g_atomic_int_inc (&_data107_->_ref_count_);
	return _data107_;
}

static void
block107_data_unref (void * _userdata_)
{
	Block107Data* _data107_;
	_data107_ = (Block107Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data107_->_ref_count_)) {
		GearyOutboxFolder* self;
		self = _data107_->self;
		_g_object_unref0 (_data107_->removed);
		_g_object_unref0 (_data107_->email_ids);
		_g_object_unref0 (_data107_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block107Data, _data107_);
	}
}

static GearyDbTransactionOutcome
__lambda120_ (Block107Data* _data107_,
              GearyDbConnection* cx,
              GError** error)
{
	GearyOutboxFolder* self;
	gint _tmp11_ = 0;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data107_->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 (_data107_->email_ids, GEE_TYPE_ITERABLE, GeeIterable));
		_id_it = _tmp0_;
		while (TRUE) {
			GeeIterator* _tmp1_;
			GearyEmailIdentifier* id = NULL;
			GeeIterator* _tmp2_;
			gpointer _tmp3_;
			GearyOutboxEmailIdentifier* outbox_id = NULL;
			GearyEmailIdentifier* _tmp4_;
			GearyOutboxEmailIdentifier* _tmp5_;
			GearyOutboxEmailIdentifier* _tmp6_;
			gboolean _tmp7_ = FALSE;
			GearyOutboxEmailIdentifier* _tmp8_;
			_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_OUTBOX_IS_EMAIL_IDENTIFIER (_tmp4_) ? ((GearyOutboxEmailIdentifier*) _tmp4_) : NULL);
			outbox_id = _tmp5_;
			_tmp6_ = outbox_id;
			if (_tmp6_ == NULL) {
				_g_object_unref0 (outbox_id);
				_g_object_unref0 (id);
				continue;
			}
			geary_outbox_folder_do_get_next_ordering (self, cx, _data107_->cancellable, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (outbox_id);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				return 0;
			}
			_tmp8_ = outbox_id;
			_tmp7_ = geary_outbox_folder_do_remove_email (self, cx, _tmp8_, _data107_->cancellable, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (outbox_id);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				return 0;
			}
			if (_tmp7_) {
				GeeList* _tmp9_;
				GearyOutboxEmailIdentifier* _tmp10_;
				_tmp9_ = _data107_->removed;
				_tmp10_ = outbox_id;
				gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp9_, GEE_TYPE_COLLECTION, GeeCollection), G_TYPE_CHECK_INSTANCE_CAST (_tmp10_, GEARY_TYPE_EMAIL_IDENTIFIER, GearyEmailIdentifier));
			}
			_g_object_unref0 (outbox_id);
			_g_object_unref0 (id);
		}
		_g_object_unref0 (_id_it);
	}
	_tmp11_ = geary_outbox_folder_do_get_email_count (self, cx, _data107_->cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_data107_->final_count = _tmp11_;
	result = GEARY_DB_TRANSACTION_OUTCOME_COMMIT;
	return result;
}

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

static void
geary_outbox_folder_remove_email_async_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_)
{
	GearyOutboxFolderRemoveEmailAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_outbox_folder_real_remove_email_async_co (_data_);
}

static gboolean
geary_outbox_folder_real_remove_email_async_co (GearyOutboxFolderRemoveEmailAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data107_ = g_slice_new0 (Block107Data);
	_data_->_data107_->_ref_count_ = 1;
	_data_->_data107_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data107_->email_ids);
	_data_->_data107_->email_ids = _data_->email_ids;
	_g_object_unref0 (_data_->_data107_->cancellable);
	_data_->_data107_->cancellable = _data_->cancellable;
	_data_->_data107_->_async_data_ = _data_;
	geary_abstract_local_folder_check_open (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_ABSTRACT_LOCAL_FOLDER, GearyAbstractLocalFolder), &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block107_data_unref (_data_->_data107_);
		_data_->_data107_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp0_ = gee_array_list_new (GEARY_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data_->_data107_->removed = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEE_TYPE_LIST, GeeList);
	_data_->_data107_->final_count = 0;
	_data_->_tmp1_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp1_, GEARY_DB_TRANSACTION_TYPE_WR, ___lambda120__geary_db_transaction_method, _data_->_data107_, _data_->_data107_->cancellable, geary_outbox_folder_remove_email_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (_data_->_tmp1_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block107_data_unref (_data_->_data107_);
		_data_->_data107_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp2_ = _data_->_data107_->removed;
	_data_->_tmp3_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp4_ = _data_->_tmp3_;
	if (_data_->_tmp4_ >= 0) {
		_data_->_tmp5_ = _data_->self->priv->_properties;
		geary_outbox_folder_properties_set_total (_data_->_tmp5_, _data_->_data107_->final_count);
		_data_->_tmp6_ = _data_->_data107_->removed;
		geary_folder_notify_email_removed (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_FOLDER, GearyFolder), G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp6_, GEE_TYPE_COLLECTION, GeeCollection));
		geary_folder_notify_email_count_changed (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_FOLDER, GearyFolder), _data_->_data107_->final_count, GEARY_FOLDER_COUNT_CHANGE_REASON_REMOVED);
	}
	block107_data_unref (_data_->_data107_);
	_data_->_data107_ = 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;
}

void
geary_outbox_folder_remove_email_async (GearyOutboxFolder* self,
                                        GeeCollection* email_ids,
                                        GCancellable* cancellable,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_)
{
	GearyOutboxFolderClass* _klass_;
	_klass_ = GEARY_OUTBOX_FOLDER_GET_CLASS (self);
	if (_klass_->remove_email_async) {
		_klass_->remove_email_async (self, email_ids, cancellable, _callback_, _user_data_);
	}
}

void
geary_outbox_folder_remove_email_finish (GearyOutboxFolder* self,
                                         GAsyncResult* _res_,
                                         GError** error)
{
	GearyOutboxFolderClass* _klass_;
	_klass_ = GEARY_OUTBOX_FOLDER_GET_CLASS (self);
	if (_klass_->remove_email_finish) {
		_klass_->remove_email_finish (self, _res_, error);
	}
}

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

static void
geary_outbox_folder_real_contains_identifiers (GearyFolder* base,
                                               GeeCollection* ids,
                                               GCancellable* cancellable,
                                               GAsyncReadyCallback _callback_,
                                               gpointer _user_data_)
{
	GearyOutboxFolder * self;
	GearyOutboxFolderContainsIdentifiersData* _data_;
	GearyOutboxFolder* _tmp0_;
	GeeCollection* _tmp1_;
	GCancellable* _tmp2_;
	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 ()));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_OUTBOX_TYPE_FOLDER, GearyOutboxFolder);
	_data_ = g_slice_new0 (GearyOutboxFolderContainsIdentifiersData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_outbox_folder_real_contains_identifiers_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 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_outbox_folder_real_contains_identifiers_co (_data_);
}

static GeeCollection*
geary_outbox_folder_contains_identifiers_finish (GearyFolder* base,
                                                 GAsyncResult* _res_,
                                                 GError** error)
{
	GeeCollection* result;
	GearyOutboxFolderContainsIdentifiersData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

/** {@inheritDoc} */
static Block108Data*
block108_data_ref (Block108Data* _data108_)
{
	g_atomic_int_inc (&_data108_->_ref_count_);
	return _data108_;
}

static void
block108_data_unref (void * _userdata_)
{
	Block108Data* _data108_;
	_data108_ = (Block108Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data108_->_ref_count_)) {
		GearyOutboxFolder* self;
		self = _data108_->self;
		_g_object_unref0 (_data108_->contains);
		_g_object_unref0 (_data108_->ids);
		_g_object_unref0 (self);
		g_slice_free (Block108Data, _data108_);
	}
}

static GearyDbTransactionOutcome
__lambda121_ (Block108Data* _data108_,
              GearyDbConnection* cx,
              GCancellable* cancellable,
              GError** error)
{
	GearyOutboxFolder* self;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data108_->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 (_data108_->ids, GEE_TYPE_ITERABLE, GeeIterable));
		_id_it = _tmp0_;
		while (TRUE) {
			GeeIterator* _tmp1_;
			GearyEmailIdentifier* id = NULL;
			GeeIterator* _tmp2_;
			gpointer _tmp3_;
			GearyOutboxEmailIdentifier* outbox_id = NULL;
			GearyEmailIdentifier* _tmp4_;
			GearyOutboxEmailIdentifier* _tmp5_;
			GearyOutboxEmailIdentifier* _tmp6_;
			_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_OUTBOX_IS_EMAIL_IDENTIFIER (_tmp4_) ? ((GearyOutboxEmailIdentifier*) _tmp4_) : NULL);
			outbox_id = _tmp5_;
			_tmp6_ = outbox_id;
			if (_tmp6_ != NULL) {
				GearyOutboxFolderOutboxRow* row = NULL;
				GearyOutboxEmailIdentifier* _tmp7_;
				gint64 _tmp8_;
				gint64 _tmp9_;
				GearyOutboxFolderOutboxRow* _tmp10_;
				GearyOutboxFolderOutboxRow* _tmp11_;
				_tmp7_ = outbox_id;
				_tmp8_ = geary_outbox_email_identifier_get_ordering (_tmp7_);
				_tmp9_ = _tmp8_;
				_tmp10_ = geary_outbox_folder_do_fetch_row_by_ordering (self, cx, _tmp9_, cancellable, &_inner_error0_);
				row = _tmp10_;
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					g_propagate_error (error, _inner_error0_);
					_g_object_unref0 (outbox_id);
					_g_object_unref0 (id);
					_g_object_unref0 (_id_it);
					return 0;
				}
				_tmp11_ = row;
				if (_tmp11_ != NULL) {
					GeeHashSet* _tmp12_;
					GearyEmailIdentifier* _tmp13_;
					_tmp12_ = _data108_->contains;
					_tmp13_ = id;
					gee_abstract_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp12_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection), _tmp13_);
				}
				_geary_outbox_folder_outbox_row_unref0 (row);
			}
			_g_object_unref0 (outbox_id);
			_g_object_unref0 (id);
		}
		_g_object_unref0 (_id_it);
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	return result;
}

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

static void
geary_outbox_folder_contains_identifiers_ready (GObject* source_object,
                                                GAsyncResult* _res_,
                                                gpointer _user_data_)
{
	GearyOutboxFolderContainsIdentifiersData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_outbox_folder_real_contains_identifiers_co (_data_);
}

static gboolean
geary_outbox_folder_real_contains_identifiers_co (GearyOutboxFolderContainsIdentifiersData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data108_ = g_slice_new0 (Block108Data);
	_data_->_data108_->_ref_count_ = 1;
	_data_->_data108_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data108_->ids);
	_data_->_data108_->ids = _data_->ids;
	_data_->_data108_->_async_data_ = _data_;
	geary_abstract_local_folder_check_open (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_ABSTRACT_LOCAL_FOLDER, GearyAbstractLocalFolder), &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block108_data_unref (_data_->_data108_);
		_data_->_data108_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp0_ = gee_hash_set_new (GEARY_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->_data108_->contains = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp1_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda121__geary_db_transaction_method, _data_->_data108_, _data_->cancellable, geary_outbox_folder_contains_identifiers_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (_data_->_tmp1_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block108_data_unref (_data_->_data108_);
		_data_->_data108_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp2_ = _data_->_data108_->contains;
	_data_->_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->result = _data_->_tmp3_;
	block108_data_unref (_data_->_data108_);
	_data_->_data108_ = 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_outbox_folder_real_list_email_by_id_async_data_free (gpointer _data)
{
	GearyOutboxFolderListEmailByIdAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->_initial_id);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyOutboxFolderListEmailByIdAsyncData, _data_);
}

static void
geary_outbox_folder_real_list_email_by_id_async (GearyFolder* base,
                                                 GearyEmailIdentifier* _initial_id,
                                                 gint count,
                                                 GearyEmailField required_fields,
                                                 GearyFolderListFlags flags,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_)
{
	GearyOutboxFolder * self;
	GearyOutboxFolderListEmailByIdAsyncData* _data_;
	GearyOutboxFolder* _tmp0_;
	GearyEmailIdentifier* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail ((_initial_id == NULL) || GEARY_IS_EMAIL_IDENTIFIER (_initial_id));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_OUTBOX_TYPE_FOLDER, GearyOutboxFolder);
	_data_ = g_slice_new0 (GearyOutboxFolderListEmailByIdAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_outbox_folder_real_list_email_by_id_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (_initial_id);
	_g_object_unref0 (_data_->_initial_id);
	_data_->_initial_id = _tmp1_;
	_data_->count = count;
	_data_->required_fields = required_fields;
	_data_->flags = flags;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_outbox_folder_real_list_email_by_id_async_co (_data_);
}

static GeeList*
geary_outbox_folder_list_email_by_id_finish (GearyFolder* base,
                                             GAsyncResult* _res_,
                                             GError** error)
{
	GeeList* result;
	GearyOutboxFolderListEmailByIdAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block109Data*
block109_data_ref (Block109Data* _data109_)
{
	g_atomic_int_inc (&_data109_->_ref_count_);
	return _data109_;
}

static void
block109_data_unref (void * _userdata_)
{
	Block109Data* _data109_;
	_data109_ = (Block109Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data109_->_ref_count_)) {
		GearyOutboxFolder* self;
		self = _data109_->self;
		_g_object_unref0 (_data109_->list);
		_g_free0 (_data109_->select);
		_g_object_unref0 (_data109_->initial_id);
		_g_object_unref0 (_data109_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block109Data, _data109_);
	}
}

static GearyDbTransactionOutcome
__lambda122_ (Block109Data* _data109_,
              GearyDbConnection* cx,
              GError** error)
{
	GearyOutboxFolder* self;
	const gchar* _tmp0_ = NULL;
	gchar* dir = NULL;
	gchar* _tmp1_;
	GearyDbStatement* stmt = NULL;
	GearyOutboxEmailIdentifier* _tmp2_;
	GearyDbResult* results = NULL;
	GearyDbStatement* _tmp35_;
	GearyDbResult* _tmp36_;
	GearyDbResult* _tmp37_;
	gboolean _tmp38_;
	gboolean _tmp39_;
	GeeArrayList* _tmp40_;
	gint position = 0;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data109_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	if (geary_folder_list_flags_is_newest_to_oldest (_data109_->flags)) {
		_tmp0_ = "DESC";
	} else {
		_tmp0_ = "ASC";
	}
	_tmp1_ = g_strdup (_tmp0_);
	dir = _tmp1_;
	_tmp2_ = _data109_->initial_id;
	if (_tmp2_ != NULL) {
		GearyDbStatement* _tmp3_ = NULL;
		const gchar* _tmp4_;
		const gchar* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		GearyDbStatement* _tmp8_;
		GearyDbStatement* _tmp9_;
		GearyDbStatement* _tmp10_;
		gint64 _tmp11_ = 0LL;
		GearyDbStatement* _tmp18_;
		GearyDbStatement* _tmp19_;
		GearyDbStatement* _tmp20_;
		GearyDbStatement* _tmp21_;
		GearyDbStatement* _tmp22_;
		GearyDbStatement* _tmp23_;
		_tmp4_ = _data109_->select;
		_tmp5_ = dir;
		_tmp6_ = g_strdup_printf ("\n" \
"                    SELECT %s\n" \
"                    FROM SmtpOutboxTable\n" \
"                    WHERE ordering >= ?\n" \
"                    ORDER BY ordering %s\n" \
"                    LIMIT ?\n" \
"                ", _tmp4_, _tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = geary_db_connection_prepare (cx, _tmp7_, &_inner_error0_);
		_tmp9_ = _tmp8_;
		_g_free0 (_tmp7_);
		_tmp3_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_g_free0 (dir);
			return 0;
		}
		_tmp10_ = _tmp3_;
		_tmp3_ = NULL;
		_g_object_unref0 (stmt);
		stmt = _tmp10_;
		if (geary_folder_list_flags_is_including_id (_data109_->flags)) {
			GearyOutboxEmailIdentifier* _tmp12_;
			gint64 _tmp13_;
			gint64 _tmp14_;
			_tmp12_ = _data109_->initial_id;
			_tmp13_ = geary_outbox_email_identifier_get_ordering (_tmp12_);
			_tmp14_ = _tmp13_;
			_tmp11_ = _tmp14_;
		} else {
			GearyOutboxEmailIdentifier* _tmp15_;
			gint64 _tmp16_;
			gint64 _tmp17_;
			_tmp15_ = _data109_->initial_id;
			_tmp16_ = geary_outbox_email_identifier_get_ordering (_tmp15_);
			_tmp17_ = _tmp16_;
			_tmp11_ = _tmp17_ + 1;
		}
		_tmp18_ = stmt;
		_tmp19_ = geary_db_statement_bind_int64 (_tmp18_, 0, _tmp11_, &_inner_error0_);
		_tmp20_ = _tmp19_;
		_g_object_unref0 (_tmp20_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (_tmp3_);
			_g_object_unref0 (stmt);
			_g_free0 (dir);
			return 0;
		}
		_tmp21_ = stmt;
		_tmp22_ = geary_db_statement_bind_int (_tmp21_, 1, _data109_->count, &_inner_error0_);
		_tmp23_ = _tmp22_;
		_g_object_unref0 (_tmp23_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (_tmp3_);
			_g_object_unref0 (stmt);
			_g_free0 (dir);
			return 0;
		}
		_g_object_unref0 (_tmp3_);
	} else {
		GearyDbStatement* _tmp24_ = NULL;
		const gchar* _tmp25_;
		const gchar* _tmp26_;
		gchar* _tmp27_;
		gchar* _tmp28_;
		GearyDbStatement* _tmp29_;
		GearyDbStatement* _tmp30_;
		GearyDbStatement* _tmp31_;
		GearyDbStatement* _tmp32_;
		GearyDbStatement* _tmp33_;
		GearyDbStatement* _tmp34_;
		_tmp25_ = _data109_->select;
		_tmp26_ = dir;
		_tmp27_ = g_strdup_printf ("\n" \
"                    SELECT %s\n" \
"                    FROM SmtpOutboxTable\n" \
"                    ORDER BY ordering %s\n" \
"                    LIMIT ?\n" \
"                ", _tmp25_, _tmp26_);
		_tmp28_ = _tmp27_;
		_tmp29_ = geary_db_connection_prepare (cx, _tmp28_, &_inner_error0_);
		_tmp30_ = _tmp29_;
		_g_free0 (_tmp28_);
		_tmp24_ = _tmp30_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_g_free0 (dir);
			return 0;
		}
		_tmp31_ = _tmp24_;
		_tmp24_ = NULL;
		_g_object_unref0 (stmt);
		stmt = _tmp31_;
		_tmp32_ = stmt;
		_tmp33_ = geary_db_statement_bind_int (_tmp32_, 0, _data109_->count, &_inner_error0_);
		_tmp34_ = _tmp33_;
		_g_object_unref0 (_tmp34_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (_tmp24_);
			_g_object_unref0 (stmt);
			_g_free0 (dir);
			return 0;
		}
		_g_object_unref0 (_tmp24_);
	}
	_tmp35_ = stmt;
	_tmp36_ = geary_db_statement_exec (_tmp35_, _data109_->cancellable, &_inner_error0_);
	results = _tmp36_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_free0 (dir);
		return 0;
	}
	_tmp37_ = results;
	_tmp38_ = geary_db_result_get_finished (_tmp37_);
	_tmp39_ = _tmp38_;
	if (_tmp39_) {
		result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		_g_free0 (dir);
		return result;
	}
	_tmp40_ = gee_array_list_new (GEARY_TYPE_EMAIL, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (_data109_->list);
	_data109_->list = G_TYPE_CHECK_INSTANCE_CAST (_tmp40_, GEE_TYPE_LIST, GeeList);
	position = -1;
	{
		gboolean _tmp41_ = FALSE;
		_tmp41_ = TRUE;
		while (TRUE) {
			gint64 ordering = 0LL;
			GearyDbResult* _tmp44_;
			gint64 _tmp46_ = 0LL;
			GearyDbResult* _tmp47_;
			gboolean _tmp48_ = FALSE;
			GearyMemoryBuffer* _tmp50_ = NULL;
			GearyEmail* _tmp53_ = NULL;
			GearyOutboxFolderOutboxRow* _tmp54_;
			GearyOutboxFolderOutboxRow* _tmp55_;
			GearyEmail* _tmp56_;
			GearyEmail* _tmp57_;
			GeeList* _tmp58_;
			gint _tmp59_ = 0;
			if (!_tmp41_) {
				gboolean _tmp42_ = FALSE;
				GearyDbResult* _tmp43_;
				_tmp43_ = results;
				_tmp42_ = geary_db_result_next (_tmp43_, NULL, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					g_propagate_error (error, _inner_error0_);
					_g_object_unref0 (results);
					_g_object_unref0 (stmt);
					_g_free0 (dir);
					return 0;
				}
				if (!_tmp42_) {
					break;
				}
			}
			_tmp41_ = FALSE;
			_tmp44_ = results;
			ordering = geary_db_result_int64_at (_tmp44_, 1, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (results);
				_g_object_unref0 (stmt);
				_g_free0 (dir);
				return 0;
			}
			if (position == -1) {
				gint _tmp45_ = 0;
				_tmp45_ = geary_outbox_folder_do_get_position_by_ordering (self, cx, ordering, _data109_->cancellable, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					g_propagate_error (error, _inner_error0_);
					_g_object_unref0 (results);
					_g_object_unref0 (stmt);
					_g_free0 (dir);
					return 0;
				}
				position = _tmp45_;
				_vala_assert (position >= 1, "position >= 1");
			}
			_tmp47_ = results;
			_tmp46_ = geary_db_result_rowid_at (_tmp47_, 0, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (results);
				_g_object_unref0 (stmt);
				_g_free0 (dir);
				return 0;
			}
			if (_data109_->list_all) {
				GearyDbResult* _tmp49_;
				_tmp49_ = results;
				_tmp48_ = geary_db_result_bool_at (_tmp49_, 3, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					g_propagate_error (error, _inner_error0_);
					_g_object_unref0 (results);
					_g_object_unref0 (stmt);
					_g_free0 (dir);
					return 0;
				}
			} else {
				_tmp48_ = FALSE;
			}
			if (_data109_->list_all) {
				GearyDbResult* _tmp51_;
				GearyMemoryBuffer* _tmp52_;
				_tmp51_ = results;
				_tmp52_ = geary_db_result_string_buffer_at (_tmp51_, 2, &_inner_error0_);
				_g_object_unref0 (_tmp50_);
				_tmp50_ = _tmp52_;
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					g_propagate_error (error, _inner_error0_);
					_g_object_unref0 (_tmp50_);
					_g_object_unref0 (results);
					_g_object_unref0 (stmt);
					_g_free0 (dir);
					return 0;
				}
			} else {
				_g_object_unref0 (_tmp50_);
				_tmp50_ = NULL;
			}
			_tmp54_ = geary_outbox_folder_outbox_row_new (_tmp46_, position, ordering, _tmp48_, _tmp50_);
			_tmp55_ = _tmp54_;
			_tmp56_ = geary_outbox_folder_row_to_email (self, _tmp55_, &_inner_error0_);
			_tmp57_ = _tmp56_;
			_geary_outbox_folder_outbox_row_unref0 (_tmp55_);
			_tmp53_ = _tmp57_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (_tmp50_);
				_g_object_unref0 (results);
				_g_object_unref0 (stmt);
				_g_free0 (dir);
				return 0;
			}
			_tmp58_ = _data109_->list;
			gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp58_, GEE_TYPE_COLLECTION, GeeCollection), _tmp53_);
			if (geary_folder_list_flags_is_newest_to_oldest (_data109_->flags)) {
				_tmp59_ = -1;
			} else {
				_tmp59_ = 1;
			}
			position += _tmp59_;
			_vala_assert (position >= 1, "position >= 1");
			_g_object_unref0 (_tmp53_);
			_g_object_unref0 (_tmp50_);
		}
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	_g_object_unref0 (results);
	_g_object_unref0 (stmt);
	_g_free0 (dir);
	return result;
}

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

static void
geary_outbox_folder_list_email_by_id_async_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_)
{
	GearyOutboxFolderListEmailByIdAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_outbox_folder_real_list_email_by_id_async_co (_data_);
}

static gboolean
geary_outbox_folder_real_list_email_by_id_async_co (GearyOutboxFolderListEmailByIdAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data109_ = g_slice_new0 (Block109Data);
	_data_->_data109_->_ref_count_ = 1;
	_data_->_data109_->self = g_object_ref (_data_->self);
	_data_->_data109_->count = _data_->count;
	_data_->_data109_->flags = _data_->flags;
	_g_object_unref0 (_data_->_data109_->cancellable);
	_data_->_data109_->cancellable = _data_->cancellable;
	_data_->_data109_->_async_data_ = _data_;
	geary_abstract_local_folder_check_open (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_ABSTRACT_LOCAL_FOLDER, GearyAbstractLocalFolder), &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block109_data_unref (_data_->_data109_);
		_data_->_data109_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp0_ = _g_object_ref0 (GEARY_OUTBOX_IS_EMAIL_IDENTIFIER (_data_->_initial_id) ? ((GearyOutboxEmailIdentifier*) _data_->_initial_id) : NULL);
	_data_->_data109_->initial_id = _data_->_tmp0_;
	if (_data_->_initial_id != NULL) {
		_data_->_tmp2_ = _data_->_data109_->initial_id;
		_data_->_tmp1_ = _data_->_tmp2_ == NULL;
	} else {
		_data_->_tmp1_ = FALSE;
	}
	if (_data_->_tmp1_) {
		_data_->_tmp3_ = _data_->_data109_->initial_id;
		_data_->_tmp4_ = geary_email_identifier_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp3_, GEARY_TYPE_EMAIL_IDENTIFIER, GearyEmailIdentifier));
		_data_->_tmp5_ = _data_->_tmp4_;
		_data_->_tmp6_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_BAD_PARAMETERS, "EmailIdentifier %s not for Outbox", _data_->_tmp5_);
		_data_->_tmp7_ = _data_->_tmp6_;
		_g_free0 (_data_->_tmp5_);
		_data_->_inner_error0_ = _data_->_tmp7_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block109_data_unref (_data_->_data109_);
		_data_->_data109_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (_data_->_data109_->count <= 0) {
		_data_->result = NULL;
		block109_data_unref (_data_->_data109_);
		_data_->_data109_ = 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_->_data109_->list_all = _data_->required_fields != GEARY_EMAIL_FIELD_NONE;
	_data_->_tmp8_ = g_strdup ("id, ordering");
	_data_->_data109_->select = _data_->_tmp8_;
	if (_data_->_data109_->list_all) {
		_data_->_tmp9_ = _data_->_data109_->select;
		_data_->_tmp10_ = g_strconcat (_data_->_tmp9_, ", message, sent", NULL);
		_g_free0 (_data_->_data109_->select);
		_data_->_data109_->select = _data_->_tmp10_;
	}
	_data_->_data109_->list = NULL;
	_data_->_tmp11_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp11_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda122__geary_db_transaction_method, _data_->_data109_, _data_->_data109_->cancellable, geary_outbox_folder_list_email_by_id_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (_data_->_tmp11_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block109_data_unref (_data_->_data109_);
		_data_->_data109_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp12_ = _data_->_data109_->list;
	_data_->_tmp13_ = _g_object_ref0 (_data_->_tmp12_);
	_data_->result = _data_->_tmp13_;
	block109_data_unref (_data_->_data109_);
	_data_->_data109_ = 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_outbox_folder_real_list_email_by_sparse_id_async_data_free (gpointer _data)
{
	GearyOutboxFolderListEmailBySparseIdAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyOutboxFolderListEmailBySparseIdAsyncData, _data_);
}

static void
geary_outbox_folder_real_list_email_by_sparse_id_async (GearyFolder* base,
                                                        GeeCollection* ids,
                                                        GearyEmailField required_fields,
                                                        GearyFolderListFlags flags,
                                                        GCancellable* cancellable,
                                                        GAsyncReadyCallback _callback_,
                                                        gpointer _user_data_)
{
	GearyOutboxFolder * self;
	GearyOutboxFolderListEmailBySparseIdAsyncData* _data_;
	GearyOutboxFolder* _tmp0_;
	GeeCollection* _tmp1_;
	GCancellable* _tmp2_;
	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 ()));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_OUTBOX_TYPE_FOLDER, GearyOutboxFolder);
	_data_ = g_slice_new0 (GearyOutboxFolderListEmailBySparseIdAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_outbox_folder_real_list_email_by_sparse_id_async_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;
	_data_->flags = flags;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_outbox_folder_real_list_email_by_sparse_id_async_co (_data_);
}

static GeeList*
geary_outbox_folder_list_email_by_sparse_id_finish (GearyFolder* base,
                                                    GAsyncResult* _res_,
                                                    GError** error)
{
	GeeList* result;
	GearyOutboxFolderListEmailBySparseIdAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block110Data*
block110_data_ref (Block110Data* _data110_)
{
	g_atomic_int_inc (&_data110_->_ref_count_);
	return _data110_;
}

static void
block110_data_unref (void * _userdata_)
{
	Block110Data* _data110_;
	_data110_ = (Block110Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data110_->_ref_count_)) {
		GearyOutboxFolder* self;
		self = _data110_->self;
		_g_object_unref0 (_data110_->list);
		_g_object_unref0 (_data110_->ids);
		_g_object_unref0 (_data110_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block110Data, _data110_);
	}
}

static GearyDbTransactionOutcome
__lambda123_ (Block110Data* _data110_,
              GearyDbConnection* cx,
              GError** error)
{
	GearyOutboxFolder* self;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data110_->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 (_data110_->ids, GEE_TYPE_ITERABLE, GeeIterable));
		_id_it = _tmp0_;
		while (TRUE) {
			GeeIterator* _tmp1_;
			GearyEmailIdentifier* id = NULL;
			GeeIterator* _tmp2_;
			gpointer _tmp3_;
			GearyOutboxEmailIdentifier* outbox_id = NULL;
			GearyEmailIdentifier* _tmp4_;
			GearyOutboxEmailIdentifier* _tmp5_;
			GearyOutboxEmailIdentifier* _tmp6_;
			GearyOutboxFolderOutboxRow* row = NULL;
			GearyOutboxEmailIdentifier* _tmp12_;
			gint64 _tmp13_;
			gint64 _tmp14_;
			GearyOutboxFolderOutboxRow* _tmp15_;
			GearyOutboxFolderOutboxRow* _tmp16_;
			GearyEmail* _tmp17_ = NULL;
			GearyOutboxFolderOutboxRow* _tmp18_;
			GearyEmail* _tmp19_;
			GeeList* _tmp20_;
			_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_OUTBOX_IS_EMAIL_IDENTIFIER (_tmp4_) ? ((GearyOutboxEmailIdentifier*) _tmp4_) : NULL);
			outbox_id = _tmp5_;
			_tmp6_ = outbox_id;
			if (_tmp6_ == NULL) {
				GearyEmailIdentifier* _tmp7_;
				gchar* _tmp8_;
				gchar* _tmp9_;
				GError* _tmp10_;
				GError* _tmp11_;
				_tmp7_ = id;
				_tmp8_ = geary_email_identifier_to_string (_tmp7_);
				_tmp9_ = _tmp8_;
				_tmp10_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_BAD_PARAMETERS, "%s is not outbox EmailIdentifier", _tmp9_);
				_tmp11_ = _tmp10_;
				_g_free0 (_tmp9_);
				_inner_error0_ = _tmp11_;
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (outbox_id);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				return 0;
			}
			_tmp12_ = outbox_id;
			_tmp13_ = geary_outbox_email_identifier_get_ordering (_tmp12_);
			_tmp14_ = _tmp13_;
			_tmp15_ = geary_outbox_folder_do_fetch_row_by_ordering (self, cx, _tmp14_, _data110_->cancellable, &_inner_error0_);
			row = _tmp15_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (outbox_id);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				return 0;
			}
			_tmp16_ = row;
			if (_tmp16_ == NULL) {
				_geary_outbox_folder_outbox_row_unref0 (row);
				_g_object_unref0 (outbox_id);
				_g_object_unref0 (id);
				continue;
			}
			_tmp18_ = row;
			_tmp19_ = geary_outbox_folder_row_to_email (self, _tmp18_, &_inner_error0_);
			_tmp17_ = _tmp19_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_geary_outbox_folder_outbox_row_unref0 (row);
				_g_object_unref0 (outbox_id);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				return 0;
			}
			_tmp20_ = _data110_->list;
			gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp20_, GEE_TYPE_COLLECTION, GeeCollection), _tmp17_);
			_g_object_unref0 (_tmp17_);
			_geary_outbox_folder_outbox_row_unref0 (row);
			_g_object_unref0 (outbox_id);
			_g_object_unref0 (id);
		}
		_g_object_unref0 (_id_it);
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	return result;
}

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

static void
geary_outbox_folder_list_email_by_sparse_id_async_ready (GObject* source_object,
                                                         GAsyncResult* _res_,
                                                         gpointer _user_data_)
{
	GearyOutboxFolderListEmailBySparseIdAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_outbox_folder_real_list_email_by_sparse_id_async_co (_data_);
}

static gboolean
geary_outbox_folder_real_list_email_by_sparse_id_async_co (GearyOutboxFolderListEmailBySparseIdAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data110_ = g_slice_new0 (Block110Data);
	_data_->_data110_->_ref_count_ = 1;
	_data_->_data110_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data110_->ids);
	_data_->_data110_->ids = _data_->ids;
	_g_object_unref0 (_data_->_data110_->cancellable);
	_data_->_data110_->cancellable = _data_->cancellable;
	_data_->_data110_->_async_data_ = _data_;
	geary_abstract_local_folder_check_open (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_ABSTRACT_LOCAL_FOLDER, GearyAbstractLocalFolder), &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block110_data_unref (_data_->_data110_);
		_data_->_data110_ = 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_->_data110_->list = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEE_TYPE_LIST, GeeList);
	_data_->_tmp1_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp1_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda123__geary_db_transaction_method, _data_->_data110_, _data_->_data110_->cancellable, geary_outbox_folder_list_email_by_sparse_id_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (_data_->_tmp1_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block110_data_unref (_data_->_data110_);
		_data_->_data110_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp3_ = _data_->_data110_->list;
	_data_->_tmp4_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp3_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp5_ = _data_->_tmp4_;
	if (_data_->_tmp5_ > 0) {
		_data_->_tmp6_ = _data_->_data110_->list;
		_data_->_tmp2_ = _data_->_tmp6_;
	} else {
		_data_->_tmp2_ = NULL;
	}
	_data_->_tmp7_ = _g_object_ref0 (_data_->_tmp2_);
	_data_->result = _data_->_tmp7_;
	block110_data_unref (_data_->_data110_);
	_data_->_data110_ = 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_outbox_folder_real_fetch_email_async_data_free (gpointer _data)
{
	GearyOutboxFolderFetchEmailAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->id);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyOutboxFolderFetchEmailAsyncData, _data_);
}

static void
geary_outbox_folder_real_fetch_email_async (GearyFolder* base,
                                            GearyEmailIdentifier* id,
                                            GearyEmailField required_fields,
                                            GearyFolderListFlags flags,
                                            GCancellable* cancellable,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_)
{
	GearyOutboxFolder * self;
	GearyOutboxFolderFetchEmailAsyncData* _data_;
	GearyOutboxFolder* _tmp0_;
	GearyEmailIdentifier* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IS_EMAIL_IDENTIFIER (id));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_OUTBOX_TYPE_FOLDER, GearyOutboxFolder);
	_data_ = g_slice_new0 (GearyOutboxFolderFetchEmailAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_outbox_folder_real_fetch_email_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (id);
	_g_object_unref0 (_data_->id);
	_data_->id = _tmp1_;
	_data_->required_fields = required_fields;
	_data_->flags = flags;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_outbox_folder_real_fetch_email_async_co (_data_);
}

static GearyEmail*
geary_outbox_folder_fetch_email_finish (GearyFolder* base,
                                        GAsyncResult* _res_,
                                        GError** error)
{
	GearyEmail* result;
	GearyOutboxFolderFetchEmailAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block111Data*
block111_data_ref (Block111Data* _data111_)
{
	g_atomic_int_inc (&_data111_->_ref_count_);
	return _data111_;
}

static void
block111_data_unref (void * _userdata_)
{
	Block111Data* _data111_;
	_data111_ = (Block111Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data111_->_ref_count_)) {
		GearyOutboxFolder* self;
		self = _data111_->self;
		_geary_outbox_folder_outbox_row_unref0 (_data111_->row);
		_g_object_unref0 (_data111_->outbox_id);
		_g_object_unref0 (_data111_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block111Data, _data111_);
	}
}

static GearyDbTransactionOutcome
__lambda124_ (Block111Data* _data111_,
              GearyDbConnection* cx,
              GError** error)
{
	GearyOutboxFolder* self;
	GearyOutboxFolderOutboxRow* _tmp0_ = NULL;
	GearyOutboxEmailIdentifier* _tmp1_;
	gint64 _tmp2_;
	gint64 _tmp3_;
	GearyOutboxFolderOutboxRow* _tmp4_;
	GearyOutboxFolderOutboxRow* _tmp5_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data111_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp1_ = _data111_->outbox_id;
	_tmp2_ = geary_outbox_email_identifier_get_ordering (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = geary_outbox_folder_do_fetch_row_by_ordering (self, cx, _tmp3_, _data111_->cancellable, &_inner_error0_);
	_tmp0_ = _tmp4_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp5_ = _tmp0_;
	_tmp0_ = NULL;
	_geary_outbox_folder_outbox_row_unref0 (_data111_->row);
	_data111_->row = _tmp5_;
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	_geary_outbox_folder_outbox_row_unref0 (_tmp0_);
	return result;
}

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

static void
geary_outbox_folder_fetch_email_async_ready (GObject* source_object,
                                             GAsyncResult* _res_,
                                             gpointer _user_data_)
{
	GearyOutboxFolderFetchEmailAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_outbox_folder_real_fetch_email_async_co (_data_);
}

static gboolean
geary_outbox_folder_real_fetch_email_async_co (GearyOutboxFolderFetchEmailAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data111_ = g_slice_new0 (Block111Data);
	_data_->_data111_->_ref_count_ = 1;
	_data_->_data111_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data111_->cancellable);
	_data_->_data111_->cancellable = _data_->cancellable;
	_data_->_data111_->_async_data_ = _data_;
	geary_abstract_local_folder_check_open (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_ABSTRACT_LOCAL_FOLDER, GearyAbstractLocalFolder), &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block111_data_unref (_data_->_data111_);
		_data_->_data111_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp0_ = _g_object_ref0 (GEARY_OUTBOX_IS_EMAIL_IDENTIFIER (_data_->id) ? ((GearyOutboxEmailIdentifier*) _data_->id) : NULL);
	_data_->_data111_->outbox_id = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->_data111_->outbox_id;
	if (_data_->_tmp1_ == NULL) {
		_data_->_tmp2_ = geary_email_identifier_to_string (_data_->id);
		_data_->_tmp3_ = _data_->_tmp2_;
		_data_->_tmp4_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_BAD_PARAMETERS, "%s is not outbox EmailIdentifier", _data_->_tmp3_);
		_data_->_tmp5_ = _data_->_tmp4_;
		_g_free0 (_data_->_tmp3_);
		_data_->_inner_error0_ = _data_->_tmp5_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block111_data_unref (_data_->_data111_);
		_data_->_data111_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_data111_->row = NULL;
	_data_->_tmp6_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp6_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda124__geary_db_transaction_method, _data_->_data111_, _data_->_data111_->cancellable, geary_outbox_folder_fetch_email_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (_data_->_tmp6_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block111_data_unref (_data_->_data111_);
		_data_->_data111_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp7_ = _data_->_data111_->row;
	if (_data_->_tmp7_ == NULL) {
		_data_->_tmp8_ = geary_email_identifier_to_string (_data_->id);
		_data_->_tmp9_ = _data_->_tmp8_;
		_data_->_tmp10_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_NOT_FOUND, "No message with ID %s in outbox", _data_->_tmp9_);
		_data_->_tmp11_ = _data_->_tmp10_;
		_g_free0 (_data_->_tmp9_);
		_data_->_inner_error0_ = _data_->_tmp11_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block111_data_unref (_data_->_data111_);
		_data_->_data111_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp13_ = _data_->_data111_->row;
	_data_->_tmp14_ = geary_outbox_folder_row_to_email (_data_->self, _data_->_tmp13_, &_data_->_inner_error0_);
	_data_->_tmp12_ = _data_->_tmp14_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block111_data_unref (_data_->_data111_);
		_data_->_data111_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp15_ = _data_->_tmp12_;
	_data_->_tmp12_ = NULL;
	_data_->result = _data_->_tmp15_;
	_g_object_unref0 (_data_->_tmp12_);
	block111_data_unref (_data_->_data111_);
	_data_->_data111_ = 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_outbox_folder_real_set_used_as_custom (GearyFolder* base,
                                             gboolean enabled,
                                             GError** error)
{
	GearyOutboxFolder * self;
	GError* _tmp0_;
	GError* _inner_error0_ = NULL;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_OUTBOX_TYPE_FOLDER, GearyOutboxFolder);
	_tmp0_ = g_error_new_literal (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_UNSUPPORTED, "Folder special use cannot be changed");
	_inner_error0_ = _tmp0_;
	if (_inner_error0_->domain == GEARY_ENGINE_ERROR) {
		g_propagate_error (error, _inner_error0_);
		return;
	} else {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
}

static GearyEmail*
geary_outbox_folder_row_to_email (GearyOutboxFolder* self,
                                  GearyOutboxFolderOutboxRow* row,
                                  GError** error)
{
	GearyEmail* email = NULL;
	GearyMemoryBuffer* _tmp0_;
	GError* _inner_error0_ = NULL;
	GearyEmail* result;
	g_return_val_if_fail (GEARY_OUTBOX_IS_FOLDER (self), NULL);
	g_return_val_if_fail (GEARY_OUTBOX_FOLDER_IS_OUTBOX_ROW (row), NULL);
	email = NULL;
	_tmp0_ = row->message;
	if (_tmp0_ == NULL) {
		GearyOutboxEmailIdentifier* _tmp1_;
		GearyEmail* _tmp2_;
		_tmp1_ = row->outbox_id;
		_tmp2_ = geary_email_new (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEARY_TYPE_EMAIL_IDENTIFIER, GearyEmailIdentifier));
		_g_object_unref0 (email);
		email = _tmp2_;
	} else {
		GearyRFC822Message* message = NULL;
		GearyMemoryBuffer* _tmp3_;
		GearyRFC822Message* _tmp4_;
		GearyEmail* _tmp5_ = NULL;
		GearyOutboxEmailIdentifier* _tmp6_;
		GearyRFC822Message* _tmp7_;
		GearyEmail* _tmp8_;
		GearyEmail* _tmp9_;
		GearyEmail* _tmp10_;
		GDateTime* _tmp11_;
		GDateTime* _tmp12_;
		GearyOutboxEmailProperties* _tmp13_;
		GearyOutboxEmailProperties* _tmp14_;
		GearyEmailFlags* flags = NULL;
		GearyEmailFlags* _tmp15_;
		GearyEmail* _tmp20_;
		GearyEmailFlags* _tmp21_;
		_tmp3_ = row->message;
		_tmp4_ = geary_rf_c822_message_new_from_buffer (_tmp3_, &_inner_error0_);
		message = _tmp4_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (email);
			return NULL;
		}
		_tmp6_ = row->outbox_id;
		_tmp7_ = message;
		_tmp8_ = geary_email_new_from_message (G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, GEARY_TYPE_EMAIL_IDENTIFIER, GearyEmailIdentifier), _tmp7_, &_inner_error0_);
		_tmp5_ = _tmp8_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (message);
			_g_object_unref0 (email);
			return NULL;
		}
		_tmp9_ = _tmp5_;
		_tmp5_ = NULL;
		_g_object_unref0 (email);
		email = _tmp9_;
		_tmp10_ = email;
		_tmp11_ = g_date_time_new_now_local ();
		_tmp12_ = _tmp11_;
		_tmp13_ = geary_outbox_email_properties_new (_tmp12_, (glong) -1);
		_tmp14_ = _tmp13_;
		geary_email_set_email_properties (_tmp10_, G_TYPE_CHECK_INSTANCE_CAST (_tmp14_, GEARY_TYPE_EMAIL_PROPERTIES, GearyEmailProperties));
		_g_object_unref0 (_tmp14_);
		_g_date_time_unref0 (_tmp12_);
		_tmp15_ = geary_email_flags_new ();
		flags = _tmp15_;
		if (row->sent) {
			GearyEmailFlags* _tmp16_;
			GearyNamedFlag* _tmp17_;
			GearyNamedFlag* _tmp18_;
			GearyNamedFlag* _tmp19_;
			_tmp16_ = flags;
			_tmp17_ = geary_email_flags_get_OUTBOX_SENT ();
			_tmp18_ = _tmp17_;
			_tmp19_ = _tmp18_;
			geary_named_flags_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp16_, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags), _tmp19_);
			_g_object_unref0 (_tmp19_);
		}
		_tmp20_ = email;
		_tmp21_ = flags;
		geary_email_set_flags (_tmp20_, _tmp21_);
		_g_object_unref0 (flags);
		_g_object_unref0 (_tmp5_);
		_g_object_unref0 (message);
	}
	result = email;
	return result;
}

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

static void
geary_outbox_folder_get_email_count_async (GearyOutboxFolder* self,
                                           GCancellable* cancellable,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_)
{
	GearyOutboxFolderGetEmailCountAsyncData* _data_;
	GearyOutboxFolder* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_OUTBOX_IS_FOLDER (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyOutboxFolderGetEmailCountAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_outbox_folder_get_email_count_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_outbox_folder_get_email_count_async_co (_data_);
}

static gint
geary_outbox_folder_get_email_count_finish (GearyOutboxFolder* self,
                                            GAsyncResult* _res_,
                                            GError** error)
{
	gint result;
	GearyOutboxFolderGetEmailCountAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		gint _tmp0_ = 0;
		return _tmp0_;
	}
	result = _data_->result;
	return result;
}

static Block112Data*
block112_data_ref (Block112Data* _data112_)
{
	g_atomic_int_inc (&_data112_->_ref_count_);
	return _data112_;
}

static void
block112_data_unref (void * _userdata_)
{
	Block112Data* _data112_;
	_data112_ = (Block112Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data112_->_ref_count_)) {
		GearyOutboxFolder* self;
		self = _data112_->self;
		_g_object_unref0 (_data112_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block112Data, _data112_);
	}
}

static GearyDbTransactionOutcome
__lambda118_ (Block112Data* _data112_,
              GearyDbConnection* cx,
              GError** error)
{
	GearyOutboxFolder* self;
	gint _tmp0_ = 0;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data112_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_outbox_folder_do_get_email_count (self, cx, _data112_->cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_data112_->count = _tmp0_;
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	return result;
}

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

static void
geary_outbox_folder_get_email_count_async_ready (GObject* source_object,
                                                 GAsyncResult* _res_,
                                                 gpointer _user_data_)
{
	GearyOutboxFolderGetEmailCountAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_outbox_folder_get_email_count_async_co (_data_);
}

static gboolean
geary_outbox_folder_get_email_count_async_co (GearyOutboxFolderGetEmailCountAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data112_ = g_slice_new0 (Block112Data);
	_data_->_data112_->_ref_count_ = 1;
	_data_->_data112_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data112_->cancellable);
	_data_->_data112_->cancellable = _data_->cancellable;
	_data_->_data112_->_async_data_ = _data_;
	_data_->_data112_->count = 0;
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda118__geary_db_transaction_method, _data_->_data112_, _data_->_data112_->cancellable, geary_outbox_folder_get_email_count_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (_data_->_tmp0_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block112_data_unref (_data_->_data112_);
		_data_->_data112_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->result = _data_->_data112_->count;
	block112_data_unref (_data_->_data112_);
	_data_->_data112_ = 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 gint64
geary_outbox_folder_do_get_next_ordering (GearyOutboxFolder* self,
                                          GearyDbConnection* cx,
                                          GCancellable* cancellable,
                                          GError** error)
{
	GError* _inner_error0_ = NULL;
	gint64 result;
	g_return_val_if_fail (GEARY_OUTBOX_IS_FOLDER (self), 0LL);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0LL);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), 0LL);
	{
		gint64 _tmp10_ = -1LL;
		g_rec_mutex_lock (&self->priv->__lock_next_ordering);
		{
			gint64 _tmp8_;
			if (self->priv->next_ordering == ((gint64) 0)) {
				GearyDbStatement* stmt = NULL;
				GearyDbStatement* _tmp0_;
				GearyDbResult* _result_ = NULL;
				GearyDbStatement* _tmp1_;
				GearyDbResult* _tmp2_;
				GearyDbResult* _tmp3_;
				gboolean _tmp4_;
				gboolean _tmp5_;
				_tmp0_ = geary_db_connection_prepare (cx, "SELECT COALESCE(MAX(ordering), 0) + 1 FROM SmtpOutboxTable", &_inner_error0_);
				stmt = _tmp0_;
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					goto __catch0_g_error;
				}
				_tmp1_ = stmt;
				_tmp2_ = geary_db_statement_exec (_tmp1_, cancellable, &_inner_error0_);
				_result_ = _tmp2_;
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					_g_object_unref0 (stmt);
					goto __catch0_g_error;
				}
				_tmp3_ = _result_;
				_tmp4_ = geary_db_result_get_finished (_tmp3_);
				_tmp5_ = _tmp4_;
				if (!_tmp5_) {
					gint64 _tmp6_ = 0LL;
					GearyDbResult* _tmp7_;
					_tmp7_ = _result_;
					_tmp6_ = geary_db_result_int64_at (_tmp7_, 0, &_inner_error0_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						_g_object_unref0 (_result_);
						_g_object_unref0 (stmt);
						goto __catch0_g_error;
					}
					self->priv->next_ordering = _tmp6_;
				}
				_vala_assert (self->priv->next_ordering > ((gint64) 0), "next_ordering > 0");
				_g_object_unref0 (_result_);
				_g_object_unref0 (stmt);
			}
			_tmp8_ = self->priv->next_ordering;
			self->priv->next_ordering = _tmp8_ + 1;
			result = _tmp8_;
			{
				GError* _inner_error0_ = NULL;
				g_rec_mutex_unlock (&self->priv->__lock_next_ordering);
			}
			return result;
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* _lock_error_ = NULL;
			GError* _tmp9_;
			_lock_error_ = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp9_ = _lock_error_;
			_lock_error_ = NULL;
			_inner_error0_ = _tmp9_;
			_g_error_free0 (_lock_error_);
			goto __finally0;
		}
		__finally0:
		{
			GError* _inner_error1_ = NULL;
			g_rec_mutex_unlock (&self->priv->__lock_next_ordering);
		}
		g_propagate_error (error, _inner_error0_);
		return _tmp10_;
	}
}

static gint
geary_outbox_folder_do_get_email_count (GearyOutboxFolder* self,
                                        GearyDbConnection* cx,
                                        GCancellable* cancellable,
                                        GError** error)
{
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbResult* results = NULL;
	GearyDbStatement* _tmp2_;
	GearyDbResult* _tmp3_;
	gint _tmp5_ = 0;
	GearyDbResult* _tmp6_;
	gboolean _tmp7_;
	gboolean _tmp8_;
	GError* _inner_error0_ = NULL;
	gint result;
	g_return_val_if_fail (GEARY_OUTBOX_IS_FOLDER (self), 0);
	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);
	_tmp0_ = geary_db_connection_prepare (cx, "SELECT COUNT(*) FROM SmtpOutboxTable", &_inner_error0_);
	stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp1_ = -1;
		g_propagate_error (error, _inner_error0_);
		return _tmp1_;
	}
	_tmp2_ = stmt;
	_tmp3_ = geary_db_statement_exec (_tmp2_, cancellable, &_inner_error0_);
	results = _tmp3_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp4_ = -1;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return _tmp4_;
	}
	_tmp6_ = results;
	_tmp7_ = geary_db_result_get_finished (_tmp6_);
	_tmp8_ = _tmp7_;
	if (!_tmp8_) {
		GearyDbResult* _tmp9_;
		_tmp9_ = results;
		_tmp5_ = geary_db_result_int_at (_tmp9_, 0, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gint _tmp10_ = -1;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			return _tmp10_;
		}
	} else {
		_tmp5_ = 0;
	}
	result = _tmp5_;
	_g_object_unref0 (results);
	_g_object_unref0 (stmt);
	return result;
}

static gint
geary_outbox_folder_do_get_position_by_ordering (GearyOutboxFolder* self,
                                                 GearyDbConnection* cx,
                                                 gint64 ordering,
                                                 GCancellable* cancellable,
                                                 GError** error)
{
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbResult* results = NULL;
	GearyDbStatement* _tmp6_;
	GearyDbResult* _tmp7_;
	GearyDbResult* _tmp9_;
	gboolean _tmp10_;
	gboolean _tmp11_;
	gint64 _tmp12_ = 0LL;
	GearyDbResult* _tmp13_;
	gint _tmp15_ = 0;
	GearyDbResult* _tmp16_;
	GError* _inner_error0_ = NULL;
	gint result;
	g_return_val_if_fail (GEARY_OUTBOX_IS_FOLDER (self), 0);
	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);
	_tmp0_ = geary_db_connection_prepare (cx, "SELECT COUNT(*), MAX(ordering) FROM SmtpOutboxTable WHERE ordering <= " \
"? ORDER BY ordering ASC", &_inner_error0_);
	stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp1_ = -1;
		g_propagate_error (error, _inner_error0_);
		return _tmp1_;
	}
	_tmp2_ = stmt;
	_tmp3_ = geary_db_statement_bind_int64 (_tmp2_, 0, ordering, &_inner_error0_);
	_tmp4_ = _tmp3_;
	_g_object_unref0 (_tmp4_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp5_ = -1;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return _tmp5_;
	}
	_tmp6_ = stmt;
	_tmp7_ = geary_db_statement_exec (_tmp6_, cancellable, &_inner_error0_);
	results = _tmp7_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp8_ = -1;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return _tmp8_;
	}
	_tmp9_ = results;
	_tmp10_ = geary_db_result_get_finished (_tmp9_);
	_tmp11_ = _tmp10_;
	if (_tmp11_) {
		result = -1;
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		return result;
	}
	_tmp13_ = results;
	_tmp12_ = geary_db_result_int64_at (_tmp13_, 1, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp14_ = -1;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		return _tmp14_;
	}
	if (_tmp12_ != ordering) {
		result = -1;
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		return result;
	}
	_tmp16_ = results;
	_tmp15_ = geary_db_result_int_at (_tmp16_, 0, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp17_ = -1;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		return _tmp17_;
	}
	result = _tmp15_ + 1;
	_g_object_unref0 (results);
	_g_object_unref0 (stmt);
	return result;
}

static GearyOutboxFolderOutboxRow*
geary_outbox_folder_do_fetch_row_by_ordering (GearyOutboxFolder* self,
                                              GearyDbConnection* cx,
                                              gint64 ordering,
                                              GCancellable* cancellable,
                                              GError** error)
{
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp1_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbResult* results = NULL;
	GearyDbStatement* _tmp4_;
	GearyDbResult* _tmp5_;
	GearyDbResult* _tmp6_;
	gboolean _tmp7_;
	gboolean _tmp8_;
	gint position = 0;
	gint64 _tmp9_ = 0LL;
	GearyDbResult* _tmp10_;
	gboolean _tmp11_ = FALSE;
	GearyDbResult* _tmp12_;
	GearyMemoryBuffer* _tmp13_ = NULL;
	GearyDbResult* _tmp14_;
	GearyMemoryBuffer* _tmp15_;
	GearyOutboxFolderOutboxRow* _tmp16_;
	GError* _inner_error0_ = NULL;
	GearyOutboxFolderOutboxRow* result;
	g_return_val_if_fail (GEARY_OUTBOX_IS_FOLDER (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, "\n" \
"            SELECT id, message, sent\n" \
"            FROM SmtpOutboxTable\n" \
"            WHERE ordering=?\n" \
"        ", &_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, ordering, &_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_);
	results = _tmp5_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp6_ = results;
	_tmp7_ = geary_db_result_get_finished (_tmp6_);
	_tmp8_ = _tmp7_;
	if (_tmp8_) {
		result = NULL;
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		return result;
	}
	position = geary_outbox_folder_do_get_position_by_ordering (self, cx, ordering, cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		return NULL;
	}
	if (position < 1) {
		result = NULL;
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		return result;
	}
	_tmp10_ = results;
	_tmp9_ = geary_db_result_rowid_at (_tmp10_, 0, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp12_ = results;
	_tmp11_ = geary_db_result_bool_at (_tmp12_, 2, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp14_ = results;
	_tmp15_ = geary_db_result_string_buffer_at (_tmp14_, 1, &_inner_error0_);
	_tmp13_ = _tmp15_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp16_ = geary_outbox_folder_outbox_row_new (_tmp9_, position, ordering, _tmp11_, _tmp13_);
	result = _tmp16_;
	_g_object_unref0 (_tmp13_);
	_g_object_unref0 (results);
	_g_object_unref0 (stmt);
	return result;
}

static void
geary_outbox_folder_do_mark_email_as_sent (GearyOutboxFolder* self,
                                           GearyDbConnection* cx,
                                           GearyOutboxEmailIdentifier* id,
                                           GCancellable* cancellable,
                                           GError** error)
{
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp1_;
	gint64 _tmp2_;
	gint64 _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbStatement* _tmp5_;
	GearyDbStatement* _tmp6_;
	GearyDbResult* _tmp7_;
	GearyDbResult* _tmp8_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_OUTBOX_IS_FOLDER (self));
	g_return_if_fail (GEARY_DB_IS_CONNECTION (cx));
	g_return_if_fail (GEARY_OUTBOX_IS_EMAIL_IDENTIFIER (id));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_tmp0_ = geary_db_connection_prepare (cx, "UPDATE SmtpOutboxTable SET sent = 1 WHERE ordering = ?", &_inner_error0_);
	stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	_tmp1_ = stmt;
	_tmp2_ = geary_outbox_email_identifier_get_ordering (id);
	_tmp3_ = _tmp2_;
	_tmp4_ = geary_db_statement_bind_int64 (_tmp1_, 0, _tmp3_, &_inner_error0_);
	_tmp5_ = _tmp4_;
	_g_object_unref0 (_tmp5_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	_tmp6_ = stmt;
	_tmp7_ = geary_db_statement_exec (_tmp6_, cancellable, &_inner_error0_);
	_tmp8_ = _tmp7_;
	_g_object_unref0 (_tmp8_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	_g_object_unref0 (stmt);
}

static gboolean
geary_outbox_folder_do_remove_email (GearyOutboxFolder* self,
                                     GearyDbConnection* cx,
                                     GearyOutboxEmailIdentifier* id,
                                     GCancellable* cancellable,
                                     GError** error)
{
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp2_;
	gint64 _tmp3_;
	gint64 _tmp4_;
	GearyDbStatement* _tmp5_;
	GearyDbStatement* _tmp6_;
	gint _tmp8_ = 0;
	GearyDbStatement* _tmp9_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (GEARY_OUTBOX_IS_FOLDER (self), FALSE);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), FALSE);
	g_return_val_if_fail (GEARY_OUTBOX_IS_EMAIL_IDENTIFIER (id), 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, "DELETE FROM SmtpOutboxTable WHERE ordering=?", &_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_outbox_email_identifier_get_ordering (id);
	_tmp4_ = _tmp3_;
	_tmp5_ = geary_db_statement_bind_int64 (_tmp2_, 0, _tmp4_, &_inner_error0_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp6_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp7_ = FALSE;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return _tmp7_;
	}
	_tmp9_ = stmt;
	_tmp8_ = geary_db_statement_exec_get_modified (_tmp9_, cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp10_ = FALSE;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return _tmp10_;
	}
	result = _tmp8_ > 0;
	_g_object_unref0 (stmt);
	return result;
}

static GearyOutboxFolderOutboxRow*
geary_outbox_folder_outbox_row_construct (GType object_type,
                                          gint64 id,
                                          gint position,
                                          gint64 ordering,
                                          gboolean sent,
                                          GearyMemoryBuffer* message)
{
	GearyOutboxFolderOutboxRow* self = NULL;
	GearyMemoryBuffer* _tmp0_;
	GearyOutboxEmailIdentifier* _tmp1_;
	g_return_val_if_fail ((message == NULL) || GEARY_MEMORY_IS_BUFFER (message), NULL);
	self = (GearyOutboxFolderOutboxRow*) g_type_create_instance (object_type);
	_vala_assert (position >= 1, "position >= 1");
	self->id = id;
	self->position = position;
	self->ordering = ordering;
	self->sent = sent;
	_tmp0_ = _g_object_ref0 (message);
	_g_object_unref0 (self->message);
	self->message = _tmp0_;
	_tmp1_ = geary_outbox_email_identifier_new (id, ordering);
	_g_object_unref0 (self->outbox_id);
	self->outbox_id = _tmp1_;
	return self;
}

static GearyOutboxFolderOutboxRow*
geary_outbox_folder_outbox_row_new (gint64 id,
                                    gint position,
                                    gint64 ordering,
                                    gboolean sent,
                                    GearyMemoryBuffer* message)
{
	return geary_outbox_folder_outbox_row_construct (GEARY_OUTBOX_FOLDER_TYPE_OUTBOX_ROW, id, position, ordering, sent, message);
}

static void
geary_outbox_folder_value_outbox_row_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
geary_outbox_folder_value_outbox_row_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		geary_outbox_folder_outbox_row_unref (value->data[0].v_pointer);
	}
}

static void
geary_outbox_folder_value_outbox_row_copy_value (const GValue* src_value,
                                                 GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = geary_outbox_folder_outbox_row_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
geary_outbox_folder_value_outbox_row_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
geary_outbox_folder_value_outbox_row_collect_value (GValue* value,
                                                    guint n_collect_values,
                                                    GTypeCValue* collect_values,
                                                    guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		GearyOutboxFolderOutboxRow * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = geary_outbox_folder_outbox_row_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
geary_outbox_folder_value_outbox_row_lcopy_value (const GValue* value,
                                                  guint n_collect_values,
                                                  GTypeCValue* collect_values,
                                                  guint collect_flags)
{
	GearyOutboxFolderOutboxRow ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = geary_outbox_folder_outbox_row_ref (value->data[0].v_pointer);
	}
	return NULL;
}

static GParamSpec*
geary_outbox_folder_param_spec_outbox_row (const gchar* name,
                                           const gchar* nick,
                                           const gchar* blurb,
                                           GType object_type,
                                           GParamFlags flags)
{
	GearyOutboxFolderParamSpecOutboxRow* spec;
	g_return_val_if_fail (g_type_is_a (object_type, GEARY_OUTBOX_FOLDER_TYPE_OUTBOX_ROW), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

static gpointer
geary_outbox_folder_value_get_outbox_row (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GEARY_OUTBOX_FOLDER_TYPE_OUTBOX_ROW), NULL);
	return value->data[0].v_pointer;
}

static void
geary_outbox_folder_value_set_outbox_row (GValue* value,
                                          gpointer v_object)
{
	GearyOutboxFolderOutboxRow * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GEARY_OUTBOX_FOLDER_TYPE_OUTBOX_ROW));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GEARY_OUTBOX_FOLDER_TYPE_OUTBOX_ROW));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		geary_outbox_folder_outbox_row_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		geary_outbox_folder_outbox_row_unref (old);
	}
}

static void
geary_outbox_folder_value_take_outbox_row (GValue* value,
                                           gpointer v_object)
{
	GearyOutboxFolderOutboxRow * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GEARY_OUTBOX_FOLDER_TYPE_OUTBOX_ROW));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GEARY_OUTBOX_FOLDER_TYPE_OUTBOX_ROW));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		geary_outbox_folder_outbox_row_unref (old);
	}
}

static void
geary_outbox_folder_outbox_row_class_init (GearyOutboxFolderOutboxRowClass * klass,
                                           gpointer klass_data)
{
	geary_outbox_folder_outbox_row_parent_class = g_type_class_peek_parent (klass);
	((GearyOutboxFolderOutboxRowClass *) klass)->finalize = geary_outbox_folder_outbox_row_finalize;
}

static void
geary_outbox_folder_outbox_row_instance_init (GearyOutboxFolderOutboxRow * self,
                                              gpointer klass)
{
	self->ref_count = 1;
}

static void
geary_outbox_folder_outbox_row_finalize (GearyOutboxFolderOutboxRow * obj)
{
	GearyOutboxFolderOutboxRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_OUTBOX_FOLDER_TYPE_OUTBOX_ROW, GearyOutboxFolderOutboxRow);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->message);
	_g_object_unref0 (self->outbox_id);
}

 G_GNUC_NO_INLINE static GType
geary_outbox_folder_outbox_row_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { geary_outbox_folder_value_outbox_row_init, geary_outbox_folder_value_outbox_row_free_value, geary_outbox_folder_value_outbox_row_copy_value, geary_outbox_folder_value_outbox_row_peek_pointer, "p", geary_outbox_folder_value_outbox_row_collect_value, "p", geary_outbox_folder_value_outbox_row_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (GearyOutboxFolderOutboxRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_outbox_folder_outbox_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyOutboxFolderOutboxRow), 0, (GInstanceInitFunc) geary_outbox_folder_outbox_row_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType geary_outbox_folder_outbox_row_type_id;
	geary_outbox_folder_outbox_row_type_id = g_type_register_fundamental (g_type_fundamental_next (), "GearyOutboxFolderOutboxRow", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return geary_outbox_folder_outbox_row_type_id;
}

static GType
geary_outbox_folder_outbox_row_get_type (void)
{
	static gsize geary_outbox_folder_outbox_row_type_id__once = 0;
	if (g_once_init_enter (&geary_outbox_folder_outbox_row_type_id__once)) {
		GType geary_outbox_folder_outbox_row_type_id;
		geary_outbox_folder_outbox_row_type_id = geary_outbox_folder_outbox_row_get_type_once ();
		g_once_init_leave (&geary_outbox_folder_outbox_row_type_id__once, geary_outbox_folder_outbox_row_type_id);
	}
	return geary_outbox_folder_outbox_row_type_id__once;
}

static gpointer
geary_outbox_folder_outbox_row_ref (gpointer instance)
{
	GearyOutboxFolderOutboxRow * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

static void
geary_outbox_folder_outbox_row_unref (gpointer instance)
{
	GearyOutboxFolderOutboxRow * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		GEARY_OUTBOX_FOLDER_OUTBOX_ROW_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static void
geary_outbox_folder_class_init (GearyOutboxFolderClass * klass,
                                gpointer klass_data)
{
	geary_outbox_folder_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GearyOutboxFolder_private_offset);
	((GearyFolderClass *) klass)->open_async = (void (*) (GearyFolder*, GearyFolderOpenFlags, GCancellable*, GAsyncReadyCallback, gpointer)) geary_outbox_folder_real_open_async;
	((GearyFolderClass *) klass)->open_finish = (gboolean (*) (GearyFolder*, GAsyncResult*, GError**)) geary_outbox_folder_open_finish;
	((GearyFolderClass *) klass)->close_async = (void (*) (GearyFolder*, GCancellable*, GAsyncReadyCallback, gpointer)) geary_outbox_folder_real_close_async;
	((GearyFolderClass *) klass)->close_finish = (gboolean (*) (GearyFolder*, GAsyncResult*, GError**)) geary_outbox_folder_close_finish;
	((GearyOutboxFolderClass *) klass)->create_email_async = (void (*) (GearyOutboxFolder*, GearyRFC822Message*, GearyEmailFlags*, GDateTime*, GCancellable*, GAsyncReadyCallback, gpointer)) geary_outbox_folder_real_create_email_async;
	((GearyOutboxFolderClass *) klass)->create_email_finish = (GearyEmailIdentifier* (*) (GearyOutboxFolder*, GAsyncResult*, GError**)) geary_outbox_folder_real_create_email_finish;
	((GearyOutboxFolderClass *) klass)->mark_email_async = (void (*) (GearyOutboxFolder*, GeeCollection*, GearyEmailFlags*, GearyEmailFlags*, GCancellable*, GAsyncReadyCallback, gpointer)) geary_outbox_folder_real_mark_email_async;
	((GearyOutboxFolderClass *) klass)->mark_email_finish = (void (*) (GearyOutboxFolder*, GAsyncResult*, GError**)) geary_outbox_folder_real_mark_email_finish;
	((GearyOutboxFolderClass *) klass)->remove_email_async = (void (*) (GearyOutboxFolder*, GeeCollection*, GCancellable*, GAsyncReadyCallback, gpointer)) geary_outbox_folder_real_remove_email_async;
	((GearyOutboxFolderClass *) klass)->remove_email_finish = (void (*) (GearyOutboxFolder*, GAsyncResult*, GError**)) geary_outbox_folder_real_remove_email_finish;
	((GearyFolderClass *) klass)->contains_identifiers = (void (*) (GearyFolder*, GeeCollection*, GCancellable*, GAsyncReadyCallback, gpointer)) geary_outbox_folder_real_contains_identifiers;
	((GearyFolderClass *) klass)->contains_identifiers_finish = (GeeCollection* (*) (GearyFolder*, GAsyncResult*, GError**)) geary_outbox_folder_contains_identifiers_finish;
	((GearyFolderClass *) klass)->list_email_by_id_async = (void (*) (GearyFolder*, GearyEmailIdentifier*, gint, GearyEmailField, GearyFolderListFlags, GCancellable*, GAsyncReadyCallback, gpointer)) geary_outbox_folder_real_list_email_by_id_async;
	((GearyFolderClass *) klass)->list_email_by_id_finish = (GeeList* (*) (GearyFolder*, GAsyncResult*, GError**)) geary_outbox_folder_list_email_by_id_finish;
	((GearyFolderClass *) klass)->list_email_by_sparse_id_async = (void (*) (GearyFolder*, GeeCollection*, GearyEmailField, GearyFolderListFlags, GCancellable*, GAsyncReadyCallback, gpointer)) geary_outbox_folder_real_list_email_by_sparse_id_async;
	((GearyFolderClass *) klass)->list_email_by_sparse_id_finish = (GeeList* (*) (GearyFolder*, GAsyncResult*, GError**)) geary_outbox_folder_list_email_by_sparse_id_finish;
	((GearyFolderClass *) klass)->fetch_email_async = (void (*) (GearyFolder*, GearyEmailIdentifier*, GearyEmailField, GearyFolderListFlags, GCancellable*, GAsyncReadyCallback, gpointer)) geary_outbox_folder_real_fetch_email_async;
	((GearyFolderClass *) klass)->fetch_email_finish = (GearyEmail* (*) (GearyFolder*, GAsyncResult*, GError**)) geary_outbox_folder_fetch_email_finish;
	((GearyFolderClass *) klass)->set_used_as_custom = (void (*) (GearyFolder*, gboolean, GError**)) geary_outbox_folder_real_set_used_as_custom;
	GEARY_FOLDER_CLASS (klass)->get_account = geary_outbox_folder_real_get_account;
	GEARY_FOLDER_CLASS (klass)->get_properties = geary_outbox_folder_real_get_properties;
	GEARY_FOLDER_CLASS (klass)->get_path = geary_outbox_folder_real_get_path;
	GEARY_FOLDER_CLASS (klass)->get_used_as = geary_outbox_folder_real_get_used_as;
	G_OBJECT_CLASS (klass)->get_property = _vala_geary_outbox_folder_get_property;
	G_OBJECT_CLASS (klass)->finalize = geary_outbox_folder_finalize;
	/** {@inheritDoc} */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_OUTBOX_FOLDER_ACCOUNT_PROPERTY, geary_outbox_folder_properties[GEARY_OUTBOX_FOLDER_ACCOUNT_PROPERTY] = g_param_spec_object ("account", "account", "account", GEARY_TYPE_ACCOUNT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** {@inheritDoc} */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_OUTBOX_FOLDER_PROPERTIES_PROPERTY, geary_outbox_folder_properties[GEARY_OUTBOX_FOLDER_PROPERTIES_PROPERTY] = g_param_spec_object ("properties", "properties", "properties", GEARY_TYPE_FOLDER_PROPERTIES, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/**
	     * Returns the path to this folder.
	     *
	     * This is always the child of the root given to the constructor,
	     * with the name given by {@link MAGIC_BASENAME}.
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_OUTBOX_FOLDER_PATH_PROPERTY, geary_outbox_folder_properties[GEARY_OUTBOX_FOLDER_PATH_PROPERTY] = g_param_spec_object ("path", "path", "path", GEARY_TYPE_FOLDER_PATH, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/**
	     * Returns the type of this folder.
	     *
	     * This is always {@link Folder.SpecialUse.OUTBOX}
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_OUTBOX_FOLDER_USED_AS_PROPERTY, geary_outbox_folder_properties[GEARY_OUTBOX_FOLDER_USED_AS_PROPERTY] = g_param_spec_enum ("used-as", "used-as", "used-as", GEARY_FOLDER_TYPE_SPECIAL_USE, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
geary_outbox_folder_geary_folder_support_create_interface_init (GearyFolderSupportCreateIface * iface,
                                                                gpointer iface_data)
{
	geary_outbox_folder_geary_folder_support_create_parent_iface = g_type_interface_peek_parent (iface);
	iface->create_email_async = (void (*) (GearyFolderSupportCreate*, GearyRFC822Message*, GearyEmailFlags*, GDateTime*, GCancellable*, GAsyncReadyCallback, gpointer)) geary_outbox_folder_create_email_async;
	iface->create_email_finish = (GearyEmailIdentifier* (*) (GearyFolderSupportCreate*, GAsyncResult*, GError**)) geary_outbox_folder_create_email_finish;
}

static void
geary_outbox_folder_geary_folder_support_mark_interface_init (GearyFolderSupportMarkIface * iface,
                                                              gpointer iface_data)
{
	geary_outbox_folder_geary_folder_support_mark_parent_iface = g_type_interface_peek_parent (iface);
	iface->mark_email_async = (void (*) (GearyFolderSupportMark*, GeeCollection*, GearyEmailFlags*, GearyEmailFlags*, GCancellable*, GAsyncReadyCallback, gpointer)) geary_outbox_folder_mark_email_async;
	iface->mark_email_finish = (void (*) (GearyFolderSupportMark*, GAsyncResult*, GError**)) geary_outbox_folder_mark_email_finish;
}

static void
geary_outbox_folder_geary_folder_support_remove_interface_init (GearyFolderSupportRemoveIface * iface,
                                                                gpointer iface_data)
{
	geary_outbox_folder_geary_folder_support_remove_parent_iface = g_type_interface_peek_parent (iface);
	iface->remove_email_async = (void (*) (GearyFolderSupportRemove*, GeeCollection*, GCancellable*, GAsyncReadyCallback, gpointer)) geary_outbox_folder_remove_email_async;
	iface->remove_email_finish = (void (*) (GearyFolderSupportRemove*, GAsyncResult*, GError**)) geary_outbox_folder_remove_email_finish;
}

static void
geary_outbox_folder_instance_init (GearyOutboxFolder * self,
                                   gpointer klass)
{
	GearyOutboxFolderProperties* _tmp0_;
	self->priv = geary_outbox_folder_get_instance_private (self);
	self->priv->db = NULL;
	_tmp0_ = geary_outbox_folder_properties_new (0, 0);
	self->priv->_properties = _tmp0_;
	g_rec_mutex_init (&self->priv->__lock_next_ordering);
	self->priv->next_ordering = (gint64) 0;
}

static void
geary_outbox_folder_finalize (GObject * obj)
{
	GearyOutboxFolder * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_OUTBOX_TYPE_FOLDER, GearyOutboxFolder);
	_g_object_unref0 (self->priv->_path);
	_g_object_unref0 (self->priv->db);
	_g_object_unref0 (self->priv->_properties);
	g_rec_mutex_clear (&self->priv->__lock_next_ordering);
	G_OBJECT_CLASS (geary_outbox_folder_parent_class)->finalize (obj);
}

/**
 * A folder for storing outgoing mail.
 */
 G_GNUC_NO_INLINE static GType
geary_outbox_folder_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyOutboxFolderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_outbox_folder_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyOutboxFolder), 0, (GInstanceInitFunc) geary_outbox_folder_instance_init, NULL };
	static const GInterfaceInfo geary_folder_support_create_info = { (GInterfaceInitFunc) geary_outbox_folder_geary_folder_support_create_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	static const GInterfaceInfo geary_folder_support_mark_info = { (GInterfaceInitFunc) geary_outbox_folder_geary_folder_support_mark_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	static const GInterfaceInfo geary_folder_support_remove_info = { (GInterfaceInitFunc) geary_outbox_folder_geary_folder_support_remove_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType geary_outbox_folder_type_id;
	geary_outbox_folder_type_id = g_type_register_static (GEARY_TYPE_ABSTRACT_LOCAL_FOLDER, "GearyOutboxFolder", &g_define_type_info, 0);
	g_type_add_interface_static (geary_outbox_folder_type_id, GEARY_FOLDER_SUPPORT_TYPE_CREATE, &geary_folder_support_create_info);
	g_type_add_interface_static (geary_outbox_folder_type_id, GEARY_FOLDER_SUPPORT_TYPE_MARK, &geary_folder_support_mark_info);
	g_type_add_interface_static (geary_outbox_folder_type_id, GEARY_FOLDER_SUPPORT_TYPE_REMOVE, &geary_folder_support_remove_info);
	GearyOutboxFolder_private_offset = g_type_add_instance_private (geary_outbox_folder_type_id, sizeof (GearyOutboxFolderPrivate));
	return geary_outbox_folder_type_id;
}

GType
geary_outbox_folder_get_type (void)
{
	static gsize geary_outbox_folder_type_id__once = 0;
	if (g_once_init_enter (&geary_outbox_folder_type_id__once)) {
		GType geary_outbox_folder_type_id;
		geary_outbox_folder_type_id = geary_outbox_folder_get_type_once ();
		g_once_init_leave (&geary_outbox_folder_type_id__once, geary_outbox_folder_type_id);
	}
	return geary_outbox_folder_type_id__once;
}

static void
_vala_geary_outbox_folder_get_property (GObject * object,
                                        guint property_id,
                                        GValue * value,
                                        GParamSpec * pspec)
{
	GearyOutboxFolder * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_OUTBOX_TYPE_FOLDER, GearyOutboxFolder);
	switch (property_id) {
		case GEARY_OUTBOX_FOLDER_ACCOUNT_PROPERTY:
		g_value_set_object (value, geary_folder_get_account (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_TYPE_FOLDER, GearyFolder)));
		break;
		case GEARY_OUTBOX_FOLDER_PROPERTIES_PROPERTY:
		g_value_set_object (value, geary_folder_get_properties (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_TYPE_FOLDER, GearyFolder)));
		break;
		case GEARY_OUTBOX_FOLDER_PATH_PROPERTY:
		g_value_set_object (value, geary_folder_get_path (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_TYPE_FOLDER, GearyFolder)));
		break;
		case GEARY_OUTBOX_FOLDER_USED_AS_PROPERTY:
		g_value_set_enum (value, geary_folder_get_used_as (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_TYPE_FOLDER, GearyFolder)));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

