/* imap-engine-server-search-email.c generated by valac 0.56.3, the Vala compiler
 * generated from imap-engine-server-search-email.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 <gee.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>

#define GEARY_IMAP_DB_FOLDER_REQUIRED_FIELDS ((GEARY_EMAIL_FIELD_PROPERTIES | GEARY_EMAIL_FIELD_REFERENCES) | GEARY_EMAIL_FIELD_FLAGS)

#define GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION (geary_imap_engine_replay_operation_get_type ())
#define GEARY_IMAP_ENGINE_REPLAY_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, GearyImapEngineReplayOperation))
#define GEARY_IMAP_ENGINE_REPLAY_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, GearyImapEngineReplayOperationClass))
#define GEARY_IMAP_ENGINE_IS_REPLAY_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION))
#define GEARY_IMAP_ENGINE_IS_REPLAY_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION))
#define GEARY_IMAP_ENGINE_REPLAY_OPERATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, GearyImapEngineReplayOperationClass))

typedef struct _GearyImapEngineReplayOperation GearyImapEngineReplayOperation;
typedef struct _GearyImapEngineReplayOperationClass GearyImapEngineReplayOperationClass;
typedef struct _GearyImapEngineReplayOperationPrivate GearyImapEngineReplayOperationPrivate;

#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 enum  {
	GEARY_IMAP_ENGINE_REPLAY_OPERATION_STATUS_COMPLETED,
	GEARY_IMAP_ENGINE_REPLAY_OPERATION_STATUS_CONTINUE
} GearyImapEngineReplayOperationStatus;

#define GEARY_IMAP_ENGINE_REPLAY_OPERATION_TYPE_STATUS (geary_imap_engine_replay_operation_status_get_type ())

#define GEARY_IMAP_TYPE_FOLDER_SESSION (geary_imap_folder_session_get_type ())
#define GEARY_IMAP_FOLDER_SESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_TYPE_FOLDER_SESSION, GearyImapFolderSession))
#define GEARY_IMAP_FOLDER_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_TYPE_FOLDER_SESSION, GearyImapFolderSessionClass))
#define GEARY_IMAP_IS_FOLDER_SESSION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_TYPE_FOLDER_SESSION))
#define GEARY_IMAP_IS_FOLDER_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_TYPE_FOLDER_SESSION))
#define GEARY_IMAP_FOLDER_SESSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_TYPE_FOLDER_SESSION, GearyImapFolderSessionClass))

typedef struct _GearyImapFolderSession GearyImapFolderSession;
typedef struct _GearyImapFolderSessionClass GearyImapFolderSessionClass;

#define GEARY_IMAP_ENGINE_TYPE_SEND_REPLAY_OPERATION (geary_imap_engine_send_replay_operation_get_type ())
#define GEARY_IMAP_ENGINE_SEND_REPLAY_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_ENGINE_TYPE_SEND_REPLAY_OPERATION, GearyImapEngineSendReplayOperation))
#define GEARY_IMAP_ENGINE_SEND_REPLAY_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_ENGINE_TYPE_SEND_REPLAY_OPERATION, GearyImapEngineSendReplayOperationClass))
#define GEARY_IMAP_ENGINE_IS_SEND_REPLAY_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_ENGINE_TYPE_SEND_REPLAY_OPERATION))
#define GEARY_IMAP_ENGINE_IS_SEND_REPLAY_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_ENGINE_TYPE_SEND_REPLAY_OPERATION))
#define GEARY_IMAP_ENGINE_SEND_REPLAY_OPERATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_ENGINE_TYPE_SEND_REPLAY_OPERATION, GearyImapEngineSendReplayOperationClass))

typedef struct _GearyImapEngineSendReplayOperation GearyImapEngineSendReplayOperation;
typedef struct _GearyImapEngineSendReplayOperationClass GearyImapEngineSendReplayOperationClass;
typedef struct _GearyImapEngineSendReplayOperationPrivate GearyImapEngineSendReplayOperationPrivate;

#define GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL (geary_imap_engine_abstract_list_email_get_type ())
#define GEARY_IMAP_ENGINE_ABSTRACT_LIST_EMAIL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmail))
#define GEARY_IMAP_ENGINE_ABSTRACT_LIST_EMAIL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmailClass))
#define GEARY_IMAP_ENGINE_IS_ABSTRACT_LIST_EMAIL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL))
#define GEARY_IMAP_ENGINE_IS_ABSTRACT_LIST_EMAIL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL))
#define GEARY_IMAP_ENGINE_ABSTRACT_LIST_EMAIL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmailClass))

typedef struct _GearyImapEngineAbstractListEmail GearyImapEngineAbstractListEmail;
typedef struct _GearyImapEngineAbstractListEmailClass GearyImapEngineAbstractListEmailClass;
typedef struct _GearyImapEngineAbstractListEmailPrivate GearyImapEngineAbstractListEmailPrivate;

#define GEARY_IMAP_ENGINE_TYPE_MINIMAL_FOLDER (geary_imap_engine_minimal_folder_get_type ())
#define GEARY_IMAP_ENGINE_MINIMAL_FOLDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_ENGINE_TYPE_MINIMAL_FOLDER, GearyImapEngineMinimalFolder))
#define GEARY_IMAP_ENGINE_MINIMAL_FOLDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_ENGINE_TYPE_MINIMAL_FOLDER, GearyImapEngineMinimalFolderClass))
#define GEARY_IMAP_ENGINE_IS_MINIMAL_FOLDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_ENGINE_TYPE_MINIMAL_FOLDER))
#define GEARY_IMAP_ENGINE_IS_MINIMAL_FOLDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_ENGINE_TYPE_MINIMAL_FOLDER))
#define GEARY_IMAP_ENGINE_MINIMAL_FOLDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_ENGINE_TYPE_MINIMAL_FOLDER, GearyImapEngineMinimalFolderClass))

typedef struct _GearyImapEngineMinimalFolder GearyImapEngineMinimalFolder;
typedef struct _GearyImapEngineMinimalFolderClass GearyImapEngineMinimalFolderClass;

#define GEARY_IMAP_ENGINE_TYPE_SERVER_SEARCH_EMAIL (geary_imap_engine_server_search_email_get_type ())
#define GEARY_IMAP_ENGINE_SERVER_SEARCH_EMAIL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_ENGINE_TYPE_SERVER_SEARCH_EMAIL, GearyImapEngineServerSearchEmail))
#define GEARY_IMAP_ENGINE_SERVER_SEARCH_EMAIL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_ENGINE_TYPE_SERVER_SEARCH_EMAIL, GearyImapEngineServerSearchEmailClass))
#define GEARY_IMAP_ENGINE_IS_SERVER_SEARCH_EMAIL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_ENGINE_TYPE_SERVER_SEARCH_EMAIL))
#define GEARY_IMAP_ENGINE_IS_SERVER_SEARCH_EMAIL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_ENGINE_TYPE_SERVER_SEARCH_EMAIL))
#define GEARY_IMAP_ENGINE_SERVER_SEARCH_EMAIL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_ENGINE_TYPE_SERVER_SEARCH_EMAIL, GearyImapEngineServerSearchEmailClass))

typedef struct _GearyImapEngineServerSearchEmail GearyImapEngineServerSearchEmail;
typedef struct _GearyImapEngineServerSearchEmailClass GearyImapEngineServerSearchEmailClass;
typedef struct _GearyImapEngineServerSearchEmailPrivate GearyImapEngineServerSearchEmailPrivate;
enum  {
	GEARY_IMAP_ENGINE_SERVER_SEARCH_EMAIL_0_PROPERTY,
	GEARY_IMAP_ENGINE_SERVER_SEARCH_EMAIL_NUM_PROPERTIES
};
static GParamSpec* geary_imap_engine_server_search_email_properties[GEARY_IMAP_ENGINE_SERVER_SEARCH_EMAIL_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef enum  {
	GEARY_IMAP_ENGINE_REPLAY_OPERATION_ON_ERROR_THROW,
	GEARY_IMAP_ENGINE_REPLAY_OPERATION_ON_ERROR_RETRY,
	GEARY_IMAP_ENGINE_REPLAY_OPERATION_ON_ERROR_IGNORE_REMOTE
} GearyImapEngineReplayOperationOnError;

#define GEARY_IMAP_ENGINE_REPLAY_OPERATION_TYPE_ON_ERROR (geary_imap_engine_replay_operation_on_error_get_type ())
typedef struct _GearyImapEngineServerSearchEmailReplayLocalAsyncData GearyImapEngineServerSearchEmailReplayLocalAsyncData;

#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 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 ())
typedef struct _GearyImapEngineServerSearchEmailReplayRemoteAsyncData GearyImapEngineServerSearchEmailReplayRemoteAsyncData;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _GearyImapEngineReplayOperation {
	GearyBaseObject parent_instance;
	GearyImapEngineReplayOperationPrivate * priv;
};

struct _GearyImapEngineReplayOperationClass {
	GearyBaseObjectClass parent_class;
	void (*notify_remote_removed_position) (GearyImapEngineReplayOperation* self, GearyImapSequenceNumber* removed);
	void (*notify_remote_removed_ids) (GearyImapEngineReplayOperation* self, GeeCollection* ids);
	void (*get_ids_to_be_remote_removed) (GearyImapEngineReplayOperation* self, GeeCollection* ids);
	void (*replay_local_async) (GearyImapEngineReplayOperation* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
	GearyImapEngineReplayOperationStatus (*replay_local_finish) (GearyImapEngineReplayOperation* self, GAsyncResult* _res_, GError** error);
	void (*replay_remote_async) (GearyImapEngineReplayOperation* self, GearyImapFolderSession* remote, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*replay_remote_finish) (GearyImapEngineReplayOperation* self, GAsyncResult* _res_, GError** error);
	void (*backout_local_async) (GearyImapEngineReplayOperation* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*backout_local_finish) (GearyImapEngineReplayOperation* self, GAsyncResult* _res_, GError** error);
	gchar* (*describe_state) (GearyImapEngineReplayOperation* self);
};

struct _GearyImapEngineSendReplayOperation {
	GearyImapEngineReplayOperation parent_instance;
	GearyImapEngineSendReplayOperationPrivate * priv;
};

struct _GearyImapEngineSendReplayOperationClass {
	GearyImapEngineReplayOperationClass parent_class;
};

struct _GearyImapEngineAbstractListEmail {
	GearyImapEngineSendReplayOperation parent_instance;
	GeeList* accumulator;
	GearyImapEngineMinimalFolder* owner;
	GearyEmailField required_fields;
	GCancellable* cancellable;
	GearyFolderListFlags flags;
	GearyImapEngineAbstractListEmailPrivate * priv;
};

struct _GearyImapEngineAbstractListEmailClass {
	GearyImapEngineSendReplayOperationClass parent_class;
};

struct _GearyImapEngineServerSearchEmail {
	GearyImapEngineAbstractListEmail parent_instance;
	GearyImapEngineServerSearchEmailPrivate * priv;
};

struct _GearyImapEngineServerSearchEmailClass {
	GearyImapEngineAbstractListEmailClass parent_class;
};

struct _GearyImapEngineServerSearchEmailPrivate {
	GearyImapSearchCriteria* criteria;
};

struct _GearyImapEngineServerSearchEmailReplayLocalAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineServerSearchEmail* self;
	GearyImapEngineReplayOperationStatus result;
};

struct _GearyImapEngineServerSearchEmailReplayRemoteAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineServerSearchEmail* self;
	GearyImapFolderSession* remote;
	GeeSortedSet* uids;
	GearyImapSearchCriteria* _tmp0_;
	GCancellable* _tmp1_;
	GeeSortedSet* _tmp2_;
	gboolean _tmp3_;
	GeeSortedSet* _tmp4_;
	GeeSortedSet* _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	GearyEmailIdentifier* first_id;
	GearyImapEngineMinimalFolder* _tmp8_;
	GearyImapDBFolder* _tmp9_;
	GearyImapDBFolder* _tmp10_;
	GeeSortedSet* _tmp11_;
	gpointer _tmp12_;
	GearyImapUID* _tmp13_;
	GCancellable* _tmp14_;
	GearyImapDBEmailIdentifier* _tmp15_;
	GearyEmailIdentifier* _tmp16_;
	GearyEmailIdentifier* _tmp17_;
	GeeSortedSet* _tmp18_;
	gpointer _tmp19_;
	GearyImapUID* _tmp20_;
	GeeSet* _tmp21_;
	GeeSet* _tmp22_;
	GeeHashSet* local_ids;
	GeeHashSet* _tmp23_;
	GeeIterator* _uid_it;
	GeeSortedSet* _tmp24_;
	GeeIterator* _tmp25_;
	GeeIterator* _tmp26_;
	GearyImapUID* uid;
	GeeIterator* _tmp27_;
	gpointer _tmp28_;
	GearyImapDBEmailIdentifier* id;
	GearyImapEngineMinimalFolder* _tmp29_;
	GearyImapDBFolder* _tmp30_;
	GearyImapDBFolder* _tmp31_;
	GearyImapUID* _tmp32_;
	GCancellable* _tmp33_;
	GearyImapDBEmailIdentifier* _tmp34_;
	GearyImapDBEmailIdentifier* _tmp35_;
	GeeHashSet* _tmp36_;
	GearyImapDBEmailIdentifier* _tmp37_;
	GeeList* local_list;
	GearyImapEngineMinimalFolder* _tmp38_;
	GearyImapDBFolder* _tmp39_;
	GearyImapDBFolder* _tmp40_;
	GeeHashSet* _tmp41_;
	GCancellable* _tmp42_;
	GeeList* _tmp43_;
	GeeMap* map;
	GeeHashMap* _tmp44_;
	GeeList* _tmp45_;
	GeeList* _email_list;
	GeeList* _tmp46_;
	gint _email_size;
	GeeList* _tmp47_;
	gint _tmp48_;
	gint _tmp49_;
	gint _email_index;
	gint _tmp50_;
	gint _tmp51_;
	GearyEmail* email;
	GeeList* _tmp52_;
	gpointer _tmp53_;
	GeeMap* _tmp54_;
	GearyEmail* _tmp55_;
	GearyEmailIdentifier* _tmp56_;
	GearyEmailIdentifier* _tmp57_;
	GearyEmail* _tmp58_;
	GeeIterator* _id_it;
	GeeMap* _tmp59_;
	GeeSet* _tmp60_;
	GeeSet* _tmp61_;
	GeeSet* _tmp62_;
	GeeIterator* _tmp63_;
	GeeIterator* _tmp64_;
	GeeIterator* _tmp65_;
	GearyImapDBEmailIdentifier* _vala1_id;
	GeeIterator* _tmp66_;
	gpointer _tmp67_;
	GearyEmail* _vala1_email;
	GeeMap* _tmp68_;
	GearyImapDBEmailIdentifier* _tmp69_;
	gpointer _tmp70_;
	GearyEmail* _tmp71_;
	GearyImapDBEmailIdentifier* _tmp72_;
	GearyImapUID* _tmp73_;
	GearyImapUID* _tmp74_;
	GearyEmail* _tmp75_;
	GearyEmailField _tmp76_;
	GearyEmailField _tmp77_;
	GearyImapDBEmailIdentifier* _tmp78_;
	GearyImapUID* _tmp79_;
	GearyImapUID* _tmp80_;
	GearyEmail* _tmp81_;
	GearyEmailField _tmp82_;
	GearyEmailField _tmp83_;
	GeeList* _tmp84_;
	GearyEmail* _tmp85_;
	GError* _inner_error0_;
};

static gint GearyImapEngineServerSearchEmail_private_offset;
static gpointer geary_imap_engine_server_search_email_parent_class = NULL;

VALA_EXTERN GType geary_imap_engine_replay_operation_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_db_email_identifier_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_engine_replay_operation_status_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_folder_session_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_engine_send_replay_operation_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_engine_abstract_list_email_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_engine_minimal_folder_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_engine_server_search_email_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void geary_imap_engine_replay_operation_replay_local_async (GearyImapEngineReplayOperation* self,
                                                            GAsyncReadyCallback _callback_,
                                                            gpointer _user_data_);
VALA_EXTERN GearyImapEngineReplayOperationStatus geary_imap_engine_replay_operation_replay_local_finish (GearyImapEngineReplayOperation* self,
                                                                                             GAsyncResult* _res_,
                                                                                             GError** error);
VALA_EXTERN void geary_imap_engine_replay_operation_replay_remote_async (GearyImapEngineReplayOperation* self,
                                                             GearyImapFolderSession* remote,
                                                             GAsyncReadyCallback _callback_,
                                                             gpointer _user_data_);
VALA_EXTERN void geary_imap_engine_replay_operation_replay_remote_finish (GearyImapEngineReplayOperation* self,
                                                              GAsyncResult* _res_,
                                                              GError** error);
VALA_EXTERN gchar* geary_imap_engine_replay_operation_describe_state (GearyImapEngineReplayOperation* self);
VALA_EXTERN GearyImapEngineServerSearchEmail* geary_imap_engine_server_search_email_new (GearyImapEngineMinimalFolder* owner,
                                                                             GearyImapSearchCriteria* criteria,
                                                                             GearyEmailField required_fields,
                                                                             GCancellable* cancellable);
VALA_EXTERN GearyImapEngineServerSearchEmail* geary_imap_engine_server_search_email_construct (GType object_type,
                                                                                   GearyImapEngineMinimalFolder* owner,
                                                                                   GearyImapSearchCriteria* criteria,
                                                                                   GearyEmailField required_fields,
                                                                                   GCancellable* cancellable);
VALA_EXTERN GearyImapEngineAbstractListEmail* geary_imap_engine_abstract_list_email_construct (GType object_type,
                                                                                   const gchar* name,
                                                                                   GearyImapEngineMinimalFolder* owner,
                                                                                   GearyEmailField required_fields,
                                                                                   GearyFolderListFlags flags,
                                                                                   GCancellable* cancellable);
VALA_EXTERN GType geary_imap_engine_replay_operation_on_error_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void geary_imap_engine_replay_operation_set_on_remote_error (GearyImapEngineReplayOperation* self,
                                                             GearyImapEngineReplayOperationOnError value);
static void geary_imap_engine_server_search_email_real_replay_local_async_data_free (gpointer _data);
static void geary_imap_engine_server_search_email_real_replay_local_async (GearyImapEngineReplayOperation* base,
                                                                    GAsyncReadyCallback _callback_,
                                                                    gpointer _user_data_);
static gboolean geary_imap_engine_server_search_email_real_replay_local_async_co (GearyImapEngineServerSearchEmailReplayLocalAsyncData* _data_);
static void geary_imap_engine_server_search_email_real_replay_remote_async_data_free (gpointer _data);
static void geary_imap_engine_server_search_email_real_replay_remote_async (GearyImapEngineReplayOperation* base,
                                                                     GearyImapFolderSession* remote,
                                                                     GAsyncReadyCallback _callback_,
                                                                     gpointer _user_data_);
static gboolean geary_imap_engine_server_search_email_real_replay_remote_async_co (GearyImapEngineServerSearchEmailReplayRemoteAsyncData* _data_);
VALA_EXTERN void geary_imap_folder_session_search_async (GearyImapFolderSession* self,
                                             GearyImapSearchCriteria* criteria,
                                             GCancellable* cancellable,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_);
VALA_EXTERN GeeSortedSet* geary_imap_folder_session_search_finish (GearyImapFolderSession* self,
                                                       GAsyncResult* _res_,
                                                       GError** error);
static void geary_imap_engine_server_search_email_replay_remote_async_ready (GObject* source_object,
                                                                      GAsyncResult* _res_,
                                                                      gpointer _user_data_);
VALA_EXTERN GType geary_imap_db_folder_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GearyImapDBFolder* geary_imap_engine_minimal_folder_get_local_folder (GearyImapEngineMinimalFolder* self);
VALA_EXTERN GType geary_imap_db_folder_list_flags_get_type (void) G_GNUC_CONST ;
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);
VALA_EXTERN void geary_imap_engine_abstract_list_email_expand_vector_async (GearyImapEngineAbstractListEmail* self,
                                                                GearyImapFolderSession* remote,
                                                                GearyImapUID* initial_uid,
                                                                gint count,
                                                                GAsyncReadyCallback _callback_,
                                                                gpointer _user_data_);
VALA_EXTERN GeeSet* geary_imap_engine_abstract_list_email_expand_vector_finish (GearyImapEngineAbstractListEmail* self,
                                                                    GAsyncResult* _res_,
                                                                    GError** error);
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);
VALA_EXTERN void geary_imap_engine_abstract_list_email_add_unfulfilled_fields (GearyImapEngineAbstractListEmail* self,
                                                                   GearyImapUID* uid,
                                                                   GearyEmailField unfulfilled_fields);
VALA_EXTERN GearyImapUID* geary_imap_db_email_identifier_get_uid (GearyImapDBEmailIdentifier* self);
static gchar* geary_imap_engine_server_search_email_real_describe_state (GearyImapEngineReplayOperation* base);
static void geary_imap_engine_server_search_email_finalize (GObject * obj);
static GType geary_imap_engine_server_search_email_get_type_once (void);

static inline gpointer
geary_imap_engine_server_search_email_get_instance_private (GearyImapEngineServerSearchEmail* self)
{
	return G_STRUCT_MEMBER_P (self, GearyImapEngineServerSearchEmail_private_offset);
}

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

GearyImapEngineServerSearchEmail*
geary_imap_engine_server_search_email_construct (GType object_type,
                                                 GearyImapEngineMinimalFolder* owner,
                                                 GearyImapSearchCriteria* criteria,
                                                 GearyEmailField required_fields,
                                                 GCancellable* cancellable)
{
	GearyImapEngineServerSearchEmail * self = NULL;
	GearyImapSearchCriteria* _tmp0_;
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_MINIMAL_FOLDER (owner), NULL);
	g_return_val_if_fail (GEARY_IMAP_IS_SEARCH_CRITERIA (criteria), NULL);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), NULL);
	self = (GearyImapEngineServerSearchEmail*) geary_imap_engine_abstract_list_email_construct (object_type, "ServerSearchEmail", owner, required_fields, GEARY_FOLDER_LIST_FLAGS_OLDEST_TO_NEWEST, cancellable);
	geary_imap_engine_replay_operation_set_on_remote_error (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, GearyImapEngineReplayOperation), GEARY_IMAP_ENGINE_REPLAY_OPERATION_ON_ERROR_RETRY);
	_tmp0_ = _g_object_ref0 (criteria);
	_g_object_unref0 (self->priv->criteria);
	self->priv->criteria = _tmp0_;
	return self;
}

GearyImapEngineServerSearchEmail*
geary_imap_engine_server_search_email_new (GearyImapEngineMinimalFolder* owner,
                                           GearyImapSearchCriteria* criteria,
                                           GearyEmailField required_fields,
                                           GCancellable* cancellable)
{
	return geary_imap_engine_server_search_email_construct (GEARY_IMAP_ENGINE_TYPE_SERVER_SEARCH_EMAIL, owner, criteria, required_fields, cancellable);
}

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

static void
geary_imap_engine_server_search_email_real_replay_local_async (GearyImapEngineReplayOperation* base,
                                                               GAsyncReadyCallback _callback_,
                                                               gpointer _user_data_)
{
	GearyImapEngineServerSearchEmail * self;
	GearyImapEngineServerSearchEmailReplayLocalAsyncData* _data_;
	GearyImapEngineServerSearchEmail* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_TYPE_SERVER_SEARCH_EMAIL, GearyImapEngineServerSearchEmail);
	_data_ = g_slice_new0 (GearyImapEngineServerSearchEmailReplayLocalAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_engine_server_search_email_real_replay_local_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	geary_imap_engine_server_search_email_real_replay_local_async_co (_data_);
}

static GearyImapEngineReplayOperationStatus
geary_imap_engine_server_search_email_replay_local_finish (GearyImapEngineReplayOperation* base,
                                                           GAsyncResult* _res_,
                                                           GError** error)
{
	GearyImapEngineReplayOperationStatus result;
	GearyImapEngineServerSearchEmailReplayLocalAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return 0;
	}
	result = _data_->result;
	return result;
}

static gboolean
geary_imap_engine_server_search_email_real_replay_local_async_co (GearyImapEngineServerSearchEmailReplayLocalAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->result = GEARY_IMAP_ENGINE_REPLAY_OPERATION_STATUS_CONTINUE;
	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_engine_server_search_email_real_replay_remote_async_data_free (gpointer _data)
{
	GearyImapEngineServerSearchEmailReplayRemoteAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->remote);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapEngineServerSearchEmailReplayRemoteAsyncData, _data_);
}

static void
geary_imap_engine_server_search_email_real_replay_remote_async (GearyImapEngineReplayOperation* base,
                                                                GearyImapFolderSession* remote,
                                                                GAsyncReadyCallback _callback_,
                                                                gpointer _user_data_)
{
	GearyImapEngineServerSearchEmail * self;
	GearyImapEngineServerSearchEmailReplayRemoteAsyncData* _data_;
	GearyImapEngineServerSearchEmail* _tmp0_;
	GearyImapFolderSession* _tmp1_;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (remote));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_TYPE_SERVER_SEARCH_EMAIL, GearyImapEngineServerSearchEmail);
	_data_ = g_slice_new0 (GearyImapEngineServerSearchEmailReplayRemoteAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_engine_server_search_email_real_replay_remote_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (remote);
	_g_object_unref0 (_data_->remote);
	_data_->remote = _tmp1_;
	geary_imap_engine_server_search_email_real_replay_remote_async_co (_data_);
}

static void
geary_imap_engine_server_search_email_replay_remote_finish (GearyImapEngineReplayOperation* base,
                                                            GAsyncResult* _res_,
                                                            GError** error)
{
	GearyImapEngineServerSearchEmailReplayRemoteAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
geary_imap_engine_server_search_email_replay_remote_async_ready (GObject* source_object,
                                                                 GAsyncResult* _res_,
                                                                 gpointer _user_data_)
{
	GearyImapEngineServerSearchEmailReplayRemoteAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_engine_server_search_email_real_replay_remote_async_co (_data_);
}

static gboolean
geary_imap_engine_server_search_email_real_replay_remote_async_co (GearyImapEngineServerSearchEmailReplayRemoteAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		case 4:
		goto _state_4;
		case 5:
		goto _state_5;
		case 6:
		goto _state_6;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->criteria;
	_data_->_tmp1_ = G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmail)->cancellable;
	_data_->_state_ = 1;
	geary_imap_folder_session_search_async (_data_->remote, _data_->_tmp0_, _data_->_tmp1_, geary_imap_engine_server_search_email_replay_remote_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp2_ = geary_imap_folder_session_search_finish (_data_->remote, _data_->_res_, &_data_->_inner_error0_);
	_data_->uids = _data_->_tmp2_;
	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_->_tmp4_ = _data_->uids;
	if (_data_->_tmp4_ == NULL) {
		_data_->_tmp3_ = TRUE;
	} else {
		_data_->_tmp5_ = _data_->uids;
		_data_->_tmp6_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp5_, GEE_TYPE_COLLECTION, GeeCollection));
		_data_->_tmp7_ = _data_->_tmp6_;
		_data_->_tmp3_ = _data_->_tmp7_ == 0;
	}
	if (_data_->_tmp3_) {
		_g_object_unref0 (_data_->uids);
		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_->_tmp8_ = G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmail)->owner;
	_data_->_tmp9_ = geary_imap_engine_minimal_folder_get_local_folder (_data_->_tmp8_);
	_data_->_tmp10_ = _data_->_tmp9_;
	_data_->_tmp11_ = _data_->uids;
	_data_->_tmp12_ = gee_sorted_set_first (_data_->_tmp11_);
	_data_->_tmp13_ = (GearyImapUID*) _data_->_tmp12_;
	_data_->_tmp14_ = G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmail)->cancellable;
	_data_->_state_ = 2;
	geary_imap_db_folder_get_id_async (_data_->_tmp10_, _data_->_tmp13_, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_NONE, _data_->_tmp14_, geary_imap_engine_server_search_email_replay_remote_async_ready, _data_);
	return FALSE;
	_state_2:
	_data_->_tmp15_ = geary_imap_db_folder_get_id_finish (_data_->_tmp10_, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp16_ = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp15_, GEARY_TYPE_EMAIL_IDENTIFIER, GearyEmailIdentifier);
	_g_object_unref0 (_data_->_tmp13_);
	_data_->first_id = _data_->_tmp16_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->uids);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp17_ = _data_->first_id;
	if (_data_->_tmp17_ == NULL) {
		_data_->_tmp18_ = _data_->uids;
		_data_->_tmp19_ = gee_sorted_set_first (_data_->_tmp18_);
		_data_->_tmp20_ = (GearyImapUID*) _data_->_tmp19_;
		_data_->_state_ = 3;
		geary_imap_engine_abstract_list_email_expand_vector_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmail), _data_->remote, _data_->_tmp20_, 1, geary_imap_engine_server_search_email_replay_remote_async_ready, _data_);
		return FALSE;
		_state_3:
		_data_->_tmp21_ = geary_imap_engine_abstract_list_email_expand_vector_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmail), _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp22_ = _data_->_tmp21_;
		_g_object_unref0 (_data_->_tmp22_);
		_g_object_unref0 (_data_->_tmp20_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->first_id);
			_g_object_unref0 (_data_->uids);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->_tmp23_ = 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_->local_ids = _data_->_tmp23_;
	{
		_data_->_tmp24_ = _data_->uids;
		_data_->_tmp25_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp24_, GEE_TYPE_ITERABLE, GeeIterable));
		_data_->_uid_it = _data_->_tmp25_;
		while (TRUE) {
			_data_->_tmp26_ = _data_->_uid_it;
			if (!gee_iterator_next (_data_->_tmp26_)) {
				break;
			}
			_data_->_tmp27_ = _data_->_uid_it;
			_data_->_tmp28_ = gee_iterator_get (_data_->_tmp27_);
			_data_->uid = (GearyImapUID*) _data_->_tmp28_;
			_data_->_tmp29_ = G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmail)->owner;
			_data_->_tmp30_ = geary_imap_engine_minimal_folder_get_local_folder (_data_->_tmp29_);
			_data_->_tmp31_ = _data_->_tmp30_;
			_data_->_tmp32_ = _data_->uid;
			_data_->_tmp33_ = G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmail)->cancellable;
			_data_->_state_ = 4;
			geary_imap_db_folder_get_id_async (_data_->_tmp31_, _data_->_tmp32_, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_NONE, _data_->_tmp33_, geary_imap_engine_server_search_email_replay_remote_async_ready, _data_);
			return FALSE;
			_state_4:
			_data_->_tmp34_ = geary_imap_db_folder_get_id_finish (_data_->_tmp31_, _data_->_res_, &_data_->_inner_error0_);
			_data_->id = _data_->_tmp34_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
				_g_object_unref0 (_data_->uid);
				_g_object_unref0 (_data_->_uid_it);
				_g_object_unref0 (_data_->local_ids);
				_g_object_unref0 (_data_->first_id);
				_g_object_unref0 (_data_->uids);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
			_data_->_tmp35_ = _data_->id;
			if (_data_->_tmp35_ != NULL) {
				_data_->_tmp36_ = _data_->local_ids;
				_data_->_tmp37_ = _data_->id;
				gee_abstract_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp36_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection), _data_->_tmp37_);
			}
			_g_object_unref0 (_data_->id);
			_g_object_unref0 (_data_->uid);
		}
		_g_object_unref0 (_data_->_uid_it);
	}
	_data_->_tmp38_ = G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmail)->owner;
	_data_->_tmp39_ = geary_imap_engine_minimal_folder_get_local_folder (_data_->_tmp38_);
	_data_->_tmp40_ = _data_->_tmp39_;
	_data_->_tmp41_ = _data_->local_ids;
	_data_->_tmp42_ = G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmail)->cancellable;
	_data_->_state_ = 5;
	geary_imap_db_folder_list_email_by_sparse_id_async (_data_->_tmp40_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp41_, GEE_TYPE_COLLECTION, GeeCollection), G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmail)->required_fields, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_PARTIAL_OK, _data_->_tmp42_, geary_imap_engine_server_search_email_replay_remote_async_ready, _data_);
	return FALSE;
	_state_5:
	_data_->_tmp43_ = geary_imap_db_folder_list_email_by_sparse_id_finish (_data_->_tmp40_, _data_->_res_, &_data_->_inner_error0_);
	_data_->local_list = _data_->_tmp43_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->local_ids);
		_g_object_unref0 (_data_->first_id);
		_g_object_unref0 (_data_->uids);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp44_ = gee_hash_map_new (GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEARY_TYPE_EMAIL, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->map = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp44_, GEE_TYPE_MAP, GeeMap);
	_data_->_tmp45_ = _data_->local_list;
	if (_data_->_tmp45_ != NULL) {
		{
			_data_->_tmp46_ = _data_->local_list;
			_data_->_email_list = _data_->_tmp46_;
			_data_->_tmp47_ = _data_->_email_list;
			_data_->_tmp48_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp47_, GEE_TYPE_COLLECTION, GeeCollection));
			_data_->_tmp49_ = _data_->_tmp48_;
			_data_->_email_size = _data_->_tmp49_;
			_data_->_email_index = -1;
			while (TRUE) {
				_data_->_email_index = _data_->_email_index + 1;
				_data_->_tmp50_ = _data_->_email_index;
				_data_->_tmp51_ = _data_->_email_size;
				if (!(_data_->_tmp50_ < _data_->_tmp51_)) {
					break;
				}
				_data_->_tmp52_ = _data_->_email_list;
				_data_->_tmp53_ = gee_list_get (_data_->_tmp52_, _data_->_email_index);
				_data_->email = (GearyEmail*) _data_->_tmp53_;
				_data_->_tmp54_ = _data_->map;
				_data_->_tmp55_ = _data_->email;
				_data_->_tmp56_ = geary_email_get_id (_data_->_tmp55_);
				_data_->_tmp57_ = _data_->_tmp56_;
				_data_->_tmp58_ = _data_->email;
				gee_map_set (_data_->_tmp54_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp57_, GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, GearyImapDBEmailIdentifier), _data_->_tmp58_);
				_g_object_unref0 (_data_->email);
			}
		}
	}
	{
		_data_->_tmp59_ = _data_->map;
		_data_->_tmp60_ = gee_map_get_keys (_data_->_tmp59_);
		_data_->_tmp61_ = _data_->_tmp60_;
		_data_->_tmp62_ = _data_->_tmp61_;
		_data_->_tmp63_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp62_, GEE_TYPE_ITERABLE, GeeIterable));
		_data_->_tmp64_ = _data_->_tmp63_;
		_g_object_unref0 (_data_->_tmp62_);
		_data_->_id_it = _data_->_tmp64_;
		while (TRUE) {
			_data_->_tmp65_ = _data_->_id_it;
			if (!gee_iterator_next (_data_->_tmp65_)) {
				break;
			}
			_data_->_tmp66_ = _data_->_id_it;
			_data_->_tmp67_ = gee_iterator_get (_data_->_tmp66_);
			_data_->_vala1_id = (GearyImapDBEmailIdentifier*) _data_->_tmp67_;
			_data_->_tmp68_ = _data_->map;
			_data_->_tmp69_ = _data_->_vala1_id;
			_data_->_tmp70_ = gee_map_get (_data_->_tmp68_, _data_->_tmp69_);
			_data_->_vala1_email = (GearyEmail*) _data_->_tmp70_;
			_data_->_tmp71_ = _data_->_vala1_email;
			if (_data_->_tmp71_ == NULL) {
				_data_->_tmp72_ = _data_->_vala1_id;
				_data_->_tmp73_ = geary_imap_db_email_identifier_get_uid (_data_->_tmp72_);
				_data_->_tmp74_ = _data_->_tmp73_;
				geary_imap_engine_abstract_list_email_add_unfulfilled_fields (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmail), _data_->_tmp74_, G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmail)->required_fields | GEARY_IMAP_DB_FOLDER_REQUIRED_FIELDS);
			} else {
				_data_->_tmp75_ = _data_->_vala1_email;
				_data_->_tmp76_ = geary_email_get_fields (_data_->_tmp75_);
				_data_->_tmp77_ = _data_->_tmp76_;
				if (!geary_email_field_fulfills (_data_->_tmp77_, G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmail)->required_fields)) {
					_data_->_tmp78_ = _data_->_vala1_id;
					_data_->_tmp79_ = geary_imap_db_email_identifier_get_uid (_data_->_tmp78_);
					_data_->_tmp80_ = _data_->_tmp79_;
					_data_->_tmp81_ = _data_->_vala1_email;
					_data_->_tmp82_ = geary_email_get_fields (_data_->_tmp81_);
					_data_->_tmp83_ = _data_->_tmp82_;
					geary_imap_engine_abstract_list_email_add_unfulfilled_fields (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmail), _data_->_tmp80_, geary_email_field_clear (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmail)->required_fields, _data_->_tmp83_));
				} else {
					_data_->_tmp84_ = G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmail)->accumulator;
					_data_->_tmp85_ = _data_->_vala1_email;
					gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp84_, GEE_TYPE_COLLECTION, GeeCollection), _data_->_tmp85_);
				}
			}
			_g_object_unref0 (_data_->_vala1_email);
			_g_object_unref0 (_data_->_vala1_id);
		}
		_g_object_unref0 (_data_->_id_it);
	}
	_data_->_state_ = 6;
	GEARY_IMAP_ENGINE_REPLAY_OPERATION_CLASS (geary_imap_engine_server_search_email_parent_class)->replay_remote_async (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmail), GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, GearyImapEngineReplayOperation), _data_->remote, geary_imap_engine_server_search_email_replay_remote_async_ready, _data_);
	return FALSE;
	_state_6:
	GEARY_IMAP_ENGINE_REPLAY_OPERATION_CLASS (geary_imap_engine_server_search_email_parent_class)->replay_remote_finish (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, GearyImapEngineAbstractListEmail), GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, GearyImapEngineReplayOperation), _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_->map);
		_g_object_unref0 (_data_->local_list);
		_g_object_unref0 (_data_->local_ids);
		_g_object_unref0 (_data_->first_id);
		_g_object_unref0 (_data_->uids);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_object_unref0 (_data_->map);
	_g_object_unref0 (_data_->local_list);
	_g_object_unref0 (_data_->local_ids);
	_g_object_unref0 (_data_->first_id);
	_g_object_unref0 (_data_->uids);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static gchar*
geary_imap_engine_server_search_email_real_describe_state (GearyImapEngineReplayOperation* base)
{
	GearyImapEngineServerSearchEmail * self;
	GearyImapSearchCriteria* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_TYPE_SERVER_SEARCH_EMAIL, GearyImapEngineServerSearchEmail);
	_tmp0_ = self->priv->criteria;
	_tmp1_ = geary_imap_parameter_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup_printf ("criteria=%s", _tmp2_);
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	result = _tmp4_;
	return result;
}

static void
geary_imap_engine_server_search_email_class_init (GearyImapEngineServerSearchEmailClass * klass,
                                                  gpointer klass_data)
{
	geary_imap_engine_server_search_email_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GearyImapEngineServerSearchEmail_private_offset);
	((GearyImapEngineReplayOperationClass *) klass)->replay_local_async = (void (*) (GearyImapEngineReplayOperation*, GAsyncReadyCallback, gpointer)) geary_imap_engine_server_search_email_real_replay_local_async;
	((GearyImapEngineReplayOperationClass *) klass)->replay_local_finish = (GearyImapEngineReplayOperationStatus (*) (GearyImapEngineReplayOperation*, GAsyncResult*, GError**)) geary_imap_engine_server_search_email_replay_local_finish;
	((GearyImapEngineReplayOperationClass *) klass)->replay_remote_async = (void (*) (GearyImapEngineReplayOperation*, GearyImapFolderSession*, GAsyncReadyCallback, gpointer)) geary_imap_engine_server_search_email_real_replay_remote_async;
	((GearyImapEngineReplayOperationClass *) klass)->replay_remote_finish = (void (*) (GearyImapEngineReplayOperation*, GAsyncResult*, GError**)) geary_imap_engine_server_search_email_replay_remote_finish;
	((GearyImapEngineReplayOperationClass *) klass)->describe_state = (gchar* (*) (GearyImapEngineReplayOperation*)) geary_imap_engine_server_search_email_real_describe_state;
	G_OBJECT_CLASS (klass)->finalize = geary_imap_engine_server_search_email_finalize;
}

static void
geary_imap_engine_server_search_email_instance_init (GearyImapEngineServerSearchEmail * self,
                                                     gpointer klass)
{
	self->priv = geary_imap_engine_server_search_email_get_instance_private (self);
}

static void
geary_imap_engine_server_search_email_finalize (GObject * obj)
{
	GearyImapEngineServerSearchEmail * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_IMAP_ENGINE_TYPE_SERVER_SEARCH_EMAIL, GearyImapEngineServerSearchEmail);
	_g_object_unref0 (self->priv->criteria);
	G_OBJECT_CLASS (geary_imap_engine_server_search_email_parent_class)->finalize (obj);
}

/**
 * Performs an IMAP SEARCH command on the server, performing vector expansion to include all
 * discovered emails if required.
 *
 * Note that this does ''no'' searching of local email.
 */
 G_GNUC_NO_INLINE static GType
