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

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

#define GEARY_IMAP_DB_FOLDER_REQUIRED_FIELDS ((GEARY_EMAIL_FIELD_PROPERTIES | GEARY_EMAIL_FIELD_REFERENCES) | GEARY_EMAIL_FIELD_FLAGS)
#define GEARY_IMAP_DB_FOLDER_REQUIRED_FTS_FIELDS GEARY_EMAIL_REQUIRED_FOR_MESSAGE
#define GEARY_IMAP_DB_FOLDER_LIST_EMAIL_WITH_MESSAGE_CHUNK_COUNT 10
#define GEARY_IMAP_DB_FOLDER_LIST_EMAIL_METADATA_COUNT 100
#define GEARY_IMAP_DB_FOLDER_LIST_EMAIL_FIELDS_CHUNK_COUNT 500
#define GEARY_IMAP_DB_FOLDER_REMOVE_COMPLETE_LOCATIONS_CHUNK_COUNT 500
#define GEARY_IMAP_DB_FOLDER_CREATE_MERGE_EMAIL_CHUNK_COUNT 10
#define GEARY_IMAP_DB_FOLDER_OLD_MSG_DETACH_BATCH_SIZE 1000
#define GEARY_IMAP_DB_FOLDER_MINIMUM_MESSAGES_TO_RETAIN_DURING_GC 100
#define GEARY_IMAP_DB_ATTACHMENT_REQUIRED_FIELDS GEARY_EMAIL_REQUIRED_FOR_MESSAGE

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

typedef struct _GearyImapDBFolder GearyImapDBFolder;
typedef struct _GearyImapDBFolderClass GearyImapDBFolderClass;
typedef struct _GearyImapDBFolderPrivate GearyImapDBFolderPrivate;
enum  {
	GEARY_IMAP_DB_FOLDER_0_PROPERTY,
	GEARY_IMAP_DB_FOLDER_MANUAL_REF_COUNT_PROPERTY,
	GEARY_IMAP_DB_FOLDER_NUM_PROPERTIES
};
static GParamSpec* geary_imap_db_folder_properties[GEARY_IMAP_DB_FOLDER_NUM_PROPERTIES];
typedef enum  {
	GEARY_IMAP_DB_FOLDER_LIST_FLAGS_NONE = 0,
	GEARY_IMAP_DB_FOLDER_LIST_FLAGS_PARTIAL_OK = 1 << 0,
	GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDE_MARKED_FOR_REMOVE = 1 << 1,
	GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDING_ID = 1 << 2,
	GEARY_IMAP_DB_FOLDER_LIST_FLAGS_OLDEST_TO_NEWEST = 1 << 3,
	GEARY_IMAP_DB_FOLDER_LIST_FLAGS_ONLY_INCOMPLETE = 1 << 4
} GearyImapDBFolderListFlags;

#define GEARY_IMAP_DB_FOLDER_TYPE_LIST_FLAGS (geary_imap_db_folder_list_flags_get_type ())
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

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

typedef struct _GearyImapDBEmailIdentifier GearyImapDBEmailIdentifier;
typedef struct _GearyImapDBEmailIdentifierClass GearyImapDBEmailIdentifierClass;
typedef struct _Block51Data Block51Data;
typedef struct _GearyImapDbFolderGetEmailCountAsyncData GearyImapDbFolderGetEmailCountAsyncData;
typedef struct _Block52Data Block52Data;
typedef struct _GearyImapDbFolderUpdateFolderStatusData GearyImapDbFolderUpdateFolderStatusData;
typedef struct _Block53Data Block53Data;
typedef struct _GearyImapDbFolderUpdateFolderSelectExamineData GearyImapDbFolderUpdateFolderSelectExamineData;
typedef struct _Block54Data Block54Data;
typedef struct _GearyImapDbFolderUpdateRemoteSelectedMessageCountData GearyImapDbFolderUpdateRemoteSelectedMessageCountData;

#define GEARY_TYPE_CONTACT_HARVESTER (geary_contact_harvester_get_type ())
#define GEARY_CONTACT_HARVESTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_TYPE_CONTACT_HARVESTER, GearyContactHarvester))
#define GEARY_IS_CONTACT_HARVESTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_TYPE_CONTACT_HARVESTER))
#define GEARY_CONTACT_HARVESTER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEARY_TYPE_CONTACT_HARVESTER, GearyContactHarvesterIface))

typedef struct _GearyContactHarvester GearyContactHarvester;
typedef struct _GearyContactHarvesterIface GearyContactHarvesterIface;
typedef struct _Block55Data Block55Data;
typedef struct _Block56Data Block56Data;
typedef struct _GearyImapDbFolderCreateOrMergeEmailAsyncData GearyImapDbFolderCreateOrMergeEmailAsyncData;
typedef struct _Block57Data Block57Data;
typedef struct _Block58Data Block58Data;
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
typedef struct _GearyImapDbFolderContainsIdentifiersData GearyImapDbFolderContainsIdentifiersData;

#define GEARY_IMAP_DB_FOLDER_TYPE_LOCATION_IDENTIFIER (geary_imap_db_folder_location_identifier_get_type ())
#define GEARY_IMAP_DB_FOLDER_LOCATION_IDENTIFIER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_DB_FOLDER_TYPE_LOCATION_IDENTIFIER, GearyImapDBFolderLocationIdentifier))
#define GEARY_IMAP_DB_FOLDER_LOCATION_IDENTIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_DB_FOLDER_TYPE_LOCATION_IDENTIFIER, GearyImapDBFolderLocationIdentifierClass))
#define GEARY_IMAP_DB_FOLDER_IS_LOCATION_IDENTIFIER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_DB_FOLDER_TYPE_LOCATION_IDENTIFIER))
#define GEARY_IMAP_DB_FOLDER_IS_LOCATION_IDENTIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_DB_FOLDER_TYPE_LOCATION_IDENTIFIER))
#define GEARY_IMAP_DB_FOLDER_LOCATION_IDENTIFIER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_DB_FOLDER_TYPE_LOCATION_IDENTIFIER, GearyImapDBFolderLocationIdentifierClass))

typedef struct _GearyImapDBFolderLocationIdentifier GearyImapDBFolderLocationIdentifier;
typedef struct _GearyImapDBFolderLocationIdentifierClass GearyImapDBFolderLocationIdentifierClass;
typedef struct _Block59Data Block59Data;
#define _geary_imap_db_folder_location_identifier_unref0(var) ((var == NULL) ? NULL : (var = (geary_imap_db_folder_location_identifier_unref (var), NULL)))
typedef struct _GearyImapDBFolderLocationIdentifierPrivate GearyImapDBFolderLocationIdentifierPrivate;
typedef struct _GearyImapDbFolderListEmailByIdAsyncData GearyImapDbFolderListEmailByIdAsyncData;
typedef struct _Block60Data Block60Data;
typedef struct _GearyImapDbFolderListEmailByRangeAsyncData GearyImapDbFolderListEmailByRangeAsyncData;
typedef struct _Block61Data Block61Data;
typedef struct _GearyImapDbFolderListEmailByUidRangeAsyncData GearyImapDbFolderListEmailByUidRangeAsyncData;
typedef struct _Block62Data Block62Data;
typedef struct _GearyImapDbFolderListEmailBySparseIdAsyncData GearyImapDbFolderListEmailBySparseIdAsyncData;
typedef struct _Block63Data Block63Data;
typedef struct _Block64Data Block64Data;
typedef struct _GearyImapDbFolderRemoveCompleteLocationsInChunksAsyncData GearyImapDbFolderRemoveCompleteLocationsInChunksAsyncData;
typedef struct _Block65Data Block65Data;
typedef struct _Block66Data Block66Data;
typedef struct _GearyImapDbFolderListEmailInChunksAsyncData GearyImapDbFolderListEmailInChunksAsyncData;
typedef struct _Block67Data Block67Data;
typedef struct _GearyImapDbFolderFetchEmailAsyncData GearyImapDbFolderFetchEmailAsyncData;
typedef struct _Block68Data Block68Data;
typedef struct _GearyImapDbFolderListUidsByRangeAsyncData GearyImapDbFolderListUidsByRangeAsyncData;
typedef struct _Block69Data Block69Data;
typedef struct _GearyImapDbFolderGetIdAtAsyncData GearyImapDbFolderGetIdAtAsyncData;
typedef struct _Block70Data Block70Data;
typedef struct _GearyImapDbFolderGetUidAsyncData GearyImapDbFolderGetUidAsyncData;
typedef struct _Block71Data Block71Data;
typedef struct _GearyImapDbFolderGetUidsAsyncData GearyImapDbFolderGetUidsAsyncData;
typedef struct _Block72Data Block72Data;
typedef struct _GearyImapDbFolderGetIdAsyncData GearyImapDbFolderGetIdAsyncData;
typedef struct _Block73Data Block73Data;
typedef struct _GearyImapDbFolderGetIdsAsyncData GearyImapDbFolderGetIdsAsyncData;
typedef struct _GearyImapDbFolderGetEarliestIdAsyncData GearyImapDbFolderGetEarliestIdAsyncData;
typedef struct _GearyImapDbFolderGetLatestIdAsyncData GearyImapDbFolderGetLatestIdAsyncData;
typedef struct _Block74Data Block74Data;
typedef struct _GearyImapDbFolderGetIdExtremesAsyncData GearyImapDbFolderGetIdExtremesAsyncData;
typedef struct _Block75Data Block75Data;
typedef struct _GearyImapDbFolderDetachMultipleEmailsAsyncData GearyImapDbFolderDetachMultipleEmailsAsyncData;
typedef struct _Block76Data Block76Data;
typedef struct _GearyImapDbFolderDetachAllEmailsAsyncData GearyImapDbFolderDetachAllEmailsAsyncData;
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
typedef struct _Block77Data Block77Data;
typedef struct _Block78Data Block78Data;
typedef struct _GearyImapDbFolderDetachEmailsBeforeTimestampData GearyImapDbFolderDetachEmailsBeforeTimestampData;
typedef struct _Block79Data Block79Data;
typedef struct _GearyImapDbFolderMarkEmailAsyncData GearyImapDbFolderMarkEmailAsyncData;
typedef struct _Block80Data Block80Data;
typedef struct _GearyImapDbFolderGetEmailUidsAsyncData GearyImapDbFolderGetEmailUidsAsyncData;
typedef struct _Block81Data Block81Data;
typedef struct _GearyImapDbFolderGetEmailFlagsAsyncData GearyImapDbFolderGetEmailFlagsAsyncData;
typedef struct _Block82Data Block82Data;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _GearyImapDbFolderSetEmailFlagsAsyncData GearyImapDbFolderSetEmailFlagsAsyncData;
typedef struct _Block83Data Block83Data;
typedef struct _GearyImapDbFolderDetachSingleEmailAsyncData GearyImapDbFolderDetachSingleEmailAsyncData;
typedef struct _Block84Data Block84Data;
typedef struct _GearyImapDbFolderMarkRemovedAsyncData GearyImapDbFolderMarkRemovedAsyncData;
typedef struct _Block85Data Block85Data;
typedef struct _GearyImapDbFolderGetMarkedForRemoveCountAsyncData GearyImapDbFolderGetMarkedForRemoveCountAsyncData;
typedef struct _Block86Data Block86Data;
typedef struct _GearyImapDbFolderGetMarkedIdsAsyncData GearyImapDbFolderGetMarkedIdsAsyncData;
typedef struct _Block87Data Block87Data;
typedef struct _GearyImapDbFolderClearRemoveMarkersAsyncData GearyImapDbFolderClearRemoveMarkersAsyncData;
typedef struct _Block88Data Block88Data;
typedef struct _GearyImapDbFolderListEmailFieldsByIdAsyncData GearyImapDbFolderListEmailFieldsByIdAsyncData;

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

typedef struct _GearyImapDBMessageRow GearyImapDBMessageRow;
typedef struct _GearyImapDBMessageRowClass GearyImapDBMessageRowClass;
#define _geary_imap_db_message_row_unref0(var) ((var == NULL) ? NULL : (var = (geary_imap_db_message_row_unref (var), NULL)))

#define GEARY_IMAP_DB_TYPE_ATTACHMENT (geary_imap_db_attachment_get_type ())
#define GEARY_IMAP_DB_ATTACHMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_DB_TYPE_ATTACHMENT, GearyImapDBAttachment))
#define GEARY_IMAP_DB_ATTACHMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_DB_TYPE_ATTACHMENT, GearyImapDBAttachmentClass))
#define GEARY_IMAP_DB_IS_ATTACHMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_DB_TYPE_ATTACHMENT))
#define GEARY_IMAP_DB_IS_ATTACHMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_DB_TYPE_ATTACHMENT))
#define GEARY_IMAP_DB_ATTACHMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_DB_TYPE_ATTACHMENT, GearyImapDBAttachmentClass))

typedef struct _GearyImapDBAttachment GearyImapDBAttachment;
typedef struct _GearyImapDBAttachmentClass GearyImapDBAttachmentClass;
typedef struct _GearyImapDBFolderParamSpecLocationIdentifier GearyImapDBFolderParamSpecLocationIdentifier;
enum  {
	GEARY_IMAP_DB_FOLDER_EMAIL_COMPLETE_SIGNAL,
	GEARY_IMAP_DB_FOLDER_UNREAD_UPDATED_SIGNAL,
	GEARY_IMAP_DB_FOLDER_NUM_SIGNALS
};
static guint geary_imap_db_folder_signals[GEARY_IMAP_DB_FOLDER_NUM_SIGNALS] = {0};
#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 _GearyImapDBFolder {
	GearyBaseObject parent_instance;
	GearyImapDBFolderPrivate * priv;
};

struct _GearyImapDBFolderClass {
	GearyBaseObjectClass parent_class;
};

struct _GearyImapDBFolderPrivate {
	gint _manual_ref_count;
	GearyDbDatabase* db;
	GearyFolderPath* path;
	GFile* attachments_path;
	gchar* account_owner_email;
	gint64 folder_id;
	GearyImapFolderProperties* properties;
};

struct _Block51Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	gint count;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderGetEmailCountAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	gint result;
	Block51Data* _data51_;
	GearyDbDatabase* _tmp0_;
	GError* _inner_error0_;
};

struct _Block52Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	gint adjust_unseen;
	gint adjust_total;
	GearyImapFolderProperties* remote_properties;
	gboolean respect_marked_for_remove;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderUpdateFolderStatusData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GearyImapFolderProperties* remote_properties;
	gboolean respect_marked_for_remove;
	GCancellable* cancellable;
	Block52Data* _data52_;
	GearyDbDatabase* _tmp0_;
	GCancellable* _tmp1_;
	GearyImapFolderProperties* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	GearyImapFolderProperties* _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	GearyImapFolderProperties* _tmp8_;
	GearyImapMailboxAttributes* _tmp9_;
	GearyImapMailboxAttributes* _tmp10_;
	gint _tmp11_;
	gint _tmp12_;
	GearyImapFolderProperties* _tmp13_;
	gint _tmp14_;
	gint _tmp15_;
	GError* _inner_error0_;
};

struct _Block53Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GearyImapFolderProperties* remote_properties;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderUpdateFolderSelectExamineData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GearyImapFolderProperties* remote_properties;
	GCancellable* cancellable;
	Block53Data* _data53_;
	GearyDbDatabase* _tmp0_;
	GearyImapFolderProperties* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	GearyImapFolderProperties* _tmp4_;
	gint _tmp5_;
	gint _tmp6_;
	GearyImapFolderProperties* _tmp7_;
	GearyImapUIDValidity* _tmp8_;
	GearyImapUIDValidity* _tmp9_;
	GearyImapFolderProperties* _tmp10_;
	GearyImapUID* _tmp11_;
	GearyImapUID* _tmp12_;
	gint _tmp13_;
	gint _tmp14_;
	GearyImapFolderProperties* _tmp15_;
	gint _tmp16_;
	gint _tmp17_;
	GError* _inner_error0_;
};

struct _Block54Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	gint count;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderUpdateRemoteSelectedMessageCountData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	gint count;
	GCancellable* cancellable;
	Block54Data* _data54_;
	GearyDbDatabase* _tmp0_;
	GearyImapFolderProperties* _tmp1_;
	GError* _inner_error0_;
};

struct _GearyContactHarvesterIface {
	GTypeInterface parent_iface;
	void (*harvest_from_email) (GearyContactHarvester* self, GeeCollection* messages, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*harvest_from_email_finish) (GearyContactHarvester* self, GAsyncResult* _res_, GError** error);
};

struct _Block55Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GeeHashMap* results;
	gboolean update_totals;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _Block56Data {
	int _ref_count_;
	Block55Data * _data55_;
	GeeList* slice;
	GeeArrayList* complete_ids;
	gint total_unread_change;
};

struct _GearyImapDbFolderCreateOrMergeEmailAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GeeCollection* emails;
	gboolean update_totals;
	GearyContactHarvester* harvester;
	GCancellable* cancellable;
	GeeMap* result;
	Block55Data* _data55_;
	GeeHashMap* _tmp0_;
	GeeArrayList* list;
	GearyIterable* _tmp1_;
	GearyIterable* _tmp2_;
	GeeArrayList* _tmp3_;
	GeeArrayList* _tmp4_;
	gint index;
	Block56Data* _data56_;
	GeeArrayList* _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	gint stop;
	GeeArrayList* _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	GeeArrayList* _tmp11_;
	GeeList* _tmp12_;
	GeeArrayList* _tmp13_;
	GearyDbDatabase* _tmp14_;
	GCancellable* _tmp15_;
	GearyImapFolderProperties* _tmp16_;
	GearyImapFolderProperties* _tmp17_;
	gint _tmp18_;
	gint _tmp19_;
	GeeArrayList* _tmp20_;
	gint _tmp21_;
	gint _tmp22_;
	GeeArrayList* _tmp23_;
	GeeArrayList* _tmp24_;
	gint _tmp25_;
	gint _tmp26_;
	GeeHashMap* _tmp27_;
	GeeSet* _tmp28_;
	GeeSet* _tmp29_;
	GeeSet* _tmp30_;
	GeeHashMap* _tmp31_;
	GeeMap* _tmp32_;
	GError* _inner_error0_;
};

struct _Block57Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GeeHashMap* contained_ids;
	GeeCollection* ids;
	gpointer _async_data_;
};

struct _Block58Data {
	int _ref_count_;
	Block57Data * _data57_;
	GeeHashMap* valid_ids;
};

struct _GearyImapDbFolderContainsIdentifiersData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GeeCollection* ids;
	GCancellable* cancellable;
	GeeCollection* result;
	Block57Data* _data57_;
	GeeHashMap* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	Block58Data* _data58_;
	GeeHashMap* _tmp3_;
	GearyDbDatabase* _tmp4_;
	GeeHashMap* _tmp5_;
	GeeCollection* _tmp6_;
	GeeCollection* _tmp7_;
	GError* _inner_error0_;
};

struct _Block59Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	gboolean including_id;
	gboolean oldest_to_newest;
	GeeList* locations;
	GearyImapDBEmailIdentifier* initial_id;
	gint count;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDBFolderLocationIdentifier {
	GTypeInstance parent_instance;
	volatile int ref_count;
	gint64 message_id;
	GearyImapUID* uid;
	GearyImapDBEmailIdentifier* email_id;
	gboolean marked_removed;
	GearyImapDBFolderLocationIdentifierPrivate * priv;
};

struct _GearyImapDBFolderLocationIdentifierClass {
	GTypeClass parent_class;
	void (*finalize) (GearyImapDBFolderLocationIdentifier *self);
};

struct _GearyImapDbFolderListEmailByIdAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GearyImapDBEmailIdentifier* initial_id;
	gint count;
	GearyEmailField required_fields;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	GeeList* result;
	Block59Data* _data59_;
	gboolean only_incomplete;
	GearyDbDatabase* _tmp0_;
	GeeList* _tmp1_;
	GeeList* _tmp2_;
	GeeList* _tmp3_;
	GeeList* _tmp4_;
	GeeList* _tmp5_;
	GeeList* _tmp6_;
	GeeList* _tmp7_;
	GeeList* _tmp8_;
	GError* _inner_error0_;
};

struct _Block60Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	gboolean including_id;
	GeeList* locations;
	GearyImapDBEmailIdentifier* start_id;
	GearyImapDBEmailIdentifier* end_id;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderListEmailByRangeAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GearyImapDBEmailIdentifier* start_id;
	GearyImapDBEmailIdentifier* end_id;
	GearyEmailField required_fields;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	GeeList* result;
	Block60Data* _data60_;
	GearyDbDatabase* _tmp0_;
	GeeList* _tmp1_;
	GeeList* _tmp2_;
	GeeList* _tmp3_;
	GeeList* _tmp4_;
	GError* _inner_error0_;
};

struct _Block61Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GearyImapUID* start_uid;
	GearyImapUID* end_uid;
	GeeList* locations;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderListEmailByUidRangeAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GearyImapUID* start;
	GearyImapUID* end;
	GearyEmailField required_fields;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	GeeList* result;
	Block61Data* _data61_;
	gboolean including_id;
	gboolean only_incomplete;
	GearyImapUID* _tmp0_;
	GearyImapUID* _tmp1_;
	GearyImapUID* _tmp2_;
	GearyImapUID* _tmp3_;
	GearyImapUID* _tmp4_;
	GearyImapUID* _tmp5_;
	gboolean _tmp6_;
	gboolean _tmp7_;
	GearyImapUID* _tmp8_;
	GearyImapUID* _tmp9_;
	GearyImapUID* _tmp10_;
	GearyImapUID* _tmp11_;
	GearyDbDatabase* _tmp12_;
	GeeList* _tmp13_;
	GeeList* _tmp14_;
	GeeList* _tmp15_;
	GeeList* _tmp16_;
	GeeList* _tmp17_;
	GeeList* _tmp18_;
	GeeList* _tmp19_;
	GeeList* _tmp20_;
	GError* _inner_error0_;
};

struct _Block62Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GeeList* locations;
	GeeCollection* ids;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderListEmailBySparseIdAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GeeCollection* ids;
	GearyEmailField required_fields;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	GeeList* result;
	Block62Data* _data62_;
	gint _tmp0_;
	gint _tmp1_;
	gboolean only_incomplete;
	GeeArrayList* _tmp2_;
	GearyDbDatabase* _tmp3_;
	GCancellable* _tmp4_;
	GeeList* _tmp5_;
	GeeList* _tmp6_;
	GeeList* _tmp7_;
	GeeList* _tmp8_;
	GeeList* _tmp9_;
	GeeList* _tmp10_;
	GeeList* _tmp11_;
	GeeList* _tmp12_;
	GError* _inner_error0_;
};

struct _Block63Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _Block64Data {
	int _ref_count_;
	Block63Data * _data63_;
	GeeList* slice;
};

struct _GearyImapDbFolderRemoveCompleteLocationsInChunksAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GeeList* locations;
	GCancellable* cancellable;
	GeeList* result;
	Block63Data* _data63_;
	gboolean _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	GeeList* _tmp3_;
	GeeList* incomplete_locations;
	GeeArrayList* _tmp4_;
	gint start;
	gboolean _tmp5_;
	Block64Data* _data64_;
	gint _tmp6_;
	gint _tmp7_;
	gint end;
	gint _tmp8_;
	gint _tmp9_;
	GeeList* _tmp10_;
	GearyDbDatabase* _tmp11_;
	GeeList* _tmp12_;
	GeeList* _tmp13_;
	GeeList* _tmp14_;
	GeeList* _tmp15_;
	gint _tmp16_;
	gint _tmp17_;
	GeeList* _tmp18_;
	GeeList* _tmp19_;
	GError* _inner_error0_;
};

struct _Block65Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GearyEmailField required_fields;
	GearyImapDBFolderListFlags flags;
	gpointer _async_data_;
};

struct _Block66Data {
	int _ref_count_;
	Block65Data * _data65_;
	GeeList* slice;
	GeeList* list;
};

struct _GearyImapDbFolderListEmailInChunksAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GeeList* ids;
	GearyEmailField required_fields;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	GeeList* result;
	Block65Data* _data65_;
	gboolean _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	gint chunk_count;
	gint length_rounded_up;
	gint _tmp4_;
	gint _tmp5_;
	GeeList* results;
	GeeArrayList* _tmp6_;
	gint start;
	gboolean _tmp7_;
	Block66Data* _data66_;
	gint stop;
	gint _tmp8_;
	gint _tmp9_;
	GeeList* _tmp10_;
	gboolean _tmp11_;
	GeeList* _tmp12_;
	GeeList* _tmp13_;
	gint _tmp14_;
	gint _tmp15_;
	GearyDbDatabase* _tmp16_;
	GeeList* _tmp17_;
	GeeList* _tmp18_;
	GeeList* _tmp19_;
	GeeList* _tmp20_;
	gint _tmp21_;
	gint _tmp22_;
	gint _tmp23_;
	gint _tmp24_;
	gint _tmp25_;
	gint _tmp26_;
	GeeList* _tmp27_;
	gint _tmp28_;
	gint _tmp29_;
	GeeList* _tmp30_;
	GeeList* _tmp31_;
	gint _tmp32_;
	gint _tmp33_;
	GeeList* _tmp34_;
	GeeList* _tmp35_;
	GError* _inner_error0_;
};

struct _Block67Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GearyEmail* email;
	GearyImapDBEmailIdentifier* id;
	GearyEmailField required_fields;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderFetchEmailAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GearyImapDBEmailIdentifier* id;
	GearyEmailField required_fields;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	GearyEmail* result;
	Block67Data* _data67_;
	GearyDbDatabase* _tmp0_;
	GearyEmail* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GError* _tmp6_;
	GError* _tmp7_;
	GearyEmail* _tmp8_;
	GearyEmail* _tmp9_;
	GError* _inner_error0_;
};

struct _Block68Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GearyImapUID* start;
	GearyImapUID* end;
	GeeSet* uids;
	gboolean include_marked_for_removal;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderListUidsByRangeAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GearyImapUID* first_uid;
	GearyImapUID* last_uid;
	gboolean include_marked_for_removal;
	GCancellable* cancellable;
	GeeSet* result;
	Block68Data* _data68_;
	GearyImapUID* _tmp0_;
	GearyImapUID* _tmp1_;
	GearyImapUID* _tmp2_;
	GearyImapUID* _tmp3_;
	GeeHashSet* _tmp4_;
	GearyDbDatabase* _tmp5_;
	GeeSet* _tmp6_;
	gint _tmp7_;
	gint _tmp8_;
	GeeSet* _tmp9_;
	GError* _inner_error0_;
};

struct _Block69Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GearyImapDBEmailIdentifier* id;
	gint64 pos;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderGetIdAtAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	gint64 pos;
	GCancellable* cancellable;
	GearyImapDBEmailIdentifier* result;
	Block69Data* _data69_;
	GearyDbDatabase* _tmp0_;
	GearyImapDBEmailIdentifier* _tmp1_;
	GError* _inner_error0_;
};

struct _Block70Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GearyImapUID* uid;
	GearyImapDBEmailIdentifier* id;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderGetUidAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GearyImapDBEmailIdentifier* id;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	GearyImapUID* result;
	Block70Data* _data70_;
	GearyDbDatabase* _tmp0_;
	GearyImapUID* _tmp1_;
	GError* _inner_error0_;
};

struct _Block71Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GeeSet* uids;
	GeeCollection* ids;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderGetUidsAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GeeCollection* ids;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	GeeSet* result;
	Block71Data* _data71_;
	GeeHashSet* _tmp0_;
	GearyDbDatabase* _tmp1_;
	GCancellable* _tmp2_;
	GeeSet* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	GeeSet* _tmp6_;
	GError* _inner_error0_;
};

struct _Block72Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GearyImapDBEmailIdentifier* id;
	GearyImapUID* uid;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderGetIdAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GearyImapUID* uid;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	GearyImapDBEmailIdentifier* result;
	Block72Data* _data72_;
	GearyDbDatabase* _tmp0_;
	GearyImapDBEmailIdentifier* _tmp1_;
	GError* _inner_error0_;
};

struct _Block73Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GeeSet* ids;
	GeeCollection* uids;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderGetIdsAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GeeCollection* uids;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	GeeSet* result;
	Block73Data* _data73_;
	GeeHashSet* _tmp0_;
	GearyDbDatabase* _tmp1_;
	GCancellable* _tmp2_;
	GeeSet* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	GeeSet* _tmp6_;
	GError* _inner_error0_;
};

struct _GearyImapDbFolderGetEarliestIdAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GCancellable* cancellable;
	GearyImapDBEmailIdentifier* result;
	GearyImapDBEmailIdentifier* _tmp0_;
	GearyImapDBEmailIdentifier* _tmp1_;
	GearyImapDBEmailIdentifier* _tmp2_;
	GError* _inner_error0_;
};

struct _GearyImapDbFolderGetLatestIdAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GCancellable* cancellable;
	GearyImapDBEmailIdentifier* result;
	GearyImapDBEmailIdentifier* _tmp0_;
	GearyImapDBEmailIdentifier* _tmp1_;
	GearyImapDBEmailIdentifier* _tmp2_;
	GError* _inner_error0_;
};

struct _Block74Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GearyImapDBEmailIdentifier* id;
	gboolean earliest;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderGetIdExtremesAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	gboolean earliest;
	GCancellable* cancellable;
	GearyImapDBEmailIdentifier* result;
	Block74Data* _data74_;
	GearyDbDatabase* _tmp0_;
	GearyImapDBEmailIdentifier* _tmp1_;
	GError* _inner_error0_;
};

struct _Block75Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	gint unread_count;
	GeeCollection* ids;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderDetachMultipleEmailsAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GeeCollection* ids;
	GCancellable* cancellable;
	Block75Data* _data75_;
	GearyDbDatabase* _tmp0_;
	GearyImapFolderProperties* _tmp1_;
	GearyImapFolderProperties* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	GError* _inner_error0_;
};

struct _Block76Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderDetachAllEmailsAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GCancellable* cancellable;
	Block76Data* _data76_;
	GearyDbDatabase* _tmp0_;
	GError* _inner_error0_;
};

struct _Block77Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GeeArrayList* deleted_email_ids;
	GeeArrayList* deleted_primary_keys;
	GDateTime* cutoff;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _Block78Data {
	int _ref_count_;
	Block77Data * _data77_;
	GString* message_location_ids_sql_sublist;
	GString* message_ids_sql_sublist;
};

struct _GearyImapDbFolderDetachEmailsBeforeTimestampData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GDateTime* cutoff;
	GCancellable* cancellable;
	GeeCollection* result;
	Block77Data* _data77_;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	GearyDbDatabase* _tmp4_;
	GeeArrayList* _tmp5_;
	gint delete_index;
	Block78Data* _data78_;
	GeeArrayList* _tmp6_;
	gint _tmp7_;
	gint _tmp8_;
	gint batch_counter;
	GString* _tmp9_;
	GString* _tmp10_;
	gboolean _tmp11_;
	GeeArrayList* _tmp12_;
	gint _tmp13_;
	gint _tmp14_;
	GString* _tmp15_;
	GString* _tmp16_;
	GString* _tmp17_;
	GeeArrayList* _tmp18_;
	gpointer _tmp19_;
	gchar* _tmp20_;
	GString* _tmp21_;
	GeeArrayList* _tmp22_;
	gpointer _tmp23_;
	GearyImapDBEmailIdentifier* _tmp24_;
	gint64 _tmp25_;
	gint64 _tmp26_;
	gchar* _tmp27_;
	gchar* _tmp28_;
	gint _tmp29_;
	gint _tmp30_;
	GearyDbDatabase* _tmp31_;
	GeeArrayList* _tmp32_;
	GeeCollection* _tmp33_;
	GError* _inner_error0_;
};

struct _Block79Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	gint unread_change;
	GeeMap* unread_status;
	GeeCollection* to_mark;
	GearyEmailFlags* flags_to_add;
	GearyEmailFlags* flags_to_remove;
	gpointer _async_data_;
};

struct _GearyImapDbFolderMarkEmailAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GeeCollection* to_mark;
	GearyEmailFlags* flags_to_add;
	GearyEmailFlags* flags_to_remove;
	GCancellable* cancellable;
	Block79Data* _data79_;
	GeeHashMap* _tmp0_;
	GearyDbDatabase* _tmp1_;
	GCancellable* _tmp2_;
	GearyImapFolderProperties* _tmp3_;
	GearyImapFolderProperties* _tmp4_;
	gint _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	gint _tmp8_;
	GError* _inner_error0_;
};

struct _Block80Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GeeList* uids;
	GeeCollection* ids;
	gpointer _async_data_;
};

struct _GearyImapDbFolderGetEmailUidsAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GeeCollection* ids;
	GCancellable* cancellable;
	GeeList* result;
	Block80Data* _data80_;
	GearyDbDatabase* _tmp0_;
	GeeList* _tmp1_;
	GError* _inner_error0_;
};

struct _Block81Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GeeMap* map;
	GeeCollection* ids;
	gpointer _async_data_;
};

struct _GearyImapDbFolderGetEmailFlagsAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GeeCollection* ids;
	GCancellable* cancellable;
	GeeMap* result;
	Block81Data* _data81_;
	GearyDbDatabase* _tmp0_;
	GeeMap* _tmp1_;
	GError* _inner_error0_;
};

struct _Block82Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	gint unread_change;
	GeeMap* map;
	gpointer _async_data_;
};

struct _GearyImapDbFolderSetEmailFlagsAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GeeMap* map;
	GCancellable* cancellable;
	Block82Data* _data82_;
	GError* _error_;
	GearyDbDatabase* _tmp0_;
	GCancellable* _tmp1_;
	GError* e;
	GError* _tmp2_;
	GError* _tmp3_;
	GError* _tmp4_;
	GearyImapFolderProperties* _tmp5_;
	GearyImapFolderProperties* _tmp6_;
	gint _tmp7_;
	gint _tmp8_;
	GError* _tmp9_;
	GError* _tmp10_;
	GError* _inner_error0_;
};

struct _Block83Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	gboolean internal_is_marked;
	gboolean was_unread;
	GearyImapDBEmailIdentifier* id;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderDetachSingleEmailAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GearyImapDBEmailIdentifier* id;
	GCancellable* cancellable;
	gboolean is_marked;
	Block83Data* _data83_;
	GearyDbDatabase* _tmp0_;
	GearyImapFolderProperties* _tmp1_;
	GearyImapFolderProperties* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	GError* _inner_error0_;
};

struct _Block84Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	gint total_changed;
	gint unread_count;
	GeeSet* removed_ids;
	GeeCollection* ids;
	gboolean mark_removed;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderMarkRemovedAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GeeCollection* ids;
	gboolean mark_removed;
	GCancellable* cancellable;
	GeeSet* result;
	Block84Data* _data84_;
	GeeHashSet* _tmp0_;
	GearyDbDatabase* _tmp1_;
	GCancellable* _tmp2_;
	gint total;
	GearyImapFolderProperties* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	GearyImapFolderProperties* _tmp6_;
	GearyImapFolderProperties* _tmp7_;
	GearyImapFolderProperties* _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	GeeSet* _tmp11_;
	gint _tmp12_;
	gint _tmp13_;
	GeeSet* _tmp14_;
	GError* _inner_error0_;
};

struct _Block85Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	gint count;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderGetMarkedForRemoveCountAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GCancellable* cancellable;
	gint result;
	Block85Data* _data85_;
	GearyDbDatabase* _tmp0_;
	GError* _inner_error0_;
};

struct _Block86Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GeeSet* ids;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderGetMarkedIdsAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GCancellable* cancellable;
	GeeSet* result;
	Block86Data* _data86_;
	GeeHashSet* _tmp0_;
	GearyDbDatabase* _tmp1_;
	GeeSet* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	GeeSet* _tmp5_;
	GError* _inner_error0_;
};

struct _Block87Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GeeCollection* exceptions;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _GearyImapDbFolderClearRemoveMarkersAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GeeCollection* exceptions;
	GCancellable* cancellable;
	Block87Data* _data87_;
	GearyDbDatabase* _tmp0_;
	GError* _inner_error0_;
};

struct _Block88Data {
	int _ref_count_;
	GearyImapDBFolder* self;
	GeeHashMap* map;
	GeeCollection* ids;
	GearyImapDBFolderListFlags flags;
	gpointer _async_data_;
};

struct _GearyImapDbFolderListEmailFieldsByIdAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapDBFolder* self;
	GeeCollection* ids;
	GearyImapDBFolderListFlags flags;
	GCancellable* cancellable;
	GeeMap* result;
	Block88Data* _data88_;
	gint _tmp0_;
	gint _tmp1_;
	GeeHashMap* _tmp2_;
	GeeList* list;
	GeeArrayList* _tmp3_;
	GeeIterator* iter;
	GeeIterator* _tmp4_;
	GeeIterator* _tmp5_;
	GeeList* _tmp6_;
	GeeIterator* _tmp7_;
	gpointer _tmp8_;
	GearyImapDBEmailIdentifier* _tmp9_;
	gboolean _tmp10_;
	GeeList* _tmp11_;
	gint _tmp12_;
	gint _tmp13_;
	GeeIterator* _tmp14_;
	GearyDbDatabase* _tmp15_;
	GCancellable* _tmp16_;
	GeeList* _tmp17_;
	GeeList* _tmp18_;
	gint _tmp19_;
	gint _tmp20_;
	GeeHashMap* _tmp21_;
	GeeHashMap* _tmp22_;
	gint _tmp23_;
	gint _tmp24_;
	GeeHashMap* _tmp25_;
	GeeMap* _tmp26_;
	GError* _inner_error0_;
};

struct _GearyImapDBFolderParamSpecLocationIdentifier {
	GParamSpec parent_instance;
};

static gint GearyImapDBFolder_private_offset;
static gpointer geary_imap_db_folder_parent_class = NULL;
static gpointer geary_imap_db_folder_location_identifier_parent_class = NULL;
static GearyReferenceSemanticsIface * geary_imap_db_folder_geary_reference_semantics_parent_iface = NULL;

VALA_EXTERN GType geary_imap_db_folder_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_db_folder_list_flags_get_type (void) G_GNUC_CONST ;
VALA_EXTERN gboolean geary_imap_db_folder_list_flags_is_all_set (GearyImapDBFolderListFlags self,
                                                     GearyImapDBFolderListFlags flags);
VALA_EXTERN gboolean geary_imap_db_folder_list_flags_include_marked_for_remove (GearyImapDBFolderListFlags self);
VALA_EXTERN GearyImapDBFolderListFlags geary_imap_db_folder_list_flags_from_folder_flags (GearyFolderListFlags flags);
VALA_EXTERN GType geary_imap_db_email_identifier_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GearyImapDBFolder* geary_imap_db_folder_new (GearyDbDatabase* db,
                                             GearyFolderPath* path,
                                             GFile* attachments_path,
                                             const gchar* account_owner_email,
                                             gint64 folder_id,
                                             GearyImapFolderProperties* properties);
VALA_EXTERN GearyImapDBFolder* geary_imap_db_folder_construct (GType object_type,
                                                   GearyDbDatabase* db,
                                                   GearyFolderPath* path,
                                                   GFile* attachments_path,
                                                   const gchar* account_owner_email,
                                                   gint64 folder_id,
                                                   GearyImapFolderProperties* properties);
VALA_EXTERN GearyFolderPath* geary_imap_db_folder_get_path (GearyImapDBFolder* self);
VALA_EXTERN GearyImapFolderProperties* geary_imap_db_folder_get_properties (GearyImapDBFolder* self);
VALA_EXTERN void geary_imap_db_folder_set_properties (GearyImapDBFolder* self,
                                          GearyImapFolderProperties* properties);
static void geary_imap_db_folder_get_email_count_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_get_email_count_async (GearyImapDBFolder* self,
                                                 GearyImapDBFolderListFlags flags,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
VALA_EXTERN gint geary_imap_db_folder_get_email_count_finish (GearyImapDBFolder* self,
                                                  GAsyncResult* _res_,
                                                  GError** error);
static gboolean geary_imap_db_folder_get_email_count_async_co (GearyImapDbFolderGetEmailCountAsyncData* _data_);
static Block51Data* block51_data_ref (Block51Data* _data51_);
static void block51_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda51_ (Block51Data* _data51_,
                                       GearyDbConnection* cx,
                                       GError** error);
static gint geary_imap_db_folder_do_get_email_count (GearyImapDBFolder* self,
                                              GearyDbConnection* cx,
                                              GearyImapDBFolderListFlags flags,
                                              GCancellable* cancellable,
                                              GError** error);
static GearyDbTransactionOutcome ___lambda51__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_get_email_count_async_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_);
static void geary_imap_db_folder_update_folder_status_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_update_folder_status (GearyImapDBFolder* self,
                                                GearyImapFolderProperties* remote_properties,
                                                gboolean respect_marked_for_remove,
                                                GCancellable* cancellable,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_);
VALA_EXTERN void geary_imap_db_folder_update_folder_status_finish (GearyImapDBFolder* self,
                                                       GAsyncResult* _res_,
                                                       GError** error);
static gboolean geary_imap_db_folder_update_folder_status_co (GearyImapDbFolderUpdateFolderStatusData* _data_);
static Block52Data* block52_data_ref (Block52Data* _data52_);
static void block52_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda52_ (Block52Data* _data52_,
                                       GearyDbConnection* cx,
                                       GError** error);
static void geary_imap_db_folder_do_update_last_seen_status_total (GearyImapDBFolder* self,
                                                            GearyDbConnection* cx,
                                                            gint total,
                                                            GCancellable* cancellable,
                                                            GError** error);
static GearyDbTransactionOutcome ___lambda52__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_update_folder_status_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_);
VALA_EXTERN void geary_imap_folder_properties_set_recent (GearyImapFolderProperties* self,
                                              gint value);
VALA_EXTERN void geary_imap_folder_properties_set_attrs (GearyImapFolderProperties* self,
                                             GearyImapMailboxAttributes* value);
static void geary_imap_db_folder_update_folder_select_examine_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_update_folder_select_examine (GearyImapDBFolder* self,
                                                        GearyImapFolderProperties* remote_properties,
                                                        GCancellable* cancellable,
                                                        GAsyncReadyCallback _callback_,
                                                        gpointer _user_data_);
VALA_EXTERN void geary_imap_db_folder_update_folder_select_examine_finish (GearyImapDBFolder* self,
                                                               GAsyncResult* _res_,
                                                               GError** error);
static gboolean geary_imap_db_folder_update_folder_select_examine_co (GearyImapDbFolderUpdateFolderSelectExamineData* _data_);
static Block53Data* block53_data_ref (Block53Data* _data53_);
static void block53_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda53_ (Block53Data* _data53_,
                                       GearyDbConnection* cx,
                                       GError** error);
static void geary_imap_db_folder_do_update_uid_info (GearyImapDBFolder* self,
                                              GearyDbConnection* cx,
                                              GearyImapFolderProperties* remote_properties,
                                              GCancellable* cancellable,
                                              GError** error);
static void geary_imap_db_folder_do_update_last_seen_select_examine_total (GearyImapDBFolder* self,
                                                                    GearyDbConnection* cx,
                                                                    gint total,
                                                                    GCancellable* cancellable,
                                                                    GError** error);
static GearyDbTransactionOutcome ___lambda53__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_update_folder_select_examine_ready (GObject* source_object,
                                                              GAsyncResult* _res_,
                                                              gpointer _user_data_);
VALA_EXTERN void geary_imap_folder_properties_set_uid_validity (GearyImapFolderProperties* self,
                                                    GearyImapUIDValidity* value);
VALA_EXTERN void geary_imap_folder_properties_set_uid_next (GearyImapFolderProperties* self,
                                                GearyImapUID* value);
static void geary_imap_db_folder_update_remote_selected_message_count_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_update_remote_selected_message_count (GearyImapDBFolder* self,
                                                                gint count,
                                                                GCancellable* cancellable,
                                                                GAsyncReadyCallback _callback_,
                                                                gpointer _user_data_);
VALA_EXTERN void geary_imap_db_folder_update_remote_selected_message_count_finish (GearyImapDBFolder* self,
                                                                       GAsyncResult* _res_,
                                                                       GError** error);
static gboolean geary_imap_db_folder_update_remote_selected_message_count_co (GearyImapDbFolderUpdateRemoteSelectedMessageCountData* _data_);
static Block54Data* block54_data_ref (Block54Data* _data54_);
static void block54_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda54_ (Block54Data* _data54_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GearyDbTransactionOutcome ___lambda54__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_update_remote_selected_message_count_ready (GObject* source_object,
                                                                      GAsyncResult* _res_,
                                                                      gpointer _user_data_);
static void geary_imap_db_folder_create_or_merge_email_async_data_free (gpointer _data);
VALA_EXTERN GType geary_contact_harvester_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void geary_imap_db_folder_create_or_merge_email_async (GearyImapDBFolder* self,
                                                       GeeCollection* emails,
                                                       gboolean update_totals,
                                                       GearyContactHarvester* harvester,
                                                       GCancellable* cancellable,
                                                       GAsyncReadyCallback _callback_,
                                                       gpointer _user_data_);
VALA_EXTERN GeeMap* geary_imap_db_folder_create_or_merge_email_finish (GearyImapDBFolder* self,
                                                           GAsyncResult* _res_,
                                                           GError** error);
static gboolean geary_imap_db_folder_create_or_merge_email_async_co (GearyImapDbFolderCreateOrMergeEmailAsyncData* _data_);
static Block55Data* block55_data_ref (Block55Data* _data55_);
static void block55_data_unref (void * _userdata_);
static Block56Data* block56_data_ref (Block56Data* _data56_);
static void block56_data_unref (void * _userdata_);
static GearyDbTransactionOutcome ___lambda55_ (Block56Data* _data56_,
                                        GearyDbConnection* cx,
                                        GError** error);
static gboolean geary_imap_db_folder_do_create_or_merge_email (GearyImapDBFolder* self,
                                                        GearyDbConnection* cx,
                                                        GearyEmail* email,
                                                        GearyEmailField* pre_fields,
                                                        GearyEmailField* post_fields,
                                                        gint* unread_count_change,
                                                        GCancellable* cancellable,
                                                        GError** error);
VALA_EXTERN void geary_imap_db_folder_do_add_to_unread_count (GearyImapDBFolder* self,
                                                  GearyDbConnection* cx,
                                                  gint to_add,
                                                  GCancellable* cancellable,
                                                  GError** error);
static GearyDbTransactionOutcome ____lambda55__geary_db_transaction_method (GearyDbConnection* cx,
                                                                     GCancellable* cancellable,
                                                                     gpointer self,
                                                                     GError** error);
static void geary_imap_db_folder_create_or_merge_email_async_ready (GObject* source_object,
                                                             GAsyncResult* _res_,
                                                             gpointer _user_data_);
VALA_EXTERN void geary_contact_harvester_harvest_from_email (GearyContactHarvester* self,
                                                 GeeCollection* messages,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
VALA_EXTERN void geary_contact_harvester_harvest_from_email_finish (GearyContactHarvester* self,
                                                        GAsyncResult* _res_,
                                                        GError** error);
static void geary_imap_db_folder_contains_identifiers_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_contains_identifiers (GearyImapDBFolder* self,
                                                GeeCollection* ids,
                                                GCancellable* cancellable,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_);
VALA_EXTERN GeeCollection* geary_imap_db_folder_contains_identifiers_finish (GearyImapDBFolder* self,
                                                                 GAsyncResult* _res_,
                                                                 GError** error);
static gboolean geary_imap_db_folder_contains_identifiers_co (GearyImapDbFolderContainsIdentifiersData* _data_);
static Block57Data* block57_data_ref (Block57Data* _data57_);
static void block57_data_unref (void * _userdata_);
static guint _geary_collection_int64_hash_func_gee_hash_data_func (gconstpointer v,
                                                            gpointer self);
static gboolean _geary_collection_int64_equal_func_gee_equal_data_func (gconstpointer a,
                                                                 gconstpointer b,
                                                                 gpointer self);
static gint64* _int64_dup (gint64* self);
static Block58Data* block58_data_ref (Block58Data* _data58_);
static void block58_data_unref (void * _userdata_);
static GearyDbTransactionOutcome ___lambda56_ (Block58Data* _data58_,
                                        GearyDbConnection* cx,
                                        GCancellable* cancellable,
                                        GError** error);
VALA_EXTERN gint64 geary_imap_db_email_identifier_get_message_id (GearyImapDBEmailIdentifier* self);
static GearyDbTransactionOutcome ____lambda56__geary_db_transaction_method (GearyDbConnection* cx,
                                                                     GCancellable* cancellable,
                                                                     gpointer self,
                                                                     GError** error);
static void geary_imap_db_folder_contains_identifiers_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_);
static void geary_imap_db_folder_list_email_by_id_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_list_email_by_id_async (GearyImapDBFolder* self,
                                                  GearyImapDBEmailIdentifier* initial_id,
                                                  gint count,
                                                  GearyEmailField required_fields,
                                                  GearyImapDBFolderListFlags flags,
                                                  GCancellable* cancellable,
                                                  GAsyncReadyCallback _callback_,
                                                  gpointer _user_data_);
VALA_EXTERN GeeList* geary_imap_db_folder_list_email_by_id_finish (GearyImapDBFolder* self,
                                                       GAsyncResult* _res_,
                                                       GError** error);
static gboolean geary_imap_db_folder_list_email_by_id_async_co (GearyImapDbFolderListEmailByIdAsyncData* _data_);
static gpointer geary_imap_db_folder_location_identifier_ref (gpointer instance);
static void geary_imap_db_folder_location_identifier_unref (gpointer instance);
static GParamSpec* geary_imap_db_folder_param_spec_location_identifier (const gchar* name,
                                                                 const gchar* nick,
                                                                 const gchar* blurb,
                                                                 GType object_type,
                                                                 GParamFlags flags) G_GNUC_UNUSED ;
static void geary_imap_db_folder_value_set_location_identifier (GValue* value,
                                                         gpointer v_object) G_GNUC_UNUSED ;
static void geary_imap_db_folder_value_take_location_identifier (GValue* value,
                                                          gpointer v_object) G_GNUC_UNUSED ;
static gpointer geary_imap_db_folder_value_get_location_identifier (const GValue* value) G_GNUC_UNUSED ;
static GType geary_imap_db_folder_location_identifier_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static Block59Data* block59_data_ref (Block59Data* _data59_);
static void block59_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda57_ (Block59Data* _data59_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GearyImapDBFolderLocationIdentifier* geary_imap_db_folder_do_get_location_for_id (GearyImapDBFolder* self,
                                                                                  GearyDbConnection* cx,
                                                                                  GearyImapDBEmailIdentifier* id,
                                                                                  GearyImapDBFolderListFlags flags,
                                                                                  GCancellable* cancellable,
                                                                                  GError** error);
static GeeList* geary_imap_db_folder_do_results_to_locations (GearyImapDBFolder* self,
                                                       GearyDbResult* results,
                                                       gint count,
                                                       GearyImapDBFolderListFlags flags,
                                                       GCancellable* cancellable,
                                                       GError** error);
static GearyDbTransactionOutcome ___lambda57__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_list_email_by_id_async_ready (GObject* source_object,
                                                        GAsyncResult* _res_,
                                                        gpointer _user_data_);
static void geary_imap_db_folder_remove_complete_locations_in_chunks_async (GearyImapDBFolder* self,
                                                                     GeeList* locations,
                                                                     GCancellable* cancellable,
                                                                     GAsyncReadyCallback _callback_,
                                                                     gpointer _user_data_);
static GeeList* geary_imap_db_folder_remove_complete_locations_in_chunks_finish (GearyImapDBFolder* self,
                                                                          GAsyncResult* _res_,
                                                                          GError** error);
static void geary_imap_db_folder_list_email_in_chunks_async (GearyImapDBFolder* self,
                                                      GeeList* ids,
                                                      GearyEmailField required_fields,
                                                      GearyImapDBFolderListFlags flags,
                                                      GCancellable* cancellable,
                                                      GAsyncReadyCallback _callback_,
                                                      gpointer _user_data_);
static GeeList* geary_imap_db_folder_list_email_in_chunks_finish (GearyImapDBFolder* self,
                                                           GAsyncResult* _res_,
                                                           GError** error);
static void geary_imap_db_folder_list_email_by_range_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_list_email_by_range_async (GearyImapDBFolder* self,
                                                     GearyImapDBEmailIdentifier* start_id,
                                                     GearyImapDBEmailIdentifier* end_id,
                                                     GearyEmailField required_fields,
                                                     GearyImapDBFolderListFlags flags,
                                                     GCancellable* cancellable,
                                                     GAsyncReadyCallback _callback_,
                                                     gpointer _user_data_);
VALA_EXTERN GeeList* geary_imap_db_folder_list_email_by_range_finish (GearyImapDBFolder* self,
                                                          GAsyncResult* _res_,
                                                          GError** error);
static gboolean geary_imap_db_folder_list_email_by_range_async_co (GearyImapDbFolderListEmailByRangeAsyncData* _data_);
static Block60Data* block60_data_ref (Block60Data* _data60_);
static void block60_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda60_ (Block60Data* _data60_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GearyDbTransactionOutcome ___lambda60__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_list_email_by_range_async_ready (GObject* source_object,
                                                           GAsyncResult* _res_,
                                                           gpointer _user_data_);
static void geary_imap_db_folder_list_email_by_uid_range_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_list_email_by_uid_range_async (GearyImapDBFolder* self,
                                                         GearyImapUID* start,
                                                         GearyImapUID* end,
                                                         GearyEmailField required_fields,
                                                         GearyImapDBFolderListFlags flags,
                                                         GCancellable* cancellable,
                                                         GAsyncReadyCallback _callback_,
                                                         gpointer _user_data_);
VALA_EXTERN GeeList* geary_imap_db_folder_list_email_by_uid_range_finish (GearyImapDBFolder* self,
                                                              GAsyncResult* _res_,
                                                              GError** error);
static gboolean geary_imap_db_folder_list_email_by_uid_range_async_co (GearyImapDbFolderListEmailByUidRangeAsyncData* _data_);
static Block61Data* block61_data_ref (Block61Data* _data61_);
static void block61_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda61_ (Block61Data* _data61_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GearyDbTransactionOutcome ___lambda61__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_list_email_by_uid_range_async_ready (GObject* source_object,
                                                               GAsyncResult* _res_,
                                                               gpointer _user_data_);
static void geary_imap_db_folder_list_email_by_sparse_id_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_list_email_by_sparse_id_async (GearyImapDBFolder* self,
                                                         GeeCollection* ids,
                                                         GearyEmailField required_fields,
                                                         GearyImapDBFolderListFlags flags,
                                                         GCancellable* cancellable,
                                                         GAsyncReadyCallback _callback_,
                                                         gpointer _user_data_);
VALA_EXTERN GeeList* geary_imap_db_folder_list_email_by_sparse_id_finish (GearyImapDBFolder* self,
                                                              GAsyncResult* _res_,
                                                              GError** error);
static gboolean geary_imap_db_folder_list_email_by_sparse_id_async_co (GearyImapDbFolderListEmailBySparseIdAsyncData* _data_);
static Block62Data* block62_data_ref (Block62Data* _data62_);
static void block62_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda62_ (Block62Data* _data62_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GeeList* geary_imap_db_folder_do_get_locations_for_ids (GearyImapDBFolder* self,
                                                        GearyDbConnection* cx,
                                                        GeeCollection* ids,
                                                        GearyImapDBFolderListFlags flags,
                                                        GCancellable* cancellable,
                                                        GError** error);
static GearyDbTransactionOutcome ___lambda62__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_list_email_by_sparse_id_async_ready (GObject* source_object,
                                                               GAsyncResult* _res_,
                                                               gpointer _user_data_);
static void geary_imap_db_folder_remove_complete_locations_in_chunks_async_data_free (gpointer _data);
static gboolean geary_imap_db_folder_remove_complete_locations_in_chunks_async_co (GearyImapDbFolderRemoveCompleteLocationsInChunksAsyncData* _data_);
static Block63Data* block63_data_ref (Block63Data* _data63_);
static void block63_data_unref (void * _userdata_);
static Block64Data* block64_data_ref (Block64Data* _data64_);
static void block64_data_unref (void * _userdata_);
static GearyDbTransactionOutcome ____lambda58_ (Block64Data* _data64_,
                                         GearyDbConnection* cx,
                                         GError** error);
static void geary_imap_db_folder_do_remove_complete_locations (GearyImapDBFolder* self,
                                                        GearyDbConnection* cx,
                                                        GeeList* locations,
                                                        GCancellable* cancellable,
                                                        GError** error);
static GearyDbTransactionOutcome _____lambda58__geary_db_transaction_method (GearyDbConnection* cx,
                                                                      GCancellable* cancellable,
                                                                      gpointer self,
                                                                      GError** error);
static void geary_imap_db_folder_remove_complete_locations_in_chunks_async_ready (GObject* source_object,
                                                                           GAsyncResult* _res_,
                                                                           gpointer _user_data_);
static void geary_imap_db_folder_list_email_in_chunks_async_data_free (gpointer _data);
static gboolean geary_imap_db_folder_list_email_in_chunks_async_co (GearyImapDbFolderListEmailInChunksAsyncData* _data_);
static Block65Data* block65_data_ref (Block65Data* _data65_);
static void block65_data_unref (void * _userdata_);
static Block66Data* block66_data_ref (Block66Data* _data66_);
static void block66_data_unref (void * _userdata_);
static GearyDbTransactionOutcome _____lambda59_ (Block66Data* _data66_,
                                          GearyDbConnection* cx,
                                          GCancellable* cancellable,
                                          GError** error);
static GeeList* geary_imap_db_folder_do_list_email (GearyImapDBFolder* self,
                                             GearyDbConnection* cx,
                                             GeeList* locations,
                                             GearyEmailField required_fields,
                                             GearyImapDBFolderListFlags flags,
                                             GCancellable* cancellable,
                                             GError** error);
static GearyDbTransactionOutcome ______lambda59__geary_db_transaction_method (GearyDbConnection* cx,
                                                                       GCancellable* cancellable,
                                                                       gpointer self,
                                                                       GError** error);
static void geary_imap_db_folder_list_email_in_chunks_async_ready (GObject* source_object,
                                                            GAsyncResult* _res_,
                                                            gpointer _user_data_);
static void geary_imap_db_folder_fetch_email_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_fetch_email_async (GearyImapDBFolder* self,
                                             GearyImapDBEmailIdentifier* id,
                                             GearyEmailField required_fields,
                                             GearyImapDBFolderListFlags flags,
                                             GCancellable* cancellable,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_);
VALA_EXTERN GearyEmail* geary_imap_db_folder_fetch_email_finish (GearyImapDBFolder* self,
                                                     GAsyncResult* _res_,
                                                     GError** error);
static gboolean geary_imap_db_folder_fetch_email_async_co (GearyImapDbFolderFetchEmailAsyncData* _data_);
static Block67Data* block67_data_ref (Block67Data* _data67_);
static void block67_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda63_ (Block67Data* _data67_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GearyEmail* geary_imap_db_folder_do_location_to_email (GearyImapDBFolder* self,
                                                       GearyDbConnection* cx,
                                                       GearyImapDBFolderLocationIdentifier* location,
                                                       GearyEmailField required_fields,
                                                       GearyImapDBFolderListFlags flags,
                                                       GCancellable* cancellable,
                                                       GError** error);
static GearyDbTransactionOutcome ___lambda63__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_fetch_email_async_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_);
VALA_EXTERN gchar* geary_imap_db_folder_to_string (GearyImapDBFolder* self);
static void geary_imap_db_folder_list_uids_by_range_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_list_uids_by_range_async (GearyImapDBFolder* self,
                                                    GearyImapUID* first_uid,
                                                    GearyImapUID* last_uid,
                                                    gboolean include_marked_for_removal,
                                                    GCancellable* cancellable,
                                                    GAsyncReadyCallback _callback_,
                                                    gpointer _user_data_);
VALA_EXTERN GeeSet* geary_imap_db_folder_list_uids_by_range_finish (GearyImapDBFolder* self,
                                                        GAsyncResult* _res_,
                                                        GError** error);
static gboolean geary_imap_db_folder_list_uids_by_range_async_co (GearyImapDbFolderListUidsByRangeAsyncData* _data_);
static Block68Data* block68_data_ref (Block68Data* _data68_);
static void block68_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda64_ (Block68Data* _data68_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GearyDbTransactionOutcome ___lambda64__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_list_uids_by_range_async_ready (GObject* source_object,
                                                          GAsyncResult* _res_,
                                                          gpointer _user_data_);
static void geary_imap_db_folder_get_id_at_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_get_id_at_async (GearyImapDBFolder* self,
                                           gint64 pos,
                                           GCancellable* cancellable,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_);
VALA_EXTERN GearyImapDBEmailIdentifier* geary_imap_db_folder_get_id_at_finish (GearyImapDBFolder* self,
                                                                   GAsyncResult* _res_,
                                                                   GError** error);
static gboolean geary_imap_db_folder_get_id_at_async_co (GearyImapDbFolderGetIdAtAsyncData* _data_);
static Block69Data* block69_data_ref (Block69Data* _data69_);
static void block69_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda65_ (Block69Data* _data69_,
                                       GearyDbConnection* cx,
                                       GError** error);
VALA_EXTERN GearyImapDBEmailIdentifier* geary_imap_db_email_identifier_new (gint64 message_id,
                                                                GearyImapUID* uid);
VALA_EXTERN GearyImapDBEmailIdentifier* geary_imap_db_email_identifier_construct (GType object_type,
                                                                      gint64 message_id,
                                                                      GearyImapUID* uid);
static GearyDbTransactionOutcome ___lambda65__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_get_id_at_async_ready (GObject* source_object,
                                                 GAsyncResult* _res_,
                                                 gpointer _user_data_);
static void geary_imap_db_folder_get_uid_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_get_uid_async (GearyImapDBFolder* self,
                                         GearyImapDBEmailIdentifier* id,
                                         GearyImapDBFolderListFlags flags,
                                         GCancellable* cancellable,
                                         GAsyncReadyCallback _callback_,
                                         gpointer _user_data_);
VALA_EXTERN GearyImapUID* geary_imap_db_folder_get_uid_finish (GearyImapDBFolder* self,
                                                   GAsyncResult* _res_,
                                                   GError** error);
static gboolean geary_imap_db_folder_get_uid_async_co (GearyImapDbFolderGetUidAsyncData* _data_);
static Block70Data* block70_data_ref (Block70Data* _data70_);
static void block70_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda66_ (Block70Data* _data70_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GearyDbTransactionOutcome ___lambda66__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_get_uid_async_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_);
static void geary_imap_db_folder_get_uids_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_get_uids_async (GearyImapDBFolder* self,
                                          GeeCollection* ids,
                                          GearyImapDBFolderListFlags flags,
                                          GCancellable* cancellable,
                                          GAsyncReadyCallback _callback_,
                                          gpointer _user_data_);
VALA_EXTERN GeeSet* geary_imap_db_folder_get_uids_finish (GearyImapDBFolder* self,
                                              GAsyncResult* _res_,
                                              GError** error);
static gboolean geary_imap_db_folder_get_uids_async_co (GearyImapDbFolderGetUidsAsyncData* _data_);
static Block71Data* block71_data_ref (Block71Data* _data71_);
static void block71_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda67_ (Block71Data* _data71_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GearyDbTransactionOutcome ___lambda67__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_get_uids_async_ready (GObject* source_object,
                                                GAsyncResult* _res_,
                                                gpointer _user_data_);
static void geary_imap_db_folder_get_id_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_get_id_async (GearyImapDBFolder* self,
                                        GearyImapUID* uid,
                                        GearyImapDBFolderListFlags flags,
                                        GCancellable* cancellable,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_);
VALA_EXTERN GearyImapDBEmailIdentifier* geary_imap_db_folder_get_id_finish (GearyImapDBFolder* self,
                                                                GAsyncResult* _res_,
                                                                GError** error);
static gboolean geary_imap_db_folder_get_id_async_co (GearyImapDbFolderGetIdAsyncData* _data_);
static Block72Data* block72_data_ref (Block72Data* _data72_);
static void block72_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda68_ (Block72Data* _data72_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GearyImapDBFolderLocationIdentifier* geary_imap_db_folder_do_get_location_for_uid (GearyImapDBFolder* self,
                                                                                   GearyDbConnection* cx,
                                                                                   GearyImapUID* uid,
                                                                                   GearyImapDBFolderListFlags flags,
                                                                                   GCancellable* cancellable,
                                                                                   GError** error);
static GearyDbTransactionOutcome ___lambda68__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_get_id_async_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_);
static void geary_imap_db_folder_get_ids_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_get_ids_async (GearyImapDBFolder* self,
                                         GeeCollection* uids,
                                         GearyImapDBFolderListFlags flags,
                                         GCancellable* cancellable,
                                         GAsyncReadyCallback _callback_,
                                         gpointer _user_data_);
VALA_EXTERN GeeSet* geary_imap_db_folder_get_ids_finish (GearyImapDBFolder* self,
                                             GAsyncResult* _res_,
                                             GError** error);
static gboolean geary_imap_db_folder_get_ids_async_co (GearyImapDbFolderGetIdsAsyncData* _data_);
static Block73Data* block73_data_ref (Block73Data* _data73_);
static void block73_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda69_ (Block73Data* _data73_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GeeList* geary_imap_db_folder_do_get_locations_for_uids (GearyImapDBFolder* self,
                                                         GearyDbConnection* cx,
                                                         GeeCollection* uids,
                                                         GearyImapDBFolderListFlags flags,
                                                         GCancellable* cancellable,
                                                         GError** error);
static GearyDbTransactionOutcome ___lambda69__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_get_ids_async_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_);
static void geary_imap_db_folder_get_earliest_id_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_get_earliest_id_async (GearyImapDBFolder* self,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
VALA_EXTERN GearyImapDBEmailIdentifier* geary_imap_db_folder_get_earliest_id_finish (GearyImapDBFolder* self,
                                                                         GAsyncResult* _res_,
                                                                         GError** error);
static gboolean geary_imap_db_folder_get_earliest_id_async_co (GearyImapDbFolderGetEarliestIdAsyncData* _data_);
static void geary_imap_db_folder_get_id_extremes_async (GearyImapDBFolder* self,
                                                 gboolean earliest,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
static GearyImapDBEmailIdentifier* geary_imap_db_folder_get_id_extremes_finish (GearyImapDBFolder* self,
                                                                         GAsyncResult* _res_,
                                                                         GError** error);
static void geary_imap_db_folder_get_earliest_id_async_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_);
static void geary_imap_db_folder_get_latest_id_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_get_latest_id_async (GearyImapDBFolder* self,
                                               GCancellable* cancellable,
                                               GAsyncReadyCallback _callback_,
                                               gpointer _user_data_);
VALA_EXTERN GearyImapDBEmailIdentifier* geary_imap_db_folder_get_latest_id_finish (GearyImapDBFolder* self,
                                                                       GAsyncResult* _res_,
                                                                       GError** error);
static gboolean geary_imap_db_folder_get_latest_id_async_co (GearyImapDbFolderGetLatestIdAsyncData* _data_);
static void geary_imap_db_folder_get_latest_id_async_ready (GObject* source_object,
                                                     GAsyncResult* _res_,
                                                     gpointer _user_data_);
static void geary_imap_db_folder_get_id_extremes_async_data_free (gpointer _data);
static gboolean geary_imap_db_folder_get_id_extremes_async_co (GearyImapDbFolderGetIdExtremesAsyncData* _data_);
static Block74Data* block74_data_ref (Block74Data* _data74_);
static void block74_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda70_ (Block74Data* _data74_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GearyDbTransactionOutcome ___lambda70__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_get_id_extremes_async_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_);
static void geary_imap_db_folder_detach_multiple_emails_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_detach_multiple_emails_async (GearyImapDBFolder* self,
                                                        GeeCollection* ids,
                                                        GCancellable* cancellable,
                                                        GAsyncReadyCallback _callback_,
                                                        gpointer _user_data_);
VALA_EXTERN void geary_imap_db_folder_detach_multiple_emails_finish (GearyImapDBFolder* self,
                                                         GAsyncResult* _res_,
                                                         GError** error);
static gboolean geary_imap_db_folder_detach_multiple_emails_async_co (GearyImapDbFolderDetachMultipleEmailsAsyncData* _data_);
static Block75Data* block75_data_ref (Block75Data* _data75_);
static void block75_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda71_ (Block75Data* _data75_,
                                       GearyDbConnection* cx,
                                       GError** error);
static gint geary_imap_db_folder_do_get_unread_count_for_ids (GearyImapDBFolder* self,
                                                       GearyDbConnection* cx,
                                                       GeeCollection* ids,
                                                       GCancellable* cancellable,
                                                       GError** error);
static GearyDbTransactionOutcome ___lambda71__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_detach_multiple_emails_async_ready (GObject* source_object,
                                                              GAsyncResult* _res_,
                                                              gpointer _user_data_);
static void geary_imap_db_folder_detach_all_emails_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_detach_all_emails_async (GearyImapDBFolder* self,
                                                   GCancellable* cancellable,
                                                   GAsyncReadyCallback _callback_,
                                                   gpointer _user_data_);
VALA_EXTERN void geary_imap_db_folder_detach_all_emails_finish (GearyImapDBFolder* self,
                                                    GAsyncResult* _res_,
                                                    GError** error);
static gboolean geary_imap_db_folder_detach_all_emails_async_co (GearyImapDbFolderDetachAllEmailsAsyncData* _data_);
static Block76Data* block76_data_ref (Block76Data* _data76_);
static void block76_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda73_ (Block76Data* _data76_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GearyDbTransactionOutcome ___lambda73__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_detach_all_emails_async_ready (GObject* source_object,
                                                         GAsyncResult* _res_,
                                                         gpointer _user_data_);
static void geary_imap_db_folder_detach_emails_before_timestamp_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_detach_emails_before_timestamp (GearyImapDBFolder* self,
                                                          GDateTime* cutoff,
                                                          GCancellable* cancellable,
                                                          GAsyncReadyCallback _callback_,
                                                          gpointer _user_data_);
VALA_EXTERN GeeCollection* geary_imap_db_folder_detach_emails_before_timestamp_finish (GearyImapDBFolder* self,
                                                                           GAsyncResult* _res_,
                                                                           GError** error);
static gboolean geary_imap_db_folder_detach_emails_before_timestamp_co (GearyImapDbFolderDetachEmailsBeforeTimestampData* _data_);
static Block77Data* block77_data_ref (Block77Data* _data77_);
static void block77_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda74_ (Block77Data* _data77_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GearyDbTransactionOutcome ___lambda74__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_detach_emails_before_timestamp_ready (GObject* source_object,
                                                                GAsyncResult* _res_,
                                                                gpointer _user_data_);
static Block78Data* block78_data_ref (Block78Data* _data78_);
static void block78_data_unref (void * _userdata_);
static GearyDbTransactionOutcome ____lambda75_ (Block78Data* _data78_,
                                         GearyDbConnection* cx,
                                         GError** error);
static GearyDbTransactionOutcome _____lambda75__geary_db_transaction_method (GearyDbConnection* cx,
                                                                      GCancellable* cancellable,
                                                                      gpointer self,
                                                                      GError** error);
static void geary_imap_db_folder_mark_email_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_mark_email_async (GearyImapDBFolder* self,
                                            GeeCollection* to_mark,
                                            GearyEmailFlags* flags_to_add,
                                            GearyEmailFlags* flags_to_remove,
                                            GCancellable* cancellable,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_);
VALA_EXTERN void geary_imap_db_folder_mark_email_finish (GearyImapDBFolder* self,
                                             GAsyncResult* _res_,
                                             GError** error);
static gboolean geary_imap_db_folder_mark_email_async_co (GearyImapDbFolderMarkEmailAsyncData* _data_);
static Block79Data* block79_data_ref (Block79Data* _data79_);
static void block79_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda76_ (Block79Data* _data79_,
                                       GearyDbConnection* cx,
                                       GCancellable* cancellable,
                                       GError** error);
static GeeMap* geary_imap_db_folder_do_get_email_flags (GearyImapDBFolder* self,
                                                 GearyDbConnection* cx,
                                                 GeeCollection* ids,
                                                 GCancellable* cancellable,
                                                 GError** error);
static void geary_imap_db_folder_do_set_email_flags (GearyImapDBFolder* self,
                                              GearyDbConnection* cx,
                                              GeeMap* map,
                                              GCancellable* cancellable,
                                              GError** error);
static GearyDbTransactionOutcome ___lambda76__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_mark_email_async_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_);
static void geary_imap_db_folder_get_email_uids_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_get_email_uids_async (GearyImapDBFolder* self,
                                                GeeCollection* ids,
                                                GCancellable* cancellable,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_);
VALA_EXTERN GeeList* geary_imap_db_folder_get_email_uids_finish (GearyImapDBFolder* self,
                                                     GAsyncResult* _res_,
                                                     GError** error);
static gboolean geary_imap_db_folder_get_email_uids_async_co (GearyImapDbFolderGetEmailUidsAsyncData* _data_);
static Block80Data* block80_data_ref (Block80Data* _data80_);
static void block80_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda77_ (Block80Data* _data80_,
                                       GearyDbConnection* cx,
                                       GCancellable* cancellable,
                                       GError** error);
static GeeList* geary_imap_db_folder_do_get_email_uids (GearyImapDBFolder* self,
                                                 GearyDbConnection* cx,
                                                 GeeCollection* ids,
                                                 GCancellable* cancellable,
                                                 GError** error);
static GearyDbTransactionOutcome ___lambda77__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_get_email_uids_async_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_);
static void geary_imap_db_folder_get_email_flags_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_get_email_flags_async (GearyImapDBFolder* self,
                                                 GeeCollection* ids,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
VALA_EXTERN GeeMap* geary_imap_db_folder_get_email_flags_finish (GearyImapDBFolder* self,
                                                     GAsyncResult* _res_,
                                                     GError** error);
static gboolean geary_imap_db_folder_get_email_flags_async_co (GearyImapDbFolderGetEmailFlagsAsyncData* _data_);
static Block81Data* block81_data_ref (Block81Data* _data81_);
static void block81_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda78_ (Block81Data* _data81_,
                                       GearyDbConnection* cx,
                                       GCancellable* cancellable,
                                       GError** error);
static GearyDbTransactionOutcome ___lambda78__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_get_email_flags_async_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_);
static void geary_imap_db_folder_set_email_flags_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_set_email_flags_async (GearyImapDBFolder* self,
                                                 GeeMap* map,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
VALA_EXTERN void geary_imap_db_folder_set_email_flags_finish (GearyImapDBFolder* self,
                                                  GAsyncResult* _res_,
                                                  GError** error);
static gboolean geary_imap_db_folder_set_email_flags_async_co (GearyImapDbFolderSetEmailFlagsAsyncData* _data_);
static Block82Data* block82_data_ref (Block82Data* _data82_);
static void block82_data_unref (void * _userdata_);
static GearyDbTransactionOutcome ___lambda79_ (Block82Data* _data82_,
                                        GearyDbConnection* cx,
                                        GCancellable* cancellable,
                                        GError** error);
static GearyDbTransactionOutcome ____lambda79__geary_db_transaction_method (GearyDbConnection* cx,
                                                                     GCancellable* cancellable,
                                                                     gpointer self,
                                                                     GError** error);
static void geary_imap_db_folder_set_email_flags_async_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_);
static void geary_imap_db_folder_detach_single_email_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_detach_single_email_async (GearyImapDBFolder* self,
                                                     GearyImapDBEmailIdentifier* id,
                                                     GCancellable* cancellable,
                                                     GAsyncReadyCallback _callback_,
                                                     gpointer _user_data_);
VALA_EXTERN void geary_imap_db_folder_detach_single_email_finish (GearyImapDBFolder* self,
                                                      GAsyncResult* _res_,
                                                      gboolean* is_marked,
                                                      GError** error);
static gboolean geary_imap_db_folder_detach_single_email_async_co (GearyImapDbFolderDetachSingleEmailAsyncData* _data_);
static Block83Data* block83_data_ref (Block83Data* _data83_);
static void block83_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda80_ (Block83Data* _data83_,
                                       GearyDbConnection* cx,
                                       GError** error);
static void geary_imap_db_folder_do_remove_association_with_folder (GearyImapDBFolder* self,
                                                             GearyDbConnection* cx,
                                                             GearyImapDBFolderLocationIdentifier* location,
                                                             GCancellable* cancellable,
                                                             GError** error);
static GearyDbTransactionOutcome ___lambda80__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_detach_single_email_async_ready (GObject* source_object,
                                                           GAsyncResult* _res_,
                                                           gpointer _user_data_);
static void geary_imap_db_folder_mark_removed_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_mark_removed_async (GearyImapDBFolder* self,
                                              GeeCollection* ids,
                                              gboolean mark_removed,
                                              GCancellable* cancellable,
                                              GAsyncReadyCallback _callback_,
                                              gpointer _user_data_);
VALA_EXTERN GeeSet* geary_imap_db_folder_mark_removed_finish (GearyImapDBFolder* self,
                                                  GAsyncResult* _res_,
                                                  GError** error);
static gboolean geary_imap_db_folder_mark_removed_async_co (GearyImapDbFolderMarkRemovedAsyncData* _data_);
static Block84Data* block84_data_ref (Block84Data* _data84_);
static void block84_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda81_ (Block84Data* _data84_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GeeList* geary_imap_db_folder_do_get_all_locations (GearyImapDBFolder* self,
                                                    GearyDbConnection* cx,
                                                    GearyImapDBFolderListFlags flags,
                                                    GCancellable* cancellable,
                                                    GError** error);
static void geary_imap_db_folder_do_mark_unmark_removed (GearyImapDBFolder* self,
                                                  GearyDbConnection* cx,
                                                  GeeCollection* uids,
                                                  gboolean mark_removed,
                                                  GCancellable* cancellable,
                                                  GError** error);
static GearyDbTransactionOutcome ___lambda81__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_mark_removed_async_ready (GObject* source_object,
                                                    GAsyncResult* _res_,
                                                    gpointer _user_data_);
static void geary_imap_db_folder_get_marked_for_remove_count_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_get_marked_for_remove_count_async (GearyImapDBFolder* self,
                                                             GCancellable* cancellable,
                                                             GAsyncReadyCallback _callback_,
                                                             gpointer _user_data_);
VALA_EXTERN gint geary_imap_db_folder_get_marked_for_remove_count_finish (GearyImapDBFolder* self,
                                                              GAsyncResult* _res_,
                                                              GError** error);
static gboolean geary_imap_db_folder_get_marked_for_remove_count_async_co (GearyImapDbFolderGetMarkedForRemoveCountAsyncData* _data_);
static Block85Data* block85_data_ref (Block85Data* _data85_);
static void block85_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda82_ (Block85Data* _data85_,
                                       GearyDbConnection* cx,
                                       GError** error);
static gint geary_imap_db_folder_do_get_marked_removed_count (GearyImapDBFolder* self,
                                                       GearyDbConnection* cx,
                                                       GCancellable* cancellable,
                                                       GError** error);
static GearyDbTransactionOutcome ___lambda82__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_get_marked_for_remove_count_async_ready (GObject* source_object,
                                                                   GAsyncResult* _res_,
                                                                   gpointer _user_data_);
static void geary_imap_db_folder_get_marked_ids_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_get_marked_ids_async (GearyImapDBFolder* self,
                                                GCancellable* cancellable,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_);
VALA_EXTERN GeeSet* geary_imap_db_folder_get_marked_ids_finish (GearyImapDBFolder* self,
                                                    GAsyncResult* _res_,
                                                    GError** error);
static gboolean geary_imap_db_folder_get_marked_ids_async_co (GearyImapDbFolderGetMarkedIdsAsyncData* _data_);
static Block86Data* block86_data_ref (Block86Data* _data86_);
static void block86_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda83_ (Block86Data* _data86_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GearyDbTransactionOutcome ___lambda83__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_get_marked_ids_async_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_);
static void geary_imap_db_folder_clear_remove_markers_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_clear_remove_markers_async (GearyImapDBFolder* self,
                                                      GeeCollection* exceptions,
                                                      GCancellable* cancellable,
                                                      GAsyncReadyCallback _callback_,
                                                      gpointer _user_data_);
VALA_EXTERN void geary_imap_db_folder_clear_remove_markers_finish (GearyImapDBFolder* self,
                                                       GAsyncResult* _res_,
                                                       GError** error);
static gboolean geary_imap_db_folder_clear_remove_markers_async_co (GearyImapDbFolderClearRemoveMarkersAsyncData* _data_);
static Block87Data* block87_data_ref (Block87Data* _data87_);
static void block87_data_unref (void * _userdata_);
static GearyDbTransactionOutcome __lambda84_ (Block87Data* _data87_,
                                       GearyDbConnection* cx,
                                       GError** error);
static GearyDbTransactionOutcome ___lambda84__geary_db_transaction_method (GearyDbConnection* cx,
                                                                    GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static void geary_imap_db_folder_clear_remove_markers_async_ready (GObject* source_object,
                                                            GAsyncResult* _res_,
                                                            gpointer _user_data_);
static void geary_imap_db_folder_list_email_fields_by_id_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_db_folder_list_email_fields_by_id_async (GearyImapDBFolder* self,
                                                         GeeCollection* ids,
                                                         GearyImapDBFolderListFlags flags,
                                                         GCancellable* cancellable,
                                                         GAsyncReadyCallback _callback_,
                                                         gpointer _user_data_);
VALA_EXTERN GeeMap* geary_imap_db_folder_list_email_fields_by_id_finish (GearyImapDBFolder* self,
                                                             GAsyncResult* _res_,
                                                             GError** error);
static gboolean geary_imap_db_folder_list_email_fields_by_id_async_co (GearyImapDbFolderListEmailFieldsByIdAsyncData* _data_);
static Block88Data* block88_data_ref (Block88Data* _data88_);
static void block88_data_unref (void * _userdata_);
static GearyDbTransactionOutcome ___lambda85_ (Block88Data* _data88_,
                                        GearyDbConnection* cx,
                                        GCancellable* cancellable,
                                        GError** error);
static GearyDbTransactionOutcome ____lambda85__geary_db_transaction_method (GearyDbConnection* cx,
                                                                     GCancellable* cancellable,
                                                                     gpointer self,
                                                                     GError** error);
static void geary_imap_db_folder_list_email_fields_by_id_async_ready (GObject* source_object,
                                                               GAsyncResult* _res_,
                                                               gpointer _user_data_);
static gint64 geary_imap_db_folder_do_search_for_duplicates (GearyImapDBFolder* self,
                                                      GearyDbConnection* cx,
                                                      GearyEmail* email,
                                                      GearyImapDBEmailIdentifier* email_id,
                                                      GCancellable* cancellable,
                                                      GError** error);
static void geary_imap_db_folder_do_associate_with_folder (GearyImapDBFolder* self,
                                                    GearyDbConnection* cx,
                                                    gint64 message_id,
                                                    GearyImapUID* uid,
                                                    GCancellable* cancellable,
                                                    GError** error);
VALA_EXTERN GearyImapUID* geary_imap_db_email_identifier_get_uid (GearyImapDBEmailIdentifier* self);
static GearyImapDBFolderLocationIdentifier* geary_imap_db_folder_location_identifier_new (gint64 message_id,
                                                                                   GearyImapUID* uid,
                                                                                   gboolean marked_removed);
static GearyImapDBFolderLocationIdentifier* geary_imap_db_folder_location_identifier_construct (GType object_type,
                                                                                         gint64 message_id,
                                                                                         GearyImapUID* uid,
                                                                                         gboolean marked_removed);
static void geary_imap_db_folder_do_merge_email (GearyImapDBFolder* self,
                                          GearyDbConnection* cx,
                                          GearyImapDBFolderLocationIdentifier* location,
                                          GearyEmail* email,
                                          GearyEmailField* pre_fields,
                                          GearyEmailField* post_fields,
                                          gint* unread_count_change,
                                          GCancellable* cancellable,
                                          GError** error);
static void geary_imap_db_folder_do_merge_email_flags (GearyImapDBFolder* self,
                                                GearyDbConnection* cx,
                                                GearyImapDBFolderLocationIdentifier* location,
                                                GearyEmail* email,
                                                GearyEmailField* pre_fields,
                                                GearyEmailField* post_fields,
                                                gint* unread_count_change,
                                                GCancellable* cancellable,
                                                GError** error);
VALA_EXTERN gpointer geary_imap_db_message_row_ref (gpointer instance);
VALA_EXTERN void geary_imap_db_message_row_unref (gpointer instance);
VALA_EXTERN GParamSpec* geary_imap_db_param_spec_message_row (const gchar* name,
                                                  const gchar* nick,
                                                  const gchar* blurb,
                                                  GType object_type,
                                                  GParamFlags flags);
VALA_EXTERN void geary_imap_db_value_set_message_row (GValue* value,
                                          gpointer v_object);
VALA_EXTERN void geary_imap_db_value_take_message_row (GValue* value,
                                           gpointer v_object);
VALA_EXTERN gpointer geary_imap_db_value_get_message_row (const GValue* value);
VALA_EXTERN GType geary_imap_db_message_row_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GearyImapDBMessageRow* geary_imap_db_message_row_new_from_email (GearyEmail* email);
VALA_EXTERN GearyImapDBMessageRow* geary_imap_db_message_row_construct_from_email (GType object_type,
                                                                       GearyEmail* email);
VALA_EXTERN GearyEmailField geary_imap_db_message_row_get_fields (GearyImapDBMessageRow* self);
VALA_EXTERN const gchar* geary_imap_db_message_row_get_date (GearyImapDBMessageRow* self);
VALA_EXTERN gint64 geary_imap_db_message_row_get_date_time_t (GearyImapDBMessageRow* self);
VALA_EXTERN const gchar* geary_imap_db_message_row_get_from (GearyImapDBMessageRow* self);
VALA_EXTERN const gchar* geary_imap_db_message_row_get_sender (GearyImapDBMessageRow* self);
VALA_EXTERN const gchar* geary_imap_db_message_row_get_reply_to (GearyImapDBMessageRow* self);
VALA_EXTERN const gchar* geary_imap_db_message_row_get_to (GearyImapDBMessageRow* self);
VALA_EXTERN const gchar* geary_imap_db_message_row_get_cc (GearyImapDBMessageRow* self);
VALA_EXTERN const gchar* geary_imap_db_message_row_get_bcc (GearyImapDBMessageRow* self);
VALA_EXTERN const gchar* geary_imap_db_message_row_get_message_id (GearyImapDBMessageRow* self);
VALA_EXTERN const gchar* geary_imap_db_message_row_get_in_reply_to (GearyImapDBMessageRow* self);
VALA_EXTERN const gchar* geary_imap_db_message_row_get_references (GearyImapDBMessageRow* self);
VALA_EXTERN const gchar* geary_imap_db_message_row_get_subject (GearyImapDBMessageRow* self);
VALA_EXTERN GearyMemoryBuffer* geary_imap_db_message_row_get_header (GearyImapDBMessageRow* self);
VALA_EXTERN GearyMemoryBuffer* geary_imap_db_message_row_get_body (GearyImapDBMessageRow* self);
VALA_EXTERN const gchar* geary_imap_db_message_row_get_preview (GearyImapDBMessageRow* self);
VALA_EXTERN const gchar* geary_imap_db_message_row_get_email_flags (GearyImapDBMessageRow* self);
VALA_EXTERN const gchar* geary_imap_db_message_row_get_internaldate (GearyImapDBMessageRow* self);
VALA_EXTERN gint64 geary_imap_db_message_row_get_internaldate_time_t (GearyImapDBMessageRow* self);
VALA_EXTERN gint64 geary_imap_db_message_row_get_rfc822_size (GearyImapDBMessageRow* self);
VALA_EXTERN GeeList* geary_rf_c822_message_get_attachments (GearyRFC822Message* self,
                                                GearyMimeDispositionType disposition,
                                                GError** error);
VALA_EXTERN GType geary_imap_db_attachment_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GeeList* geary_imap_db_attachment_save_attachments (GearyDbConnection* cx,
                                                    GFile* attachments_path,
                                                    gint64 message_id,
                                                    GeeList* attachments,
                                                    GCancellable* cancellable,
                                                    GError** error);
VALA_EXTERN void geary_imap_db_folder_do_add_email_to_search_table (GearyDbConnection* cx,
                                                        gint64 message_id,
                                                        GearyEmail* email,
                                                        GCancellable* cancellable,
                                                        GError** error);
VALA_EXTERN void geary_imap_db_email_identifier_promote_with_message_id (GearyImapDBEmailIdentifier* self,
                                                             gint64 message_id);
static gboolean geary_imap_db_folder_do_check_for_message_search_row (GearyDbConnection* cx,
                                                               gint64 message_id,
                                                               GCancellable* cancellable,
                                                               GError** error);
VALA_EXTERN GearyImapDBMessageRow* geary_imap_db_folder_do_fetch_message_row (GearyDbConnection* cx,
                                                                  gint64 message_id,
                                                                  GearyEmailField requested_fields,
                                                                  GearyEmailField* db_fields,
                                                                  GCancellable* cancellable,
                                                                  GError** error);
static gchar* geary_imap_db_folder_fields_to_columns (GearyEmailField fields);
VALA_EXTERN GearyImapDBMessageRow* geary_imap_db_message_row_new_from_result (GearyEmailField requested_fields,
                                                                  GearyDbResult* results,
                                                                  GError** error);
VALA_EXTERN GearyImapDBMessageRow* geary_imap_db_message_row_construct_from_result (GType object_type,
                                                                        GearyEmailField requested_fields,
                                                                        GearyDbResult* results,
                                                                        GError** error);
VALA_EXTERN GearyEmail* geary_imap_db_message_row_to_email (GearyImapDBMessageRow* self,
                                                GearyImapDBEmailIdentifier* id,
                                                GError** error);
VALA_EXTERN void geary_imap_db_attachment_add_attachments (GearyDbConnection* cx,
                                               GFile* attachments_path,
                                               GearyEmail* email,
                                               gint64 message_id,
                                               GCancellable* cancellable,
                                               GError** error);
static GearyEmailFlags* geary_imap_db_folder_do_get_email_flags_single (GearyImapDBFolder* self,
                                                                 GearyDbConnection* cx,
                                                                 gint64 message_id,
                                                                 GCancellable* cancellable,
                                                                 GError** error);
static gboolean geary_imap_db_folder_do_fetch_email_fields (GearyImapDBFolder* self,
                                                     GearyDbConnection* cx,
                                                     gint64 message_id,
                                                     GearyEmailField* fields,
                                                     GCancellable* cancellable,
                                                     GError** error);
static void geary_imap_db_folder_do_merge_message_row (GearyImapDBFolder* self,
                                                GearyDbConnection* cx,
                                                GearyImapDBMessageRow* row,
                                                GearyEmailField* new_fields,
                                                gint* unread_count_change,
                                                GCancellable* cancellable,
                                                GError** error);
VALA_EXTERN gint64 geary_imap_db_message_row_get_id (GearyImapDBMessageRow* self);
static void geary_imap_db_folder_do_merge_email_in_search_table (GearyImapDBFolder* self,
                                                          GearyDbConnection* cx,
                                                          gint64 message_id,
                                                          GearyEmailField new_fields,
                                                          GearyEmail* email,
                                                          GCancellable* cancellable,
                                                          GError** error);
VALA_EXTERN void geary_imap_db_message_row_merge_from_remote (GearyImapDBMessageRow* self,
                                                  GearyEmail* email);
static gboolean ___lambda72_ (GearyImapDBFolder* self,
                       GearyEmailFlags* f);
static gboolean ____lambda72__gee_predicate (gconstpointer g,
                                      gpointer self);
static void geary_imap_db_folder_location_identifier_finalize (GearyImapDBFolderLocationIdentifier * obj);
static GType geary_imap_db_folder_location_identifier_get_type_once (void);
static void geary_imap_db_folder_finalize (GObject * obj);
static GType geary_imap_db_folder_get_type_once (void);
static void _vala_geary_imap_db_folder_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec);
static void _vala_geary_imap_db_folder_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec);

static inline gpointer
geary_imap_db_folder_get_instance_private (GearyImapDBFolder* self)
{
	return G_STRUCT_MEMBER_P (self, GearyImapDBFolder_private_offset);
}

gboolean
geary_imap_db_folder_list_flags_is_all_set (GearyImapDBFolderListFlags self,
                                            GearyImapDBFolderListFlags flags)
{
	gboolean result;
	result = (self & flags) == flags;
	return result;
}

gboolean
geary_imap_db_folder_list_flags_include_marked_for_remove (GearyImapDBFolderListFlags self)
{
	gboolean result;
	result = geary_imap_db_folder_list_flags_is_all_set (self, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDE_MARKED_FOR_REMOVE);
	return result;
}

GearyImapDBFolderListFlags
geary_imap_db_folder_list_flags_from_folder_flags (GearyFolderListFlags flags)
{
	GearyImapDBFolderListFlags _result_ = 0U;
	GearyImapDBFolderListFlags result;
	_result_ = GEARY_IMAP_DB_FOLDER_LIST_FLAGS_NONE;
	if (geary_folder_list_flags_is_all_set (flags, GEARY_FOLDER_LIST_FLAGS_INCLUDING_ID)) {
		_result_ |= GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDING_ID;
	}
	if (geary_folder_list_flags_is_all_set (flags, GEARY_FOLDER_LIST_FLAGS_OLDEST_TO_NEWEST)) {
		_result_ |= GEARY_IMAP_DB_FOLDER_LIST_FLAGS_OLDEST_TO_NEWEST;
	}
	result = _result_;
	return result;
}

 G_GNUC_NO_INLINE static GType
geary_imap_db_folder_list_flags_get_type_once (void)
{
	static const GFlagsValue values[] = {{GEARY_IMAP_DB_FOLDER_LIST_FLAGS_NONE, "GEARY_IMAP_DB_FOLDER_LIST_FLAGS_NONE", "none"}, {GEARY_IMAP_DB_FOLDER_LIST_FLAGS_PARTIAL_OK, "GEARY_IMAP_DB_FOLDER_LIST_FLAGS_PARTIAL_OK", "partial-ok"}, {GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDE_MARKED_FOR_REMOVE, "GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDE_MARKED_FOR_REMOVE", "include-marked-for-remove"}, {GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDING_ID, "GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDING_ID", "including-id"}, {GEARY_IMAP_DB_FOLDER_LIST_FLAGS_OLDEST_TO_NEWEST, "GEARY_IMAP_DB_FOLDER_LIST_FLAGS_OLDEST_TO_NEWEST", "oldest-to-newest"}, {GEARY_IMAP_DB_FOLDER_LIST_FLAGS_ONLY_INCOMPLETE, "GEARY_IMAP_DB_FOLDER_LIST_FLAGS_ONLY_INCOMPLETE", "only-incomplete"}, {0, NULL, NULL}};
	GType geary_imap_db_folder_list_flags_type_id;
	geary_imap_db_folder_list_flags_type_id = g_flags_register_static ("GearyImapDBFolderListFlags", values);
	return geary_imap_db_folder_list_flags_type_id;
}

GType
geary_imap_db_folder_list_flags_get_type (void)
{
	static gsize geary_imap_db_folder_list_flags_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_db_folder_list_flags_type_id__once)) {
		GType geary_imap_db_folder_list_flags_type_id;
		geary_imap_db_folder_list_flags_type_id = geary_imap_db_folder_list_flags_get_type_once ();
		g_once_init_leave (&geary_imap_db_folder_list_flags_type_id__once, geary_imap_db_folder_list_flags_type_id);
	}
	return geary_imap_db_folder_list_flags_type_id__once;
}

static gint
geary_imap_db_folder_real_get_manual_ref_count (GearyReferenceSemantics* base)
{
	gint result;
	GearyImapDBFolder* self;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_DB_TYPE_FOLDER, GearyImapDBFolder);
	result = self->priv->_manual_ref_count;
	return result;
}

static void
geary_imap_db_folder_real_set_manual_ref_count (GearyReferenceSemantics* base,
                                                gint value)
{
	GearyImapDBFolder* self;
	gint old_value;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_DB_TYPE_FOLDER, GearyImapDBFolder);
	old_value = geary_imap_db_folder_real_get_manual_ref_count (base);
	if (old_value != value) {
		self->priv->_manual_ref_count = value;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_db_folder_properties[GEARY_IMAP_DB_FOLDER_MANUAL_REF_COUNT_PROPERTY]);
	}
}

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

GearyImapDBFolder*
geary_imap_db_folder_construct (GType object_type,
                                GearyDbDatabase* db,
                                GearyFolderPath* path,
                                GFile* attachments_path,
                                const gchar* account_owner_email,
                                gint64 folder_id,
                                GearyImapFolderProperties* properties)
{
	GearyImapDBFolder * self = NULL;
	GearyDbDatabase* _tmp0_;
	GearyFolderPath* _tmp1_;
	GFile* _tmp2_;
	gchar* _tmp3_;
	GearyImapFolderProperties* _tmp4_;
	g_return_val_if_fail (GEARY_DB_IS_DATABASE (db), NULL);
	g_return_val_if_fail (GEARY_IS_FOLDER_PATH (path), NULL);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (attachments_path, g_file_get_type ()), NULL);
	g_return_val_if_fail (account_owner_email != NULL, NULL);
	g_return_val_if_fail (GEARY_IMAP_IS_FOLDER_PROPERTIES (properties), NULL);
	self = (GearyImapDBFolder*) geary_base_object_construct (object_type);
	_tmp0_ = _g_object_ref0 (db);
	_g_object_unref0 (self->priv->db);
	self->priv->db = _tmp0_;
	_tmp1_ = _g_object_ref0 (path);
	_g_object_unref0 (self->priv->path);
	self->priv->path = _tmp1_;
	_tmp2_ = _g_object_ref0 (attachments_path);
	_g_object_unref0 (self->priv->attachments_path);
	self->priv->attachments_path = _tmp2_;
	_tmp3_ = g_strdup (account_owner_email);
	_g_free0 (self->priv->account_owner_email);
	self->priv->account_owner_email = _tmp3_;
	self->priv->folder_id = folder_id;
	_tmp4_ = _g_object_ref0 (properties);
	_g_object_unref0 (self->priv->properties);
	self->priv->properties = _tmp4_;
	return self;
}

GearyImapDBFolder*
geary_imap_db_folder_new (GearyDbDatabase* db,
                          GearyFolderPath* path,
                          GFile* attachments_path,
                          const gchar* account_owner_email,
                          gint64 folder_id,
                          GearyImapFolderProperties* properties)
{
	return geary_imap_db_folder_construct (GEARY_IMAP_DB_TYPE_FOLDER, db, path, attachments_path, account_owner_email, folder_id, properties);
}

GearyFolderPath*
geary_imap_db_folder_get_path (GearyImapDBFolder* self)
{
	GearyFolderPath* _tmp0_;
	GearyFolderPath* result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_FOLDER (self), NULL);
	_tmp0_ = self->priv->path;
	result = _tmp0_;
	return result;
}

GearyImapFolderProperties*
geary_imap_db_folder_get_properties (GearyImapDBFolder* self)
{
	GearyImapFolderProperties* _tmp0_;
	GearyImapFolderProperties* _tmp1_;
	GearyImapFolderProperties* result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_FOLDER (self), NULL);
	_tmp0_ = self->priv->properties;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	result = _tmp1_;
	return result;
}

void
geary_imap_db_folder_set_properties (GearyImapDBFolder* self,
                                     GearyImapFolderProperties* properties)
{
	GearyImapFolderProperties* _tmp0_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_PROPERTIES (properties));
	_tmp0_ = _g_object_ref0 (properties);
	_g_object_unref0 (self->priv->properties);
	self->priv->properties = _tmp0_;
}

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

void
geary_imap_db_folder_get_email_count_async (GearyImapDBFolder* self,
                                            GearyImapDBFolderListFlags flags,
                                            GCancellable* cancellable,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_)
{
	GearyImapDbFolderGetEmailCountAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderGetEmailCountAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_get_email_count_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->flags = flags;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_db_folder_get_email_count_async_co (_data_);
}

gint
geary_imap_db_folder_get_email_count_finish (GearyImapDBFolder* self,
                                             GAsyncResult* _res_,
                                             GError** error)
{
	gint result;
	GearyImapDbFolderGetEmailCountAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		gint _tmp0_ = 0;
		return _tmp0_;
	}
	result = _data_->result;
	return result;
}

static Block51Data*
block51_data_ref (Block51Data* _data51_)
{
	g_atomic_int_inc (&_data51_->_ref_count_);
	return _data51_;
}

static void
block51_data_unref (void * _userdata_)
{
	Block51Data* _data51_;
	_data51_ = (Block51Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data51_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data51_->self;
		_g_object_unref0 (_data51_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block51Data, _data51_);
	}
}

static GearyDbTransactionOutcome
__lambda51_ (Block51Data* _data51_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	gint _tmp0_ = 0;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data51_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_imap_db_folder_do_get_email_count (self, cx, _data51_->flags, _data51_->cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_data51_->count = _tmp0_;
	result = GEARY_DB_TRANSACTION_OUTCOME_SUCCESS;
	return result;
}

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

static void
geary_imap_db_folder_get_email_count_async_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_)
{
	GearyImapDbFolderGetEmailCountAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_get_email_count_async_co (_data_);
}

static gboolean
geary_imap_db_folder_get_email_count_async_co (GearyImapDbFolderGetEmailCountAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data51_ = g_slice_new0 (Block51Data);
	_data_->_data51_->_ref_count_ = 1;
	_data_->_data51_->self = g_object_ref (_data_->self);
	_data_->_data51_->flags = _data_->flags;
	_g_object_unref0 (_data_->_data51_->cancellable);
	_data_->_data51_->cancellable = _data_->cancellable;
	_data_->_data51_->_async_data_ = _data_;
	_data_->_data51_->count = 0;
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda51__geary_db_transaction_method, _data_->_data51_, _data_->_data51_->cancellable, geary_imap_db_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_);
		block51_data_unref (_data_->_data51_);
		_data_->_data51_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->result = _data_->_data51_->count;
	block51_data_unref (_data_->_data51_);
	_data_->_data51_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_update_folder_status (GearyImapDBFolder* self,
                                           GearyImapFolderProperties* remote_properties,
                                           gboolean respect_marked_for_remove,
                                           GCancellable* cancellable,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_)
{
	GearyImapDbFolderUpdateFolderStatusData* _data_;
	GearyImapDBFolder* _tmp0_;
	GearyImapFolderProperties* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_PROPERTIES (remote_properties));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderUpdateFolderStatusData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_update_folder_status_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (remote_properties);
	_g_object_unref0 (_data_->remote_properties);
	_data_->remote_properties = _tmp1_;
	_data_->respect_marked_for_remove = respect_marked_for_remove;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_folder_update_folder_status_co (_data_);
}

void
geary_imap_db_folder_update_folder_status_finish (GearyImapDBFolder* self,
                                                  GAsyncResult* _res_,
                                                  GError** error)
{
	GearyImapDbFolderUpdateFolderStatusData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

/**
     * Updates folder's STATUS message count, attributes, recent, and unseen.
     *
     * UIDVALIDITY and UIDNEXT updated when the folder is
     * SELECT/EXAMINED (see update_folder_select_examine_async())
     * unless update_uid_info is true.
     */
static Block52Data*
block52_data_ref (Block52Data* _data52_)
{
	g_atomic_int_inc (&_data52_->_ref_count_);
	return _data52_;
}

static void
block52_data_unref (void * _userdata_)
{
	Block52Data* _data52_;
	_data52_ = (Block52Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data52_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data52_->self;
		_g_object_unref0 (_data52_->remote_properties);
		_g_object_unref0 (_data52_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block52Data, _data52_);
	}
}

static GearyDbTransactionOutcome
__lambda52_ (Block52Data* _data52_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp27_;
	GearyDbStatement* _tmp28_;
	GearyImapMailboxAttributes* _tmp29_;
	GearyImapMailboxAttributes* _tmp30_;
	gchar* _tmp31_;
	gchar* _tmp32_;
	GearyDbStatement* _tmp33_;
	GearyDbStatement* _tmp34_;
	GearyDbStatement* _tmp35_;
	gint _tmp36_;
	gint _tmp37_;
	GearyDbStatement* _tmp38_;
	GearyDbStatement* _tmp39_;
	GearyDbStatement* _tmp40_;
	GearyDbStatement* _tmp41_;
	GearyDbStatement* _tmp42_;
	GearyDbStatement* _tmp43_;
	GearyDbResult* _tmp44_;
	GearyDbResult* _tmp45_;
	gint _tmp46_;
	gint _tmp47_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data52_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	if (_data52_->respect_marked_for_remove) {
		GearyDbStatement* stmt = NULL;
		GearyDbStatement* _tmp0_;
		GearyDbStatement* _tmp1_;
		GearyDbStatement* _tmp2_;
		GearyDbStatement* _tmp3_;
		GearyDbStatement* _tmp4_;
		GearyDbStatement* _tmp5_;
		GearyDbStatement* _tmp6_;
		GearyDbResult* results = NULL;
		GearyDbStatement* _tmp7_;
		GearyDbResult* _tmp8_;
		_tmp0_ = geary_db_connection_prepare (cx, "\n" \
"                    SELECT flags\n" \
"                    FROM MessageTable\n" \
"                    WHERE id IN (\n" \
"                        SELECT message_id\n" \
"                        FROM MessageLocationTable\n" \
"                        WHERE folder_id = ? AND remove_marker = ?\n" \
"                    )\n" \
"                ", &_inner_error0_);
		stmt = _tmp0_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			return 0;
		}
		_tmp1_ = stmt;
		_tmp2_ = geary_db_statement_bind_rowid (_tmp1_, 0, self->priv->folder_id, &_inner_error0_);
		_tmp3_ = _tmp2_;
		_g_object_unref0 (_tmp3_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp4_ = stmt;
		_tmp5_ = geary_db_statement_bind_bool (_tmp4_, 1, TRUE, &_inner_error0_);
		_tmp6_ = _tmp5_;
		_g_object_unref0 (_tmp6_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp7_ = stmt;
		_tmp8_ = geary_db_statement_exec (_tmp7_, _data52_->cancellable, &_inner_error0_);
		results = _tmp8_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return 0;
		}
		while (TRUE) {
			GearyDbResult* _tmp9_;
			gboolean _tmp10_;
			gboolean _tmp11_;
			gint _tmp12_;
			const gchar* _tmp13_ = NULL;
			GearyDbResult* _tmp14_;
			const gchar* _tmp15_;
			GearyImapEmailFlags* flags = NULL;
			GearyImapMessageFlags* _tmp16_;
			GearyImapMessageFlags* _tmp17_;
			GearyImapEmailFlags* _tmp18_;
			GearyImapEmailFlags* _tmp19_;
			GearyImapEmailFlags* _tmp20_;
			GearyNamedFlag* _tmp21_;
			GearyNamedFlag* _tmp22_;
			GearyNamedFlag* _tmp23_;
			gboolean _tmp24_;
			GearyDbResult* _tmp26_;
			_tmp9_ = results;
			_tmp10_ = geary_db_result_get_finished (_tmp9_);
			_tmp11_ = _tmp10_;
			if (!(!_tmp11_)) {
				break;
			}
			_tmp12_ = _data52_->adjust_total;
			_data52_->adjust_total = _tmp12_ + 1;
			_tmp14_ = results;
			_tmp15_ = geary_db_result_string_at (_tmp14_, 0, &_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 0;
			}
			_tmp16_ = geary_imap_message_flags_deserialize (_tmp13_);
			_tmp17_ = _tmp16_;
			_tmp18_ = geary_imap_email_flags_new (_tmp17_);
			_tmp19_ = _tmp18_;
			_g_object_unref0 (_tmp17_);
			flags = _tmp19_;
			_tmp20_ = flags;
			_tmp21_ = geary_email_flags_get_UNREAD ();
			_tmp22_ = _tmp21_;
			_tmp23_ = _tmp22_;
			_tmp24_ = geary_named_flags_contains (G_TYPE_CHECK_INSTANCE_CAST (_tmp20_, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags), _tmp23_);
			_g_object_unref0 (_tmp23_);
			if (_tmp24_) {
				gint _tmp25_;
				_tmp25_ = _data52_->adjust_unseen;
				_data52_->adjust_unseen = _tmp25_ + 1;
			}
			_tmp26_ = results;
			geary_db_result_next (_tmp26_, _data52_->cancellable, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (flags);
				_g_object_unref0 (results);
				_g_object_unref0 (stmt);
				return 0;
			}
			_g_object_unref0 (flags);
		}
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
	}
	_tmp27_ = geary_db_connection_prepare (cx, "UPDATE FolderTable SET attributes=?, unread_count=? WHERE id=?", &_inner_error0_);
	stmt = _tmp27_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp28_ = stmt;
	_tmp29_ = geary_imap_folder_properties_get_attrs (_data52_->remote_properties);
	_tmp30_ = _tmp29_;
	_tmp31_ = geary_imap_flags_serialize (G_TYPE_CHECK_INSTANCE_CAST (_tmp30_, GEARY_IMAP_TYPE_FLAGS, GearyImapFlags));
	_tmp32_ = _tmp31_;
	_tmp33_ = geary_db_statement_bind_string (_tmp28_, 0, _tmp32_, &_inner_error0_);
	_tmp34_ = _tmp33_;
	_g_object_unref0 (_tmp34_);
	_g_free0 (_tmp32_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp35_ = stmt;
	_tmp36_ = geary_folder_properties_get_email_unread (G_TYPE_CHECK_INSTANCE_CAST (_data52_->remote_properties, GEARY_TYPE_FOLDER_PROPERTIES, GearyFolderProperties));
	_tmp37_ = _tmp36_;
	_tmp38_ = geary_db_statement_bind_int (_tmp35_, 1, _tmp37_, &_inner_error0_);
	_tmp39_ = _tmp38_;
	_g_object_unref0 (_tmp39_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp40_ = stmt;
	_tmp41_ = geary_db_statement_bind_rowid (_tmp40_, 2, self->priv->folder_id, &_inner_error0_);
	_tmp42_ = _tmp41_;
	_g_object_unref0 (_tmp42_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp43_ = stmt;
	_tmp44_ = geary_db_statement_exec (_tmp43_, _data52_->cancellable, &_inner_error0_);
	_tmp45_ = _tmp44_;
	_g_object_unref0 (_tmp45_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp46_ = geary_imap_folder_properties_get_status_messages (_data52_->remote_properties);
	_tmp47_ = _tmp46_;
	if (_tmp47_ >= 0) {
		gint _tmp48_;
		gint _tmp49_;
		_tmp48_ = geary_imap_folder_properties_get_status_messages (_data52_->remote_properties);
		_tmp49_ = _tmp48_;
		geary_imap_db_folder_do_update_last_seen_status_total (self, cx, _tmp49_, _data52_->cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return 0;
		}
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_COMMIT;
	_g_object_unref0 (stmt);
	return result;
}

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

static void
geary_imap_db_folder_update_folder_status_ready (GObject* source_object,
                                                 GAsyncResult* _res_,
                                                 gpointer _user_data_)
{
	GearyImapDbFolderUpdateFolderStatusData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_update_folder_status_co (_data_);
}

static gboolean
geary_imap_db_folder_update_folder_status_co (GearyImapDbFolderUpdateFolderStatusData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data52_ = g_slice_new0 (Block52Data);
	_data_->_data52_->_ref_count_ = 1;
	_data_->_data52_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data52_->remote_properties);
	_data_->_data52_->remote_properties = _data_->remote_properties;
	_data_->_data52_->respect_marked_for_remove = _data_->respect_marked_for_remove;
	_g_object_unref0 (_data_->_data52_->cancellable);
	_data_->_data52_->cancellable = _data_->cancellable;
	_data_->_data52_->_async_data_ = _data_;
	_data_->_data52_->adjust_unseen = 0;
	_data_->_data52_->adjust_total = 0;
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_tmp1_ = _data_->_data52_->cancellable;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_RW, ___lambda52__geary_db_transaction_method, _data_->_data52_, _data_->_tmp1_, geary_imap_db_folder_update_folder_status_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_);
		block52_data_unref (_data_->_data52_);
		_data_->_data52_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp2_ = _data_->self->priv->properties;
	_data_->_tmp3_ = geary_imap_folder_properties_get_unseen (_data_->_data52_->remote_properties);
	_data_->_tmp4_ = _data_->_tmp3_;
	geary_imap_folder_properties_set_status_unseen (_data_->_tmp2_, geary_numeric_int_floor (_data_->_tmp4_ - _data_->_data52_->adjust_unseen, 0));
	_data_->_tmp5_ = _data_->self->priv->properties;
	_data_->_tmp6_ = geary_imap_folder_properties_get_recent (_data_->_data52_->remote_properties);
	_data_->_tmp7_ = _data_->_tmp6_;
	geary_imap_folder_properties_set_recent (_data_->_tmp5_, _data_->_tmp7_);
	_data_->_tmp8_ = _data_->self->priv->properties;
	_data_->_tmp9_ = geary_imap_folder_properties_get_attrs (_data_->_data52_->remote_properties);
	_data_->_tmp10_ = _data_->_tmp9_;
	geary_imap_folder_properties_set_attrs (_data_->_tmp8_, _data_->_tmp10_);
	_data_->_tmp11_ = geary_imap_folder_properties_get_status_messages (_data_->_data52_->remote_properties);
	_data_->_tmp12_ = _data_->_tmp11_;
	if (_data_->_tmp12_ >= 0) {
		_data_->_tmp13_ = _data_->self->priv->properties;
		_data_->_tmp14_ = geary_imap_folder_properties_get_status_messages (_data_->_data52_->remote_properties);
		_data_->_tmp15_ = _data_->_tmp14_;
		geary_imap_folder_properties_set_status_message_count (_data_->_tmp13_, geary_numeric_int_floor (_data_->_tmp15_ - _data_->_data52_->adjust_total, 0), TRUE);
	}
	block52_data_unref (_data_->_data52_);
	_data_->_data52_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_update_folder_select_examine (GearyImapDBFolder* self,
                                                   GearyImapFolderProperties* remote_properties,
                                                   GCancellable* cancellable,
                                                   GAsyncReadyCallback _callback_,
                                                   gpointer _user_data_)
{
	GearyImapDbFolderUpdateFolderSelectExamineData* _data_;
	GearyImapDBFolder* _tmp0_;
	GearyImapFolderProperties* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_PROPERTIES (remote_properties));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderUpdateFolderSelectExamineData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_update_folder_select_examine_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (remote_properties);
	_g_object_unref0 (_data_->remote_properties);
	_data_->remote_properties = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_folder_update_folder_select_examine_co (_data_);
}

void
geary_imap_db_folder_update_folder_select_examine_finish (GearyImapDBFolder* self,
                                                          GAsyncResult* _res_,
                                                          GError** error)
{
	GearyImapDbFolderUpdateFolderSelectExamineData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

/**
     * Updates folder's SELECT/EXAMINE message count, UIDVALIDITY, UIDNEXT, unseen, and recent.
     * See also update_folder_status_async().
     */
static Block53Data*
block53_data_ref (Block53Data* _data53_)
{
	g_atomic_int_inc (&_data53_->_ref_count_);
	return _data53_;
}

static void
block53_data_unref (void * _userdata_)
{
	Block53Data* _data53_;
	_data53_ = (Block53Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data53_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data53_->self;
		_g_object_unref0 (_data53_->remote_properties);
		_g_object_unref0 (_data53_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block53Data, _data53_);
	}
}

static GearyDbTransactionOutcome
__lambda53_ (Block53Data* _data53_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	gint _tmp0_;
	gint _tmp1_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data53_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	geary_imap_db_folder_do_update_uid_info (self, cx, _data53_->remote_properties, _data53_->cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp0_ = geary_imap_folder_properties_get_select_examine_messages (_data53_->remote_properties);
	_tmp1_ = _tmp0_;
	if (_tmp1_ >= 0) {
		gint _tmp2_;
		gint _tmp3_;
		_tmp2_ = geary_imap_folder_properties_get_select_examine_messages (_data53_->remote_properties);
		_tmp3_ = _tmp2_;
		geary_imap_db_folder_do_update_last_seen_select_examine_total (self, cx, _tmp3_, _data53_->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
___lambda53__geary_db_transaction_method (GearyDbConnection* cx,
                                          GCancellable* cancellable,
                                          gpointer self,
                                          GError** error)
{
	GearyDbTransactionOutcome result;
	result = __lambda53_ (self, cx, error);
	return result;
}

static void
geary_imap_db_folder_update_folder_select_examine_ready (GObject* source_object,
                                                         GAsyncResult* _res_,
                                                         gpointer _user_data_)
{
	GearyImapDbFolderUpdateFolderSelectExamineData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_update_folder_select_examine_co (_data_);
}

static gboolean
geary_imap_db_folder_update_folder_select_examine_co (GearyImapDbFolderUpdateFolderSelectExamineData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data53_ = g_slice_new0 (Block53Data);
	_data_->_data53_->_ref_count_ = 1;
	_data_->_data53_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data53_->remote_properties);
	_data_->_data53_->remote_properties = _data_->remote_properties;
	_g_object_unref0 (_data_->_data53_->cancellable);
	_data_->_data53_->cancellable = _data_->cancellable;
	_data_->_data53_->_async_data_ = _data_;
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_RW, ___lambda53__geary_db_transaction_method, _data_->_data53_, _data_->_data53_->cancellable, geary_imap_db_folder_update_folder_select_examine_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_);
		block53_data_unref (_data_->_data53_);
		_data_->_data53_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp1_ = _data_->self->priv->properties;
	_data_->_tmp2_ = geary_imap_folder_properties_get_unseen (_data_->_data53_->remote_properties);
	_data_->_tmp3_ = _data_->_tmp2_;
	geary_imap_folder_properties_set_status_unseen (_data_->_tmp1_, _data_->_tmp3_);
	_data_->_tmp4_ = _data_->self->priv->properties;
	_data_->_tmp5_ = geary_imap_folder_properties_get_recent (_data_->_data53_->remote_properties);
	_data_->_tmp6_ = _data_->_tmp5_;
	geary_imap_folder_properties_set_recent (_data_->_tmp4_, _data_->_tmp6_);
	_data_->_tmp7_ = _data_->self->priv->properties;
	_data_->_tmp8_ = geary_imap_folder_properties_get_uid_validity (_data_->_data53_->remote_properties);
	_data_->_tmp9_ = _data_->_tmp8_;
	geary_imap_folder_properties_set_uid_validity (_data_->_tmp7_, _data_->_tmp9_);
	_data_->_tmp10_ = _data_->self->priv->properties;
	_data_->_tmp11_ = geary_imap_folder_properties_get_uid_next (_data_->_data53_->remote_properties);
	_data_->_tmp12_ = _data_->_tmp11_;
	geary_imap_folder_properties_set_uid_next (_data_->_tmp10_, _data_->_tmp12_);
	_data_->_tmp13_ = geary_imap_folder_properties_get_select_examine_messages (_data_->_data53_->remote_properties);
	_data_->_tmp14_ = _data_->_tmp13_;
	if (_data_->_tmp14_ >= 0) {
		_data_->_tmp15_ = _data_->self->priv->properties;
		_data_->_tmp16_ = geary_imap_folder_properties_get_select_examine_messages (_data_->_data53_->remote_properties);
		_data_->_tmp17_ = _data_->_tmp16_;
		geary_imap_folder_properties_set_select_examine_message_count (_data_->_tmp15_, _data_->_tmp17_);
	}
	block53_data_unref (_data_->_data53_);
	_data_->_data53_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_update_remote_selected_message_count (GearyImapDBFolder* self,
                                                           gint count,
                                                           GCancellable* cancellable,
                                                           GAsyncReadyCallback _callback_,
                                                           gpointer _user_data_)
{
	GearyImapDbFolderUpdateRemoteSelectedMessageCountData* _data_;
	GearyImapDBFolder* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderUpdateRemoteSelectedMessageCountData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_update_remote_selected_message_count_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->count = count;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_db_folder_update_remote_selected_message_count_co (_data_);
}

void
geary_imap_db_folder_update_remote_selected_message_count_finish (GearyImapDBFolder* self,
                                                                  GAsyncResult* _res_,
                                                                  GError** error)
{
	GearyImapDbFolderUpdateRemoteSelectedMessageCountData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static Block54Data*
block54_data_ref (Block54Data* _data54_)
{
	g_atomic_int_inc (&_data54_->_ref_count_);
	return _data54_;
}

static void
block54_data_unref (void * _userdata_)
{
	Block54Data* _data54_;
	_data54_ = (Block54Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data54_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data54_->self;
		_g_object_unref0 (_data54_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block54Data, _data54_);
	}
}

static GearyDbTransactionOutcome
__lambda54_ (Block54Data* _data54_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data54_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	geary_imap_db_folder_do_update_last_seen_select_examine_total (self, cx, _data54_->count, _data54_->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
___lambda54__geary_db_transaction_method (GearyDbConnection* cx,
                                          GCancellable* cancellable,
                                          gpointer self,
                                          GError** error)
{
	GearyDbTransactionOutcome result;
	result = __lambda54_ (self, cx, error);
	return result;
}

static void
geary_imap_db_folder_update_remote_selected_message_count_ready (GObject* source_object,
                                                                 GAsyncResult* _res_,
                                                                 gpointer _user_data_)
{
	GearyImapDbFolderUpdateRemoteSelectedMessageCountData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_update_remote_selected_message_count_co (_data_);
}

static gboolean
geary_imap_db_folder_update_remote_selected_message_count_co (GearyImapDbFolderUpdateRemoteSelectedMessageCountData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data54_ = g_slice_new0 (Block54Data);
	_data_->_data54_->_ref_count_ = 1;
	_data_->_data54_->self = g_object_ref (_data_->self);
	_data_->_data54_->count = _data_->count;
	_g_object_unref0 (_data_->_data54_->cancellable);
	_data_->_data54_->cancellable = _data_->cancellable;
	_data_->_data54_->_async_data_ = _data_;
	if (_data_->_data54_->count < 0) {
		block54_data_unref (_data_->_data54_);
		_data_->_data54_ = 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_->_tmp0_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_RW, ___lambda54__geary_db_transaction_method, _data_->_data54_, _data_->_data54_->cancellable, geary_imap_db_folder_update_remote_selected_message_count_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_);
		block54_data_unref (_data_->_data54_);
		_data_->_data54_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp1_ = _data_->self->priv->properties;
	geary_imap_folder_properties_set_select_examine_message_count (_data_->_tmp1_, _data_->_data54_->count);
	block54_data_unref (_data_->_data54_);
	_data_->_data54_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_db_folder_create_or_merge_email_async_data_free (gpointer _data)
{
	GearyImapDbFolderCreateOrMergeEmailAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->emails);
	_g_object_unref0 (_data_->harvester);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbFolderCreateOrMergeEmailAsyncData, _data_);
}

void
geary_imap_db_folder_create_or_merge_email_async (GearyImapDBFolder* self,
                                                  GeeCollection* emails,
                                                  gboolean update_totals,
                                                  GearyContactHarvester* harvester,
                                                  GCancellable* cancellable,
                                                  GAsyncReadyCallback _callback_,
                                                  gpointer _user_data_)
{
	GearyImapDbFolderCreateOrMergeEmailAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GeeCollection* _tmp1_;
	GearyContactHarvester* _tmp2_;
	GCancellable* _tmp3_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (emails, GEE_TYPE_COLLECTION));
	g_return_if_fail (GEARY_IS_CONTACT_HARVESTER (harvester));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderCreateOrMergeEmailAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_create_or_merge_email_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (emails);
	_g_object_unref0 (_data_->emails);
	_data_->emails = _tmp1_;
	_data_->update_totals = update_totals;
	_tmp2_ = _g_object_ref0 (harvester);
	_g_object_unref0 (_data_->harvester);
	_data_->harvester = _tmp2_;
	_tmp3_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp3_;
	geary_imap_db_folder_create_or_merge_email_async_co (_data_);
}

GeeMap*
geary_imap_db_folder_create_or_merge_email_finish (GearyImapDBFolder* self,
                                                   GAsyncResult* _res_,
                                                   GError** error)
{
	GeeMap* result;
	GearyImapDbFolderCreateOrMergeEmailAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block55Data*
block55_data_ref (Block55Data* _data55_)
{
	g_atomic_int_inc (&_data55_->_ref_count_);
	return _data55_;
}

static void
block55_data_unref (void * _userdata_)
{
	Block55Data* _data55_;
	_data55_ = (Block55Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data55_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data55_->self;
		_g_object_unref0 (_data55_->results);
		_g_object_unref0 (_data55_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block55Data, _data55_);
	}
}

static Block56Data*
block56_data_ref (Block56Data* _data56_)
{
	g_atomic_int_inc (&_data56_->_ref_count_);
	return _data56_;
}

static void
block56_data_unref (void * _userdata_)
{
	Block56Data* _data56_;
	_data56_ = (Block56Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data56_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data56_->_data55_->self;
		_g_object_unref0 (_data56_->complete_ids);
		_g_object_unref0 (_data56_->slice);
		block55_data_unref (_data56_->_data55_);
		_data56_->_data55_ = NULL;
		g_slice_free (Block56Data, _data56_);
	}
}

static GearyDbTransactionOutcome
___lambda55_ (Block56Data* _data56_,
              GearyDbConnection* cx,
              GError** error)
{
	Block55Data* _data55_;
	GearyImapDBFolder* self;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	_data55_ = _data56_->_data55_;
	self = _data55_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	{
		GeeList* _email_list = NULL;
		GeeList* _tmp0_;
		gint _email_size = 0;
		GeeList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _email_index = 0;
		_tmp0_ = _data56_->slice;
		_email_list = _tmp0_;
		_tmp1_ = _email_list;
		_tmp2_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEE_TYPE_COLLECTION, GeeCollection));
		_tmp3_ = _tmp2_;
		_email_size = _tmp3_;
		_email_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			GearyEmail* email = NULL;
			GeeList* _tmp6_;
			gpointer _tmp7_;
			GearyEmailField pre_fields = 0;
			GearyEmailField post_fields = 0;
			gint unread_change = 0;
			gboolean created = FALSE;
			GearyEmail* _tmp8_;
			GearyEmailField _tmp9_ = 0;
			GearyEmailField _tmp10_ = 0;
			gboolean _tmp11_;
			GeeHashMap* _tmp12_;
			GearyEmail* _tmp13_;
			gboolean _tmp14_ = FALSE;
			_email_index = _email_index + 1;
			_tmp4_ = _email_index;
			_tmp5_ = _email_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _email_list;
			_tmp7_ = gee_list_get (_tmp6_, _email_index);
			email = (GearyEmail*) _tmp7_;
			unread_change = 0;
			_tmp8_ = email;
			_tmp11_ = geary_imap_db_folder_do_create_or_merge_email (self, cx, _tmp8_, &_tmp9_, &_tmp10_, &unread_change, _data55_->cancellable, &_inner_error0_);
			pre_fields = _tmp9_;
			post_fields = _tmp10_;
			created = _tmp11_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (email);
				return 0;
			}
			_tmp12_ = _data55_->results;
			_tmp13_ = email;
			gee_abstract_map_set (G_TYPE_CHECK_INSTANCE_CAST (_tmp12_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _tmp13_, (gpointer) ((gintptr) created));
			if (geary_email_field_is_all_set (post_fields, GEARY_EMAIL_FIELD_ALL)) {
				_tmp14_ = !geary_email_field_is_all_set (pre_fields, GEARY_EMAIL_FIELD_ALL);
			} else {
				_tmp14_ = FALSE;
			}
			if (_tmp14_) {
				GeeArrayList* _tmp15_;
				GearyEmail* _tmp16_;
				GearyEmailIdentifier* _tmp17_;
				GearyEmailIdentifier* _tmp18_;
				_tmp15_ = _data56_->complete_ids;
				_tmp16_ = email;
				_tmp17_ = geary_email_get_id (_tmp16_);
				_tmp18_ = _tmp17_;
				gee_abstract_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp15_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection), _tmp18_);
			}
			if (_data55_->update_totals) {
				geary_imap_db_folder_do_add_to_unread_count (self, cx, unread_change, _data55_->cancellable, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					g_propagate_error (error, _inner_error0_);
					_g_object_unref0 (email);
					return 0;
				}
				_data56_->total_unread_change += unread_change;
			}
			_g_object_unref0 (email);
		}
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_COMMIT;
	return result;
}

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

static void
geary_imap_db_folder_create_or_merge_email_async_ready (GObject* source_object,
                                                        GAsyncResult* _res_,
                                                        gpointer _user_data_)
{
	GearyImapDbFolderCreateOrMergeEmailAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_create_or_merge_email_async_co (_data_);
}

static gboolean
geary_imap_db_folder_create_or_merge_email_async_co (GearyImapDbFolderCreateOrMergeEmailAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data55_ = g_slice_new0 (Block55Data);
	_data_->_data55_->_ref_count_ = 1;
	_data_->_data55_->self = g_object_ref (_data_->self);
	_data_->_data55_->update_totals = _data_->update_totals;
	_g_object_unref0 (_data_->_data55_->cancellable);
	_data_->_data55_->cancellable = _data_->cancellable;
	_data_->_data55_->_async_data_ = _data_;
	_data_->_tmp0_ = gee_hash_map_new (GEARY_TYPE_EMAIL, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, G_TYPE_BOOLEAN, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->_data55_->results = _data_->_tmp0_;
	_data_->_tmp1_ = geary_traverse (GEARY_TYPE_EMAIL, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, G_TYPE_CHECK_INSTANCE_CAST (_data_->emails, GEE_TYPE_ITERABLE, GeeIterable));
	_data_->_tmp2_ = _data_->_tmp1_;
	_data_->_tmp3_ = geary_iterable_to_array_list (_data_->_tmp2_, NULL, NULL, NULL);
	_data_->_tmp4_ = _data_->_tmp3_;
	_g_object_unref0 (_data_->_tmp2_);
	_data_->list = _data_->_tmp4_;
	_data_->index = 0;
	while (TRUE) {
		_data_->_data56_ = g_slice_new0 (Block56Data);
		_data_->_data56_->_ref_count_ = 1;
		_data_->_data56_->_data55_ = block55_data_ref (_data_->_data55_);
		_data_->_tmp5_ = _data_->list;
		_data_->_tmp6_ = gee_abstract_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp5_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection));
		_data_->_tmp7_ = _data_->_tmp6_;
		if (!(_data_->index < _data_->_tmp7_)) {
			block56_data_unref (_data_->_data56_);
			_data_->_data56_ = NULL;
			break;
		}
		_data_->_tmp8_ = _data_->list;
		_data_->_tmp9_ = gee_abstract_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp8_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection));
		_data_->_tmp10_ = _data_->_tmp9_;
		_data_->stop = geary_numeric_int_ceiling (_data_->index + GEARY_IMAP_DB_FOLDER_CREATE_MERGE_EMAIL_CHUNK_COUNT, _data_->_tmp10_);
		_data_->_tmp11_ = _data_->list;
		_data_->_tmp12_ = gee_abstract_list_slice (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp11_, GEE_TYPE_ABSTRACT_LIST, GeeAbstractList), _data_->index, _data_->stop);
		_data_->_data56_->slice = _data_->_tmp12_;
		_data_->_tmp13_ = gee_array_list_new (GEARY_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
		_data_->_data56_->complete_ids = _data_->_tmp13_;
		_data_->_data56_->total_unread_change = 0;
		_data_->_tmp14_ = _data_->self->priv->db;
		_data_->_tmp15_ = _data_->_data55_->cancellable;
		_data_->_state_ = 1;
		geary_db_database_exec_transaction_async (_data_->_tmp14_, GEARY_DB_TRANSACTION_TYPE_RW, ____lambda55__geary_db_transaction_method, _data_->_data56_, _data_->_tmp15_, geary_imap_db_folder_create_or_merge_email_async_ready, _data_);
		return FALSE;
		_state_1:
		geary_db_database_exec_transaction_finish (_data_->_tmp14_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			block56_data_unref (_data_->_data56_);
			_data_->_data56_ = NULL;
			_g_object_unref0 (_data_->list);
			block55_data_unref (_data_->_data55_);
			_data_->_data55_ = NULL;
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		if (_data_->_data55_->update_totals) {
			_data_->_tmp16_ = _data_->self->priv->properties;
			_data_->_tmp17_ = _data_->self->priv->properties;
			_data_->_tmp18_ = geary_folder_properties_get_email_unread (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp17_, GEARY_TYPE_FOLDER_PROPERTIES, GearyFolderProperties));
			_data_->_tmp19_ = _data_->_tmp18_;
			geary_imap_folder_properties_set_status_unseen (_data_->_tmp16_, CLAMP (_data_->_tmp19_ + _data_->_data56_->total_unread_change, 0, G_MAXINT));
		}
		_data_->_tmp20_ = _data_->_data56_->complete_ids;
		_data_->_tmp21_ = gee_abstract_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp20_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection));
		_data_->_tmp22_ = _data_->_tmp21_;
		if (_data_->_tmp22_ > 0) {
			_data_->_tmp23_ = _data_->_data56_->complete_ids;
			g_signal_emit (_data_->self, geary_imap_db_folder_signals[GEARY_IMAP_DB_FOLDER_EMAIL_COMPLETE_SIGNAL], 0, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp23_, GEE_TYPE_COLLECTION, GeeCollection));
		}
		_data_->index = _data_->stop;
		_data_->_tmp24_ = _data_->list;
		_data_->_tmp25_ = gee_abstract_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp24_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection));
		_data_->_tmp26_ = _data_->_tmp25_;
		if (_data_->index < _data_->_tmp26_) {
			_data_->_state_ = 2;
			geary_scheduler_sleep_ms_async ((guint) 100, geary_imap_db_folder_create_or_merge_email_async_ready, _data_);
			return FALSE;
			_state_2:
			geary_scheduler_sleep_ms_finish (_data_->_res_);
		}
		block56_data_unref (_data_->_data56_);
		_data_->_data56_ = NULL;
	}
	_data_->_tmp27_ = _data_->_data55_->results;
	_data_->_tmp28_ = gee_abstract_map_get_keys (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp27_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap));
	_data_->_tmp29_ = _data_->_tmp28_;
	_data_->_tmp30_ = _data_->_tmp29_;
	_data_->_state_ = 3;
	geary_contact_harvester_harvest_from_email (_data_->harvester, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp30_, GEE_TYPE_COLLECTION, GeeCollection), _data_->_data55_->cancellable, geary_imap_db_folder_create_or_merge_email_async_ready, _data_);
	return FALSE;
	_state_3:
	geary_contact_harvester_harvest_from_email_finish (_data_->harvester, _data_->_res_, &_data_->_inner_error0_);
	_g_object_unref0 (_data_->_tmp30_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->list);
		block55_data_unref (_data_->_data55_);
		_data_->_data55_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp31_ = _data_->_data55_->results;
	_data_->_tmp32_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp31_, GEE_TYPE_MAP, GeeMap));
	_data_->result = _data_->_tmp32_;
	_g_object_unref0 (_data_->list);
	block55_data_unref (_data_->_data55_);
	_data_->_data55_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_contains_identifiers (GearyImapDBFolder* self,
                                           GeeCollection* ids,
                                           GCancellable* cancellable,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_)
{
	GearyImapDbFolderContainsIdentifiersData* _data_;
	GearyImapDBFolder* _tmp0_;
	GeeCollection* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderContainsIdentifiersData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_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_imap_db_folder_contains_identifiers_co (_data_);
}

GeeCollection*
geary_imap_db_folder_contains_identifiers_finish (GearyImapDBFolder* self,
                                                  GAsyncResult* _res_,
                                                  GError** error)
{
	GeeCollection* result;
	GearyImapDbFolderContainsIdentifiersData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

/** Returns a subset of the given ids that are in this folder. */
static Block57Data*
block57_data_ref (Block57Data* _data57_)
{
	g_atomic_int_inc (&_data57_->_ref_count_);
	return _data57_;
}

static void
block57_data_unref (void * _userdata_)
{
	Block57Data* _data57_;
	_data57_ = (Block57Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data57_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data57_->self;
		_g_object_unref0 (_data57_->contained_ids);
		_g_object_unref0 (_data57_->ids);
		_g_object_unref0 (self);
		g_slice_free (Block57Data, _data57_);
	}
}

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

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

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

static Block58Data*
block58_data_ref (Block58Data* _data58_)
{
	g_atomic_int_inc (&_data58_->_ref_count_);
	return _data58_;
}

static void
block58_data_unref (void * _userdata_)
{
	Block58Data* _data58_;
	_data58_ = (Block58Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data58_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data58_->_data57_->self;
		_g_object_unref0 (_data58_->valid_ids);
		block57_data_unref (_data58_->_data57_);
		_data58_->_data57_ = NULL;
		g_slice_free (Block58Data, _data58_);
	}
}

static GearyDbTransactionOutcome
___lambda56_ (Block58Data* _data58_,
              GearyDbConnection* cx,
              GCancellable* cancellable,
              GError** error)
{
	Block57Data* _data57_;
	GearyImapDBFolder* self;
	GString* sql = NULL;
	GString* _tmp0_;
	GString* _tmp19_;
	GearyDbStatement* stmt = NULL;
	GString* _tmp20_;
	const gchar* _tmp21_;
	GearyDbStatement* _tmp22_;
	GearyDbStatement* _tmp23_;
	GearyDbStatement* _tmp24_;
	GearyDbStatement* _tmp25_;
	GearyDbStatement* _tmp26_;
	GearyDbStatement* _tmp27_;
	GearyDbStatement* _tmp28_;
	GearyDbResult* results = NULL;
	GearyDbStatement* _tmp29_;
	GearyDbResult* _tmp30_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	_data57_ = _data58_->_data57_;
	self = _data57_->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);
	_tmp0_ = g_string_new ("\n" \
"                        SELECT message_id\n" \
"                        FROM MessageLocationTable\n" \
"                        WHERE message_id IN (\n" \
"                    ");
	sql = _tmp0_;
	{
		GeeIterator* _id_it = NULL;
		GeeIterator* _tmp1_;
		_tmp1_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_data57_->ids, GEE_TYPE_ITERABLE, GeeIterable));
		_id_it = _tmp1_;
		while (TRUE) {
			GeeIterator* _tmp2_;
			GearyEmailIdentifier* id = NULL;
			GeeIterator* _tmp3_;
			gpointer _tmp4_;
			GearyImapDBEmailIdentifier* id_impl = NULL;
			GearyEmailIdentifier* _tmp5_;
			GearyImapDBEmailIdentifier* _tmp6_;
			GearyImapDBEmailIdentifier* _tmp7_;
			_tmp2_ = _id_it;
			if (!gee_iterator_next (_tmp2_)) {
				break;
			}
			_tmp3_ = _id_it;
			_tmp4_ = gee_iterator_get (_tmp3_);
			id = (GearyEmailIdentifier*) _tmp4_;
			_tmp5_ = id;
			_tmp6_ = _g_object_ref0 (GEARY_IMAP_DB_IS_EMAIL_IDENTIFIER (_tmp5_) ? ((GearyImapDBEmailIdentifier*) _tmp5_) : NULL);
			id_impl = _tmp6_;
			_tmp7_ = id_impl;
			if (_tmp7_ != NULL) {
				GString* _tmp8_;
				GearyImapDBEmailIdentifier* _tmp9_;
				gint64 _tmp10_;
				gint64 _tmp11_;
				gchar* _tmp12_;
				gchar* _tmp13_;
				GeeHashMap* _tmp14_;
				GearyImapDBEmailIdentifier* _tmp15_;
				gint64 _tmp16_;
				gint64 _tmp17_;
				GearyImapDBEmailIdentifier* _tmp18_;
				_tmp8_ = sql;
				_tmp9_ = id_impl;
				_tmp10_ = geary_imap_db_email_identifier_get_message_id (_tmp9_);
				_tmp11_ = _tmp10_;
				_tmp12_ = g_strdup_printf ("%" G_GINT64_FORMAT, _tmp11_);
				_tmp13_ = _tmp12_;
				g_string_append (_tmp8_, _tmp13_);
				_g_free0 (_tmp13_);
				_tmp14_ = _data58_->valid_ids;
				_tmp15_ = id_impl;
				_tmp16_ = geary_imap_db_email_identifier_get_message_id (_tmp15_);
				_tmp17_ = _tmp16_;
				_tmp18_ = id_impl;
				gee_abstract_map_set (G_TYPE_CHECK_INSTANCE_CAST (_tmp14_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), &_tmp17_, _tmp18_);
			}
			_g_object_unref0 (id_impl);
			_g_object_unref0 (id);
		}
		_g_object_unref0 (_id_it);
	}
	_tmp19_ = sql;
	g_string_append (_tmp19_, ") AND folder_id=? AND remove_marker<>?");
	_tmp20_ = sql;
	_tmp21_ = _tmp20_->str;
	_tmp22_ = geary_db_connection_prepare (cx, _tmp21_, &_inner_error0_);
	stmt = _tmp22_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp23_ = stmt;
	_tmp24_ = geary_db_statement_bind_rowid (_tmp23_, 0, self->priv->folder_id, &_inner_error0_);
	_tmp25_ = _tmp24_;
	_g_object_unref0 (_tmp25_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp26_ = stmt;
	_tmp27_ = geary_db_statement_bind_bool (_tmp26_, 0, FALSE, &_inner_error0_);
	_tmp28_ = _tmp27_;
	_g_object_unref0 (_tmp28_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp29_ = stmt;
	_tmp30_ = geary_db_statement_exec (_tmp29_, cancellable, &_inner_error0_);
	results = _tmp30_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	while (TRUE) {
		GearyDbResult* _tmp31_;
		gboolean _tmp32_;
		gboolean _tmp33_;
		gint64 message_id = 0LL;
		GearyDbResult* _tmp34_;
		GeeHashMap* _tmp35_;
		GeeHashMap* _tmp36_;
		gpointer _tmp37_;
		GearyImapDBEmailIdentifier* _tmp38_;
		GearyDbResult* _tmp39_;
		_tmp31_ = results;
		_tmp32_ = geary_db_result_get_finished (_tmp31_);
		_tmp33_ = _tmp32_;
		if (!(!_tmp33_)) {
			break;
		}
		_tmp34_ = results;
		message_id = geary_db_result_int64_at (_tmp34_, 0, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			_g_string_free0 (sql);
			return 0;
		}
		_tmp35_ = _data57_->contained_ids;
		_tmp36_ = _data58_->valid_ids;
		_tmp37_ = gee_abstract_map_get (G_TYPE_CHECK_INSTANCE_CAST (_tmp36_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), &message_id);
		_tmp38_ = (GearyImapDBEmailIdentifier*) _tmp37_;
		gee_abstract_map_set (G_TYPE_CHECK_INSTANCE_CAST (_tmp35_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), &message_id, _tmp38_);
		_g_object_unref0 (_tmp38_);
		_tmp39_ = results;
		geary_db_result_next (_tmp39_, cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			_g_string_free0 (sql);
			return 0;
		}
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_COMMIT;
	_g_object_unref0 (results);
	_g_object_unref0 (stmt);
	_g_string_free0 (sql);
	return result;
}

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

static void
geary_imap_db_folder_contains_identifiers_ready (GObject* source_object,
                                                 GAsyncResult* _res_,
                                                 gpointer _user_data_)
{
	GearyImapDbFolderContainsIdentifiersData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_contains_identifiers_co (_data_);
}

static gboolean
geary_imap_db_folder_contains_identifiers_co (GearyImapDbFolderContainsIdentifiersData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data57_ = g_slice_new0 (Block57Data);
	_data_->_data57_->_ref_count_ = 1;
	_data_->_data57_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data57_->ids);
	_data_->_data57_->ids = _data_->ids;
	_data_->_data57_->_async_data_ = _data_;
	_data_->_tmp0_ = gee_hash_map_new (G_TYPE_INT64, (GBoxedCopyFunc) _int64_dup, (GDestroyNotify) g_free, GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _geary_collection_int64_hash_func_gee_hash_data_func, NULL, NULL, _geary_collection_int64_equal_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	_data_->_data57_->contained_ids = _data_->_tmp0_;
	_data_->_tmp1_ = gee_collection_get_is_empty (_data_->_data57_->ids);
	_data_->_tmp2_ = _data_->_tmp1_;
	if (!_data_->_tmp2_) {
		_data_->_data58_ = g_slice_new0 (Block58Data);
		_data_->_data58_->_ref_count_ = 1;
		_data_->_data58_->_data57_ = block57_data_ref (_data_->_data57_);
		_data_->_tmp3_ = gee_hash_map_new (G_TYPE_INT64, (GBoxedCopyFunc) _int64_dup, (GDestroyNotify) g_free, GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _geary_collection_int64_hash_func_gee_hash_data_func, NULL, NULL, _geary_collection_int64_equal_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
		_data_->_data58_->valid_ids = _data_->_tmp3_;
		_data_->_tmp4_ = _data_->self->priv->db;
		_data_->_state_ = 1;
		geary_db_database_exec_transaction_async (_data_->_tmp4_, GEARY_DB_TRANSACTION_TYPE_RO, ____lambda56__geary_db_transaction_method, _data_->_data58_, _data_->cancellable, geary_imap_db_folder_contains_identifiers_ready, _data_);
		return FALSE;
		_state_1:
		geary_db_database_exec_transaction_finish (_data_->_tmp4_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			block58_data_unref (_data_->_data58_);
			_data_->_data58_ = NULL;
			block57_data_unref (_data_->_data57_);
			_data_->_data57_ = NULL;
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		block58_data_unref (_data_->_data58_);
		_data_->_data58_ = NULL;
	}
	_data_->_tmp5_ = _data_->_data57_->contained_ids;
	_data_->_tmp6_ = gee_abstract_map_get_values (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp5_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap));
	_data_->_tmp7_ = _data_->_tmp6_;
	_data_->result = _data_->_tmp7_;
	block57_data_unref (_data_->_data57_);
	_data_->_data57_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_list_email_by_id_async (GearyImapDBFolder* self,
                                             GearyImapDBEmailIdentifier* initial_id,
                                             gint count,
                                             GearyEmailField required_fields,
                                             GearyImapDBFolderListFlags flags,
                                             GCancellable* cancellable,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_)
{
	GearyImapDbFolderListEmailByIdAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GearyImapDBEmailIdentifier* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail ((initial_id == NULL) || GEARY_IMAP_DB_IS_EMAIL_IDENTIFIER (initial_id));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderListEmailByIdAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_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_imap_db_folder_list_email_by_id_async_co (_data_);
}

GeeList*
geary_imap_db_folder_list_email_by_id_finish (GearyImapDBFolder* self,
                                              GAsyncResult* _res_,
                                              GError** error)
{
	GeeList* result;
	GearyImapDbFolderListEmailByIdAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block59Data*
block59_data_ref (Block59Data* _data59_)
{
	g_atomic_int_inc (&_data59_->_ref_count_);
	return _data59_;
}

static void
block59_data_unref (void * _userdata_)
{
	Block59Data* _data59_;
	_data59_ = (Block59Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data59_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data59_->self;
		_g_object_unref0 (_data59_->locations);
		_g_object_unref0 (_data59_->initial_id);
		_g_object_unref0 (_data59_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block59Data, _data59_);
	}
}

static GearyDbTransactionOutcome
__lambda57_ (Block59Data* _data59_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GearyImapUID* start_uid = NULL;
	GearyImapUID* _tmp11_;
	GString* sql = NULL;
	GString* _tmp12_;
	GearyDbStatement* stmt = NULL;
	GString* _tmp18_;
	const gchar* _tmp19_;
	GearyDbStatement* _tmp20_;
	GearyDbStatement* _tmp21_;
	GearyDbStatement* _tmp22_;
	GearyDbStatement* _tmp23_;
	GearyDbStatement* _tmp24_;
	GearyImapUID* _tmp25_;
	gint64 _tmp26_;
	gint64 _tmp27_;
	GearyDbStatement* _tmp28_;
	GearyDbStatement* _tmp29_;
	GearyDbResult* _tmp33_ = NULL;
	GearyDbStatement* _tmp34_;
	GearyDbResult* _tmp35_;
	GeeList* _tmp36_ = NULL;
	GeeList* _tmp37_;
	GeeList* _tmp38_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data59_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	start_uid = NULL;
	if (_data59_->initial_id != NULL) {
		GearyImapDBFolderLocationIdentifier* location = NULL;
		GearyImapDBFolderLocationIdentifier* _tmp0_;
		GearyImapDBFolderLocationIdentifier* _tmp1_;
		GearyImapDBFolderLocationIdentifier* _tmp2_;
		GearyImapUID* _tmp3_;
		GearyImapUID* _tmp4_;
		_tmp0_ = geary_imap_db_folder_do_get_location_for_id (self, cx, _data59_->initial_id, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDE_MARKED_FOR_REMOVE, _data59_->cancellable, &_inner_error0_);
		location = _tmp0_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (start_uid);
			return 0;
		}
		_tmp1_ = location;
		if (_tmp1_ == NULL) {
			result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (start_uid);
			return result;
		}
		_tmp2_ = location;
		_tmp3_ = _tmp2_->uid;
		_tmp4_ = _g_object_ref0 (_tmp3_);
		_g_object_unref0 (start_uid);
		start_uid = _tmp4_;
		if (!_data59_->including_id) {
			if (_data59_->oldest_to_newest) {
				GearyImapUID* _tmp5_;
				GearyImapUID* _tmp6_;
				_tmp5_ = start_uid;
				_tmp6_ = geary_imap_uid_next (_tmp5_, FALSE);
				_g_object_unref0 (start_uid);
				start_uid = _tmp6_;
			} else {
				GearyImapUID* _tmp7_;
				GearyImapUID* _tmp8_;
				_tmp7_ = start_uid;
				_tmp8_ = geary_imap_uid_previous (_tmp7_, FALSE);
				_g_object_unref0 (start_uid);
				start_uid = _tmp8_;
			}
		}
		_geary_imap_db_folder_location_identifier_unref0 (location);
	} else {
		if (_data59_->oldest_to_newest) {
			GearyImapUID* _tmp9_;
			_tmp9_ = geary_imap_uid_new (GEARY_IMAP_UID_MIN);
			_g_object_unref0 (start_uid);
			start_uid = _tmp9_;
		} else {
			GearyImapUID* _tmp10_;
			_tmp10_ = geary_imap_uid_new (GEARY_IMAP_UID_MAX);
			_g_object_unref0 (start_uid);
			start_uid = _tmp10_;
		}
	}
	_tmp11_ = start_uid;
	if (!geary_imap_uid_is_valid (_tmp11_)) {
		result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
		_g_object_unref0 (start_uid);
		return result;
	}
	_tmp12_ = g_string_new ("\n" \
"                SELECT MessageLocationTable.message_id, ordering, remo" \
"ve_marker\n" \
"                FROM MessageLocationTable\n" \
"                WHERE folder_id = ?\n" \
"            ");
	sql = _tmp12_;
	if (_data59_->oldest_to_newest) {
		GString* _tmp13_;
		_tmp13_ = sql;
		g_string_append (_tmp13_, "AND ordering >= ? ");
	} else {
		GString* _tmp14_;
		_tmp14_ = sql;
		g_string_append (_tmp14_, "AND ordering <= ? ");
	}
	if (_data59_->oldest_to_newest) {
		GString* _tmp15_;
		_tmp15_ = sql;
		g_string_append (_tmp15_, "ORDER BY ordering ASC ");
	} else {
		GString* _tmp16_;
		_tmp16_ = sql;
		g_string_append (_tmp16_, "ORDER BY ordering DESC ");
	}
	if (_data59_->count != G_MAXINT) {
		GString* _tmp17_;
		_tmp17_ = sql;
		g_string_append (_tmp17_, "LIMIT ? ");
	}
	_tmp18_ = sql;
	_tmp19_ = _tmp18_->str;
	_tmp20_ = geary_db_connection_prepare (cx, _tmp19_, &_inner_error0_);
	stmt = _tmp20_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_string_free0 (sql);
		_g_object_unref0 (start_uid);
		return 0;
	}
	_tmp21_ = stmt;
	_tmp22_ = geary_db_statement_bind_rowid (_tmp21_, 0, self->priv->folder_id, &_inner_error0_);
	_tmp23_ = _tmp22_;
	_g_object_unref0 (_tmp23_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		_g_object_unref0 (start_uid);
		return 0;
	}
	_tmp24_ = stmt;
	_tmp25_ = start_uid;
	_tmp26_ = geary_message_data_int64_message_data_get_value (G_TYPE_CHECK_INSTANCE_CAST (_tmp25_, GEARY_MESSAGE_DATA_TYPE_INT64_MESSAGE_DATA, GearyMessageDataInt64MessageData));
	_tmp27_ = _tmp26_;
	_tmp28_ = geary_db_statement_bind_int64 (_tmp24_, 1, _tmp27_, &_inner_error0_);
	_tmp29_ = _tmp28_;
	_g_object_unref0 (_tmp29_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		_g_object_unref0 (start_uid);
		return 0;
	}
	if (_data59_->count != G_MAXINT) {
		GearyDbStatement* _tmp30_;
		GearyDbStatement* _tmp31_;
		GearyDbStatement* _tmp32_;
		_tmp30_ = stmt;
		_tmp31_ = geary_db_statement_bind_int (_tmp30_, 2, _data59_->count, &_inner_error0_);
		_tmp32_ = _tmp31_;
		_g_object_unref0 (_tmp32_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_g_string_free0 (sql);
			_g_object_unref0 (start_uid);
			return 0;
		}
	}
	_tmp34_ = stmt;
	_tmp35_ = geary_db_statement_exec (_tmp34_, _data59_->cancellable, &_inner_error0_);
	_tmp33_ = _tmp35_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		_g_object_unref0 (start_uid);
		return 0;
	}
	_tmp37_ = geary_imap_db_folder_do_results_to_locations (self, _tmp33_, _data59_->count, _data59_->flags, _data59_->cancellable, &_inner_error0_);
	_tmp36_ = _tmp37_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp33_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		_g_object_unref0 (start_uid);
		return 0;
	}
	_tmp38_ = _tmp36_;
	_tmp36_ = NULL;
	_g_object_unref0 (_data59_->locations);
	_data59_->locations = _tmp38_;
	result = GEARY_DB_TRANSACTION_OUTCOME_SUCCESS;
	_g_object_unref0 (_tmp36_);
	_g_object_unref0 (_tmp33_);
	_g_object_unref0 (stmt);
	_g_string_free0 (sql);
	_g_object_unref0 (start_uid);
	return result;
}

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

static void
geary_imap_db_folder_list_email_by_id_async_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_)
{
	GearyImapDbFolderListEmailByIdAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_list_email_by_id_async_co (_data_);
}

static gboolean
geary_imap_db_folder_list_email_by_id_async_co (GearyImapDbFolderListEmailByIdAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data59_ = g_slice_new0 (Block59Data);
	_data_->_data59_->_ref_count_ = 1;
	_data_->_data59_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data59_->initial_id);
	_data_->_data59_->initial_id = _data_->initial_id;
	_data_->_data59_->count = _data_->count;
	_data_->_data59_->flags = _data_->flags;
	_g_object_unref0 (_data_->_data59_->cancellable);
	_data_->_data59_->cancellable = _data_->cancellable;
	_data_->_data59_->_async_data_ = _data_;
	if (_data_->_data59_->count <= 0) {
		_data_->result = NULL;
		block59_data_unref (_data_->_data59_);
		_data_->_data59_ = 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_->_data59_->including_id = geary_imap_db_folder_list_flags_is_all_set (_data_->_data59_->flags, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDING_ID);
	_data_->_data59_->oldest_to_newest = geary_imap_db_folder_list_flags_is_all_set (_data_->_data59_->flags, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_OLDEST_TO_NEWEST);
	_data_->only_incomplete = geary_imap_db_folder_list_flags_is_all_set (_data_->_data59_->flags, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_ONLY_INCOMPLETE);
	_data_->_data59_->locations = NULL;
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda57__geary_db_transaction_method, _data_->_data59_, _data_->_data59_->cancellable, geary_imap_db_folder_list_email_by_id_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_);
		block59_data_unref (_data_->_data59_);
		_data_->_data59_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (_data_->only_incomplete) {
		_data_->_tmp2_ = _data_->_data59_->locations;
		_data_->_state_ = 2;
		geary_imap_db_folder_remove_complete_locations_in_chunks_async (_data_->self, _data_->_tmp2_, _data_->_data59_->cancellable, geary_imap_db_folder_list_email_by_id_async_ready, _data_);
		return FALSE;
		_state_2:
		_data_->_tmp3_ = geary_imap_db_folder_remove_complete_locations_in_chunks_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp1_ = _data_->_tmp3_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			block59_data_unref (_data_->_data59_);
			_data_->_data59_ = NULL;
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp4_ = _data_->_tmp1_;
		_data_->_tmp1_ = NULL;
		_g_object_unref0 (_data_->_data59_->locations);
		_data_->_data59_->locations = _data_->_tmp4_;
		_g_object_unref0 (_data_->_tmp1_);
	}
	_data_->_tmp6_ = _data_->_data59_->locations;
	_data_->_state_ = 3;
	geary_imap_db_folder_list_email_in_chunks_async (_data_->self, _data_->_tmp6_, _data_->required_fields, _data_->_data59_->flags, _data_->_data59_->cancellable, geary_imap_db_folder_list_email_by_id_async_ready, _data_);
	return FALSE;
	_state_3:
	_data_->_tmp7_ = geary_imap_db_folder_list_email_in_chunks_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp5_ = _data_->_tmp7_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block59_data_unref (_data_->_data59_);
		_data_->_data59_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp8_ = _data_->_tmp5_;
	_data_->_tmp5_ = NULL;
	_data_->result = _data_->_tmp8_;
	_g_object_unref0 (_data_->_tmp5_);
	block59_data_unref (_data_->_data59_);
	_data_->_data59_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_list_email_by_range_async (GearyImapDBFolder* self,
                                                GearyImapDBEmailIdentifier* start_id,
                                                GearyImapDBEmailIdentifier* end_id,
                                                GearyEmailField required_fields,
                                                GearyImapDBFolderListFlags flags,
                                                GCancellable* cancellable,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_)
{
	GearyImapDbFolderListEmailByRangeAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GearyImapDBEmailIdentifier* _tmp1_;
	GearyImapDBEmailIdentifier* _tmp2_;
	GCancellable* _tmp3_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_IMAP_DB_IS_EMAIL_IDENTIFIER (start_id));
	g_return_if_fail (GEARY_IMAP_DB_IS_EMAIL_IDENTIFIER (end_id));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderListEmailByRangeAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_list_email_by_range_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (start_id);
	_g_object_unref0 (_data_->start_id);
	_data_->start_id = _tmp1_;
	_tmp2_ = _g_object_ref0 (end_id);
	_g_object_unref0 (_data_->end_id);
	_data_->end_id = _tmp2_;
	_data_->required_fields = required_fields;
	_data_->flags = flags;
	_tmp3_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp3_;
	geary_imap_db_folder_list_email_by_range_async_co (_data_);
}

GeeList*
geary_imap_db_folder_list_email_by_range_finish (GearyImapDBFolder* self,
                                                 GAsyncResult* _res_,
                                                 GError** error)
{
	GeeList* result;
	GearyImapDbFolderListEmailByRangeAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block60Data*
block60_data_ref (Block60Data* _data60_)
{
	g_atomic_int_inc (&_data60_->_ref_count_);
	return _data60_;
}

static void
block60_data_unref (void * _userdata_)
{
	Block60Data* _data60_;
	_data60_ = (Block60Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data60_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data60_->self;
		_g_object_unref0 (_data60_->locations);
		_g_object_unref0 (_data60_->start_id);
		_g_object_unref0 (_data60_->end_id);
		_g_object_unref0 (_data60_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block60Data, _data60_);
	}
}

static GearyDbTransactionOutcome
__lambda60_ (Block60Data* _data60_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GearyImapDBFolderLocationIdentifier* start_location = NULL;
	GearyImapDBFolderLocationIdentifier* _tmp0_;
	GearyImapDBFolderLocationIdentifier* _tmp1_;
	GearyImapUID* start_uid = NULL;
	GearyImapDBFolderLocationIdentifier* _tmp2_;
	GearyImapUID* _tmp3_;
	GearyImapUID* _tmp4_;
	GearyImapDBFolderLocationIdentifier* end_location = NULL;
	GearyImapDBFolderLocationIdentifier* _tmp5_;
	GearyImapDBFolderLocationIdentifier* _tmp6_;
	GearyImapUID* end_uid = NULL;
	GearyImapDBFolderLocationIdentifier* _tmp7_;
	GearyImapUID* _tmp8_;
	GearyImapUID* _tmp9_;
	gboolean _tmp14_ = FALSE;
	gboolean _tmp15_ = FALSE;
	GearyImapUID* _tmp16_;
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp20_;
	GearyDbStatement* _tmp21_;
	GearyDbStatement* _tmp22_;
	GearyDbStatement* _tmp23_;
	GearyDbStatement* _tmp24_;
	GearyImapUID* _tmp25_;
	gint64 _tmp26_;
	gint64 _tmp27_;
	GearyDbStatement* _tmp28_;
	GearyDbStatement* _tmp29_;
	GearyDbStatement* _tmp30_;
	GearyImapUID* _tmp31_;
	gint64 _tmp32_;
	gint64 _tmp33_;
	GearyDbStatement* _tmp34_;
	GearyDbStatement* _tmp35_;
	GearyDbResult* _tmp36_ = NULL;
	GearyDbStatement* _tmp37_;
	GearyDbResult* _tmp38_;
	GeeList* _tmp39_ = NULL;
	GeeList* _tmp40_;
	GeeList* _tmp41_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data60_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_imap_db_folder_do_get_location_for_id (self, cx, _data60_->start_id, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDE_MARKED_FOR_REMOVE, _data60_->cancellable, &_inner_error0_);
	start_location = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp1_ = start_location;
	if (_tmp1_ == NULL) {
		result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
		_geary_imap_db_folder_location_identifier_unref0 (start_location);
		return result;
	}
	_tmp2_ = start_location;
	_tmp3_ = _tmp2_->uid;
	_tmp4_ = _g_object_ref0 (_tmp3_);
	start_uid = _tmp4_;
	_tmp5_ = geary_imap_db_folder_do_get_location_for_id (self, cx, _data60_->end_id, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDE_MARKED_FOR_REMOVE, _data60_->cancellable, &_inner_error0_);
	end_location = _tmp5_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (start_uid);
		_geary_imap_db_folder_location_identifier_unref0 (start_location);
		return 0;
	}
	_tmp6_ = end_location;
	if (_tmp6_ == NULL) {
		result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
		_geary_imap_db_folder_location_identifier_unref0 (end_location);
		_g_object_unref0 (start_uid);
		_geary_imap_db_folder_location_identifier_unref0 (start_location);
		return result;
	}
	_tmp7_ = end_location;
	_tmp8_ = _tmp7_->uid;
	_tmp9_ = _g_object_ref0 (_tmp8_);
	end_uid = _tmp9_;
	if (!_data60_->including_id) {
		GearyImapUID* _tmp10_;
		GearyImapUID* _tmp11_;
		GearyImapUID* _tmp12_;
		GearyImapUID* _tmp13_;
		_tmp10_ = start_uid;
		_tmp11_ = geary_imap_uid_next (_tmp10_, FALSE);
		_g_object_unref0 (start_uid);
		start_uid = _tmp11_;
		_tmp12_ = end_uid;
		_tmp13_ = geary_imap_uid_previous (_tmp12_, FALSE);
		_g_object_unref0 (end_uid);
		end_uid = _tmp13_;
	}
	_tmp16_ = start_uid;
	if (!geary_imap_uid_is_valid (_tmp16_)) {
		_tmp15_ = TRUE;
	} else {
		GearyImapUID* _tmp17_;
		_tmp17_ = end_uid;
		_tmp15_ = !geary_imap_uid_is_valid (_tmp17_);
	}
	if (_tmp15_) {
		_tmp14_ = TRUE;
	} else {
		GearyImapUID* _tmp18_;
		GearyImapUID* _tmp19_;
		_tmp18_ = start_uid;
		_tmp19_ = end_uid;
		_tmp14_ = geary_imap_uid_compare_to (_tmp18_, _tmp19_) > 0;
	}
	if (_tmp14_) {
		result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
		_g_object_unref0 (end_uid);
		_geary_imap_db_folder_location_identifier_unref0 (end_location);
		_g_object_unref0 (start_uid);
		_geary_imap_db_folder_location_identifier_unref0 (start_location);
		return result;
	}
	_tmp20_ = geary_db_connection_prepare (cx, "\n" \
"                SELECT message_id, ordering, remove_marker\n" \
"                FROM MessageLocationTable\n" \
"                WHERE folder_id = ? AND ordering >= ? AND ordering <= " \
"?\n" \
"            ", &_inner_error0_);
	stmt = _tmp20_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (end_uid);
		_geary_imap_db_folder_location_identifier_unref0 (end_location);
		_g_object_unref0 (start_uid);
		_geary_imap_db_folder_location_identifier_unref0 (start_location);
		return 0;
	}
	_tmp21_ = stmt;
	_tmp22_ = geary_db_statement_bind_rowid (_tmp21_, 0, self->priv->folder_id, &_inner_error0_);
	_tmp23_ = _tmp22_;
	_g_object_unref0 (_tmp23_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_object_unref0 (end_uid);
		_geary_imap_db_folder_location_identifier_unref0 (end_location);
		_g_object_unref0 (start_uid);
		_geary_imap_db_folder_location_identifier_unref0 (start_location);
		return 0;
	}
	_tmp24_ = stmt;
	_tmp25_ = start_uid;
	_tmp26_ = geary_message_data_int64_message_data_get_value (G_TYPE_CHECK_INSTANCE_CAST (_tmp25_, GEARY_MESSAGE_DATA_TYPE_INT64_MESSAGE_DATA, GearyMessageDataInt64MessageData));
	_tmp27_ = _tmp26_;
	_tmp28_ = geary_db_statement_bind_int64 (_tmp24_, 1, _tmp27_, &_inner_error0_);
	_tmp29_ = _tmp28_;
	_g_object_unref0 (_tmp29_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_object_unref0 (end_uid);
		_geary_imap_db_folder_location_identifier_unref0 (end_location);
		_g_object_unref0 (start_uid);
		_geary_imap_db_folder_location_identifier_unref0 (start_location);
		return 0;
	}
	_tmp30_ = stmt;
	_tmp31_ = end_uid;
	_tmp32_ = geary_message_data_int64_message_data_get_value (G_TYPE_CHECK_INSTANCE_CAST (_tmp31_, GEARY_MESSAGE_DATA_TYPE_INT64_MESSAGE_DATA, GearyMessageDataInt64MessageData));
	_tmp33_ = _tmp32_;
	_tmp34_ = geary_db_statement_bind_int64 (_tmp30_, 2, _tmp33_, &_inner_error0_);
	_tmp35_ = _tmp34_;
	_g_object_unref0 (_tmp35_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_object_unref0 (end_uid);
		_geary_imap_db_folder_location_identifier_unref0 (end_location);
		_g_object_unref0 (start_uid);
		_geary_imap_db_folder_location_identifier_unref0 (start_location);
		return 0;
	}
	_tmp37_ = stmt;
	_tmp38_ = geary_db_statement_exec (_tmp37_, _data60_->cancellable, &_inner_error0_);
	_tmp36_ = _tmp38_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_object_unref0 (end_uid);
		_geary_imap_db_folder_location_identifier_unref0 (end_location);
		_g_object_unref0 (start_uid);
		_geary_imap_db_folder_location_identifier_unref0 (start_location);
		return 0;
	}
	_tmp40_ = geary_imap_db_folder_do_results_to_locations (self, _tmp36_, G_MAXINT, _data60_->flags, _data60_->cancellable, &_inner_error0_);
	_tmp39_ = _tmp40_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp36_);
		_g_object_unref0 (stmt);
		_g_object_unref0 (end_uid);
		_geary_imap_db_folder_location_identifier_unref0 (end_location);
		_g_object_unref0 (start_uid);
		_geary_imap_db_folder_location_identifier_unref0 (start_location);
		return 0;
	}
	_tmp41_ = _tmp39_;
	_tmp39_ = NULL;
	_g_object_unref0 (_data60_->locations);
	_data60_->locations = _tmp41_;
	result = GEARY_DB_TRANSACTION_OUTCOME_SUCCESS;
	_g_object_unref0 (_tmp39_);
	_g_object_unref0 (_tmp36_);
	_g_object_unref0 (stmt);
	_g_object_unref0 (end_uid);
	_geary_imap_db_folder_location_identifier_unref0 (end_location);
	_g_object_unref0 (start_uid);
	_geary_imap_db_folder_location_identifier_unref0 (start_location);
	return result;
}

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

static void
geary_imap_db_folder_list_email_by_range_async_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_)
{
	GearyImapDbFolderListEmailByRangeAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_list_email_by_range_async_co (_data_);
}

static gboolean
geary_imap_db_folder_list_email_by_range_async_co (GearyImapDbFolderListEmailByRangeAsyncData* _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_->_data60_ = g_slice_new0 (Block60Data);
	_data_->_data60_->_ref_count_ = 1;
	_data_->_data60_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data60_->start_id);
	_data_->_data60_->start_id = _data_->start_id;
	_g_object_unref0 (_data_->_data60_->end_id);
	_data_->_data60_->end_id = _data_->end_id;
	_data_->_data60_->flags = _data_->flags;
	_g_object_unref0 (_data_->_data60_->cancellable);
	_data_->_data60_->cancellable = _data_->cancellable;
	_data_->_data60_->_async_data_ = _data_;
	_data_->_data60_->including_id = geary_imap_db_folder_list_flags_is_all_set (_data_->_data60_->flags, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDING_ID);
	_data_->_data60_->locations = NULL;
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda60__geary_db_transaction_method, _data_->_data60_, _data_->_data60_->cancellable, geary_imap_db_folder_list_email_by_range_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_);
		block60_data_unref (_data_->_data60_);
		_data_->_data60_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp2_ = _data_->_data60_->locations;
	_data_->_state_ = 2;
	geary_imap_db_folder_list_email_in_chunks_async (_data_->self, _data_->_tmp2_, _data_->required_fields, _data_->_data60_->flags, _data_->_data60_->cancellable, geary_imap_db_folder_list_email_by_range_async_ready, _data_);
	return FALSE;
	_state_2:
	_data_->_tmp3_ = geary_imap_db_folder_list_email_in_chunks_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp1_ = _data_->_tmp3_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block60_data_unref (_data_->_data60_);
		_data_->_data60_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp4_ = _data_->_tmp1_;
	_data_->_tmp1_ = NULL;
	_data_->result = _data_->_tmp4_;
	_g_object_unref0 (_data_->_tmp1_);
	block60_data_unref (_data_->_data60_);
	_data_->_data60_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_db_folder_list_email_by_uid_range_async_data_free (gpointer _data)
{
	GearyImapDbFolderListEmailByUidRangeAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->start);
	_g_object_unref0 (_data_->end);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbFolderListEmailByUidRangeAsyncData, _data_);
}

void
geary_imap_db_folder_list_email_by_uid_range_async (GearyImapDBFolder* self,
                                                    GearyImapUID* start,
                                                    GearyImapUID* end,
                                                    GearyEmailField required_fields,
                                                    GearyImapDBFolderListFlags flags,
                                                    GCancellable* cancellable,
                                                    GAsyncReadyCallback _callback_,
                                                    gpointer _user_data_)
{
	GearyImapDbFolderListEmailByUidRangeAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GearyImapUID* _tmp1_;
	GearyImapUID* _tmp2_;
	GCancellable* _tmp3_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_IMAP_IS_UID (start));
	g_return_if_fail (GEARY_IMAP_IS_UID (end));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderListEmailByUidRangeAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_list_email_by_uid_range_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (start);
	_g_object_unref0 (_data_->start);
	_data_->start = _tmp1_;
	_tmp2_ = _g_object_ref0 (end);
	_g_object_unref0 (_data_->end);
	_data_->end = _tmp2_;
	_data_->required_fields = required_fields;
	_data_->flags = flags;
	_tmp3_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp3_;
	geary_imap_db_folder_list_email_by_uid_range_async_co (_data_);
}

GeeList*
geary_imap_db_folder_list_email_by_uid_range_finish (GearyImapDBFolder* self,
                                                     GAsyncResult* _res_,
                                                     GError** error)
{
	GeeList* result;
	GearyImapDbFolderListEmailByUidRangeAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block61Data*
block61_data_ref (Block61Data* _data61_)
{
	g_atomic_int_inc (&_data61_->_ref_count_);
	return _data61_;
}

static void
block61_data_unref (void * _userdata_)
{
	Block61Data* _data61_;
	_data61_ = (Block61Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data61_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data61_->self;
		_g_object_unref0 (_data61_->locations);
		_g_object_unref0 (_data61_->end_uid);
		_g_object_unref0 (_data61_->start_uid);
		_g_object_unref0 (_data61_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block61Data, _data61_);
	}
}

static GearyDbTransactionOutcome
__lambda61_ (Block61Data* _data61_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GString* sql = NULL;
	GString* _tmp0_;
	GString* _tmp1_;
	GearyDbStatement* stmt = NULL;
	GString* _tmp2_;
	const gchar* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbStatement* _tmp5_;
	GearyDbStatement* _tmp6_;
	GearyDbStatement* _tmp7_;
	GearyDbStatement* _tmp8_;
	GearyImapUID* _tmp9_;
	gint64 _tmp10_;
	gint64 _tmp11_;
	GearyDbStatement* _tmp12_;
	GearyDbStatement* _tmp13_;
	GearyDbStatement* _tmp14_;
	GearyImapUID* _tmp15_;
	gint64 _tmp16_;
	gint64 _tmp17_;
	GearyDbStatement* _tmp18_;
	GearyDbStatement* _tmp19_;
	GearyDbResult* _tmp20_ = NULL;
	GearyDbStatement* _tmp21_;
	GearyDbResult* _tmp22_;
	GeeList* _tmp23_ = NULL;
	GeeList* _tmp24_;
	GeeList* _tmp25_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data61_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = g_string_new ("\n" \
"                SELECT MessageLocationTable.message_id, ordering, remo" \
"ve_marker\n" \
"                FROM MessageLocationTable\n" \
"            ");
	sql = _tmp0_;
	_tmp1_ = sql;
	g_string_append (_tmp1_, "WHERE folder_id = ? AND ordering >= ? AND ordering <= ? ");
	_tmp2_ = sql;
	_tmp3_ = _tmp2_->str;
	_tmp4_ = geary_db_connection_prepare (cx, _tmp3_, &_inner_error0_);
	stmt = _tmp4_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp5_ = stmt;
	_tmp6_ = geary_db_statement_bind_rowid (_tmp5_, 0, self->priv->folder_id, &_inner_error0_);
	_tmp7_ = _tmp6_;
	_g_object_unref0 (_tmp7_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp8_ = stmt;
	_tmp9_ = _data61_->start_uid;
	_tmp10_ = geary_message_data_int64_message_data_get_value (G_TYPE_CHECK_INSTANCE_CAST (_tmp9_, GEARY_MESSAGE_DATA_TYPE_INT64_MESSAGE_DATA, GearyMessageDataInt64MessageData));
	_tmp11_ = _tmp10_;
	_tmp12_ = geary_db_statement_bind_int64 (_tmp8_, 1, _tmp11_, &_inner_error0_);
	_tmp13_ = _tmp12_;
	_g_object_unref0 (_tmp13_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp14_ = stmt;
	_tmp15_ = _data61_->end_uid;
	_tmp16_ = geary_message_data_int64_message_data_get_value (G_TYPE_CHECK_INSTANCE_CAST (_tmp15_, GEARY_MESSAGE_DATA_TYPE_INT64_MESSAGE_DATA, GearyMessageDataInt64MessageData));
	_tmp17_ = _tmp16_;
	_tmp18_ = geary_db_statement_bind_int64 (_tmp14_, 2, _tmp17_, &_inner_error0_);
	_tmp19_ = _tmp18_;
	_g_object_unref0 (_tmp19_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp21_ = stmt;
	_tmp22_ = geary_db_statement_exec (_tmp21_, _data61_->cancellable, &_inner_error0_);
	_tmp20_ = _tmp22_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp24_ = geary_imap_db_folder_do_results_to_locations (self, _tmp20_, G_MAXINT, _data61_->flags, _data61_->cancellable, &_inner_error0_);
	_tmp23_ = _tmp24_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp20_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp25_ = _tmp23_;
	_tmp23_ = NULL;
	_g_object_unref0 (_data61_->locations);
	_data61_->locations = _tmp25_;
	result = GEARY_DB_TRANSACTION_OUTCOME_SUCCESS;
	_g_object_unref0 (_tmp23_);
	_g_object_unref0 (_tmp20_);
	_g_object_unref0 (stmt);
	_g_string_free0 (sql);
	return result;
}

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

static void
geary_imap_db_folder_list_email_by_uid_range_async_ready (GObject* source_object,
                                                          GAsyncResult* _res_,
                                                          gpointer _user_data_)
{
	GearyImapDbFolderListEmailByUidRangeAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_list_email_by_uid_range_async_co (_data_);
}

static gboolean
geary_imap_db_folder_list_email_by_uid_range_async_co (GearyImapDbFolderListEmailByUidRangeAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data61_ = g_slice_new0 (Block61Data);
	_data_->_data61_->_ref_count_ = 1;
	_data_->_data61_->self = g_object_ref (_data_->self);
	_data_->_data61_->flags = _data_->flags;
	_g_object_unref0 (_data_->_data61_->cancellable);
	_data_->_data61_->cancellable = _data_->cancellable;
	_data_->_data61_->_async_data_ = _data_;
	_data_->including_id = geary_imap_db_folder_list_flags_is_all_set (_data_->_data61_->flags, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDING_ID);
	_data_->only_incomplete = geary_imap_db_folder_list_flags_is_all_set (_data_->_data61_->flags, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_ONLY_INCOMPLETE);
	_data_->_tmp0_ = _g_object_ref0 (_data_->start);
	_data_->_data61_->start_uid = _data_->_tmp0_;
	_data_->_tmp1_ = _g_object_ref0 (_data_->end);
	_data_->_data61_->end_uid = _data_->_tmp1_;
	if (!_data_->including_id) {
		_data_->_tmp2_ = _data_->_data61_->start_uid;
		_data_->_tmp3_ = geary_imap_uid_next (_data_->_tmp2_, FALSE);
		_g_object_unref0 (_data_->_data61_->start_uid);
		_data_->_data61_->start_uid = _data_->_tmp3_;
		_data_->_tmp4_ = _data_->_data61_->end_uid;
		_data_->_tmp5_ = geary_imap_uid_previous (_data_->_tmp4_, FALSE);
		_g_object_unref0 (_data_->_data61_->end_uid);
		_data_->_data61_->end_uid = _data_->_tmp5_;
	}
	_data_->_tmp8_ = _data_->_data61_->start_uid;
	if (!geary_imap_uid_is_valid (_data_->_tmp8_)) {
		_data_->_tmp7_ = TRUE;
	} else {
		_data_->_tmp9_ = _data_->_data61_->end_uid;
		_data_->_tmp7_ = !geary_imap_uid_is_valid (_data_->_tmp9_);
	}
	if (_data_->_tmp7_) {
		_data_->_tmp6_ = TRUE;
	} else {
		_data_->_tmp10_ = _data_->_data61_->start_uid;
		_data_->_tmp11_ = _data_->_data61_->end_uid;
		_data_->_tmp6_ = geary_imap_uid_compare_to (_data_->_tmp10_, _data_->_tmp11_) > 0;
	}
	if (_data_->_tmp6_) {
		_data_->result = NULL;
		block61_data_unref (_data_->_data61_);
		_data_->_data61_ = 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_->_data61_->locations = NULL;
	_data_->_tmp12_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp12_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda61__geary_db_transaction_method, _data_->_data61_, _data_->_data61_->cancellable, geary_imap_db_folder_list_email_by_uid_range_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (_data_->_tmp12_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block61_data_unref (_data_->_data61_);
		_data_->_data61_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (_data_->only_incomplete) {
		_data_->_tmp14_ = _data_->_data61_->locations;
		_data_->_state_ = 2;
		geary_imap_db_folder_remove_complete_locations_in_chunks_async (_data_->self, _data_->_tmp14_, _data_->_data61_->cancellable, geary_imap_db_folder_list_email_by_uid_range_async_ready, _data_);
		return FALSE;
		_state_2:
		_data_->_tmp15_ = geary_imap_db_folder_remove_complete_locations_in_chunks_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp13_ = _data_->_tmp15_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			block61_data_unref (_data_->_data61_);
			_data_->_data61_ = NULL;
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp16_ = _data_->_tmp13_;
		_data_->_tmp13_ = NULL;
		_g_object_unref0 (_data_->_data61_->locations);
		_data_->_data61_->locations = _data_->_tmp16_;
		_g_object_unref0 (_data_->_tmp13_);
	}
	_data_->_tmp18_ = _data_->_data61_->locations;
	_data_->_state_ = 3;
	geary_imap_db_folder_list_email_in_chunks_async (_data_->self, _data_->_tmp18_, _data_->required_fields, _data_->_data61_->flags, _data_->_data61_->cancellable, geary_imap_db_folder_list_email_by_uid_range_async_ready, _data_);
	return FALSE;
	_state_3:
	_data_->_tmp19_ = geary_imap_db_folder_list_email_in_chunks_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp17_ = _data_->_tmp19_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block61_data_unref (_data_->_data61_);
		_data_->_data61_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp20_ = _data_->_tmp17_;
	_data_->_tmp17_ = NULL;
	_data_->result = _data_->_tmp20_;
	_g_object_unref0 (_data_->_tmp17_);
	block61_data_unref (_data_->_data61_);
	_data_->_data61_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_list_email_by_sparse_id_async (GearyImapDBFolder* self,
                                                    GeeCollection* ids,
                                                    GearyEmailField required_fields,
                                                    GearyImapDBFolderListFlags flags,
                                                    GCancellable* cancellable,
                                                    GAsyncReadyCallback _callback_,
                                                    gpointer _user_data_)
{
	GearyImapDbFolderListEmailBySparseIdAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GeeCollection* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderListEmailBySparseIdAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_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_imap_db_folder_list_email_by_sparse_id_async_co (_data_);
}

GeeList*
geary_imap_db_folder_list_email_by_sparse_id_finish (GearyImapDBFolder* self,
                                                     GAsyncResult* _res_,
                                                     GError** error)
{
	GeeList* result;
	GearyImapDbFolderListEmailBySparseIdAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block62Data*
block62_data_ref (Block62Data* _data62_)
{
	g_atomic_int_inc (&_data62_->_ref_count_);
	return _data62_;
}

static void
block62_data_unref (void * _userdata_)
{
	Block62Data* _data62_;
	_data62_ = (Block62Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data62_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data62_->self;
		_g_object_unref0 (_data62_->locations);
		_g_object_unref0 (_data62_->ids);
		_g_object_unref0 (_data62_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block62Data, _data62_);
	}
}

static GearyDbTransactionOutcome
__lambda62_ (Block62Data* _data62_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GeeList* locs = NULL;
	GeeList* _tmp0_;
	gboolean _tmp1_ = FALSE;
	GeeList* _tmp2_;
	GString* sql = NULL;
	GString* _tmp6_;
	GeeList* _tmp7_;
	gint _tmp8_;
	gint _tmp9_;
	GString* _tmp33_;
	GearyDbStatement* stmt = NULL;
	GString* _tmp34_;
	const gchar* _tmp35_;
	GearyDbStatement* _tmp36_;
	GearyDbStatement* _tmp37_;
	GearyDbStatement* _tmp38_;
	GearyDbStatement* _tmp39_;
	GearyDbResult* _tmp40_ = NULL;
	GearyDbStatement* _tmp41_;
	GearyDbResult* _tmp42_;
	GeeList* _tmp43_ = NULL;
	GeeList* _tmp44_;
	GeeList* _tmp45_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data62_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_imap_db_folder_do_get_locations_for_ids (self, cx, _data62_->ids, _data62_->flags, _data62_->cancellable, &_inner_error0_);
	locs = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp2_ = locs;
	if (_tmp2_ == NULL) {
		_tmp1_ = TRUE;
	} else {
		GeeList* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		_tmp3_ = locs;
		_tmp4_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, GEE_TYPE_COLLECTION, GeeCollection));
		_tmp5_ = _tmp4_;
		_tmp1_ = _tmp5_ == 0;
	}
	if (_tmp1_) {
		result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
		_g_object_unref0 (locs);
		return result;
	}
	_tmp6_ = g_string_new ("\n" \
"                SELECT MessageLocationTable.message_id, ordering, remo" \
"ve_marker\n" \
"                FROM MessageLocationTable\n" \
"            ");
	sql = _tmp6_;
	_tmp7_ = locs;
	_tmp8_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, GEE_TYPE_COLLECTION, GeeCollection));
	_tmp9_ = _tmp8_;
	if (_tmp9_ != 1) {
		GString* _tmp10_;
		gboolean first = FALSE;
		GString* _tmp25_;
		_tmp10_ = sql;
		g_string_append (_tmp10_, "WHERE ordering IN (");
		first = TRUE;
		{
			GeeList* _location_list = NULL;
			GeeList* _tmp11_;
			gint _location_size = 0;
			GeeList* _tmp12_;
			gint _tmp13_;
			gint _tmp14_;
			gint _location_index = 0;
			_tmp11_ = locs;
			_location_list = _tmp11_;
			_tmp12_ = _location_list;
			_tmp13_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp12_, GEE_TYPE_COLLECTION, GeeCollection));
			_tmp14_ = _tmp13_;
			_location_size = _tmp14_;
			_location_index = -1;
			while (TRUE) {
				gint _tmp15_;
				gint _tmp16_;
				GearyImapDBFolderLocationIdentifier* location = NULL;
				GeeList* _tmp17_;
				gpointer _tmp18_;
				GString* _tmp20_;
				GearyImapDBFolderLocationIdentifier* _tmp21_;
				GearyImapUID* _tmp22_;
				gchar* _tmp23_;
				gchar* _tmp24_;
				_location_index = _location_index + 1;
				_tmp15_ = _location_index;
				_tmp16_ = _location_size;
				if (!(_tmp15_ < _tmp16_)) {
					break;
				}
				_tmp17_ = _location_list;
				_tmp18_ = gee_list_get (_tmp17_, _location_index);
				location = (GearyImapDBFolderLocationIdentifier*) _tmp18_;
				if (!first) {
					GString* _tmp19_;
					_tmp19_ = sql;
					g_string_append (_tmp19_, ",");
				}
				_tmp20_ = sql;
				_tmp21_ = location;
				_tmp22_ = _tmp21_->uid;
				_tmp23_ = geary_message_data_abstract_message_data_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp22_, GEARY_MESSAGE_DATA_TYPE_ABSTRACT_MESSAGE_DATA, GearyMessageDataAbstractMessageData));
				_tmp24_ = _tmp23_;
				g_string_append (_tmp20_, _tmp24_);
				_g_free0 (_tmp24_);
				first = FALSE;
				_geary_imap_db_folder_location_identifier_unref0 (location);
			}
		}
		_tmp25_ = sql;
		g_string_append (_tmp25_, ")");
	} else {
		GString* _tmp26_;
		GeeList* _tmp27_;
		gpointer _tmp28_;
		GearyImapDBFolderLocationIdentifier* _tmp29_;
		GearyImapUID* _tmp30_;
		gchar* _tmp31_;
		gchar* _tmp32_;
		_tmp26_ = sql;
		_tmp27_ = locs;
		_tmp28_ = gee_list_get (_tmp27_, 0);
		_tmp29_ = (GearyImapDBFolderLocationIdentifier*) _tmp28_;
		_tmp30_ = _tmp29_->uid;
		_tmp31_ = geary_message_data_abstract_message_data_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp30_, GEARY_MESSAGE_DATA_TYPE_ABSTRACT_MESSAGE_DATA, GearyMessageDataAbstractMessageData));
		_tmp32_ = _tmp31_;
		g_string_append_printf (_tmp26_, "WHERE ordering = '%s' ", _tmp32_);
		_g_free0 (_tmp32_);
		_geary_imap_db_folder_location_identifier_unref0 (_tmp29_);
	}
	_tmp33_ = sql;
	g_string_append (_tmp33_, "AND folder_id = ? ");
	_tmp34_ = sql;
	_tmp35_ = _tmp34_->str;
	_tmp36_ = geary_db_connection_prepare (cx, _tmp35_, &_inner_error0_);
	stmt = _tmp36_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_string_free0 (sql);
		_g_object_unref0 (locs);
		return 0;
	}
	_tmp37_ = stmt;
	_tmp38_ = geary_db_statement_bind_rowid (_tmp37_, 0, self->priv->folder_id, &_inner_error0_);
	_tmp39_ = _tmp38_;
	_g_object_unref0 (_tmp39_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		_g_object_unref0 (locs);
		return 0;
	}
	_tmp41_ = stmt;
	_tmp42_ = geary_db_statement_exec (_tmp41_, _data62_->cancellable, &_inner_error0_);
	_tmp40_ = _tmp42_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		_g_object_unref0 (locs);
		return 0;
	}
	_tmp44_ = geary_imap_db_folder_do_results_to_locations (self, _tmp40_, G_MAXINT, _data62_->flags, _data62_->cancellable, &_inner_error0_);
	_tmp43_ = _tmp44_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp40_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		_g_object_unref0 (locs);
		return 0;
	}
	_tmp45_ = _tmp43_;
	_tmp43_ = NULL;
	_g_object_unref0 (_data62_->locations);
	_data62_->locations = _tmp45_;
	result = GEARY_DB_TRANSACTION_OUTCOME_SUCCESS;
	_g_object_unref0 (_tmp43_);
	_g_object_unref0 (_tmp40_);
	_g_object_unref0 (stmt);
	_g_string_free0 (sql);
	_g_object_unref0 (locs);
	return result;
}

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

static void
geary_imap_db_folder_list_email_by_sparse_id_async_ready (GObject* source_object,
                                                          GAsyncResult* _res_,
                                                          gpointer _user_data_)
{
	GearyImapDbFolderListEmailBySparseIdAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_list_email_by_sparse_id_async_co (_data_);
}

static gboolean
geary_imap_db_folder_list_email_by_sparse_id_async_co (GearyImapDbFolderListEmailBySparseIdAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data62_ = g_slice_new0 (Block62Data);
	_data_->_data62_->_ref_count_ = 1;
	_data_->_data62_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data62_->ids);
	_data_->_data62_->ids = _data_->ids;
	_data_->_data62_->flags = _data_->flags;
	_g_object_unref0 (_data_->_data62_->cancellable);
	_data_->_data62_->cancellable = _data_->cancellable;
	_data_->_data62_->_async_data_ = _data_;
	_data_->_tmp0_ = gee_collection_get_size (_data_->_data62_->ids);
	_data_->_tmp1_ = _data_->_tmp0_;
	if (_data_->_tmp1_ == 0) {
		_data_->result = NULL;
		block62_data_unref (_data_->_data62_);
		_data_->_data62_ = 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_->only_incomplete = geary_imap_db_folder_list_flags_is_all_set (_data_->_data62_->flags, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_ONLY_INCOMPLETE);
	_data_->_tmp2_ = gee_array_list_new (GEARY_IMAP_DB_FOLDER_TYPE_LOCATION_IDENTIFIER, (GBoxedCopyFunc) geary_imap_db_folder_location_identifier_ref, (GDestroyNotify) geary_imap_db_folder_location_identifier_unref, NULL, NULL, NULL);
	_data_->_data62_->locations = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, GEE_TYPE_LIST, GeeList);
	_data_->_tmp3_ = _data_->self->priv->db;
	_data_->_tmp4_ = _data_->_data62_->cancellable;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp3_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda62__geary_db_transaction_method, _data_->_data62_, _data_->_tmp4_, geary_imap_db_folder_list_email_by_sparse_id_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (_data_->_tmp3_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block62_data_unref (_data_->_data62_);
		_data_->_data62_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (_data_->only_incomplete) {
		_data_->_tmp6_ = _data_->_data62_->locations;
		_data_->_state_ = 2;
		geary_imap_db_folder_remove_complete_locations_in_chunks_async (_data_->self, _data_->_tmp6_, _data_->_data62_->cancellable, geary_imap_db_folder_list_email_by_sparse_id_async_ready, _data_);
		return FALSE;
		_state_2:
		_data_->_tmp7_ = geary_imap_db_folder_remove_complete_locations_in_chunks_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp5_ = _data_->_tmp7_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			block62_data_unref (_data_->_data62_);
			_data_->_data62_ = NULL;
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp8_ = _data_->_tmp5_;
		_data_->_tmp5_ = NULL;
		_g_object_unref0 (_data_->_data62_->locations);
		_data_->_data62_->locations = _data_->_tmp8_;
		_g_object_unref0 (_data_->_tmp5_);
	}
	_data_->_tmp10_ = _data_->_data62_->locations;
	_data_->_state_ = 3;
	geary_imap_db_folder_list_email_in_chunks_async (_data_->self, _data_->_tmp10_, _data_->required_fields, _data_->_data62_->flags, _data_->_data62_->cancellable, geary_imap_db_folder_list_email_by_sparse_id_async_ready, _data_);
	return FALSE;
	_state_3:
	_data_->_tmp11_ = geary_imap_db_folder_list_email_in_chunks_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp9_ = _data_->_tmp11_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block62_data_unref (_data_->_data62_);
		_data_->_data62_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp12_ = _data_->_tmp9_;
	_data_->_tmp9_ = NULL;
	_data_->result = _data_->_tmp12_;
	_g_object_unref0 (_data_->_tmp9_);
	block62_data_unref (_data_->_data62_);
	_data_->_data62_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_db_folder_remove_complete_locations_in_chunks_async_data_free (gpointer _data)
{
	GearyImapDbFolderRemoveCompleteLocationsInChunksAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->locations);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbFolderRemoveCompleteLocationsInChunksAsyncData, _data_);
}

static void
geary_imap_db_folder_remove_complete_locations_in_chunks_async (GearyImapDBFolder* self,
                                                                GeeList* locations,
                                                                GCancellable* cancellable,
                                                                GAsyncReadyCallback _callback_,
                                                                gpointer _user_data_)
{
	GearyImapDbFolderRemoveCompleteLocationsInChunksAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GeeList* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail ((locations == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (locations, GEE_TYPE_LIST));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderRemoveCompleteLocationsInChunksAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_remove_complete_locations_in_chunks_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (locations);
	_g_object_unref0 (_data_->locations);
	_data_->locations = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_folder_remove_complete_locations_in_chunks_async_co (_data_);
}

static GeeList*
geary_imap_db_folder_remove_complete_locations_in_chunks_finish (GearyImapDBFolder* self,
                                                                 GAsyncResult* _res_,
                                                                 GError** error)
{
	GeeList* result;
	GearyImapDbFolderRemoveCompleteLocationsInChunksAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block63Data*
block63_data_ref (Block63Data* _data63_)
{
	g_atomic_int_inc (&_data63_->_ref_count_);
	return _data63_;
}

static void
block63_data_unref (void * _userdata_)
{
	Block63Data* _data63_;
	_data63_ = (Block63Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data63_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data63_->self;
		_g_object_unref0 (_data63_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block63Data, _data63_);
	}
}

static Block64Data*
block64_data_ref (Block64Data* _data64_)
{
	g_atomic_int_inc (&_data64_->_ref_count_);
	return _data64_;
}

static void
block64_data_unref (void * _userdata_)
{
	Block64Data* _data64_;
	_data64_ = (Block64Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data64_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data64_->_data63_->self;
		_g_object_unref0 (_data64_->slice);
		block63_data_unref (_data64_->_data63_);
		_data64_->_data63_ = NULL;
		g_slice_free (Block64Data, _data64_);
	}
}

static GearyDbTransactionOutcome
____lambda58_ (Block64Data* _data64_,
               GearyDbConnection* cx,
               GError** error)
{
	Block63Data* _data63_;
	GearyImapDBFolder* self;
	GeeList* _tmp0_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	_data63_ = _data64_->_data63_;
	self = _data63_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = _data64_->slice;
	geary_imap_db_folder_do_remove_complete_locations (self, cx, _tmp0_, _data63_->cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_SUCCESS;
	return result;
}

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

static void
geary_imap_db_folder_remove_complete_locations_in_chunks_async_ready (GObject* source_object,
                                                                      GAsyncResult* _res_,
                                                                      gpointer _user_data_)
{
	GearyImapDbFolderRemoveCompleteLocationsInChunksAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_remove_complete_locations_in_chunks_async_co (_data_);
}

static gboolean
geary_imap_db_folder_remove_complete_locations_in_chunks_async_co (GearyImapDbFolderRemoveCompleteLocationsInChunksAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data63_ = g_slice_new0 (Block63Data);
	_data_->_data63_->_ref_count_ = 1;
	_data_->_data63_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data63_->cancellable);
	_data_->_data63_->cancellable = _data_->cancellable;
	_data_->_data63_->_async_data_ = _data_;
	if (_data_->locations == NULL) {
		_data_->_tmp0_ = TRUE;
	} else {
		_data_->_tmp1_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->locations, GEE_TYPE_COLLECTION, GeeCollection));
		_data_->_tmp2_ = _data_->_tmp1_;
		_data_->_tmp0_ = _data_->_tmp2_ == 0;
	}
	if (_data_->_tmp0_) {
		_data_->_tmp3_ = _g_object_ref0 (_data_->locations);
		_data_->result = _data_->_tmp3_;
		block63_data_unref (_data_->_data63_);
		_data_->_data63_ = 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_->_tmp4_ = gee_array_list_new (GEARY_IMAP_DB_FOLDER_TYPE_LOCATION_IDENTIFIER, (GBoxedCopyFunc) geary_imap_db_folder_location_identifier_ref, (GDestroyNotify) geary_imap_db_folder_location_identifier_unref, NULL, NULL, NULL);
	_data_->incomplete_locations = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp4_, GEE_TYPE_LIST, GeeList);
	_data_->start = 0;
	{
		_data_->_tmp5_ = TRUE;
		while (TRUE) {
			_data_->_data64_ = g_slice_new0 (Block64Data);
			_data_->_data64_->_ref_count_ = 1;
			_data_->_data64_->_data63_ = block63_data_ref (_data_->_data63_);
			if (!_data_->_tmp5_) {
			}
			_data_->_tmp5_ = FALSE;
			_data_->_tmp6_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->locations, GEE_TYPE_COLLECTION, GeeCollection));
			_data_->_tmp7_ = _data_->_tmp6_;
			if (_data_->start >= _data_->_tmp7_) {
				block64_data_unref (_data_->_data64_);
				_data_->_data64_ = NULL;
				break;
			}
			_data_->_tmp8_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->locations, GEE_TYPE_COLLECTION, GeeCollection));
			_data_->_tmp9_ = _data_->_tmp8_;
			_data_->end = CLAMP (_data_->start + GEARY_IMAP_DB_FOLDER_REMOVE_COMPLETE_LOCATIONS_CHUNK_COUNT, 0, _data_->_tmp9_);
			_data_->_tmp10_ = gee_list_slice (_data_->locations, _data_->start, _data_->end);
			_data_->_data64_->slice = _data_->_tmp10_;
			_data_->_tmp11_ = _data_->self->priv->db;
			_data_->_state_ = 1;
			geary_db_database_exec_transaction_async (_data_->_tmp11_, GEARY_DB_TRANSACTION_TYPE_RO, _____lambda58__geary_db_transaction_method, _data_->_data64_, _data_->_data63_->cancellable, geary_imap_db_folder_remove_complete_locations_in_chunks_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_);
				block64_data_unref (_data_->_data64_);
				_data_->_data64_ = NULL;
				_g_object_unref0 (_data_->incomplete_locations);
				block63_data_unref (_data_->_data63_);
				_data_->_data63_ = NULL;
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
			_data_->_tmp12_ = _data_->incomplete_locations;
			_data_->_tmp13_ = _data_->_data64_->slice;
			gee_collection_add_all (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp12_, GEE_TYPE_COLLECTION, GeeCollection), G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp13_, GEE_TYPE_COLLECTION, GeeCollection));
			_data_->start = _data_->end;
			block64_data_unref (_data_->_data64_);
			_data_->_data64_ = NULL;
		}
	}
	_data_->_tmp15_ = _data_->incomplete_locations;
	_data_->_tmp16_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp15_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp17_ = _data_->_tmp16_;
	if (_data_->_tmp17_ > 0) {
		_data_->_tmp18_ = _data_->incomplete_locations;
		_data_->_tmp14_ = _data_->_tmp18_;
	} else {
		_data_->_tmp14_ = NULL;
	}
	_data_->_tmp19_ = _g_object_ref0 (_data_->_tmp14_);
	_data_->result = _data_->_tmp19_;
	_g_object_unref0 (_data_->incomplete_locations);
	block63_data_unref (_data_->_data63_);
	_data_->_data63_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

static void
geary_imap_db_folder_list_email_in_chunks_async (GearyImapDBFolder* self,
                                                 GeeList* ids,
                                                 GearyEmailField required_fields,
                                                 GearyImapDBFolderListFlags flags,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_)
{
	GearyImapDbFolderListEmailInChunksAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GeeList* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail ((ids == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_LIST));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderListEmailInChunksAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_list_email_in_chunks_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_imap_db_folder_list_email_in_chunks_async_co (_data_);
}

static GeeList*
geary_imap_db_folder_list_email_in_chunks_finish (GearyImapDBFolder* self,
                                                  GAsyncResult* _res_,
                                                  GError** error)
{
	GeeList* result;
	GearyImapDbFolderListEmailInChunksAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block65Data*
block65_data_ref (Block65Data* _data65_)
{
	g_atomic_int_inc (&_data65_->_ref_count_);
	return _data65_;
}

static void
block65_data_unref (void * _userdata_)
{
	Block65Data* _data65_;
	_data65_ = (Block65Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data65_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data65_->self;
		_g_object_unref0 (self);
		g_slice_free (Block65Data, _data65_);
	}
}

static Block66Data*
block66_data_ref (Block66Data* _data66_)
{
	g_atomic_int_inc (&_data66_->_ref_count_);
	return _data66_;
}

static void
block66_data_unref (void * _userdata_)
{
	Block66Data* _data66_;
	_data66_ = (Block66Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data66_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data66_->_data65_->self;
		_g_object_unref0 (_data66_->list);
		_g_object_unref0 (_data66_->slice);
		block65_data_unref (_data66_->_data65_);
		_data66_->_data65_ = NULL;
		g_slice_free (Block66Data, _data66_);
	}
}

static GearyDbTransactionOutcome
_____lambda59_ (Block66Data* _data66_,
                GearyDbConnection* cx,
                GCancellable* cancellable,
                GError** error)
{
	Block65Data* _data65_;
	GearyImapDBFolder* self;
	GeeList* _tmp0_ = NULL;
	GeeList* _tmp1_;
	GeeList* _tmp2_;
	GeeList* _tmp3_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	_data65_ = _data66_->_data65_;
	self = _data65_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), 0);
	_tmp1_ = _data66_->slice;
	_tmp2_ = geary_imap_db_folder_do_list_email (self, cx, _tmp1_, _data65_->required_fields, _data65_->flags, cancellable, &_inner_error0_);
	_tmp0_ = _tmp2_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp3_ = _tmp0_;
	_tmp0_ = NULL;
	_g_object_unref0 (_data66_->list);
	_data66_->list = _tmp3_;
	result = GEARY_DB_TRANSACTION_OUTCOME_SUCCESS;
	_g_object_unref0 (_tmp0_);
	return result;
}

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

static void
geary_imap_db_folder_list_email_in_chunks_async_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_)
{
	GearyImapDbFolderListEmailInChunksAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_list_email_in_chunks_async_co (_data_);
}

static gboolean
geary_imap_db_folder_list_email_in_chunks_async_co (GearyImapDbFolderListEmailInChunksAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data65_ = g_slice_new0 (Block65Data);
	_data_->_data65_->_ref_count_ = 1;
	_data_->_data65_->self = g_object_ref (_data_->self);
	_data_->_data65_->required_fields = _data_->required_fields;
	_data_->_data65_->flags = _data_->flags;
	_data_->_data65_->_async_data_ = _data_;
	if (_data_->ids == NULL) {
		_data_->_tmp0_ = TRUE;
	} else {
		_data_->_tmp1_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->ids, GEE_TYPE_COLLECTION, GeeCollection));
		_data_->_tmp2_ = _data_->_tmp1_;
		_data_->_tmp0_ = _data_->_tmp2_ == 0;
	}
	if (_data_->_tmp0_) {
		_data_->result = NULL;
		block65_data_unref (_data_->_data65_);
		_data_->_data65_ = 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;
	}
	if (geary_email_field_requires_any (_data_->_data65_->required_fields, GEARY_EMAIL_FIELD_BODY | GEARY_EMAIL_FIELD_HEADER)) {
		_data_->_tmp3_ = GEARY_IMAP_DB_FOLDER_LIST_EMAIL_WITH_MESSAGE_CHUNK_COUNT;
	} else {
		_data_->_tmp3_ = GEARY_IMAP_DB_FOLDER_LIST_EMAIL_METADATA_COUNT;
	}
	_data_->chunk_count = _data_->_tmp3_;
	_data_->_tmp4_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->ids, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp5_ = _data_->_tmp4_;
	_data_->length_rounded_up = geary_numeric_int_round_up (_data_->_tmp5_, _data_->chunk_count);
	_data_->_tmp6_ = gee_array_list_new (GEARY_TYPE_EMAIL, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data_->results = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp6_, GEE_TYPE_LIST, GeeList);
	{
		_data_->start = 0;
		{
			_data_->_tmp7_ = TRUE;
			while (TRUE) {
				_data_->_data66_ = g_slice_new0 (Block66Data);
				_data_->_data66_->_ref_count_ = 1;
				_data_->_data66_->_data65_ = block65_data_ref (_data_->_data65_);
				if (!_data_->_tmp7_) {
					_data_->start += _data_->chunk_count;
				}
				_data_->_tmp7_ = FALSE;
				if (!(_data_->start < _data_->length_rounded_up)) {
					block66_data_unref (_data_->_data66_);
					_data_->_data66_ = NULL;
					break;
				}
				_data_->_tmp8_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->ids, GEE_TYPE_COLLECTION, GeeCollection));
				_data_->_tmp9_ = _data_->_tmp8_;
				_data_->stop = geary_numeric_int_ceiling (_data_->start + _data_->chunk_count, _data_->_tmp9_);
				_data_->_tmp10_ = gee_list_slice (_data_->ids, _data_->start, _data_->stop);
				_data_->_data66_->slice = _data_->_tmp10_;
				_data_->_tmp12_ = _data_->_data66_->slice;
				if (_data_->_tmp12_ != NULL) {
					_data_->_tmp13_ = _data_->_data66_->slice;
					_data_->_tmp14_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp13_, GEE_TYPE_COLLECTION, GeeCollection));
					_data_->_tmp15_ = _data_->_tmp14_;
					_data_->_tmp11_ = _data_->_tmp15_ > 0;
				} else {
					_data_->_tmp11_ = FALSE;
				}
				_vala_assert (_data_->_tmp11_, "slice != null && slice.size > 0");
				_data_->_data66_->list = NULL;
				_data_->_tmp16_ = _data_->self->priv->db;
				_data_->_state_ = 1;
				geary_db_database_exec_transaction_async (_data_->_tmp16_, GEARY_DB_TRANSACTION_TYPE_RO, ______lambda59__geary_db_transaction_method, _data_->_data66_, _data_->cancellable, geary_imap_db_folder_list_email_in_chunks_async_ready, _data_);
				return FALSE;
				_state_1:
				geary_db_database_exec_transaction_finish (_data_->_tmp16_, _data_->_res_, &_data_->_inner_error0_);
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
					block66_data_unref (_data_->_data66_);
					_data_->_data66_ = NULL;
					_g_object_unref0 (_data_->results);
					block65_data_unref (_data_->_data65_);
					_data_->_data65_ = NULL;
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
				_data_->_tmp17_ = _data_->_data66_->list;
				if (_data_->_tmp17_ != NULL) {
					_data_->_tmp18_ = _data_->results;
					_data_->_tmp19_ = _data_->_data66_->list;
					gee_collection_add_all (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp18_, GEE_TYPE_COLLECTION, GeeCollection), G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp19_, GEE_TYPE_COLLECTION, GeeCollection));
				}
				block66_data_unref (_data_->_data66_);
				_data_->_data66_ = NULL;
			}
		}
	}
	_data_->_tmp20_ = _data_->results;
	_data_->_tmp21_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp20_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp22_ = _data_->_tmp21_;
	_data_->_tmp23_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->ids, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp24_ = _data_->_tmp23_;
	if (_data_->_tmp22_ != _data_->_tmp24_) {
		_data_->_tmp25_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->ids, GEE_TYPE_COLLECTION, GeeCollection));
		_data_->_tmp26_ = _data_->_tmp25_;
		_data_->_tmp27_ = _data_->results;
		_data_->_tmp28_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp27_, GEE_TYPE_COLLECTION, GeeCollection));
		_data_->_tmp29_ = _data_->_tmp28_;
		g_debug ("imap-db-folder.vala:696: list_email_in_chunks_async: Requested %d emai" \
"l, returned %d", _data_->_tmp26_, _data_->_tmp29_);
	}
	_data_->_tmp31_ = _data_->results;
	_data_->_tmp32_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp31_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp33_ = _data_->_tmp32_;
	if (_data_->_tmp33_ > 0) {
		_data_->_tmp34_ = _data_->results;
		_data_->_tmp30_ = _data_->_tmp34_;
	} else {
		_data_->_tmp30_ = NULL;
	}
	_data_->_tmp35_ = _g_object_ref0 (_data_->_tmp30_);
	_data_->result = _data_->_tmp35_;
	_g_object_unref0 (_data_->results);
	block65_data_unref (_data_->_data65_);
	_data_->_data65_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_fetch_email_async (GearyImapDBFolder* self,
                                        GearyImapDBEmailIdentifier* id,
                                        GearyEmailField required_fields,
                                        GearyImapDBFolderListFlags flags,
                                        GCancellable* cancellable,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_)
{
	GearyImapDbFolderFetchEmailAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GearyImapDBEmailIdentifier* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_IMAP_DB_IS_EMAIL_IDENTIFIER (id));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderFetchEmailAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_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_imap_db_folder_fetch_email_async_co (_data_);
}

GearyEmail*
geary_imap_db_folder_fetch_email_finish (GearyImapDBFolder* self,
                                         GAsyncResult* _res_,
                                         GError** error)
{
	GearyEmail* result;
	GearyImapDbFolderFetchEmailAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block67Data*
block67_data_ref (Block67Data* _data67_)
{
	g_atomic_int_inc (&_data67_->_ref_count_);
	return _data67_;
}

static void
block67_data_unref (void * _userdata_)
{
	Block67Data* _data67_;
	_data67_ = (Block67Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data67_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data67_->self;
		_g_object_unref0 (_data67_->email);
		_g_object_unref0 (_data67_->id);
		_g_object_unref0 (_data67_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block67Data, _data67_);
	}
}

static GearyDbTransactionOutcome
__lambda63_ (Block67Data* _data67_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GearyImapDBFolderLocationIdentifier* location = NULL;
	GearyImapDBFolderLocationIdentifier* _tmp0_;
	GearyImapDBFolderLocationIdentifier* _tmp1_;
	GearyEmail* _tmp2_ = NULL;
	GearyImapDBFolderLocationIdentifier* _tmp3_;
	GearyEmail* _tmp4_;
	GearyEmail* _tmp5_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data67_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_imap_db_folder_do_get_location_for_id (self, cx, _data67_->id, _data67_->flags, _data67_->cancellable, &_inner_error0_);
	location = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp1_ = location;
	if (_tmp1_ == NULL) {
		result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
		_geary_imap_db_folder_location_identifier_unref0 (location);
		return result;
	}
	_tmp3_ = location;
	_tmp4_ = geary_imap_db_folder_do_location_to_email (self, cx, _tmp3_, _data67_->required_fields, _data67_->flags, _data67_->cancellable, &_inner_error0_);
	_tmp2_ = _tmp4_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_geary_imap_db_folder_location_identifier_unref0 (location);
		return 0;
	}
	_tmp5_ = _tmp2_;
	_tmp2_ = NULL;
	_g_object_unref0 (_data67_->email);
	_data67_->email = _tmp5_;
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	_g_object_unref0 (_tmp2_);
	_geary_imap_db_folder_location_identifier_unref0 (location);
	return result;
}

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

static void
geary_imap_db_folder_fetch_email_async_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_)
{
	GearyImapDbFolderFetchEmailAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_fetch_email_async_co (_data_);
}

static gboolean
geary_imap_db_folder_fetch_email_async_co (GearyImapDbFolderFetchEmailAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data67_ = g_slice_new0 (Block67Data);
	_data_->_data67_->_ref_count_ = 1;
	_data_->_data67_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data67_->id);
	_data_->_data67_->id = _data_->id;
	_data_->_data67_->required_fields = _data_->required_fields;
	_data_->_data67_->flags = _data_->flags;
	_g_object_unref0 (_data_->_data67_->cancellable);
	_data_->_data67_->cancellable = _data_->cancellable;
	_data_->_data67_->_async_data_ = _data_;
	_data_->_data67_->email = NULL;
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda63__geary_db_transaction_method, _data_->_data67_, _data_->_data67_->cancellable, geary_imap_db_folder_fetch_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_);
		block67_data_unref (_data_->_data67_);
		_data_->_data67_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp1_ = _data_->_data67_->email;
	if (_data_->_tmp1_ == NULL) {
		_data_->_tmp2_ = geary_email_identifier_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->_data67_->id, GEARY_TYPE_EMAIL_IDENTIFIER, GearyEmailIdentifier));
		_data_->_tmp3_ = _data_->_tmp2_;
		_data_->_tmp4_ = geary_imap_db_folder_to_string (_data_->self);
		_data_->_tmp5_ = _data_->_tmp4_;
		_data_->_tmp6_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_NOT_FOUND, "No message ID %s in folder %s", _data_->_tmp3_, _data_->_tmp5_);
		_data_->_tmp7_ = _data_->_tmp6_;
		_g_free0 (_data_->_tmp5_);
		_g_free0 (_data_->_tmp3_);
		_data_->_inner_error0_ = _data_->_tmp7_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block67_data_unref (_data_->_data67_);
		_data_->_data67_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp8_ = _data_->_data67_->email;
	_data_->_tmp9_ = _g_object_ref0 (_data_->_tmp8_);
	_data_->result = _data_->_tmp9_;
	block67_data_unref (_data_->_data67_);
	_data_->_data67_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_db_folder_list_uids_by_range_async_data_free (gpointer _data)
{
	GearyImapDbFolderListUidsByRangeAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->first_uid);
	_g_object_unref0 (_data_->last_uid);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapDbFolderListUidsByRangeAsyncData, _data_);
}

void
geary_imap_db_folder_list_uids_by_range_async (GearyImapDBFolder* self,
                                               GearyImapUID* first_uid,
                                               GearyImapUID* last_uid,
                                               gboolean include_marked_for_removal,
                                               GCancellable* cancellable,
                                               GAsyncReadyCallback _callback_,
                                               gpointer _user_data_)
{
	GearyImapDbFolderListUidsByRangeAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GearyImapUID* _tmp1_;
	GearyImapUID* _tmp2_;
	GCancellable* _tmp3_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_IMAP_IS_UID (first_uid));
	g_return_if_fail (GEARY_IMAP_IS_UID (last_uid));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderListUidsByRangeAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_list_uids_by_range_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (first_uid);
	_g_object_unref0 (_data_->first_uid);
	_data_->first_uid = _tmp1_;
	_tmp2_ = _g_object_ref0 (last_uid);
	_g_object_unref0 (_data_->last_uid);
	_data_->last_uid = _tmp2_;
	_data_->include_marked_for_removal = include_marked_for_removal;
	_tmp3_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp3_;
	geary_imap_db_folder_list_uids_by_range_async_co (_data_);
}

GeeSet*
geary_imap_db_folder_list_uids_by_range_finish (GearyImapDBFolder* self,
                                                GAsyncResult* _res_,
                                                GError** error)
{
	GeeSet* result;
	GearyImapDbFolderListUidsByRangeAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block68Data*
block68_data_ref (Block68Data* _data68_)
{
	g_atomic_int_inc (&_data68_->_ref_count_);
	return _data68_;
}

static void
block68_data_unref (void * _userdata_)
{
	Block68Data* _data68_;
	_data68_ = (Block68Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data68_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data68_->self;
		_g_object_unref0 (_data68_->uids);
		_g_object_unref0 (_data68_->end);
		_g_object_unref0 (_data68_->start);
		_g_object_unref0 (_data68_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block68Data, _data68_);
	}
}

static GearyDbTransactionOutcome
__lambda64_ (Block68Data* _data68_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp1_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyImapUID* _tmp5_;
	gint64 _tmp6_;
	gint64 _tmp7_;
	GearyDbStatement* _tmp8_;
	GearyDbStatement* _tmp9_;
	GearyDbStatement* _tmp10_;
	GearyImapUID* _tmp11_;
	gint64 _tmp12_;
	gint64 _tmp13_;
	GearyDbStatement* _tmp14_;
	GearyDbStatement* _tmp15_;
	GearyDbResult* _result_ = NULL;
	GearyDbStatement* _tmp16_;
	GearyDbResult* _tmp17_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data68_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_db_connection_prepare (cx, "\n" \
"                SELECT ordering, remove_marker\n" \
"                FROM MessageLocationTable\n" \
"                WHERE folder_id = ? AND ordering >= ? AND ordering <= " \
"?\n" \
"            ", &_inner_error0_);
	stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp1_ = stmt;
	_tmp2_ = geary_db_statement_bind_rowid (_tmp1_, 0, self->priv->folder_id, &_inner_error0_);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp3_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp4_ = stmt;
	_tmp5_ = _data68_->start;
	_tmp6_ = geary_message_data_int64_message_data_get_value (G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, GEARY_MESSAGE_DATA_TYPE_INT64_MESSAGE_DATA, GearyMessageDataInt64MessageData));
	_tmp7_ = _tmp6_;
	_tmp8_ = geary_db_statement_bind_int64 (_tmp4_, 1, _tmp7_, &_inner_error0_);
	_tmp9_ = _tmp8_;
	_g_object_unref0 (_tmp9_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp10_ = stmt;
	_tmp11_ = _data68_->end;
	_tmp12_ = geary_message_data_int64_message_data_get_value (G_TYPE_CHECK_INSTANCE_CAST (_tmp11_, GEARY_MESSAGE_DATA_TYPE_INT64_MESSAGE_DATA, GearyMessageDataInt64MessageData));
	_tmp13_ = _tmp12_;
	_tmp14_ = geary_db_statement_bind_int64 (_tmp10_, 2, _tmp13_, &_inner_error0_);
	_tmp15_ = _tmp14_;
	_g_object_unref0 (_tmp15_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp16_ = stmt;
	_tmp17_ = geary_db_statement_exec (_tmp16_, _data68_->cancellable, &_inner_error0_);
	_result_ = _tmp17_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	while (TRUE) {
		GearyDbResult* _tmp18_;
		gboolean _tmp19_;
		gboolean _tmp20_;
		gboolean _tmp21_ = FALSE;
		GearyDbResult* _tmp28_;
		_tmp18_ = _result_;
		_tmp19_ = geary_db_result_get_finished (_tmp18_);
		_tmp20_ = _tmp19_;
		if (!(!_tmp20_)) {
			break;
		}
		if (_data68_->include_marked_for_removal) {
			_tmp21_ = TRUE;
		} else {
			gboolean _tmp22_ = FALSE;
			GearyDbResult* _tmp23_;
			_tmp23_ = _result_;
			_tmp22_ = geary_db_result_bool_at (_tmp23_, 1, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (_result_);
				_g_object_unref0 (stmt);
				return 0;
			}
			_tmp21_ = !_tmp22_;
		}
		if (_tmp21_) {
			gint64 _tmp24_ = 0LL;
			GearyDbResult* _tmp25_;
			GearyImapUID* _tmp26_;
			GearyImapUID* _tmp27_;
			_tmp25_ = _result_;
			_tmp24_ = geary_db_result_int64_at (_tmp25_, 0, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (_result_);
				_g_object_unref0 (stmt);
				return 0;
			}
			_tmp26_ = geary_imap_uid_new (_tmp24_);
			_tmp27_ = _tmp26_;
			gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_data68_->uids, GEE_TYPE_COLLECTION, GeeCollection), _tmp27_);
			_g_object_unref0 (_tmp27_);
		}
		_tmp28_ = _result_;
		geary_db_result_next (_tmp28_, _data68_->cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (_result_);
			_g_object_unref0 (stmt);
			return 0;
		}
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	_g_object_unref0 (_result_);
	_g_object_unref0 (stmt);
	return result;
}

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

static void
geary_imap_db_folder_list_uids_by_range_async_ready (GObject* source_object,
                                                     GAsyncResult* _res_,
                                                     gpointer _user_data_)
{
	GearyImapDbFolderListUidsByRangeAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_list_uids_by_range_async_co (_data_);
}

static gboolean
geary_imap_db_folder_list_uids_by_range_async_co (GearyImapDbFolderListUidsByRangeAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data68_ = g_slice_new0 (Block68Data);
	_data_->_data68_->_ref_count_ = 1;
	_data_->_data68_->self = g_object_ref (_data_->self);
	_data_->_data68_->include_marked_for_removal = _data_->include_marked_for_removal;
	_g_object_unref0 (_data_->_data68_->cancellable);
	_data_->_data68_->cancellable = _data_->cancellable;
	_data_->_data68_->_async_data_ = _data_;
	if (geary_imap_uid_compare_to (_data_->first_uid, _data_->last_uid) < 0) {
		_data_->_tmp0_ = _g_object_ref0 (_data_->first_uid);
		_g_object_unref0 (_data_->_data68_->start);
		_data_->_data68_->start = _data_->_tmp0_;
		_data_->_tmp1_ = _g_object_ref0 (_data_->last_uid);
		_g_object_unref0 (_data_->_data68_->end);
		_data_->_data68_->end = _data_->_tmp1_;
	} else {
		_data_->_tmp2_ = _g_object_ref0 (_data_->last_uid);
		_g_object_unref0 (_data_->_data68_->start);
		_data_->_data68_->start = _data_->_tmp2_;
		_data_->_tmp3_ = _g_object_ref0 (_data_->first_uid);
		_g_object_unref0 (_data_->_data68_->end);
		_data_->_data68_->end = _data_->_tmp3_;
	}
	_data_->_tmp4_ = gee_hash_set_new (GEARY_IMAP_TYPE_UID, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->_data68_->uids = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp4_, GEE_TYPE_SET, GeeSet);
	_data_->_tmp5_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp5_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda64__geary_db_transaction_method, _data_->_data68_, _data_->_data68_->cancellable, geary_imap_db_folder_list_uids_by_range_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (_data_->_tmp5_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block68_data_unref (_data_->_data68_);
		_data_->_data68_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp7_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_data68_->uids, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp8_ = _data_->_tmp7_;
	if (_data_->_tmp8_ > 0) {
		_data_->_tmp6_ = _data_->_data68_->uids;
	} else {
		_data_->_tmp6_ = NULL;
	}
	_data_->_tmp9_ = _g_object_ref0 (_data_->_tmp6_);
	_data_->result = _data_->_tmp9_;
	block68_data_unref (_data_->_data68_);
	_data_->_data68_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_get_id_at_async (GearyImapDBFolder* self,
                                      gint64 pos,
                                      GCancellable* cancellable,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_)
{
	GearyImapDbFolderGetIdAtAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderGetIdAtAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_get_id_at_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->pos = pos;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_db_folder_get_id_at_async_co (_data_);
}

GearyImapDBEmailIdentifier*
geary_imap_db_folder_get_id_at_finish (GearyImapDBFolder* self,
                                       GAsyncResult* _res_,
                                       GError** error)
{
	GearyImapDBEmailIdentifier* result;
	GearyImapDbFolderGetIdAtAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block69Data*
block69_data_ref (Block69Data* _data69_)
{
	g_atomic_int_inc (&_data69_->_ref_count_);
	return _data69_;
}

static void
block69_data_unref (void * _userdata_)
{
	Block69Data* _data69_;
	_data69_ = (Block69Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data69_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data69_->self;
		_g_object_unref0 (_data69_->id);
		_g_object_unref0 (_data69_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block69Data, _data69_);
	}
}

static GearyDbTransactionOutcome
__lambda65_ (Block69Data* _data69_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp1_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbStatement* _tmp5_;
	GearyDbStatement* _tmp6_;
	GearyDbResult* results = NULL;
	GearyDbStatement* _tmp7_;
	GearyDbResult* _tmp8_;
	GearyDbResult* _tmp9_;
	gboolean _tmp10_;
	gboolean _tmp11_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data69_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_db_connection_prepare (cx, "\n" \
"                SELECT message_id, ordering\n" \
"                FROM MessageLocationTable\n" \
"                WHERE folder_id=?\n" \
"                ORDER BY ordering\n" \
"                LIMIT 1\n" \
"                OFFSET ?\n" \
"            ", &_inner_error0_);
	stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp1_ = stmt;
	_tmp2_ = geary_db_statement_bind_rowid (_tmp1_, 0, self->priv->folder_id, &_inner_error0_);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp3_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp4_ = stmt;
	_tmp5_ = geary_db_statement_bind_int64 (_tmp4_, 1, _data69_->pos - 1, &_inner_error0_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp6_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp7_ = stmt;
	_tmp8_ = geary_db_statement_exec (_tmp7_, _data69_->cancellable, &_inner_error0_);
	results = _tmp8_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp9_ = results;
	_tmp10_ = geary_db_result_get_finished (_tmp9_);
	_tmp11_ = _tmp10_;
	if (!_tmp11_) {
		gint64 _tmp12_ = 0LL;
		GearyDbResult* _tmp13_;
		gint64 _tmp14_ = 0LL;
		GearyDbResult* _tmp15_;
		GearyImapUID* _tmp16_;
		GearyImapUID* _tmp17_;
		GearyImapDBEmailIdentifier* _tmp18_;
		_tmp13_ = results;
		_tmp12_ = geary_db_result_rowid_at (_tmp13_, 0, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp15_ = results;
		_tmp14_ = geary_db_result_int64_at (_tmp15_, 1, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp16_ = geary_imap_uid_new (_tmp14_);
		_tmp17_ = _tmp16_;
		_tmp18_ = geary_imap_db_email_identifier_new (_tmp12_, _tmp17_);
		_g_object_unref0 (_data69_->id);
		_data69_->id = _tmp18_;
		_g_object_unref0 (_tmp17_);
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	_g_object_unref0 (results);
	_g_object_unref0 (stmt);
	return result;
}

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

static void
geary_imap_db_folder_get_id_at_async_ready (GObject* source_object,
                                            GAsyncResult* _res_,
                                            gpointer _user_data_)
{
	GearyImapDbFolderGetIdAtAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_get_id_at_async_co (_data_);
}

static gboolean
geary_imap_db_folder_get_id_at_async_co (GearyImapDbFolderGetIdAtAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data69_ = g_slice_new0 (Block69Data);
	_data_->_data69_->_ref_count_ = 1;
	_data_->_data69_->self = g_object_ref (_data_->self);
	_data_->_data69_->pos = _data_->pos;
	_g_object_unref0 (_data_->_data69_->cancellable);
	_data_->_data69_->cancellable = _data_->cancellable;
	_data_->_data69_->_async_data_ = _data_;
	_vala_assert (_data_->_data69_->pos >= ((gint64) 1), "pos >= 1");
	_data_->_data69_->id = NULL;
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda65__geary_db_transaction_method, _data_->_data69_, _data_->_data69_->cancellable, geary_imap_db_folder_get_id_at_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_);
		block69_data_unref (_data_->_data69_);
		_data_->_data69_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp1_ = _g_object_ref0 (_data_->_data69_->id);
	_data_->result = _data_->_tmp1_;
	block69_data_unref (_data_->_data69_);
	_data_->_data69_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_get_uid_async (GearyImapDBFolder* self,
                                    GearyImapDBEmailIdentifier* id,
                                    GearyImapDBFolderListFlags flags,
                                    GCancellable* cancellable,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_)
{
	GearyImapDbFolderGetUidAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GearyImapDBEmailIdentifier* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_IMAP_DB_IS_EMAIL_IDENTIFIER (id));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderGetUidAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_get_uid_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_->flags = flags;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_folder_get_uid_async_co (_data_);
}

GearyImapUID*
geary_imap_db_folder_get_uid_finish (GearyImapDBFolder* self,
                                     GAsyncResult* _res_,
                                     GError** error)
{
	GearyImapUID* result;
	GearyImapDbFolderGetUidAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block70Data*
block70_data_ref (Block70Data* _data70_)
{
	g_atomic_int_inc (&_data70_->_ref_count_);
	return _data70_;
}

static void
block70_data_unref (void * _userdata_)
{
	Block70Data* _data70_;
	_data70_ = (Block70Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data70_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data70_->self;
		_g_object_unref0 (_data70_->uid);
		_g_object_unref0 (_data70_->id);
		_g_object_unref0 (_data70_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block70Data, _data70_);
	}
}

static GearyDbTransactionOutcome
__lambda66_ (Block70Data* _data70_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GearyImapDBFolderLocationIdentifier* location = NULL;
	GearyImapDBFolderLocationIdentifier* _tmp0_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data70_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_imap_db_folder_do_get_location_for_id (self, cx, _data70_->id, _data70_->flags, _data70_->cancellable, &_inner_error0_);
	location = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	if (location != NULL) {
		GearyImapUID* _tmp1_;
		GearyImapUID* _tmp2_;
		_tmp1_ = location->uid;
		_tmp2_ = _g_object_ref0 (_tmp1_);
		_g_object_unref0 (_data70_->uid);
		_data70_->uid = _tmp2_;
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	_geary_imap_db_folder_location_identifier_unref0 (location);
	return result;
}

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

static void
geary_imap_db_folder_get_uid_async_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_)
{
	GearyImapDbFolderGetUidAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_get_uid_async_co (_data_);
}

static gboolean
geary_imap_db_folder_get_uid_async_co (GearyImapDbFolderGetUidAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data70_ = g_slice_new0 (Block70Data);
	_data_->_data70_->_ref_count_ = 1;
	_data_->_data70_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data70_->id);
	_data_->_data70_->id = _data_->id;
	_data_->_data70_->flags = _data_->flags;
	_g_object_unref0 (_data_->_data70_->cancellable);
	_data_->_data70_->cancellable = _data_->cancellable;
	_data_->_data70_->_async_data_ = _data_;
	_data_->_data70_->uid = NULL;
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda66__geary_db_transaction_method, _data_->_data70_, _data_->_data70_->cancellable, geary_imap_db_folder_get_uid_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_);
		block70_data_unref (_data_->_data70_);
		_data_->_data70_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp1_ = _g_object_ref0 (_data_->_data70_->uid);
	_data_->result = _data_->_tmp1_;
	block70_data_unref (_data_->_data70_);
	_data_->_data70_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_get_uids_async (GearyImapDBFolder* self,
                                     GeeCollection* ids,
                                     GearyImapDBFolderListFlags flags,
                                     GCancellable* cancellable,
                                     GAsyncReadyCallback _callback_,
                                     gpointer _user_data_)
{
	GearyImapDbFolderGetUidsAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GeeCollection* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderGetUidsAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_get_uids_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_->flags = flags;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_folder_get_uids_async_co (_data_);
}

GeeSet*
geary_imap_db_folder_get_uids_finish (GearyImapDBFolder* self,
                                      GAsyncResult* _res_,
                                      GError** error)
{
	GeeSet* result;
	GearyImapDbFolderGetUidsAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block71Data*
block71_data_ref (Block71Data* _data71_)
{
	g_atomic_int_inc (&_data71_->_ref_count_);
	return _data71_;
}

static void
block71_data_unref (void * _userdata_)
{
	Block71Data* _data71_;
	_data71_ = (Block71Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data71_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data71_->self;
		_g_object_unref0 (_data71_->uids);
		_g_object_unref0 (_data71_->ids);
		_g_object_unref0 (_data71_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block71Data, _data71_);
	}
}

static GearyDbTransactionOutcome
__lambda67_ (Block71Data* _data71_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GeeList* locs = NULL;
	GeeList* _tmp0_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data71_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_imap_db_folder_do_get_locations_for_ids (self, cx, _data71_->ids, _data71_->flags, _data71_->cancellable, &_inner_error0_);
	locs = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	if (locs != NULL) {
		{
			GeeList* _location_list = NULL;
			gint _location_size = 0;
			GeeList* _tmp1_;
			gint _tmp2_;
			gint _tmp3_;
			gint _location_index = 0;
			_location_list = locs;
			_tmp1_ = _location_list;
			_tmp2_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEE_TYPE_COLLECTION, GeeCollection));
			_tmp3_ = _tmp2_;
			_location_size = _tmp3_;
			_location_index = -1;
			while (TRUE) {
				gint _tmp4_;
				gint _tmp5_;
				GearyImapDBFolderLocationIdentifier* location = NULL;
				GeeList* _tmp6_;
				gpointer _tmp7_;
				GearyImapDBFolderLocationIdentifier* _tmp8_;
				GearyImapUID* _tmp9_;
				_location_index = _location_index + 1;
				_tmp4_ = _location_index;
				_tmp5_ = _location_size;
				if (!(_tmp4_ < _tmp5_)) {
					break;
				}
				_tmp6_ = _location_list;
				_tmp7_ = gee_list_get (_tmp6_, _location_index);
				location = (GearyImapDBFolderLocationIdentifier*) _tmp7_;
				_tmp8_ = location;
				_tmp9_ = _tmp8_->uid;
				gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_data71_->uids, GEE_TYPE_COLLECTION, GeeCollection), _tmp9_);
				_geary_imap_db_folder_location_identifier_unref0 (location);
			}
		}
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	_g_object_unref0 (locs);
	return result;
}

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

static void
geary_imap_db_folder_get_uids_async_ready (GObject* source_object,
                                           GAsyncResult* _res_,
                                           gpointer _user_data_)
{
	GearyImapDbFolderGetUidsAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_get_uids_async_co (_data_);
}

static gboolean
geary_imap_db_folder_get_uids_async_co (GearyImapDbFolderGetUidsAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data71_ = g_slice_new0 (Block71Data);
	_data_->_data71_->_ref_count_ = 1;
	_data_->_data71_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data71_->ids);
	_data_->_data71_->ids = _data_->ids;
	_data_->_data71_->flags = _data_->flags;
	_g_object_unref0 (_data_->_data71_->cancellable);
	_data_->_data71_->cancellable = _data_->cancellable;
	_data_->_data71_->_async_data_ = _data_;
	_data_->_tmp0_ = gee_hash_set_new (GEARY_IMAP_TYPE_UID, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->_data71_->uids = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEE_TYPE_SET, GeeSet);
	_data_->_tmp1_ = _data_->self->priv->db;
	_data_->_tmp2_ = _data_->_data71_->cancellable;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp1_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda67__geary_db_transaction_method, _data_->_data71_, _data_->_tmp2_, geary_imap_db_folder_get_uids_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_);
		block71_data_unref (_data_->_data71_);
		_data_->_data71_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp4_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_data71_->uids, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp5_ = _data_->_tmp4_;
	if (_data_->_tmp5_ > 0) {
		_data_->_tmp3_ = _data_->_data71_->uids;
	} else {
		_data_->_tmp3_ = NULL;
	}
	_data_->_tmp6_ = _g_object_ref0 (_data_->_tmp3_);
	_data_->result = _data_->_tmp6_;
	block71_data_unref (_data_->_data71_);
	_data_->_data71_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_get_id_async (GearyImapDBFolder* self,
                                   GearyImapUID* uid,
                                   GearyImapDBFolderListFlags flags,
                                   GCancellable* cancellable,
                                   GAsyncReadyCallback _callback_,
                                   gpointer _user_data_)
{
	GearyImapDbFolderGetIdAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GearyImapUID* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_IMAP_IS_UID (uid));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderGetIdAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_get_id_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (uid);
	_g_object_unref0 (_data_->uid);
	_data_->uid = _tmp1_;
	_data_->flags = flags;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_folder_get_id_async_co (_data_);
}

GearyImapDBEmailIdentifier*
geary_imap_db_folder_get_id_finish (GearyImapDBFolder* self,
                                    GAsyncResult* _res_,
                                    GError** error)
{
	GearyImapDBEmailIdentifier* result;
	GearyImapDbFolderGetIdAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block72Data*
block72_data_ref (Block72Data* _data72_)
{
	g_atomic_int_inc (&_data72_->_ref_count_);
	return _data72_;
}

static void
block72_data_unref (void * _userdata_)
{
	Block72Data* _data72_;
	_data72_ = (Block72Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data72_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data72_->self;
		_g_object_unref0 (_data72_->id);
		_g_object_unref0 (_data72_->uid);
		_g_object_unref0 (_data72_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block72Data, _data72_);
	}
}

static GearyDbTransactionOutcome
__lambda68_ (Block72Data* _data72_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GearyImapDBFolderLocationIdentifier* location = NULL;
	GearyImapDBFolderLocationIdentifier* _tmp0_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data72_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_imap_db_folder_do_get_location_for_uid (self, cx, _data72_->uid, _data72_->flags, _data72_->cancellable, &_inner_error0_);
	location = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	if (location != NULL) {
		GearyImapDBEmailIdentifier* _tmp1_;
		GearyImapDBEmailIdentifier* _tmp2_;
		_tmp1_ = location->email_id;
		_tmp2_ = _g_object_ref0 (_tmp1_);
		_g_object_unref0 (_data72_->id);
		_data72_->id = _tmp2_;
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	_geary_imap_db_folder_location_identifier_unref0 (location);
	return result;
}

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

static void
geary_imap_db_folder_get_id_async_ready (GObject* source_object,
                                         GAsyncResult* _res_,
                                         gpointer _user_data_)
{
	GearyImapDbFolderGetIdAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_get_id_async_co (_data_);
}

static gboolean
geary_imap_db_folder_get_id_async_co (GearyImapDbFolderGetIdAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data72_ = g_slice_new0 (Block72Data);
	_data_->_data72_->_ref_count_ = 1;
	_data_->_data72_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data72_->uid);
	_data_->_data72_->uid = _data_->uid;
	_data_->_data72_->flags = _data_->flags;
	_g_object_unref0 (_data_->_data72_->cancellable);
	_data_->_data72_->cancellable = _data_->cancellable;
	_data_->_data72_->_async_data_ = _data_;
	_data_->_data72_->id = NULL;
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda68__geary_db_transaction_method, _data_->_data72_, _data_->_data72_->cancellable, geary_imap_db_folder_get_id_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_);
		block72_data_unref (_data_->_data72_);
		_data_->_data72_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp1_ = _g_object_ref0 (_data_->_data72_->id);
	_data_->result = _data_->_tmp1_;
	block72_data_unref (_data_->_data72_);
	_data_->_data72_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_get_ids_async (GearyImapDBFolder* self,
                                    GeeCollection* uids,
                                    GearyImapDBFolderListFlags flags,
                                    GCancellable* cancellable,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_)
{
	GearyImapDbFolderGetIdsAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GeeCollection* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (uids, GEE_TYPE_COLLECTION));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderGetIdsAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_get_ids_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (uids);
	_g_object_unref0 (_data_->uids);
	_data_->uids = _tmp1_;
	_data_->flags = flags;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_folder_get_ids_async_co (_data_);
}

GeeSet*
geary_imap_db_folder_get_ids_finish (GearyImapDBFolder* self,
                                     GAsyncResult* _res_,
                                     GError** error)
{
	GeeSet* result;
	GearyImapDbFolderGetIdsAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block73Data*
block73_data_ref (Block73Data* _data73_)
{
	g_atomic_int_inc (&_data73_->_ref_count_);
	return _data73_;
}

static void
block73_data_unref (void * _userdata_)
{
	Block73Data* _data73_;
	_data73_ = (Block73Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data73_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data73_->self;
		_g_object_unref0 (_data73_->ids);
		_g_object_unref0 (_data73_->uids);
		_g_object_unref0 (_data73_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block73Data, _data73_);
	}
}

static GearyDbTransactionOutcome
__lambda69_ (Block73Data* _data73_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GeeList* locs = NULL;
	GeeList* _tmp0_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data73_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_imap_db_folder_do_get_locations_for_uids (self, cx, _data73_->uids, _data73_->flags, _data73_->cancellable, &_inner_error0_);
	locs = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	if (locs != NULL) {
		{
			GeeList* _location_list = NULL;
			gint _location_size = 0;
			GeeList* _tmp1_;
			gint _tmp2_;
			gint _tmp3_;
			gint _location_index = 0;
			_location_list = locs;
			_tmp1_ = _location_list;
			_tmp2_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEE_TYPE_COLLECTION, GeeCollection));
			_tmp3_ = _tmp2_;
			_location_size = _tmp3_;
			_location_index = -1;
			while (TRUE) {
				gint _tmp4_;
				gint _tmp5_;
				GearyImapDBFolderLocationIdentifier* location = NULL;
				GeeList* _tmp6_;
				gpointer _tmp7_;
				GearyImapDBFolderLocationIdentifier* _tmp8_;
				GearyImapDBEmailIdentifier* _tmp9_;
				_location_index = _location_index + 1;
				_tmp4_ = _location_index;
				_tmp5_ = _location_size;
				if (!(_tmp4_ < _tmp5_)) {
					break;
				}
				_tmp6_ = _location_list;
				_tmp7_ = gee_list_get (_tmp6_, _location_index);
				location = (GearyImapDBFolderLocationIdentifier*) _tmp7_;
				_tmp8_ = location;
				_tmp9_ = _tmp8_->email_id;
				gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_data73_->ids, GEE_TYPE_COLLECTION, GeeCollection), _tmp9_);
				_geary_imap_db_folder_location_identifier_unref0 (location);
			}
		}
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	_g_object_unref0 (locs);
	return result;
}

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

static void
geary_imap_db_folder_get_ids_async_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_)
{
	GearyImapDbFolderGetIdsAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_get_ids_async_co (_data_);
}

static gboolean
geary_imap_db_folder_get_ids_async_co (GearyImapDbFolderGetIdsAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data73_ = g_slice_new0 (Block73Data);
	_data_->_data73_->_ref_count_ = 1;
	_data_->_data73_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data73_->uids);
	_data_->_data73_->uids = _data_->uids;
	_data_->_data73_->flags = _data_->flags;
	_g_object_unref0 (_data_->_data73_->cancellable);
	_data_->_data73_->cancellable = _data_->cancellable;
	_data_->_data73_->_async_data_ = _data_;
	_data_->_tmp0_ = gee_hash_set_new (GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->_data73_->ids = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEE_TYPE_SET, GeeSet);
	_data_->_tmp1_ = _data_->self->priv->db;
	_data_->_tmp2_ = _data_->_data73_->cancellable;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp1_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda69__geary_db_transaction_method, _data_->_data73_, _data_->_tmp2_, geary_imap_db_folder_get_ids_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_);
		block73_data_unref (_data_->_data73_);
		_data_->_data73_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp4_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_data73_->ids, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp5_ = _data_->_tmp4_;
	if (_data_->_tmp5_ > 0) {
		_data_->_tmp3_ = _data_->_data73_->ids;
	} else {
		_data_->_tmp3_ = NULL;
	}
	_data_->_tmp6_ = _g_object_ref0 (_data_->_tmp3_);
	_data_->result = _data_->_tmp6_;
	block73_data_unref (_data_->_data73_);
	_data_->_data73_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_get_earliest_id_async (GearyImapDBFolder* self,
                                            GCancellable* cancellable,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_)
{
	GearyImapDbFolderGetEarliestIdAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderGetEarliestIdAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_get_earliest_id_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_db_folder_get_earliest_id_async_co (_data_);
}

GearyImapDBEmailIdentifier*
geary_imap_db_folder_get_earliest_id_finish (GearyImapDBFolder* self,
                                             GAsyncResult* _res_,
                                             GError** error)
{
	GearyImapDBEmailIdentifier* result;
	GearyImapDbFolderGetEarliestIdAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
geary_imap_db_folder_get_earliest_id_async_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_)
{
	GearyImapDbFolderGetEarliestIdAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_get_earliest_id_async_co (_data_);
}

static gboolean
geary_imap_db_folder_get_earliest_id_async_co (GearyImapDbFolderGetEarliestIdAsyncData* _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_imap_db_folder_get_id_extremes_async (_data_->self, TRUE, _data_->cancellable, geary_imap_db_folder_get_earliest_id_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp1_ = geary_imap_db_folder_get_id_extremes_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp0_ = _data_->_tmp1_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp2_ = _data_->_tmp0_;
	_data_->_tmp0_ = NULL;
	_data_->result = _data_->_tmp2_;
	_g_object_unref0 (_data_->_tmp0_);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_get_latest_id_async (GearyImapDBFolder* self,
                                          GCancellable* cancellable,
                                          GAsyncReadyCallback _callback_,
                                          gpointer _user_data_)
{
	GearyImapDbFolderGetLatestIdAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderGetLatestIdAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_get_latest_id_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_db_folder_get_latest_id_async_co (_data_);
}

GearyImapDBEmailIdentifier*
geary_imap_db_folder_get_latest_id_finish (GearyImapDBFolder* self,
                                           GAsyncResult* _res_,
                                           GError** error)
{
	GearyImapDBEmailIdentifier* result;
	GearyImapDbFolderGetLatestIdAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
geary_imap_db_folder_get_latest_id_async_ready (GObject* source_object,
                                                GAsyncResult* _res_,
                                                gpointer _user_data_)
{
	GearyImapDbFolderGetLatestIdAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_get_latest_id_async_co (_data_);
}

static gboolean
geary_imap_db_folder_get_latest_id_async_co (GearyImapDbFolderGetLatestIdAsyncData* _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_imap_db_folder_get_id_extremes_async (_data_->self, FALSE, _data_->cancellable, geary_imap_db_folder_get_latest_id_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp1_ = geary_imap_db_folder_get_id_extremes_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp0_ = _data_->_tmp1_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp2_ = _data_->_tmp0_;
	_data_->_tmp0_ = NULL;
	_data_->result = _data_->_tmp2_;
	_g_object_unref0 (_data_->_tmp0_);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

static void
geary_imap_db_folder_get_id_extremes_async (GearyImapDBFolder* self,
                                            gboolean earliest,
                                            GCancellable* cancellable,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_)
{
	GearyImapDbFolderGetIdExtremesAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderGetIdExtremesAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_get_id_extremes_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->earliest = earliest;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_db_folder_get_id_extremes_async_co (_data_);
}

static GearyImapDBEmailIdentifier*
geary_imap_db_folder_get_id_extremes_finish (GearyImapDBFolder* self,
                                             GAsyncResult* _res_,
                                             GError** error)
{
	GearyImapDBEmailIdentifier* result;
	GearyImapDbFolderGetIdExtremesAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block74Data*
block74_data_ref (Block74Data* _data74_)
{
	g_atomic_int_inc (&_data74_->_ref_count_);
	return _data74_;
}

static void
block74_data_unref (void * _userdata_)
{
	Block74Data* _data74_;
	_data74_ = (Block74Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data74_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data74_->self;
		_g_object_unref0 (_data74_->id);
		_g_object_unref0 (_data74_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block74Data, _data74_);
	}
}

static GearyDbTransactionOutcome
__lambda70_ (Block74Data* _data74_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp6_;
	GearyDbStatement* _tmp7_;
	GearyDbStatement* _tmp8_;
	GearyDbResult* results = NULL;
	GearyDbStatement* _tmp9_;
	GearyDbResult* _tmp10_;
	gboolean _tmp11_ = FALSE;
	GearyDbResult* _tmp12_;
	gboolean _tmp13_;
	gboolean _tmp14_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data74_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	if (_data74_->earliest) {
		GearyDbStatement* _tmp0_ = NULL;
		GearyDbStatement* _tmp1_;
		GearyDbStatement* _tmp2_;
		_tmp1_ = geary_db_connection_prepare (cx, "SELECT MIN(ordering), message_id FROM MessageLocationTable WHERE folde" \
"r_id=?", &_inner_error0_);
		_tmp0_ = _tmp1_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp2_ = _tmp0_;
		_tmp0_ = NULL;
		_g_object_unref0 (stmt);
		stmt = _tmp2_;
		_g_object_unref0 (_tmp0_);
	} else {
		GearyDbStatement* _tmp3_ = NULL;
		GearyDbStatement* _tmp4_;
		GearyDbStatement* _tmp5_;
		_tmp4_ = geary_db_connection_prepare (cx, "SELECT MAX(ordering), message_id FROM MessageLocationTable WHERE folde" \
"r_id=?", &_inner_error0_);
		_tmp3_ = _tmp4_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp5_ = _tmp3_;
		_tmp3_ = NULL;
		_g_object_unref0 (stmt);
		stmt = _tmp5_;
		_g_object_unref0 (_tmp3_);
	}
	_tmp6_ = stmt;
	_tmp7_ = geary_db_statement_bind_rowid (_tmp6_, 0, self->priv->folder_id, &_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 0;
	}
	_tmp9_ = stmt;
	_tmp10_ = geary_db_statement_exec (_tmp9_, _data74_->cancellable, &_inner_error0_);
	results = _tmp10_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp12_ = results;
	_tmp13_ = geary_db_result_get_finished (_tmp12_);
	_tmp14_ = _tmp13_;
	if (!_tmp14_) {
		gboolean _tmp15_ = FALSE;
		GearyDbResult* _tmp16_;
		_tmp16_ = results;
		_tmp15_ = geary_db_result_is_null_at (_tmp16_, 0, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp11_ = !_tmp15_;
	} else {
		_tmp11_ = FALSE;
	}
	if (_tmp11_) {
		gint64 _tmp17_ = 0LL;
		GearyDbResult* _tmp18_;
		gint64 _tmp19_ = 0LL;
		GearyDbResult* _tmp20_;
		GearyImapUID* _tmp21_;
		GearyImapUID* _tmp22_;
		GearyImapDBEmailIdentifier* _tmp23_;
		_tmp18_ = results;
		_tmp17_ = geary_db_result_rowid_at (_tmp18_, 1, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp20_ = results;
		_tmp19_ = geary_db_result_int64_at (_tmp20_, 0, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp21_ = geary_imap_uid_new (_tmp19_);
		_tmp22_ = _tmp21_;
		_tmp23_ = geary_imap_db_email_identifier_new (_tmp17_, _tmp22_);
		_g_object_unref0 (_data74_->id);
		_data74_->id = _tmp23_;
		_g_object_unref0 (_tmp22_);
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	_g_object_unref0 (results);
	_g_object_unref0 (stmt);
	return result;
}

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

static void
geary_imap_db_folder_get_id_extremes_async_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_)
{
	GearyImapDbFolderGetIdExtremesAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_get_id_extremes_async_co (_data_);
}

static gboolean
geary_imap_db_folder_get_id_extremes_async_co (GearyImapDbFolderGetIdExtremesAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data74_ = g_slice_new0 (Block74Data);
	_data_->_data74_->_ref_count_ = 1;
	_data_->_data74_->self = g_object_ref (_data_->self);
	_data_->_data74_->earliest = _data_->earliest;
	_g_object_unref0 (_data_->_data74_->cancellable);
	_data_->_data74_->cancellable = _data_->cancellable;
	_data_->_data74_->_async_data_ = _data_;
	_data_->_data74_->id = NULL;
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda70__geary_db_transaction_method, _data_->_data74_, _data_->_data74_->cancellable, geary_imap_db_folder_get_id_extremes_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_);
		block74_data_unref (_data_->_data74_);
		_data_->_data74_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp1_ = _g_object_ref0 (_data_->_data74_->id);
	_data_->result = _data_->_tmp1_;
	block74_data_unref (_data_->_data74_);
	_data_->_data74_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_detach_multiple_emails_async (GearyImapDBFolder* self,
                                                   GeeCollection* ids,
                                                   GCancellable* cancellable,
                                                   GAsyncReadyCallback _callback_,
                                                   gpointer _user_data_)
{
	GearyImapDbFolderDetachMultipleEmailsAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GeeCollection* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderDetachMultipleEmailsAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_detach_multiple_emails_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (ids);
	_g_object_unref0 (_data_->ids);
	_data_->ids = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_folder_detach_multiple_emails_async_co (_data_);
}

void
geary_imap_db_folder_detach_multiple_emails_finish (GearyImapDBFolder* self,
                                                    GAsyncResult* _res_,
                                                    GError** error)
{
	GearyImapDbFolderDetachMultipleEmailsAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static Block75Data*
block75_data_ref (Block75Data* _data75_)
{
	g_atomic_int_inc (&_data75_->_ref_count_);
	return _data75_;
}

static void
block75_data_unref (void * _userdata_)
{
	Block75Data* _data75_;
	_data75_ = (Block75Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data75_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data75_->self;
		_g_object_unref0 (_data75_->ids);
		_g_object_unref0 (_data75_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block75Data, _data75_);
	}
}

static GearyDbTransactionOutcome
__lambda71_ (Block75Data* _data75_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GeeList* locs = NULL;
	GeeList* _tmp0_;
	gboolean _tmp1_ = FALSE;
	GeeList* _tmp2_;
	gint _tmp6_ = 0;
	GString* sql = NULL;
	GString* _tmp7_;
	GeeIterator* iter = NULL;
	GeeList* _tmp8_;
	GeeIterator* _tmp9_;
	GString* _tmp19_;
	GearyDbStatement* stmt = NULL;
	GString* _tmp20_;
	const gchar* _tmp21_;
	GearyDbStatement* _tmp22_;
	GearyDbStatement* _tmp23_;
	GearyDbStatement* _tmp24_;
	GearyDbStatement* _tmp25_;
	GearyDbStatement* _tmp26_;
	GearyDbResult* _tmp27_;
	GearyDbResult* _tmp28_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data75_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_imap_db_folder_do_get_locations_for_ids (self, cx, _data75_->ids, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDE_MARKED_FOR_REMOVE, _data75_->cancellable, &_inner_error0_);
	locs = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp2_ = locs;
	if (_tmp2_ == NULL) {
		_tmp1_ = TRUE;
	} else {
		GeeList* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		_tmp3_ = locs;
		_tmp4_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, GEE_TYPE_COLLECTION, GeeCollection));
		_tmp5_ = _tmp4_;
		_tmp1_ = _tmp5_ == 0;
	}
	if (_tmp1_) {
		result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
		_g_object_unref0 (locs);
		return result;
	}
	_tmp6_ = geary_imap_db_folder_do_get_unread_count_for_ids (self, cx, _data75_->ids, _data75_->cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (locs);
		return 0;
	}
	_data75_->unread_count = _tmp6_;
	geary_imap_db_folder_do_add_to_unread_count (self, cx, -_data75_->unread_count, _data75_->cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (locs);
		return 0;
	}
	_tmp7_ = g_string_new ("\n" \
"                DELETE FROM MessageLocationTable WHERE message_id IN (" \
"\n" \
"            ");
	sql = _tmp7_;
	_tmp8_ = locs;
	_tmp9_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, GEE_TYPE_ITERABLE, GeeIterable));
	iter = _tmp9_;
	while (TRUE) {
		GeeIterator* _tmp10_;
		GString* _tmp11_;
		GeeIterator* _tmp12_;
		gpointer _tmp13_;
		GearyImapDBFolderLocationIdentifier* _tmp14_;
		gchar* _tmp15_;
		gchar* _tmp16_;
		GeeIterator* _tmp17_;
		_tmp10_ = iter;
		if (!gee_iterator_next (_tmp10_)) {
			break;
		}
		_tmp11_ = sql;
		_tmp12_ = iter;
		_tmp13_ = gee_iterator_get (_tmp12_);
		_tmp14_ = (GearyImapDBFolderLocationIdentifier*) _tmp13_;
		_tmp15_ = g_strdup_printf ("%" G_GINT64_FORMAT, _tmp14_->message_id);
		_tmp16_ = _tmp15_;
		g_string_append_printf (_tmp11_, "%s", _tmp16_);
		_g_free0 (_tmp16_);
		_geary_imap_db_folder_location_identifier_unref0 (_tmp14_);
		_tmp17_ = iter;
		if (gee_iterator_has_next (_tmp17_)) {
			GString* _tmp18_;
			_tmp18_ = sql;
			g_string_append (_tmp18_, ", ");
		}
	}
	_tmp19_ = sql;
	g_string_append (_tmp19_, ") AND folder_id=?");
	_tmp20_ = sql;
	_tmp21_ = _tmp20_->str;
	_tmp22_ = geary_db_connection_prepare (cx, _tmp21_, &_inner_error0_);
	stmt = _tmp22_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (iter);
		_g_string_free0 (sql);
		_g_object_unref0 (locs);
		return 0;
	}
	_tmp23_ = stmt;
	_tmp24_ = geary_db_statement_bind_rowid (_tmp23_, 0, self->priv->folder_id, &_inner_error0_);
	_tmp25_ = _tmp24_;
	_g_object_unref0 (_tmp25_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_object_unref0 (iter);
		_g_string_free0 (sql);
		_g_object_unref0 (locs);
		return 0;
	}
	_tmp26_ = stmt;
	_tmp27_ = geary_db_statement_exec (_tmp26_, _data75_->cancellable, &_inner_error0_);
	_tmp28_ = _tmp27_;
	_g_object_unref0 (_tmp28_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_object_unref0 (iter);
		_g_string_free0 (sql);
		_g_object_unref0 (locs);
		return 0;
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_COMMIT;
	_g_object_unref0 (stmt);
	_g_object_unref0 (iter);
	_g_string_free0 (sql);
	_g_object_unref0 (locs);
	return result;
}

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

static void
geary_imap_db_folder_detach_multiple_emails_async_ready (GObject* source_object,
                                                         GAsyncResult* _res_,
                                                         gpointer _user_data_)
{
	GearyImapDbFolderDetachMultipleEmailsAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_detach_multiple_emails_async_co (_data_);
}

static gboolean
geary_imap_db_folder_detach_multiple_emails_async_co (GearyImapDbFolderDetachMultipleEmailsAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data75_ = g_slice_new0 (Block75Data);
	_data_->_data75_->_ref_count_ = 1;
	_data_->_data75_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data75_->ids);
	_data_->_data75_->ids = _data_->ids;
	_g_object_unref0 (_data_->_data75_->cancellable);
	_data_->_data75_->cancellable = _data_->cancellable;
	_data_->_data75_->_async_data_ = _data_;
	_data_->_data75_->unread_count = 0;
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_RW, ___lambda71__geary_db_transaction_method, _data_->_data75_, _data_->_data75_->cancellable, geary_imap_db_folder_detach_multiple_emails_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_);
		block75_data_unref (_data_->_data75_);
		_data_->_data75_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (_data_->_data75_->unread_count > 0) {
		_data_->_tmp1_ = _data_->self->priv->properties;
		_data_->_tmp2_ = _data_->self->priv->properties;
		_data_->_tmp3_ = geary_folder_properties_get_email_unread (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, GEARY_TYPE_FOLDER_PROPERTIES, GearyFolderProperties));
		_data_->_tmp4_ = _data_->_tmp3_;
		geary_imap_folder_properties_set_status_unseen (_data_->_tmp1_, _data_->_tmp4_ - _data_->_data75_->unread_count);
	}
	block75_data_unref (_data_->_data75_);
	_data_->_data75_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_detach_all_emails_async (GearyImapDBFolder* self,
                                              GCancellable* cancellable,
                                              GAsyncReadyCallback _callback_,
                                              gpointer _user_data_)
{
	GearyImapDbFolderDetachAllEmailsAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderDetachAllEmailsAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_detach_all_emails_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_db_folder_detach_all_emails_async_co (_data_);
}

void
geary_imap_db_folder_detach_all_emails_finish (GearyImapDBFolder* self,
                                               GAsyncResult* _res_,
                                               GError** error)
{
	GearyImapDbFolderDetachAllEmailsAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static Block76Data*
block76_data_ref (Block76Data* _data76_)
{
	g_atomic_int_inc (&_data76_->_ref_count_);
	return _data76_;
}

static void
block76_data_unref (void * _userdata_)
{
	Block76Data* _data76_;
	_data76_ = (Block76Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data76_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data76_->self;
		_g_object_unref0 (_data76_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block76Data, _data76_);
	}
}

static GearyDbTransactionOutcome
__lambda73_ (Block76Data* _data76_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp1_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbResult* _tmp5_;
	GearyDbResult* _tmp6_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data76_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_db_connection_prepare (cx, "DELETE FROM MessageLocationTable WHERE folder_id=?", &_inner_error0_);
	stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp1_ = stmt;
	_tmp2_ = geary_db_statement_bind_rowid (_tmp1_, 0, self->priv->folder_id, &_inner_error0_);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp3_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp4_ = stmt;
	_tmp5_ = geary_db_statement_exec (_tmp4_, _data76_->cancellable, &_inner_error0_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp6_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_COMMIT;
	_g_object_unref0 (stmt);
	return result;
}

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

static void
geary_imap_db_folder_detach_all_emails_async_ready (GObject* source_object,
                                                    GAsyncResult* _res_,
                                                    gpointer _user_data_)
{
	GearyImapDbFolderDetachAllEmailsAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_detach_all_emails_async_co (_data_);
}

static gboolean
geary_imap_db_folder_detach_all_emails_async_co (GearyImapDbFolderDetachAllEmailsAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data76_ = g_slice_new0 (Block76Data);
	_data_->_data76_->_ref_count_ = 1;
	_data_->_data76_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data76_->cancellable);
	_data_->_data76_->cancellable = _data_->cancellable;
	_data_->_data76_->_async_data_ = _data_;
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_WO, ___lambda73__geary_db_transaction_method, _data_->_data76_, _data_->_data76_->cancellable, geary_imap_db_folder_detach_all_emails_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_);
		block76_data_unref (_data_->_data76_);
		_data_->_data76_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	block76_data_unref (_data_->_data76_);
	_data_->_data76_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

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

void
geary_imap_db_folder_detach_emails_before_timestamp (GearyImapDBFolder* self,
                                                     GDateTime* cutoff,
                                                     GCancellable* cancellable,
                                                     GAsyncReadyCallback _callback_,
                                                     gpointer _user_data_)
{
	GearyImapDbFolderDetachEmailsBeforeTimestampData* _data_;
	GearyImapDBFolder* _tmp0_;
	GDateTime* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (cutoff != NULL);
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderDetachEmailsBeforeTimestampData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_detach_emails_before_timestamp_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_date_time_ref0 (cutoff);
	_g_date_time_unref0 (_data_->cutoff);
	_data_->cutoff = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_folder_detach_emails_before_timestamp_co (_data_);
}

GeeCollection*
geary_imap_db_folder_detach_emails_before_timestamp_finish (GearyImapDBFolder* self,
                                                            GAsyncResult* _res_,
                                                            GError** error)
{
	GeeCollection* result;
	GearyImapDbFolderDetachEmailsBeforeTimestampData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block77Data*
block77_data_ref (Block77Data* _data77_)
{
	g_atomic_int_inc (&_data77_->_ref_count_);
	return _data77_;
}

static void
block77_data_unref (void * _userdata_)
{
	Block77Data* _data77_;
	_data77_ = (Block77Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data77_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data77_->self;
		_g_object_unref0 (_data77_->deleted_primary_keys);
		_g_object_unref0 (_data77_->deleted_email_ids);
		_g_date_time_unref0 (_data77_->cutoff);
		_g_object_unref0 (_data77_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block77Data, _data77_);
	}
}

static gchar*
g_date_time_to_string (GDateTime* self)
{
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_date_time_format (self, "%FT%H:%M:%S%z");
	result = _tmp0_;
	return result;
}

static GearyDbTransactionOutcome
__lambda74_ (Block77Data* _data77_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GString* sql = NULL;
	GString* _tmp0_;
	GString* _tmp1_;
	GearyDbStatement* stmt = NULL;
	GString* _tmp2_;
	const gchar* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbStatement* _tmp5_;
	GearyDbStatement* _tmp6_;
	GearyDbStatement* _tmp7_;
	GearyDbStatement* _tmp8_;
	GearyDbStatement* _tmp9_;
	GearyDbStatement* _tmp10_;
	GearyDbResult* results = NULL;
	GearyDbStatement* _tmp11_;
	GearyDbResult* _tmp12_;
	gint64 found_within_threshold = 0LL;
	GearyDbResult* _tmp13_;
	gint64 extra_to_retain = 0LL;
	GString* _tmp14_;
	GString* _tmp15_;
	GearyDbStatement* _tmp16_ = NULL;
	GString* _tmp17_;
	const gchar* _tmp18_;
	GearyDbStatement* _tmp19_;
	GearyDbStatement* _tmp20_;
	GearyDbStatement* _tmp21_;
	GearyDbStatement* _tmp22_;
	GearyDbStatement* _tmp23_;
	GearyDbStatement* _tmp24_;
	GearyDbStatement* _tmp25_;
	GearyDbStatement* _tmp26_;
	GearyDbStatement* _tmp27_;
	GearyDbStatement* _tmp28_;
	GearyDbStatement* _tmp29_;
	GearyDbResult* _tmp30_ = NULL;
	GearyDbStatement* _tmp31_;
	GearyDbResult* _tmp32_;
	GearyDbResult* _tmp33_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data77_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = g_string_new ("");
	sql = _tmp0_;
	_tmp1_ = sql;
	g_string_append (_tmp1_, "\n" \
"                SELECT COUNT(*)\n" \
"                FROM MessageLocationTable\n" \
"                WHERE folder_id = ?\n" \
"                AND message_id IN (\n" \
"                    SELECT id\n" \
"                    FROM MessageTable\n" \
"                    INDEXED BY MessageTableInternalDateTimeTIndex\n" \
"                    WHERE internaldate_time_t >= ?\n" \
"                )\n" \
"            ");
	_tmp2_ = sql;
	_tmp3_ = _tmp2_->str;
	_tmp4_ = geary_db_connection_prepare (cx, _tmp3_, &_inner_error0_);
	stmt = _tmp4_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp5_ = stmt;
	_tmp6_ = geary_db_statement_bind_rowid (_tmp5_, 0, self->priv->folder_id, &_inner_error0_);
	_tmp7_ = _tmp6_;
	_g_object_unref0 (_tmp7_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp8_ = stmt;
	_tmp9_ = geary_db_statement_bind_int64 (_tmp8_, 1, g_date_time_to_unix (_data77_->cutoff), &_inner_error0_);
	_tmp10_ = _tmp9_;
	_g_object_unref0 (_tmp10_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp11_ = stmt;
	_tmp12_ = geary_db_statement_exec (_tmp11_, _data77_->cancellable, &_inner_error0_);
	results = _tmp12_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp13_ = results;
	found_within_threshold = geary_db_result_int64_at (_tmp13_, 0, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	extra_to_retain = CLAMP (GEARY_IMAP_DB_FOLDER_MINIMUM_MESSAGES_TO_RETAIN_DURING_GC - found_within_threshold, (gint64) 0, G_MAXINT64);
	_tmp14_ = g_string_new ("");
	_g_string_free0 (sql);
	sql = _tmp14_;
	_tmp15_ = sql;
	g_string_append (_tmp15_, "\n" \
"                SELECT ml.id, ml.message_id, ml.ordering\n" \
"                FROM MessageLocationTable ml\n" \
"                INNER JOIN MessageTable m\n" \
"                INDEXED BY MessageTableInternalDateTimeTIndex\n" \
"                    ON ml.message_id = m.id\n" \
"                WHERE ml.folder_id = ?\n" \
"                AND m.internaldate_time_t < ?\n" \
"                ORDER BY m.internaldate_time_t DESC\n" \
"                LIMIT -1 OFFSET ?;\n" \
"            ");
	_tmp17_ = sql;
	_tmp18_ = _tmp17_->str;
	_tmp19_ = geary_db_connection_prepare (cx, _tmp18_, &_inner_error0_);
	_tmp16_ = _tmp19_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp20_ = _tmp16_;
	_tmp16_ = NULL;
	_g_object_unref0 (stmt);
	stmt = _tmp20_;
	_tmp21_ = stmt;
	_tmp22_ = geary_db_statement_bind_rowid (_tmp21_, 0, self->priv->folder_id, &_inner_error0_);
	_tmp23_ = _tmp22_;
	_g_object_unref0 (_tmp23_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp16_);
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp24_ = stmt;
	_tmp25_ = geary_db_statement_bind_int64 (_tmp24_, 1, g_date_time_to_unix (_data77_->cutoff), &_inner_error0_);
	_tmp26_ = _tmp25_;
	_g_object_unref0 (_tmp26_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp16_);
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp27_ = stmt;
	_tmp28_ = geary_db_statement_bind_int64 (_tmp27_, 2, extra_to_retain, &_inner_error0_);
	_tmp29_ = _tmp28_;
	_g_object_unref0 (_tmp29_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp16_);
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp31_ = stmt;
	_tmp32_ = geary_db_statement_exec (_tmp31_, _data77_->cancellable, &_inner_error0_);
	_tmp30_ = _tmp32_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp16_);
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp33_ = _tmp30_;
	_tmp30_ = NULL;
	_g_object_unref0 (results);
	results = _tmp33_;
	while (TRUE) {
		GearyDbResult* _tmp34_;
		gboolean _tmp35_;
		gboolean _tmp36_;
		GeeArrayList* _tmp37_;
		gint64 _tmp40_ = 0LL;
		GearyDbResult* _tmp41_;
		gint64 _tmp42_ = 0LL;
		GearyDbResult* _tmp43_;
		GeeArrayList* _tmp44_;
		GearyImapUID* _tmp45_;
		GearyImapUID* _tmp46_;
		GearyImapDBEmailIdentifier* _tmp47_;
		GearyImapDBEmailIdentifier* _tmp48_;
		gint64 _tmp49_ = 0LL;
		GearyDbResult* _tmp50_;
		GeeArrayList* _tmp51_;
		gchar* _tmp52_;
		gchar* _tmp53_;
		GearyDbResult* _tmp54_;
		_tmp34_ = results;
		_tmp35_ = geary_db_result_get_finished (_tmp34_);
		_tmp36_ = _tmp35_;
		if (!(!_tmp36_)) {
			break;
		}
		_tmp37_ = _data77_->deleted_email_ids;
		if (_tmp37_ == NULL) {
			GeeArrayList* _tmp38_;
			GeeArrayList* _tmp39_;
			_tmp38_ = gee_array_list_new (GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
			_g_object_unref0 (_data77_->deleted_email_ids);
			_data77_->deleted_email_ids = _tmp38_;
			_tmp39_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
			_g_object_unref0 (_data77_->deleted_primary_keys);
			_data77_->deleted_primary_keys = _tmp39_;
		}
		_tmp41_ = results;
		_tmp40_ = geary_db_result_int64_at (_tmp41_, 1, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (_tmp30_);
			_g_object_unref0 (_tmp16_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			_g_string_free0 (sql);
			return 0;
		}
		_tmp43_ = results;
		_tmp42_ = geary_db_result_int64_at (_tmp43_, 2, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (_tmp30_);
			_g_object_unref0 (_tmp16_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			_g_string_free0 (sql);
			return 0;
		}
		_tmp44_ = _data77_->deleted_email_ids;
		_tmp45_ = geary_imap_uid_new (_tmp42_);
		_tmp46_ = _tmp45_;
		_tmp47_ = geary_imap_db_email_identifier_new (_tmp40_, _tmp46_);
		_tmp48_ = _tmp47_;
		gee_abstract_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp44_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection), _tmp48_);
		_g_object_unref0 (_tmp48_);
		_g_object_unref0 (_tmp46_);
		_tmp50_ = results;
		_tmp49_ = geary_db_result_rowid_at (_tmp50_, 0, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (_tmp30_);
			_g_object_unref0 (_tmp16_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			_g_string_free0 (sql);
			return 0;
		}
		_tmp51_ = _data77_->deleted_primary_keys;
		_tmp52_ = g_strdup_printf ("%" G_GINT64_FORMAT, _tmp49_);
		_tmp53_ = _tmp52_;
		gee_abstract_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp51_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection), _tmp53_);
		_g_free0 (_tmp53_);
		_tmp54_ = results;
		geary_db_result_next (_tmp54_, _data77_->cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (_tmp30_);
			_g_object_unref0 (_tmp16_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			_g_string_free0 (sql);
			return 0;
		}
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	_g_object_unref0 (_tmp30_);
	_g_object_unref0 (_tmp16_);
	_g_object_unref0 (results);
	_g_object_unref0 (stmt);
	_g_string_free0 (sql);
	return result;
}

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

static void
geary_imap_db_folder_detach_emails_before_timestamp_ready (GObject* source_object,
                                                           GAsyncResult* _res_,
                                                           gpointer _user_data_)
{
	GearyImapDbFolderDetachEmailsBeforeTimestampData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_detach_emails_before_timestamp_co (_data_);
}

static Block78Data*
block78_data_ref (Block78Data* _data78_)
{
	g_atomic_int_inc (&_data78_->_ref_count_);
	return _data78_;
}

static void
block78_data_unref (void * _userdata_)
{
	Block78Data* _data78_;
	_data78_ = (Block78Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data78_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data78_->_data77_->self;
		_g_string_free0 (_data78_->message_ids_sql_sublist);
		_g_string_free0 (_data78_->message_location_ids_sql_sublist);
		block77_data_unref (_data78_->_data77_);
		_data78_->_data77_ = NULL;
		g_slice_free (Block78Data, _data78_);
	}
}

static GearyDbTransactionOutcome
____lambda75_ (Block78Data* _data78_,
               GearyDbConnection* cx,
               GError** error)
{
	Block77Data* _data77_;
	GearyImapDBFolder* self;
	GString* sql = NULL;
	GString* _tmp0_;
	GString* _tmp1_;
	GString* _tmp2_;
	GString* _tmp3_;
	const gchar* _tmp4_;
	GString* _tmp5_;
	GearyDbStatement* stmt = NULL;
	GString* _tmp6_;
	const gchar* _tmp7_;
	GearyDbStatement* _tmp8_;
	GearyDbStatement* _tmp9_;
	GearyDbResult* _tmp10_;
	GearyDbResult* _tmp11_;
	GString* _tmp12_;
	GString* _tmp13_;
	GString* _tmp14_;
	GString* _tmp15_;
	const gchar* _tmp16_;
	GString* _tmp17_;
	GearyDbStatement* _tmp18_ = NULL;
	GString* _tmp19_;
	const gchar* _tmp20_;
	GearyDbStatement* _tmp21_;
	GearyDbStatement* _tmp22_;
	GearyDbStatement* _tmp23_;
	GearyDbResult* _tmp24_;
	GearyDbResult* _tmp25_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	_data77_ = _data78_->_data77_;
	self = _data77_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = g_string_new ("");
	sql = _tmp0_;
	_tmp1_ = sql;
	g_string_append (_tmp1_, "\n" \
"                        DELETE FROM MessageLocationTable\n" \
"                        WHERE id IN (\n" \
"                    ");
	_tmp2_ = sql;
	_tmp3_ = _data78_->message_location_ids_sql_sublist;
	_tmp4_ = _tmp3_->str;
	g_string_append (_tmp2_, _tmp4_);
	_tmp5_ = sql;
	g_string_append (_tmp5_, ")");
	_tmp6_ = sql;
	_tmp7_ = _tmp6_->str;
	_tmp8_ = geary_db_connection_prepare (cx, _tmp7_, &_inner_error0_);
	stmt = _tmp8_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp9_ = stmt;
	_tmp10_ = geary_db_statement_exec (_tmp9_, _data77_->cancellable, &_inner_error0_);
	_tmp11_ = _tmp10_;
	_g_object_unref0 (_tmp11_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp12_ = g_string_new ("");
	_g_string_free0 (sql);
	sql = _tmp12_;
	_tmp13_ = sql;
	g_string_append (_tmp13_, "\n" \
"                        DELETE FROM MessageSearchTable\n" \
"                        WHERE rowid IN (\n" \
"                    ");
	_tmp14_ = sql;
	_tmp15_ = _data78_->message_ids_sql_sublist;
	_tmp16_ = _tmp15_->str;
	g_string_append (_tmp14_, _tmp16_);
	_tmp17_ = sql;
	g_string_append (_tmp17_, ")");
	_tmp19_ = sql;
	_tmp20_ = _tmp19_->str;
	_tmp21_ = geary_db_connection_prepare (cx, _tmp20_, &_inner_error0_);
	_tmp18_ = _tmp21_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp22_ = _tmp18_;
	_tmp18_ = NULL;
	_g_object_unref0 (stmt);
	stmt = _tmp22_;
	_tmp23_ = stmt;
	_tmp24_ = geary_db_statement_exec (_tmp23_, _data77_->cancellable, &_inner_error0_);
	_tmp25_ = _tmp24_;
	_g_object_unref0 (_tmp25_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp18_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_COMMIT;
	_g_object_unref0 (_tmp18_);
	_g_object_unref0 (stmt);
	_g_string_free0 (sql);
	return result;
}

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

static gboolean
geary_imap_db_folder_detach_emails_before_timestamp_co (GearyImapDbFolderDetachEmailsBeforeTimestampData* _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_->_data77_ = g_slice_new0 (Block77Data);
	_data_->_data77_->_ref_count_ = 1;
	_data_->_data77_->self = g_object_ref (_data_->self);
	_g_date_time_unref0 (_data_->_data77_->cutoff);
	_data_->_data77_->cutoff = _data_->cutoff;
	_g_object_unref0 (_data_->_data77_->cancellable);
	_data_->_data77_->cancellable = _data_->cancellable;
	_data_->_data77_->_async_data_ = _data_;
	_data_->_tmp0_ = g_date_time_to_string (_data_->_data77_->cutoff);
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = g_strdup_printf ("%" G_GINT64_FORMAT, _data_->self->priv->folder_id);
	_data_->_tmp3_ = _data_->_tmp2_;
	g_debug ("imap-db-folder.vala:941: Detaching emails before %s for folder ID %s", _data_->_tmp1_, _data_->_tmp3_);
	_g_free0 (_data_->_tmp3_);
	_g_free0 (_data_->_tmp1_);
	_data_->_data77_->deleted_email_ids = NULL;
	_data_->_data77_->deleted_primary_keys = NULL;
	_data_->_tmp4_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp4_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda74__geary_db_transaction_method, _data_->_data77_, _data_->_data77_->cancellable, geary_imap_db_folder_detach_emails_before_timestamp_ready, _data_);
	return FALSE;
	_state_1:
	geary_db_database_exec_transaction_finish (_data_->_tmp4_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block77_data_unref (_data_->_data77_);
		_data_->_data77_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp5_ = _data_->_data77_->deleted_email_ids;
	if (_data_->_tmp5_ != NULL) {
		_data_->delete_index = 0;
		while (TRUE) {
			_data_->_data78_ = g_slice_new0 (Block78Data);
			_data_->_data78_->_ref_count_ = 1;
			_data_->_data78_->_data77_ = block77_data_ref (_data_->_data77_);
			_data_->_tmp6_ = _data_->_data77_->deleted_primary_keys;
			_data_->_tmp7_ = gee_abstract_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp6_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection));
			_data_->_tmp8_ = _data_->_tmp7_;
			if (!(_data_->delete_index < _data_->_tmp8_)) {
				block78_data_unref (_data_->_data78_);
				_data_->_data78_ = NULL;
				break;
			}
			_data_->batch_counter = 0;
			_data_->_tmp9_ = g_string_new ("");
			_data_->_data78_->message_location_ids_sql_sublist = _data_->_tmp9_;
			_data_->_tmp10_ = g_string_new ("");
			_data_->_data78_->message_ids_sql_sublist = _data_->_tmp10_;
			while (TRUE) {
				_data_->_tmp12_ = _data_->_data77_->deleted_primary_keys;
				_data_->_tmp13_ = gee_abstract_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp12_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection));
				_data_->_tmp14_ = _data_->_tmp13_;
				if (_data_->delete_index < _data_->_tmp14_) {
					_data_->_tmp11_ = _data_->batch_counter < GEARY_IMAP_DB_FOLDER_OLD_MSG_DETACH_BATCH_SIZE;
				} else {
					_data_->_tmp11_ = FALSE;
				}
				if (!_data_->_tmp11_) {
					break;
				}
				if (_data_->batch_counter > 0) {
					_data_->_tmp15_ = _data_->_data78_->message_location_ids_sql_sublist;
					g_string_append (_data_->_tmp15_, ",");
					_data_->_tmp16_ = _data_->_data78_->message_ids_sql_sublist;
					g_string_append (_data_->_tmp16_, ",");
				}
				_data_->_tmp17_ = _data_->_data78_->message_location_ids_sql_sublist;
				_data_->_tmp18_ = _data_->_data77_->deleted_primary_keys;
				_data_->_tmp19_ = gee_abstract_list_get (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp18_, GEE_TYPE_ABSTRACT_LIST, GeeAbstractList), _data_->delete_index);
				_data_->_tmp20_ = (gchar*) _data_->_tmp19_;
				g_string_append (_data_->_tmp17_, _data_->_tmp20_);
				_g_free0 (_data_->_tmp20_);
				_data_->_tmp21_ = _data_->_data78_->message_ids_sql_sublist;
				_data_->_tmp22_ = _data_->_data77_->deleted_email_ids;
				_data_->_tmp23_ = gee_abstract_list_get (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp22_, GEE_TYPE_ABSTRACT_LIST, GeeAbstractList), _data_->delete_index);
				_data_->_tmp24_ = (GearyImapDBEmailIdentifier*) _data_->_tmp23_;
				_data_->_tmp25_ = geary_imap_db_email_identifier_get_message_id (_data_->_tmp24_);
				_data_->_tmp26_ = _data_->_tmp25_;
				_data_->_tmp27_ = g_strdup_printf ("%" G_GINT64_FORMAT, _data_->_tmp26_);
				_data_->_tmp28_ = _data_->_tmp27_;
				g_string_append (_data_->_tmp21_, _data_->_tmp28_);
				_g_free0 (_data_->_tmp28_);
				_g_object_unref0 (_data_->_tmp24_);
				_data_->_tmp29_ = _data_->delete_index;
				_data_->delete_index = _data_->_tmp29_ + 1;
				_data_->_tmp30_ = _data_->batch_counter;
				_data_->batch_counter = _data_->_tmp30_ + 1;
			}
			_data_->_tmp31_ = _data_->self->priv->db;
			_data_->_state_ = 2;
			geary_db_database_exec_transaction_async (_data_->_tmp31_, GEARY_DB_TRANSACTION_TYPE_WO, _____lambda75__geary_db_transaction_method, _data_->_data78_, _data_->_data77_->cancellable, geary_imap_db_folder_detach_emails_before_timestamp_ready, _data_);
			return FALSE;
			_state_2:
			geary_db_database_exec_transaction_finish (_data_->_tmp31_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
				block78_data_unref (_data_->_data78_);
				_data_->_data78_ = NULL;
				block77_data_unref (_data_->_data77_);
				_data_->_data77_ = NULL;
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
			block78_data_unref (_data_->_data78_);
			_data_->_data78_ = NULL;
		}
	}
	_data_->_tmp32_ = _data_->_data77_->deleted_email_ids;
	_data_->_tmp33_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp32_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->result = _data_->_tmp33_;
	block77_data_unref (_data_->_data77_);
	_data_->_data77_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_mark_email_async (GearyImapDBFolder* self,
                                       GeeCollection* to_mark,
                                       GearyEmailFlags* flags_to_add,
                                       GearyEmailFlags* flags_to_remove,
                                       GCancellable* cancellable,
                                       GAsyncReadyCallback _callback_,
                                       gpointer _user_data_)
{
	GearyImapDbFolderMarkEmailAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GeeCollection* _tmp1_;
	GearyEmailFlags* _tmp2_;
	GearyEmailFlags* _tmp3_;
	GCancellable* _tmp4_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	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 (GearyImapDbFolderMarkEmailAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_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_imap_db_folder_mark_email_async_co (_data_);
}

void
geary_imap_db_folder_mark_email_finish (GearyImapDBFolder* self,
                                        GAsyncResult* _res_,
                                        GError** error)
{
	GearyImapDbFolderMarkEmailAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static Block79Data*
block79_data_ref (Block79Data* _data79_)
{
	g_atomic_int_inc (&_data79_->_ref_count_);
	return _data79_;
}

static void
block79_data_unref (void * _userdata_)
{
	Block79Data* _data79_;
	_data79_ = (Block79Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data79_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data79_->self;
		_g_object_unref0 (_data79_->unread_status);
		_g_object_unref0 (_data79_->to_mark);
		_g_object_unref0 (_data79_->flags_to_add);
		_g_object_unref0 (_data79_->flags_to_remove);
		_g_object_unref0 (self);
		g_slice_free (Block79Data, _data79_);
	}
}

static GearyDbTransactionOutcome
__lambda76_ (Block79Data* _data79_,
             GearyDbConnection* cx,
             GCancellable* cancellable,
             GError** error)
{
	GearyImapDBFolder* self;
	GeeMap* map = NULL;
	GeeMap* _tmp0_;
	GeeMap* _tmp1_;
	GeeMap* _tmp50_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data79_->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);
	_tmp0_ = geary_imap_db_folder_do_get_email_flags (self, cx, _data79_->to_mark, cancellable, &_inner_error0_);
	map = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp1_ = map;
	if (_tmp1_ == NULL) {
		result = GEARY_DB_TRANSACTION_OUTCOME_COMMIT;
		_g_object_unref0 (map);
		return result;
	}
	{
		GeeIterator* _id_it = NULL;
		GeeMap* _tmp2_;
		GeeSet* _tmp3_;
		GeeSet* _tmp4_;
		GeeSet* _tmp5_;
		GeeIterator* _tmp6_;
		GeeIterator* _tmp7_;
		_tmp2_ = map;
		_tmp3_ = gee_map_get_keys (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp5_ = _tmp4_;
		_tmp6_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, GEE_TYPE_ITERABLE, GeeIterable));
		_tmp7_ = _tmp6_;
		_g_object_unref0 (_tmp5_);
		_id_it = _tmp7_;
		while (TRUE) {
			GeeIterator* _tmp8_;
			GearyImapDBEmailIdentifier* id = NULL;
			GeeIterator* _tmp9_;
			gpointer _tmp10_;
			GearyImapEmailFlags* flags = NULL;
			GeeMap* _tmp11_;
			GearyImapDBEmailIdentifier* _tmp12_;
			gpointer _tmp13_;
			_tmp8_ = _id_it;
			if (!gee_iterator_next (_tmp8_)) {
				break;
			}
			_tmp9_ = _id_it;
			_tmp10_ = gee_iterator_get (_tmp9_);
			id = (GearyImapDBEmailIdentifier*) _tmp10_;
			_tmp11_ = map;
			_tmp12_ = id;
			_tmp13_ = gee_map_get (_tmp11_, _tmp12_);
			flags = G_TYPE_CHECK_INSTANCE_CAST ((GearyEmailFlags*) _tmp13_, GEARY_IMAP_TYPE_EMAIL_FLAGS, GearyImapEmailFlags);
			if (_data79_->flags_to_add != NULL) {
				{
					GeeIterator* _flag_it = NULL;
					GeeSet* _tmp14_;
					GeeSet* _tmp15_;
					GeeIterator* _tmp16_;
					GeeIterator* _tmp17_;
					_tmp14_ = geary_named_flags_get_all (G_TYPE_CHECK_INSTANCE_CAST (_data79_->flags_to_add, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags));
					_tmp15_ = _tmp14_;
					_tmp16_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp15_, GEE_TYPE_ITERABLE, GeeIterable));
					_tmp17_ = _tmp16_;
					_g_object_unref0 (_tmp15_);
					_flag_it = _tmp17_;
					while (TRUE) {
						GeeIterator* _tmp18_;
						GearyNamedFlag* flag = NULL;
						GeeIterator* _tmp19_;
						gpointer _tmp20_;
						GearyImapEmailFlags* _tmp21_;
						GearyNamedFlag* _tmp22_;
						GearyImapEmailFlags* _tmp23_;
						GearyNamedFlag* _tmp24_;
						GearyNamedFlag* _tmp25_;
						GearyNamedFlag* _tmp26_;
						GearyNamedFlag* _tmp27_;
						GearyNamedFlag* _tmp28_;
						gboolean _tmp29_;
						_tmp18_ = _flag_it;
						if (!gee_iterator_next (_tmp18_)) {
							break;
						}
						_tmp19_ = _flag_it;
						_tmp20_ = gee_iterator_get (_tmp19_);
						flag = (GearyNamedFlag*) _tmp20_;
						_tmp21_ = flags;
						_tmp22_ = flag;
						if (geary_named_flags_contains (G_TYPE_CHECK_INSTANCE_CAST (_tmp21_, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags), _tmp22_)) {
							_g_object_unref0 (flag);
							continue;
						}
						_tmp23_ = flags;
						_tmp24_ = flag;
						geary_named_flags_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp23_, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags), _tmp24_);
						_tmp25_ = flag;
						_tmp26_ = geary_email_flags_get_UNREAD ();
						_tmp27_ = _tmp26_;
						_tmp28_ = _tmp27_;
						_tmp29_ = gee_hashable_equal_to (G_TYPE_CHECK_INSTANCE_CAST (_tmp25_, GEE_TYPE_HASHABLE, GeeHashable), _tmp28_);
						_g_object_unref0 (_tmp28_);
						if (_tmp29_) {
							gint _tmp30_;
							GearyImapDBEmailIdentifier* _tmp31_;
							_tmp30_ = _data79_->unread_change;
							_data79_->unread_change = _tmp30_ + 1;
							_tmp31_ = id;
							gee_map_set (_data79_->unread_status, _tmp31_, (gpointer) ((gintptr) TRUE));
						}
						_g_object_unref0 (flag);
					}
					_g_object_unref0 (_flag_it);
				}
			}
			if (_data79_->flags_to_remove != NULL) {
				{
					GeeIterator* _flag_it = NULL;
					GeeSet* _tmp32_;
					GeeSet* _tmp33_;
					GeeIterator* _tmp34_;
					GeeIterator* _tmp35_;
					_tmp32_ = geary_named_flags_get_all (G_TYPE_CHECK_INSTANCE_CAST (_data79_->flags_to_remove, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags));
					_tmp33_ = _tmp32_;
					_tmp34_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp33_, GEE_TYPE_ITERABLE, GeeIterable));
					_tmp35_ = _tmp34_;
					_g_object_unref0 (_tmp33_);
					_flag_it = _tmp35_;
					while (TRUE) {
						GeeIterator* _tmp36_;
						GearyNamedFlag* flag = NULL;
						GeeIterator* _tmp37_;
						gpointer _tmp38_;
						GearyImapEmailFlags* _tmp39_;
						GearyNamedFlag* _tmp40_;
						GearyImapEmailFlags* _tmp41_;
						GearyNamedFlag* _tmp42_;
						GearyNamedFlag* _tmp43_;
						GearyNamedFlag* _tmp44_;
						GearyNamedFlag* _tmp45_;
						GearyNamedFlag* _tmp46_;
						gboolean _tmp47_;
						_tmp36_ = _flag_it;
						if (!gee_iterator_next (_tmp36_)) {
							break;
						}
						_tmp37_ = _flag_it;
						_tmp38_ = gee_iterator_get (_tmp37_);
						flag = (GearyNamedFlag*) _tmp38_;
						_tmp39_ = flags;
						_tmp40_ = flag;
						if (!geary_named_flags_contains (G_TYPE_CHECK_INSTANCE_CAST (_tmp39_, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags), _tmp40_)) {
							_g_object_unref0 (flag);
							continue;
						}
						_tmp41_ = flags;
						_tmp42_ = flag;
						geary_named_flags_remove (G_TYPE_CHECK_INSTANCE_CAST (_tmp41_, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags), _tmp42_);
						_tmp43_ = flag;
						_tmp44_ = geary_email_flags_get_UNREAD ();
						_tmp45_ = _tmp44_;
						_tmp46_ = _tmp45_;
						_tmp47_ = gee_hashable_equal_to (G_TYPE_CHECK_INSTANCE_CAST (_tmp43_, GEE_TYPE_HASHABLE, GeeHashable), _tmp46_);
						_g_object_unref0 (_tmp46_);
						if (_tmp47_) {
							gint _tmp48_;
							GearyImapDBEmailIdentifier* _tmp49_;
							_tmp48_ = _data79_->unread_change;
							_data79_->unread_change = _tmp48_ - 1;
							_tmp49_ = id;
							gee_map_set (_data79_->unread_status, _tmp49_, (gpointer) ((gintptr) FALSE));
						}
						_g_object_unref0 (flag);
					}
					_g_object_unref0 (_flag_it);
				}
			}
			_g_object_unref0 (flags);
			_g_object_unref0 (id);
		}
		_g_object_unref0 (_id_it);
	}
	_tmp50_ = map;
	geary_imap_db_folder_do_set_email_flags (self, cx, _tmp50_, cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (map);
		return 0;
	}
	geary_imap_db_folder_do_add_to_unread_count (self, cx, _data79_->unread_change, cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (map);
		return 0;
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_COMMIT;
	_g_object_unref0 (map);
	return result;
}

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

static void
geary_imap_db_folder_mark_email_async_ready (GObject* source_object,
                                             GAsyncResult* _res_,
                                             gpointer _user_data_)
{
	GearyImapDbFolderMarkEmailAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_mark_email_async_co (_data_);
}

static gboolean
geary_imap_db_folder_mark_email_async_co (GearyImapDbFolderMarkEmailAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data79_ = g_slice_new0 (Block79Data);
	_data_->_data79_->_ref_count_ = 1;
	_data_->_data79_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data79_->to_mark);
	_data_->_data79_->to_mark = _data_->to_mark;
	_g_object_unref0 (_data_->_data79_->flags_to_add);
	_data_->_data79_->flags_to_add = _data_->flags_to_add;
	_g_object_unref0 (_data_->_data79_->flags_to_remove);
	_data_->_data79_->flags_to_remove = _data_->flags_to_remove;
	_data_->_data79_->_async_data_ = _data_;
	_data_->_data79_->unread_change = 0;
	_data_->_tmp0_ = gee_hash_map_new (GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, G_TYPE_BOOLEAN, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->_data79_->unread_status = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEE_TYPE_MAP, GeeMap);
	_data_->_tmp1_ = _data_->self->priv->db;
	_data_->_tmp2_ = _data_->cancellable;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp1_, GEARY_DB_TRANSACTION_TYPE_RW, ___lambda76__geary_db_transaction_method, _data_->_data79_, _data_->_tmp2_, geary_imap_db_folder_mark_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_);
		block79_data_unref (_data_->_data79_);
		_data_->_data79_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp3_ = _data_->self->priv->properties;
	_data_->_tmp4_ = _data_->self->priv->properties;
	_data_->_tmp5_ = geary_folder_properties_get_email_unread (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp4_, GEARY_TYPE_FOLDER_PROPERTIES, GearyFolderProperties));
	_data_->_tmp6_ = _data_->_tmp5_;
	geary_imap_folder_properties_set_status_unseen (_data_->_tmp3_, CLAMP (_data_->_tmp6_ + _data_->_data79_->unread_change, 0, G_MAXINT));
	_data_->_tmp7_ = gee_map_get_size (_data_->_data79_->unread_status);
	_data_->_tmp8_ = _data_->_tmp7_;
	if (_data_->_tmp8_ > 0) {
		g_signal_emit (_data_->self, geary_imap_db_folder_signals[GEARY_IMAP_DB_FOLDER_UNREAD_UPDATED_SIGNAL], 0, _data_->_data79_->unread_status);
	}
	block79_data_unref (_data_->_data79_);
	_data_->_data79_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_get_email_uids_async (GearyImapDBFolder* self,
                                           GeeCollection* ids,
                                           GCancellable* cancellable,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_)
{
	GearyImapDbFolderGetEmailUidsAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GeeCollection* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderGetEmailUidsAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_get_email_uids_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (ids);
	_g_object_unref0 (_data_->ids);
	_data_->ids = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_folder_get_email_uids_async_co (_data_);
}

GeeList*
geary_imap_db_folder_get_email_uids_finish (GearyImapDBFolder* self,
                                            GAsyncResult* _res_,
                                            GError** error)
{
	GeeList* result;
	GearyImapDbFolderGetEmailUidsAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block80Data*
block80_data_ref (Block80Data* _data80_)
{
	g_atomic_int_inc (&_data80_->_ref_count_);
	return _data80_;
}

static void
block80_data_unref (void * _userdata_)
{
	Block80Data* _data80_;
	_data80_ = (Block80Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data80_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data80_->self;
		_g_object_unref0 (_data80_->uids);
		_g_object_unref0 (_data80_->ids);
		_g_object_unref0 (self);
		g_slice_free (Block80Data, _data80_);
	}
}

static GearyDbTransactionOutcome
__lambda77_ (Block80Data* _data80_,
             GearyDbConnection* cx,
             GCancellable* cancellable,
             GError** error)
{
	GearyImapDBFolder* self;
	GeeList* _tmp0_ = NULL;
	GeeList* _tmp1_;
	GeeList* _tmp2_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data80_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), 0);
	_tmp1_ = geary_imap_db_folder_do_get_email_uids (self, cx, _data80_->ids, cancellable, &_inner_error0_);
	_tmp0_ = _tmp1_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp2_ = _tmp0_;
	_tmp0_ = NULL;
	_g_object_unref0 (_data80_->uids);
	_data80_->uids = _tmp2_;
	result = GEARY_DB_TRANSACTION_OUTCOME_SUCCESS;
	_g_object_unref0 (_tmp0_);
	return result;
}

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

static void
geary_imap_db_folder_get_email_uids_async_ready (GObject* source_object,
                                                 GAsyncResult* _res_,
                                                 gpointer _user_data_)
{
	GearyImapDbFolderGetEmailUidsAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_get_email_uids_async_co (_data_);
}

static gboolean
geary_imap_db_folder_get_email_uids_async_co (GearyImapDbFolderGetEmailUidsAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data80_ = g_slice_new0 (Block80Data);
	_data_->_data80_->_ref_count_ = 1;
	_data_->_data80_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data80_->ids);
	_data_->_data80_->ids = _data_->ids;
	_data_->_data80_->_async_data_ = _data_;
	_data_->_data80_->uids = NULL;
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda77__geary_db_transaction_method, _data_->_data80_, _data_->cancellable, geary_imap_db_folder_get_email_uids_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_);
		block80_data_unref (_data_->_data80_);
		_data_->_data80_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp1_ = _g_object_ref0 (_data_->_data80_->uids);
	_data_->result = _data_->_tmp1_;
	block80_data_unref (_data_->_data80_);
	_data_->_data80_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_get_email_flags_async (GearyImapDBFolder* self,
                                            GeeCollection* ids,
                                            GCancellable* cancellable,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_)
{
	GearyImapDbFolderGetEmailFlagsAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GeeCollection* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderGetEmailFlagsAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_get_email_flags_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (ids);
	_g_object_unref0 (_data_->ids);
	_data_->ids = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_folder_get_email_flags_async_co (_data_);
}

GeeMap*
geary_imap_db_folder_get_email_flags_finish (GearyImapDBFolder* self,
                                             GAsyncResult* _res_,
                                             GError** error)
{
	GeeMap* result;
	GearyImapDbFolderGetEmailFlagsAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block81Data*
block81_data_ref (Block81Data* _data81_)
{
	g_atomic_int_inc (&_data81_->_ref_count_);
	return _data81_;
}

static void
block81_data_unref (void * _userdata_)
{
	Block81Data* _data81_;
	_data81_ = (Block81Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data81_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data81_->self;
		_g_object_unref0 (_data81_->map);
		_g_object_unref0 (_data81_->ids);
		_g_object_unref0 (self);
		g_slice_free (Block81Data, _data81_);
	}
}

static GearyDbTransactionOutcome
__lambda78_ (Block81Data* _data81_,
             GearyDbConnection* cx,
             GCancellable* cancellable,
             GError** error)
{
	GearyImapDBFolder* self;
	GeeMap* _tmp0_ = NULL;
	GeeMap* _tmp1_;
	GeeMap* _tmp2_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data81_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), 0);
	_tmp1_ = geary_imap_db_folder_do_get_email_flags (self, cx, _data81_->ids, cancellable, &_inner_error0_);
	_tmp0_ = _tmp1_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp2_ = _tmp0_;
	_tmp0_ = NULL;
	_g_object_unref0 (_data81_->map);
	_data81_->map = _tmp2_;
	result = GEARY_DB_TRANSACTION_OUTCOME_SUCCESS;
	_g_object_unref0 (_tmp0_);
	return result;
}

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

static void
geary_imap_db_folder_get_email_flags_async_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_)
{
	GearyImapDbFolderGetEmailFlagsAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_get_email_flags_async_co (_data_);
}

static gboolean
geary_imap_db_folder_get_email_flags_async_co (GearyImapDbFolderGetEmailFlagsAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data81_ = g_slice_new0 (Block81Data);
	_data_->_data81_->_ref_count_ = 1;
	_data_->_data81_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data81_->ids);
	_data_->_data81_->ids = _data_->ids;
	_data_->_data81_->_async_data_ = _data_;
	_data_->_data81_->map = NULL;
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda78__geary_db_transaction_method, _data_->_data81_, _data_->cancellable, geary_imap_db_folder_get_email_flags_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_);
		block81_data_unref (_data_->_data81_);
		_data_->_data81_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp1_ = _g_object_ref0 (_data_->_data81_->map);
	_data_->result = _data_->_tmp1_;
	block81_data_unref (_data_->_data81_);
	_data_->_data81_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_set_email_flags_async (GearyImapDBFolder* self,
                                            GeeMap* map,
                                            GCancellable* cancellable,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_)
{
	GearyImapDbFolderSetEmailFlagsAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GeeMap* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (map, GEE_TYPE_MAP));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderSetEmailFlagsAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_set_email_flags_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (map);
	_g_object_unref0 (_data_->map);
	_data_->map = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_folder_set_email_flags_async_co (_data_);
}

void
geary_imap_db_folder_set_email_flags_finish (GearyImapDBFolder* self,
                                             GAsyncResult* _res_,
                                             GError** error)
{
	GearyImapDbFolderSetEmailFlagsAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static Block82Data*
block82_data_ref (Block82Data* _data82_)
{
	g_atomic_int_inc (&_data82_->_ref_count_);
	return _data82_;
}

static void
block82_data_unref (void * _userdata_)
{
	Block82Data* _data82_;
	_data82_ = (Block82Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data82_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data82_->self;
		_g_object_unref0 (_data82_->map);
		_g_object_unref0 (self);
		g_slice_free (Block82Data, _data82_);
	}
}

static GearyDbTransactionOutcome
___lambda79_ (Block82Data* _data82_,
              GearyDbConnection* cx,
              GCancellable* cancellable,
              GError** error)
{
	GearyImapDBFolder* self;
	GeeMap* existing_map = NULL;
	GeeSet* _tmp0_;
	GeeSet* _tmp1_;
	GeeSet* _tmp2_;
	GeeMap* _tmp3_;
	GeeMap* _tmp4_;
	GeeMap* _tmp5_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data82_->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);
	_tmp0_ = gee_map_get_keys (_data82_->map);
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_;
	_tmp3_ = geary_imap_db_folder_do_get_email_flags (self, cx, G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, GEE_TYPE_COLLECTION, GeeCollection), cancellable, &_inner_error0_);
	_tmp4_ = _tmp3_;
	_g_object_unref0 (_tmp2_);
	existing_map = _tmp4_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp5_ = existing_map;
	if (_tmp5_ != NULL) {
		{
			GeeIterator* _id_it = NULL;
			GeeSet* _tmp6_;
			GeeSet* _tmp7_;
			GeeSet* _tmp8_;
			GeeIterator* _tmp9_;
			GeeIterator* _tmp10_;
			_tmp6_ = gee_map_get_keys (_data82_->map);
			_tmp7_ = _tmp6_;
			_tmp8_ = _tmp7_;
			_tmp9_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, GEE_TYPE_ITERABLE, GeeIterable));
			_tmp10_ = _tmp9_;
			_g_object_unref0 (_tmp8_);
			_id_it = _tmp10_;
			while (TRUE) {
				GeeIterator* _tmp11_;
				GearyImapDBEmailIdentifier* id = NULL;
				GeeIterator* _tmp12_;
				gpointer _tmp13_;
				GearyEmailFlags* existing_flags = NULL;
				GeeMap* _tmp14_;
				GearyImapDBEmailIdentifier* _tmp15_;
				gpointer _tmp16_;
				GearyEmailFlags* _tmp17_;
				GearyEmailFlags* new_flags = NULL;
				GearyImapDBEmailIdentifier* _tmp18_;
				gpointer _tmp19_;
				gboolean _tmp20_ = FALSE;
				GearyEmailFlags* _tmp21_;
				GearyNamedFlag* _tmp22_;
				GearyNamedFlag* _tmp23_;
				GearyNamedFlag* _tmp24_;
				gboolean _tmp25_;
				_tmp11_ = _id_it;
				if (!gee_iterator_next (_tmp11_)) {
					break;
				}
				_tmp12_ = _id_it;
				_tmp13_ = gee_iterator_get (_tmp12_);
				id = (GearyImapDBEmailIdentifier*) _tmp13_;
				_tmp14_ = existing_map;
				_tmp15_ = id;
				_tmp16_ = gee_map_get (_tmp14_, _tmp15_);
				existing_flags = (GearyEmailFlags*) _tmp16_;
				_tmp17_ = existing_flags;
				if (_tmp17_ == NULL) {
					_g_object_unref0 (existing_flags);
					_g_object_unref0 (id);
					continue;
				}
				_tmp18_ = id;
				_tmp19_ = gee_map_get (_data82_->map, _tmp18_);
				new_flags = (GearyEmailFlags*) _tmp19_;
				_tmp21_ = existing_flags;
				_tmp22_ = geary_email_flags_get_UNREAD ();
				_tmp23_ = _tmp22_;
				_tmp24_ = _tmp23_;
				_tmp25_ = !geary_named_flags_contains (G_TYPE_CHECK_INSTANCE_CAST (_tmp21_, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags), _tmp24_);
				_g_object_unref0 (_tmp24_);
				if (_tmp25_) {
					GearyEmailFlags* _tmp26_;
					GearyNamedFlag* _tmp27_;
					GearyNamedFlag* _tmp28_;
					GearyNamedFlag* _tmp29_;
					_tmp26_ = new_flags;
					_tmp27_ = geary_email_flags_get_UNREAD ();
					_tmp28_ = _tmp27_;
					_tmp29_ = _tmp28_;
					_tmp20_ = geary_named_flags_contains (G_TYPE_CHECK_INSTANCE_CAST (_tmp26_, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags), _tmp29_);
					_g_object_unref0 (_tmp29_);
				} else {
					_tmp20_ = FALSE;
				}
				if (_tmp20_) {
					gint _tmp30_;
					_tmp30_ = _data82_->unread_change;
					_data82_->unread_change = _tmp30_ + 1;
				} else {
					gboolean _tmp31_ = FALSE;
					GearyEmailFlags* _tmp32_;
					GearyNamedFlag* _tmp33_;
					GearyNamedFlag* _tmp34_;
					GearyNamedFlag* _tmp35_;
					gboolean _tmp36_;
					_tmp32_ = existing_flags;
					_tmp33_ = geary_email_flags_get_UNREAD ();
					_tmp34_ = _tmp33_;
					_tmp35_ = _tmp34_;
					_tmp36_ = geary_named_flags_contains (G_TYPE_CHECK_INSTANCE_CAST (_tmp32_, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags), _tmp35_);
					_g_object_unref0 (_tmp35_);
					if (_tmp36_) {
						GearyEmailFlags* _tmp37_;
						GearyNamedFlag* _tmp38_;
						GearyNamedFlag* _tmp39_;
						GearyNamedFlag* _tmp40_;
						_tmp37_ = new_flags;
						_tmp38_ = geary_email_flags_get_UNREAD ();
						_tmp39_ = _tmp38_;
						_tmp40_ = _tmp39_;
						_tmp31_ = !geary_named_flags_contains (G_TYPE_CHECK_INSTANCE_CAST (_tmp37_, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags), _tmp40_);
						_g_object_unref0 (_tmp40_);
					} else {
						_tmp31_ = FALSE;
					}
					if (_tmp31_) {
						gint _tmp41_;
						_tmp41_ = _data82_->unread_change;
						_data82_->unread_change = _tmp41_ - 1;
					}
				}
				_g_object_unref0 (new_flags);
				_g_object_unref0 (existing_flags);
				_g_object_unref0 (id);
			}
			_g_object_unref0 (_id_it);
		}
	}
	geary_imap_db_folder_do_set_email_flags (self, cx, _data82_->map, cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (existing_map);
		return 0;
	}
	geary_imap_db_folder_do_add_to_unread_count (self, cx, _data82_->unread_change, cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (existing_map);
		return 0;
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_COMMIT;
	_g_object_unref0 (existing_map);
	return result;
}

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

static void
geary_imap_db_folder_set_email_flags_async_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_)
{
	GearyImapDbFolderSetEmailFlagsAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_set_email_flags_async_co (_data_);
}

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

static gboolean
geary_imap_db_folder_set_email_flags_async_co (GearyImapDbFolderSetEmailFlagsAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data82_ = g_slice_new0 (Block82Data);
	_data_->_data82_->_ref_count_ = 1;
	_data_->_data82_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data82_->map);
	_data_->_data82_->map = _data_->map;
	_data_->_data82_->_async_data_ = _data_;
	_data_->_error_ = NULL;
	_data_->_data82_->unread_change = 0;
	{
		_data_->_tmp0_ = _data_->self->priv->db;
		_data_->_tmp1_ = _data_->cancellable;
		_data_->_state_ = 1;
		geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_RW, ____lambda79__geary_db_transaction_method, _data_->_data82_, _data_->_tmp1_, geary_imap_db_folder_set_email_flags_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)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp2_ = _data_->e;
		_data_->_tmp3_ = _g_error_copy0 (_data_->_tmp2_);
		_g_error_free0 (_data_->_error_);
		_data_->_error_ = _data_->_tmp3_;
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_error_free0 (_data_->_error_);
		block82_data_unref (_data_->_data82_);
		_data_->_data82_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp4_ = _data_->_error_;
	if (_data_->_tmp4_ == NULL) {
		_data_->_tmp5_ = _data_->self->priv->properties;
		_data_->_tmp6_ = _data_->self->priv->properties;
		_data_->_tmp7_ = geary_folder_properties_get_email_unread (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp6_, GEARY_TYPE_FOLDER_PROPERTIES, GearyFolderProperties));
		_data_->_tmp8_ = _data_->_tmp7_;
		geary_imap_folder_properties_set_status_unseen (_data_->_tmp5_, CLAMP (_data_->_tmp8_ + _data_->_data82_->unread_change, 0, G_MAXINT));
	} else {
		_data_->_tmp9_ = _data_->_error_;
		_data_->_tmp10_ = _g_error_copy0 (_data_->_tmp9_);
		_data_->_inner_error0_ = _data_->_tmp10_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_error_free0 (_data_->_error_);
		block82_data_unref (_data_->_data82_);
		_data_->_data82_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_error_free0 (_data_->_error_);
	block82_data_unref (_data_->_data82_);
	_data_->_data82_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_detach_single_email_async (GearyImapDBFolder* self,
                                                GearyImapDBEmailIdentifier* id,
                                                GCancellable* cancellable,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_)
{
	GearyImapDbFolderDetachSingleEmailAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GearyImapDBEmailIdentifier* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_IMAP_DB_IS_EMAIL_IDENTIFIER (id));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderDetachSingleEmailAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_detach_single_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_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_folder_detach_single_email_async_co (_data_);
}

void
geary_imap_db_folder_detach_single_email_finish (GearyImapDBFolder* self,
                                                 GAsyncResult* _res_,
                                                 gboolean* is_marked,
                                                 GError** error)
{
	GearyImapDbFolderDetachSingleEmailAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
	if (is_marked) {
		*is_marked = _data_->is_marked;
	}
}

static Block83Data*
block83_data_ref (Block83Data* _data83_)
{
	g_atomic_int_inc (&_data83_->_ref_count_);
	return _data83_;
}

static void
block83_data_unref (void * _userdata_)
{
	Block83Data* _data83_;
	_data83_ = (Block83Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data83_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data83_->self;
		_g_object_unref0 (_data83_->id);
		_g_object_unref0 (_data83_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block83Data, _data83_);
	}
}

static GearyDbTransactionOutcome
__lambda80_ (Block83Data* _data83_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GearyImapDBFolderLocationIdentifier* location = NULL;
	GearyImapDBFolderLocationIdentifier* _tmp0_;
	GearyImapDBFolderLocationIdentifier* _tmp1_;
	gint _tmp8_ = 0;
	GearyIterable* _tmp9_;
	GearyIterable* _tmp10_;
	GeeArrayList* _tmp11_;
	GeeArrayList* _tmp12_;
	gint _tmp13_;
	GearyImapDBFolderLocationIdentifier* _tmp14_;
	GearyImapDBFolderLocationIdentifier* _tmp15_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data83_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_imap_db_folder_do_get_location_for_id (self, cx, _data83_->id, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDE_MARKED_FOR_REMOVE, _data83_->cancellable, &_inner_error0_);
	location = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp1_ = location;
	if (_tmp1_ == NULL) {
		gchar* _tmp2_;
		gchar* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		GError* _tmp6_;
		GError* _tmp7_;
		_tmp2_ = geary_email_identifier_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data83_->id, GEARY_TYPE_EMAIL_IDENTIFIER, GearyEmailIdentifier));
		_tmp3_ = _tmp2_;
		_tmp4_ = geary_imap_db_folder_to_string (self);
		_tmp5_ = _tmp4_;
		_tmp6_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_NOT_FOUND, "Message %s cannot be removed from %s: not found", _tmp3_, _tmp5_);
		_tmp7_ = _tmp6_;
		_g_free0 (_tmp5_);
		_g_free0 (_tmp3_);
		_inner_error0_ = _tmp7_;
		g_propagate_error (error, _inner_error0_);
		_geary_imap_db_folder_location_identifier_unref0 (location);
		return 0;
	}
	_tmp9_ = geary_iterate (GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data83_->id, NULL);
	_tmp10_ = _tmp9_;
	_tmp11_ = geary_iterable_to_array_list (_tmp10_, NULL, NULL, NULL);
	_tmp12_ = _tmp11_;
	_tmp13_ = geary_imap_db_folder_do_get_unread_count_for_ids (self, cx, G_TYPE_CHECK_INSTANCE_CAST (_tmp12_, GEE_TYPE_COLLECTION, GeeCollection), _data83_->cancellable, &_inner_error0_);
	_g_object_unref0 (_tmp12_);
	_g_object_unref0 (_tmp10_);
	_tmp8_ = _tmp13_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_geary_imap_db_folder_location_identifier_unref0 (location);
		return 0;
	}
	if (_tmp8_ > 0) {
		geary_imap_db_folder_do_add_to_unread_count (self, cx, -1, _data83_->cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			return 0;
		}
		_data83_->was_unread = TRUE;
	}
	_tmp14_ = location;
	_data83_->internal_is_marked = _tmp14_->marked_removed;
	_tmp15_ = location;
	geary_imap_db_folder_do_remove_association_with_folder (self, cx, _tmp15_, _data83_->cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_geary_imap_db_folder_location_identifier_unref0 (location);
		return 0;
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_COMMIT;
	_geary_imap_db_folder_location_identifier_unref0 (location);
	return result;
}

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

static void
geary_imap_db_folder_detach_single_email_async_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_)
{
	GearyImapDbFolderDetachSingleEmailAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_detach_single_email_async_co (_data_);
}

static gboolean
geary_imap_db_folder_detach_single_email_async_co (GearyImapDbFolderDetachSingleEmailAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data83_ = g_slice_new0 (Block83Data);
	_data_->_data83_->_ref_count_ = 1;
	_data_->_data83_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data83_->id);
	_data_->_data83_->id = _data_->id;
	_g_object_unref0 (_data_->_data83_->cancellable);
	_data_->_data83_->cancellable = _data_->cancellable;
	_data_->_data83_->_async_data_ = _data_;
	_data_->_data83_->internal_is_marked = FALSE;
	_data_->_data83_->was_unread = FALSE;
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_RW, ___lambda80__geary_db_transaction_method, _data_->_data83_, _data_->_data83_->cancellable, geary_imap_db_folder_detach_single_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_);
		block83_data_unref (_data_->_data83_);
		_data_->_data83_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->is_marked = _data_->_data83_->internal_is_marked;
	if (_data_->_data83_->was_unread) {
		_data_->_tmp1_ = _data_->self->priv->properties;
		_data_->_tmp2_ = _data_->self->priv->properties;
		_data_->_tmp3_ = geary_folder_properties_get_email_unread (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, GEARY_TYPE_FOLDER_PROPERTIES, GearyFolderProperties));
		_data_->_tmp4_ = _data_->_tmp3_;
		geary_imap_folder_properties_set_status_unseen (_data_->_tmp1_, _data_->_tmp4_ - 1);
	}
	block83_data_unref (_data_->_data83_);
	_data_->_data83_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_mark_removed_async (GearyImapDBFolder* self,
                                         GeeCollection* ids,
                                         gboolean mark_removed,
                                         GCancellable* cancellable,
                                         GAsyncReadyCallback _callback_,
                                         gpointer _user_data_)
{
	GearyImapDbFolderMarkRemovedAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GeeCollection* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail ((ids == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderMarkRemovedAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_mark_removed_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_->mark_removed = mark_removed;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_folder_mark_removed_async_co (_data_);
}

GeeSet*
geary_imap_db_folder_mark_removed_finish (GearyImapDBFolder* self,
                                          GAsyncResult* _res_,
                                          GError** error)
{
	GeeSet* result;
	GearyImapDbFolderMarkRemovedAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block84Data*
block84_data_ref (Block84Data* _data84_)
{
	g_atomic_int_inc (&_data84_->_ref_count_);
	return _data84_;
}

static void
block84_data_unref (void * _userdata_)
{
	Block84Data* _data84_;
	_data84_ = (Block84Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data84_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data84_->self;
		_g_object_unref0 (_data84_->removed_ids);
		_g_object_unref0 (_data84_->ids);
		_g_object_unref0 (_data84_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block84Data, _data84_);
	}
}

static GearyDbTransactionOutcome
__lambda81_ (Block84Data* _data84_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GeeList* locs = NULL;
	gboolean _tmp6_ = FALSE;
	GeeList* _tmp7_;
	GeeList* _tmp11_;
	gint _tmp12_;
	gint _tmp13_;
	gint _tmp14_ = 0;
	GeeHashSet* uids = NULL;
	GeeHashSet* _tmp15_;
	GeeHashSet* _tmp29_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data84_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	if (_data84_->ids != NULL) {
		GeeList* _tmp0_ = NULL;
		GeeList* _tmp1_;
		GeeList* _tmp2_;
		_tmp1_ = geary_imap_db_folder_do_get_locations_for_ids (self, cx, _data84_->ids, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDE_MARKED_FOR_REMOVE, _data84_->cancellable, &_inner_error0_);
		_tmp0_ = _tmp1_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (locs);
			return 0;
		}
		_tmp2_ = _tmp0_;
		_tmp0_ = NULL;
		_g_object_unref0 (locs);
		locs = _tmp2_;
		_g_object_unref0 (_tmp0_);
	} else {
		GeeList* _tmp3_ = NULL;
		GeeList* _tmp4_;
		GeeList* _tmp5_;
		_tmp4_ = geary_imap_db_folder_do_get_all_locations (self, cx, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDE_MARKED_FOR_REMOVE, _data84_->cancellable, &_inner_error0_);
		_tmp3_ = _tmp4_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (locs);
			return 0;
		}
		_tmp5_ = _tmp3_;
		_tmp3_ = NULL;
		_g_object_unref0 (locs);
		locs = _tmp5_;
		_g_object_unref0 (_tmp3_);
	}
	_tmp7_ = locs;
	if (_tmp7_ == NULL) {
		_tmp6_ = TRUE;
	} else {
		GeeList* _tmp8_;
		gint _tmp9_;
		gint _tmp10_;
		_tmp8_ = locs;
		_tmp9_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, GEE_TYPE_COLLECTION, GeeCollection));
		_tmp10_ = _tmp9_;
		_tmp6_ = _tmp10_ == 0;
	}
	if (_tmp6_) {
		result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
		_g_object_unref0 (locs);
		return result;
	}
	_tmp11_ = locs;
	_tmp12_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp11_, GEE_TYPE_COLLECTION, GeeCollection));
	_tmp13_ = _tmp12_;
	_data84_->total_changed = _tmp13_;
	_tmp14_ = geary_imap_db_folder_do_get_unread_count_for_ids (self, cx, _data84_->ids, _data84_->cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (locs);
		return 0;
	}
	_data84_->unread_count = _tmp14_;
	_tmp15_ = gee_hash_set_new (GEARY_IMAP_TYPE_UID, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL);
	uids = _tmp15_;
	{
		GeeList* _location_list = NULL;
		GeeList* _tmp16_;
		gint _location_size = 0;
		GeeList* _tmp17_;
		gint _tmp18_;
		gint _tmp19_;
		gint _location_index = 0;
		_tmp16_ = locs;
		_location_list = _tmp16_;
		_tmp17_ = _location_list;
		_tmp18_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp17_, GEE_TYPE_COLLECTION, GeeCollection));
		_tmp19_ = _tmp18_;
		_location_size = _tmp19_;
		_location_index = -1;
		while (TRUE) {
			gint _tmp20_;
			gint _tmp21_;
			GearyImapDBFolderLocationIdentifier* location = NULL;
			GeeList* _tmp22_;
			gpointer _tmp23_;
			GeeHashSet* _tmp24_;
			GearyImapDBFolderLocationIdentifier* _tmp25_;
			GearyImapUID* _tmp26_;
			GearyImapDBFolderLocationIdentifier* _tmp27_;
			GearyImapDBEmailIdentifier* _tmp28_;
			_location_index = _location_index + 1;
			_tmp20_ = _location_index;
			_tmp21_ = _location_size;
			if (!(_tmp20_ < _tmp21_)) {
				break;
			}
			_tmp22_ = _location_list;
			_tmp23_ = gee_list_get (_tmp22_, _location_index);
			location = (GearyImapDBFolderLocationIdentifier*) _tmp23_;
			_tmp24_ = uids;
			_tmp25_ = location;
			_tmp26_ = _tmp25_->uid;
			gee_abstract_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp24_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection), _tmp26_);
			_tmp27_ = location;
			_tmp28_ = _tmp27_->email_id;
			gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_data84_->removed_ids, GEE_TYPE_COLLECTION, GeeCollection), _tmp28_);
			_geary_imap_db_folder_location_identifier_unref0 (location);
		}
	}
	_tmp29_ = uids;
	geary_imap_db_folder_do_mark_unmark_removed (self, cx, G_TYPE_CHECK_INSTANCE_CAST (_tmp29_, GEE_TYPE_COLLECTION, GeeCollection), _data84_->mark_removed, _data84_->cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (uids);
		_g_object_unref0 (locs);
		return 0;
	}
	geary_imap_db_folder_do_add_to_unread_count (self, cx, -_data84_->unread_count, _data84_->cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (uids);
		_g_object_unref0 (locs);
		return 0;
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	_g_object_unref0 (uids);
	_g_object_unref0 (locs);
	return result;
}

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

static void
geary_imap_db_folder_mark_removed_async_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_)
{
	GearyImapDbFolderMarkRemovedAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_mark_removed_async_co (_data_);
}

static gboolean
geary_imap_db_folder_mark_removed_async_co (GearyImapDbFolderMarkRemovedAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data84_ = g_slice_new0 (Block84Data);
	_data_->_data84_->_ref_count_ = 1;
	_data_->_data84_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data84_->ids);
	_data_->_data84_->ids = _data_->ids;
	_data_->_data84_->mark_removed = _data_->mark_removed;
	_g_object_unref0 (_data_->_data84_->cancellable);
	_data_->_data84_->cancellable = _data_->cancellable;
	_data_->_data84_->_async_data_ = _data_;
	_data_->_data84_->total_changed = 0;
	_data_->_data84_->unread_count = 0;
	_data_->_tmp0_ = gee_hash_set_new (GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->_data84_->removed_ids = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEE_TYPE_SET, GeeSet);
	_data_->_tmp1_ = _data_->self->priv->db;
	_data_->_tmp2_ = _data_->_data84_->cancellable;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp1_, GEARY_DB_TRANSACTION_TYPE_RW, ___lambda81__geary_db_transaction_method, _data_->_data84_, _data_->_tmp2_, geary_imap_db_folder_mark_removed_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_);
		block84_data_unref (_data_->_data84_);
		_data_->_data84_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (_data_->_data84_->mark_removed) {
		_data_->_data84_->total_changed = -_data_->_data84_->total_changed;
	}
	_data_->_tmp3_ = _data_->self->priv->properties;
	_data_->_tmp4_ = geary_imap_folder_properties_get_select_examine_messages (_data_->_tmp3_);
	_data_->_tmp5_ = _data_->_tmp4_;
	_data_->total = _data_->_tmp5_ + _data_->_data84_->total_changed;
	if (_data_->total >= 0) {
		_data_->_tmp6_ = _data_->self->priv->properties;
		geary_imap_folder_properties_set_select_examine_message_count (_data_->_tmp6_, _data_->total);
	}
	if (_data_->_data84_->unread_count > 0) {
		_data_->_tmp7_ = _data_->self->priv->properties;
		_data_->_tmp8_ = _data_->self->priv->properties;
		_data_->_tmp9_ = geary_folder_properties_get_email_unread (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp8_, GEARY_TYPE_FOLDER_PROPERTIES, GearyFolderProperties));
		_data_->_tmp10_ = _data_->_tmp9_;
		geary_imap_folder_properties_set_status_unseen (_data_->_tmp7_, _data_->_tmp10_ - _data_->_data84_->unread_count);
	}
	_data_->_tmp12_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_data84_->removed_ids, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp13_ = _data_->_tmp12_;
	if (_data_->_tmp13_ > 0) {
		_data_->_tmp11_ = _data_->_data84_->removed_ids;
	} else {
		_data_->_tmp11_ = NULL;
	}
	_data_->_tmp14_ = _g_object_ref0 (_data_->_tmp11_);
	_data_->result = _data_->_tmp14_;
	block84_data_unref (_data_->_data84_);
	_data_->_data84_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_get_marked_for_remove_count_async (GearyImapDBFolder* self,
                                                        GCancellable* cancellable,
                                                        GAsyncReadyCallback _callback_,
                                                        gpointer _user_data_)
{
	GearyImapDbFolderGetMarkedForRemoveCountAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderGetMarkedForRemoveCountAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_get_marked_for_remove_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_imap_db_folder_get_marked_for_remove_count_async_co (_data_);
}

gint
geary_imap_db_folder_get_marked_for_remove_count_finish (GearyImapDBFolder* self,
                                                         GAsyncResult* _res_,
                                                         GError** error)
{
	gint result;
	GearyImapDbFolderGetMarkedForRemoveCountAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		gint _tmp0_ = 0;
		return _tmp0_;
	}
	result = _data_->result;
	return result;
}

static Block85Data*
block85_data_ref (Block85Data* _data85_)
{
	g_atomic_int_inc (&_data85_->_ref_count_);
	return _data85_;
}

static void
block85_data_unref (void * _userdata_)
{
	Block85Data* _data85_;
	_data85_ = (Block85Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data85_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data85_->self;
		_g_object_unref0 (_data85_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block85Data, _data85_);
	}
}

static GearyDbTransactionOutcome
__lambda82_ (Block85Data* _data85_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	gint _tmp0_ = 0;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data85_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_imap_db_folder_do_get_marked_removed_count (self, cx, _data85_->cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_data85_->count = _tmp0_;
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	return result;
}

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

static void
geary_imap_db_folder_get_marked_for_remove_count_async_ready (GObject* source_object,
                                                              GAsyncResult* _res_,
                                                              gpointer _user_data_)
{
	GearyImapDbFolderGetMarkedForRemoveCountAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_get_marked_for_remove_count_async_co (_data_);
}

static gboolean
geary_imap_db_folder_get_marked_for_remove_count_async_co (GearyImapDbFolderGetMarkedForRemoveCountAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data85_ = g_slice_new0 (Block85Data);
	_data_->_data85_->_ref_count_ = 1;
	_data_->_data85_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data85_->cancellable);
	_data_->_data85_->cancellable = _data_->cancellable;
	_data_->_data85_->_async_data_ = _data_;
	_data_->_data85_->count = 0;
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda82__geary_db_transaction_method, _data_->_data85_, _data_->_data85_->cancellable, geary_imap_db_folder_get_marked_for_remove_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_);
		block85_data_unref (_data_->_data85_);
		_data_->_data85_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->result = _data_->_data85_->count;
	block85_data_unref (_data_->_data85_);
	_data_->_data85_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_get_marked_ids_async (GearyImapDBFolder* self,
                                           GCancellable* cancellable,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_)
{
	GearyImapDbFolderGetMarkedIdsAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderGetMarkedIdsAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_get_marked_ids_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_db_folder_get_marked_ids_async_co (_data_);
}

GeeSet*
geary_imap_db_folder_get_marked_ids_finish (GearyImapDBFolder* self,
                                            GAsyncResult* _res_,
                                            GError** error)
{
	GeeSet* result;
	GearyImapDbFolderGetMarkedIdsAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block86Data*
block86_data_ref (Block86Data* _data86_)
{
	g_atomic_int_inc (&_data86_->_ref_count_);
	return _data86_;
}

static void
block86_data_unref (void * _userdata_)
{
	Block86Data* _data86_;
	_data86_ = (Block86Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data86_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data86_->self;
		_g_object_unref0 (_data86_->ids);
		_g_object_unref0 (_data86_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block86Data, _data86_);
	}
}

static GearyDbTransactionOutcome
__lambda83_ (Block86Data* _data86_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp1_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbStatement* _tmp5_;
	GearyDbStatement* _tmp6_;
	GearyDbResult* results = NULL;
	GearyDbStatement* _tmp7_;
	GearyDbResult* _tmp8_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data86_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = geary_db_connection_prepare (cx, "\n" \
"                SELECT message_id, ordering\n" \
"                FROM MessageLocationTable\n" \
"                WHERE folder_id=? AND remove_marker<>?\n" \
"            ", &_inner_error0_);
	stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp1_ = stmt;
	_tmp2_ = geary_db_statement_bind_rowid (_tmp1_, 0, self->priv->folder_id, &_inner_error0_);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp3_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp4_ = stmt;
	_tmp5_ = geary_db_statement_bind_bool (_tmp4_, 1, FALSE, &_inner_error0_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp6_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	_tmp7_ = stmt;
	_tmp8_ = geary_db_statement_exec (_tmp7_, _data86_->cancellable, &_inner_error0_);
	results = _tmp8_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return 0;
	}
	while (TRUE) {
		GearyDbResult* _tmp9_;
		gboolean _tmp10_;
		gboolean _tmp11_;
		gint64 _tmp12_ = 0LL;
		GearyDbResult* _tmp13_;
		gint64 _tmp14_ = 0LL;
		GearyDbResult* _tmp15_;
		GearyImapUID* _tmp16_;
		GearyImapUID* _tmp17_;
		GearyImapDBEmailIdentifier* _tmp18_;
		GearyImapDBEmailIdentifier* _tmp19_;
		GearyDbResult* _tmp20_;
		_tmp9_ = results;
		_tmp10_ = geary_db_result_get_finished (_tmp9_);
		_tmp11_ = _tmp10_;
		if (!(!_tmp11_)) {
			break;
		}
		_tmp13_ = results;
		_tmp12_ = geary_db_result_rowid_at (_tmp13_, 0, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp15_ = results;
		_tmp14_ = geary_db_result_int64_at (_tmp15_, 1, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			return 0;
		}
		_tmp16_ = geary_imap_uid_new (_tmp14_);
		_tmp17_ = _tmp16_;
		_tmp18_ = geary_imap_db_email_identifier_new (_tmp12_, _tmp17_);
		_tmp19_ = _tmp18_;
		gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_data86_->ids, GEE_TYPE_COLLECTION, GeeCollection), _tmp19_);
		_g_object_unref0 (_tmp19_);
		_g_object_unref0 (_tmp17_);
		_tmp20_ = results;
		geary_db_result_next (_tmp20_, _data86_->cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			return 0;
		}
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
	_g_object_unref0 (results);
	_g_object_unref0 (stmt);
	return result;
}

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

static void
geary_imap_db_folder_get_marked_ids_async_ready (GObject* source_object,
                                                 GAsyncResult* _res_,
                                                 gpointer _user_data_)
{
	GearyImapDbFolderGetMarkedIdsAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_get_marked_ids_async_co (_data_);
}

static gboolean
geary_imap_db_folder_get_marked_ids_async_co (GearyImapDbFolderGetMarkedIdsAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data86_ = g_slice_new0 (Block86Data);
	_data_->_data86_->_ref_count_ = 1;
	_data_->_data86_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data86_->cancellable);
	_data_->_data86_->cancellable = _data_->cancellable;
	_data_->_data86_->_async_data_ = _data_;
	_data_->_tmp0_ = gee_hash_set_new (GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->_data86_->ids = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEE_TYPE_SET, GeeSet);
	_data_->_tmp1_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp1_, GEARY_DB_TRANSACTION_TYPE_RO, ___lambda83__geary_db_transaction_method, _data_->_data86_, _data_->_data86_->cancellable, geary_imap_db_folder_get_marked_ids_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_);
		block86_data_unref (_data_->_data86_);
		_data_->_data86_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp3_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_data86_->ids, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp4_ = _data_->_tmp3_;
	if (_data_->_tmp4_ > 0) {
		_data_->_tmp2_ = _data_->_data86_->ids;
	} else {
		_data_->_tmp2_ = NULL;
	}
	_data_->_tmp5_ = _g_object_ref0 (_data_->_tmp2_);
	_data_->result = _data_->_tmp5_;
	block86_data_unref (_data_->_data86_);
	_data_->_data86_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_clear_remove_markers_async (GearyImapDBFolder* self,
                                                 GeeCollection* exceptions,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_)
{
	GearyImapDbFolderClearRemoveMarkersAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GeeCollection* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail ((exceptions == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (exceptions, GEE_TYPE_COLLECTION));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderClearRemoveMarkersAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_clear_remove_markers_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (exceptions);
	_g_object_unref0 (_data_->exceptions);
	_data_->exceptions = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_folder_clear_remove_markers_async_co (_data_);
}

void
geary_imap_db_folder_clear_remove_markers_finish (GearyImapDBFolder* self,
                                                  GAsyncResult* _res_,
                                                  GError** error)
{
	GearyImapDbFolderClearRemoveMarkersAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static Block87Data*
block87_data_ref (Block87Data* _data87_)
{
	g_atomic_int_inc (&_data87_->_ref_count_);
	return _data87_;
}

static void
block87_data_unref (void * _userdata_)
{
	Block87Data* _data87_;
	_data87_ = (Block87Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data87_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data87_->self;
		_g_object_unref0 (_data87_->exceptions);
		_g_object_unref0 (_data87_->cancellable);
		_g_object_unref0 (self);
		g_slice_free (Block87Data, _data87_);
	}
}

static GearyDbTransactionOutcome
__lambda84_ (Block87Data* _data87_,
             GearyDbConnection* cx,
             GError** error)
{
	GearyImapDBFolder* self;
	GString* sql = NULL;
	GString* _tmp0_;
	GString* _tmp1_;
	gboolean _tmp2_ = FALSE;
	GearyDbStatement* stmt = NULL;
	GString* _tmp19_;
	const gchar* _tmp20_;
	GearyDbStatement* _tmp21_;
	GearyDbStatement* _tmp22_;
	GearyDbStatement* _tmp23_;
	GearyDbStatement* _tmp24_;
	GearyDbStatement* _tmp25_;
	GearyDbStatement* _tmp26_;
	GearyDbStatement* _tmp27_;
	GearyDbStatement* _tmp28_;
	GearyDbStatement* _tmp29_;
	GearyDbStatement* _tmp30_;
	GearyDbStatement* _tmp31_;
	GearyDbResult* _tmp32_;
	GearyDbResult* _tmp33_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data87_->self;
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	_tmp0_ = g_string_new ("");
	sql = _tmp0_;
	_tmp1_ = sql;
	g_string_append (_tmp1_, "\n" \
"                UPDATE MessageLocationTable\n" \
"                SET remove_marker=?\n" \
"                WHERE folder_id=? AND remove_marker <> ?\n" \
"            ");
	if (_data87_->exceptions != NULL) {
		gint _tmp3_;
		gint _tmp4_;
		_tmp3_ = gee_collection_get_size (_data87_->exceptions);
		_tmp4_ = _tmp3_;
		_tmp2_ = _tmp4_ > 0;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		GString* _tmp5_;
		GeeIterator* iter = NULL;
		GeeIterator* _tmp6_;
		GString* _tmp18_;
		_tmp5_ = sql;
		g_string_append (_tmp5_, "\n                    AND message_id NOT IN (\n                ");
		_tmp6_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_data87_->exceptions, GEE_TYPE_ITERABLE, GeeIterable));
		iter = _tmp6_;
		while (TRUE) {
			GeeIterator* _tmp7_;
			GString* _tmp8_;
			GeeIterator* _tmp9_;
			gpointer _tmp10_;
			GearyImapDBEmailIdentifier* _tmp11_;
			gint64 _tmp12_;
			gint64 _tmp13_;
			gchar* _tmp14_;
			gchar* _tmp15_;
			GeeIterator* _tmp16_;
			_tmp7_ = iter;
			if (!gee_iterator_next (_tmp7_)) {
				break;
			}
			_tmp8_ = sql;
			_tmp9_ = iter;
			_tmp10_ = gee_iterator_get (_tmp9_);
			_tmp11_ = (GearyImapDBEmailIdentifier*) _tmp10_;
			_tmp12_ = geary_imap_db_email_identifier_get_message_id (_tmp11_);
			_tmp13_ = _tmp12_;
			_tmp14_ = g_strdup_printf ("%" G_GINT64_FORMAT, _tmp13_);
			_tmp15_ = _tmp14_;
			g_string_append (_tmp8_, _tmp15_);
			_g_free0 (_tmp15_);
			_g_object_unref0 (_tmp11_);
			_tmp16_ = iter;
			if (gee_iterator_has_next (_tmp16_)) {
				GString* _tmp17_;
				_tmp17_ = sql;
				g_string_append (_tmp17_, ", ");
			}
		}
		_tmp18_ = sql;
		g_string_append (_tmp18_, ")");
		_g_object_unref0 (iter);
	}
	_tmp19_ = sql;
	_tmp20_ = _tmp19_->str;
	_tmp21_ = geary_db_connection_prepare (cx, _tmp20_, &_inner_error0_);
	stmt = _tmp21_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp22_ = stmt;
	_tmp23_ = geary_db_statement_bind_bool (_tmp22_, 0, FALSE, &_inner_error0_);
	_tmp24_ = _tmp23_;
	_g_object_unref0 (_tmp24_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp25_ = stmt;
	_tmp26_ = geary_db_statement_bind_rowid (_tmp25_, 1, self->priv->folder_id, &_inner_error0_);
	_tmp27_ = _tmp26_;
	_g_object_unref0 (_tmp27_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp28_ = stmt;
	_tmp29_ = geary_db_statement_bind_bool (_tmp28_, 2, FALSE, &_inner_error0_);
	_tmp30_ = _tmp29_;
	_g_object_unref0 (_tmp30_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	_tmp31_ = stmt;
	_tmp32_ = geary_db_statement_exec (_tmp31_, _data87_->cancellable, &_inner_error0_);
	_tmp33_ = _tmp32_;
	_g_object_unref0 (_tmp33_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return 0;
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_COMMIT;
	_g_object_unref0 (stmt);
	_g_string_free0 (sql);
	return result;
}

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

static void
geary_imap_db_folder_clear_remove_markers_async_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_)
{
	GearyImapDbFolderClearRemoveMarkersAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_clear_remove_markers_async_co (_data_);
}

static gboolean
geary_imap_db_folder_clear_remove_markers_async_co (GearyImapDbFolderClearRemoveMarkersAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data87_ = g_slice_new0 (Block87Data);
	_data_->_data87_->_ref_count_ = 1;
	_data_->_data87_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data87_->exceptions);
	_data_->_data87_->exceptions = _data_->exceptions;
	_g_object_unref0 (_data_->_data87_->cancellable);
	_data_->_data87_->cancellable = _data_->cancellable;
	_data_->_data87_->_async_data_ = _data_;
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_state_ = 1;
	geary_db_database_exec_transaction_async (_data_->_tmp0_, GEARY_DB_TRANSACTION_TYPE_WO, ___lambda84__geary_db_transaction_method, _data_->_data87_, _data_->_data87_->cancellable, geary_imap_db_folder_clear_remove_markers_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_);
		block87_data_unref (_data_->_data87_);
		_data_->_data87_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	block87_data_unref (_data_->_data87_);
	_data_->_data87_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_imap_db_folder_list_email_fields_by_id_async (GearyImapDBFolder* self,
                                                    GeeCollection* ids,
                                                    GearyImapDBFolderListFlags flags,
                                                    GCancellable* cancellable,
                                                    GAsyncReadyCallback _callback_,
                                                    gpointer _user_data_)
{
	GearyImapDbFolderListEmailFieldsByIdAsyncData* _data_;
	GearyImapDBFolder* _tmp0_;
	GeeCollection* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapDbFolderListEmailFieldsByIdAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_db_folder_list_email_fields_by_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_->flags = flags;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_db_folder_list_email_fields_by_id_async_co (_data_);
}

GeeMap*
geary_imap_db_folder_list_email_fields_by_id_finish (GearyImapDBFolder* self,
                                                     GAsyncResult* _res_,
                                                     GError** error)
{
	GeeMap* result;
	GearyImapDbFolderListEmailFieldsByIdAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block88Data*
block88_data_ref (Block88Data* _data88_)
{
	g_atomic_int_inc (&_data88_->_ref_count_);
	return _data88_;
}

static void
block88_data_unref (void * _userdata_)
{
	Block88Data* _data88_;
	_data88_ = (Block88Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data88_->_ref_count_)) {
		GearyImapDBFolder* self;
		self = _data88_->self;
		_g_object_unref0 (_data88_->map);
		_g_object_unref0 (_data88_->ids);
		_g_object_unref0 (self);
		g_slice_free (Block88Data, _data88_);
	}
}

static GearyDbTransactionOutcome
___lambda85_ (Block88Data* _data88_,
              GearyDbConnection* cx,
              GCancellable* cancellable,
              GError** error)
{
	GearyImapDBFolder* self;
	GeeList* locs = NULL;
	GeeList* _tmp0_;
	gboolean _tmp1_ = FALSE;
	GeeList* _tmp2_;
	GearyDbStatement* fetch_stmt = NULL;
	GearyDbStatement* _tmp6_;
	GError* _inner_error0_ = NULL;
	GearyDbTransactionOutcome result;
	self = _data88_->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);
	_tmp0_ = geary_imap_db_folder_do_get_locations_for_ids (self, cx, _data88_->ids, _data88_->flags, cancellable, &_inner_error0_);
	locs = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return 0;
	}
	_tmp2_ = locs;
	if (_tmp2_ == NULL) {
		_tmp1_ = TRUE;
	} else {
		GeeList* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		_tmp3_ = locs;
		_tmp4_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, GEE_TYPE_COLLECTION, GeeCollection));
		_tmp5_ = _tmp4_;
		_tmp1_ = _tmp5_ == 0;
	}
	if (_tmp1_) {
		result = GEARY_DB_TRANSACTION_OUTCOME_DONE;
		_g_object_unref0 (locs);
		return result;
	}
	_tmp6_ = geary_db_connection_prepare (cx, "SELECT fields FROM MessageTable WHERE id = ?", &_inner_error0_);
	fetch_stmt = _tmp6_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (locs);
		return 0;
	}
	{
		GeeList* _location_list = NULL;
		GeeList* _tmp7_;
		gint _location_size = 0;
		GeeList* _tmp8_;
		gint _tmp9_;
		gint _tmp10_;
		gint _location_index = 0;
		_tmp7_ = locs;
		_location_list = _tmp7_;
		_tmp8_ = _location_list;
		_tmp9_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, GEE_TYPE_COLLECTION, GeeCollection));
		_tmp10_ = _tmp9_;
		_location_size = _tmp10_;
		_location_index = -1;
		while (TRUE) {
			gint _tmp11_;
			gint _tmp12_;
			GearyImapDBFolderLocationIdentifier* location = NULL;
			GeeList* _tmp13_;
			gpointer _tmp14_;
			GearyDbStatement* _tmp15_;
			GearyDbStatement* _tmp16_;
			GearyDbStatement* _tmp17_;
			GearyDbStatement* _tmp18_;
			GearyImapDBFolderLocationIdentifier* _tmp19_;
			GearyDbStatement* _tmp20_;
			GearyDbStatement* _tmp21_;
			GearyDbResult* results = NULL;
			GearyDbStatement* _tmp22_;
			GearyDbResult* _tmp23_;
			GearyDbResult* _tmp24_;
			gboolean _tmp25_;
			gboolean _tmp26_;
			_location_index = _location_index + 1;
			_tmp11_ = _location_index;
			_tmp12_ = _location_size;
			if (!(_tmp11_ < _tmp12_)) {
				break;
			}
			_tmp13_ = _location_list;
			_tmp14_ = gee_list_get (_tmp13_, _location_index);
			location = (GearyImapDBFolderLocationIdentifier*) _tmp14_;
			_tmp15_ = fetch_stmt;
			_tmp16_ = geary_db_statement_reset (_tmp15_, GEARY_DB_RESET_SCOPE_CLEAR_BINDINGS, &_inner_error0_);
			_tmp17_ = _tmp16_;
			_g_object_unref0 (_tmp17_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (fetch_stmt);
				_g_object_unref0 (locs);
				return 0;
			}
			_tmp18_ = fetch_stmt;
			_tmp19_ = location;
			_tmp20_ = geary_db_statement_bind_rowid (_tmp18_, 0, _tmp19_->message_id, &_inner_error0_);
			_tmp21_ = _tmp20_;
			_g_object_unref0 (_tmp21_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (fetch_stmt);
				_g_object_unref0 (locs);
				return 0;
			}
			_tmp22_ = fetch_stmt;
			_tmp23_ = geary_db_statement_exec (_tmp22_, cancellable, &_inner_error0_);
			results = _tmp23_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (fetch_stmt);
				_g_object_unref0 (locs);
				return 0;
			}
			_tmp24_ = results;
			_tmp25_ = geary_db_result_get_finished (_tmp24_);
			_tmp26_ = _tmp25_;
			if (!_tmp26_) {
				gint _tmp27_ = 0;
				GearyDbResult* _tmp28_;
				GeeHashMap* _tmp29_;
				GearyImapDBFolderLocationIdentifier* _tmp30_;
				GearyImapDBEmailIdentifier* _tmp31_;
				_tmp28_ = results;
				_tmp27_ = geary_db_result_int_at (_tmp28_, 0, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					g_propagate_error (error, _inner_error0_);
					_g_object_unref0 (results);
					_geary_imap_db_folder_location_identifier_unref0 (location);
					_g_object_unref0 (fetch_stmt);
					_g_object_unref0 (locs);
					return 0;
				}
				_tmp29_ = _data88_->map;
				_tmp30_ = location;
				_tmp31_ = _tmp30_->email_id;
				gee_abstract_map_set (G_TYPE_CHECK_INSTANCE_CAST (_tmp29_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _tmp31_, (gpointer) ((gintptr) _tmp27_));
			}
			_g_object_unref0 (results);
			_geary_imap_db_folder_location_identifier_unref0 (location);
		}
	}
	result = GEARY_DB_TRANSACTION_OUTCOME_SUCCESS;
	_g_object_unref0 (fetch_stmt);
	_g_object_unref0 (locs);
	return result;
}

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

static void
geary_imap_db_folder_list_email_fields_by_id_async_ready (GObject* source_object,
                                                          GAsyncResult* _res_,
                                                          gpointer _user_data_)
{
	GearyImapDbFolderListEmailFieldsByIdAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_db_folder_list_email_fields_by_id_async_co (_data_);
}

static gboolean
geary_imap_db_folder_list_email_fields_by_id_async_co (GearyImapDbFolderListEmailFieldsByIdAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data88_ = g_slice_new0 (Block88Data);
	_data_->_data88_->_ref_count_ = 1;
	_data_->_data88_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data88_->ids);
	_data_->_data88_->ids = _data_->ids;
	_data_->_data88_->flags = _data_->flags;
	_data_->_data88_->_async_data_ = _data_;
	_data_->_tmp0_ = gee_collection_get_size (_data_->_data88_->ids);
	_data_->_tmp1_ = _data_->_tmp0_;
	if (_data_->_tmp1_ == 0) {
		_data_->result = NULL;
		block88_data_unref (_data_->_data88_);
		_data_->_data88_ = 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_->_tmp2_ = gee_hash_map_new (GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEARY_EMAIL_TYPE_FIELD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->_data88_->map = _data_->_tmp2_;
	_data_->_tmp3_ = gee_array_list_new (GEARY_IMAP_DB_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_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_data_->_data88_->ids, GEE_TYPE_ITERABLE, GeeIterable));
	_data_->iter = _data_->_tmp4_;
	while (TRUE) {
		_data_->_tmp5_ = _data_->iter;
		if (!gee_iterator_next (_data_->_tmp5_)) {
			break;
		}
		_data_->_tmp6_ = _data_->list;
		_data_->_tmp7_ = _data_->iter;
		_data_->_tmp8_ = gee_iterator_get (_data_->_tmp7_);
		_data_->_tmp9_ = (GearyImapDBEmailIdentifier*) _data_->_tmp8_;
		gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp6_, GEE_TYPE_COLLECTION, GeeCollection), _data_->_tmp9_);
		_g_object_unref0 (_data_->_tmp9_);
		_data_->_tmp11_ = _data_->list;
		_data_->_tmp12_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp11_, GEE_TYPE_COLLECTION, GeeCollection));
		_data_->_tmp13_ = _data_->_tmp12_;
		if (_data_->_tmp13_ < GEARY_IMAP_DB_FOLDER_LIST_EMAIL_FIELDS_CHUNK_COUNT) {
			_data_->_tmp14_ = _data_->iter;
			_data_->_tmp10_ = gee_iterator_has_next (_data_->_tmp14_);
		} else {
			_data_->_tmp10_ = FALSE;
		}
		if (_data_->_tmp10_) {
			continue;
		}
		_data_->_tmp15_ = _data_->self->priv->db;
		_data_->_tmp16_ = _data_->cancellable;
		_data_->_state_ = 1;
		geary_db_database_exec_transaction_async (_data_->_tmp15_, GEARY_DB_TRANSACTION_TYPE_RO, ____lambda85__geary_db_transaction_method, _data_->_data88_, _data_->_tmp16_, geary_imap_db_folder_list_email_fields_by_id_async_ready, _data_);
		return FALSE;
		_state_1:
		geary_db_database_exec_transaction_finish (_data_->_tmp15_, _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_->iter);
			_g_object_unref0 (_data_->list);
			block88_data_unref (_data_->_data88_);
			_data_->_data88_ = NULL;
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp17_ = _data_->list;
		gee_collection_clear (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp17_, GEE_TYPE_COLLECTION, GeeCollection));
	}
	_data_->_tmp18_ = _data_->list;
	_data_->_tmp19_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp18_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp20_ = _data_->_tmp19_;
	_vala_assert (_data_->_tmp20_ == 0, "list.size == 0");
	_data_->_tmp22_ = _data_->_data88_->map;
	_data_->_tmp23_ = gee_abstract_map_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp22_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap));
	_data_->_tmp24_ = _data_->_tmp23_;
	if (_data_->_tmp24_ > 0) {
		_data_->_tmp25_ = _data_->_data88_->map;
		_data_->_tmp21_ = _data_->_tmp25_;
	} else {
		_data_->_tmp21_ = NULL;
	}
	_data_->_tmp26_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp21_, GEE_TYPE_MAP, GeeMap));
	_data_->result = _data_->_tmp26_;
	_g_object_unref0 (_data_->iter);
	_g_object_unref0 (_data_->list);
	block88_data_unref (_data_->_data88_);
	_data_->_data88_ = 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;
}

gchar*
geary_imap_db_folder_to_string (GearyImapDBFolder* self)
{
	GearyFolderPath* _tmp0_;
	gchar* _tmp1_;
	gchar* result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_FOLDER (self), NULL);
	_tmp0_ = self->priv->path;
	_tmp1_ = geary_folder_path_to_string (_tmp0_);
	result = _tmp1_;
	return result;
}

static gint
geary_imap_db_folder_do_get_email_count (GearyImapDBFolder* self,
                                         GearyDbConnection* cx,
                                         GearyImapDBFolderListFlags flags,
                                         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_;
	gint _tmp12_ = 0;
	gint marked = 0;
	gint _tmp14_ = 0;
	GearyDbResult* _tmp15_;
	GError* _inner_error0_ = NULL;
	gint result;
	g_return_val_if_fail (GEARY_IMAP_DB_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 MessageLocationTable WHERE folder_id=?", &_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_rowid (_tmp2_, 0, self->priv->folder_id, &_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 = 0;
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		return result;
	}
	if (!geary_imap_db_folder_list_flags_include_marked_for_remove (flags)) {
		_tmp12_ = geary_imap_db_folder_do_get_marked_removed_count (self, cx, cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gint _tmp13_ = -1;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			return _tmp13_;
		}
	} else {
		_tmp12_ = 0;
	}
	marked = _tmp12_;
	_tmp15_ = results;
	_tmp14_ = geary_db_result_int_at (_tmp15_, 0, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp16_ = -1;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		return _tmp16_;
	}
	result = geary_numeric_int_floor (_tmp14_ - marked, 0);
	_g_object_unref0 (results);
	_g_object_unref0 (stmt);
	return result;
}

static gint
geary_imap_db_folder_do_get_marked_removed_count (GearyImapDBFolder* self,
                                                  GearyDbConnection* cx,
                                                  GCancellable* cancellable,
                                                  GError** error)
{
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbStatement* _tmp6_;
	GearyDbStatement* _tmp7_;
	GearyDbStatement* _tmp8_;
	GearyDbResult* results = NULL;
	GearyDbStatement* _tmp10_;
	GearyDbResult* _tmp11_;
	gint _tmp13_ = 0;
	GearyDbResult* _tmp14_;
	gboolean _tmp15_;
	gboolean _tmp16_;
	GError* _inner_error0_ = NULL;
	gint result;
	g_return_val_if_fail (GEARY_IMAP_DB_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 MessageLocationTable WHERE folder_id=? AND remove" \
"_marker <> ?", &_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_rowid (_tmp2_, 0, self->priv->folder_id, &_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_bind_bool (_tmp6_, 1, FALSE, &_inner_error0_);
	_tmp8_ = _tmp7_;
	_g_object_unref0 (_tmp8_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp9_ = -1;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return _tmp9_;
	}
	_tmp10_ = stmt;
	_tmp11_ = geary_db_statement_exec (_tmp10_, cancellable, &_inner_error0_);
	results = _tmp11_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp12_ = -1;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return _tmp12_;
	}
	_tmp14_ = results;
	_tmp15_ = geary_db_result_get_finished (_tmp14_);
	_tmp16_ = _tmp15_;
	if (!_tmp16_) {
		GearyDbResult* _tmp17_;
		_tmp17_ = results;
		_tmp13_ = geary_db_result_int_at (_tmp17_, 0, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gint _tmp18_ = -1;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			return _tmp18_;
		}
	} else {
		_tmp13_ = 0;
	}
	result = _tmp13_;
	_g_object_unref0 (results);
	_g_object_unref0 (stmt);
	return result;
}

static void
geary_imap_db_folder_do_mark_unmark_removed (GearyImapDBFolder* self,
                                             GearyDbConnection* cx,
                                             GeeCollection* uids,
                                             gboolean mark_removed,
                                             GCancellable* cancellable,
                                             GError** error)
{
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp1_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbStatement* _tmp5_;
	GearyDbStatement* _tmp6_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_DB_IS_CONNECTION (cx));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (uids, GEE_TYPE_COLLECTION));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_tmp0_ = geary_db_connection_prepare (cx, "UPDATE MessageLocationTable SET remove_marker=? WHERE folder_id=? AND " \
"ordering=?", &_inner_error0_);
	stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	_tmp1_ = stmt;
	_tmp2_ = geary_db_statement_bind_bool (_tmp1_, 0, mark_removed, &_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;
	}
	_tmp4_ = stmt;
	_tmp5_ = geary_db_statement_bind_rowid (_tmp4_, 1, self->priv->folder_id, &_inner_error0_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp6_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	{
		GeeIterator* _uid_it = NULL;
		GeeIterator* _tmp7_;
		_tmp7_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (uids, GEE_TYPE_ITERABLE, GeeIterable));
		_uid_it = _tmp7_;
		while (TRUE) {
			GeeIterator* _tmp8_;
			GearyImapUID* uid = NULL;
			GeeIterator* _tmp9_;
			gpointer _tmp10_;
			GearyDbStatement* _tmp11_;
			GearyImapUID* _tmp12_;
			gint64 _tmp13_;
			gint64 _tmp14_;
			GearyDbStatement* _tmp15_;
			GearyDbStatement* _tmp16_;
			GearyDbStatement* _tmp17_;
			GearyDbResult* _tmp18_;
			GearyDbResult* _tmp19_;
			GearyDbStatement* _tmp20_;
			GearyDbStatement* _tmp21_;
			GearyDbStatement* _tmp22_;
			_tmp8_ = _uid_it;
			if (!gee_iterator_next (_tmp8_)) {
				break;
			}
			_tmp9_ = _uid_it;
			_tmp10_ = gee_iterator_get (_tmp9_);
			uid = (GearyImapUID*) _tmp10_;
			_tmp11_ = stmt;
			_tmp12_ = uid;
			_tmp13_ = geary_message_data_int64_message_data_get_value (G_TYPE_CHECK_INSTANCE_CAST (_tmp12_, GEARY_MESSAGE_DATA_TYPE_INT64_MESSAGE_DATA, GearyMessageDataInt64MessageData));
			_tmp14_ = _tmp13_;
			_tmp15_ = geary_db_statement_bind_int64 (_tmp11_, 2, _tmp14_, &_inner_error0_);
			_tmp16_ = _tmp15_;
			_g_object_unref0 (_tmp16_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (uid);
				_g_object_unref0 (_uid_it);
				_g_object_unref0 (stmt);
				return;
			}
			_tmp17_ = stmt;
			_tmp18_ = geary_db_statement_exec (_tmp17_, cancellable, &_inner_error0_);
			_tmp19_ = _tmp18_;
			_g_object_unref0 (_tmp19_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (uid);
				_g_object_unref0 (_uid_it);
				_g_object_unref0 (stmt);
				return;
			}
			_tmp20_ = stmt;
			_tmp21_ = geary_db_statement_reset (_tmp20_, GEARY_DB_RESET_SCOPE_SAVE_BINDINGS, &_inner_error0_);
			_tmp22_ = _tmp21_;
			_g_object_unref0 (_tmp22_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (uid);
				_g_object_unref0 (_uid_it);
				_g_object_unref0 (stmt);
				return;
			}
			_g_object_unref0 (uid);
		}
		_g_object_unref0 (_uid_it);
	}
	_g_object_unref0 (stmt);
}

/**
     * Returns the id of any existing message matching the given.
     *
     * Searches for an existing message that matches `email`, based on
     * its message attributes. Currently, since ImapDB only requests
     * the IMAP internal date and RFC822 message size, these are the
     * only attributes used.
     *
     * The unique, internal message ID of the first matching message
     * is returned, else `-1` if no matching message was found.
     *
     * This should only be called on messages obtained via the IMAP
     * stack.
     */
static gint64
geary_imap_db_folder_do_search_for_duplicates (GearyImapDBFolder* self,
                                               GearyDbConnection* cx,
                                               GearyEmail* email,
                                               GearyImapDBEmailIdentifier* email_id,
                                               GCancellable* cancellable,
                                               GError** error)
{
	gint64 id = 0LL;
	GearyEmailField _tmp0_;
	GearyEmailField _tmp1_;
	GearyImapEmailProperties* imap_properties = NULL;
	GearyEmailProperties* _tmp12_;
	GearyEmailProperties* _tmp13_;
	GearyImapEmailProperties* _tmp14_;
	gchar* _tmp15_ = NULL;
	gboolean _tmp16_ = FALSE;
	GearyImapEmailProperties* _tmp17_;
	gchar* internaldate = NULL;
	gchar* _tmp25_;
	gint64 _tmp26_ = 0LL;
	GearyImapEmailProperties* _tmp27_;
	gint64 rfc822_size = 0LL;
	gboolean _tmp33_ = FALSE;
	const gchar* _tmp34_;
	GearyDbStatement* stmt = NULL;
	GearyRFC822MessageID* _tmp43_;
	GearyRFC822MessageID* _tmp44_;
	GearyDbStatement* _tmp53_;
	const gchar* _tmp54_;
	GearyDbStatement* _tmp55_;
	GearyDbStatement* _tmp56_;
	GearyDbStatement* _tmp58_;
	GearyDbStatement* _tmp59_;
	GearyDbStatement* _tmp60_;
	GearyRFC822MessageID* _tmp62_;
	GearyRFC822MessageID* _tmp63_;
	GearyDbResult* results = NULL;
	GearyDbStatement* _tmp72_;
	GearyDbResult* _tmp73_;
	GearyDbResult* _tmp75_;
	gboolean _tmp76_;
	gboolean _tmp77_;
	GError* _inner_error0_ = NULL;
	gint64 result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_FOLDER (self), 0LL);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0LL);
	g_return_val_if_fail (GEARY_IS_EMAIL (email), 0LL);
	g_return_val_if_fail (GEARY_IMAP_DB_IS_EMAIL_IDENTIFIER (email_id), 0LL);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), 0LL);
	id = (gint64) -1;
	_tmp0_ = geary_email_get_fields (email);
	_tmp1_ = _tmp0_;
	if (!geary_email_field_is_all_set (_tmp1_, GEARY_IMAP_DB_FOLDER_REQUIRED_FIELDS)) {
		gchar* _tmp2_;
		gchar* _tmp3_;
		GearyEmailIdentifier* _tmp4_;
		GearyEmailIdentifier* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		GearyEmailField _tmp8_;
		GearyEmailField _tmp9_;
		gchar* _tmp10_;
		gchar* _tmp11_;
		_tmp2_ = geary_imap_db_folder_to_string (self);
		_tmp3_ = _tmp2_;
		_tmp4_ = geary_email_get_id (email);
		_tmp5_ = _tmp4_;
		_tmp6_ = geary_email_identifier_to_string (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = geary_email_get_fields (email);
		_tmp9_ = _tmp8_;
		_tmp10_ = geary_email_field_to_string (_tmp9_);
		_tmp11_ = _tmp10_;
		g_debug ("imap-db-folder.vala:1481: %s: Unable to detect duplicates for %s, fiel" \
"ds available: %s", _tmp3_, _tmp7_, _tmp11_);
		_g_free0 (_tmp11_);
		_g_free0 (_tmp7_);
		_g_free0 (_tmp3_);
		result = id;
		return result;
	}
	_tmp12_ = geary_email_get_properties (email);
	_tmp13_ = _tmp12_;
	_tmp14_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp13_, GEARY_IMAP_TYPE_EMAIL_PROPERTIES, GearyImapEmailProperties));
	imap_properties = _tmp14_;
	_tmp17_ = imap_properties;
	if (_tmp17_ != NULL) {
		GearyImapEmailProperties* _tmp18_;
		GearyImapInternalDate* _tmp19_;
		GearyImapInternalDate* _tmp20_;
		_tmp18_ = imap_properties;
		_tmp19_ = geary_imap_email_properties_get_internaldate (_tmp18_);
		_tmp20_ = _tmp19_;
		_tmp16_ = _tmp20_ != NULL;
	} else {
		_tmp16_ = FALSE;
	}
	if (_tmp16_) {
		GearyImapEmailProperties* _tmp21_;
		GearyImapInternalDate* _tmp22_;
		GearyImapInternalDate* _tmp23_;
		gchar* _tmp24_;
		_tmp21_ = imap_properties;
		_tmp22_ = geary_imap_email_properties_get_internaldate (_tmp21_);
		_tmp23_ = _tmp22_;
		_tmp24_ = geary_imap_internal_date_serialize (_tmp23_);
		_g_free0 (_tmp15_);
		_tmp15_ = _tmp24_;
	} else {
		_g_free0 (_tmp15_);
		_tmp15_ = NULL;
	}
	_tmp25_ = g_strdup (_tmp15_);
	internaldate = _tmp25_;
	_tmp27_ = imap_properties;
	if (_tmp27_ != NULL) {
		GearyImapEmailProperties* _tmp28_;
		GearyImapRFC822Size* _tmp29_;
		GearyImapRFC822Size* _tmp30_;
		gint64 _tmp31_;
		gint64 _tmp32_;
		_tmp28_ = imap_properties;
		_tmp29_ = geary_imap_email_properties_get_rfc822_size (_tmp28_);
		_tmp30_ = _tmp29_;
		_tmp31_ = geary_message_data_int64_message_data_get_value (G_TYPE_CHECK_INSTANCE_CAST (_tmp30_, GEARY_MESSAGE_DATA_TYPE_INT64_MESSAGE_DATA, GearyMessageDataInt64MessageData));
		_tmp32_ = _tmp31_;
		_tmp26_ = _tmp32_;
	} else {
		_tmp26_ = (gint64) -1;
	}
	rfc822_size = _tmp26_;
	_tmp34_ = internaldate;
	if (geary_string_is_empty (_tmp34_)) {
		_tmp33_ = TRUE;
	} else {
		_tmp33_ = rfc822_size < ((gint64) 0);
	}
	if (_tmp33_) {
		GearyEmailIdentifier* _tmp35_;
		GearyEmailIdentifier* _tmp36_;
		gchar* _tmp37_;
		gchar* _tmp38_;
		GearyEmailField _tmp39_;
		GearyEmailField _tmp40_;
		gchar* _tmp41_;
		gchar* _tmp42_;
		_tmp35_ = geary_email_get_id (email);
		_tmp36_ = _tmp35_;
		_tmp37_ = geary_email_identifier_to_string (_tmp36_);
		_tmp38_ = _tmp37_;
		_tmp39_ = geary_email_get_fields (email);
		_tmp40_ = _tmp39_;
		_tmp41_ = geary_email_field_to_string (_tmp40_);
		_tmp42_ = _tmp41_;
		g_debug ("imap-db-folder.vala:1498: Unable to detect duplicates for %s (%s avail" \
"able but invalid)", _tmp38_, _tmp42_);
		_g_free0 (_tmp42_);
		_g_free0 (_tmp38_);
		result = id;
		_g_free0 (internaldate);
		_g_free0 (_tmp15_);
		_g_object_unref0 (imap_properties);
		return result;
	}
	_tmp43_ = geary_email_header_set_get_message_id (G_TYPE_CHECK_INSTANCE_CAST (email, GEARY_TYPE_EMAIL_HEADER_SET, GearyEmailHeaderSet));
	_tmp44_ = _tmp43_;
	if (_tmp44_ != NULL) {
		GearyDbStatement* _tmp45_ = NULL;
		GearyDbStatement* _tmp46_;
		GearyDbStatement* _tmp48_;
		_tmp46_ = geary_db_connection_prepare (cx, "SELECT id FROM MessageTable WHERE internaldate=? AND rfc822_size=? AND" \
" message_id=?", &_inner_error0_);
		_tmp45_ = _tmp46_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gint64 _tmp47_ = -1LL;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_g_free0 (internaldate);
			_g_free0 (_tmp15_);
			_g_object_unref0 (imap_properties);
			return _tmp47_;
		}
		_tmp48_ = _tmp45_;
		_tmp45_ = NULL;
		_g_object_unref0 (stmt);
		stmt = _tmp48_;
		_g_object_unref0 (_tmp45_);
	} else {
		GearyDbStatement* _tmp49_ = NULL;
		GearyDbStatement* _tmp50_;
		GearyDbStatement* _tmp52_;
		_tmp50_ = geary_db_connection_prepare (cx, "SELECT id FROM MessageTable WHERE internaldate=? AND rfc822_size=?", &_inner_error0_);
		_tmp49_ = _tmp50_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gint64 _tmp51_ = -1LL;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_g_free0 (internaldate);
			_g_free0 (_tmp15_);
			_g_object_unref0 (imap_properties);
			return _tmp51_;
		}
		_tmp52_ = _tmp49_;
		_tmp49_ = NULL;
		_g_object_unref0 (stmt);
		stmt = _tmp52_;
		_g_object_unref0 (_tmp49_);
	}
	_tmp53_ = stmt;
	_tmp54_ = internaldate;
	_tmp55_ = geary_db_statement_bind_string (_tmp53_, 0, _tmp54_, &_inner_error0_);
	_tmp56_ = _tmp55_;
	_g_object_unref0 (_tmp56_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint64 _tmp57_ = -1LL;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_free0 (internaldate);
		_g_free0 (_tmp15_);
		_g_object_unref0 (imap_properties);
		return _tmp57_;
	}
	_tmp58_ = stmt;
	_tmp59_ = geary_db_statement_bind_int64 (_tmp58_, 1, rfc822_size, &_inner_error0_);
	_tmp60_ = _tmp59_;
	_g_object_unref0 (_tmp60_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint64 _tmp61_ = -1LL;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_free0 (internaldate);
		_g_free0 (_tmp15_);
		_g_object_unref0 (imap_properties);
		return _tmp61_;
	}
	_tmp62_ = geary_email_header_set_get_message_id (G_TYPE_CHECK_INSTANCE_CAST (email, GEARY_TYPE_EMAIL_HEADER_SET, GearyEmailHeaderSet));
	_tmp63_ = _tmp62_;
	if (_tmp63_ != NULL) {
		GearyDbStatement* _tmp64_;
		GearyRFC822MessageID* _tmp65_;
		GearyRFC822MessageID* _tmp66_;
		gchar* _tmp67_;
		gchar* _tmp68_;
		GearyDbStatement* _tmp69_;
		GearyDbStatement* _tmp70_;
		_tmp64_ = stmt;
		_tmp65_ = geary_email_header_set_get_message_id (G_TYPE_CHECK_INSTANCE_CAST (email, GEARY_TYPE_EMAIL_HEADER_SET, GearyEmailHeaderSet));
		_tmp66_ = _tmp65_;
		_tmp67_ = geary_rf_c822_decoded_message_data_to_rfc822_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp66_, GEARY_RF_C822_TYPE_DECODED_MESSAGE_DATA, GearyRFC822DecodedMessageData));
		_tmp68_ = _tmp67_;
		_tmp69_ = geary_db_statement_bind_string (_tmp64_, 2, _tmp68_, &_inner_error0_);
		_tmp70_ = _tmp69_;
		_g_object_unref0 (_tmp70_);
		_g_free0 (_tmp68_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gint64 _tmp71_ = -1LL;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_g_free0 (internaldate);
			_g_free0 (_tmp15_);
			_g_object_unref0 (imap_properties);
			return _tmp71_;
		}
	}
	_tmp72_ = stmt;
	_tmp73_ = geary_db_statement_exec (_tmp72_, cancellable, &_inner_error0_);
	results = _tmp73_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint64 _tmp74_ = -1LL;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_free0 (internaldate);
		_g_free0 (_tmp15_);
		_g_object_unref0 (imap_properties);
		return _tmp74_;
	}
	_tmp75_ = results;
	_tmp76_ = geary_db_result_get_finished (_tmp75_);
	_tmp77_ = _tmp76_;
	if (!_tmp77_) {
		gint64 _tmp78_ = 0LL;
		GearyDbResult* _tmp79_;
		_tmp79_ = results;
		_tmp78_ = geary_db_result_int64_at (_tmp79_, 0, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gint64 _tmp80_ = -1LL;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			_g_free0 (internaldate);
			_g_free0 (_tmp15_);
			_g_object_unref0 (imap_properties);
			return _tmp80_;
		}
		id = _tmp78_;
	}
	result = id;
	_g_object_unref0 (results);
	_g_object_unref0 (stmt);
	_g_free0 (internaldate);
	_g_free0 (_tmp15_);
	_g_object_unref0 (imap_properties);
	return result;
}

/**
     * Adds a message to the folder.
     *
     * Note: does NOT check if message is already associated with this
     * folder.
     */
static void
geary_imap_db_folder_do_associate_with_folder (GearyImapDBFolder* self,
                                               GearyDbConnection* cx,
                                               gint64 message_id,
                                               GearyImapUID* uid,
                                               GCancellable* cancellable,
                                               GError** error)
{
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp1_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbStatement* _tmp5_;
	GearyDbStatement* _tmp6_;
	GearyDbStatement* _tmp7_;
	gint64 _tmp8_;
	gint64 _tmp9_;
	GearyDbStatement* _tmp10_;
	GearyDbStatement* _tmp11_;
	GearyDbStatement* _tmp12_;
	GearyDbResult* _tmp13_;
	GearyDbResult* _tmp14_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_DB_IS_CONNECTION (cx));
	g_return_if_fail (GEARY_IMAP_IS_UID (uid));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_tmp0_ = geary_db_connection_prepare (cx, "INSERT INTO MessageLocationTable (message_id, folder_id, ordering) VAL" \
"UES (?, ?, ?)", &_inner_error0_);
	stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	_tmp1_ = stmt;
	_tmp2_ = geary_db_statement_bind_rowid (_tmp1_, 0, message_id, &_inner_error0_);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp3_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	_tmp4_ = stmt;
	_tmp5_ = geary_db_statement_bind_rowid (_tmp4_, 1, self->priv->folder_id, &_inner_error0_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp6_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	_tmp7_ = stmt;
	_tmp8_ = geary_message_data_int64_message_data_get_value (G_TYPE_CHECK_INSTANCE_CAST (uid, GEARY_MESSAGE_DATA_TYPE_INT64_MESSAGE_DATA, GearyMessageDataInt64MessageData));
	_tmp9_ = _tmp8_;
	_tmp10_ = geary_db_statement_bind_int64 (_tmp7_, 2, _tmp9_, &_inner_error0_);
	_tmp11_ = _tmp10_;
	_g_object_unref0 (_tmp11_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	_tmp12_ = stmt;
	_tmp13_ = geary_db_statement_exec (_tmp12_, cancellable, &_inner_error0_);
	_tmp14_ = _tmp13_;
	_g_object_unref0 (_tmp14_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	_g_object_unref0 (stmt);
}

static void
geary_imap_db_folder_do_remove_association_with_folder (GearyImapDBFolder* self,
                                                        GearyDbConnection* cx,
                                                        GearyImapDBFolderLocationIdentifier* location,
                                                        GCancellable* cancellable,
                                                        GError** error)
{
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp1_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbStatement* _tmp5_;
	GearyDbStatement* _tmp6_;
	GearyDbStatement* _tmp7_;
	GearyDbResult* _tmp8_;
	GearyDbResult* _tmp9_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_DB_IS_CONNECTION (cx));
	g_return_if_fail (GEARY_IMAP_DB_FOLDER_IS_LOCATION_IDENTIFIER (location));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_tmp0_ = geary_db_connection_prepare (cx, "DELETE FROM MessageLocationTable WHERE folder_id=? AND message_id=?", &_inner_error0_);
	stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	_tmp1_ = stmt;
	_tmp2_ = geary_db_statement_bind_rowid (_tmp1_, 0, self->priv->folder_id, &_inner_error0_);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp3_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	_tmp4_ = stmt;
	_tmp5_ = geary_db_statement_bind_int64 (_tmp4_, 1, location->message_id, &_inner_error0_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp6_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	_tmp7_ = stmt;
	_tmp8_ = geary_db_statement_exec (_tmp7_, cancellable, &_inner_error0_);
	_tmp9_ = _tmp8_;
	_g_object_unref0 (_tmp9_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	_g_object_unref0 (stmt);
}

/**
     * Adds a single message to the folder, creating or merging it.
     *
     * This creates the message and appends it to the folder if the
     * message does not already exist, else appends and merges if the
     * message exists but not in the given position in this folder,
     * else it exists in the given position, so simply merges it.
     *
     * Returns `true` if created, else was merged and returns `false`.
     */
static gboolean
geary_imap_db_folder_do_create_or_merge_email (GearyImapDBFolder* self,
                                               GearyDbConnection* cx,
                                               GearyEmail* email,
                                               GearyEmailField* pre_fields,
                                               GearyEmailField* post_fields,
                                               gint* unread_count_change,
                                               GCancellable* cancellable,
                                               GError** error)
{
	GearyEmailField _vala_pre_fields = 0;
	GearyEmailField _vala_post_fields = 0;
	GearyImapDBEmailIdentifier* email_id = NULL;
	GearyEmailIdentifier* _tmp0_;
	GearyEmailIdentifier* _tmp1_;
	GearyImapDBEmailIdentifier* _tmp2_;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_ = FALSE;
	GearyImapDBEmailIdentifier* _tmp5_;
	gint64 message_id = 0LL;
	gboolean is_associated = FALSE;
	GearyImapDBFolderLocationIdentifier* location = NULL;
	GearyImapDBEmailIdentifier* _tmp14_;
	GearyImapUID* _tmp15_;
	GearyImapUID* _tmp16_;
	GearyImapDBFolderLocationIdentifier* _tmp17_;
	GearyImapDBFolderLocationIdentifier* _tmp19_;
	gboolean was_created = FALSE;
	GearyImapDBFolderLocationIdentifier* _tmp28_;
	GearyImapDBEmailIdentifier* _tmp207_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_FOLDER (self), FALSE);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), FALSE);
	g_return_val_if_fail (GEARY_IS_EMAIL (email), FALSE);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), FALSE);
	_tmp0_ = geary_email_get_id (email);
	_tmp1_ = _tmp0_;
	_tmp2_ = _g_object_ref0 (GEARY_IMAP_DB_IS_EMAIL_IDENTIFIER (_tmp1_) ? ((GearyImapDBEmailIdentifier*) _tmp1_) : NULL);
	email_id = _tmp2_;
	_tmp5_ = email_id;
	if (_tmp5_ == NULL) {
		_tmp4_ = TRUE;
	} else {
		GearyImapDBEmailIdentifier* _tmp6_;
		gint64 _tmp7_;
		gint64 _tmp8_;
		_tmp6_ = email_id;
		_tmp7_ = geary_imap_db_email_identifier_get_message_id (_tmp6_);
		_tmp8_ = _tmp7_;
		_tmp4_ = _tmp8_ != GEARY_DB_INVALID_ROWID;
	}
	if (_tmp4_) {
		_tmp3_ = TRUE;
	} else {
		GearyImapDBEmailIdentifier* _tmp9_;
		GearyImapUID* _tmp10_;
		GearyImapUID* _tmp11_;
		_tmp9_ = email_id;
		_tmp10_ = geary_imap_db_email_identifier_get_uid (_tmp9_);
		_tmp11_ = _tmp10_;
		_tmp3_ = _tmp11_ == NULL;
	}
	if (_tmp3_) {
		GError* _tmp12_;
		gboolean _tmp13_ = FALSE;
		_tmp12_ = g_error_new_literal (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_BAD_PARAMETERS, "IMAP message with UID required");
		_inner_error0_ = _tmp12_;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (email_id);
		return _tmp13_;
	}
	message_id = (gint64) -1;
	is_associated = FALSE;
	_tmp14_ = email_id;
	_tmp15_ = geary_imap_db_email_identifier_get_uid (_tmp14_);
	_tmp16_ = _tmp15_;
	_tmp17_ = geary_imap_db_folder_do_get_location_for_uid (self, cx, _tmp16_, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDE_MARKED_FOR_REMOVE, cancellable, &_inner_error0_);
	location = _tmp17_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp18_ = FALSE;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (email_id);
		return _tmp18_;
	}
	_tmp19_ = location;
	if (_tmp19_ != NULL) {
		GearyImapDBFolderLocationIdentifier* _tmp20_;
		_tmp20_ = location;
		message_id = _tmp20_->message_id;
		is_associated = TRUE;
	} else {
		gint64 _tmp21_ = 0LL;
		GearyImapDBEmailIdentifier* _tmp22_;
		_tmp22_ = email_id;
		_tmp21_ = geary_imap_db_folder_do_search_for_duplicates (self, cx, email, _tmp22_, cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp23_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp23_;
		}
		message_id = _tmp21_;
		if (message_id >= ((gint64) 0)) {
			GearyImapDBEmailIdentifier* _tmp24_;
			GearyImapUID* _tmp25_;
			GearyImapUID* _tmp26_;
			GearyImapDBFolderLocationIdentifier* _tmp27_;
			_tmp24_ = email_id;
			_tmp25_ = geary_imap_db_email_identifier_get_uid (_tmp24_);
			_tmp26_ = _tmp25_;
			_tmp27_ = geary_imap_db_folder_location_identifier_new (message_id, _tmp26_, FALSE);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			location = _tmp27_;
		}
	}
	was_created = FALSE;
	_tmp28_ = location;
	if (_tmp28_ != NULL) {
		GearyEmailField _tmp29_;
		GearyEmailField _tmp30_;
		_tmp29_ = geary_email_get_fields (email);
		_tmp30_ = _tmp29_;
		if (_tmp30_ != GEARY_EMAIL_FIELD_FLAGS) {
			GearyImapDBFolderLocationIdentifier* _tmp31_;
			GearyEmailField _tmp32_ = 0;
			GearyEmailField _tmp33_ = 0;
			gboolean _tmp35_ = FALSE;
			_tmp31_ = location;
			geary_imap_db_folder_do_merge_email (self, cx, _tmp31_, email, &_tmp32_, &_tmp33_, unread_count_change, cancellable, &_inner_error0_);
			_vala_pre_fields = _tmp32_;
			_vala_post_fields = _tmp33_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				gboolean _tmp34_ = FALSE;
				g_propagate_error (error, _inner_error0_);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (email_id);
				return _tmp34_;
			}
			if (is_associated) {
				_tmp35_ = geary_email_field_is_all_set (_vala_pre_fields, GEARY_EMAIL_FIELD_FLAGS);
			} else {
				_tmp35_ = FALSE;
			}
			if (_tmp35_) {
				*unread_count_change = 0;
			}
		} else {
			GearyImapDBFolderLocationIdentifier* _tmp36_;
			GearyEmailField _tmp37_ = 0;
			GearyEmailField _tmp38_ = 0;
			_tmp36_ = location;
			geary_imap_db_folder_do_merge_email_flags (self, cx, _tmp36_, email, &_tmp37_, &_tmp38_, unread_count_change, cancellable, &_inner_error0_);
			_vala_pre_fields = _tmp37_;
			_vala_post_fields = _tmp38_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				gboolean _tmp39_ = FALSE;
				g_propagate_error (error, _inner_error0_);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (email_id);
				return _tmp39_;
			}
		}
	} else {
		GearyImapDBMessageRow* row = NULL;
		GearyImapDBMessageRow* _tmp40_;
		GearyEmailField _tmp41_;
		GearyEmailField _tmp42_;
		GearyDbStatement* stmt = NULL;
		GearyDbStatement* _tmp43_;
		GearyDbStatement* _tmp45_;
		GearyImapDBMessageRow* _tmp46_;
		GearyEmailField _tmp47_;
		GearyEmailField _tmp48_;
		GearyDbStatement* _tmp49_;
		GearyDbStatement* _tmp50_;
		GearyDbStatement* _tmp52_;
		GearyImapDBMessageRow* _tmp53_;
		const gchar* _tmp54_;
		const gchar* _tmp55_;
		GearyDbStatement* _tmp56_;
		GearyDbStatement* _tmp57_;
		GearyDbStatement* _tmp59_;
		GearyImapDBMessageRow* _tmp60_;
		gint64 _tmp61_;
		gint64 _tmp62_;
		GearyDbStatement* _tmp63_;
		GearyDbStatement* _tmp64_;
		GearyDbStatement* _tmp66_;
		GearyImapDBMessageRow* _tmp67_;
		const gchar* _tmp68_;
		const gchar* _tmp69_;
		GearyDbStatement* _tmp70_;
		GearyDbStatement* _tmp71_;
		GearyDbStatement* _tmp73_;
		GearyImapDBMessageRow* _tmp74_;
		const gchar* _tmp75_;
		const gchar* _tmp76_;
		GearyDbStatement* _tmp77_;
		GearyDbStatement* _tmp78_;
		GearyDbStatement* _tmp80_;
		GearyImapDBMessageRow* _tmp81_;
		const gchar* _tmp82_;
		const gchar* _tmp83_;
		GearyDbStatement* _tmp84_;
		GearyDbStatement* _tmp85_;
		GearyDbStatement* _tmp87_;
		GearyImapDBMessageRow* _tmp88_;
		const gchar* _tmp89_;
		const gchar* _tmp90_;
		GearyDbStatement* _tmp91_;
		GearyDbStatement* _tmp92_;
		GearyDbStatement* _tmp94_;
		GearyImapDBMessageRow* _tmp95_;
		const gchar* _tmp96_;
		const gchar* _tmp97_;
		GearyDbStatement* _tmp98_;
		GearyDbStatement* _tmp99_;
		GearyDbStatement* _tmp101_;
		GearyImapDBMessageRow* _tmp102_;
		const gchar* _tmp103_;
		const gchar* _tmp104_;
		GearyDbStatement* _tmp105_;
		GearyDbStatement* _tmp106_;
		GearyDbStatement* _tmp108_;
		GearyImapDBMessageRow* _tmp109_;
		const gchar* _tmp110_;
		const gchar* _tmp111_;
		GearyDbStatement* _tmp112_;
		GearyDbStatement* _tmp113_;
		GearyDbStatement* _tmp115_;
		GearyImapDBMessageRow* _tmp116_;
		const gchar* _tmp117_;
		const gchar* _tmp118_;
		GearyDbStatement* _tmp119_;
		GearyDbStatement* _tmp120_;
		GearyDbStatement* _tmp122_;
		GearyImapDBMessageRow* _tmp123_;
		const gchar* _tmp124_;
		const gchar* _tmp125_;
		GearyDbStatement* _tmp126_;
		GearyDbStatement* _tmp127_;
		GearyDbStatement* _tmp129_;
		GearyImapDBMessageRow* _tmp130_;
		const gchar* _tmp131_;
		const gchar* _tmp132_;
		GearyDbStatement* _tmp133_;
		GearyDbStatement* _tmp134_;
		GearyDbStatement* _tmp136_;
		GearyImapDBMessageRow* _tmp137_;
		GearyMemoryBuffer* _tmp138_;
		GearyMemoryBuffer* _tmp139_;
		GearyDbStatement* _tmp140_;
		GearyDbStatement* _tmp141_;
		GearyDbStatement* _tmp143_;
		GearyImapDBMessageRow* _tmp144_;
		GearyMemoryBuffer* _tmp145_;
		GearyMemoryBuffer* _tmp146_;
		GearyDbStatement* _tmp147_;
		GearyDbStatement* _tmp148_;
		GearyDbStatement* _tmp150_;
		GearyImapDBMessageRow* _tmp151_;
		const gchar* _tmp152_;
		const gchar* _tmp153_;
		GearyDbStatement* _tmp154_;
		GearyDbStatement* _tmp155_;
		GearyDbStatement* _tmp157_;
		GearyImapDBMessageRow* _tmp158_;
		const gchar* _tmp159_;
		const gchar* _tmp160_;
		GearyDbStatement* _tmp161_;
		GearyDbStatement* _tmp162_;
		GearyDbStatement* _tmp164_;
		GearyImapDBMessageRow* _tmp165_;
		const gchar* _tmp166_;
		const gchar* _tmp167_;
		GearyDbStatement* _tmp168_;
		GearyDbStatement* _tmp169_;
		GearyDbStatement* _tmp171_;
		GearyImapDBMessageRow* _tmp172_;
		gint64 _tmp173_;
		gint64 _tmp174_;
		GearyDbStatement* _tmp175_;
		GearyDbStatement* _tmp176_;
		GearyDbStatement* _tmp178_;
		GearyImapDBMessageRow* _tmp179_;
		gint64 _tmp180_;
		gint64 _tmp181_;
		GearyDbStatement* _tmp182_;
		GearyDbStatement* _tmp183_;
		gint64 _tmp185_ = 0LL;
		GearyDbStatement* _tmp186_;
		GearyEmailField _tmp188_;
		GearyEmailField _tmp189_;
		gboolean _tmp201_ = FALSE;
		GearyEmailFlags* _tmp202_;
		GearyEmailFlags* _tmp203_;
		was_created = TRUE;
		_tmp40_ = geary_imap_db_message_row_new_from_email (email);
		row = _tmp40_;
		_vala_pre_fields = GEARY_EMAIL_FIELD_NONE;
		_tmp41_ = geary_email_get_fields (email);
		_tmp42_ = _tmp41_;
		_vala_post_fields = _tmp42_;
		_tmp43_ = geary_db_connection_prepare (cx, "INSERT INTO MessageTable " "(fields, date_field, date_time_t, from_field, sender, reply_to, to_fie" \
"ld, cc, bcc, " "message_id, in_reply_to, reference_ids, subject, header, body, preview" \
", flags, " "internaldate, internaldate_time_t, rfc822_size) " "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", &_inner_error0_);
		stmt = _tmp43_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp44_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp44_;
		}
		_tmp45_ = stmt;
		_tmp46_ = row;
		_tmp47_ = geary_imap_db_message_row_get_fields (_tmp46_);
		_tmp48_ = _tmp47_;
		_tmp49_ = geary_db_statement_bind_int (_tmp45_, 0, (gint) _tmp48_, &_inner_error0_);
		_tmp50_ = _tmp49_;
		_g_object_unref0 (_tmp50_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp51_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp51_;
		}
		_tmp52_ = stmt;
		_tmp53_ = row;
		_tmp54_ = geary_imap_db_message_row_get_date (_tmp53_);
		_tmp55_ = _tmp54_;
		_tmp56_ = geary_db_statement_bind_string (_tmp52_, 1, _tmp55_, &_inner_error0_);
		_tmp57_ = _tmp56_;
		_g_object_unref0 (_tmp57_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp58_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp58_;
		}
		_tmp59_ = stmt;
		_tmp60_ = row;
		_tmp61_ = geary_imap_db_message_row_get_date_time_t (_tmp60_);
		_tmp62_ = _tmp61_;
		_tmp63_ = geary_db_statement_bind_int64 (_tmp59_, 2, _tmp62_, &_inner_error0_);
		_tmp64_ = _tmp63_;
		_g_object_unref0 (_tmp64_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp65_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp65_;
		}
		_tmp66_ = stmt;
		_tmp67_ = row;
		_tmp68_ = geary_imap_db_message_row_get_from (_tmp67_);
		_tmp69_ = _tmp68_;
		_tmp70_ = geary_db_statement_bind_string (_tmp66_, 3, _tmp69_, &_inner_error0_);
		_tmp71_ = _tmp70_;
		_g_object_unref0 (_tmp71_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp72_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp72_;
		}
		_tmp73_ = stmt;
		_tmp74_ = row;
		_tmp75_ = geary_imap_db_message_row_get_sender (_tmp74_);
		_tmp76_ = _tmp75_;
		_tmp77_ = geary_db_statement_bind_string (_tmp73_, 4, _tmp76_, &_inner_error0_);
		_tmp78_ = _tmp77_;
		_g_object_unref0 (_tmp78_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp79_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp79_;
		}
		_tmp80_ = stmt;
		_tmp81_ = row;
		_tmp82_ = geary_imap_db_message_row_get_reply_to (_tmp81_);
		_tmp83_ = _tmp82_;
		_tmp84_ = geary_db_statement_bind_string (_tmp80_, 5, _tmp83_, &_inner_error0_);
		_tmp85_ = _tmp84_;
		_g_object_unref0 (_tmp85_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp86_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp86_;
		}
		_tmp87_ = stmt;
		_tmp88_ = row;
		_tmp89_ = geary_imap_db_message_row_get_to (_tmp88_);
		_tmp90_ = _tmp89_;
		_tmp91_ = geary_db_statement_bind_string (_tmp87_, 6, _tmp90_, &_inner_error0_);
		_tmp92_ = _tmp91_;
		_g_object_unref0 (_tmp92_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp93_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp93_;
		}
		_tmp94_ = stmt;
		_tmp95_ = row;
		_tmp96_ = geary_imap_db_message_row_get_cc (_tmp95_);
		_tmp97_ = _tmp96_;
		_tmp98_ = geary_db_statement_bind_string (_tmp94_, 7, _tmp97_, &_inner_error0_);
		_tmp99_ = _tmp98_;
		_g_object_unref0 (_tmp99_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp100_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp100_;
		}
		_tmp101_ = stmt;
		_tmp102_ = row;
		_tmp103_ = geary_imap_db_message_row_get_bcc (_tmp102_);
		_tmp104_ = _tmp103_;
		_tmp105_ = geary_db_statement_bind_string (_tmp101_, 8, _tmp104_, &_inner_error0_);
		_tmp106_ = _tmp105_;
		_g_object_unref0 (_tmp106_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp107_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp107_;
		}
		_tmp108_ = stmt;
		_tmp109_ = row;
		_tmp110_ = geary_imap_db_message_row_get_message_id (_tmp109_);
		_tmp111_ = _tmp110_;
		_tmp112_ = geary_db_statement_bind_string (_tmp108_, 9, _tmp111_, &_inner_error0_);
		_tmp113_ = _tmp112_;
		_g_object_unref0 (_tmp113_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp114_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp114_;
		}
		_tmp115_ = stmt;
		_tmp116_ = row;
		_tmp117_ = geary_imap_db_message_row_get_in_reply_to (_tmp116_);
		_tmp118_ = _tmp117_;
		_tmp119_ = geary_db_statement_bind_string (_tmp115_, 10, _tmp118_, &_inner_error0_);
		_tmp120_ = _tmp119_;
		_g_object_unref0 (_tmp120_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp121_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp121_;
		}
		_tmp122_ = stmt;
		_tmp123_ = row;
		_tmp124_ = geary_imap_db_message_row_get_references (_tmp123_);
		_tmp125_ = _tmp124_;
		_tmp126_ = geary_db_statement_bind_string (_tmp122_, 11, _tmp125_, &_inner_error0_);
		_tmp127_ = _tmp126_;
		_g_object_unref0 (_tmp127_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp128_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp128_;
		}
		_tmp129_ = stmt;
		_tmp130_ = row;
		_tmp131_ = geary_imap_db_message_row_get_subject (_tmp130_);
		_tmp132_ = _tmp131_;
		_tmp133_ = geary_db_statement_bind_string (_tmp129_, 12, _tmp132_, &_inner_error0_);
		_tmp134_ = _tmp133_;
		_g_object_unref0 (_tmp134_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp135_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp135_;
		}
		_tmp136_ = stmt;
		_tmp137_ = row;
		_tmp138_ = geary_imap_db_message_row_get_header (_tmp137_);
		_tmp139_ = _tmp138_;
		_tmp140_ = geary_db_statement_bind_string_buffer (_tmp136_, 13, _tmp139_, &_inner_error0_);
		_tmp141_ = _tmp140_;
		_g_object_unref0 (_tmp141_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp142_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp142_;
		}
		_tmp143_ = stmt;
		_tmp144_ = row;
		_tmp145_ = geary_imap_db_message_row_get_body (_tmp144_);
		_tmp146_ = _tmp145_;
		_tmp147_ = geary_db_statement_bind_string_buffer (_tmp143_, 14, _tmp146_, &_inner_error0_);
		_tmp148_ = _tmp147_;
		_g_object_unref0 (_tmp148_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp149_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp149_;
		}
		_tmp150_ = stmt;
		_tmp151_ = row;
		_tmp152_ = geary_imap_db_message_row_get_preview (_tmp151_);
		_tmp153_ = _tmp152_;
		_tmp154_ = geary_db_statement_bind_string (_tmp150_, 15, _tmp153_, &_inner_error0_);
		_tmp155_ = _tmp154_;
		_g_object_unref0 (_tmp155_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp156_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp156_;
		}
		_tmp157_ = stmt;
		_tmp158_ = row;
		_tmp159_ = geary_imap_db_message_row_get_email_flags (_tmp158_);
		_tmp160_ = _tmp159_;
		_tmp161_ = geary_db_statement_bind_string (_tmp157_, 16, _tmp160_, &_inner_error0_);
		_tmp162_ = _tmp161_;
		_g_object_unref0 (_tmp162_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp163_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp163_;
		}
		_tmp164_ = stmt;
		_tmp165_ = row;
		_tmp166_ = geary_imap_db_message_row_get_internaldate (_tmp165_);
		_tmp167_ = _tmp166_;
		_tmp168_ = geary_db_statement_bind_string (_tmp164_, 17, _tmp167_, &_inner_error0_);
		_tmp169_ = _tmp168_;
		_g_object_unref0 (_tmp169_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp170_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp170_;
		}
		_tmp171_ = stmt;
		_tmp172_ = row;
		_tmp173_ = geary_imap_db_message_row_get_internaldate_time_t (_tmp172_);
		_tmp174_ = _tmp173_;
		_tmp175_ = geary_db_statement_bind_int64 (_tmp171_, 18, _tmp174_, &_inner_error0_);
		_tmp176_ = _tmp175_;
		_g_object_unref0 (_tmp176_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp177_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp177_;
		}
		_tmp178_ = stmt;
		_tmp179_ = row;
		_tmp180_ = geary_imap_db_message_row_get_rfc822_size (_tmp179_);
		_tmp181_ = _tmp180_;
		_tmp182_ = geary_db_statement_bind_int64 (_tmp178_, 19, _tmp181_, &_inner_error0_);
		_tmp183_ = _tmp182_;
		_g_object_unref0 (_tmp183_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp184_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp184_;
		}
		_tmp186_ = stmt;
		_tmp185_ = geary_db_statement_exec_insert (_tmp186_, cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp187_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp187_;
		}
		message_id = _tmp185_;
		_tmp188_ = geary_email_get_fields (email);
		_tmp189_ = _tmp188_;
		if (geary_email_field_fulfills (_tmp189_, GEARY_IMAP_DB_ATTACHMENT_REQUIRED_FIELDS)) {
			GearyRFC822Message* _tmp190_ = NULL;
			GearyRFC822Message* _tmp191_;
			GeeList* _tmp193_ = NULL;
			GeeList* _tmp194_;
			GFile* _tmp196_;
			GeeList* _tmp197_;
			GeeList* _tmp198_;
			_tmp191_ = geary_email_get_message (email, &_inner_error0_);
			_tmp190_ = _tmp191_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				gboolean _tmp192_ = FALSE;
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (stmt);
				_geary_imap_db_message_row_unref0 (row);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (email_id);
				return _tmp192_;
			}
			_tmp194_ = geary_rf_c822_message_get_attachments (_tmp190_, GEARY_MIME_DISPOSITION_TYPE_UNSPECIFIED, &_inner_error0_);
			_tmp193_ = _tmp194_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				gboolean _tmp195_ = FALSE;
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (_tmp190_);
				_g_object_unref0 (stmt);
				_geary_imap_db_message_row_unref0 (row);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (email_id);
				return _tmp195_;
			}
			_tmp196_ = self->priv->attachments_path;
			_tmp197_ = geary_imap_db_attachment_save_attachments (cx, _tmp196_, message_id, _tmp193_, cancellable, &_inner_error0_);
			_tmp198_ = _tmp197_;
			_g_object_unref0 (_tmp198_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				gboolean _tmp199_ = FALSE;
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (_tmp193_);
				_g_object_unref0 (_tmp190_);
				_g_object_unref0 (stmt);
				_geary_imap_db_message_row_unref0 (row);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (email_id);
				return _tmp199_;
			}
			_g_object_unref0 (_tmp193_);
			_g_object_unref0 (_tmp190_);
		}
		geary_imap_db_folder_do_add_email_to_search_table (cx, message_id, email, cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp200_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_geary_imap_db_message_row_unref0 (row);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp200_;
		}
		_tmp202_ = geary_email_get_email_flags (email);
		_tmp203_ = _tmp202_;
		if (_tmp203_ != NULL) {
			GearyEmailFlags* _tmp204_;
			GearyEmailFlags* _tmp205_;
			_tmp204_ = geary_email_get_email_flags (email);
			_tmp205_ = _tmp204_;
			_tmp201_ = geary_email_flags_is_unread (_tmp205_);
		} else {
			_tmp201_ = FALSE;
		}
		if (_tmp201_) {
			gint _tmp206_;
			_tmp206_ = *unread_count_change;
			*unread_count_change = _tmp206_ + 1;
		}
		_g_object_unref0 (stmt);
		_geary_imap_db_message_row_unref0 (row);
	}
	_tmp207_ = email_id;
	geary_imap_db_email_identifier_promote_with_message_id (_tmp207_, message_id);
	if (!is_associated) {
		GearyImapDBEmailIdentifier* _tmp208_;
		GearyImapUID* _tmp209_;
		GearyImapUID* _tmp210_;
		_tmp208_ = email_id;
		_tmp209_ = geary_imap_db_email_identifier_get_uid (_tmp208_);
		_tmp210_ = _tmp209_;
		geary_imap_db_folder_do_associate_with_folder (self, cx, message_id, _tmp210_, cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp211_ = FALSE;
			g_propagate_error (error, _inner_error0_);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (email_id);
			return _tmp211_;
		}
	}
	result = was_created;
	_geary_imap_db_folder_location_identifier_unref0 (location);
	_g_object_unref0 (email_id);
	if (pre_fields) {
		*pre_fields = _vala_pre_fields;
	}
	if (post_fields) {
		*post_fields = _vala_post_fields;
	}
	return result;
}

void
geary_imap_db_folder_do_add_email_to_search_table (GearyDbConnection* cx,
                                                   gint64 message_id,
                                                   GearyEmail* email,
                                                   GCancellable* cancellable,
                                                   GError** error)
{
	gchar* body = NULL;
	gchar* recipients = NULL;
	gchar* attachments = NULL;
	gchar* _tmp8_;
	gchar* _tmp9_ = NULL;
	GearyRFC822Subject* _tmp10_;
	GearyRFC822Subject* _tmp11_;
	gchar* subject = NULL;
	gchar* _tmp15_;
	gchar* _tmp16_ = NULL;
	GearyRFC822MailboxAddresses* _tmp17_;
	GearyRFC822MailboxAddresses* _tmp18_;
	gchar* from = NULL;
	gchar* _tmp22_;
	gchar* _tmp23_ = NULL;
	GearyRFC822MailboxAddresses* _tmp24_;
	GearyRFC822MailboxAddresses* _tmp25_;
	gchar* cc = NULL;
	gchar* _tmp29_;
	gchar* _tmp30_ = NULL;
	GearyRFC822MailboxAddresses* _tmp31_;
	GearyRFC822MailboxAddresses* _tmp32_;
	gchar* bcc = NULL;
	gchar* _tmp36_;
	gchar* _tmp37_ = NULL;
	GearyEmailFlags* _tmp38_;
	GearyEmailFlags* _tmp39_;
	gchar* flags = NULL;
	gchar* _tmp43_;
	gboolean _tmp44_ = FALSE;
	gboolean _tmp45_ = FALSE;
	gboolean _tmp46_ = FALSE;
	gboolean _tmp47_ = FALSE;
	gboolean _tmp48_ = FALSE;
	gboolean _tmp49_ = FALSE;
	gboolean _tmp50_ = FALSE;
	const gchar* _tmp51_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_DB_IS_CONNECTION (cx));
	g_return_if_fail (GEARY_IS_EMAIL (email));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	body = NULL;
	{
		GearyRFC822Message* _tmp0_ = NULL;
		GearyRFC822Message* _tmp1_;
		gchar* _tmp2_ = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_;
		_tmp1_ = geary_email_get_message (email, &_inner_error0_);
		_tmp0_ = _tmp1_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp3_ = geary_rf_c822_message_get_searchable_body (_tmp0_, TRUE, &_inner_error0_);
		_tmp2_ = _tmp3_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (_tmp0_);
			goto __catch0_g_error;
		}
		_tmp4_ = _tmp2_;
		_tmp2_ = NULL;
		_g_free0 (body);
		body = _tmp4_;
		_g_free0 (_tmp2_);
		_g_object_unref0 (_tmp0_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_inner_error0_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_free0 (body);
		return;
	}
	recipients = NULL;
	{
		GearyRFC822Message* _tmp5_ = NULL;
		GearyRFC822Message* _tmp6_;
		gchar* _tmp7_;
		_tmp6_ = geary_email_get_message (email, &_inner_error0_);
		_tmp5_ = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch1_g_error;
		}
		_tmp7_ = geary_rf_c822_message_get_searchable_recipients (_tmp5_);
		_g_free0 (recipients);
		recipients = _tmp7_;
		_g_object_unref0 (_tmp5_);
	}
	goto __finally1;
	__catch1_g_error:
	{
		g_clear_error (&_inner_error0_);
	}
	__finally1:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_free0 (recipients);
		_g_free0 (body);
		return;
	}
	_tmp8_ = geary_email_get_searchable_attachment_list (email);
	attachments = _tmp8_;
	_tmp10_ = geary_email_header_set_get_subject (G_TYPE_CHECK_INSTANCE_CAST (email, GEARY_TYPE_EMAIL_HEADER_SET, GearyEmailHeaderSet));
	_tmp11_ = _tmp10_;
	if (_tmp11_ != NULL) {
		GearyRFC822Subject* _tmp12_;
		GearyRFC822Subject* _tmp13_;
		gchar* _tmp14_;
		_tmp12_ = geary_email_header_set_get_subject (G_TYPE_CHECK_INSTANCE_CAST (email, GEARY_TYPE_EMAIL_HEADER_SET, GearyEmailHeaderSet));
		_tmp13_ = _tmp12_;
		_tmp14_ = geary_message_data_searchable_message_data_to_searchable_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp13_, GEARY_MESSAGE_DATA_TYPE_SEARCHABLE_MESSAGE_DATA, GearyMessageDataSearchableMessageData));
		_g_free0 (_tmp9_);
		_tmp9_ = _tmp14_;
	} else {
		_g_free0 (_tmp9_);
		_tmp9_ = NULL;
	}
	_tmp15_ = g_strdup (_tmp9_);
	subject = _tmp15_;
	_tmp17_ = geary_email_header_set_get_from (G_TYPE_CHECK_INSTANCE_CAST (email, GEARY_TYPE_EMAIL_HEADER_SET, GearyEmailHeaderSet));
	_tmp18_ = _tmp17_;
	if (_tmp18_ != NULL) {
		GearyRFC822MailboxAddresses* _tmp19_;
		GearyRFC822MailboxAddresses* _tmp20_;
		gchar* _tmp21_;
		_tmp19_ = geary_email_header_set_get_from (G_TYPE_CHECK_INSTANCE_CAST (email, GEARY_TYPE_EMAIL_HEADER_SET, GearyEmailHeaderSet));
		_tmp20_ = _tmp19_;
		_tmp21_ = geary_message_data_searchable_message_data_to_searchable_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp20_, GEARY_MESSAGE_DATA_TYPE_SEARCHABLE_MESSAGE_DATA, GearyMessageDataSearchableMessageData));
		_g_free0 (_tmp16_);
		_tmp16_ = _tmp21_;
	} else {
		_g_free0 (_tmp16_);
		_tmp16_ = NULL;
	}
	_tmp22_ = g_strdup (_tmp16_);
	from = _tmp22_;
	_tmp24_ = geary_email_header_set_get_cc (G_TYPE_CHECK_INSTANCE_CAST (email, GEARY_TYPE_EMAIL_HEADER_SET, GearyEmailHeaderSet));
	_tmp25_ = _tmp24_;
	if (_tmp25_ != NULL) {
		GearyRFC822MailboxAddresses* _tmp26_;
		GearyRFC822MailboxAddresses* _tmp27_;
		gchar* _tmp28_;
		_tmp26_ = geary_email_header_set_get_cc (G_TYPE_CHECK_INSTANCE_CAST (email, GEARY_TYPE_EMAIL_HEADER_SET, GearyEmailHeaderSet));
		_tmp27_ = _tmp26_;
		_tmp28_ = geary_message_data_searchable_message_data_to_searchable_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp27_, GEARY_MESSAGE_DATA_TYPE_SEARCHABLE_MESSAGE_DATA, GearyMessageDataSearchableMessageData));
		_g_free0 (_tmp23_);
		_tmp23_ = _tmp28_;
	} else {
		_g_free0 (_tmp23_);
		_tmp23_ = NULL;
	}
	_tmp29_ = g_strdup (_tmp23_);
	cc = _tmp29_;
	_tmp31_ = geary_email_header_set_get_bcc (G_TYPE_CHECK_INSTANCE_CAST (email, GEARY_TYPE_EMAIL_HEADER_SET, GearyEmailHeaderSet));
	_tmp32_ = _tmp31_;
	if (_tmp32_ != NULL) {
		GearyRFC822MailboxAddresses* _tmp33_;
		GearyRFC822MailboxAddresses* _tmp34_;
		gchar* _tmp35_;
		_tmp33_ = geary_email_header_set_get_bcc (G_TYPE_CHECK_INSTANCE_CAST (email, GEARY_TYPE_EMAIL_HEADER_SET, GearyEmailHeaderSet));
		_tmp34_ = _tmp33_;
		_tmp35_ = geary_message_data_searchable_message_data_to_searchable_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp34_, GEARY_MESSAGE_DATA_TYPE_SEARCHABLE_MESSAGE_DATA, GearyMessageDataSearchableMessageData));
		_g_free0 (_tmp30_);
		_tmp30_ = _tmp35_;
	} else {
		_g_free0 (_tmp30_);
		_tmp30_ = NULL;
	}
	_tmp36_ = g_strdup (_tmp30_);
	bcc = _tmp36_;
	_tmp38_ = geary_email_get_email_flags (email);
	_tmp39_ = _tmp38_;
	if (_tmp39_ != NULL) {
		GearyEmailFlags* _tmp40_;
		GearyEmailFlags* _tmp41_;
		gchar* _tmp42_;
		_tmp40_ = geary_email_get_email_flags (email);
		_tmp41_ = _tmp40_;
		_tmp42_ = geary_named_flags_serialise (G_TYPE_CHECK_INSTANCE_CAST (_tmp41_, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags));
		_g_free0 (_tmp37_);
		_tmp37_ = _tmp42_;
	} else {
		_g_free0 (_tmp37_);
		_tmp37_ = NULL;
	}
	_tmp43_ = g_strdup (_tmp37_);
	flags = _tmp43_;
	_tmp51_ = body;
	if (!geary_string_is_empty (_tmp51_)) {
		_tmp50_ = TRUE;
	} else {
		const gchar* _tmp52_;
		_tmp52_ = attachments;
		_tmp50_ = !geary_string_is_empty (_tmp52_);
	}
	if (_tmp50_) {
		_tmp49_ = TRUE;
	} else {
		const gchar* _tmp53_;
		_tmp53_ = subject;
		_tmp49_ = !geary_string_is_empty (_tmp53_);
	}
	if (_tmp49_) {
		_tmp48_ = TRUE;
	} else {
		const gchar* _tmp54_;
		_tmp54_ = from;
		_tmp48_ = !geary_string_is_empty (_tmp54_);
	}
	if (_tmp48_) {
		_tmp47_ = TRUE;
	} else {
		const gchar* _tmp55_;
		_tmp55_ = recipients;
		_tmp47_ = !geary_string_is_empty (_tmp55_);
	}
	if (_tmp47_) {
		_tmp46_ = TRUE;
	} else {
		const gchar* _tmp56_;
		_tmp56_ = cc;
		_tmp46_ = !geary_string_is_empty (_tmp56_);
	}
	if (_tmp46_) {
		_tmp45_ = TRUE;
	} else {
		const gchar* _tmp57_;
		_tmp57_ = bcc;
		_tmp45_ = !geary_string_is_empty (_tmp57_);
	}
	if (_tmp45_) {
		_tmp44_ = TRUE;
	} else {
		const gchar* _tmp58_;
		_tmp58_ = flags;
		_tmp44_ = !geary_string_is_empty (_tmp58_);
	}
	if (_tmp44_) {
		GearyDbStatement* stmt = NULL;
		GearyDbStatement* _tmp59_;
		GearyDbStatement* _tmp60_;
		GearyDbStatement* _tmp61_;
		GearyDbStatement* _tmp62_;
		GearyDbStatement* _tmp63_;
		const gchar* _tmp64_;
		GearyDbStatement* _tmp65_;
		GearyDbStatement* _tmp66_;
		GearyDbStatement* _tmp67_;
		const gchar* _tmp68_;
		GearyDbStatement* _tmp69_;
		GearyDbStatement* _tmp70_;
		GearyDbStatement* _tmp71_;
		const gchar* _tmp72_;
		GearyDbStatement* _tmp73_;
		GearyDbStatement* _tmp74_;
		GearyDbStatement* _tmp75_;
		const gchar* _tmp76_;
		GearyDbStatement* _tmp77_;
		GearyDbStatement* _tmp78_;
		GearyDbStatement* _tmp79_;
		const gchar* _tmp80_;
		GearyDbStatement* _tmp81_;
		GearyDbStatement* _tmp82_;
		GearyDbStatement* _tmp83_;
		const gchar* _tmp84_;
		GearyDbStatement* _tmp85_;
		GearyDbStatement* _tmp86_;
		GearyDbStatement* _tmp87_;
		const gchar* _tmp88_;
		GearyDbStatement* _tmp89_;
		GearyDbStatement* _tmp90_;
		GearyDbStatement* _tmp91_;
		const gchar* _tmp92_;
		GearyDbStatement* _tmp93_;
		GearyDbStatement* _tmp94_;
		GearyDbStatement* _tmp95_;
		_tmp59_ = geary_db_connection_prepare (cx, "\n" \
"                INSERT INTO MessageSearchTable\n" \
"                    (rowid, body, attachments, subject, \"from\", rece" \
"ivers, cc, bcc, flags)\n" \
"                VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)\n" \
"            ", &_inner_error0_);
		stmt = _tmp59_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_free0 (flags);
			_g_free0 (_tmp37_);
			_g_free0 (bcc);
			_g_free0 (_tmp30_);
			_g_free0 (cc);
			_g_free0 (_tmp23_);
			_g_free0 (from);
			_g_free0 (_tmp16_);
			_g_free0 (subject);
			_g_free0 (_tmp9_);
			_g_free0 (attachments);
			_g_free0 (recipients);
			_g_free0 (body);
			return;
		}
		_tmp60_ = stmt;
		_tmp61_ = geary_db_statement_bind_rowid (_tmp60_, 0, message_id, &_inner_error0_);
		_tmp62_ = _tmp61_;
		_g_object_unref0 (_tmp62_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_g_free0 (flags);
			_g_free0 (_tmp37_);
			_g_free0 (bcc);
			_g_free0 (_tmp30_);
			_g_free0 (cc);
			_g_free0 (_tmp23_);
			_g_free0 (from);
			_g_free0 (_tmp16_);
			_g_free0 (subject);
			_g_free0 (_tmp9_);
			_g_free0 (attachments);
			_g_free0 (recipients);
			_g_free0 (body);
			return;
		}
		_tmp63_ = stmt;
		_tmp64_ = body;
		_tmp65_ = geary_db_statement_bind_string (_tmp63_, 1, _tmp64_, &_inner_error0_);
		_tmp66_ = _tmp65_;
		_g_object_unref0 (_tmp66_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_g_free0 (flags);
			_g_free0 (_tmp37_);
			_g_free0 (bcc);
			_g_free0 (_tmp30_);
			_g_free0 (cc);
			_g_free0 (_tmp23_);
			_g_free0 (from);
			_g_free0 (_tmp16_);
			_g_free0 (subject);
			_g_free0 (_tmp9_);
			_g_free0 (attachments);
			_g_free0 (recipients);
			_g_free0 (body);
			return;
		}
		_tmp67_ = stmt;
		_tmp68_ = attachments;
		_tmp69_ = geary_db_statement_bind_string (_tmp67_, 2, _tmp68_, &_inner_error0_);
		_tmp70_ = _tmp69_;
		_g_object_unref0 (_tmp70_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_g_free0 (flags);
			_g_free0 (_tmp37_);
			_g_free0 (bcc);
			_g_free0 (_tmp30_);
			_g_free0 (cc);
			_g_free0 (_tmp23_);
			_g_free0 (from);
			_g_free0 (_tmp16_);
			_g_free0 (subject);
			_g_free0 (_tmp9_);
			_g_free0 (attachments);
			_g_free0 (recipients);
			_g_free0 (body);
			return;
		}
		_tmp71_ = stmt;
		_tmp72_ = subject;
		_tmp73_ = geary_db_statement_bind_string (_tmp71_, 3, _tmp72_, &_inner_error0_);
		_tmp74_ = _tmp73_;
		_g_object_unref0 (_tmp74_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_g_free0 (flags);
			_g_free0 (_tmp37_);
			_g_free0 (bcc);
			_g_free0 (_tmp30_);
			_g_free0 (cc);
			_g_free0 (_tmp23_);
			_g_free0 (from);
			_g_free0 (_tmp16_);
			_g_free0 (subject);
			_g_free0 (_tmp9_);
			_g_free0 (attachments);
			_g_free0 (recipients);
			_g_free0 (body);
			return;
		}
		_tmp75_ = stmt;
		_tmp76_ = from;
		_tmp77_ = geary_db_statement_bind_string (_tmp75_, 4, _tmp76_, &_inner_error0_);
		_tmp78_ = _tmp77_;
		_g_object_unref0 (_tmp78_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_g_free0 (flags);
			_g_free0 (_tmp37_);
			_g_free0 (bcc);
			_g_free0 (_tmp30_);
			_g_free0 (cc);
			_g_free0 (_tmp23_);
			_g_free0 (from);
			_g_free0 (_tmp16_);
			_g_free0 (subject);
			_g_free0 (_tmp9_);
			_g_free0 (attachments);
			_g_free0 (recipients);
			_g_free0 (body);
			return;
		}
		_tmp79_ = stmt;
		_tmp80_ = recipients;
		_tmp81_ = geary_db_statement_bind_string (_tmp79_, 5, _tmp80_, &_inner_error0_);
		_tmp82_ = _tmp81_;
		_g_object_unref0 (_tmp82_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_g_free0 (flags);
			_g_free0 (_tmp37_);
			_g_free0 (bcc);
			_g_free0 (_tmp30_);
			_g_free0 (cc);
			_g_free0 (_tmp23_);
			_g_free0 (from);
			_g_free0 (_tmp16_);
			_g_free0 (subject);
			_g_free0 (_tmp9_);
			_g_free0 (attachments);
			_g_free0 (recipients);
			_g_free0 (body);
			return;
		}
		_tmp83_ = stmt;
		_tmp84_ = cc;
		_tmp85_ = geary_db_statement_bind_string (_tmp83_, 6, _tmp84_, &_inner_error0_);
		_tmp86_ = _tmp85_;
		_g_object_unref0 (_tmp86_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_g_free0 (flags);
			_g_free0 (_tmp37_);
			_g_free0 (bcc);
			_g_free0 (_tmp30_);
			_g_free0 (cc);
			_g_free0 (_tmp23_);
			_g_free0 (from);
			_g_free0 (_tmp16_);
			_g_free0 (subject);
			_g_free0 (_tmp9_);
			_g_free0 (attachments);
			_g_free0 (recipients);
			_g_free0 (body);
			return;
		}
		_tmp87_ = stmt;
		_tmp88_ = bcc;
		_tmp89_ = geary_db_statement_bind_string (_tmp87_, 7, _tmp88_, &_inner_error0_);
		_tmp90_ = _tmp89_;
		_g_object_unref0 (_tmp90_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_g_free0 (flags);
			_g_free0 (_tmp37_);
			_g_free0 (bcc);
			_g_free0 (_tmp30_);
			_g_free0 (cc);
			_g_free0 (_tmp23_);
			_g_free0 (from);
			_g_free0 (_tmp16_);
			_g_free0 (subject);
			_g_free0 (_tmp9_);
			_g_free0 (attachments);
			_g_free0 (recipients);
			_g_free0 (body);
			return;
		}
		_tmp91_ = stmt;
		_tmp92_ = flags;
		_tmp93_ = geary_db_statement_bind_string (_tmp91_, 8, _tmp92_, &_inner_error0_);
		_tmp94_ = _tmp93_;
		_g_object_unref0 (_tmp94_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_g_free0 (flags);
			_g_free0 (_tmp37_);
			_g_free0 (bcc);
			_g_free0 (_tmp30_);
			_g_free0 (cc);
			_g_free0 (_tmp23_);
			_g_free0 (from);
			_g_free0 (_tmp16_);
			_g_free0 (subject);
			_g_free0 (_tmp9_);
			_g_free0 (attachments);
			_g_free0 (recipients);
			_g_free0 (body);
			return;
		}
		_tmp95_ = stmt;
		geary_db_statement_exec_insert (_tmp95_, cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_g_free0 (flags);
			_g_free0 (_tmp37_);
			_g_free0 (bcc);
			_g_free0 (_tmp30_);
			_g_free0 (cc);
			_g_free0 (_tmp23_);
			_g_free0 (from);
			_g_free0 (_tmp16_);
			_g_free0 (subject);
			_g_free0 (_tmp9_);
			_g_free0 (attachments);
			_g_free0 (recipients);
			_g_free0 (body);
			return;
		}
		_g_object_unref0 (stmt);
	}
	_g_free0 (flags);
	_g_free0 (_tmp37_);
	_g_free0 (bcc);
	_g_free0 (_tmp30_);
	_g_free0 (cc);
	_g_free0 (_tmp23_);
	_g_free0 (from);
	_g_free0 (_tmp16_);
	_g_free0 (subject);
	_g_free0 (_tmp9_);
	_g_free0 (attachments);
	_g_free0 (recipients);
	_g_free0 (body);
}

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

static GeeList*
geary_imap_db_folder_do_list_email (GearyImapDBFolder* self,
                                    GearyDbConnection* cx,
                                    GeeList* locations,
                                    GearyEmailField required_fields,
                                    GearyImapDBFolderListFlags flags,
                                    GCancellable* cancellable,
                                    GError** error)
{
	GeeList* emails = NULL;
	GeeArrayList* _tmp0_;
	GeeList* _tmp18_ = NULL;
	GeeList* _tmp19_;
	gint _tmp20_;
	gint _tmp21_;
	GeeList* _tmp23_;
	GError* _inner_error0_ = NULL;
	GeeList* result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_FOLDER (self), NULL);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), NULL);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (locations, GEE_TYPE_LIST), NULL);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), NULL);
	_tmp0_ = gee_array_list_new (GEARY_TYPE_EMAIL, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	emails = G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEE_TYPE_LIST, GeeList);
	{
		GeeList* _location_list = NULL;
		gint _location_size = 0;
		GeeList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _location_index = 0;
		_location_list = locations;
		_tmp1_ = _location_list;
		_tmp2_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEE_TYPE_COLLECTION, GeeCollection));
		_tmp3_ = _tmp2_;
		_location_size = _tmp3_;
		_location_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			GearyImapDBFolderLocationIdentifier* location = NULL;
			GeeList* _tmp6_;
			gpointer _tmp7_;
			_location_index = _location_index + 1;
			_tmp4_ = _location_index;
			_tmp5_ = _location_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _location_list;
			_tmp7_ = gee_list_get (_tmp6_, _location_index);
			location = (GearyImapDBFolderLocationIdentifier*) _tmp7_;
			{
				GearyEmail* _tmp8_ = NULL;
				GearyImapDBFolderLocationIdentifier* _tmp9_;
				GearyEmail* _tmp10_;
				GeeList* _tmp11_;
				_tmp9_ = location;
				_tmp10_ = geary_imap_db_folder_do_location_to_email (self, cx, _tmp9_, required_fields, flags, cancellable, &_inner_error0_);
				_tmp8_ = _tmp10_;
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					if (_inner_error0_->domain == GEARY_ENGINE_ERROR) {
						goto __catch0_geary_engine_error;
					}
					goto __finally0;
				}
				_tmp11_ = emails;
				gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp11_, GEE_TYPE_COLLECTION, GeeCollection), _tmp8_);
				_g_object_unref0 (_tmp8_);
			}
			goto __finally0;
			__catch0_geary_engine_error:
			{
				GError* err = NULL;
				GError* _tmp12_;
				err = _inner_error0_;
				_inner_error0_ = NULL;
				_tmp12_ = err;
				if (g_error_matches (_tmp12_, GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_NOT_FOUND)) {
					GError* _tmp13_;
					const gchar* _tmp14_;
					_tmp13_ = err;
					_tmp14_ = _tmp13_->message;
					g_debug ("imap-db-folder.vala:1774: Warning: Message not found, dropping: %s", _tmp14_);
				} else {
					GError* _tmp15_;
					_tmp15_ = err;
					if (!g_error_matches (_tmp15_, GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_INCOMPLETE_MESSAGE)) {
						GError* _tmp16_;
						GError* _tmp17_;
						_tmp16_ = err;
						_tmp17_ = _g_error_copy0 (_tmp16_);
						_inner_error0_ = _tmp17_;
						_g_error_free0 (err);
						goto __finally0;
					}
				}
				_g_error_free0 (err);
			}
			__finally0:
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (emails);
				return NULL;
			}
			_geary_imap_db_folder_location_identifier_unref0 (location);
		}
	}
	_tmp19_ = emails;
	_tmp20_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp19_, GEE_TYPE_COLLECTION, GeeCollection));
	_tmp21_ = _tmp20_;
	if (_tmp21_ > 0) {
		GeeList* _tmp22_;
		_tmp22_ = emails;
		_tmp18_ = _tmp22_;
	} else {
		_tmp18_ = NULL;
	}
	_tmp23_ = _g_object_ref0 (_tmp18_);
	result = _tmp23_;
	_g_object_unref0 (emails);
	return result;
}

GearyImapDBMessageRow*
geary_imap_db_folder_do_fetch_message_row (GearyDbConnection* cx,
                                           gint64 message_id,
                                           GearyEmailField requested_fields,
                                           GearyEmailField* db_fields,
                                           GCancellable* cancellable,
                                           GError** error)
{
	GearyEmailField _vala_db_fields = 0;
	GearyDbStatement* stmt = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbStatement* _tmp5_;
	GearyDbStatement* _tmp6_;
	GearyDbStatement* _tmp7_;
	GearyDbStatement* _tmp8_;
	GearyDbResult* results = NULL;
	GearyDbStatement* _tmp9_;
	GearyDbResult* _tmp10_;
	GearyDbResult* _tmp11_;
	gboolean _tmp12_;
	gboolean _tmp13_;
	gint _tmp18_ = 0;
	GearyDbResult* _tmp19_;
	GearyImapDBMessageRow* _tmp20_ = NULL;
	GearyDbResult* _tmp21_;
	GearyImapDBMessageRow* _tmp22_;
	GearyImapDBMessageRow* _tmp23_;
	GError* _inner_error0_ = NULL;
	GearyImapDBMessageRow* result;
	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_imap_db_folder_fields_to_columns (requested_fields);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strdup_printf ("SELECT %s FROM MessageTable WHERE id=?", _tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = geary_db_connection_prepare (cx, _tmp3_, &_inner_error0_);
	_tmp5_ = _tmp4_;
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
	stmt = _tmp5_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return NULL;
	}
	_tmp6_ = stmt;
	_tmp7_ = geary_db_statement_bind_rowid (_tmp6_, 0, message_id, &_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 NULL;
	}
	_tmp9_ = stmt;
	_tmp10_ = geary_db_statement_exec (_tmp9_, cancellable, &_inner_error0_);
	results = _tmp10_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp11_ = results;
	_tmp12_ = geary_db_result_get_finished (_tmp11_);
	_tmp13_ = _tmp12_;
	if (_tmp13_) {
		gchar* _tmp14_;
		gchar* _tmp15_;
		GError* _tmp16_;
		GError* _tmp17_;
		_tmp14_ = g_strdup_printf ("%" G_GINT64_FORMAT, message_id);
		_tmp15_ = _tmp14_;
		_tmp16_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_NOT_FOUND, "No message ID %s found in database", _tmp15_);
		_tmp17_ = _tmp16_;
		_g_free0 (_tmp15_);
		_inner_error0_ = _tmp17_;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp19_ = results;
	_tmp18_ = geary_db_result_int_for (_tmp19_, "fields", &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_vala_db_fields = (GearyEmailField) _tmp18_;
	_tmp21_ = results;
	_tmp22_ = geary_imap_db_message_row_new_from_result (requested_fields, _tmp21_, &_inner_error0_);
	_tmp20_ = _tmp22_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp23_ = _tmp20_;
	_tmp20_ = NULL;
	result = _tmp23_;
	_geary_imap_db_message_row_unref0 (_tmp20_);
	_g_object_unref0 (results);
	_g_object_unref0 (stmt);
	if (db_fields) {
		*db_fields = _vala_db_fields;
	}
	return result;
}

static GearyEmail*
geary_imap_db_folder_do_location_to_email (GearyImapDBFolder* self,
                                           GearyDbConnection* cx,
                                           GearyImapDBFolderLocationIdentifier* location,
                                           GearyEmailField required_fields,
                                           GearyImapDBFolderListFlags flags,
                                           GCancellable* cancellable,
                                           GError** error)
{
	gboolean _tmp0_ = FALSE;
	GearyEmailField db_fields = 0;
	GearyImapDBMessageRow* row = NULL;
	GearyEmailField _tmp10_ = 0;
	GearyImapDBMessageRow* _tmp11_;
	gboolean _tmp12_ = FALSE;
	GearyEmail* email = NULL;
	GearyImapDBMessageRow* _tmp26_;
	GearyImapDBEmailIdentifier* _tmp27_;
	GearyEmail* _tmp28_;
	GFile* _tmp29_;
	GearyEmail* _tmp30_;
	GError* _inner_error0_ = NULL;
	GearyEmail* result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_FOLDER (self), NULL);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), NULL);
	g_return_val_if_fail (GEARY_IMAP_DB_FOLDER_IS_LOCATION_IDENTIFIER (location), NULL);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), NULL);
	if (!geary_imap_db_folder_list_flags_include_marked_for_remove (flags)) {
		_tmp0_ = location->marked_removed;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		GearyImapDBEmailIdentifier* _tmp1_;
		gchar* _tmp2_;
		gchar* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		GError* _tmp6_;
		GError* _tmp7_;
		_tmp1_ = location->email_id;
		_tmp2_ = geary_email_identifier_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEARY_TYPE_EMAIL_IDENTIFIER, GearyEmailIdentifier));
		_tmp3_ = _tmp2_;
		_tmp4_ = geary_imap_db_folder_to_string (self);
		_tmp5_ = _tmp4_;
		_tmp6_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_NOT_FOUND, "Message %s marked as removed in %s", _tmp3_, _tmp5_);
		_tmp7_ = _tmp6_;
		_g_free0 (_tmp5_);
		_g_free0 (_tmp3_);
		_inner_error0_ = _tmp7_;
		g_propagate_error (error, _inner_error0_);
		return NULL;
	}
	if (required_fields == GEARY_EMAIL_FIELD_NONE) {
		GearyImapDBEmailIdentifier* _tmp8_;
		GearyEmail* _tmp9_;
		_tmp8_ = location->email_id;
		_tmp9_ = geary_email_new (G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, GEARY_TYPE_EMAIL_IDENTIFIER, GearyEmailIdentifier));
		result = _tmp9_;
		return result;
	}
	_tmp11_ = geary_imap_db_folder_do_fetch_message_row (cx, location->message_id, required_fields, &_tmp10_, cancellable, &_inner_error0_);
	db_fields = _tmp10_;
	row = _tmp11_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return NULL;
	}
	if (!geary_imap_db_folder_list_flags_is_all_set (flags, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_PARTIAL_OK)) {
		GearyImapDBMessageRow* _tmp13_;
		GearyEmailField _tmp14_;
		GearyEmailField _tmp15_;
		_tmp13_ = row;
		_tmp14_ = geary_imap_db_message_row_get_fields (_tmp13_);
		_tmp15_ = _tmp14_;
		_tmp12_ = !geary_email_field_fulfills (_tmp15_, required_fields);
	} else {
		_tmp12_ = FALSE;
	}
	if (_tmp12_) {
		GearyImapDBEmailIdentifier* _tmp16_;
		gchar* _tmp17_;
		gchar* _tmp18_;
		gchar* _tmp19_;
		gchar* _tmp20_;
		GearyImapDBMessageRow* _tmp21_;
		GearyEmailField _tmp22_;
		GearyEmailField _tmp23_;
		GError* _tmp24_;
		GError* _tmp25_;
		_tmp16_ = location->email_id;
		_tmp17_ = geary_email_identifier_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp16_, GEARY_TYPE_EMAIL_IDENTIFIER, GearyEmailIdentifier));
		_tmp18_ = _tmp17_;
		_tmp19_ = geary_imap_db_folder_to_string (self);
		_tmp20_ = _tmp19_;
		_tmp21_ = row;
		_tmp22_ = geary_imap_db_message_row_get_fields (_tmp21_);
		_tmp23_ = _tmp22_;
		_tmp24_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_INCOMPLETE_MESSAGE, "Message %s in folder %s only fulfills %Xh fields (required: %Xh)", _tmp18_, _tmp20_, (guint) _tmp23_, (guint) required_fields);
		_tmp25_ = _tmp24_;
		_g_free0 (_tmp20_);
		_g_free0 (_tmp18_);
		_inner_error0_ = _tmp25_;
		g_propagate_error (error, _inner_error0_);
		_geary_imap_db_message_row_unref0 (row);
		return NULL;
	}
	_tmp26_ = row;
	_tmp27_ = location->email_id;
	_tmp28_ = geary_imap_db_message_row_to_email (_tmp26_, _tmp27_, &_inner_error0_);
	email = _tmp28_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_geary_imap_db_message_row_unref0 (row);
		return NULL;
	}
	_tmp29_ = self->priv->attachments_path;
	_tmp30_ = email;
	geary_imap_db_attachment_add_attachments (cx, _tmp29_, _tmp30_, location->message_id, cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (email);
		_geary_imap_db_message_row_unref0 (row);
		return NULL;
	}
	result = email;
	_geary_imap_db_message_row_unref0 (row);
	return result;
}

static gchar*
geary_imap_db_folder_fields_to_columns (GearyEmailField fields)
{
	GString* builder = NULL;
	GString* _tmp0_;
	gint _tmp1_ = 0;
	GearyEmailField* _tmp2_;
	GString* _tmp7_;
	const gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* result;
	_tmp0_ = g_string_new ("id, fields");
	builder = _tmp0_;
	_tmp2_ = geary_email_field_all (&_tmp1_);
	{
		GearyEmailField* field_collection = NULL;
		gint field_collection_length1 = 0;
		gint _field_collection_size_ = 0;
		gint field_it = 0;
		field_collection = _tmp2_;
		field_collection_length1 = _tmp1_;
		for (field_it = 0; field_it < field_collection_length1; field_it = field_it + 1) {
			GearyEmailField field = 0;
			field = field_collection[field_it];
			{
				const gchar* append = NULL;
				const gchar* _tmp3_;
				append = NULL;
				if (geary_email_field_is_all_set (fields, fields)) {
					switch (field) {
						case GEARY_EMAIL_FIELD_DATE:
						{
							append = "date_field, date_time_t";
							break;
						}
						case GEARY_EMAIL_FIELD_ORIGINATORS:
						{
							append = "from_field, sender, reply_to";
							break;
						}
						case GEARY_EMAIL_FIELD_RECEIVERS:
						{
							append = "to_field, cc, bcc";
							break;
						}
						case GEARY_EMAIL_FIELD_REFERENCES:
						{
							append = "message_id, in_reply_to, reference_ids";
							break;
						}
						case GEARY_EMAIL_FIELD_SUBJECT:
						{
							append = "subject";
							break;
						}
						case GEARY_EMAIL_FIELD_HEADER:
						{
							append = "header";
							break;
						}
						case GEARY_EMAIL_FIELD_BODY:
						{
							append = "body";
							break;
						}
						case GEARY_EMAIL_FIELD_PREVIEW:
						{
							append = "preview";
							break;
						}
						case GEARY_EMAIL_FIELD_FLAGS:
						{
							append = "flags";
							break;
						}
						case GEARY_EMAIL_FIELD_PROPERTIES:
						{
							append = "internaldate, internaldate_time_t, rfc822_size";
							break;
						}
						case GEARY_EMAIL_FIELD_NONE:
						{
							break;
						}
						case GEARY_EMAIL_FIELD_ENVELOPE:
						case GEARY_EMAIL_FIELD_ALL:
						{
							break;
						}
						default:
						break;
					}
				}
				_tmp3_ = append;
				if (_tmp3_ != NULL) {
					GString* _tmp4_;
					GString* _tmp5_;
					const gchar* _tmp6_;
					_tmp4_ = builder;
					g_string_append (_tmp4_, ", ");
					_tmp5_ = builder;
					_tmp6_ = append;
					g_string_append (_tmp5_, _tmp6_);
				}
			}
		}
		field_collection = (g_free (field_collection), NULL);
	}
	_tmp7_ = builder;
	_tmp8_ = _tmp7_->str;
	_tmp9_ = g_strdup (_tmp8_);
	result = _tmp9_;
	_g_string_free0 (builder);
	return result;
}

static GeeList*
geary_imap_db_folder_do_get_email_uids (GearyImapDBFolder* self,
                                        GearyDbConnection* cx,
                                        GeeCollection* ids,
                                        GCancellable* cancellable,
                                        GError** error)
{
	GeeList* locs = NULL;
	GeeList* _tmp0_;
	GeeList* uids = NULL;
	GeeArrayList* _tmp1_;
	GeeList* _tmp12_ = NULL;
	GeeList* _tmp13_;
	gint _tmp14_;
	gint _tmp15_;
	GeeList* _tmp17_;
	GError* _inner_error0_ = NULL;
	GeeList* result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_FOLDER (self), NULL);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), NULL);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION), NULL);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), NULL);
	_tmp0_ = geary_imap_db_folder_do_get_locations_for_ids (self, cx, ids, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_NONE, cancellable, &_inner_error0_);
	locs = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return NULL;
	}
	if (locs == NULL) {
		result = NULL;
		_g_object_unref0 (locs);
		return result;
	}
	_tmp1_ = gee_array_list_new (GEARY_IMAP_TYPE_UID, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	uids = G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEE_TYPE_LIST, GeeList);
	{
		GeeList* _location_list = NULL;
		gint _location_size = 0;
		GeeList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _location_index = 0;
		_location_list = locs;
		_tmp2_ = _location_list;
		_tmp3_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, GEE_TYPE_COLLECTION, GeeCollection));
		_tmp4_ = _tmp3_;
		_location_size = _tmp4_;
		_location_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			GearyImapDBFolderLocationIdentifier* location = NULL;
			GeeList* _tmp7_;
			gpointer _tmp8_;
			GeeList* _tmp9_;
			GearyImapDBFolderLocationIdentifier* _tmp10_;
			GearyImapUID* _tmp11_;
			_location_index = _location_index + 1;
			_tmp5_ = _location_index;
			_tmp6_ = _location_size;
			if (!(_tmp5_ < _tmp6_)) {
				break;
			}
			_tmp7_ = _location_list;
			_tmp8_ = gee_list_get (_tmp7_, _location_index);
			location = (GearyImapDBFolderLocationIdentifier*) _tmp8_;
			_tmp9_ = uids;
			_tmp10_ = location;
			_tmp11_ = _tmp10_->uid;
			gee_list_insert (_tmp9_, 0, _tmp11_);
			_geary_imap_db_folder_location_identifier_unref0 (location);
		}
	}
	_tmp13_ = uids;
	_tmp14_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp13_, GEE_TYPE_COLLECTION, GeeCollection));
	_tmp15_ = _tmp14_;
	if (_tmp15_ > 0) {
		GeeList* _tmp16_;
		_tmp16_ = uids;
		_tmp12_ = _tmp16_;
	} else {
		_tmp12_ = NULL;
	}
	_tmp17_ = _g_object_ref0 (_tmp12_);
	result = _tmp17_;
	_g_object_unref0 (uids);
	_g_object_unref0 (locs);
	return result;
}

static GeeMap*
geary_imap_db_folder_do_get_email_flags (GearyImapDBFolder* self,
                                         GearyDbConnection* cx,
                                         GeeCollection* ids,
                                         GCancellable* cancellable,
                                         GError** error)
{
	GeeList* locs = NULL;
	GeeList* _tmp0_;
	gboolean _tmp1_ = FALSE;
	GeeList* _tmp2_;
	GearyDbStatement* fetch_stmt = NULL;
	GearyDbStatement* _tmp6_;
	GeeMap* map = NULL;
	GeeHashMap* _tmp7_;
	GeeMap* _tmp41_ = NULL;
	GeeMap* _tmp42_;
	gint _tmp43_;
	gint _tmp44_;
	GeeMap* _tmp46_;
	GError* _inner_error0_ = NULL;
	GeeMap* result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_FOLDER (self), NULL);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), NULL);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION), NULL);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), NULL);
	_tmp0_ = geary_imap_db_folder_do_get_locations_for_ids (self, cx, ids, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_NONE, cancellable, &_inner_error0_);
	locs = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return NULL;
	}
	_tmp2_ = locs;
	if (_tmp2_ == NULL) {
		_tmp1_ = TRUE;
	} else {
		GeeList* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		_tmp3_ = locs;
		_tmp4_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, GEE_TYPE_COLLECTION, GeeCollection));
		_tmp5_ = _tmp4_;
		_tmp1_ = _tmp5_ == 0;
	}
	if (_tmp1_) {
		result = NULL;
		_g_object_unref0 (locs);
		return result;
	}
	_tmp6_ = geary_db_connection_prepare (cx, "SELECT flags FROM MessageTable WHERE id=?", &_inner_error0_);
	fetch_stmt = _tmp6_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (locs);
		return NULL;
	}
	_tmp7_ = gee_hash_map_new (GEARY_IMAP_DB_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);
	map = G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, GEE_TYPE_MAP, GeeMap);
	{
		GeeList* _location_list = NULL;
		GeeList* _tmp8_;
		gint _location_size = 0;
		GeeList* _tmp9_;
		gint _tmp10_;
		gint _tmp11_;
		gint _location_index = 0;
		_tmp8_ = locs;
		_location_list = _tmp8_;
		_tmp9_ = _location_list;
		_tmp10_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp9_, GEE_TYPE_COLLECTION, GeeCollection));
		_tmp11_ = _tmp10_;
		_location_size = _tmp11_;
		_location_index = -1;
		while (TRUE) {
			gint _tmp12_;
			gint _tmp13_;
			GearyImapDBFolderLocationIdentifier* location = NULL;
			GeeList* _tmp14_;
			gpointer _tmp15_;
			GearyDbStatement* _tmp16_;
			GearyDbStatement* _tmp17_;
			GearyDbStatement* _tmp18_;
			GearyDbStatement* _tmp19_;
			GearyImapDBFolderLocationIdentifier* _tmp20_;
			GearyDbStatement* _tmp21_;
			GearyDbStatement* _tmp22_;
			GearyDbResult* results = NULL;
			GearyDbStatement* _tmp23_;
			GearyDbResult* _tmp24_;
			gboolean _tmp25_ = FALSE;
			GearyDbResult* _tmp26_;
			gboolean _tmp27_;
			gboolean _tmp28_;
			const gchar* _tmp31_ = NULL;
			GearyDbResult* _tmp32_;
			const gchar* _tmp33_;
			GeeMap* _tmp34_;
			GearyImapDBFolderLocationIdentifier* _tmp35_;
			GearyImapDBEmailIdentifier* _tmp36_;
			GearyImapMessageFlags* _tmp37_;
			GearyImapMessageFlags* _tmp38_;
			GearyImapEmailFlags* _tmp39_;
			GearyImapEmailFlags* _tmp40_;
			_location_index = _location_index + 1;
			_tmp12_ = _location_index;
			_tmp13_ = _location_size;
			if (!(_tmp12_ < _tmp13_)) {
				break;
			}
			_tmp14_ = _location_list;
			_tmp15_ = gee_list_get (_tmp14_, _location_index);
			location = (GearyImapDBFolderLocationIdentifier*) _tmp15_;
			_tmp16_ = fetch_stmt;
			_tmp17_ = geary_db_statement_reset (_tmp16_, GEARY_DB_RESET_SCOPE_CLEAR_BINDINGS, &_inner_error0_);
			_tmp18_ = _tmp17_;
			_g_object_unref0 (_tmp18_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (map);
				_g_object_unref0 (fetch_stmt);
				_g_object_unref0 (locs);
				return NULL;
			}
			_tmp19_ = fetch_stmt;
			_tmp20_ = location;
			_tmp21_ = geary_db_statement_bind_rowid (_tmp19_, 0, _tmp20_->message_id, &_inner_error0_);
			_tmp22_ = _tmp21_;
			_g_object_unref0 (_tmp22_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (map);
				_g_object_unref0 (fetch_stmt);
				_g_object_unref0 (locs);
				return NULL;
			}
			_tmp23_ = fetch_stmt;
			_tmp24_ = geary_db_statement_exec (_tmp23_, cancellable, &_inner_error0_);
			results = _tmp24_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (map);
				_g_object_unref0 (fetch_stmt);
				_g_object_unref0 (locs);
				return NULL;
			}
			_tmp26_ = results;
			_tmp27_ = geary_db_result_get_finished (_tmp26_);
			_tmp28_ = _tmp27_;
			if (_tmp28_) {
				_tmp25_ = TRUE;
			} else {
				gboolean _tmp29_ = FALSE;
				GearyDbResult* _tmp30_;
				_tmp30_ = results;
				_tmp29_ = geary_db_result_is_null_at (_tmp30_, 0, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					g_propagate_error (error, _inner_error0_);
					_g_object_unref0 (results);
					_geary_imap_db_folder_location_identifier_unref0 (location);
					_g_object_unref0 (map);
					_g_object_unref0 (fetch_stmt);
					_g_object_unref0 (locs);
					return NULL;
				}
				_tmp25_ = _tmp29_;
			}
			if (_tmp25_) {
				_g_object_unref0 (results);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				continue;
			}
			_tmp32_ = results;
			_tmp33_ = geary_db_result_string_at (_tmp32_, 0, &_inner_error0_);
			_tmp31_ = _tmp33_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (results);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (map);
				_g_object_unref0 (fetch_stmt);
				_g_object_unref0 (locs);
				return NULL;
			}
			_tmp34_ = map;
			_tmp35_ = location;
			_tmp36_ = _tmp35_->email_id;
			_tmp37_ = geary_imap_message_flags_deserialize (_tmp31_);
			_tmp38_ = _tmp37_;
			_tmp39_ = geary_imap_email_flags_new (_tmp38_);
			_tmp40_ = _tmp39_;
			gee_map_set (_tmp34_, _tmp36_, G_TYPE_CHECK_INSTANCE_CAST (_tmp40_, GEARY_TYPE_EMAIL_FLAGS, GearyEmailFlags));
			_g_object_unref0 (_tmp40_);
			_g_object_unref0 (_tmp38_);
			_g_object_unref0 (results);
			_geary_imap_db_folder_location_identifier_unref0 (location);
		}
	}
	_tmp42_ = map;
	_tmp43_ = gee_map_get_size (_tmp42_);
	_tmp44_ = _tmp43_;
	if (_tmp44_ > 0) {
		GeeMap* _tmp45_;
		_tmp45_ = map;
		_tmp41_ = _tmp45_;
	} else {
		_tmp41_ = NULL;
	}
	_tmp46_ = _g_object_ref0 (_tmp41_);
	result = _tmp46_;
	_g_object_unref0 (map);
	_g_object_unref0 (fetch_stmt);
	_g_object_unref0 (locs);
	return result;
}

static GearyEmailFlags*
geary_imap_db_folder_do_get_email_flags_single (GearyImapDBFolder* self,
                                                GearyDbConnection* cx,
                                                gint64 message_id,
                                                GCancellable* cancellable,
                                                GError** error)
{
	GearyDbStatement* fetch_stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp1_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbResult* results = NULL;
	GearyDbStatement* _tmp4_;
	GearyDbResult* _tmp5_;
	gboolean _tmp6_ = FALSE;
	GearyDbResult* _tmp7_;
	gboolean _tmp8_;
	gboolean _tmp9_;
	const gchar* _tmp12_ = NULL;
	GearyDbResult* _tmp13_;
	const gchar* _tmp14_;
	GearyImapMessageFlags* _tmp15_;
	GearyImapMessageFlags* _tmp16_;
	GearyImapEmailFlags* _tmp17_;
	GearyEmailFlags* _tmp18_;
	GError* _inner_error0_ = NULL;
	GearyEmailFlags* result;
	g_return_val_if_fail (GEARY_IMAP_DB_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, "SELECT flags FROM MessageTable WHERE id=?", &_inner_error0_);
	fetch_stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return NULL;
	}
	_tmp1_ = fetch_stmt;
	_tmp2_ = geary_db_statement_bind_rowid (_tmp1_, 0, message_id, &_inner_error0_);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp3_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (fetch_stmt);
		return NULL;
	}
	_tmp4_ = fetch_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 (fetch_stmt);
		return NULL;
	}
	_tmp7_ = results;
	_tmp8_ = geary_db_result_get_finished (_tmp7_);
	_tmp9_ = _tmp8_;
	if (_tmp9_) {
		_tmp6_ = TRUE;
	} else {
		gboolean _tmp10_ = FALSE;
		GearyDbResult* _tmp11_;
		_tmp11_ = results;
		_tmp10_ = geary_db_result_is_null_at (_tmp11_, 0, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (results);
			_g_object_unref0 (fetch_stmt);
			return NULL;
		}
		_tmp6_ = _tmp10_;
	}
	if (_tmp6_) {
		result = NULL;
		_g_object_unref0 (results);
		_g_object_unref0 (fetch_stmt);
		return result;
	}
	_tmp13_ = results;
	_tmp14_ = geary_db_result_string_at (_tmp13_, 0, &_inner_error0_);
	_tmp12_ = _tmp14_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (results);
		_g_object_unref0 (fetch_stmt);
		return NULL;
	}
	_tmp15_ = geary_imap_message_flags_deserialize (_tmp12_);
	_tmp16_ = _tmp15_;
	_tmp17_ = geary_imap_email_flags_new (_tmp16_);
	_tmp18_ = G_TYPE_CHECK_INSTANCE_CAST (_tmp17_, GEARY_TYPE_EMAIL_FLAGS, GearyEmailFlags);
	_g_object_unref0 (_tmp16_);
	result = _tmp18_;
	_g_object_unref0 (results);
	_g_object_unref0 (fetch_stmt);
	return result;
}

static void
geary_imap_db_folder_do_set_email_flags (GearyImapDBFolder* self,
                                         GearyDbConnection* cx,
                                         GeeMap* map,
                                         GCancellable* cancellable,
                                         GError** error)
{
	GearyDbStatement* update_message = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* update_search = NULL;
	GearyDbStatement* _tmp1_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_DB_IS_CONNECTION (cx));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (map, GEE_TYPE_MAP));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_tmp0_ = geary_db_connection_prepare (cx, "UPDATE MessageTable SET flags = ?, fields = fields | ? WHERE id = ?", &_inner_error0_);
	update_message = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	_tmp1_ = geary_db_connection_prepare (cx, "\n" \
"            UPDATE MessageSearchTable SET flags = ? WHERE rowid = ?\n" \
"            ", &_inner_error0_);
	update_search = _tmp1_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (update_message);
		return;
	}
	{
		GeeIterator* _id_it = NULL;
		GeeSet* _tmp2_;
		GeeSet* _tmp3_;
		GeeSet* _tmp4_;
		GeeIterator* _tmp5_;
		GeeIterator* _tmp6_;
		_tmp2_ = gee_map_get_keys (map);
		_tmp3_ = _tmp2_;
		_tmp4_ = _tmp3_;
		_tmp5_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, GEE_TYPE_ITERABLE, GeeIterable));
		_tmp6_ = _tmp5_;
		_g_object_unref0 (_tmp4_);
		_id_it = _tmp6_;
		while (TRUE) {
			GeeIterator* _tmp7_;
			GearyImapDBEmailIdentifier* id = NULL;
			GeeIterator* _tmp8_;
			gpointer _tmp9_;
			GearyImapDBFolderLocationIdentifier* location = NULL;
			GearyImapDBEmailIdentifier* _tmp10_;
			GearyImapDBFolderLocationIdentifier* _tmp11_;
			GearyImapDBFolderLocationIdentifier* _tmp12_;
			GearyImapEmailFlags* flags = NULL;
			GearyImapDBEmailIdentifier* _tmp18_;
			gpointer _tmp19_;
			GearyEmailFlags* _tmp20_;
			GearyImapEmailFlags* _tmp21_;
			GearyImapEmailFlags* _tmp22_;
			GearyDbStatement* _tmp24_;
			GearyDbStatement* _tmp25_;
			GearyDbStatement* _tmp26_;
			GearyDbStatement* _tmp27_;
			GearyImapEmailFlags* _tmp28_;
			GearyImapMessageFlags* _tmp29_;
			GearyImapMessageFlags* _tmp30_;
			gchar* _tmp31_;
			gchar* _tmp32_;
			GearyDbStatement* _tmp33_;
			GearyDbStatement* _tmp34_;
			GearyDbStatement* _tmp35_;
			GearyDbStatement* _tmp36_;
			GearyDbStatement* _tmp37_;
			GearyDbStatement* _tmp38_;
			GearyImapDBEmailIdentifier* _tmp39_;
			gint64 _tmp40_;
			gint64 _tmp41_;
			GearyDbStatement* _tmp42_;
			GearyDbStatement* _tmp43_;
			GearyDbStatement* _tmp44_;
			GearyDbResult* _tmp45_;
			GearyDbResult* _tmp46_;
			GearyDbStatement* _tmp47_;
			GearyDbStatement* _tmp48_;
			GearyDbStatement* _tmp49_;
			GearyDbStatement* _tmp50_;
			GearyImapEmailFlags* _tmp51_;
			gchar* _tmp52_;
			gchar* _tmp53_;
			GearyDbStatement* _tmp54_;
			GearyDbStatement* _tmp55_;
			GearyDbStatement* _tmp56_;
			GearyImapDBEmailIdentifier* _tmp57_;
			gint64 _tmp58_;
			gint64 _tmp59_;
			GearyDbStatement* _tmp60_;
			GearyDbStatement* _tmp61_;
			GearyDbStatement* _tmp62_;
			_tmp7_ = _id_it;
			if (!gee_iterator_next (_tmp7_)) {
				break;
			}
			_tmp8_ = _id_it;
			_tmp9_ = gee_iterator_get (_tmp8_);
			id = (GearyImapDBEmailIdentifier*) _tmp9_;
			_tmp10_ = id;
			_tmp11_ = geary_imap_db_folder_do_get_location_for_id (self, cx, _tmp10_, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDE_MARKED_FOR_REMOVE, cancellable, &_inner_error0_);
			location = _tmp11_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				_g_object_unref0 (update_search);
				_g_object_unref0 (update_message);
				return;
			}
			_tmp12_ = location;
			if (_tmp12_ == NULL) {
				GearyImapDBEmailIdentifier* _tmp13_;
				gchar* _tmp14_;
				gchar* _tmp15_;
				GError* _tmp16_;
				GError* _tmp17_;
				_tmp13_ = id;
				_tmp14_ = geary_email_identifier_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp13_, GEARY_TYPE_EMAIL_IDENTIFIER, GearyEmailIdentifier));
				_tmp15_ = _tmp14_;
				_tmp16_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_NOT_FOUND, "Email not found: %s", _tmp15_);
				_tmp17_ = _tmp16_;
				_g_free0 (_tmp15_);
				_inner_error0_ = _tmp17_;
				g_propagate_error (error, _inner_error0_);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				_g_object_unref0 (update_search);
				_g_object_unref0 (update_message);
				return;
			}
			_tmp18_ = id;
			_tmp19_ = gee_map_get (map, _tmp18_);
			_tmp20_ = (GearyEmailFlags*) _tmp19_;
			_tmp21_ = GEARY_IMAP_IS_EMAIL_FLAGS (_tmp20_) ? ((GearyImapEmailFlags*) _tmp20_) : NULL;
			if (_tmp21_ == NULL) {
				_g_object_unref0 (_tmp20_);
			}
			flags = _tmp21_;
			_tmp22_ = flags;
			if (_tmp22_ == NULL) {
				GError* _tmp23_;
				_tmp23_ = g_error_new_literal (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_BAD_PARAMETERS, "Email with Geary.Imap.EmailFlags required");
				_inner_error0_ = _tmp23_;
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (flags);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				_g_object_unref0 (update_search);
				_g_object_unref0 (update_message);
				return;
			}
			_tmp24_ = update_message;
			_tmp25_ = geary_db_statement_reset (_tmp24_, GEARY_DB_RESET_SCOPE_CLEAR_BINDINGS, &_inner_error0_);
			_tmp26_ = _tmp25_;
			_g_object_unref0 (_tmp26_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (flags);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				_g_object_unref0 (update_search);
				_g_object_unref0 (update_message);
				return;
			}
			_tmp27_ = update_message;
			_tmp28_ = flags;
			_tmp29_ = geary_imap_email_flags_get_message_flags (_tmp28_);
			_tmp30_ = _tmp29_;
			_tmp31_ = geary_imap_flags_serialize (G_TYPE_CHECK_INSTANCE_CAST (_tmp30_, GEARY_IMAP_TYPE_FLAGS, GearyImapFlags));
			_tmp32_ = _tmp31_;
			_tmp33_ = geary_db_statement_bind_string (_tmp27_, 0, _tmp32_, &_inner_error0_);
			_tmp34_ = _tmp33_;
			_g_object_unref0 (_tmp34_);
			_g_free0 (_tmp32_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (flags);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				_g_object_unref0 (update_search);
				_g_object_unref0 (update_message);
				return;
			}
			_tmp35_ = update_message;
			_tmp36_ = geary_db_statement_bind_int (_tmp35_, 1, (gint) GEARY_EMAIL_FIELD_FLAGS, &_inner_error0_);
			_tmp37_ = _tmp36_;
			_g_object_unref0 (_tmp37_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (flags);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				_g_object_unref0 (update_search);
				_g_object_unref0 (update_message);
				return;
			}
			_tmp38_ = update_message;
			_tmp39_ = id;
			_tmp40_ = geary_imap_db_email_identifier_get_message_id (_tmp39_);
			_tmp41_ = _tmp40_;
			_tmp42_ = geary_db_statement_bind_rowid (_tmp38_, 2, _tmp41_, &_inner_error0_);
			_tmp43_ = _tmp42_;
			_g_object_unref0 (_tmp43_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (flags);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				_g_object_unref0 (update_search);
				_g_object_unref0 (update_message);
				return;
			}
			_tmp44_ = update_message;
			_tmp45_ = geary_db_statement_exec (_tmp44_, cancellable, &_inner_error0_);
			_tmp46_ = _tmp45_;
			_g_object_unref0 (_tmp46_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (flags);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				_g_object_unref0 (update_search);
				_g_object_unref0 (update_message);
				return;
			}
			_tmp47_ = update_search;
			_tmp48_ = geary_db_statement_reset (_tmp47_, GEARY_DB_RESET_SCOPE_CLEAR_BINDINGS, &_inner_error0_);
			_tmp49_ = _tmp48_;
			_g_object_unref0 (_tmp49_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (flags);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				_g_object_unref0 (update_search);
				_g_object_unref0 (update_message);
				return;
			}
			_tmp50_ = update_search;
			_tmp51_ = flags;
			_tmp52_ = geary_named_flags_serialise (G_TYPE_CHECK_INSTANCE_CAST (_tmp51_, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags));
			_tmp53_ = _tmp52_;
			_tmp54_ = geary_db_statement_bind_string (_tmp50_, 0, _tmp53_, &_inner_error0_);
			_tmp55_ = _tmp54_;
			_g_object_unref0 (_tmp55_);
			_g_free0 (_tmp53_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (flags);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				_g_object_unref0 (update_search);
				_g_object_unref0 (update_message);
				return;
			}
			_tmp56_ = update_search;
			_tmp57_ = id;
			_tmp58_ = geary_imap_db_email_identifier_get_message_id (_tmp57_);
			_tmp59_ = _tmp58_;
			_tmp60_ = geary_db_statement_bind_rowid (_tmp56_, 1, _tmp59_, &_inner_error0_);
			_tmp61_ = _tmp60_;
			_g_object_unref0 (_tmp61_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (flags);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				_g_object_unref0 (update_search);
				_g_object_unref0 (update_message);
				return;
			}
			_tmp62_ = update_search;
			geary_db_statement_exec_insert (_tmp62_, cancellable, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (flags);
				_geary_imap_db_folder_location_identifier_unref0 (location);
				_g_object_unref0 (id);
				_g_object_unref0 (_id_it);
				_g_object_unref0 (update_search);
				_g_object_unref0 (update_message);
				return;
			}
			_g_object_unref0 (flags);
			_geary_imap_db_folder_location_identifier_unref0 (location);
			_g_object_unref0 (id);
		}
		_g_object_unref0 (_id_it);
	}
	_g_object_unref0 (update_search);
	_g_object_unref0 (update_message);
}

static gboolean
geary_imap_db_folder_do_fetch_email_fields (GearyImapDBFolder* self,
                                            GearyDbConnection* cx,
                                            gint64 message_id,
                                            GearyEmailField* fields,
                                            GCancellable* cancellable,
                                            GError** error)
{
	GearyEmailField _vala_fields = 0;
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbResult* results = NULL;
	GearyDbStatement* _tmp6_;
	GearyDbResult* _tmp7_;
	GearyDbResult* _tmp9_;
	gboolean _tmp10_;
	gboolean _tmp11_;
	gint _tmp12_ = 0;
	GearyDbResult* _tmp13_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_FOLDER (self), FALSE);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), FALSE);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), FALSE);
	_tmp0_ = geary_db_connection_prepare (cx, "SELECT fields FROM MessageTable WHERE id=?", &_inner_error0_);
	stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp1_ = FALSE;
		g_propagate_error (error, _inner_error0_);
		return _tmp1_;
	}
	_tmp2_ = stmt;
	_tmp3_ = geary_db_statement_bind_rowid (_tmp2_, 0, message_id, &_inner_error0_);
	_tmp4_ = _tmp3_;
	_g_object_unref0 (_tmp4_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp5_ = FALSE;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return _tmp5_;
	}
	_tmp6_ = stmt;
	_tmp7_ = geary_db_statement_exec (_tmp6_, cancellable, &_inner_error0_);
	results = _tmp7_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp8_ = FALSE;
		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_) {
		_vala_fields = GEARY_EMAIL_FIELD_NONE;
		result = FALSE;
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		if (fields) {
			*fields = _vala_fields;
		}
		return result;
	}
	_tmp13_ = results;
	_tmp12_ = geary_db_result_int_at (_tmp13_, 0, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp14_ = FALSE;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		return _tmp14_;
	}
	_vala_fields = (GearyEmailField) _tmp12_;
	result = TRUE;
	_g_object_unref0 (results);
	_g_object_unref0 (stmt);
	if (fields) {
		*fields = _vala_fields;
	}
	return result;
}

static void
geary_imap_db_folder_do_merge_message_row (GearyImapDBFolder* self,
                                           GearyDbConnection* cx,
                                           GearyImapDBMessageRow* row,
                                           GearyEmailField* new_fields,
                                           gint* unread_count_change,
                                           GCancellable* cancellable,
                                           GError** error)
{
	GearyEmailField _vala_new_fields = 0;
	GearyEmailField available_fields = 0;
	gboolean _tmp0_ = FALSE;
	gint64 _tmp1_;
	gint64 _tmp2_;
	GearyEmailField _tmp3_ = 0;
	gboolean _tmp4_;
	GearyEmailField _tmp11_;
	GearyEmailField _tmp12_;
	GearyEmailField _tmp13_;
	GearyEmailField _tmp14_;
	GearyEmailField _tmp15_;
	GearyEmailField _tmp16_;
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp219_;
	GearyDbStatement* _tmp220_;
	GearyDbStatement* _tmp221_;
	GearyDbStatement* _tmp222_;
	GearyDbStatement* _tmp223_;
	gint64 _tmp224_;
	gint64 _tmp225_;
	GearyDbStatement* _tmp226_;
	GearyDbStatement* _tmp227_;
	GearyDbStatement* _tmp228_;
	GearyDbResult* _tmp229_;
	GearyDbResult* _tmp230_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_DB_IS_CONNECTION (cx));
	g_return_if_fail (GEARY_IMAP_DB_IS_MESSAGE_ROW (row));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_tmp1_ = geary_imap_db_message_row_get_id (row);
	_tmp2_ = _tmp1_;
	_tmp4_ = geary_imap_db_folder_do_fetch_email_fields (self, cx, _tmp2_, &_tmp3_, cancellable, &_inner_error0_);
	available_fields = _tmp3_;
	_tmp0_ = _tmp4_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	if (!_tmp0_) {
		gint64 _tmp5_;
		gint64 _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		GError* _tmp9_;
		GError* _tmp10_;
		_tmp5_ = geary_imap_db_message_row_get_id (row);
		_tmp6_ = _tmp5_;
		_tmp7_ = g_strdup_printf ("%" G_GINT64_FORMAT, _tmp6_);
		_tmp8_ = _tmp7_;
		_tmp9_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_NOT_FOUND, "No message with ID %s found in database", _tmp8_);
		_tmp10_ = _tmp9_;
		_g_free0 (_tmp8_);
		_inner_error0_ = _tmp10_;
		g_propagate_error (error, _inner_error0_);
		return;
	}
	_tmp11_ = geary_imap_db_message_row_get_fields (row);
	_tmp12_ = _tmp11_;
	_tmp13_ = geary_imap_db_message_row_get_fields (row);
	_tmp14_ = _tmp13_;
	_vala_new_fields = (_tmp12_ ^ available_fields) & _tmp14_;
	_tmp15_ = geary_imap_db_message_row_get_fields (row);
	_tmp16_ = _tmp15_;
	_vala_new_fields = _vala_new_fields | (_tmp16_ & GEARY_EMAIL_MUTABLE_FIELDS);
	if (_vala_new_fields == GEARY_EMAIL_FIELD_NONE) {
		if (new_fields) {
			*new_fields = _vala_new_fields;
		}
		return;
	}
	if (geary_email_field_is_any_set (_vala_new_fields, GEARY_EMAIL_FIELD_DATE)) {
		GearyDbStatement* stmt = NULL;
		GearyDbStatement* _tmp17_;
		GearyDbStatement* _tmp18_;
		const gchar* _tmp19_;
		const gchar* _tmp20_;
		GearyDbStatement* _tmp21_;
		GearyDbStatement* _tmp22_;
		GearyDbStatement* _tmp23_;
		gint64 _tmp24_;
		gint64 _tmp25_;
		GearyDbStatement* _tmp26_;
		GearyDbStatement* _tmp27_;
		GearyDbStatement* _tmp28_;
		gint64 _tmp29_;
		gint64 _tmp30_;
		GearyDbStatement* _tmp31_;
		GearyDbStatement* _tmp32_;
		GearyDbStatement* _tmp33_;
		GearyDbResult* _tmp34_;
		GearyDbResult* _tmp35_;
		_tmp17_ = geary_db_connection_prepare (cx, "UPDATE MessageTable SET date_field=?, date_time_t=? WHERE id=?", &_inner_error0_);
		stmt = _tmp17_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			return;
		}
		_tmp18_ = stmt;
		_tmp19_ = geary_imap_db_message_row_get_date (row);
		_tmp20_ = _tmp19_;
		_tmp21_ = geary_db_statement_bind_string (_tmp18_, 0, _tmp20_, &_inner_error0_);
		_tmp22_ = _tmp21_;
		_g_object_unref0 (_tmp22_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp23_ = stmt;
		_tmp24_ = geary_imap_db_message_row_get_date_time_t (row);
		_tmp25_ = _tmp24_;
		_tmp26_ = geary_db_statement_bind_int64 (_tmp23_, 1, _tmp25_, &_inner_error0_);
		_tmp27_ = _tmp26_;
		_g_object_unref0 (_tmp27_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp28_ = stmt;
		_tmp29_ = geary_imap_db_message_row_get_id (row);
		_tmp30_ = _tmp29_;
		_tmp31_ = geary_db_statement_bind_rowid (_tmp28_, 2, _tmp30_, &_inner_error0_);
		_tmp32_ = _tmp31_;
		_g_object_unref0 (_tmp32_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp33_ = stmt;
		_tmp34_ = geary_db_statement_exec (_tmp33_, cancellable, &_inner_error0_);
		_tmp35_ = _tmp34_;
		_g_object_unref0 (_tmp35_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_g_object_unref0 (stmt);
	}
	if (geary_email_field_is_any_set (_vala_new_fields, GEARY_EMAIL_FIELD_ORIGINATORS)) {
		GearyDbStatement* stmt = NULL;
		GearyDbStatement* _tmp36_;
		GearyDbStatement* _tmp37_;
		const gchar* _tmp38_;
		const gchar* _tmp39_;
		GearyDbStatement* _tmp40_;
		GearyDbStatement* _tmp41_;
		GearyDbStatement* _tmp42_;
		const gchar* _tmp43_;
		const gchar* _tmp44_;
		GearyDbStatement* _tmp45_;
		GearyDbStatement* _tmp46_;
		GearyDbStatement* _tmp47_;
		const gchar* _tmp48_;
		const gchar* _tmp49_;
		GearyDbStatement* _tmp50_;
		GearyDbStatement* _tmp51_;
		GearyDbStatement* _tmp52_;
		gint64 _tmp53_;
		gint64 _tmp54_;
		GearyDbStatement* _tmp55_;
		GearyDbStatement* _tmp56_;
		GearyDbStatement* _tmp57_;
		GearyDbResult* _tmp58_;
		GearyDbResult* _tmp59_;
		_tmp36_ = geary_db_connection_prepare (cx, "UPDATE MessageTable SET from_field=?, sender=?, reply_to=? WHERE id=?", &_inner_error0_);
		stmt = _tmp36_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			return;
		}
		_tmp37_ = stmt;
		_tmp38_ = geary_imap_db_message_row_get_from (row);
		_tmp39_ = _tmp38_;
		_tmp40_ = geary_db_statement_bind_string (_tmp37_, 0, _tmp39_, &_inner_error0_);
		_tmp41_ = _tmp40_;
		_g_object_unref0 (_tmp41_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp42_ = stmt;
		_tmp43_ = geary_imap_db_message_row_get_sender (row);
		_tmp44_ = _tmp43_;
		_tmp45_ = geary_db_statement_bind_string (_tmp42_, 1, _tmp44_, &_inner_error0_);
		_tmp46_ = _tmp45_;
		_g_object_unref0 (_tmp46_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp47_ = stmt;
		_tmp48_ = geary_imap_db_message_row_get_reply_to (row);
		_tmp49_ = _tmp48_;
		_tmp50_ = geary_db_statement_bind_string (_tmp47_, 2, _tmp49_, &_inner_error0_);
		_tmp51_ = _tmp50_;
		_g_object_unref0 (_tmp51_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp52_ = stmt;
		_tmp53_ = geary_imap_db_message_row_get_id (row);
		_tmp54_ = _tmp53_;
		_tmp55_ = geary_db_statement_bind_rowid (_tmp52_, 3, _tmp54_, &_inner_error0_);
		_tmp56_ = _tmp55_;
		_g_object_unref0 (_tmp56_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp57_ = stmt;
		_tmp58_ = geary_db_statement_exec (_tmp57_, cancellable, &_inner_error0_);
		_tmp59_ = _tmp58_;
		_g_object_unref0 (_tmp59_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_g_object_unref0 (stmt);
	}
	if (geary_email_field_is_any_set (_vala_new_fields, GEARY_EMAIL_FIELD_RECEIVERS)) {
		GearyDbStatement* stmt = NULL;
		GearyDbStatement* _tmp60_;
		GearyDbStatement* _tmp61_;
		const gchar* _tmp62_;
		const gchar* _tmp63_;
		GearyDbStatement* _tmp64_;
		GearyDbStatement* _tmp65_;
		GearyDbStatement* _tmp66_;
		const gchar* _tmp67_;
		const gchar* _tmp68_;
		GearyDbStatement* _tmp69_;
		GearyDbStatement* _tmp70_;
		GearyDbStatement* _tmp71_;
		const gchar* _tmp72_;
		const gchar* _tmp73_;
		GearyDbStatement* _tmp74_;
		GearyDbStatement* _tmp75_;
		GearyDbStatement* _tmp76_;
		gint64 _tmp77_;
		gint64 _tmp78_;
		GearyDbStatement* _tmp79_;
		GearyDbStatement* _tmp80_;
		GearyDbStatement* _tmp81_;
		GearyDbResult* _tmp82_;
		GearyDbResult* _tmp83_;
		_tmp60_ = geary_db_connection_prepare (cx, "UPDATE MessageTable SET to_field=?, cc=?, bcc=? WHERE id=?", &_inner_error0_);
		stmt = _tmp60_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			return;
		}
		_tmp61_ = stmt;
		_tmp62_ = geary_imap_db_message_row_get_to (row);
		_tmp63_ = _tmp62_;
		_tmp64_ = geary_db_statement_bind_string (_tmp61_, 0, _tmp63_, &_inner_error0_);
		_tmp65_ = _tmp64_;
		_g_object_unref0 (_tmp65_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp66_ = stmt;
		_tmp67_ = geary_imap_db_message_row_get_cc (row);
		_tmp68_ = _tmp67_;
		_tmp69_ = geary_db_statement_bind_string (_tmp66_, 1, _tmp68_, &_inner_error0_);
		_tmp70_ = _tmp69_;
		_g_object_unref0 (_tmp70_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp71_ = stmt;
		_tmp72_ = geary_imap_db_message_row_get_bcc (row);
		_tmp73_ = _tmp72_;
		_tmp74_ = geary_db_statement_bind_string (_tmp71_, 2, _tmp73_, &_inner_error0_);
		_tmp75_ = _tmp74_;
		_g_object_unref0 (_tmp75_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp76_ = stmt;
		_tmp77_ = geary_imap_db_message_row_get_id (row);
		_tmp78_ = _tmp77_;
		_tmp79_ = geary_db_statement_bind_rowid (_tmp76_, 3, _tmp78_, &_inner_error0_);
		_tmp80_ = _tmp79_;
		_g_object_unref0 (_tmp80_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp81_ = stmt;
		_tmp82_ = geary_db_statement_exec (_tmp81_, cancellable, &_inner_error0_);
		_tmp83_ = _tmp82_;
		_g_object_unref0 (_tmp83_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_g_object_unref0 (stmt);
	}
	if (geary_email_field_is_any_set (_vala_new_fields, GEARY_EMAIL_FIELD_REFERENCES)) {
		GearyDbStatement* stmt = NULL;
		GearyDbStatement* _tmp84_;
		GearyDbStatement* _tmp85_;
		const gchar* _tmp86_;
		const gchar* _tmp87_;
		GearyDbStatement* _tmp88_;
		GearyDbStatement* _tmp89_;
		GearyDbStatement* _tmp90_;
		const gchar* _tmp91_;
		const gchar* _tmp92_;
		GearyDbStatement* _tmp93_;
		GearyDbStatement* _tmp94_;
		GearyDbStatement* _tmp95_;
		const gchar* _tmp96_;
		const gchar* _tmp97_;
		GearyDbStatement* _tmp98_;
		GearyDbStatement* _tmp99_;
		GearyDbStatement* _tmp100_;
		gint64 _tmp101_;
		gint64 _tmp102_;
		GearyDbStatement* _tmp103_;
		GearyDbStatement* _tmp104_;
		GearyDbStatement* _tmp105_;
		GearyDbResult* _tmp106_;
		GearyDbResult* _tmp107_;
		_tmp84_ = geary_db_connection_prepare (cx, "UPDATE MessageTable SET message_id=?, in_reply_to=?, reference_ids=? W" \
"HERE id=?", &_inner_error0_);
		stmt = _tmp84_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			return;
		}
		_tmp85_ = stmt;
		_tmp86_ = geary_imap_db_message_row_get_message_id (row);
		_tmp87_ = _tmp86_;
		_tmp88_ = geary_db_statement_bind_string (_tmp85_, 0, _tmp87_, &_inner_error0_);
		_tmp89_ = _tmp88_;
		_g_object_unref0 (_tmp89_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp90_ = stmt;
		_tmp91_ = geary_imap_db_message_row_get_in_reply_to (row);
		_tmp92_ = _tmp91_;
		_tmp93_ = geary_db_statement_bind_string (_tmp90_, 1, _tmp92_, &_inner_error0_);
		_tmp94_ = _tmp93_;
		_g_object_unref0 (_tmp94_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp95_ = stmt;
		_tmp96_ = geary_imap_db_message_row_get_references (row);
		_tmp97_ = _tmp96_;
		_tmp98_ = geary_db_statement_bind_string (_tmp95_, 2, _tmp97_, &_inner_error0_);
		_tmp99_ = _tmp98_;
		_g_object_unref0 (_tmp99_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp100_ = stmt;
		_tmp101_ = geary_imap_db_message_row_get_id (row);
		_tmp102_ = _tmp101_;
		_tmp103_ = geary_db_statement_bind_rowid (_tmp100_, 3, _tmp102_, &_inner_error0_);
		_tmp104_ = _tmp103_;
		_g_object_unref0 (_tmp104_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp105_ = stmt;
		_tmp106_ = geary_db_statement_exec (_tmp105_, cancellable, &_inner_error0_);
		_tmp107_ = _tmp106_;
		_g_object_unref0 (_tmp107_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_g_object_unref0 (stmt);
	}
	if (geary_email_field_is_any_set (_vala_new_fields, GEARY_EMAIL_FIELD_SUBJECT)) {
		GearyDbStatement* stmt = NULL;
		GearyDbStatement* _tmp108_;
		GearyDbStatement* _tmp109_;
		const gchar* _tmp110_;
		const gchar* _tmp111_;
		GearyDbStatement* _tmp112_;
		GearyDbStatement* _tmp113_;
		GearyDbStatement* _tmp114_;
		gint64 _tmp115_;
		gint64 _tmp116_;
		GearyDbStatement* _tmp117_;
		GearyDbStatement* _tmp118_;
		GearyDbStatement* _tmp119_;
		GearyDbResult* _tmp120_;
		GearyDbResult* _tmp121_;
		_tmp108_ = geary_db_connection_prepare (cx, "UPDATE MessageTable SET subject=? WHERE id=?", &_inner_error0_);
		stmt = _tmp108_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			return;
		}
		_tmp109_ = stmt;
		_tmp110_ = geary_imap_db_message_row_get_subject (row);
		_tmp111_ = _tmp110_;
		_tmp112_ = geary_db_statement_bind_string (_tmp109_, 0, _tmp111_, &_inner_error0_);
		_tmp113_ = _tmp112_;
		_g_object_unref0 (_tmp113_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp114_ = stmt;
		_tmp115_ = geary_imap_db_message_row_get_id (row);
		_tmp116_ = _tmp115_;
		_tmp117_ = geary_db_statement_bind_rowid (_tmp114_, 1, _tmp116_, &_inner_error0_);
		_tmp118_ = _tmp117_;
		_g_object_unref0 (_tmp118_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp119_ = stmt;
		_tmp120_ = geary_db_statement_exec (_tmp119_, cancellable, &_inner_error0_);
		_tmp121_ = _tmp120_;
		_g_object_unref0 (_tmp121_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_g_object_unref0 (stmt);
	}
	if (geary_email_field_is_any_set (_vala_new_fields, GEARY_EMAIL_FIELD_HEADER)) {
		GearyDbStatement* stmt = NULL;
		GearyDbStatement* _tmp122_;
		GearyDbStatement* _tmp123_;
		GearyMemoryBuffer* _tmp124_;
		GearyMemoryBuffer* _tmp125_;
		GearyDbStatement* _tmp126_;
		GearyDbStatement* _tmp127_;
		GearyDbStatement* _tmp128_;
		gint64 _tmp129_;
		gint64 _tmp130_;
		GearyDbStatement* _tmp131_;
		GearyDbStatement* _tmp132_;
		GearyDbStatement* _tmp133_;
		GearyDbResult* _tmp134_;
		GearyDbResult* _tmp135_;
		_tmp122_ = geary_db_connection_prepare (cx, "UPDATE MessageTable SET header=? WHERE id=?", &_inner_error0_);
		stmt = _tmp122_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			return;
		}
		_tmp123_ = stmt;
		_tmp124_ = geary_imap_db_message_row_get_header (row);
		_tmp125_ = _tmp124_;
		_tmp126_ = geary_db_statement_bind_string_buffer (_tmp123_, 0, _tmp125_, &_inner_error0_);
		_tmp127_ = _tmp126_;
		_g_object_unref0 (_tmp127_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp128_ = stmt;
		_tmp129_ = geary_imap_db_message_row_get_id (row);
		_tmp130_ = _tmp129_;
		_tmp131_ = geary_db_statement_bind_rowid (_tmp128_, 1, _tmp130_, &_inner_error0_);
		_tmp132_ = _tmp131_;
		_g_object_unref0 (_tmp132_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp133_ = stmt;
		_tmp134_ = geary_db_statement_exec (_tmp133_, cancellable, &_inner_error0_);
		_tmp135_ = _tmp134_;
		_g_object_unref0 (_tmp135_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_g_object_unref0 (stmt);
	}
	if (geary_email_field_is_any_set (_vala_new_fields, GEARY_EMAIL_FIELD_BODY)) {
		GearyDbStatement* stmt = NULL;
		GearyDbStatement* _tmp136_;
		GearyDbStatement* _tmp137_;
		GearyMemoryBuffer* _tmp138_;
		GearyMemoryBuffer* _tmp139_;
		GearyDbStatement* _tmp140_;
		GearyDbStatement* _tmp141_;
		GearyDbStatement* _tmp142_;
		gint64 _tmp143_;
		gint64 _tmp144_;
		GearyDbStatement* _tmp145_;
		GearyDbStatement* _tmp146_;
		GearyDbStatement* _tmp147_;
		GearyDbResult* _tmp148_;
		GearyDbResult* _tmp149_;
		_tmp136_ = geary_db_connection_prepare (cx, "UPDATE MessageTable SET body=? WHERE id=?", &_inner_error0_);
		stmt = _tmp136_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			return;
		}
		_tmp137_ = stmt;
		_tmp138_ = geary_imap_db_message_row_get_body (row);
		_tmp139_ = _tmp138_;
		_tmp140_ = geary_db_statement_bind_string_buffer (_tmp137_, 0, _tmp139_, &_inner_error0_);
		_tmp141_ = _tmp140_;
		_g_object_unref0 (_tmp141_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp142_ = stmt;
		_tmp143_ = geary_imap_db_message_row_get_id (row);
		_tmp144_ = _tmp143_;
		_tmp145_ = geary_db_statement_bind_rowid (_tmp142_, 1, _tmp144_, &_inner_error0_);
		_tmp146_ = _tmp145_;
		_g_object_unref0 (_tmp146_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp147_ = stmt;
		_tmp148_ = geary_db_statement_exec (_tmp147_, cancellable, &_inner_error0_);
		_tmp149_ = _tmp148_;
		_g_object_unref0 (_tmp149_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_g_object_unref0 (stmt);
	}
	if (geary_email_field_is_any_set (_vala_new_fields, GEARY_EMAIL_FIELD_PREVIEW)) {
		GearyDbStatement* stmt = NULL;
		GearyDbStatement* _tmp150_;
		GearyDbStatement* _tmp151_;
		const gchar* _tmp152_;
		const gchar* _tmp153_;
		GearyDbStatement* _tmp154_;
		GearyDbStatement* _tmp155_;
		GearyDbStatement* _tmp156_;
		gint64 _tmp157_;
		gint64 _tmp158_;
		GearyDbStatement* _tmp159_;
		GearyDbStatement* _tmp160_;
		GearyDbStatement* _tmp161_;
		GearyDbResult* _tmp162_;
		GearyDbResult* _tmp163_;
		_tmp150_ = geary_db_connection_prepare (cx, "UPDATE MessageTable SET preview=? WHERE id=?", &_inner_error0_);
		stmt = _tmp150_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			return;
		}
		_tmp151_ = stmt;
		_tmp152_ = geary_imap_db_message_row_get_preview (row);
		_tmp153_ = _tmp152_;
		_tmp154_ = geary_db_statement_bind_string (_tmp151_, 0, _tmp153_, &_inner_error0_);
		_tmp155_ = _tmp154_;
		_g_object_unref0 (_tmp155_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp156_ = stmt;
		_tmp157_ = geary_imap_db_message_row_get_id (row);
		_tmp158_ = _tmp157_;
		_tmp159_ = geary_db_statement_bind_rowid (_tmp156_, 1, _tmp158_, &_inner_error0_);
		_tmp160_ = _tmp159_;
		_g_object_unref0 (_tmp160_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp161_ = stmt;
		_tmp162_ = geary_db_statement_exec (_tmp161_, cancellable, &_inner_error0_);
		_tmp163_ = _tmp162_;
		_g_object_unref0 (_tmp163_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_g_object_unref0 (stmt);
	}
	if (geary_email_field_is_any_set (_vala_new_fields, GEARY_EMAIL_FIELD_FLAGS)) {
		GearyEmailFlags* old_flags = NULL;
		gint64 _tmp164_;
		gint64 _tmp165_;
		GearyEmailFlags* _tmp166_;
		GearyEmailFlags* new_flags = NULL;
		const gchar* _tmp167_;
		const gchar* _tmp168_;
		GearyImapMessageFlags* _tmp169_;
		GearyImapMessageFlags* _tmp170_;
		GearyImapEmailFlags* _tmp171_;
		GearyEmailFlags* _tmp172_;
		gboolean _tmp173_ = FALSE;
		GearyEmailFlags* _tmp174_;
		GearyDbStatement* stmt = NULL;
		GearyDbStatement* _tmp181_;
		GearyDbStatement* _tmp182_;
		const gchar* _tmp183_;
		const gchar* _tmp184_;
		GearyDbStatement* _tmp185_;
		GearyDbStatement* _tmp186_;
		GearyDbStatement* _tmp187_;
		gint64 _tmp188_;
		gint64 _tmp189_;
		GearyDbStatement* _tmp190_;
		GearyDbStatement* _tmp191_;
		GearyDbStatement* _tmp192_;
		GearyDbResult* _tmp193_;
		GearyDbResult* _tmp194_;
		_tmp164_ = geary_imap_db_message_row_get_id (row);
		_tmp165_ = _tmp164_;
		_tmp166_ = geary_imap_db_folder_do_get_email_flags_single (self, cx, _tmp165_, cancellable, &_inner_error0_);
		old_flags = _tmp166_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			return;
		}
		_tmp167_ = geary_imap_db_message_row_get_email_flags (row);
		_tmp168_ = _tmp167_;
		_tmp169_ = geary_imap_message_flags_deserialize (_tmp168_);
		_tmp170_ = _tmp169_;
		_tmp171_ = geary_imap_email_flags_new (_tmp170_);
		_tmp172_ = G_TYPE_CHECK_INSTANCE_CAST (_tmp171_, GEARY_TYPE_EMAIL_FLAGS, GearyEmailFlags);
		_g_object_unref0 (_tmp170_);
		new_flags = _tmp172_;
		_tmp174_ = old_flags;
		if (_tmp174_ != NULL) {
			GearyEmailFlags* _tmp175_;
			GearyEmailFlags* _tmp176_;
			_tmp175_ = old_flags;
			_tmp176_ = new_flags;
			_tmp173_ = geary_email_flags_is_unread (_tmp175_) != geary_email_flags_is_unread (_tmp176_);
		} else {
			_tmp173_ = FALSE;
		}
		if (_tmp173_) {
			gint _tmp177_ = 0;
			GearyEmailFlags* _tmp178_;
			_tmp178_ = new_flags;
			if (geary_email_flags_is_unread (_tmp178_)) {
				_tmp177_ = 1;
			} else {
				_tmp177_ = -1;
			}
			*unread_count_change = (*unread_count_change) + _tmp177_;
		} else {
			GearyEmailFlags* _tmp179_;
			_tmp179_ = new_flags;
			if (geary_email_flags_is_unread (_tmp179_)) {
				gint _tmp180_;
				_tmp180_ = *unread_count_change;
				*unread_count_change = _tmp180_ + 1;
			}
		}
		_tmp181_ = geary_db_connection_prepare (cx, "UPDATE MessageTable SET flags=? WHERE id=?", &_inner_error0_);
		stmt = _tmp181_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (new_flags);
			_g_object_unref0 (old_flags);
			return;
		}
		_tmp182_ = stmt;
		_tmp183_ = geary_imap_db_message_row_get_email_flags (row);
		_tmp184_ = _tmp183_;
		_tmp185_ = geary_db_statement_bind_string (_tmp182_, 0, _tmp184_, &_inner_error0_);
		_tmp186_ = _tmp185_;
		_g_object_unref0 (_tmp186_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_g_object_unref0 (new_flags);
			_g_object_unref0 (old_flags);
			return;
		}
		_tmp187_ = stmt;
		_tmp188_ = geary_imap_db_message_row_get_id (row);
		_tmp189_ = _tmp188_;
		_tmp190_ = geary_db_statement_bind_rowid (_tmp187_, 1, _tmp189_, &_inner_error0_);
		_tmp191_ = _tmp190_;
		_g_object_unref0 (_tmp191_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_g_object_unref0 (new_flags);
			_g_object_unref0 (old_flags);
			return;
		}
		_tmp192_ = stmt;
		_tmp193_ = geary_db_statement_exec (_tmp192_, cancellable, &_inner_error0_);
		_tmp194_ = _tmp193_;
		_g_object_unref0 (_tmp194_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			_g_object_unref0 (new_flags);
			_g_object_unref0 (old_flags);
			return;
		}
		_g_object_unref0 (stmt);
		_g_object_unref0 (new_flags);
		_g_object_unref0 (old_flags);
	}
	if (geary_email_field_is_any_set (_vala_new_fields, GEARY_EMAIL_FIELD_PROPERTIES)) {
		GearyDbStatement* stmt = NULL;
		GearyDbStatement* _tmp195_;
		GearyDbStatement* _tmp196_;
		const gchar* _tmp197_;
		const gchar* _tmp198_;
		GearyDbStatement* _tmp199_;
		GearyDbStatement* _tmp200_;
		GearyDbStatement* _tmp201_;
		gint64 _tmp202_;
		gint64 _tmp203_;
		GearyDbStatement* _tmp204_;
		GearyDbStatement* _tmp205_;
		GearyDbStatement* _tmp206_;
		gint64 _tmp207_;
		gint64 _tmp208_;
		GearyDbStatement* _tmp209_;
		GearyDbStatement* _tmp210_;
		GearyDbStatement* _tmp211_;
		gint64 _tmp212_;
		gint64 _tmp213_;
		GearyDbStatement* _tmp214_;
		GearyDbStatement* _tmp215_;
		GearyDbStatement* _tmp216_;
		GearyDbResult* _tmp217_;
		GearyDbResult* _tmp218_;
		_tmp195_ = geary_db_connection_prepare (cx, "UPDATE MessageTable SET internaldate=?, internaldate_time_t=?, rfc822_" \
"size=? WHERE id=?", &_inner_error0_);
		stmt = _tmp195_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			return;
		}
		_tmp196_ = stmt;
		_tmp197_ = geary_imap_db_message_row_get_internaldate (row);
		_tmp198_ = _tmp197_;
		_tmp199_ = geary_db_statement_bind_string (_tmp196_, 0, _tmp198_, &_inner_error0_);
		_tmp200_ = _tmp199_;
		_g_object_unref0 (_tmp200_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp201_ = stmt;
		_tmp202_ = geary_imap_db_message_row_get_internaldate_time_t (row);
		_tmp203_ = _tmp202_;
		_tmp204_ = geary_db_statement_bind_int64 (_tmp201_, 1, _tmp203_, &_inner_error0_);
		_tmp205_ = _tmp204_;
		_g_object_unref0 (_tmp205_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp206_ = stmt;
		_tmp207_ = geary_imap_db_message_row_get_rfc822_size (row);
		_tmp208_ = _tmp207_;
		_tmp209_ = geary_db_statement_bind_int64 (_tmp206_, 2, _tmp208_, &_inner_error0_);
		_tmp210_ = _tmp209_;
		_g_object_unref0 (_tmp210_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp211_ = stmt;
		_tmp212_ = geary_imap_db_message_row_get_id (row);
		_tmp213_ = _tmp212_;
		_tmp214_ = geary_db_statement_bind_rowid (_tmp211_, 3, _tmp213_, &_inner_error0_);
		_tmp215_ = _tmp214_;
		_g_object_unref0 (_tmp215_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_tmp216_ = stmt;
		_tmp217_ = geary_db_statement_exec (_tmp216_, cancellable, &_inner_error0_);
		_tmp218_ = _tmp217_;
		_g_object_unref0 (_tmp218_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (stmt);
			return;
		}
		_g_object_unref0 (stmt);
	}
	_tmp219_ = geary_db_connection_prepare (cx, "UPDATE MessageTable SET fields = fields | ? WHERE id=?", &_inner_error0_);
	stmt = _tmp219_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	_tmp220_ = stmt;
	_tmp221_ = geary_db_statement_bind_int (_tmp220_, 0, (gint) _vala_new_fields, &_inner_error0_);
	_tmp222_ = _tmp221_;
	_g_object_unref0 (_tmp222_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	_tmp223_ = stmt;
	_tmp224_ = geary_imap_db_message_row_get_id (row);
	_tmp225_ = _tmp224_;
	_tmp226_ = geary_db_statement_bind_rowid (_tmp223_, 1, _tmp225_, &_inner_error0_);
	_tmp227_ = _tmp226_;
	_g_object_unref0 (_tmp227_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	_tmp228_ = stmt;
	_tmp229_ = geary_db_statement_exec (_tmp228_, cancellable, &_inner_error0_);
	_tmp230_ = _tmp229_;
	_g_object_unref0 (_tmp230_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	_g_object_unref0 (stmt);
	if (new_fields) {
		*new_fields = _vala_new_fields;
	}
}

static void
geary_imap_db_folder_do_merge_email_in_search_table (GearyImapDBFolder* self,
                                                     GearyDbConnection* cx,
                                                     gint64 message_id,
                                                     GearyEmailField new_fields,
                                                     GearyEmail* email,
                                                     GCancellable* cancellable,
                                                     GError** error)
{
	GearyDbStatement* select = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp1_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbResult* row = NULL;
	GearyDbStatement* _tmp4_;
	GearyDbResult* _tmp5_;
	gchar* body = NULL;
	GearyDbResult* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* attachments = NULL;
	GearyDbResult* _tmp9_;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* subject = NULL;
	GearyDbResult* _tmp12_;
	const gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* from = NULL;
	GearyDbResult* _tmp15_;
	const gchar* _tmp16_;
	gchar* _tmp17_;
	gchar* recipients = NULL;
	GearyDbResult* _tmp18_;
	const gchar* _tmp19_;
	gchar* _tmp20_;
	gchar* cc = NULL;
	GearyDbResult* _tmp21_;
	const gchar* _tmp22_;
	gchar* _tmp23_;
	gchar* bcc = NULL;
	GearyDbResult* _tmp24_;
	const gchar* _tmp25_;
	gchar* _tmp26_;
	gchar* flags = NULL;
	GearyDbResult* _tmp27_;
	const gchar* _tmp28_;
	gchar* _tmp29_;
	gboolean _tmp30_ = FALSE;
	GearyDbStatement* del = NULL;
	GearyDbStatement* _tmp67_;
	GearyDbStatement* _tmp68_;
	GearyDbStatement* _tmp69_;
	GearyDbStatement* _tmp70_;
	GearyDbStatement* _tmp71_;
	GearyDbResult* _tmp72_;
	GearyDbResult* _tmp73_;
	GearyDbStatement* insert = NULL;
	GearyDbStatement* _tmp74_;
	GearyDbStatement* _tmp75_;
	GearyDbStatement* _tmp76_;
	GearyDbStatement* _tmp77_;
	GearyDbStatement* _tmp78_;
	const gchar* _tmp79_;
	GearyDbStatement* _tmp80_;
	GearyDbStatement* _tmp81_;
	GearyDbStatement* _tmp82_;
	const gchar* _tmp83_;
	GearyDbStatement* _tmp84_;
	GearyDbStatement* _tmp85_;
	GearyDbStatement* _tmp86_;
	const gchar* _tmp87_;
	GearyDbStatement* _tmp88_;
	GearyDbStatement* _tmp89_;
	GearyDbStatement* _tmp90_;
	const gchar* _tmp91_;
	GearyDbStatement* _tmp92_;
	GearyDbStatement* _tmp93_;
	GearyDbStatement* _tmp94_;
	const gchar* _tmp95_;
	GearyDbStatement* _tmp96_;
	GearyDbStatement* _tmp97_;
	GearyDbStatement* _tmp98_;
	const gchar* _tmp99_;
	GearyDbStatement* _tmp100_;
	GearyDbStatement* _tmp101_;
	GearyDbStatement* _tmp102_;
	const gchar* _tmp103_;
	GearyDbStatement* _tmp104_;
	GearyDbStatement* _tmp105_;
	GearyDbStatement* _tmp106_;
	const gchar* _tmp107_;
	GearyDbStatement* _tmp108_;
	GearyDbStatement* _tmp109_;
	GearyDbStatement* _tmp110_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_DB_IS_CONNECTION (cx));
	g_return_if_fail (GEARY_IS_EMAIL (email));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_tmp0_ = geary_db_connection_prepare (cx, "\n" \
"            SELECT body, attachments, subject, \"from\", receivers, cc" \
", bcc, flags\n" \
"            FROM MessageSearchTable\n" \
"            WHERE rowid=?\n" \
"        ", &_inner_error0_);
	select = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	_tmp1_ = select;
	_tmp2_ = geary_db_statement_bind_rowid (_tmp1_, 0, message_id, &_inner_error0_);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp3_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (select);
		return;
	}
	_tmp4_ = select;
	_tmp5_ = geary_db_statement_exec (_tmp4_, cancellable, &_inner_error0_);
	row = _tmp5_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (select);
		return;
	}
	_tmp6_ = row;
	_tmp7_ = geary_db_result_string_at (_tmp6_, 0, &_inner_error0_);
	_tmp8_ = g_strdup (_tmp7_);
	body = _tmp8_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_tmp9_ = row;
	_tmp10_ = geary_db_result_string_at (_tmp9_, 1, &_inner_error0_);
	_tmp11_ = g_strdup (_tmp10_);
	attachments = _tmp11_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_tmp12_ = row;
	_tmp13_ = geary_db_result_string_at (_tmp12_, 2, &_inner_error0_);
	_tmp14_ = g_strdup (_tmp13_);
	subject = _tmp14_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_free0 (attachments);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_tmp15_ = row;
	_tmp16_ = geary_db_result_string_at (_tmp15_, 3, &_inner_error0_);
	_tmp17_ = g_strdup (_tmp16_);
	from = _tmp17_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_free0 (subject);
		_g_free0 (attachments);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_tmp18_ = row;
	_tmp19_ = geary_db_result_string_at (_tmp18_, 4, &_inner_error0_);
	_tmp20_ = g_strdup (_tmp19_);
	recipients = _tmp20_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_free0 (from);
		_g_free0 (subject);
		_g_free0 (attachments);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_tmp21_ = row;
	_tmp22_ = geary_db_result_string_at (_tmp21_, 5, &_inner_error0_);
	_tmp23_ = g_strdup (_tmp22_);
	cc = _tmp23_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_free0 (recipients);
		_g_free0 (from);
		_g_free0 (subject);
		_g_free0 (attachments);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_tmp24_ = row;
	_tmp25_ = geary_db_result_string_at (_tmp24_, 6, &_inner_error0_);
	_tmp26_ = g_strdup (_tmp25_);
	bcc = _tmp26_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_free0 (cc);
		_g_free0 (recipients);
		_g_free0 (from);
		_g_free0 (subject);
		_g_free0 (attachments);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_tmp27_ = row;
	_tmp28_ = geary_db_result_string_at (_tmp27_, 7, &_inner_error0_);
	_tmp29_ = g_strdup (_tmp28_);
	flags = _tmp29_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_free0 (bcc);
		_g_free0 (cc);
		_g_free0 (recipients);
		_g_free0 (from);
		_g_free0 (subject);
		_g_free0 (attachments);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	if (geary_email_field_is_any_set (new_fields, GEARY_EMAIL_REQUIRED_FOR_MESSAGE)) {
		GearyEmailField _tmp31_;
		GearyEmailField _tmp32_;
		_tmp31_ = geary_email_get_fields (email);
		_tmp32_ = _tmp31_;
		_tmp30_ = geary_email_field_is_all_set (_tmp32_, GEARY_EMAIL_REQUIRED_FOR_MESSAGE);
	} else {
		_tmp30_ = FALSE;
	}
	if (_tmp30_) {
		{
			GearyRFC822Message* _tmp33_ = NULL;
			GearyRFC822Message* _tmp34_;
			gchar* _tmp35_ = NULL;
			gchar* _tmp36_;
			gchar* _tmp37_;
			_tmp34_ = geary_email_get_message (email, &_inner_error0_);
			_tmp33_ = _tmp34_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_tmp36_ = geary_rf_c822_message_get_searchable_body (_tmp33_, TRUE, &_inner_error0_);
			_tmp35_ = _tmp36_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_object_unref0 (_tmp33_);
				goto __catch0_g_error;
			}
			_tmp37_ = _tmp35_;
			_tmp35_ = NULL;
			_g_free0 (body);
			body = _tmp37_;
			_g_free0 (_tmp35_);
			_g_object_unref0 (_tmp33_);
		}
		goto __finally0;
		__catch0_g_error:
		{
			g_clear_error (&_inner_error0_);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_free0 (flags);
			_g_free0 (bcc);
			_g_free0 (cc);
			_g_free0 (recipients);
			_g_free0 (from);
			_g_free0 (subject);
			_g_free0 (attachments);
			_g_free0 (body);
			_g_object_unref0 (row);
			_g_object_unref0 (select);
			return;
		}
		{
			GearyRFC822Message* _tmp38_ = NULL;
			GearyRFC822Message* _tmp39_;
			gchar* _tmp40_;
			_tmp39_ = geary_email_get_message (email, &_inner_error0_);
			_tmp38_ = _tmp39_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch1_g_error;
			}
			_tmp40_ = geary_rf_c822_message_get_searchable_recipients (_tmp38_);
			_g_free0 (recipients);
			recipients = _tmp40_;
			_g_object_unref0 (_tmp38_);
		}
		goto __finally1;
		__catch1_g_error:
		{
			g_clear_error (&_inner_error0_);
		}
		__finally1:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_free0 (flags);
			_g_free0 (bcc);
			_g_free0 (cc);
			_g_free0 (recipients);
			_g_free0 (from);
			_g_free0 (subject);
			_g_free0 (attachments);
			_g_free0 (body);
			_g_object_unref0 (row);
			_g_object_unref0 (select);
			return;
		}
	}
	if (geary_email_field_is_any_set (new_fields, GEARY_EMAIL_FIELD_SUBJECT)) {
		GearyRFC822Subject* _tmp41_;
		GearyRFC822Subject* _tmp42_;
		_tmp41_ = geary_email_header_set_get_subject (G_TYPE_CHECK_INSTANCE_CAST (email, GEARY_TYPE_EMAIL_HEADER_SET, GearyEmailHeaderSet));
		_tmp42_ = _tmp41_;
		if (_tmp42_ != NULL) {
			GearyRFC822Subject* _tmp43_;
			GearyRFC822Subject* _tmp44_;
			gchar* _tmp45_;
			gchar* _tmp46_;
			_tmp43_ = geary_email_header_set_get_subject (G_TYPE_CHECK_INSTANCE_CAST (email, GEARY_TYPE_EMAIL_HEADER_SET, GearyEmailHeaderSet));
			_tmp44_ = _tmp43_;
			_tmp45_ = geary_message_data_searchable_message_data_to_searchable_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp44_, GEARY_MESSAGE_DATA_TYPE_SEARCHABLE_MESSAGE_DATA, GearyMessageDataSearchableMessageData));
			_tmp46_ = _tmp45_;
			_g_free0 (_tmp46_);
		}
	}
	if (geary_email_field_is_any_set (new_fields, GEARY_EMAIL_FIELD_ORIGINATORS)) {
		GearyRFC822MailboxAddresses* _tmp47_;
		GearyRFC822MailboxAddresses* _tmp48_;
		_tmp47_ = geary_email_header_set_get_from (G_TYPE_CHECK_INSTANCE_CAST (email, GEARY_TYPE_EMAIL_HEADER_SET, GearyEmailHeaderSet));
		_tmp48_ = _tmp47_;
		if (_tmp48_ != NULL) {
			GearyRFC822MailboxAddresses* _tmp49_;
			GearyRFC822MailboxAddresses* _tmp50_;
			gchar* _tmp51_;
			_tmp49_ = geary_email_header_set_get_from (G_TYPE_CHECK_INSTANCE_CAST (email, GEARY_TYPE_EMAIL_HEADER_SET, GearyEmailHeaderSet));
			_tmp50_ = _tmp49_;
			_tmp51_ = geary_message_data_searchable_message_data_to_searchable_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp50_, GEARY_MESSAGE_DATA_TYPE_SEARCHABLE_MESSAGE_DATA, GearyMessageDataSearchableMessageData));
			_g_free0 (from);
			from = _tmp51_;
		}
	}
	if (geary_email_field_is_any_set (new_fields, GEARY_EMAIL_FIELD_RECEIVERS)) {
		GearyRFC822MailboxAddresses* _tmp52_;
		GearyRFC822MailboxAddresses* _tmp53_;
		GearyRFC822MailboxAddresses* _tmp57_;
		GearyRFC822MailboxAddresses* _tmp58_;
		_tmp52_ = geary_email_header_set_get_cc (G_TYPE_CHECK_INSTANCE_CAST (email, GEARY_TYPE_EMAIL_HEADER_SET, GearyEmailHeaderSet));
		_tmp53_ = _tmp52_;
		if (_tmp53_ != NULL) {
			GearyRFC822MailboxAddresses* _tmp54_;
			GearyRFC822MailboxAddresses* _tmp55_;
			gchar* _tmp56_;
			_tmp54_ = geary_email_header_set_get_cc (G_TYPE_CHECK_INSTANCE_CAST (email, GEARY_TYPE_EMAIL_HEADER_SET, GearyEmailHeaderSet));
			_tmp55_ = _tmp54_;
			_tmp56_ = geary_message_data_searchable_message_data_to_searchable_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp55_, GEARY_MESSAGE_DATA_TYPE_SEARCHABLE_MESSAGE_DATA, GearyMessageDataSearchableMessageData));
			_g_free0 (cc);
			cc = _tmp56_;
		}
		_tmp57_ = geary_email_header_set_get_bcc (G_TYPE_CHECK_INSTANCE_CAST (email, GEARY_TYPE_EMAIL_HEADER_SET, GearyEmailHeaderSet));
		_tmp58_ = _tmp57_;
		if (_tmp58_ != NULL) {
			GearyRFC822MailboxAddresses* _tmp59_;
			GearyRFC822MailboxAddresses* _tmp60_;
			gchar* _tmp61_;
			_tmp59_ = geary_email_header_set_get_bcc (G_TYPE_CHECK_INSTANCE_CAST (email, GEARY_TYPE_EMAIL_HEADER_SET, GearyEmailHeaderSet));
			_tmp60_ = _tmp59_;
			_tmp61_ = geary_message_data_searchable_message_data_to_searchable_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp60_, GEARY_MESSAGE_DATA_TYPE_SEARCHABLE_MESSAGE_DATA, GearyMessageDataSearchableMessageData));
			_g_free0 (bcc);
			bcc = _tmp61_;
		}
	}
	if (geary_email_field_is_any_set (new_fields, GEARY_EMAIL_FIELD_FLAGS)) {
		GearyEmailFlags* _tmp62_;
		GearyEmailFlags* _tmp63_;
		_tmp62_ = geary_email_get_email_flags (email);
		_tmp63_ = _tmp62_;
		if (_tmp63_ != NULL) {
			GearyEmailFlags* _tmp64_;
			GearyEmailFlags* _tmp65_;
			gchar* _tmp66_;
			_tmp64_ = geary_email_get_email_flags (email);
			_tmp65_ = _tmp64_;
			_tmp66_ = geary_named_flags_serialise (G_TYPE_CHECK_INSTANCE_CAST (_tmp65_, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags));
			_g_free0 (flags);
			flags = _tmp66_;
		}
	}
	_tmp67_ = geary_db_connection_prepare (cx, "DELETE FROM MessageSearchTable WHERE rowid=?", &_inner_error0_);
	del = _tmp67_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_free0 (flags);
		_g_free0 (bcc);
		_g_free0 (cc);
		_g_free0 (recipients);
		_g_free0 (from);
		_g_free0 (subject);
		_g_free0 (attachments);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_tmp68_ = del;
	_tmp69_ = geary_db_statement_bind_rowid (_tmp68_, 0, message_id, &_inner_error0_);
	_tmp70_ = _tmp69_;
	_g_object_unref0 (_tmp70_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (del);
		_g_free0 (flags);
		_g_free0 (bcc);
		_g_free0 (cc);
		_g_free0 (recipients);
		_g_free0 (from);
		_g_free0 (subject);
		_g_free0 (attachments);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_tmp71_ = del;
	_tmp72_ = geary_db_statement_exec (_tmp71_, cancellable, &_inner_error0_);
	_tmp73_ = _tmp72_;
	_g_object_unref0 (_tmp73_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (del);
		_g_free0 (flags);
		_g_free0 (bcc);
		_g_free0 (cc);
		_g_free0 (recipients);
		_g_free0 (from);
		_g_free0 (subject);
		_g_free0 (attachments);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_tmp74_ = geary_db_connection_prepare (cx, "\n" \
"            INSERT INTO MessageSearchTable\n" \
"                (rowid, body, attachments, subject, \"from\", receiver" \
"s, cc, bcc, flags)\n" \
"            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)\n" \
"        ", &_inner_error0_);
	insert = _tmp74_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (del);
		_g_free0 (flags);
		_g_free0 (bcc);
		_g_free0 (cc);
		_g_free0 (recipients);
		_g_free0 (from);
		_g_free0 (subject);
		_g_free0 (attachments);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_tmp75_ = insert;
	_tmp76_ = geary_db_statement_bind_rowid (_tmp75_, 0, message_id, &_inner_error0_);
	_tmp77_ = _tmp76_;
	_g_object_unref0 (_tmp77_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (insert);
		_g_object_unref0 (del);
		_g_free0 (flags);
		_g_free0 (bcc);
		_g_free0 (cc);
		_g_free0 (recipients);
		_g_free0 (from);
		_g_free0 (subject);
		_g_free0 (attachments);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_tmp78_ = insert;
	_tmp79_ = body;
	_tmp80_ = geary_db_statement_bind_string (_tmp78_, 1, _tmp79_, &_inner_error0_);
	_tmp81_ = _tmp80_;
	_g_object_unref0 (_tmp81_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (insert);
		_g_object_unref0 (del);
		_g_free0 (flags);
		_g_free0 (bcc);
		_g_free0 (cc);
		_g_free0 (recipients);
		_g_free0 (from);
		_g_free0 (subject);
		_g_free0 (attachments);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_tmp82_ = insert;
	_tmp83_ = attachments;
	_tmp84_ = geary_db_statement_bind_string (_tmp82_, 2, _tmp83_, &_inner_error0_);
	_tmp85_ = _tmp84_;
	_g_object_unref0 (_tmp85_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (insert);
		_g_object_unref0 (del);
		_g_free0 (flags);
		_g_free0 (bcc);
		_g_free0 (cc);
		_g_free0 (recipients);
		_g_free0 (from);
		_g_free0 (subject);
		_g_free0 (attachments);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_tmp86_ = insert;
	_tmp87_ = subject;
	_tmp88_ = geary_db_statement_bind_string (_tmp86_, 3, _tmp87_, &_inner_error0_);
	_tmp89_ = _tmp88_;
	_g_object_unref0 (_tmp89_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (insert);
		_g_object_unref0 (del);
		_g_free0 (flags);
		_g_free0 (bcc);
		_g_free0 (cc);
		_g_free0 (recipients);
		_g_free0 (from);
		_g_free0 (subject);
		_g_free0 (attachments);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_tmp90_ = insert;
	_tmp91_ = from;
	_tmp92_ = geary_db_statement_bind_string (_tmp90_, 4, _tmp91_, &_inner_error0_);
	_tmp93_ = _tmp92_;
	_g_object_unref0 (_tmp93_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (insert);
		_g_object_unref0 (del);
		_g_free0 (flags);
		_g_free0 (bcc);
		_g_free0 (cc);
		_g_free0 (recipients);
		_g_free0 (from);
		_g_free0 (subject);
		_g_free0 (attachments);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_tmp94_ = insert;
	_tmp95_ = recipients;
	_tmp96_ = geary_db_statement_bind_string (_tmp94_, 5, _tmp95_, &_inner_error0_);
	_tmp97_ = _tmp96_;
	_g_object_unref0 (_tmp97_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (insert);
		_g_object_unref0 (del);
		_g_free0 (flags);
		_g_free0 (bcc);
		_g_free0 (cc);
		_g_free0 (recipients);
		_g_free0 (from);
		_g_free0 (subject);
		_g_free0 (attachments);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_tmp98_ = insert;
	_tmp99_ = cc;
	_tmp100_ = geary_db_statement_bind_string (_tmp98_, 6, _tmp99_, &_inner_error0_);
	_tmp101_ = _tmp100_;
	_g_object_unref0 (_tmp101_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (insert);
		_g_object_unref0 (del);
		_g_free0 (flags);
		_g_free0 (bcc);
		_g_free0 (cc);
		_g_free0 (recipients);
		_g_free0 (from);
		_g_free0 (subject);
		_g_free0 (attachments);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_tmp102_ = insert;
	_tmp103_ = bcc;
	_tmp104_ = geary_db_statement_bind_string (_tmp102_, 7, _tmp103_, &_inner_error0_);
	_tmp105_ = _tmp104_;
	_g_object_unref0 (_tmp105_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (insert);
		_g_object_unref0 (del);
		_g_free0 (flags);
		_g_free0 (bcc);
		_g_free0 (cc);
		_g_free0 (recipients);
		_g_free0 (from);
		_g_free0 (subject);
		_g_free0 (attachments);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_tmp106_ = insert;
	_tmp107_ = flags;
	_tmp108_ = geary_db_statement_bind_string (_tmp106_, 8, _tmp107_, &_inner_error0_);
	_tmp109_ = _tmp108_;
	_g_object_unref0 (_tmp109_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (insert);
		_g_object_unref0 (del);
		_g_free0 (flags);
		_g_free0 (bcc);
		_g_free0 (cc);
		_g_free0 (recipients);
		_g_free0 (from);
		_g_free0 (subject);
		_g_free0 (attachments);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_tmp110_ = insert;
	geary_db_statement_exec_insert (_tmp110_, cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (insert);
		_g_object_unref0 (del);
		_g_free0 (flags);
		_g_free0 (bcc);
		_g_free0 (cc);
		_g_free0 (recipients);
		_g_free0 (from);
		_g_free0 (subject);
		_g_free0 (attachments);
		_g_free0 (body);
		_g_object_unref0 (row);
		_g_object_unref0 (select);
		return;
	}
	_g_object_unref0 (insert);
	_g_object_unref0 (del);
	_g_free0 (flags);
	_g_free0 (bcc);
	_g_free0 (cc);
	_g_free0 (recipients);
	_g_free0 (from);
	_g_free0 (subject);
	_g_free0 (attachments);
	_g_free0 (body);
	_g_object_unref0 (row);
	_g_object_unref0 (select);
}

static void
geary_imap_db_folder_do_merge_email_flags (GearyImapDBFolder* self,
                                           GearyDbConnection* cx,
                                           GearyImapDBFolderLocationIdentifier* location,
                                           GearyEmail* email,
                                           GearyEmailField* pre_fields,
                                           GearyEmailField* post_fields,
                                           gint* unread_count_change,
                                           GCancellable* cancellable,
                                           GError** error)
{
	GearyEmailField _vala_pre_fields = 0;
	GearyEmailField _vala_post_fields = 0;
	GearyEmailField _tmp0_;
	GearyEmailField _tmp1_;
	GearyImapDBMessageRow* row = NULL;
	GearyEmailField _tmp2_ = 0;
	GearyImapDBMessageRow* _tmp3_;
	GearyEmail* row_email = NULL;
	GearyImapDBMessageRow* _tmp4_;
	GearyImapDBEmailIdentifier* _tmp5_;
	GearyEmail* _tmp6_;
	gboolean _tmp7_ = FALSE;
	GearyEmail* _tmp8_;
	GearyEmailFlags* _tmp9_;
	GearyEmailFlags* _tmp10_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_DB_IS_CONNECTION (cx));
	g_return_if_fail (GEARY_IMAP_DB_FOLDER_IS_LOCATION_IDENTIFIER (location));
	g_return_if_fail (GEARY_IS_EMAIL (email));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_tmp0_ = geary_email_get_fields (email);
	_tmp1_ = _tmp0_;
	_vala_assert (_tmp1_ == GEARY_EMAIL_FIELD_FLAGS, "email.fields == Geary.Email.Field.FLAGS");
	_tmp3_ = geary_imap_db_folder_do_fetch_message_row (cx, location->message_id, GEARY_EMAIL_FIELD_FLAGS, &_tmp2_, cancellable, &_inner_error0_);
	_vala_pre_fields = _tmp2_;
	row = _tmp3_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	_vala_post_fields = _vala_pre_fields;
	_tmp4_ = row;
	_tmp5_ = location->email_id;
	_tmp6_ = geary_imap_db_message_row_to_email (_tmp4_, _tmp5_, &_inner_error0_);
	row_email = _tmp6_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_geary_imap_db_message_row_unref0 (row);
		return;
	}
	_tmp8_ = row_email;
	_tmp9_ = geary_email_get_email_flags (_tmp8_);
	_tmp10_ = _tmp9_;
	if (_tmp10_ == NULL) {
		_tmp7_ = TRUE;
	} else {
		GearyEmail* _tmp11_;
		GearyEmailFlags* _tmp12_;
		GearyEmailFlags* _tmp13_;
		GearyEmailFlags* _tmp14_;
		GearyEmailFlags* _tmp15_;
		_tmp11_ = row_email;
		_tmp12_ = geary_email_get_email_flags (_tmp11_);
		_tmp13_ = _tmp12_;
		_tmp14_ = geary_email_get_email_flags (email);
		_tmp15_ = _tmp14_;
		_tmp7_ = !gee_hashable_equal_to (G_TYPE_CHECK_INSTANCE_CAST (_tmp13_, GEE_TYPE_HASHABLE, GeeHashable), G_TYPE_CHECK_INSTANCE_CAST (_tmp15_, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags));
	}
	if (_tmp7_) {
		gboolean _tmp16_ = FALSE;
		GearyEmail* _tmp17_;
		GearyEmailFlags* _tmp18_;
		GearyEmailFlags* _tmp19_;
		GearyEmail* _tmp28_;
		GearyEmailIdentifier* _tmp29_;
		GearyEmailIdentifier* _tmp30_;
		GearyEmailFlags* _tmp31_;
		GearyEmailFlags* _tmp32_;
		GeeMap* _tmp33_;
		GeeMap* _tmp34_;
		_tmp17_ = row_email;
		_tmp18_ = geary_email_get_email_flags (_tmp17_);
		_tmp19_ = _tmp18_;
		if (_tmp19_ != NULL) {
			GearyEmail* _tmp20_;
			GearyEmailFlags* _tmp21_;
			GearyEmailFlags* _tmp22_;
			GearyEmailFlags* _tmp23_;
			GearyEmailFlags* _tmp24_;
			_tmp20_ = row_email;
			_tmp21_ = geary_email_get_email_flags (_tmp20_);
			_tmp22_ = _tmp21_;
			_tmp23_ = geary_email_get_email_flags (email);
			_tmp24_ = _tmp23_;
			_tmp16_ = geary_email_flags_is_unread (_tmp22_) != geary_email_flags_is_unread (_tmp24_);
		} else {
			_tmp16_ = FALSE;
		}
		if (_tmp16_) {
			gint _tmp25_ = 0;
			GearyEmailFlags* _tmp26_;
			GearyEmailFlags* _tmp27_;
			_tmp26_ = geary_email_get_email_flags (email);
			_tmp27_ = _tmp26_;
			if (geary_email_flags_is_unread (_tmp27_)) {
				_tmp25_ = 1;
			} else {
				_tmp25_ = -1;
			}
			*unread_count_change = (*unread_count_change) + _tmp25_;
		}
		_tmp28_ = row_email;
		_tmp29_ = geary_email_get_id (_tmp28_);
		_tmp30_ = _tmp29_;
		_tmp31_ = geary_email_get_email_flags (email);
		_tmp32_ = _tmp31_;
		_tmp33_ = geary_collection_single_map (GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEARY_TYPE_EMAIL_FLAGS, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, G_TYPE_CHECK_INSTANCE_CAST (_tmp30_, GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, GearyImapDBEmailIdentifier), _tmp32_);
		_tmp34_ = _tmp33_;
		geary_imap_db_folder_do_set_email_flags (self, cx, _tmp34_, cancellable, &_inner_error0_);
		_g_object_unref0 (_tmp34_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (row_email);
			_geary_imap_db_message_row_unref0 (row);
			return;
		}
		_vala_post_fields = _vala_post_fields | GEARY_EMAIL_FIELD_FLAGS;
	}
	_g_object_unref0 (row_email);
	_geary_imap_db_message_row_unref0 (row);
	if (pre_fields) {
		*pre_fields = _vala_pre_fields;
	}
	if (post_fields) {
		*post_fields = _vala_post_fields;
	}
}

static void
geary_imap_db_folder_do_merge_email (GearyImapDBFolder* self,
                                     GearyDbConnection* cx,
                                     GearyImapDBFolderLocationIdentifier* location,
                                     GearyEmail* email,
                                     GearyEmailField* pre_fields,
                                     GearyEmailField* post_fields,
                                     gint* unread_count_change,
                                     GCancellable* cancellable,
                                     GError** error)
{
	GearyEmailField _vala_pre_fields = 0;
	GearyEmailField _vala_post_fields = 0;
	GearyImapDBMessageRow* row = NULL;
	GearyEmailField _tmp0_;
	GearyEmailField _tmp1_;
	GearyEmailField _tmp2_ = 0;
	GearyImapDBMessageRow* _tmp3_;
	GearyEmailField fetched_fields = 0;
	GearyImapDBMessageRow* _tmp4_;
	GearyEmailField _tmp5_;
	GearyEmailField _tmp6_;
	GearyEmailField _tmp7_;
	GearyEmailField _tmp8_;
	GearyImapDBMessageRow* _tmp9_;
	GearyEmailField _tmp10_;
	GearyEmailField _tmp11_;
	gint new_unread_count = 0;
	gboolean _tmp12_ = FALSE;
	GearyEmailField _tmp13_;
	GearyEmailField _tmp14_;
	GearyEmailField _tmp15_;
	GearyEmailField _tmp16_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_DB_IS_CONNECTION (cx));
	g_return_if_fail (GEARY_IMAP_DB_FOLDER_IS_LOCATION_IDENTIFIER (location));
	g_return_if_fail (GEARY_IS_EMAIL (email));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_tmp0_ = geary_email_get_fields (email);
	_tmp1_ = _tmp0_;
	_tmp3_ = geary_imap_db_folder_do_fetch_message_row (cx, location->message_id, (_tmp1_ | GEARY_EMAIL_REQUIRED_FOR_MESSAGE) | GEARY_IMAP_DB_ATTACHMENT_REQUIRED_FIELDS, &_tmp2_, cancellable, &_inner_error0_);
	_vala_pre_fields = _tmp2_;
	row = _tmp3_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	_tmp4_ = row;
	_tmp5_ = geary_imap_db_message_row_get_fields (_tmp4_);
	_tmp6_ = _tmp5_;
	fetched_fields = _tmp6_;
	_tmp7_ = geary_email_get_fields (email);
	_tmp8_ = _tmp7_;
	_vala_post_fields = _vala_pre_fields | _tmp8_;
	_tmp9_ = row;
	geary_imap_db_message_row_merge_from_remote (_tmp9_, email);
	_tmp10_ = geary_email_get_fields (email);
	_tmp11_ = _tmp10_;
	if (_tmp11_ == GEARY_EMAIL_FIELD_NONE) {
		_geary_imap_db_message_row_unref0 (row);
		if (pre_fields) {
			*pre_fields = _vala_pre_fields;
		}
		if (post_fields) {
			*post_fields = _vala_post_fields;
		}
		return;
	}
	new_unread_count = 0;
	_tmp13_ = geary_email_get_fields (email);
	_tmp14_ = _tmp13_;
	_tmp15_ = geary_email_get_fields (email);
	_tmp16_ = _tmp15_;
	if ((fetched_fields & _tmp14_) != _tmp16_) {
		_tmp12_ = TRUE;
	} else {
		GearyEmailField _tmp17_;
		GearyEmailField _tmp18_;
		_tmp17_ = geary_email_get_fields (email);
		_tmp18_ = _tmp17_;
		_tmp12_ = geary_email_field_is_any_set (_tmp18_, GEARY_EMAIL_MUTABLE_FIELDS);
	}
	if (_tmp12_) {
		GearyEmail* combined_email = NULL;
		GearyImapDBMessageRow* _tmp19_;
		GearyImapDBEmailIdentifier* _tmp20_;
		GearyEmail* _tmp21_;
		gboolean _tmp22_ = FALSE;
		GearyEmailField new_fields = 0;
		GearyImapDBMessageRow* _tmp35_;
		GearyEmailField _tmp36_ = 0;
		gboolean _tmp37_ = FALSE;
		_tmp19_ = row;
		_tmp20_ = location->email_id;
		_tmp21_ = geary_imap_db_message_row_to_email (_tmp19_, _tmp20_, &_inner_error0_);
		combined_email = _tmp21_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_geary_imap_db_message_row_unref0 (row);
			return;
		}
		if (!geary_email_field_fulfills (fetched_fields, GEARY_IMAP_DB_ATTACHMENT_REQUIRED_FIELDS)) {
			GearyEmail* _tmp23_;
			GearyEmailField _tmp24_;
			GearyEmailField _tmp25_;
			_tmp23_ = combined_email;
			_tmp24_ = geary_email_get_fields (_tmp23_);
			_tmp25_ = _tmp24_;
			_tmp22_ = geary_email_field_fulfills (_tmp25_, GEARY_IMAP_DB_ATTACHMENT_REQUIRED_FIELDS);
		} else {
			_tmp22_ = FALSE;
		}
		if (_tmp22_) {
			GearyRFC822Message* _tmp26_ = NULL;
			GearyEmail* _tmp27_;
			GearyRFC822Message* _tmp28_;
			GeeList* _tmp29_ = NULL;
			GeeList* _tmp30_;
			GeeList* _tmp31_ = NULL;
			GFile* _tmp32_;
			GeeList* _tmp33_;
			GearyEmail* _tmp34_;
			_tmp27_ = combined_email;
			_tmp28_ = geary_email_get_message (_tmp27_, &_inner_error0_);
			_tmp26_ = _tmp28_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (combined_email);
				_geary_imap_db_message_row_unref0 (row);
				return;
			}
			_tmp30_ = geary_rf_c822_message_get_attachments (_tmp26_, GEARY_MIME_DISPOSITION_TYPE_UNSPECIFIED, &_inner_error0_);
			_tmp29_ = _tmp30_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (_tmp26_);
				_g_object_unref0 (combined_email);
				_geary_imap_db_message_row_unref0 (row);
				return;
			}
			_tmp32_ = self->priv->attachments_path;
			_tmp33_ = geary_imap_db_attachment_save_attachments (cx, _tmp32_, location->message_id, _tmp29_, cancellable, &_inner_error0_);
			_tmp31_ = _tmp33_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (_tmp29_);
				_g_object_unref0 (_tmp26_);
				_g_object_unref0 (combined_email);
				_geary_imap_db_message_row_unref0 (row);
				return;
			}
			_tmp34_ = combined_email;
			geary_email_add_attachments (_tmp34_, G_TYPE_CHECK_INSTANCE_CAST (_tmp31_, GEE_TYPE_COLLECTION, GeeCollection));
			_g_object_unref0 (_tmp31_);
			_g_object_unref0 (_tmp29_);
			_g_object_unref0 (_tmp26_);
		}
		_tmp35_ = row;
		geary_imap_db_folder_do_merge_message_row (self, cx, _tmp35_, &_tmp36_, &new_unread_count, cancellable, &_inner_error0_);
		new_fields = _tmp36_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (combined_email);
			_geary_imap_db_message_row_unref0 (row);
			return;
		}
		_tmp37_ = geary_imap_db_folder_do_check_for_message_search_row (cx, location->message_id, cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (combined_email);
			_geary_imap_db_message_row_unref0 (row);
			return;
		}
		if (_tmp37_) {
			GearyEmail* _tmp38_;
			_tmp38_ = combined_email;
			geary_imap_db_folder_do_merge_email_in_search_table (self, cx, location->message_id, new_fields, _tmp38_, cancellable, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (combined_email);
				_geary_imap_db_message_row_unref0 (row);
				return;
			}
		} else {
			GearyEmail* _tmp39_;
			_tmp39_ = combined_email;
			geary_imap_db_folder_do_add_email_to_search_table (cx, location->message_id, _tmp39_, cancellable, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (combined_email);
				_geary_imap_db_message_row_unref0 (row);
				return;
			}
		}
		_g_object_unref0 (combined_email);
	} else {
		GearyEmailFlags* combined_flags = NULL;
		GearyEmailFlags* _tmp40_;
		gboolean _tmp41_ = FALSE;
		GearyEmailFlags* _tmp42_;
		_tmp40_ = geary_imap_db_folder_do_get_email_flags_single (self, cx, location->message_id, cancellable, &_inner_error0_);
		combined_flags = _tmp40_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_geary_imap_db_message_row_unref0 (row);
			return;
		}
		_tmp42_ = combined_flags;
		if (_tmp42_ != NULL) {
			GearyEmailFlags* _tmp43_;
			_tmp43_ = combined_flags;
			_tmp41_ = geary_email_flags_is_unread (_tmp43_);
		} else {
			_tmp41_ = FALSE;
		}
		if (_tmp41_) {
			new_unread_count = 1;
		}
		_g_object_unref0 (combined_flags);
	}
	*unread_count_change = (*unread_count_change) + new_unread_count;
	_geary_imap_db_message_row_unref0 (row);
	if (pre_fields) {
		*pre_fields = _vala_pre_fields;
	}
	if (post_fields) {
		*post_fields = _vala_post_fields;
	}
}

/**
     * Adds a value to the unread count.  If this makes the unread count negative, it will be
     * set to zero.
     */
void
geary_imap_db_folder_do_add_to_unread_count (GearyImapDBFolder* self,
                                             GearyDbConnection* cx,
                                             gint to_add,
                                             GCancellable* cancellable,
                                             GError** error)
{
	GearyDbStatement* update_stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp1_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbStatement* _tmp5_;
	GearyDbStatement* _tmp6_;
	GearyDbStatement* _tmp7_;
	GearyDbStatement* _tmp8_;
	GearyDbStatement* _tmp9_;
	GearyDbStatement* _tmp10_;
	GearyDbResult* _tmp11_;
	GearyDbResult* _tmp12_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_DB_IS_CONNECTION (cx));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	if (to_add == 0) {
		return;
	}
	_tmp0_ = geary_db_connection_prepare (cx, "UPDATE FolderTable SET unread_count = CASE WHEN unread_count + ? < 0 T" \
"HEN 0 ELSE " "unread_count + ? END WHERE id=?", &_inner_error0_);
	update_stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	_tmp1_ = update_stmt;
	_tmp2_ = geary_db_statement_bind_int (_tmp1_, 0, to_add, &_inner_error0_);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp3_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (update_stmt);
		return;
	}
	_tmp4_ = update_stmt;
	_tmp5_ = geary_db_statement_bind_int (_tmp4_, 1, to_add, &_inner_error0_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp6_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (update_stmt);
		return;
	}
	_tmp7_ = update_stmt;
	_tmp8_ = geary_db_statement_bind_rowid (_tmp7_, 2, self->priv->folder_id, &_inner_error0_);
	_tmp9_ = _tmp8_;
	_g_object_unref0 (_tmp9_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (update_stmt);
		return;
	}
	_tmp10_ = update_stmt;
	_tmp11_ = geary_db_statement_exec (_tmp10_, cancellable, &_inner_error0_);
	_tmp12_ = _tmp11_;
	_g_object_unref0 (_tmp12_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (update_stmt);
		return;
	}
	_g_object_unref0 (update_stmt);
}

static GeeList*
geary_imap_db_folder_do_results_to_locations (GearyImapDBFolder* self,
                                              GearyDbResult* results,
                                              gint count,
                                              GearyImapDBFolderListFlags flags,
                                              GCancellable* cancellable,
                                              GError** error)
{
	GeeList* locations = NULL;
	GeeArrayList* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	GError* _inner_error0_ = NULL;
	GeeList* result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_FOLDER (self), NULL);
	g_return_val_if_fail (GEARY_DB_IS_RESULT (results), NULL);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), NULL);
	_tmp0_ = gee_array_list_new (GEARY_IMAP_DB_FOLDER_TYPE_LOCATION_IDENTIFIER, (GBoxedCopyFunc) geary_imap_db_folder_location_identifier_ref, (GDestroyNotify) geary_imap_db_folder_location_identifier_unref, NULL, NULL, NULL);
	locations = G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEE_TYPE_LIST, GeeList);
	_tmp1_ = geary_db_result_get_finished (results);
	_tmp2_ = _tmp1_;
	if (_tmp2_) {
		result = locations;
		return result;
	}
	{
		gboolean _tmp3_ = FALSE;
		_tmp3_ = TRUE;
		while (TRUE) {
			gint64 _tmp5_ = 0LL;
			gint64 _tmp6_ = 0LL;
			gboolean _tmp7_ = FALSE;
			GearyImapDBFolderLocationIdentifier* location = NULL;
			GearyImapUID* _tmp8_;
			GearyImapUID* _tmp9_;
			GearyImapDBFolderLocationIdentifier* _tmp10_;
			GearyImapDBFolderLocationIdentifier* _tmp11_;
			gboolean _tmp12_ = FALSE;
			GeeList* _tmp14_;
			GearyImapDBFolderLocationIdentifier* _tmp15_;
			GeeList* _tmp16_;
			gint _tmp17_;
			gint _tmp18_;
			if (!_tmp3_) {
				gboolean _tmp4_ = FALSE;
				_tmp4_ = geary_db_result_next (results, cancellable, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					g_propagate_error (error, _inner_error0_);
					_g_object_unref0 (locations);
					return NULL;
				}
				if (!_tmp4_) {
					break;
				}
			}
			_tmp3_ = FALSE;
			_tmp5_ = geary_db_result_rowid_for (results, "message_id", &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (locations);
				return NULL;
			}
			_tmp6_ = geary_db_result_int64_for (results, "ordering", &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (locations);
				return NULL;
			}
			_tmp7_ = geary_db_result_bool_for (results, "remove_marker", &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (locations);
				return NULL;
			}
			_tmp8_ = geary_imap_uid_new (_tmp6_);
			_tmp9_ = _tmp8_;
			_tmp10_ = geary_imap_db_folder_location_identifier_new (_tmp5_, _tmp9_, _tmp7_);
			_tmp11_ = _tmp10_;
			_g_object_unref0 (_tmp9_);
			location = _tmp11_;
			if (!geary_imap_db_folder_list_flags_include_marked_for_remove (flags)) {
				GearyImapDBFolderLocationIdentifier* _tmp13_;
				_tmp13_ = location;
				_tmp12_ = _tmp13_->marked_removed;
			} else {
				_tmp12_ = FALSE;
			}
			if (_tmp12_) {
				_geary_imap_db_folder_location_identifier_unref0 (location);
				continue;
			}
			_tmp14_ = locations;
			_tmp15_ = location;
			gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp14_, GEE_TYPE_COLLECTION, GeeCollection), _tmp15_);
			_tmp16_ = locations;
			_tmp17_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp16_, GEE_TYPE_COLLECTION, GeeCollection));
			_tmp18_ = _tmp17_;
			if (_tmp18_ >= count) {
				_geary_imap_db_folder_location_identifier_unref0 (location);
				break;
			}
			_geary_imap_db_folder_location_identifier_unref0 (location);
		}
	}
	result = locations;
	return result;
}

static void
geary_imap_db_folder_do_remove_complete_locations (GearyImapDBFolder* self,
                                                   GearyDbConnection* cx,
                                                   GeeList* locations,
                                                   GCancellable* cancellable,
                                                   GError** error)
{
	gboolean _tmp0_ = FALSE;
	GString* sql = NULL;
	GString* _tmp3_;
	gboolean first = FALSE;
	GString* _tmp16_;
	GearyDbStatement* stmt = NULL;
	GString* _tmp17_;
	const gchar* _tmp18_;
	GearyDbStatement* _tmp19_;
	GearyDbStatement* _tmp20_;
	GearyDbStatement* _tmp21_;
	GearyDbStatement* _tmp22_;
	GearyDbResult* results = NULL;
	GearyDbStatement* _tmp23_;
	GearyDbResult* _tmp24_;
	GeeHashSet* incomplete_locations = NULL;
	GeeHashSet* _tmp25_;
	GeeHashSet* _tmp33_;
	gint _tmp34_;
	gint _tmp35_;
	GeeIterator* iter = NULL;
	GeeIterator* _tmp36_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_DB_IS_CONNECTION (cx));
	g_return_if_fail ((locations == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (locations, GEE_TYPE_LIST));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	if (locations == NULL) {
		_tmp0_ = TRUE;
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (locations, GEE_TYPE_COLLECTION, GeeCollection));
		_tmp2_ = _tmp1_;
		_tmp0_ = _tmp2_ == 0;
	}
	if (_tmp0_) {
		return;
	}
	_tmp3_ = g_string_new ("\n            SELECT id FROM MessageTable WHERE id IN (\n        ");
	sql = _tmp3_;
	first = TRUE;
	{
		GeeList* _location_id_list = NULL;
		gint _location_id_size = 0;
		GeeList* _tmp4_;
		gint _tmp5_;
		gint _tmp6_;
		gint _location_id_index = 0;
		_location_id_list = locations;
		_tmp4_ = _location_id_list;
		_tmp5_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, GEE_TYPE_COLLECTION, GeeCollection));
		_tmp6_ = _tmp5_;
		_location_id_size = _tmp6_;
		_location_id_index = -1;
		while (TRUE) {
			gint _tmp7_;
			gint _tmp8_;
			GearyImapDBFolderLocationIdentifier* location_id = NULL;
			GeeList* _tmp9_;
			gpointer _tmp10_;
			GString* _tmp12_;
			GearyImapDBFolderLocationIdentifier* _tmp13_;
			gchar* _tmp14_;
			gchar* _tmp15_;
			_location_id_index = _location_id_index + 1;
			_tmp7_ = _location_id_index;
			_tmp8_ = _location_id_size;
			if (!(_tmp7_ < _tmp8_)) {
				break;
			}
			_tmp9_ = _location_id_list;
			_tmp10_ = gee_list_get (_tmp9_, _location_id_index);
			location_id = (GearyImapDBFolderLocationIdentifier*) _tmp10_;
			if (!first) {
				GString* _tmp11_;
				_tmp11_ = sql;
				g_string_append (_tmp11_, ",");
			}
			_tmp12_ = sql;
			_tmp13_ = location_id;
			_tmp14_ = g_strdup_printf ("%" G_GINT64_FORMAT, _tmp13_->message_id);
			_tmp15_ = _tmp14_;
			g_string_append (_tmp12_, _tmp15_);
			_g_free0 (_tmp15_);
			first = FALSE;
			_geary_imap_db_folder_location_identifier_unref0 (location_id);
		}
	}
	_tmp16_ = sql;
	g_string_append (_tmp16_, ") AND fields <> ?");
	_tmp17_ = sql;
	_tmp18_ = _tmp17_->str;
	_tmp19_ = geary_db_connection_prepare (cx, _tmp18_, &_inner_error0_);
	stmt = _tmp19_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_string_free0 (sql);
		return;
	}
	_tmp20_ = stmt;
	_tmp21_ = geary_db_statement_bind_int (_tmp20_, 0, (gint) GEARY_EMAIL_FIELD_ALL, &_inner_error0_);
	_tmp22_ = _tmp21_;
	_g_object_unref0 (_tmp22_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return;
	}
	_tmp23_ = stmt;
	_tmp24_ = geary_db_statement_exec (_tmp23_, cancellable, &_inner_error0_);
	results = _tmp24_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return;
	}
	_tmp25_ = gee_hash_set_new (G_TYPE_INT64, (GBoxedCopyFunc) _int64_dup, (GDestroyNotify) g_free, _geary_collection_int64_hash_func_gee_hash_data_func, NULL, NULL, _geary_collection_int64_equal_func_gee_equal_data_func, NULL, NULL);
	incomplete_locations = _tmp25_;
	while (TRUE) {
		GearyDbResult* _tmp26_;
		gboolean _tmp27_;
		gboolean _tmp28_;
		gint64 _tmp29_ = 0LL;
		GearyDbResult* _tmp30_;
		GeeHashSet* _tmp31_;
		GearyDbResult* _tmp32_;
		_tmp26_ = results;
		_tmp27_ = geary_db_result_get_finished (_tmp26_);
		_tmp28_ = _tmp27_;
		if (!(!_tmp28_)) {
			break;
		}
		_tmp30_ = results;
		_tmp29_ = geary_db_result_int64_at (_tmp30_, 0, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (incomplete_locations);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			_g_string_free0 (sql);
			return;
		}
		_tmp31_ = incomplete_locations;
		gee_abstract_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp31_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection), &_tmp29_);
		_tmp32_ = results;
		geary_db_result_next (_tmp32_, cancellable, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (incomplete_locations);
			_g_object_unref0 (results);
			_g_object_unref0 (stmt);
			_g_string_free0 (sql);
			return;
		}
	}
	_tmp33_ = incomplete_locations;
	_tmp34_ = gee_abstract_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp33_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection));
	_tmp35_ = _tmp34_;
	if (_tmp35_ == 0) {
		gee_collection_clear (G_TYPE_CHECK_INSTANCE_CAST (locations, GEE_TYPE_COLLECTION, GeeCollection));
		_g_object_unref0 (incomplete_locations);
		_g_object_unref0 (results);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return;
	}
	_tmp36_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (locations, GEE_TYPE_ITERABLE, GeeIterable));
	iter = _tmp36_;
	while (TRUE) {
		GeeIterator* _tmp37_;
		GeeHashSet* _tmp38_;
		GeeIterator* _tmp39_;
		gpointer _tmp40_;
		GearyImapDBFolderLocationIdentifier* _tmp41_;
		gboolean _tmp42_;
		_tmp37_ = iter;
		if (!gee_iterator_next (_tmp37_)) {
			break;
		}
		_tmp38_ = incomplete_locations;
		_tmp39_ = iter;
		_tmp40_ = gee_iterator_get (_tmp39_);
		_tmp41_ = (GearyImapDBFolderLocationIdentifier*) _tmp40_;
		_tmp42_ = !gee_abstract_collection_contains (G_TYPE_CHECK_INSTANCE_CAST (_tmp38_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection), &_tmp41_->message_id);
		_geary_imap_db_folder_location_identifier_unref0 (_tmp41_);
		if (_tmp42_) {
			GeeIterator* _tmp43_;
			_tmp43_ = iter;
			gee_iterator_remove (_tmp43_);
		}
	}
	_g_object_unref0 (iter);
	_g_object_unref0 (incomplete_locations);
	_g_object_unref0 (results);
	_g_object_unref0 (stmt);
	_g_string_free0 (sql);
}

static gpointer
_geary_imap_db_folder_location_identifier_ref0 (gpointer self)
{
	return self ? geary_imap_db_folder_location_identifier_ref (self) : NULL;
}

static GearyImapDBFolderLocationIdentifier*
geary_imap_db_folder_do_get_location_for_id (GearyImapDBFolder* self,
                                             GearyDbConnection* cx,
                                             GearyImapDBEmailIdentifier* id,
                                             GearyImapDBFolderListFlags flags,
                                             GCancellable* cancellable,
                                             GError** error)
{
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp1_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbStatement* _tmp4_;
	gint64 _tmp5_;
	gint64 _tmp6_;
	GearyDbStatement* _tmp7_;
	GearyDbStatement* _tmp8_;
	GearyDbResult* _result_ = NULL;
	GearyDbStatement* _tmp9_;
	GearyDbResult* _tmp10_;
	GearyDbResult* _tmp11_;
	gboolean _tmp12_;
	gboolean _tmp13_;
	gint64 _tmp14_ = 0LL;
	GearyDbResult* _tmp15_;
	gboolean _tmp16_ = FALSE;
	GearyDbResult* _tmp17_;
	GearyImapDBFolderLocationIdentifier* location = NULL;
	gint64 _tmp18_;
	gint64 _tmp19_;
	GearyImapUID* _tmp20_;
	GearyImapUID* _tmp21_;
	GearyImapDBFolderLocationIdentifier* _tmp22_;
	GearyImapDBFolderLocationIdentifier* _tmp23_;
	GearyImapDBFolderLocationIdentifier* _tmp24_ = NULL;
	gboolean _tmp25_ = FALSE;
	GearyImapDBFolderLocationIdentifier* _tmp28_;
	GError* _inner_error0_ = NULL;
	GearyImapDBFolderLocationIdentifier* result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_FOLDER (self), NULL);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), NULL);
	g_return_val_if_fail (GEARY_IMAP_DB_IS_EMAIL_IDENTIFIER (id), 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 ordering, remove_marker\n" \
"            FROM MessageLocationTable\n" \
"            WHERE folder_id = ? AND message_id = ?\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_rowid (_tmp1_, 0, self->priv->folder_id, &_inner_error0_);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp3_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp4_ = stmt;
	_tmp5_ = geary_imap_db_email_identifier_get_message_id (id);
	_tmp6_ = _tmp5_;
	_tmp7_ = geary_db_statement_bind_rowid (_tmp4_, 1, _tmp6_, &_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 NULL;
	}
	_tmp9_ = stmt;
	_tmp10_ = geary_db_statement_exec (_tmp9_, cancellable, &_inner_error0_);
	_result_ = _tmp10_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp11_ = _result_;
	_tmp12_ = geary_db_result_get_finished (_tmp11_);
	_tmp13_ = _tmp12_;
	if (_tmp13_) {
		result = NULL;
		_g_object_unref0 (_result_);
		_g_object_unref0 (stmt);
		return result;
	}
	_tmp15_ = _result_;
	_tmp14_ = geary_db_result_int64_at (_tmp15_, 0, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_result_);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp17_ = _result_;
	_tmp16_ = geary_db_result_bool_at (_tmp17_, 1, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_result_);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp18_ = geary_imap_db_email_identifier_get_message_id (id);
	_tmp19_ = _tmp18_;
	_tmp20_ = geary_imap_uid_new (_tmp14_);
	_tmp21_ = _tmp20_;
	_tmp22_ = geary_imap_db_folder_location_identifier_new (_tmp19_, _tmp21_, _tmp16_);
	_tmp23_ = _tmp22_;
	_g_object_unref0 (_tmp21_);
	location = _tmp23_;
	if (!geary_imap_db_folder_list_flags_include_marked_for_remove (flags)) {
		GearyImapDBFolderLocationIdentifier* _tmp26_;
		_tmp26_ = location;
		_tmp25_ = _tmp26_->marked_removed;
	} else {
		_tmp25_ = FALSE;
	}
	if (_tmp25_) {
		_tmp24_ = NULL;
	} else {
		GearyImapDBFolderLocationIdentifier* _tmp27_;
		_tmp27_ = location;
		_tmp24_ = _tmp27_;
	}
	_tmp28_ = _geary_imap_db_folder_location_identifier_ref0 (_tmp24_);
	result = _tmp28_;
	_geary_imap_db_folder_location_identifier_unref0 (location);
	_g_object_unref0 (_result_);
	_g_object_unref0 (stmt);
	return result;
}

static GeeList*
geary_imap_db_folder_do_get_locations_for_ids (GearyImapDBFolder* self,
                                               GearyDbConnection* cx,
                                               GeeCollection* ids,
                                               GearyImapDBFolderListFlags flags,
                                               GCancellable* cancellable,
                                               GError** error)
{
	gboolean _tmp0_ = FALSE;
	GString* sql = NULL;
	GString* _tmp3_;
	gboolean first = FALSE;
	GString* _tmp15_;
	GearyDbStatement* stmt = NULL;
	GString* _tmp16_;
	const gchar* _tmp17_;
	GearyDbStatement* _tmp18_;
	GearyDbStatement* _tmp19_;
	GearyDbStatement* _tmp20_;
	GearyDbStatement* _tmp21_;
	GearyDbResult* _tmp22_ = NULL;
	GearyDbStatement* _tmp23_;
	GearyDbResult* _tmp24_;
	GeeList* locs = NULL;
	GeeList* _tmp25_;
	GeeList* _tmp26_ = NULL;
	GeeList* _tmp27_;
	gint _tmp28_;
	gint _tmp29_;
	GeeList* _tmp31_;
	GError* _inner_error0_ = NULL;
	GeeList* result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_FOLDER (self), NULL);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), NULL);
	g_return_val_if_fail ((ids == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION), NULL);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), NULL);
	if (ids == NULL) {
		_tmp0_ = TRUE;
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = gee_collection_get_size (ids);
		_tmp2_ = _tmp1_;
		_tmp0_ = _tmp2_ == 0;
	}
	if (_tmp0_) {
		result = NULL;
		return result;
	}
	_tmp3_ = g_string_new ("\n" \
"            SELECT message_id, ordering, remove_marker\n" \
"            FROM MessageLocationTable\n" \
"            WHERE message_id IN (\n" \
"        ");
	sql = _tmp3_;
	first = TRUE;
	{
		GeeIterator* _id_it = NULL;
		GeeIterator* _tmp4_;
		_tmp4_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (ids, GEE_TYPE_ITERABLE, GeeIterable));
		_id_it = _tmp4_;
		while (TRUE) {
			GeeIterator* _tmp5_;
			GearyImapDBEmailIdentifier* id = NULL;
			GeeIterator* _tmp6_;
			gpointer _tmp7_;
			GString* _tmp9_;
			GearyImapDBEmailIdentifier* _tmp10_;
			gint64 _tmp11_;
			gint64 _tmp12_;
			gchar* _tmp13_;
			gchar* _tmp14_;
			_tmp5_ = _id_it;
			if (!gee_iterator_next (_tmp5_)) {
				break;
			}
			_tmp6_ = _id_it;
			_tmp7_ = gee_iterator_get (_tmp6_);
			id = (GearyImapDBEmailIdentifier*) _tmp7_;
			if (!first) {
				GString* _tmp8_;
				_tmp8_ = sql;
				g_string_append (_tmp8_, ",");
			}
			_tmp9_ = sql;
			_tmp10_ = id;
			_tmp11_ = geary_imap_db_email_identifier_get_message_id (_tmp10_);
			_tmp12_ = _tmp11_;
			_tmp13_ = g_strdup_printf ("%" G_GINT64_FORMAT, _tmp12_);
			_tmp14_ = _tmp13_;
			g_string_append_printf (_tmp9_, "%s", _tmp14_);
			_g_free0 (_tmp14_);
			first = FALSE;
			_g_object_unref0 (id);
		}
		_g_object_unref0 (_id_it);
	}
	_tmp15_ = sql;
	g_string_append (_tmp15_, ") AND folder_id = ?");
	_tmp16_ = sql;
	_tmp17_ = _tmp16_->str;
	_tmp18_ = geary_db_connection_prepare (cx, _tmp17_, &_inner_error0_);
	stmt = _tmp18_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_string_free0 (sql);
		return NULL;
	}
	_tmp19_ = stmt;
	_tmp20_ = geary_db_statement_bind_rowid (_tmp19_, 0, self->priv->folder_id, &_inner_error0_);
	_tmp21_ = _tmp20_;
	_g_object_unref0 (_tmp21_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return NULL;
	}
	_tmp23_ = stmt;
	_tmp24_ = geary_db_statement_exec (_tmp23_, cancellable, &_inner_error0_);
	_tmp22_ = _tmp24_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return NULL;
	}
	_tmp25_ = geary_imap_db_folder_do_results_to_locations (self, _tmp22_, G_MAXINT, flags, cancellable, &_inner_error0_);
	locs = _tmp25_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp22_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return NULL;
	}
	_tmp27_ = locs;
	_tmp28_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp27_, GEE_TYPE_COLLECTION, GeeCollection));
	_tmp29_ = _tmp28_;
	if (_tmp29_ > 0) {
		GeeList* _tmp30_;
		_tmp30_ = locs;
		_tmp26_ = _tmp30_;
	} else {
		_tmp26_ = NULL;
	}
	_tmp31_ = _g_object_ref0 (_tmp26_);
	result = _tmp31_;
	_g_object_unref0 (locs);
	_g_object_unref0 (_tmp22_);
	_g_object_unref0 (stmt);
	_g_string_free0 (sql);
	return result;
}

static GearyImapDBFolderLocationIdentifier*
geary_imap_db_folder_do_get_location_for_uid (GearyImapDBFolder* self,
                                              GearyDbConnection* cx,
                                              GearyImapUID* uid,
                                              GearyImapDBFolderListFlags flags,
                                              GCancellable* cancellable,
                                              GError** error)
{
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp1_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbStatement* _tmp4_;
	gint64 _tmp5_;
	gint64 _tmp6_;
	GearyDbStatement* _tmp7_;
	GearyDbStatement* _tmp8_;
	GearyDbResult* _result_ = NULL;
	GearyDbStatement* _tmp9_;
	GearyDbResult* _tmp10_;
	GearyDbResult* _tmp11_;
	gboolean _tmp12_;
	gboolean _tmp13_;
	gint64 _tmp14_ = 0LL;
	GearyDbResult* _tmp15_;
	gboolean _tmp16_ = FALSE;
	GearyDbResult* _tmp17_;
	GearyImapDBFolderLocationIdentifier* location = NULL;
	GearyImapDBFolderLocationIdentifier* _tmp18_;
	GearyImapDBFolderLocationIdentifier* _tmp19_ = NULL;
	gboolean _tmp20_ = FALSE;
	GearyImapDBFolderLocationIdentifier* _tmp23_;
	GError* _inner_error0_ = NULL;
	GearyImapDBFolderLocationIdentifier* result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_FOLDER (self), NULL);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), NULL);
	g_return_val_if_fail (GEARY_IMAP_IS_UID (uid), 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 message_id, remove_marker\n" \
"            FROM MessageLocationTable\n" \
"            WHERE folder_id = ? AND 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_rowid (_tmp1_, 0, self->priv->folder_id, &_inner_error0_);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp3_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp4_ = stmt;
	_tmp5_ = geary_message_data_int64_message_data_get_value (G_TYPE_CHECK_INSTANCE_CAST (uid, GEARY_MESSAGE_DATA_TYPE_INT64_MESSAGE_DATA, GearyMessageDataInt64MessageData));
	_tmp6_ = _tmp5_;
	_tmp7_ = geary_db_statement_bind_int64 (_tmp4_, 1, _tmp6_, &_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 NULL;
	}
	_tmp9_ = stmt;
	_tmp10_ = geary_db_statement_exec (_tmp9_, cancellable, &_inner_error0_);
	_result_ = _tmp10_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp11_ = _result_;
	_tmp12_ = geary_db_result_get_finished (_tmp11_);
	_tmp13_ = _tmp12_;
	if (_tmp13_) {
		result = NULL;
		_g_object_unref0 (_result_);
		_g_object_unref0 (stmt);
		return result;
	}
	_tmp15_ = _result_;
	_tmp14_ = geary_db_result_rowid_at (_tmp15_, 0, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_result_);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp17_ = _result_;
	_tmp16_ = geary_db_result_bool_at (_tmp17_, 1, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_result_);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp18_ = geary_imap_db_folder_location_identifier_new (_tmp14_, uid, _tmp16_);
	location = _tmp18_;
	if (!geary_imap_db_folder_list_flags_include_marked_for_remove (flags)) {
		GearyImapDBFolderLocationIdentifier* _tmp21_;
		_tmp21_ = location;
		_tmp20_ = _tmp21_->marked_removed;
	} else {
		_tmp20_ = FALSE;
	}
	if (_tmp20_) {
		_tmp19_ = NULL;
	} else {
		GearyImapDBFolderLocationIdentifier* _tmp22_;
		_tmp22_ = location;
		_tmp19_ = _tmp22_;
	}
	_tmp23_ = _geary_imap_db_folder_location_identifier_ref0 (_tmp19_);
	result = _tmp23_;
	_geary_imap_db_folder_location_identifier_unref0 (location);
	_g_object_unref0 (_result_);
	_g_object_unref0 (stmt);
	return result;
}

static GeeList*
geary_imap_db_folder_do_get_locations_for_uids (GearyImapDBFolder* self,
                                                GearyDbConnection* cx,
                                                GeeCollection* uids,
                                                GearyImapDBFolderListFlags flags,
                                                GCancellable* cancellable,
                                                GError** error)
{
	gboolean _tmp0_ = FALSE;
	GString* sql = NULL;
	GString* _tmp3_;
	gboolean first = FALSE;
	GString* _tmp15_;
	GearyDbStatement* stmt = NULL;
	GString* _tmp16_;
	const gchar* _tmp17_;
	GearyDbStatement* _tmp18_;
	GearyDbStatement* _tmp19_;
	GearyDbStatement* _tmp20_;
	GearyDbStatement* _tmp21_;
	GearyDbResult* _tmp22_ = NULL;
	GearyDbStatement* _tmp23_;
	GearyDbResult* _tmp24_;
	GeeList* locs = NULL;
	GeeList* _tmp25_;
	GeeList* _tmp26_ = NULL;
	GeeList* _tmp27_;
	gint _tmp28_;
	gint _tmp29_;
	GeeList* _tmp31_;
	GError* _inner_error0_ = NULL;
	GeeList* result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_FOLDER (self), NULL);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), NULL);
	g_return_val_if_fail ((uids == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (uids, GEE_TYPE_COLLECTION), NULL);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), NULL);
	if (uids == NULL) {
		_tmp0_ = TRUE;
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = gee_collection_get_size (uids);
		_tmp2_ = _tmp1_;
		_tmp0_ = _tmp2_ == 0;
	}
	if (_tmp0_) {
		result = NULL;
		return result;
	}
	_tmp3_ = g_string_new ("\n" \
"            SELECT message_id, ordering, remove_marker\n" \
"            FROM MessageLocationTable\n" \
"            WHERE ordering IN (\n" \
"        ");
	sql = _tmp3_;
	first = TRUE;
	{
		GeeIterator* _uid_it = NULL;
		GeeIterator* _tmp4_;
		_tmp4_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (uids, GEE_TYPE_ITERABLE, GeeIterable));
		_uid_it = _tmp4_;
		while (TRUE) {
			GeeIterator* _tmp5_;
			GearyImapUID* uid = NULL;
			GeeIterator* _tmp6_;
			gpointer _tmp7_;
			GString* _tmp9_;
			GearyImapUID* _tmp10_;
			gint64 _tmp11_;
			gint64 _tmp12_;
			gchar* _tmp13_;
			gchar* _tmp14_;
			_tmp5_ = _uid_it;
			if (!gee_iterator_next (_tmp5_)) {
				break;
			}
			_tmp6_ = _uid_it;
			_tmp7_ = gee_iterator_get (_tmp6_);
			uid = (GearyImapUID*) _tmp7_;
			if (!first) {
				GString* _tmp8_;
				_tmp8_ = sql;
				g_string_append (_tmp8_, ",");
			}
			_tmp9_ = sql;
			_tmp10_ = uid;
			_tmp11_ = geary_message_data_int64_message_data_get_value (G_TYPE_CHECK_INSTANCE_CAST (_tmp10_, GEARY_MESSAGE_DATA_TYPE_INT64_MESSAGE_DATA, GearyMessageDataInt64MessageData));
			_tmp12_ = _tmp11_;
			_tmp13_ = g_strdup_printf ("%" G_GINT64_FORMAT, _tmp12_);
			_tmp14_ = _tmp13_;
			g_string_append (_tmp9_, _tmp14_);
			_g_free0 (_tmp14_);
			first = FALSE;
			_g_object_unref0 (uid);
		}
		_g_object_unref0 (_uid_it);
	}
	_tmp15_ = sql;
	g_string_append (_tmp15_, ") AND folder_id = ?");
	_tmp16_ = sql;
	_tmp17_ = _tmp16_->str;
	_tmp18_ = geary_db_connection_prepare (cx, _tmp17_, &_inner_error0_);
	stmt = _tmp18_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_string_free0 (sql);
		return NULL;
	}
	_tmp19_ = stmt;
	_tmp20_ = geary_db_statement_bind_rowid (_tmp19_, 0, self->priv->folder_id, &_inner_error0_);
	_tmp21_ = _tmp20_;
	_g_object_unref0 (_tmp21_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return NULL;
	}
	_tmp23_ = stmt;
	_tmp24_ = geary_db_statement_exec (_tmp23_, cancellable, &_inner_error0_);
	_tmp22_ = _tmp24_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return NULL;
	}
	_tmp25_ = geary_imap_db_folder_do_results_to_locations (self, _tmp22_, G_MAXINT, flags, cancellable, &_inner_error0_);
	locs = _tmp25_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp22_);
		_g_object_unref0 (stmt);
		_g_string_free0 (sql);
		return NULL;
	}
	_tmp27_ = locs;
	_tmp28_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp27_, GEE_TYPE_COLLECTION, GeeCollection));
	_tmp29_ = _tmp28_;
	if (_tmp29_ > 0) {
		GeeList* _tmp30_;
		_tmp30_ = locs;
		_tmp26_ = _tmp30_;
	} else {
		_tmp26_ = NULL;
	}
	_tmp31_ = _g_object_ref0 (_tmp26_);
	result = _tmp31_;
	_g_object_unref0 (locs);
	_g_object_unref0 (_tmp22_);
	_g_object_unref0 (stmt);
	_g_string_free0 (sql);
	return result;
}

static GeeList*
geary_imap_db_folder_do_get_all_locations (GearyImapDBFolder* self,
                                           GearyDbConnection* cx,
                                           GearyImapDBFolderListFlags flags,
                                           GCancellable* cancellable,
                                           GError** error)
{
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp1_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbResult* _tmp4_ = NULL;
	GearyDbStatement* _tmp5_;
	GearyDbResult* _tmp6_;
	GeeList* locs = NULL;
	GeeList* _tmp7_;
	GeeList* _tmp8_ = NULL;
	GeeList* _tmp9_;
	gint _tmp10_;
	gint _tmp11_;
	GeeList* _tmp13_;
	GError* _inner_error0_ = NULL;
	GeeList* result;
	g_return_val_if_fail (GEARY_IMAP_DB_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 message_id, ordering, remove_marker\n" \
"            FROM MessageLocationTable\n" \
"            WHERE folder_id = ?\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_rowid (_tmp1_, 0, self->priv->folder_id, &_inner_error0_);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp3_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp5_ = stmt;
	_tmp6_ = geary_db_statement_exec (_tmp5_, cancellable, &_inner_error0_);
	_tmp4_ = _tmp6_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp7_ = geary_imap_db_folder_do_results_to_locations (self, _tmp4_, G_MAXINT, flags, cancellable, &_inner_error0_);
	locs = _tmp7_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp4_);
		_g_object_unref0 (stmt);
		return NULL;
	}
	_tmp9_ = locs;
	_tmp10_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp9_, GEE_TYPE_COLLECTION, GeeCollection));
	_tmp11_ = _tmp10_;
	if (_tmp11_ > 0) {
		GeeList* _tmp12_;
		_tmp12_ = locs;
		_tmp8_ = _tmp12_;
	} else {
		_tmp8_ = NULL;
	}
	_tmp13_ = _g_object_ref0 (_tmp8_);
	result = _tmp13_;
	_g_object_unref0 (locs);
	_g_object_unref0 (_tmp4_);
	_g_object_unref0 (stmt);
	return result;
}

static gboolean
___lambda72_ (GearyImapDBFolder* self,
              GearyEmailFlags* f)
{
	gboolean result;
	g_return_val_if_fail (GEARY_IS_EMAIL_FLAGS (f), FALSE);
	result = geary_email_flags_is_unread (f);
	return result;
}

static gboolean
____lambda72__gee_predicate (gconstpointer g,
                             gpointer self)
{
	gboolean result;
	result = ___lambda72_ ((GearyImapDBFolder*) self, (GearyEmailFlags*) g);
	return result;
}

static gint
geary_imap_db_folder_do_get_unread_count_for_ids (GearyImapDBFolder* self,
                                                  GearyDbConnection* cx,
                                                  GeeCollection* ids,
                                                  GCancellable* cancellable,
                                                  GError** error)
{
	gboolean _tmp0_ = FALSE;
	GeeMap* flag_map = NULL;
	GeeMap* _tmp3_;
	GeeMap* _tmp5_;
	GError* _inner_error0_ = NULL;
	gint result;
	g_return_val_if_fail (GEARY_IMAP_DB_IS_FOLDER (self), 0);
	g_return_val_if_fail (GEARY_DB_IS_CONNECTION (cx), 0);
	g_return_val_if_fail ((ids == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION), 0);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), 0);
	if (ids == NULL) {
		_tmp0_ = TRUE;
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = gee_collection_get_size (ids);
		_tmp2_ = _tmp1_;
		_tmp0_ = _tmp2_ == 0;
	}
	if (_tmp0_) {
		result = 0;
		return result;
	}
	_tmp3_ = geary_imap_db_folder_do_get_email_flags (self, cx, ids, cancellable, &_inner_error0_);
	flag_map = _tmp3_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp4_ = -1;
		g_propagate_error (error, _inner_error0_);
		return _tmp4_;
	}
	_tmp5_ = flag_map;
	if (_tmp5_ != NULL) {
		GeeMap* _tmp6_;
		GeeCollection* _tmp7_;
		GeeCollection* _tmp8_;
		GeeCollection* _tmp9_;
		GearyIterable* _tmp10_;
		GearyIterable* _tmp11_;
		gint _tmp12_;
		_tmp6_ = flag_map;
		_tmp7_ = gee_map_get_values (_tmp6_);
		_tmp8_ = _tmp7_;
		_tmp9_ = _tmp8_;
		_tmp10_ = geary_traverse (GEARY_TYPE_EMAIL_FLAGS, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, G_TYPE_CHECK_INSTANCE_CAST (_tmp9_, GEE_TYPE_ITERABLE, GeeIterable));
		_tmp11_ = _tmp10_;
		_tmp12_ = geary_iterable_count_matching (_tmp11_, ____lambda72__gee_predicate, g_object_ref (self), g_object_unref);
		_g_object_unref0 (_tmp11_);
		_g_object_unref0 (_tmp9_);
		result = _tmp12_;
		_g_object_unref0 (flag_map);
		return result;
	}
	result = 0;
	_g_object_unref0 (flag_map);
	return result;
}

static void
geary_imap_db_folder_do_update_last_seen_select_examine_total (GearyImapDBFolder* self,
                                                               GearyDbConnection* cx,
                                                               gint total,
                                                               GCancellable* cancellable,
                                                               GError** error)
{
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp1_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbStatement* _tmp5_;
	GearyDbStatement* _tmp6_;
	GearyDbStatement* _tmp7_;
	GearyDbResult* _tmp8_;
	GearyDbResult* _tmp9_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_DB_IS_CONNECTION (cx));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_tmp0_ = geary_db_connection_prepare (cx, "UPDATE FolderTable SET last_seen_total=? WHERE id=?", &_inner_error0_);
	stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	_tmp1_ = stmt;
	_tmp2_ = geary_db_statement_bind_int (_tmp1_, 0, geary_numeric_int_floor (total, 0), &_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;
	}
	_tmp4_ = stmt;
	_tmp5_ = geary_db_statement_bind_rowid (_tmp4_, 1, self->priv->folder_id, &_inner_error0_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp6_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	_tmp7_ = stmt;
	_tmp8_ = geary_db_statement_exec (_tmp7_, cancellable, &_inner_error0_);
	_tmp9_ = _tmp8_;
	_g_object_unref0 (_tmp9_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	_g_object_unref0 (stmt);
}

static void
geary_imap_db_folder_do_update_last_seen_status_total (GearyImapDBFolder* self,
                                                       GearyDbConnection* cx,
                                                       gint total,
                                                       GCancellable* cancellable,
                                                       GError** error)
{
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp0_;
	GearyDbStatement* _tmp1_;
	GearyDbStatement* _tmp2_;
	GearyDbStatement* _tmp3_;
	GearyDbStatement* _tmp4_;
	GearyDbStatement* _tmp5_;
	GearyDbStatement* _tmp6_;
	GearyDbStatement* _tmp7_;
	GearyDbResult* _tmp8_;
	GearyDbResult* _tmp9_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_DB_IS_CONNECTION (cx));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_tmp0_ = geary_db_connection_prepare (cx, "UPDATE FolderTable SET last_seen_status_total=? WHERE id=?", &_inner_error0_);
	stmt = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	_tmp1_ = stmt;
	_tmp2_ = geary_db_statement_bind_int (_tmp1_, 0, geary_numeric_int_floor (total, 0), &_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;
	}
	_tmp4_ = stmt;
	_tmp5_ = geary_db_statement_bind_rowid (_tmp4_, 1, self->priv->folder_id, &_inner_error0_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp6_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	_tmp7_ = stmt;
	_tmp8_ = geary_db_statement_exec (_tmp7_, cancellable, &_inner_error0_);
	_tmp9_ = _tmp8_;
	_g_object_unref0 (_tmp9_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	_g_object_unref0 (stmt);
}

static void
geary_imap_db_folder_do_update_uid_info (GearyImapDBFolder* self,
                                         GearyDbConnection* cx,
                                         GearyImapFolderProperties* remote_properties,
                                         GCancellable* cancellable,
                                         GError** error)
{
	gint64 _tmp0_ = 0LL;
	GearyImapUIDValidity* _tmp1_;
	GearyImapUIDValidity* _tmp2_;
	gint64 uid_validity = 0LL;
	gint64 _tmp7_ = 0LL;
	GearyImapUID* _tmp8_;
	GearyImapUID* _tmp9_;
	gint64 uid_next = 0LL;
	GearyDbStatement* stmt = NULL;
	GearyDbStatement* _tmp14_;
	GearyDbStatement* _tmp15_;
	GearyDbStatement* _tmp16_;
	GearyDbStatement* _tmp17_;
	GearyDbStatement* _tmp18_;
	GearyDbStatement* _tmp19_;
	GearyDbStatement* _tmp20_;
	GearyDbStatement* _tmp21_;
	GearyDbStatement* _tmp22_;
	GearyDbStatement* _tmp23_;
	GearyDbStatement* _tmp24_;
	GearyDbResult* _tmp25_;
	GearyDbResult* _tmp26_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_DB_IS_FOLDER (self));
	g_return_if_fail (GEARY_DB_IS_CONNECTION (cx));
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_PROPERTIES (remote_properties));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_tmp1_ = geary_imap_folder_properties_get_uid_validity (remote_properties);
	_tmp2_ = _tmp1_;
	if (_tmp2_ != NULL) {
		GearyImapUIDValidity* _tmp3_;
		GearyImapUIDValidity* _tmp4_;
		gint64 _tmp5_;
		gint64 _tmp6_;
		_tmp3_ = geary_imap_folder_properties_get_uid_validity (remote_properties);
		_tmp4_ = _tmp3_;
		_tmp5_ = geary_message_data_int64_message_data_get_value (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, GEARY_MESSAGE_DATA_TYPE_INT64_MESSAGE_DATA, GearyMessageDataInt64MessageData));
		_tmp6_ = _tmp5_;
		_tmp0_ = _tmp6_;
	} else {
		_tmp0_ = GEARY_IMAP_UID_VALIDITY_INVALID;
	}
	uid_validity = _tmp0_;
	_tmp8_ = geary_imap_folder_properties_get_uid_next (remote_properties);
	_tmp9_ = _tmp8_;
	if (_tmp9_ != NULL) {
		GearyImapUID* _tmp10_;
		GearyImapUID* _tmp11_;
		gint64 _tmp12_;
		gint64 _tmp13_;
		_tmp10_ = geary_imap_folder_properties_get_uid_next (remote_properties);
		_tmp11_ = _tmp10_;
		_tmp12_ = geary_message_data_int64_message_data_get_value (G_TYPE_CHECK_INSTANCE_CAST (_tmp11_, GEARY_MESSAGE_DATA_TYPE_INT64_MESSAGE_DATA, GearyMessageDataInt64MessageData));
		_tmp13_ = _tmp12_;
		_tmp7_ = _tmp13_;
	} else {
		_tmp7_ = GEARY_IMAP_UID_INVALID;
	}
	uid_next = _tmp7_;
	_tmp14_ = geary_db_connection_prepare (cx, "UPDATE FolderTable SET uid_validity=?, uid_next=? WHERE id=?", &_inner_error0_);
	stmt = _tmp14_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	_tmp15_ = stmt;
	_tmp16_ = geary_db_statement_bind_int64 (_tmp15_, 0, uid_validity, &_inner_error0_);
	_tmp17_ = _tmp16_;
	_g_object_unref0 (_tmp17_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	_tmp18_ = stmt;
	_tmp19_ = geary_db_statement_bind_int64 (_tmp18_, 1, uid_next, &_inner_error0_);
	_tmp20_ = _tmp19_;
	_g_object_unref0 (_tmp20_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	_tmp21_ = stmt;
	_tmp22_ = geary_db_statement_bind_rowid (_tmp21_, 2, self->priv->folder_id, &_inner_error0_);
	_tmp23_ = _tmp22_;
	_g_object_unref0 (_tmp23_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	_tmp24_ = stmt;
	_tmp25_ = geary_db_statement_exec (_tmp24_, cancellable, &_inner_error0_);
	_tmp26_ = _tmp25_;
	_g_object_unref0 (_tmp26_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stmt);
		return;
	}
	_g_object_unref0 (stmt);
}

static GearyImapDBFolderLocationIdentifier*
geary_imap_db_folder_location_identifier_construct (GType object_type,
                                                    gint64 message_id,
                                                    GearyImapUID* uid,
                                                    gboolean marked_removed)
{
	GearyImapDBFolderLocationIdentifier* self = NULL;
	GearyImapUID* _tmp0_;
	GearyImapDBEmailIdentifier* _tmp1_;
	g_return_val_if_fail (GEARY_IMAP_IS_UID (uid), NULL);
	self = (GearyImapDBFolderLocationIdentifier*) g_type_create_instance (object_type);
	self->message_id = message_id;
	_tmp0_ = _g_object_ref0 (uid);
	_g_object_unref0 (self->uid);
	self->uid = _tmp0_;
	_tmp1_ = geary_imap_db_email_identifier_new (message_id, uid);
	_g_object_unref0 (self->email_id);
	self->email_id = _tmp1_;
	self->marked_removed = marked_removed;
	return self;
}

static GearyImapDBFolderLocationIdentifier*
geary_imap_db_folder_location_identifier_new (gint64 message_id,
                                              GearyImapUID* uid,
                                              gboolean marked_removed)
{
	return geary_imap_db_folder_location_identifier_construct (GEARY_IMAP_DB_FOLDER_TYPE_LOCATION_IDENTIFIER, message_id, uid, marked_removed);
}

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

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

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

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

static gchar*
geary_imap_db_folder_value_location_identifier_collect_value (GValue* value,
                                                              guint n_collect_values,
                                                              GTypeCValue* collect_values,
                                                              guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		GearyImapDBFolderLocationIdentifier * 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_imap_db_folder_location_identifier_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
geary_imap_db_folder_value_location_identifier_lcopy_value (const GValue* value,
                                                            guint n_collect_values,
                                                            GTypeCValue* collect_values,
                                                            guint collect_flags)
{
	GearyImapDBFolderLocationIdentifier ** 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_imap_db_folder_location_identifier_ref (value->data[0].v_pointer);
	}
	return NULL;
}

static GParamSpec*
geary_imap_db_folder_param_spec_location_identifier (const gchar* name,
                                                     const gchar* nick,
                                                     const gchar* blurb,
                                                     GType object_type,
                                                     GParamFlags flags)
{
	GearyImapDBFolderParamSpecLocationIdentifier* spec;
	g_return_val_if_fail (g_type_is_a (object_type, GEARY_IMAP_DB_FOLDER_TYPE_LOCATION_IDENTIFIER), 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_imap_db_folder_value_get_location_identifier (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GEARY_IMAP_DB_FOLDER_TYPE_LOCATION_IDENTIFIER), NULL);
	return value->data[0].v_pointer;
}

static void
geary_imap_db_folder_value_set_location_identifier (GValue* value,
                                                    gpointer v_object)
{
	GearyImapDBFolderLocationIdentifier * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GEARY_IMAP_DB_FOLDER_TYPE_LOCATION_IDENTIFIER));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GEARY_IMAP_DB_FOLDER_TYPE_LOCATION_IDENTIFIER));
		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_imap_db_folder_location_identifier_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		geary_imap_db_folder_location_identifier_unref (old);
	}
}

static void
geary_imap_db_folder_value_take_location_identifier (GValue* value,
                                                     gpointer v_object)
{
	GearyImapDBFolderLocationIdentifier * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GEARY_IMAP_DB_FOLDER_TYPE_LOCATION_IDENTIFIER));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GEARY_IMAP_DB_FOLDER_TYPE_LOCATION_IDENTIFIER));
		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_imap_db_folder_location_identifier_unref (old);
	}
}

static void
geary_imap_db_folder_location_identifier_class_init (GearyImapDBFolderLocationIdentifierClass * klass,
                                                     gpointer klass_data)
{
	geary_imap_db_folder_location_identifier_parent_class = g_type_class_peek_parent (klass);
	((GearyImapDBFolderLocationIdentifierClass *) klass)->finalize = geary_imap_db_folder_location_identifier_finalize;
}

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

static void
geary_imap_db_folder_location_identifier_finalize (GearyImapDBFolderLocationIdentifier * obj)
{
	GearyImapDBFolderLocationIdentifier * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_IMAP_DB_FOLDER_TYPE_LOCATION_IDENTIFIER, GearyImapDBFolderLocationIdentifier);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->uid);
	_g_object_unref0 (self->email_id);
}

 G_GNUC_NO_INLINE static GType
geary_imap_db_folder_location_identifier_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { geary_imap_db_folder_value_location_identifier_init, geary_imap_db_folder_value_location_identifier_free_value, geary_imap_db_folder_value_location_identifier_copy_value, geary_imap_db_folder_value_location_identifier_peek_pointer, "p", geary_imap_db_folder_value_location_identifier_collect_value, "p", geary_imap_db_folder_value_location_identifier_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapDBFolderLocationIdentifierClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_db_folder_location_identifier_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapDBFolderLocationIdentifier), 0, (GInstanceInitFunc) geary_imap_db_folder_location_identifier_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_imap_db_folder_location_identifier_type_id;
	geary_imap_db_folder_location_identifier_type_id = g_type_register_fundamental (g_type_fundamental_next (), "GearyImapDBFolderLocationIdentifier", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return geary_imap_db_folder_location_identifier_type_id;
}

static GType
geary_imap_db_folder_location_identifier_get_type (void)
{
	static gsize geary_imap_db_folder_location_identifier_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_db_folder_location_identifier_type_id__once)) {
		GType geary_imap_db_folder_location_identifier_type_id;
		geary_imap_db_folder_location_identifier_type_id = geary_imap_db_folder_location_identifier_get_type_once ();
		g_once_init_leave (&geary_imap_db_folder_location_identifier_type_id__once, geary_imap_db_folder_location_identifier_type_id);
	}
	return geary_imap_db_folder_location_identifier_type_id__once;
}

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

static void
geary_imap_db_folder_location_identifier_unref (gpointer instance)
{
	GearyImapDBFolderLocationIdentifier * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		GEARY_IMAP_DB_FOLDER_LOCATION_IDENTIFIER_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static void
geary_imap_db_folder_class_init (GearyImapDBFolderClass * klass,
                                 gpointer klass_data)
{
	geary_imap_db_folder_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GearyImapDBFolder_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_geary_imap_db_folder_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_geary_imap_db_folder_set_property;
	G_OBJECT_CLASS (klass)->finalize = geary_imap_db_folder_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_DB_FOLDER_MANUAL_REF_COUNT_PROPERTY, geary_imap_db_folder_properties[GEARY_IMAP_DB_FOLDER_MANUAL_REF_COUNT_PROPERTY] = g_param_spec_int ("manual-ref-count", "manual-ref-count", "manual-ref-count", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	/**
	     * Fired after one or more emails have been fetched with all Fields, and
	     * saved locally.
	     */
	geary_imap_db_folder_signals[GEARY_IMAP_DB_FOLDER_EMAIL_COMPLETE_SIGNAL] = g_signal_new ("email-complete", GEARY_IMAP_DB_TYPE_FOLDER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GEE_TYPE_COLLECTION);
	/**
	     * Fired when an email's unread (aka seen) status has changed.  This allows the account to
	     * change the unread count for other folders that contain the email.
	     */
	geary_imap_db_folder_signals[GEARY_IMAP_DB_FOLDER_UNREAD_UPDATED_SIGNAL] = g_signal_new ("unread-updated", GEARY_IMAP_DB_TYPE_FOLDER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GEE_TYPE_MAP);
}

static void
geary_imap_db_folder_geary_reference_semantics_interface_init (GearyReferenceSemanticsIface * iface,
                                                               gpointer iface_data)
{
	geary_imap_db_folder_geary_reference_semantics_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_manual_ref_count = geary_imap_db_folder_real_get_manual_ref_count;
	iface->set_manual_ref_count = geary_imap_db_folder_real_set_manual_ref_count;
}

static void
geary_imap_db_folder_instance_init (GearyImapDBFolder * self,
                                    gpointer klass)
{
	self->priv = geary_imap_db_folder_get_instance_private (self);
}

static void
geary_imap_db_folder_finalize (GObject * obj)
{
	GearyImapDBFolder * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_IMAP_DB_TYPE_FOLDER, GearyImapDBFolder);
	_g_object_unref0 (self->priv->db);
	_g_object_unref0 (self->priv->path);
	_g_object_unref0 (self->priv->attachments_path);
	_g_free0 (self->priv->account_owner_email);
	_g_object_unref0 (self->priv->properties);
	G_OBJECT_CLASS (geary_imap_db_folder_parent_class)->finalize (obj);
}

/**
 * ImapDB.Folder provides an interface for retrieving messages from the local store in methods
 * that are synonymous with Geary.Folder's interface, but with some differences that deal with
 * how IMAP addresses and organizes email.
 *
 * One important note about ImapDB.Folder: if an EmailIdentifier is returned (either by itself
 * or attached to a Geary.Email), it will always be an ImapDB.EmailIdentifier and it will always
 * have a valid Imap.UID present.  This is not the case for EmailIdentifiers returned from
 * ImapDB.Account, as those EmailIdentifiers aren't associated with a Folder, which UIDs require.
 */
 G_GNUC_NO_INLINE static GType
geary_imap_db_folder_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapDBFolderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_db_folder_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapDBFolder), 0, (GInstanceInitFunc) geary_imap_db_folder_instance_init, NULL };
	static const GInterfaceInfo geary_reference_semantics_info = { (GInterfaceInitFunc) geary_imap_db_folder_geary_reference_semantics_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType geary_imap_db_folder_type_id;
	geary_imap_db_folder_type_id = g_type_register_static (GEARY_TYPE_BASE_OBJECT, "GearyImapDBFolder", &g_define_type_info, 0);
	g_type_add_interface_static (geary_imap_db_folder_type_id, GEARY_TYPE_REFERENCE_SEMANTICS, &geary_reference_semantics_info);
	GearyImapDBFolder_private_offset = g_type_add_instance_private (geary_imap_db_folder_type_id, sizeof (GearyImapDBFolderPrivate));
	return geary_imap_db_folder_type_id;
}

GType
geary_imap_db_folder_get_type (void)
{
	static gsize geary_imap_db_folder_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_db_folder_type_id__once)) {
		GType geary_imap_db_folder_type_id;
		geary_imap_db_folder_type_id = geary_imap_db_folder_get_type_once ();
		g_once_init_leave (&geary_imap_db_folder_type_id__once, geary_imap_db_folder_type_id);
	}
	return geary_imap_db_folder_type_id__once;
}

static void
_vala_geary_imap_db_folder_get_property (GObject * object,
                                         guint property_id,
                                         GValue * value,
                                         GParamSpec * pspec)
{
	GearyImapDBFolder * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_DB_TYPE_FOLDER, GearyImapDBFolder);
	switch (property_id) {
		case GEARY_IMAP_DB_FOLDER_MANUAL_REF_COUNT_PROPERTY:
		g_value_set_int (value, geary_reference_semantics_get_manual_ref_count (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_TYPE_REFERENCE_SEMANTICS, GearyReferenceSemantics)));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_geary_imap_db_folder_set_property (GObject * object,
                                         guint property_id,
                                         const GValue * value,
                                         GParamSpec * pspec)
{
	GearyImapDBFolder * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_DB_TYPE_FOLDER, GearyImapDBFolder);
	switch (property_id) {
		case GEARY_IMAP_DB_FOLDER_MANUAL_REF_COUNT_PROPERTY:
		geary_reference_semantics_set_manual_ref_count (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_TYPE_REFERENCE_SEMANTICS, GearyReferenceSemantics), g_value_get_int (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