geary_imap_engine_server_search_email_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapEngineServerSearchEmailClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_engine_server_search_email_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapEngineServerSearchEmail), 0, (GInstanceInitFunc) geary_imap_engine_server_search_email_instance_init, NULL };
	GType geary_imap_engine_server_search_email_type_id;
	geary_imap_engine_server_search_email_type_id = g_type_register_static (GEARY_IMAP_ENGINE_TYPE_ABSTRACT_LIST_EMAIL, "GearyImapEngineServerSearchEmail", &g_define_type_info, 0);
	GearyImapEngineServerSearchEmail_private_offset = g_type_add_instance_private (geary_imap_engine_server_search_email_type_id, sizeof (GearyImapEngineServerSearchEmailPrivate));
	return geary_imap_engine_server_search_email_type_id;
}

GType
geary_imap_engine_server_search_email_get_type (void)
{
	static gsize geary_imap_engine_server_search_email_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_engine_server_search_email_type_id__once)) {
		GType geary_imap_engine_server_search_email_type_id;
		geary_imap_engine_server_search_email_type_id = geary_imap_engine_server_search_email_get_type_once ();
		g_once_init_leave (&geary_imap_engine_server_search_email_type_id__once, geary_imap_engine_server_search_email_type_id);
	}
	return geary_imap_engine_server_search_email_type_id__once;
}

