/* imap-engine-replay-queue.c generated by valac 0.56.19, the Vala compiler
 * generated from imap-engine-replay-queue.vala, do not modify */

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

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

#define GEARY_IMAP_ENGINE_REPLAY_QUEUE_MAX_OP_RETRIES 1
#define GEARY_IMAP_ENGINE_REPLAY_QUEUE_NOTIFICATION_QUEUE_WAIT_MSEC 1000
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE (geary_imap_engine_replay_queue_get_type ())
#define GEARY_IMAP_ENGINE_REPLAY_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, GearyImapEngineReplayQueue))
#define GEARY_IMAP_ENGINE_REPLAY_QUEUE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, GearyImapEngineReplayQueueClass))
#define GEARY_IMAP_ENGINE_IS_REPLAY_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE))
#define GEARY_IMAP_ENGINE_IS_REPLAY_QUEUE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE))
#define GEARY_IMAP_ENGINE_REPLAY_QUEUE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, GearyImapEngineReplayQueueClass))

typedef struct _GearyImapEngineReplayQueue GearyImapEngineReplayQueue;
typedef struct _GearyImapEngineReplayQueueClass GearyImapEngineReplayQueueClass;
typedef struct _GearyImapEngineReplayQueuePrivate GearyImapEngineReplayQueuePrivate;

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

#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;
typedef enum  {
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_STATE_OPEN,
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_STATE_CLOSING,
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_STATE_CLOSED
} GearyImapEngineReplayQueueState;

#define GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_STATE (geary_imap_engine_replay_queue_state_get_type ())
enum  {
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_0_PROPERTY,
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_LOCAL_COUNT_PROPERTY,
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_REMOTE_COUNT_PROPERTY,
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_LOGGING_PARENT_PROPERTY,
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_NUM_PROPERTIES
};
static GParamSpec* geary_imap_engine_replay_queue_properties[GEARY_IMAP_ENGINE_REPLAY_QUEUE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#define GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_CLOSE_REPLAY_QUEUE (geary_imap_engine_replay_queue_close_replay_queue_get_type ())
#define GEARY_IMAP_ENGINE_REPLAY_QUEUE_CLOSE_REPLAY_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_CLOSE_REPLAY_QUEUE, GearyImapEngineReplayQueueCloseReplayQueue))
#define GEARY_IMAP_ENGINE_REPLAY_QUEUE_CLOSE_REPLAY_QUEUE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_CLOSE_REPLAY_QUEUE, GearyImapEngineReplayQueueCloseReplayQueueClass))
#define GEARY_IMAP_ENGINE_REPLAY_QUEUE_IS_CLOSE_REPLAY_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_CLOSE_REPLAY_QUEUE))
#define GEARY_IMAP_ENGINE_REPLAY_QUEUE_IS_CLOSE_REPLAY_QUEUE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_CLOSE_REPLAY_QUEUE))
#define GEARY_IMAP_ENGINE_REPLAY_QUEUE_CLOSE_REPLAY_QUEUE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_CLOSE_REPLAY_QUEUE, GearyImapEngineReplayQueueCloseReplayQueueClass))

typedef struct _GearyImapEngineReplayQueueCloseReplayQueue GearyImapEngineReplayQueueCloseReplayQueue;
typedef struct _GearyImapEngineReplayQueueCloseReplayQueueClass GearyImapEngineReplayQueueCloseReplayQueueClass;

#define GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_WAIT_OPERATION (geary_imap_engine_replay_queue_wait_operation_get_type ())
#define GEARY_IMAP_ENGINE_REPLAY_QUEUE_WAIT_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_WAIT_OPERATION, GearyImapEngineReplayQueueWaitOperation))
#define GEARY_IMAP_ENGINE_REPLAY_QUEUE_WAIT_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_WAIT_OPERATION, GearyImapEngineReplayQueueWaitOperationClass))
#define GEARY_IMAP_ENGINE_REPLAY_QUEUE_IS_WAIT_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_WAIT_OPERATION))
#define GEARY_IMAP_ENGINE_REPLAY_QUEUE_IS_WAIT_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_WAIT_OPERATION))
#define GEARY_IMAP_ENGINE_REPLAY_QUEUE_WAIT_OPERATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_WAIT_OPERATION, GearyImapEngineReplayQueueWaitOperationClass))

typedef struct _GearyImapEngineReplayQueueWaitOperation GearyImapEngineReplayQueueWaitOperation;
typedef struct _GearyImapEngineReplayQueueWaitOperationClass GearyImapEngineReplayQueueWaitOperationClass;
typedef struct _GearyImapEngineReplayQueueCheckpointData GearyImapEngineReplayQueueCheckpointData;

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

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

#define GEARY_IMAP_ENGINE_TYPE_MARK_EMAIL (geary_imap_engine_mark_email_get_type ())
#define GEARY_IMAP_ENGINE_MARK_EMAIL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_ENGINE_TYPE_MARK_EMAIL, GearyImapEngineMarkEmail))
#define GEARY_IMAP_ENGINE_MARK_EMAIL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_ENGINE_TYPE_MARK_EMAIL, GearyImapEngineMarkEmailClass))
#define GEARY_IMAP_ENGINE_IS_MARK_EMAIL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_ENGINE_TYPE_MARK_EMAIL))
#define GEARY_IMAP_ENGINE_IS_MARK_EMAIL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_ENGINE_TYPE_MARK_EMAIL))
#define GEARY_IMAP_ENGINE_MARK_EMAIL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_ENGINE_TYPE_MARK_EMAIL, GearyImapEngineMarkEmailClass))

typedef struct _GearyImapEngineMarkEmail GearyImapEngineMarkEmail;
typedef struct _GearyImapEngineMarkEmailClass GearyImapEngineMarkEmailClass;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _GearyImapEngineReplayQueueClearPendingAsyncData GearyImapEngineReplayQueueClearPendingAsyncData;
typedef enum  {
	GEARY_IMAP_ENGINE_REPLAY_OPERATION_SCOPE_LOCAL_AND_REMOTE,
	GEARY_IMAP_ENGINE_REPLAY_OPERATION_SCOPE_LOCAL_ONLY,
	GEARY_IMAP_ENGINE_REPLAY_OPERATION_SCOPE_REMOTE_ONLY
} GearyImapEngineReplayOperationScope;

#define GEARY_IMAP_ENGINE_REPLAY_OPERATION_TYPE_SCOPE (geary_imap_engine_replay_operation_scope_get_type ())
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 ())
typedef struct _GearyImapEngineReplayQueueDoReplayLocalAsyncData GearyImapEngineReplayQueueDoReplayLocalAsyncData;

#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;
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 _GearyImapEngineReplayQueueDoReplayRemoteAsyncData GearyImapEngineReplayQueueDoReplayRemoteAsyncData;
typedef struct _GearyImapEngineReplayOperationPrivate GearyImapEngineReplayOperationPrivate;
typedef struct _GearyImapEngineReplayQueueCloseReplayQueuePrivate GearyImapEngineReplayQueueCloseReplayQueuePrivate;
enum  {
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_CLOSE_REPLAY_QUEUE_0_PROPERTY,
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_CLOSE_REPLAY_QUEUE_NUM_PROPERTIES
};
static GParamSpec* geary_imap_engine_replay_queue_close_replay_queue_properties[GEARY_IMAP_ENGINE_REPLAY_QUEUE_CLOSE_REPLAY_QUEUE_NUM_PROPERTIES];
typedef struct _GearyImapEngineReplayQueueCloseReplayQueueReplayLocalAsyncData GearyImapEngineReplayQueueCloseReplayQueueReplayLocalAsyncData;
typedef struct _GearyImapEngineReplayQueueCloseReplayQueueReplayRemoteAsyncData GearyImapEngineReplayQueueCloseReplayQueueReplayRemoteAsyncData;
typedef struct _GearyImapEngineReplayQueueWaitOperationPrivate GearyImapEngineReplayQueueWaitOperationPrivate;
enum  {
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_WAIT_OPERATION_0_PROPERTY,
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_WAIT_OPERATION_NUM_PROPERTIES
};
static GParamSpec* geary_imap_engine_replay_queue_wait_operation_properties[GEARY_IMAP_ENGINE_REPLAY_QUEUE_WAIT_OPERATION_NUM_PROPERTIES];
typedef struct _GearyImapEngineReplayQueueWaitOperationReplayLocalAsyncData GearyImapEngineReplayQueueWaitOperationReplayLocalAsyncData;
typedef struct _GearyImapEngineReplayQueueWaitOperationReplayRemoteAsyncData GearyImapEngineReplayQueueWaitOperationReplayRemoteAsyncData;
enum  {
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_SCHEDULED_SIGNAL,
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_LOCALLY_EXECUTING_SIGNAL,
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_LOCALLY_EXECUTED_SIGNAL,
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_REMOTELY_EXECUTING_SIGNAL,
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_REMOTELY_EXECUTED_SIGNAL,
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_BACKING_OUT_SIGNAL,
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_BACKED_OUT_SIGNAL,
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_BACKOUT_FAILED_SIGNAL,
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_COMPLETED_SIGNAL,
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_FAILED_SIGNAL,
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_CLOSING_SIGNAL,
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_CLOSED_SIGNAL,
	GEARY_IMAP_ENGINE_REPLAY_QUEUE_NUM_SIGNALS
};
static guint geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_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 _GearyImapEngineReplayQueue {
	GearyBaseObject parent_instance;
	GearyImapEngineReplayQueuePrivate * priv;
};

struct _GearyImapEngineReplayQueueClass {
	GearyBaseObjectClass parent_class;
	void (*scheduled) (GearyImapEngineReplayQueue* self, GearyImapEngineReplayOperation* op);
	void (*locally_executing) (GearyImapEngineReplayQueue* self, GearyImapEngineReplayOperation* op);
	void (*locally_executed) (GearyImapEngineReplayQueue* self, GearyImapEngineReplayOperation* op, gboolean continuing);
	void (*remotely_executing) (GearyImapEngineReplayQueue* self, GearyImapEngineReplayOperation* op);
	void (*remotely_executed) (GearyImapEngineReplayQueue* self, GearyImapEngineReplayOperation* op);
	void (*backing_out) (GearyImapEngineReplayQueue* self, GearyImapEngineReplayOperation* op, GError* err);
	void (*backed_out) (GearyImapEngineReplayQueue* self, GearyImapEngineReplayOperation* op, GError* err);
	void (*backout_failed) (GearyImapEngineReplayQueue* self, GearyImapEngineReplayOperation* op, GError* backout_err);
	void (*completed) (GearyImapEngineReplayQueue* self, GearyImapEngineReplayOperation* op);
	void (*failed) (GearyImapEngineReplayQueue* self, GearyImapEngineReplayOperation* op);
	void (*closing) (GearyImapEngineReplayQueue* self);
	void (*closed) (GearyImapEngineReplayQueue* self);
};

struct _GearyImapEngineReplayQueuePrivate {
	GearyImapEngineMinimalFolder* owner;
	GearyNonblockingQueue* local_queue;
	GearyNonblockingQueue* remote_queue;
	GearyImapEngineReplayOperation* local_op_active;
	GearyImapEngineReplayOperation* remote_op_active;
	GeeArrayList* notification_queue;
	GearySchedulerScheduled* notification_timer;
	gint64 next_submission_number;
	GearyImapEngineReplayQueueState state;
	GCancellable* remote_wait_cancellable;
};

struct _GearyImapEngineReplayQueueCheckpointData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineReplayQueue* self;
	GCancellable* cancellable;
	GearyImapEngineReplayQueueWaitOperation* wait_op;
	GearyImapEngineReplayQueueWaitOperation* _tmp0_;
	GearyImapEngineReplayQueueWaitOperation* _tmp1_;
	GearyImapEngineReplayQueueWaitOperation* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	GError* _inner_error0_;
};

struct _GearyImapEngineReplayQueueCloseAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineReplayQueue* self;
	gboolean flush_pending;
	GCancellable* cancellable;
	GearySchedulerScheduled* _tmp0_;
	GearySchedulerScheduled* _tmp1_;
	GCancellable* _tmp2_;
	GearyImapEngineReplayQueueCloseReplayQueue* close_op;
	GearyImapEngineReplayQueueCloseReplayQueue* _tmp3_;
	gboolean is_scheduled;
	GearyImapEngineReplayQueueCloseReplayQueue* _tmp4_;
	GearyImapEngineReplayQueueCloseReplayQueue* _tmp5_;
	GError* _inner_error0_;
};

struct _GearyImapEngineReplayQueueClearPendingAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineReplayQueue* self;
	GCancellable* cancellable;
	GeeArrayList* _tmp0_;
	GearyNonblockingQueue* _tmp1_;
	GeeList* remote_list;
	GeeArrayList* _tmp2_;
	GeeList* _tmp3_;
	GearyNonblockingQueue* _tmp4_;
	GeeCollection* _tmp5_;
	GeeCollection* _tmp6_;
	GearyNonblockingQueue* _tmp7_;
	GeeList* _op_list;
	GeeList* _tmp8_;
	gint _op_size;
	GeeList* _tmp9_;
	gint _tmp10_;
	gint _tmp11_;
	gint _op_index;
	gint _tmp12_;
	gint _tmp13_;
	GearyImapEngineReplayOperation* op;
	GeeList* _tmp14_;
	gpointer _tmp15_;
	GearyImapEngineReplayOperation* _tmp16_;
	GError* err;
	GearyImapEngineReplayOperation* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_;
	GError* _tmp20_;
	const gchar* _tmp21_;
	GError* _inner_error0_;
};

struct _GearyImapEngineReplayQueueDoReplayLocalAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineReplayQueue* self;
	gboolean queue_running;
	GearyImapEngineReplayOperation* op;
	GearyImapEngineReplayOperation* _tmp0_;
	GearyNonblockingQueue* _tmp1_;
	gpointer _tmp2_;
	GearyImapEngineReplayOperation* _tmp3_;
	GError* recv_err;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GError* _tmp6_;
	const gchar* _tmp7_;
	GearyImapEngineReplayOperation* _tmp8_;
	GearyImapEngineReplayOperation* _tmp9_;
	GearyImapEngineReplayOperation* _tmp10_;
	gboolean local_execute;
	gboolean remote_enqueue;
	GearyImapEngineReplayOperation* _tmp11_;
	GearyImapEngineReplayOperationScope _tmp12_;
	GearyImapEngineReplayOperationScope _tmp13_;
	GearyImapEngineReplayOperation* _tmp14_;
	GearyImapEngineReplayOperationStatus _tmp15_;
	GearyImapEngineReplayOperation* _tmp16_;
	GearyImapEngineReplayOperation* _tmp17_;
	GearyImapEngineReplayOperation* _tmp18_;
	GError* replay_err;
	GearyImapEngineReplayOperation* _tmp19_;
	gchar* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	gchar* _tmp23_;
	GError* _tmp24_;
	const gchar* _tmp25_;
	GearyImapEngineReplayOperation* _tmp26_;
	GError* _tmp27_;
	GearyNonblockingQueue* _tmp28_;
	GearyImapEngineReplayOperation* _tmp29_;
	GearyImapEngineReplayOperation* _tmp30_;
	gchar* _tmp31_;
	gchar* _tmp32_;
	gchar* _tmp33_;
	gchar* _tmp34_;
	GearyImapEngineReplayOperation* _tmp35_;
	gboolean _tmp36_;
	gboolean _tmp37_;
	GearyImapEngineReplayOperation* _tmp38_;
	GearyImapEngineReplayOperation* _tmp39_;
	GError* _tmp40_;
	GError* _tmp41_;
	GearyImapEngineReplayOperation* _tmp42_;
	GearyImapEngineReplayOperation* _tmp43_;
	gchar* _tmp44_;
	gchar* _tmp45_;
	GError* _inner_error0_;
};

struct _GearyImapEngineReplayQueueDoReplayRemoteAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineReplayQueue* self;
	gboolean folder_opened;
	gboolean queue_running;
	GearyImapEngineReplayOperation* op;
	GearyImapEngineReplayOperation* _tmp0_;
	GearyNonblockingQueue* _tmp1_;
	gpointer _tmp2_;
	GearyImapEngineReplayOperation* _tmp3_;
	GError* recv_err;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GError* _tmp6_;
	const gchar* _tmp7_;
	GearyImapEngineReplayOperation* _tmp8_;
	GearyImapEngineReplayOperation* _tmp9_;
	gboolean is_close_op;
	GearyImapEngineReplayOperation* _tmp10_;
	GearyImapFolderSession* remote;
	gboolean _tmp11_;
	gboolean _tmp12_;
	GearyImapFolderSession* _tmp13_;
	GearyImapEngineMinimalFolder* _tmp14_;
	GCancellable* _tmp15_;
	GearyImapFolderSession* _tmp16_;
	GearyImapFolderSession* _tmp17_;
	GError* remote_err;
	gchar* _tmp18_;
	gchar* _tmp19_;
	GError* _tmp20_;
	const gchar* _tmp21_;
	GearyImapEngineReplayOperation* _tmp22_;
	GError* _vala1_remote_err;
	GearyImapFolderSession* _tmp23_;
	GearyImapEngineReplayOperation* _tmp24_;
	gint _tmp25_;
	gint _tmp26_;
	GearyImapEngineReplayOperation* _tmp27_;
	gchar* _tmp28_;
	gchar* _tmp29_;
	gchar* _tmp30_;
	gchar* _tmp31_;
	GearyImapEngineReplayOperation* _tmp32_;
	GearyImapFolderSession* _tmp33_;
	GError* replay_err;
	GearyImapEngineReplayOperation* _tmp34_;
	gchar* _tmp35_;
	gchar* _tmp36_;
	gchar* _tmp37_;
	gchar* _tmp38_;
	GError* _tmp39_;
	const gchar* _tmp40_;
	GearyImapEngineReplayOperation* _tmp41_;
	GearyImapEngineReplayOperationOnError _tmp42_;
	GearyImapEngineReplayOperationOnError _tmp43_;
	gchar* _tmp44_;
	gboolean _tmp45_;
	gboolean _tmp46_;
	gboolean _tmp47_;
	GearyImapEngineReplayOperation* _tmp48_;
	GearyImapEngineReplayOperationOnError _tmp49_;
	GearyImapEngineReplayOperationOnError _tmp50_;
	GearyImapEngineReplayOperation* _tmp51_;
	gint _tmp52_;
	gint _tmp53_;
	GError* _tmp54_;
	GearyImapEngineReplayOperation* _tmp55_;
	gchar* _tmp56_;
	gchar* _tmp57_;
	gchar* _tmp58_;
	gchar* _tmp59_;
	GearyImapEngineReplayOperation* _tmp60_;
	gint _tmp61_;
	gint _tmp62_;
	GearyNonblockingQueue* _tmp63_;
	GearyImapEngineReplayOperation* _tmp64_;
	gboolean _tmp65_;
	GearyImapEngineReplayOperation* _tmp66_;
	GearyImapEngineReplayOperationOnError _tmp67_;
	GearyImapEngineReplayOperationOnError _tmp68_;
	GError* _tmp69_;
	GearyImapEngineReplayOperation* _tmp70_;
	gchar* _tmp71_;
	gchar* _tmp72_;
	gchar* _tmp73_;
	gchar* _tmp74_;
	GearyImapEngineReplayOperation* _tmp75_;
	gchar* _tmp76_;
	gchar* _tmp77_;
	gchar* _tmp78_;
	gchar* _tmp79_;
	GError* _tmp80_;
	const gchar* _tmp81_;
	GError* _tmp82_;
	GError* _tmp83_;
	GearyImapEngineMinimalFolder* _tmp84_;
	gchar* _tmp85_;
	gchar* _tmp86_;
	GError* _tmp87_;
	gboolean _tmp88_;
	GError* _tmp89_;
	GearyImapEngineReplayOperation* _tmp90_;
	GError* _tmp91_;
	GearyImapEngineReplayOperation* _tmp92_;
	GearyImapEngineReplayOperation* _tmp93_;
	GError* _tmp94_;
	GError* backout_err;
	GearyImapEngineReplayOperation* _tmp95_;
	GError* _tmp96_;
	GearyImapEngineReplayOperation* _tmp97_;
	GError* _tmp98_;
	GearyImapEngineReplayOperation* _tmp99_;
	GearyImapEngineReplayOperation* _tmp100_;
	GError* _tmp101_;
	GError* _tmp102_;
	GearyImapEngineReplayOperation* _tmp103_;
	GearyImapEngineReplayOperation* _tmp104_;
	gchar* _tmp105_;
	gchar* _tmp106_;
	GError* _inner_error0_;
};

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 _GearyImapEngineReplayQueueCloseReplayQueue {
	GearyImapEngineReplayOperation parent_instance;
	GearyImapEngineReplayQueueCloseReplayQueuePrivate * priv;
};

struct _GearyImapEngineReplayQueueCloseReplayQueueClass {
	GearyImapEngineReplayOperationClass parent_class;
};

struct _GearyImapEngineReplayQueueCloseReplayQueuePrivate {
	gboolean local_closed;
	gboolean remote_closed;
};

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

struct _GearyImapEngineReplayQueueCloseReplayQueueReplayRemoteAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineReplayQueueCloseReplayQueue* self;
	GearyImapFolderSession* remote;
};

struct _GearyImapEngineReplayQueueWaitOperation {
	GearyImapEngineReplayOperation parent_instance;
	GearyImapEngineReplayQueueWaitOperationPrivate * priv;
};

struct _GearyImapEngineReplayQueueWaitOperationClass {
	GearyImapEngineReplayOperationClass parent_class;
};

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

struct _GearyImapEngineReplayQueueWaitOperationReplayRemoteAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineReplayQueueWaitOperation* self;
	GearyImapFolderSession* remote;
};

static gint GearyImapEngineReplayQueue_private_offset;
static gpointer geary_imap_engine_replay_queue_parent_class = NULL;
static gint GearyImapEngineReplayQueueCloseReplayQueue_private_offset;
static gpointer geary_imap_engine_replay_queue_close_replay_queue_parent_class = NULL;
static gpointer geary_imap_engine_replay_queue_wait_operation_parent_class = NULL;
static GearyLoggingSourceIface * geary_imap_engine_replay_queue_geary_logging_source_parent_iface = NULL;

VALA_EXTERN GType geary_imap_engine_replay_queue_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_engine_replay_operation_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_engine_minimal_folder_get_type (void) G_GNUC_CONST ;
static GType geary_imap_engine_replay_queue_state_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
VALA_EXTERN gint geary_imap_engine_replay_queue_get_local_count (GearyImapEngineReplayQueue* self);
VALA_EXTERN gint geary_imap_engine_replay_queue_get_remote_count (GearyImapEngineReplayQueue* self);
static void geary_imap_engine_replay_queue_real_scheduled (GearyImapEngineReplayQueue* self,
                                                    GearyImapEngineReplayOperation* op);
VALA_EXTERN gchar* geary_imap_engine_replay_operation_to_string (GearyImapEngineReplayOperation* self);
static void geary_imap_engine_replay_queue_real_locally_executing (GearyImapEngineReplayQueue* self,
                                                            GearyImapEngineReplayOperation* op);
static void geary_imap_engine_replay_queue_real_locally_executed (GearyImapEngineReplayQueue* self,
                                                           GearyImapEngineReplayOperation* op,
                                                           gboolean continuing);
static void g_cclosure_user_marshal_VOID__OBJECT_BOOLEAN (GClosure * closure,
                                                   GValue * return_value,
                                                   guint n_param_values,
                                                   const GValue * param_values,
                                                   gpointer invocation_hint,
                                                   gpointer marshal_data);
static void geary_imap_engine_replay_queue_real_remotely_executing (GearyImapEngineReplayQueue* self,
                                                             GearyImapEngineReplayOperation* op);
static void geary_imap_engine_replay_queue_real_remotely_executed (GearyImapEngineReplayQueue* self,
                                                            GearyImapEngineReplayOperation* op);
static void geary_imap_engine_replay_queue_real_backing_out (GearyImapEngineReplayQueue* self,
                                                      GearyImapEngineReplayOperation* op,
                                                      GError* err);
static void g_cclosure_user_marshal_VOID__OBJECT_BOXED (GClosure * closure,
                                                 GValue * return_value,
                                                 guint n_param_values,
                                                 const GValue * param_values,
                                                 gpointer invocation_hint,
                                                 gpointer marshal_data);
static void geary_imap_engine_replay_queue_real_backed_out (GearyImapEngineReplayQueue* self,
                                                     GearyImapEngineReplayOperation* op,
                                                     GError* err);
static void geary_imap_engine_replay_queue_real_backout_failed (GearyImapEngineReplayQueue* self,
                                                         GearyImapEngineReplayOperation* op,
                                                         GError* backout_err);
static void geary_imap_engine_replay_queue_real_completed (GearyImapEngineReplayQueue* self,
                                                    GearyImapEngineReplayOperation* op);
static void geary_imap_engine_replay_queue_real_failed (GearyImapEngineReplayQueue* self,
                                                 GearyImapEngineReplayOperation* op);
static void geary_imap_engine_replay_queue_real_closing (GearyImapEngineReplayQueue* self);
static void geary_imap_engine_replay_queue_real_closed (GearyImapEngineReplayQueue* self);
VALA_EXTERN GearyImapEngineReplayQueue* geary_imap_engine_replay_queue_new (GearyImapEngineMinimalFolder* owner);
VALA_EXTERN GearyImapEngineReplayQueue* geary_imap_engine_replay_queue_construct (GType object_type,
                                                                      GearyImapEngineMinimalFolder* owner);
static void geary_imap_engine_replay_queue_do_replay_local_async (GearyImapEngineReplayQueue* self,
                                                           GAsyncReadyCallback _callback_,
                                                           gpointer _user_data_);
static void geary_imap_engine_replay_queue_do_replay_local_finish (GearyImapEngineReplayQueue* self,
                                                            GAsyncResult* _res_);
static void geary_imap_engine_replay_queue_do_replay_remote_async (GearyImapEngineReplayQueue* self,
                                                            GAsyncReadyCallback _callback_,
                                                            gpointer _user_data_);
static void geary_imap_engine_replay_queue_do_replay_remote_finish (GearyImapEngineReplayQueue* self,
                                                             GAsyncResult* _res_);
VALA_EXTERN gboolean geary_imap_engine_replay_queue_schedule (GearyImapEngineReplayQueue* self,
                                                  GearyImapEngineReplayOperation* op);
static GType geary_imap_engine_replay_queue_close_replay_queue_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
VALA_EXTERN void geary_imap_engine_replay_operation_set_submission_number (GearyImapEngineReplayOperation* self,
                                                               gint64 value);
VALA_EXTERN gboolean geary_imap_engine_replay_queue_schedule_server_notification (GearyImapEngineReplayQueue* self,
                                                                      GearyImapEngineReplayOperation* op);
static gboolean geary_imap_engine_replay_queue_on_notification_timeout (GearyImapEngineReplayQueue* self);
static gboolean _geary_imap_engine_replay_queue_on_notification_timeout_gsource_func (gpointer self);
static void geary_imap_engine_replay_queue_checkpoint_data_free (gpointer _data);
VALA_EXTERN void geary_imap_engine_replay_queue_checkpoint (GearyImapEngineReplayQueue* self,
                                                GCancellable* cancellable,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_);
VALA_EXTERN void geary_imap_engine_replay_queue_checkpoint_finish (GearyImapEngineReplayQueue* self,
                                                       GAsyncResult* _res_,
                                                       GError** error);
static gboolean geary_imap_engine_replay_queue_checkpoint_co (GearyImapEngineReplayQueueCheckpointData* _data_);
static GType geary_imap_engine_replay_queue_wait_operation_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static GearyImapEngineReplayQueueWaitOperation* geary_imap_engine_replay_queue_wait_operation_new (void);
static GearyImapEngineReplayQueueWaitOperation* geary_imap_engine_replay_queue_wait_operation_construct (GType object_type);
VALA_EXTERN void geary_imap_engine_replay_operation_wait_for_ready_async (GearyImapEngineReplayOperation* self,
                                                              GCancellable* cancellable,
                                                              GAsyncReadyCallback _callback_,
                                                              gpointer _user_data_);
VALA_EXTERN void geary_imap_engine_replay_operation_wait_for_ready_finish (GearyImapEngineReplayOperation* self,
                                                               GAsyncResult* _res_,
                                                               GError** error);
static void geary_imap_engine_replay_queue_checkpoint_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_);
VALA_EXTERN void geary_imap_engine_replay_queue_flush_notifications (GearyImapEngineReplayQueue* self);
VALA_EXTERN void geary_imap_engine_replay_queue_notify_remote_removed_position (GearyImapEngineReplayQueue* self,
                                                                    GearyImapSequenceNumber* pos);
static void geary_imap_engine_replay_queue_notify_remote_removed_position_collection (GearyImapEngineReplayQueue* self,
                                                                               GeeCollection* replay_ops,
                                                                               GearyImapEngineReplayOperation* active,
                                                                               GearyImapSequenceNumber* pos);
VALA_EXTERN void geary_imap_engine_replay_operation_notify_remote_removed_position (GearyImapEngineReplayOperation* self,
                                                                        GearyImapSequenceNumber* removed);
VALA_EXTERN GType geary_imap_db_email_identifier_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void geary_imap_engine_replay_queue_notify_remote_removed_ids (GearyImapEngineReplayQueue* self,
                                                               GeeCollection* ids);
static void geary_imap_engine_replay_queue_notify_remote_removed_ids_collection (GearyImapEngineReplayQueue* self,
                                                                          GeeCollection* replay_ops,
                                                                          GearyImapEngineReplayOperation* active,
                                                                          GeeCollection* ids);
VALA_EXTERN void geary_imap_engine_replay_operation_notify_remote_removed_ids (GearyImapEngineReplayOperation* self,
                                                                   GeeCollection* ids);
VALA_EXTERN void geary_imap_engine_replay_queue_get_ids_to_be_remote_removed (GearyImapEngineReplayQueue* self,
                                                                  GeeCollection* ids);
VALA_EXTERN void geary_imap_engine_replay_operation_get_ids_to_be_remote_removed (GearyImapEngineReplayOperation* self,
                                                                      GeeCollection* ids);
static void geary_imap_engine_replay_queue_close_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_engine_replay_queue_close_async (GearyImapEngineReplayQueue* self,
                                                 gboolean flush_pending,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
VALA_EXTERN void geary_imap_engine_replay_queue_close_finish (GearyImapEngineReplayQueue* self,
                                                  GAsyncResult* _res_,
                                                  GError** error);
static gboolean geary_imap_engine_replay_queue_close_async_co (GearyImapEngineReplayQueueCloseAsyncData* _data_);
static void geary_imap_engine_replay_queue_clear_pending_async (GearyImapEngineReplayQueue* self,
                                                         GCancellable* cancellable,
                                                         GAsyncReadyCallback _callback_,
                                                         gpointer _user_data_);
static void geary_imap_engine_replay_queue_clear_pending_finish (GearyImapEngineReplayQueue* self,
                                                          GAsyncResult* _res_);
static void geary_imap_engine_replay_queue_close_async_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_);
static GearyImapEngineReplayQueueCloseReplayQueue* geary_imap_engine_replay_queue_close_replay_queue_new (void);
static GearyImapEngineReplayQueueCloseReplayQueue* geary_imap_engine_replay_queue_close_replay_queue_construct (GType object_type);
VALA_EXTERN gint geary_imap_engine_replay_queue_pending_unread_change (GearyImapEngineReplayQueue* self);
VALA_EXTERN GType geary_imap_engine_send_replay_operation_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_engine_mark_email_get_type (void) G_GNUC_CONST ;
VALA_EXTERN gint geary_imap_engine_mark_email_get_unread_change (GearyImapEngineMarkEmail* self);
static GearyLoggingState* geary_imap_engine_replay_queue_real_to_logging_state (GearyLoggingSource* base);
static void geary_imap_engine_replay_queue_clear_pending_async_data_free (gpointer _data);
static gboolean geary_imap_engine_replay_queue_clear_pending_async_co (GearyImapEngineReplayQueueClearPendingAsyncData* _data_);
VALA_EXTERN void geary_imap_engine_replay_operation_backout_local_async (GearyImapEngineReplayOperation* self,
                                                             GAsyncReadyCallback _callback_,
                                                             gpointer _user_data_);
VALA_EXTERN void geary_imap_engine_replay_operation_backout_local_finish (GearyImapEngineReplayOperation* self,
                                                              GAsyncResult* _res_,
                                                              GError** error);
static void geary_imap_engine_replay_queue_clear_pending_async_ready (GObject* source_object,
                                                               GAsyncResult* _res_,
                                                               gpointer _user_data_);
static void geary_imap_engine_replay_queue_do_replay_local_async_data_free (gpointer _data);
static gboolean geary_imap_engine_replay_queue_do_replay_local_async_co (GearyImapEngineReplayQueueDoReplayLocalAsyncData* _data_);
static void geary_imap_engine_replay_queue_do_replay_local_async_ready (GObject* source_object,
                                                                 GAsyncResult* _res_,
                                                                 gpointer _user_data_);
VALA_EXTERN GType geary_imap_engine_replay_operation_scope_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GearyImapEngineReplayOperationScope geary_imap_engine_replay_operation_get_scope (GearyImapEngineReplayOperation* self);
VALA_EXTERN GType geary_imap_engine_replay_operation_status_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_notify_ready (GearyImapEngineReplayOperation* self,
                                                      GError* err);
VALA_EXTERN gboolean geary_imap_engine_replay_operation_get_notified (GearyImapEngineReplayOperation* self);
VALA_EXTERN GError* geary_imap_engine_replay_operation_get_err (GearyImapEngineReplayOperation* self);
static void geary_imap_engine_replay_queue_do_replay_remote_async_data_free (gpointer _data);
static gboolean geary_imap_engine_replay_queue_do_replay_remote_async_co (GearyImapEngineReplayQueueDoReplayRemoteAsyncData* _data_);
static void geary_imap_engine_replay_queue_do_replay_remote_async_ready (GObject* source_object,
                                                                  GAsyncResult* _res_,
                                                                  gpointer _user_data_);
VALA_EXTERN GType geary_imap_folder_session_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void geary_imap_engine_minimal_folder_claim_remote_session (GearyImapEngineMinimalFolder* self,
                                                            GCancellable* cancellable,
                                                            GAsyncReadyCallback _callback_,
                                                            gpointer _user_data_);
VALA_EXTERN GearyImapFolderSession* geary_imap_engine_minimal_folder_claim_remote_session_finish (GearyImapEngineMinimalFolder* self,
                                                                                      GAsyncResult* _res_,
                                                                                      GError** error);
VALA_EXTERN gint geary_imap_engine_replay_operation_get_remote_retry_count (GearyImapEngineReplayOperation* self);
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 GType geary_imap_engine_replay_operation_on_error_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GearyImapEngineReplayOperationOnError geary_imap_engine_replay_operation_get_on_remote_error (GearyImapEngineReplayOperation* self);
VALA_EXTERN gboolean geary_imap_engine_is_recoverable_failure (GError* err);
VALA_EXTERN void geary_imap_engine_replay_operation_set_remote_retry_count (GearyImapEngineReplayOperation* self,
                                                                gint value);
VALA_EXTERN gboolean geary_imap_engine_is_remote_error (GError* err);
VALA_EXTERN gchar* geary_imap_engine_replay_operation_describe_state (GearyImapEngineReplayOperation* self);
VALA_EXTERN GearyImapEngineReplayOperation* geary_imap_engine_replay_operation_construct (GType object_type,
                                                                              const gchar* name,
                                                                              GearyImapEngineReplayOperationScope scope,
                                                                              GearyImapEngineReplayOperationOnError on_remote_error);
static void geary_imap_engine_replay_queue_close_replay_queue_real_replay_local_async_data_free (gpointer _data);
static void geary_imap_engine_replay_queue_close_replay_queue_real_replay_local_async (GearyImapEngineReplayOperation* base,
                                                                                GAsyncReadyCallback _callback_,
                                                                                gpointer _user_data_);
static gboolean geary_imap_engine_replay_queue_close_replay_queue_real_replay_local_async_co (GearyImapEngineReplayQueueCloseReplayQueueReplayLocalAsyncData* _data_);
static void geary_imap_engine_replay_queue_close_replay_queue_real_replay_remote_async_data_free (gpointer _data);
static void geary_imap_engine_replay_queue_close_replay_queue_real_replay_remote_async (GearyImapEngineReplayOperation* base,
                                                                                 GearyImapFolderSession* remote,
                                                                                 GAsyncReadyCallback _callback_,
                                                                                 gpointer _user_data_);
static gboolean geary_imap_engine_replay_queue_close_replay_queue_real_replay_remote_async_co (GearyImapEngineReplayQueueCloseReplayQueueReplayRemoteAsyncData* _data_);
static gchar* geary_imap_engine_replay_queue_close_replay_queue_real_describe_state (GearyImapEngineReplayOperation* base);
static void geary_imap_engine_replay_queue_close_replay_queue_finalize (GObject * obj);
static GType geary_imap_engine_replay_queue_close_replay_queue_get_type_once (void);
static void geary_imap_engine_replay_queue_wait_operation_real_replay_local_async_data_free (gpointer _data);
static void geary_imap_engine_replay_queue_wait_operation_real_replay_local_async (GearyImapEngineReplayOperation* base,
                                                                            GAsyncReadyCallback _callback_,
                                                                            gpointer _user_data_);
static gboolean geary_imap_engine_replay_queue_wait_operation_real_replay_local_async_co (GearyImapEngineReplayQueueWaitOperationReplayLocalAsyncData* _data_);
static void geary_imap_engine_replay_queue_wait_operation_real_replay_remote_async_data_free (gpointer _data);
static void geary_imap_engine_replay_queue_wait_operation_real_replay_remote_async (GearyImapEngineReplayOperation* base,
                                                                             GearyImapFolderSession* remote,
                                                                             GAsyncReadyCallback _callback_,
                                                                             gpointer _user_data_);
static gboolean geary_imap_engine_replay_queue_wait_operation_real_replay_remote_async_co (GearyImapEngineReplayQueueWaitOperationReplayRemoteAsyncData* _data_);
static gchar* geary_imap_engine_replay_queue_wait_operation_real_describe_state (GearyImapEngineReplayOperation* base);
static GType geary_imap_engine_replay_queue_wait_operation_get_type_once (void);
static void geary_imap_engine_replay_queue_finalize (GObject * obj);
static GType geary_imap_engine_replay_queue_get_type_once (void);
static void _vala_geary_imap_engine_replay_queue_get_property (GObject * object,
                                                        guint property_id,
                                                        GValue * value,
                                                        GParamSpec * pspec);

static inline gpointer
geary_imap_engine_replay_queue_get_instance_private (GearyImapEngineReplayQueue* self)
{
	return G_STRUCT_MEMBER_P (self, GearyImapEngineReplayQueue_private_offset);
}

 G_GNUC_NO_INLINE static GType
geary_imap_engine_replay_queue_state_get_type_once (void)
{
	static const GEnumValue values[] = {{GEARY_IMAP_ENGINE_REPLAY_QUEUE_STATE_OPEN, "GEARY_IMAP_ENGINE_REPLAY_QUEUE_STATE_OPEN", "open"}, {GEARY_IMAP_ENGINE_REPLAY_QUEUE_STATE_CLOSING, "GEARY_IMAP_ENGINE_REPLAY_QUEUE_STATE_CLOSING", "closing"}, {GEARY_IMAP_ENGINE_REPLAY_QUEUE_STATE_CLOSED, "GEARY_IMAP_ENGINE_REPLAY_QUEUE_STATE_CLOSED", "closed"}, {0, NULL, NULL}};
	GType geary_imap_engine_replay_queue_state_type_id;
	geary_imap_engine_replay_queue_state_type_id = g_enum_register_static ("GearyImapEngineReplayQueueState", values);
	return geary_imap_engine_replay_queue_state_type_id;
}

static GType
geary_imap_engine_replay_queue_state_get_type (void)
{
	static gsize geary_imap_engine_replay_queue_state_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_engine_replay_queue_state_type_id__once)) {
		GType geary_imap_engine_replay_queue_state_type_id;
		geary_imap_engine_replay_queue_state_type_id = geary_imap_engine_replay_queue_state_get_type_once ();
		g_once_init_leave (&geary_imap_engine_replay_queue_state_type_id__once, geary_imap_engine_replay_queue_state_type_id);
	}
	return geary_imap_engine_replay_queue_state_type_id__once;
}

gint
geary_imap_engine_replay_queue_get_local_count (GearyImapEngineReplayQueue* self)
{
	gint result;
	GearyNonblockingQueue* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_QUEUE (self), -1);
	_tmp0_ = self->priv->local_queue;
	_tmp1_ = geary_nonblocking_queue_get_size (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

gint
geary_imap_engine_replay_queue_get_remote_count (GearyImapEngineReplayQueue* self)
{
	gint result;
	GearyNonblockingQueue* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_QUEUE (self), -1);
	_tmp0_ = self->priv->remote_queue;
	_tmp1_ = geary_nonblocking_queue_get_size (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

static const gchar*
geary_imap_engine_replay_queue_real_get_logging_domain (GearyLoggingSource* base)
{
	const gchar* result;
	GearyImapEngineReplayQueue* self;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, GearyImapEngineReplayQueue);
	result = GEARY_IMAP_CLIENT_SERVICE_REPLAY_QUEUE_LOGGING_DOMAIN;
	return result;
}

static GearyLoggingSource*
geary_imap_engine_replay_queue_real_get_logging_parent (GearyLoggingSource* base)
{
	GearyLoggingSource* result;
	GearyImapEngineReplayQueue* self;
	GearyImapEngineMinimalFolder* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, GearyImapEngineReplayQueue);
	_tmp0_ = self->priv->owner;
	result = G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource);
	return result;
}

static void
geary_imap_engine_replay_queue_real_scheduled (GearyImapEngineReplayQueue* self,
                                               GearyImapEngineReplayOperation* op)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_OPERATION (op));
	_tmp0_ = geary_imap_engine_replay_operation_to_string (op);
	_tmp1_ = _tmp0_;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Scheduled: %s", _tmp1_);
	_g_free0 (_tmp1_);
}

static void
geary_imap_engine_replay_queue_real_locally_executing (GearyImapEngineReplayQueue* self,
                                                       GearyImapEngineReplayOperation* op)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_OPERATION (op));
	_tmp0_ = geary_imap_engine_replay_operation_to_string (op);
	_tmp1_ = _tmp0_;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Locally-executing: %s", _tmp1_);
	_g_free0 (_tmp1_);
}

static gchar*
bool_to_string (gboolean self)
{
	gchar* result;
	if (self) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup ("true");
		result = _tmp0_;
		return result;
	} else {
		gchar* _tmp1_;
		_tmp1_ = g_strdup ("false");
		result = _tmp1_;
		return result;
	}
}

static void
geary_imap_engine_replay_queue_real_locally_executed (GearyImapEngineReplayQueue* self,
                                                      GearyImapEngineReplayOperation* op,
                                                      gboolean continuing)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_OPERATION (op));
	_tmp0_ = geary_imap_engine_replay_operation_to_string (op);
	_tmp1_ = _tmp0_;
	_tmp2_ = bool_to_string (continuing);
	_tmp3_ = _tmp2_;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Locally-executed: %s continuing=%s", _tmp1_, _tmp3_);
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
}

static void
g_cclosure_user_marshal_VOID__OBJECT_BOOLEAN (GClosure * closure,
                                              GValue * return_value,
                                              guint n_param_values,
                                              const GValue * param_values,
                                              gpointer invocation_hint,
                                              gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__OBJECT_BOOLEAN) (gpointer data1, gpointer arg_1, gboolean arg_2, gpointer data2);
	register GMarshalFunc_VOID__OBJECT_BOOLEAN callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__OBJECT_BOOLEAN) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_object (param_values + 1), g_value_get_boolean (param_values + 2), data2);
}

static void
geary_imap_engine_replay_queue_real_remotely_executing (GearyImapEngineReplayQueue* self,
                                                        GearyImapEngineReplayOperation* op)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_OPERATION (op));
	_tmp0_ = geary_imap_engine_replay_operation_to_string (op);
	_tmp1_ = _tmp0_;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Remotely-executing: %s", _tmp1_);
	_g_free0 (_tmp1_);
}

static void
geary_imap_engine_replay_queue_real_remotely_executed (GearyImapEngineReplayQueue* self,
                                                       GearyImapEngineReplayOperation* op)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_OPERATION (op));
	_tmp0_ = geary_imap_engine_replay_operation_to_string (op);
	_tmp1_ = _tmp0_;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Remotely-executed: %s", _tmp1_);
	_g_free0 (_tmp1_);
}

static void
geary_imap_engine_replay_queue_real_backing_out (GearyImapEngineReplayQueue* self,
                                                 GearyImapEngineReplayOperation* op,
                                                 GError* err)
{
	const gchar* _tmp0_ = NULL;
	gchar* _tmp2_;
	gchar* _tmp3_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_OPERATION (op));
	if (err != NULL) {
		const gchar* _tmp1_;
		_tmp1_ = err->message;
		_tmp0_ = _tmp1_;
	} else {
		_tmp0_ = "(null)";
	}
	_tmp2_ = geary_imap_engine_replay_operation_to_string (op);
	_tmp3_ = _tmp2_;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Backout-out: %s err=%s", _tmp3_, _tmp0_);
	_g_free0 (_tmp3_);
}

static void
g_cclosure_user_marshal_VOID__OBJECT_BOXED (GClosure * closure,
                                            GValue * return_value,
                                            guint n_param_values,
                                            const GValue * param_values,
                                            gpointer invocation_hint,
                                            gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__OBJECT_BOXED) (gpointer data1, gpointer arg_1, gpointer arg_2, gpointer data2);
	register GMarshalFunc_VOID__OBJECT_BOXED callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__OBJECT_BOXED) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_object (param_values + 1), g_value_get_boxed (param_values + 2), data2);
}

static void
geary_imap_engine_replay_queue_real_backed_out (GearyImapEngineReplayQueue* self,
                                                GearyImapEngineReplayOperation* op,
                                                GError* err)
{
	const gchar* _tmp0_ = NULL;
	gchar* _tmp2_;
	gchar* _tmp3_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_OPERATION (op));
	if (err != NULL) {
		const gchar* _tmp1_;
		_tmp1_ = err->message;
		_tmp0_ = _tmp1_;
	} else {
		_tmp0_ = "(null)";
	}
	_tmp2_ = geary_imap_engine_replay_operation_to_string (op);
	_tmp3_ = _tmp2_;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Backed-out: %s err=%s", _tmp3_, _tmp0_);
	_g_free0 (_tmp3_);
}

static void
geary_imap_engine_replay_queue_real_backout_failed (GearyImapEngineReplayQueue* self,
                                                    GearyImapEngineReplayOperation* op,
                                                    GError* backout_err)
{
	const gchar* _tmp0_ = NULL;
	gchar* _tmp2_;
	gchar* _tmp3_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_OPERATION (op));
	if (backout_err != NULL) {
		const gchar* _tmp1_;
		_tmp1_ = backout_err->message;
		_tmp0_ = _tmp1_;
	} else {
		_tmp0_ = "(null)";
	}
	_tmp2_ = geary_imap_engine_replay_operation_to_string (op);
	_tmp3_ = _tmp2_;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Backout-failed: %s err=%s", _tmp3_, _tmp0_);
	_g_free0 (_tmp3_);
}

static void
geary_imap_engine_replay_queue_real_completed (GearyImapEngineReplayQueue* self,
                                               GearyImapEngineReplayOperation* op)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_OPERATION (op));
	_tmp0_ = geary_imap_engine_replay_operation_to_string (op);
	_tmp1_ = _tmp0_;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Completed: %s", _tmp1_);
	_g_free0 (_tmp1_);
}

static void
geary_imap_engine_replay_queue_real_failed (GearyImapEngineReplayQueue* self,
                                            GearyImapEngineReplayOperation* op)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_OPERATION (op));
	_tmp0_ = geary_imap_engine_replay_operation_to_string (op);
	_tmp1_ = _tmp0_;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Failed: %s", _tmp1_);
	_g_free0 (_tmp1_);
}

static void
geary_imap_engine_replay_queue_real_closing (GearyImapEngineReplayQueue* self)
{
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Closing");
}

static void
geary_imap_engine_replay_queue_real_closed (GearyImapEngineReplayQueue* self)
{
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Closed");
}

/**
     * ReplayQueue accepts a NonblockingReportingSemaphore<bool> which, when signaled, returns
     * true if the remote folder is ready and open, false if not (closing or closed), and
     * throws an Error if the semaphore has failed.  ReplayQueue will wait on this semaphore for
     * each ReplayOperation waiting to perform a remote operation, cancelling it if the remote
     * folder is not ready.
     */
GearyImapEngineReplayQueue*
geary_imap_engine_replay_queue_construct (GType object_type,
                                          GearyImapEngineMinimalFolder* owner)
{
	GearyImapEngineReplayQueue * self = NULL;
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_MINIMAL_FOLDER (owner), NULL);
	self = (GearyImapEngineReplayQueue*) geary_base_object_construct (object_type);
	self->priv->owner = owner;
	geary_imap_engine_replay_queue_do_replay_local_async (self, NULL, NULL);
	geary_imap_engine_replay_queue_do_replay_remote_async (self, NULL, NULL);
	return self;
}

GearyImapEngineReplayQueue*
geary_imap_engine_replay_queue_new (GearyImapEngineMinimalFolder* owner)
{
	return geary_imap_engine_replay_queue_construct (GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, owner);
}

/**
     * Returns false if the operation was not schedule (queue already closed).
     */
gboolean
geary_imap_engine_replay_queue_schedule (GearyImapEngineReplayQueue* self,
                                         GearyImapEngineReplayOperation* op)
{
	gboolean _tmp0_ = FALSE;
	gint64 _tmp5_;
	gboolean is_scheduled = FALSE;
	GearyNonblockingQueue* _tmp6_;
	gboolean result;
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_QUEUE (self), FALSE);
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_OPERATION (op), FALSE);
	if (self->priv->state != GEARY_IMAP_ENGINE_REPLAY_QUEUE_STATE_OPEN) {
		_tmp0_ = !GEARY_IMAP_ENGINE_REPLAY_QUEUE_IS_CLOSE_REPLAY_QUEUE (op);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gchar* _tmp1_;
		gchar* _tmp2_;
		gchar* _tmp3_;
		gchar* _tmp4_;
		_tmp1_ = geary_imap_engine_replay_operation_to_string (op);
		_tmp2_ = _tmp1_;
		_tmp3_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
		_tmp4_ = _tmp3_;
		geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Unable to schedule replay operation %s on %s: replay queue closed", _tmp2_, _tmp4_);
		_g_free0 (_tmp4_);
		_g_free0 (_tmp2_);
		result = FALSE;
		return result;
	}
	_tmp5_ = self->priv->next_submission_number;
	self->priv->next_submission_number = _tmp5_ + 1;
	geary_imap_engine_replay_operation_set_submission_number (op, _tmp5_);
	_tmp6_ = self->priv->local_queue;
	is_scheduled = geary_nonblocking_queue_send (_tmp6_, op);
	if (is_scheduled) {
		g_signal_emit (self, geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_SCHEDULED_SIGNAL], 0, op);
	}
	result = is_scheduled;
	return result;
}

/**
     * Schedules a ReplayOperation created due to a server notification.
     *
     * All unsolicited server data uses positional addressing, so it's possible for an EXISTS
     * (append) to arrive followed by one or more EXPUNGEs (removes), meaning that the first
     * append's position has shifted downward.  Without a pause, Geary will immediately issue a
     * FETCH on that position, which no longer exists on the server.
     *
     * There is no signal in IMAP for the server to say "no more notifications arriving", hence a
     * timer must be used.
     *
     * Server notifications can arrive with significant time lapses between then (i.e.
     * up to 250ms) and back-to-back EXPUNGEs and EXISTs have serious affects on positional
     * addressing, ReplayQueue will store them for a period of time without adding them to the
     * queues.  When they stop arriving, it will enqueue them in order for processing.
     *
     * In particular, notify_remote_removed_position() should be called ''before'' adding the
     * ReplayRemoval operation, otherwise its own notification method will be called (making it
     * look like it was removed twice).
     *
     * Returns false if the operation was not schedule (queue already closed).
     */
static gboolean
_geary_imap_engine_replay_queue_on_notification_timeout_gsource_func (gpointer self)
{
	gboolean result;
	result = geary_imap_engine_replay_queue_on_notification_timeout ((GearyImapEngineReplayQueue*) self);
	return result;
}

gboolean
geary_imap_engine_replay_queue_schedule_server_notification (GearyImapEngineReplayQueue* self,
                                                             GearyImapEngineReplayOperation* op)
{
	GeeArrayList* _tmp4_;
	GearySchedulerScheduled* _tmp5_;
	GearySchedulerScheduled* _tmp7_;
	gboolean result;
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_QUEUE (self), FALSE);
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_OPERATION (op), FALSE);
	if (self->priv->state != GEARY_IMAP_ENGINE_REPLAY_QUEUE_STATE_OPEN) {
		gchar* _tmp0_;
		gchar* _tmp1_;
		gchar* _tmp2_;
		gchar* _tmp3_;
		_tmp0_ = geary_imap_engine_replay_operation_to_string (op);
		_tmp1_ = _tmp0_;
		_tmp2_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
		_tmp3_ = _tmp2_;
		geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Unable to schedule notification operation %s on %s: replay queue close" \
"d", _tmp1_, _tmp3_);
		_g_free0 (_tmp3_);
		_g_free0 (_tmp1_);
		result = FALSE;
		return result;
	}
	_tmp4_ = self->priv->notification_queue;
	gee_abstract_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection), op);
	_tmp5_ = self->priv->notification_timer;
	if (_tmp5_ != NULL) {
		GearySchedulerScheduled* _tmp6_;
		_tmp6_ = self->priv->notification_timer;
		geary_scheduler_scheduled_cancel (_tmp6_);
	}
	_tmp7_ = geary_scheduler_after_msec ((guint) GEARY_IMAP_ENGINE_REPLAY_QUEUE_NOTIFICATION_QUEUE_WAIT_MSEC, _geary_imap_engine_replay_queue_on_notification_timeout_gsource_func, self, G_PRIORITY_DEFAULT);
	_g_object_unref0 (self->priv->notification_timer);
	self->priv->notification_timer = _tmp7_;
	result = TRUE;
	return result;
}

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

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

void
geary_imap_engine_replay_queue_checkpoint (GearyImapEngineReplayQueue* self,
                                           GCancellable* cancellable,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_)
{
	GearyImapEngineReplayQueueCheckpointData* _data_;
	GearyImapEngineReplayQueue* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_QUEUE (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapEngineReplayQueueCheckpointData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_engine_replay_queue_checkpoint_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_engine_replay_queue_checkpoint_co (_data_);
}

void
geary_imap_engine_replay_queue_checkpoint_finish (GearyImapEngineReplayQueue* self,
                                                  GAsyncResult* _res_,
                                                  GError** error)
{
	GearyImapEngineReplayQueueCheckpointData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

/** Waits until all pending operations have been processed. */
static void
geary_imap_engine_replay_queue_checkpoint_ready (GObject* source_object,
                                                 GAsyncResult* _res_,
                                                 gpointer _user_data_)
{
	GearyImapEngineReplayQueueCheckpointData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_engine_replay_queue_checkpoint_co (_data_);
}

static gboolean
geary_imap_engine_replay_queue_checkpoint_co (GearyImapEngineReplayQueueCheckpointData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = geary_imap_engine_replay_queue_wait_operation_new ();
	_data_->wait_op = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->wait_op;
	if (geary_imap_engine_replay_queue_schedule (_data_->self, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, GearyImapEngineReplayOperation))) {
		_data_->_tmp2_ = _data_->wait_op;
		_data_->_state_ = 1;
		geary_imap_engine_replay_operation_wait_for_ready_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, GearyImapEngineReplayOperation), _data_->cancellable, geary_imap_engine_replay_queue_checkpoint_ready, _data_);
		return FALSE;
		_state_1:
		geary_imap_engine_replay_operation_wait_for_ready_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, 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_->wait_op);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	} else {
		_data_->_tmp3_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
		_data_->_tmp4_ = _data_->_tmp3_;
		geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Unable to schedule checkpoint op on %s", _data_->_tmp4_);
		_g_free0 (_data_->_tmp4_);
	}
	_g_object_unref0 (_data_->wait_op);
	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;
}

/** Queues for any pending server notifications to be processed. */
void
geary_imap_engine_replay_queue_flush_notifications (GearyImapEngineReplayQueue* self)
{
	GeeArrayList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_QUEUE (self));
	_tmp0_ = self->priv->notification_queue;
	_tmp1_ = gee_abstract_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection));
	_tmp2_ = _tmp1_;
	if (_tmp2_ > 0) {
		GearyImapEngineMinimalFolder* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		GeeArrayList* _tmp6_;
		gint _tmp7_;
		gint _tmp8_;
		GeeArrayList* _tmp23_;
		_tmp3_ = self->priv->owner;
		_tmp4_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
		_tmp5_ = _tmp4_;
		_tmp6_ = self->priv->notification_queue;
		_tmp7_ = gee_abstract_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection));
		_tmp8_ = _tmp7_;
		geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "%s: Scheduling %d held server notification operations", _tmp5_, _tmp8_);
		_g_free0 (_tmp5_);
		{
			GeeArrayList* _notification_op_list = NULL;
			GeeArrayList* _tmp9_;
			gint _notification_op_size = 0;
			GeeArrayList* _tmp10_;
			gint _tmp11_;
			gint _tmp12_;
			gint _notification_op_index = 0;
			_tmp9_ = self->priv->notification_queue;
			_notification_op_list = _tmp9_;
			_tmp10_ = _notification_op_list;
			_tmp11_ = gee_abstract_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp10_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection));
			_tmp12_ = _tmp11_;
			_notification_op_size = _tmp12_;
			_notification_op_index = -1;
			while (TRUE) {
				gint _tmp13_;
				gint _tmp14_;
				GearyImapEngineReplayOperation* notification_op = NULL;
				GeeArrayList* _tmp15_;
				gpointer _tmp16_;
				GearyImapEngineReplayOperation* _tmp17_;
				_notification_op_index = _notification_op_index + 1;
				_tmp13_ = _notification_op_index;
				_tmp14_ = _notification_op_size;
				if (!(_tmp13_ < _tmp14_)) {
					break;
				}
				_tmp15_ = _notification_op_list;
				_tmp16_ = gee_abstract_list_get (G_TYPE_CHECK_INSTANCE_CAST (_tmp15_, GEE_TYPE_ABSTRACT_LIST, GeeAbstractList), _notification_op_index);
				notification_op = (GearyImapEngineReplayOperation*) _tmp16_;
				_tmp17_ = notification_op;
				if (!geary_imap_engine_replay_queue_schedule (self, _tmp17_)) {
					GearyImapEngineReplayOperation* _tmp18_;
					gchar* _tmp19_;
					gchar* _tmp20_;
					gchar* _tmp21_;
					gchar* _tmp22_;
					_tmp18_ = notification_op;
					_tmp19_ = geary_imap_engine_replay_operation_to_string (_tmp18_);
					_tmp20_ = _tmp19_;
					_tmp21_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
					_tmp22_ = _tmp21_;
					geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Unable to schedule notification operation %s on %s", _tmp20_, _tmp22_);
					_g_free0 (_tmp22_);
					_g_free0 (_tmp20_);
				}
				_g_object_unref0 (notification_op);
			}
		}
		_tmp23_ = self->priv->notification_queue;
		gee_abstract_collection_clear (G_TYPE_CHECK_INSTANCE_CAST (_tmp23_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection));
	}
}

static gboolean
geary_imap_engine_replay_queue_on_notification_timeout (GearyImapEngineReplayQueue* self)
{
	gboolean result;
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_QUEUE (self), FALSE);
	geary_imap_engine_replay_queue_flush_notifications (self);
	result = FALSE;
	return result;
}

/**
     * This call gives all enqueued remote replay operations a chance to update their own state
     * due to a message being removed due to an unsolicited notification from the server)
     *
     * @see ReplayOperation.notify_remote_removed_position
     */
void
geary_imap_engine_replay_queue_notify_remote_removed_position (GearyImapEngineReplayQueue* self,
                                                               GearyImapSequenceNumber* pos)
{
	GeeArrayList* _tmp0_;
	GearyNonblockingQueue* _tmp1_;
	GeeCollection* _tmp2_;
	GeeCollection* _tmp3_;
	GearyImapEngineReplayOperation* _tmp4_;
	GearyNonblockingQueue* _tmp5_;
	GeeCollection* _tmp6_;
	GeeCollection* _tmp7_;
	GearyImapEngineReplayOperation* _tmp8_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_QUEUE (self));
	g_return_if_fail (GEARY_IMAP_IS_SEQUENCE_NUMBER (pos));
	_tmp0_ = self->priv->notification_queue;
	geary_imap_engine_replay_queue_notify_remote_removed_position_collection (self, G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEE_TYPE_COLLECTION, GeeCollection), NULL, pos);
	_tmp1_ = self->priv->local_queue;
	_tmp2_ = geary_nonblocking_queue_get_all (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = self->priv->local_op_active;
	geary_imap_engine_replay_queue_notify_remote_removed_position_collection (self, _tmp3_, _tmp4_, pos);
	_g_object_unref0 (_tmp3_);
	_tmp5_ = self->priv->remote_queue;
	_tmp6_ = geary_nonblocking_queue_get_all (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = self->priv->remote_op_active;
	geary_imap_engine_replay_queue_notify_remote_removed_position_collection (self, _tmp7_, _tmp8_, pos);
	_g_object_unref0 (_tmp7_);
}

static void
geary_imap_engine_replay_queue_notify_remote_removed_position_collection (GearyImapEngineReplayQueue* self,
                                                                          GeeCollection* replay_ops,
                                                                          GearyImapEngineReplayOperation* active,
                                                                          GearyImapSequenceNumber* pos)
{
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_QUEUE (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (replay_ops, GEE_TYPE_COLLECTION));
	g_return_if_fail ((active == NULL) || GEARY_IMAP_ENGINE_IS_REPLAY_OPERATION (active));
	g_return_if_fail (GEARY_IMAP_IS_SEQUENCE_NUMBER (pos));
	{
		GeeIterator* _replay_op_it = NULL;
		GeeIterator* _tmp0_;
		_tmp0_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (replay_ops, GEE_TYPE_ITERABLE, GeeIterable));
		_replay_op_it = _tmp0_;
		while (TRUE) {
			GeeIterator* _tmp1_;
			GearyImapEngineReplayOperation* replay_op = NULL;
			GeeIterator* _tmp2_;
			gpointer _tmp3_;
			GearyImapEngineReplayOperation* _tmp4_;
			_tmp1_ = _replay_op_it;
			if (!gee_iterator_next (_tmp1_)) {
				break;
			}
			_tmp2_ = _replay_op_it;
			_tmp3_ = gee_iterator_get (_tmp2_);
			replay_op = (GearyImapEngineReplayOperation*) _tmp3_;
			_tmp4_ = replay_op;
			geary_imap_engine_replay_operation_notify_remote_removed_position (_tmp4_, pos);
			_g_object_unref0 (replay_op);
		}
		_g_object_unref0 (_replay_op_it);
	}
	if (active != NULL) {
		geary_imap_engine_replay_operation_notify_remote_removed_position (active, pos);
	}
}

/**
     * This call gives all enqueued remote replay operations a chance to update their own state
     * due to a message being removed (either during normalization or an unsolicited notification
     * from the server)
     *
     * @see ReplayOperation.notify_remote_removed_ids
     */
void
geary_imap_engine_replay_queue_notify_remote_removed_ids (GearyImapEngineReplayQueue* self,
                                                          GeeCollection* ids)
{
	GeeArrayList* _tmp0_;
	GearyNonblockingQueue* _tmp1_;
	GeeCollection* _tmp2_;
	GeeCollection* _tmp3_;
	GearyImapEngineReplayOperation* _tmp4_;
	GearyNonblockingQueue* _tmp5_;
	GeeCollection* _tmp6_;
	GeeCollection* _tmp7_;
	GearyImapEngineReplayOperation* _tmp8_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_QUEUE (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION));
	_tmp0_ = self->priv->notification_queue;
	geary_imap_engine_replay_queue_notify_remote_removed_ids_collection (self, G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEE_TYPE_COLLECTION, GeeCollection), NULL, ids);
	_tmp1_ = self->priv->local_queue;
	_tmp2_ = geary_nonblocking_queue_get_all (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = self->priv->local_op_active;
	geary_imap_engine_replay_queue_notify_remote_removed_ids_collection (self, _tmp3_, _tmp4_, ids);
	_g_object_unref0 (_tmp3_);
	_tmp5_ = self->priv->remote_queue;
	_tmp6_ = geary_nonblocking_queue_get_all (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = self->priv->remote_op_active;
	geary_imap_engine_replay_queue_notify_remote_removed_ids_collection (self, _tmp7_, _tmp8_, ids);
	_g_object_unref0 (_tmp7_);
}

static void
geary_imap_engine_replay_queue_notify_remote_removed_ids_collection (GearyImapEngineReplayQueue* self,
                                                                     GeeCollection* replay_ops,
                                                                     GearyImapEngineReplayOperation* active,
                                                                     GeeCollection* ids)
{
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_QUEUE (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (replay_ops, GEE_TYPE_COLLECTION));
	g_return_if_fail ((active == NULL) || GEARY_IMAP_ENGINE_IS_REPLAY_OPERATION (active));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION));
	{
		GeeIterator* _replay_op_it = NULL;
		GeeIterator* _tmp0_;
		_tmp0_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (replay_ops, GEE_TYPE_ITERABLE, GeeIterable));
		_replay_op_it = _tmp0_;
		while (TRUE) {
			GeeIterator* _tmp1_;
			GearyImapEngineReplayOperation* replay_op = NULL;
			GeeIterator* _tmp2_;
			gpointer _tmp3_;
			GearyImapEngineReplayOperation* _tmp4_;
			_tmp1_ = _replay_op_it;
			if (!gee_iterator_next (_tmp1_)) {
				break;
			}
			_tmp2_ = _replay_op_it;
			_tmp3_ = gee_iterator_get (_tmp2_);
			replay_op = (GearyImapEngineReplayOperation*) _tmp3_;
			_tmp4_ = replay_op;
			geary_imap_engine_replay_operation_notify_remote_removed_ids (_tmp4_, ids);
			_g_object_unref0 (replay_op);
		}
		_g_object_unref0 (_replay_op_it);
	}
	if (active != NULL) {
		geary_imap_engine_replay_operation_notify_remote_removed_ids (active, ids);
	}
}

/**
     * Returns all ImapDb.EmailIdentifiers for enqueued ReplayOperations waiting for
     * replay_remote_async() that are planning to be removed on the server.
     */
void
geary_imap_engine_replay_queue_get_ids_to_be_remote_removed (GearyImapEngineReplayQueue* self,
                                                             GeeCollection* ids)
{
	GearyImapEngineReplayOperation* _tmp9_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_QUEUE (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION));
	{
		GeeIterator* _replay_op_it = NULL;
		GearyNonblockingQueue* _tmp0_;
		GeeCollection* _tmp1_;
		GeeCollection* _tmp2_;
		GeeIterator* _tmp3_;
		GeeIterator* _tmp4_;
		_tmp0_ = self->priv->remote_queue;
		_tmp1_ = geary_nonblocking_queue_get_all (_tmp0_);
		_tmp2_ = _tmp1_;
		_tmp3_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, GEE_TYPE_ITERABLE, GeeIterable));
		_tmp4_ = _tmp3_;
		_g_object_unref0 (_tmp2_);
		_replay_op_it = _tmp4_;
		while (TRUE) {
			GeeIterator* _tmp5_;
			GearyImapEngineReplayOperation* replay_op = NULL;
			GeeIterator* _tmp6_;
			gpointer _tmp7_;
			GearyImapEngineReplayOperation* _tmp8_;
			_tmp5_ = _replay_op_it;
			if (!gee_iterator_next (_tmp5_)) {
				break;
			}
			_tmp6_ = _replay_op_it;
			_tmp7_ = gee_iterator_get (_tmp6_);
			replay_op = (GearyImapEngineReplayOperation*) _tmp7_;
			_tmp8_ = replay_op;
			geary_imap_engine_replay_operation_get_ids_to_be_remote_removed (_tmp8_, ids);
			_g_object_unref0 (replay_op);
		}
		_g_object_unref0 (_replay_op_it);
	}
	_tmp9_ = self->priv->remote_op_active;
	if (_tmp9_ != NULL) {
		GearyImapEngineReplayOperation* _tmp10_;
		_tmp10_ = self->priv->remote_op_active;
		geary_imap_engine_replay_operation_get_ids_to_be_remote_removed (_tmp10_, ids);
	}
}

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

void
geary_imap_engine_replay_queue_close_async (GearyImapEngineReplayQueue* self,
                                            gboolean flush_pending,
                                            GCancellable* cancellable,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_)
{
	GearyImapEngineReplayQueueCloseAsyncData* _data_;
	GearyImapEngineReplayQueue* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_QUEUE (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapEngineReplayQueueCloseAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_engine_replay_queue_close_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->flush_pending = flush_pending;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_engine_replay_queue_close_async_co (_data_);
}

void
geary_imap_engine_replay_queue_close_finish (GearyImapEngineReplayQueue* self,
                                             GAsyncResult* _res_,
                                             GError** error)
{
	GearyImapEngineReplayQueueCloseAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

/**
     * Closes the {@link ReplayQueue}.
     *
     * If flush_pending is false, outstanding operations are cancelled.  If a {@link ReplayOperation}
     * has executed locally and is waiting to execute remotely, it will be backed out.
     *
     * Otherwise, all outstanding operations are permitted to execute, but no new ones may be
     * scheduled.
     *
     * A ReplayQueue cannot be re-opened.
     */
static void
geary_imap_engine_replay_queue_close_async_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_)
{
	GearyImapEngineReplayQueueCloseAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_engine_replay_queue_close_async_co (_data_);
}

static gboolean
geary_imap_engine_replay_queue_close_async_co (GearyImapEngineReplayQueueCloseAsyncData* _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:
	if (_data_->self->priv->state != GEARY_IMAP_ENGINE_REPLAY_QUEUE_STATE_OPEN) {
		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->notification_timer;
	if (_data_->_tmp0_ != NULL) {
		_data_->_tmp1_ = _data_->self->priv->notification_timer;
		geary_scheduler_scheduled_cancel (_data_->_tmp1_);
	}
	if (_data_->flush_pending) {
		geary_imap_engine_replay_queue_on_notification_timeout (_data_->self);
	}
	_data_->self->priv->state = GEARY_IMAP_ENGINE_REPLAY_QUEUE_STATE_CLOSING;
	g_signal_emit (_data_->self, geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_CLOSING_SIGNAL], 0);
	if (!_data_->flush_pending) {
		_data_->_tmp2_ = _data_->self->priv->remote_wait_cancellable;
		g_cancellable_cancel (_data_->_tmp2_);
		_data_->_state_ = 1;
		geary_imap_engine_replay_queue_clear_pending_async (_data_->self, _data_->cancellable, geary_imap_engine_replay_queue_close_async_ready, _data_);
		return FALSE;
		_state_1:
		geary_imap_engine_replay_queue_clear_pending_finish (_data_->self, _data_->_res_);
	}
	_data_->_tmp3_ = geary_imap_engine_replay_queue_close_replay_queue_new ();
	_data_->close_op = _data_->_tmp3_;
	_data_->_tmp4_ = _data_->close_op;
	_data_->is_scheduled = geary_imap_engine_replay_queue_schedule (_data_->self, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp4_, GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, GearyImapEngineReplayOperation));
	_vala_assert (_data_->is_scheduled, "is_scheduled");
	_data_->_tmp5_ = _data_->close_op;
	_data_->_state_ = 2;
	geary_imap_engine_replay_operation_wait_for_ready_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp5_, GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, GearyImapEngineReplayOperation), _data_->cancellable, geary_imap_engine_replay_queue_close_async_ready, _data_);
	return FALSE;
	_state_2:
	geary_imap_engine_replay_operation_wait_for_ready_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp5_, 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_->close_op);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->self->priv->state = GEARY_IMAP_ENGINE_REPLAY_QUEUE_STATE_CLOSED;
	g_signal_emit (_data_->self, geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_CLOSED_SIGNAL], 0);
	_g_object_unref0 (_data_->close_op);
	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;
}

/**
     * Get pending unread change.
     */
gint
geary_imap_engine_replay_queue_pending_unread_change (GearyImapEngineReplayQueue* self)
{
	gint unread_change = 0;
	GeeCollection* replay_ops = NULL;
	GearyNonblockingQueue* _tmp0_;
	GeeCollection* _tmp1_;
	GeeCollection* _tmp2_;
	GearyIterable* _tmp3_;
	GearyIterable* _tmp4_;
	GeeArrayList* _tmp5_;
	GeeCollection* _tmp6_;
	GeeCollection* _tmp7_;
	GearyImapEngineReplayOperation* _tmp8_;
	gint result;
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_QUEUE (self), -1);
	unread_change = 0;
	_tmp0_ = self->priv->remote_queue;
	_tmp1_ = geary_nonblocking_queue_get_all (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = geary_traverse (GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, GEE_TYPE_ITERABLE, GeeIterable));
	_tmp4_ = _tmp3_;
	_tmp5_ = geary_iterable_to_array_list (_tmp4_, NULL, NULL, NULL);
	_tmp6_ = G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, GEE_TYPE_COLLECTION, GeeCollection);
	_g_object_unref0 (_tmp4_);
	_g_object_unref0 (_tmp2_);
	replay_ops = _tmp6_;
	_tmp7_ = replay_ops;
	_tmp8_ = self->priv->remote_op_active;
	gee_collection_add (_tmp7_, _tmp8_);
	{
		GeeIterator* _op_it = NULL;
		GeeCollection* _tmp9_;
		GeeIterator* _tmp10_;
		_tmp9_ = replay_ops;
		_tmp10_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp9_, GEE_TYPE_ITERABLE, GeeIterable));
		_op_it = _tmp10_;
		while (TRUE) {
			GeeIterator* _tmp11_;
			GearyImapEngineReplayOperation* op = NULL;
			GeeIterator* _tmp12_;
			gpointer _tmp13_;
			GearyImapEngineReplayOperation* _tmp14_;
			_tmp11_ = _op_it;
			if (!gee_iterator_next (_tmp11_)) {
				break;
			}
			_tmp12_ = _op_it;
			_tmp13_ = gee_iterator_get (_tmp12_);
			op = (GearyImapEngineReplayOperation*) _tmp13_;
			_tmp14_ = op;
			if (GEARY_IMAP_ENGINE_IS_MARK_EMAIL (_tmp14_)) {
				GearyImapEngineMarkEmail* mark_email = NULL;
				GearyImapEngineReplayOperation* _tmp15_;
				GearyImapEngineMarkEmail* _tmp16_;
				GearyImapEngineMarkEmail* _tmp17_;
				gint _tmp18_;
				gint _tmp19_;
				_tmp15_ = op;
				_tmp16_ = _g_object_ref0 (GEARY_IMAP_ENGINE_IS_MARK_EMAIL (_tmp15_) ? ((GearyImapEngineMarkEmail*) _tmp15_) : NULL);
				mark_email = _tmp16_;
				_tmp17_ = mark_email;
				_tmp18_ = geary_imap_engine_mark_email_get_unread_change (_tmp17_);
				_tmp19_ = _tmp18_;
				unread_change += _tmp19_;
				_g_object_unref0 (mark_email);
			}
			_g_object_unref0 (op);
		}
		_g_object_unref0 (_op_it);
	}
	result = unread_change;
	_g_object_unref0 (replay_ops);
	return result;
}

/** {@inheritDoc} */
static GearyLoggingState*
geary_imap_engine_replay_queue_real_to_logging_state (GearyLoggingSource* base)
{
	GearyImapEngineReplayQueue * self;
	GeeArrayList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	GearyNonblockingQueue* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	GearyImapEngineReplayOperation* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	GearyNonblockingQueue* _tmp9_;
	gint _tmp10_;
	gint _tmp11_;
	GearyImapEngineReplayOperation* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	GearyLoggingState* _tmp15_;
	GearyLoggingState* _tmp16_;
	GearyLoggingState* result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, GearyImapEngineReplayQueue);
	_tmp0_ = self->priv->notification_queue;
	_tmp1_ = gee_abstract_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection));
	_tmp2_ = _tmp1_;
	_tmp3_ = self->priv->local_queue;
	_tmp4_ = geary_nonblocking_queue_get_size (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = self->priv->local_op_active;
	_tmp7_ = bool_to_string (_tmp6_ != NULL);
	_tmp8_ = _tmp7_;
	_tmp9_ = self->priv->remote_queue;
	_tmp10_ = geary_nonblocking_queue_get_size (_tmp9_);
	_tmp11_ = _tmp10_;
	_tmp12_ = self->priv->remote_op_active;
	_tmp13_ = bool_to_string (_tmp12_ != NULL);
	_tmp14_ = _tmp13_;
	_tmp15_ = geary_logging_state_new (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "notification=%d local=%d local_active=%s remote=%d remote_active=%s", _tmp2_, _tmp5_, _tmp8_, _tmp11_, _tmp14_);
	_tmp16_ = _tmp15_;
	_g_free0 (_tmp14_);
	_g_free0 (_tmp8_);
	result = _tmp16_;
	return result;
}

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

static void
geary_imap_engine_replay_queue_clear_pending_async (GearyImapEngineReplayQueue* self,
                                                    GCancellable* cancellable,
                                                    GAsyncReadyCallback _callback_,
                                                    gpointer _user_data_)
{
	GearyImapEngineReplayQueueClearPendingAsyncData* _data_;
	GearyImapEngineReplayQueue* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_QUEUE (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapEngineReplayQueueClearPendingAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_engine_replay_queue_clear_pending_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_engine_replay_queue_clear_pending_async_co (_data_);
}

static void
geary_imap_engine_replay_queue_clear_pending_finish (GearyImapEngineReplayQueue* self,
                                                     GAsyncResult* _res_)
{
	GearyImapEngineReplayQueueClearPendingAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return;
	}
}

static void
geary_imap_engine_replay_queue_clear_pending_async_ready (GObject* source_object,
                                                          GAsyncResult* _res_,
                                                          gpointer _user_data_)
{
	GearyImapEngineReplayQueueClearPendingAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_engine_replay_queue_clear_pending_async_co (_data_);
}

static gboolean
geary_imap_engine_replay_queue_clear_pending_async_co (GearyImapEngineReplayQueueClearPendingAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->notification_queue;
	gee_abstract_collection_clear (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection));
	_data_->_tmp1_ = _data_->self->priv->local_queue;
	geary_nonblocking_queue_clear (_data_->_tmp1_);
	_data_->_tmp2_ = gee_array_list_new (GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data_->remote_list = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, GEE_TYPE_LIST, GeeList);
	_data_->_tmp3_ = _data_->remote_list;
	_data_->_tmp4_ = _data_->self->priv->remote_queue;
	_data_->_tmp5_ = geary_nonblocking_queue_get_all (_data_->_tmp4_);
	_data_->_tmp6_ = _data_->_tmp5_;
	gee_collection_add_all (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp3_, GEE_TYPE_COLLECTION, GeeCollection), _data_->_tmp6_);
	_g_object_unref0 (_data_->_tmp6_);
	_data_->_tmp7_ = _data_->self->priv->remote_queue;
	geary_nonblocking_queue_clear (_data_->_tmp7_);
	{
		_data_->_tmp8_ = _data_->remote_list;
		_data_->_op_list = _data_->_tmp8_;
		_data_->_tmp9_ = _data_->_op_list;
		_data_->_tmp10_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp9_, GEE_TYPE_COLLECTION, GeeCollection));
		_data_->_tmp11_ = _data_->_tmp10_;
		_data_->_op_size = _data_->_tmp11_;
		_data_->_op_index = -1;
		while (TRUE) {
			_data_->_op_index = _data_->_op_index + 1;
			_data_->_tmp12_ = _data_->_op_index;
			_data_->_tmp13_ = _data_->_op_size;
			if (!(_data_->_tmp12_ < _data_->_tmp13_)) {
				break;
			}
			_data_->_tmp14_ = _data_->_op_list;
			_data_->_tmp15_ = gee_list_get (_data_->_tmp14_, _data_->_op_index);
			_data_->op = (GearyImapEngineReplayOperation*) _data_->_tmp15_;
			{
				_data_->_tmp16_ = _data_->op;
				_data_->_state_ = 1;
				geary_imap_engine_replay_operation_backout_local_async (_data_->_tmp16_, geary_imap_engine_replay_queue_clear_pending_async_ready, _data_);
				return FALSE;
				_state_1:
				geary_imap_engine_replay_operation_backout_local_finish (_data_->_tmp16_, _data_->_res_, &_data_->_inner_error0_);
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					goto __catch0_g_error;
				}
			}
			goto __finally0;
			__catch0_g_error:
			{
				_data_->err = _data_->_inner_error0_;
				_data_->_inner_error0_ = NULL;
				_data_->_tmp17_ = _data_->op;
				_data_->_tmp18_ = geary_imap_engine_replay_operation_to_string (_data_->_tmp17_);
				_data_->_tmp19_ = _data_->_tmp18_;
				_data_->_tmp20_ = _data_->err;
				_data_->_tmp21_ = _data_->_tmp20_->message;
				geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Error backing out operation %s: %s", _data_->_tmp19_, _data_->_tmp21_);
				_g_free0 (_data_->_tmp19_);
				_g_error_free0 (_data_->err);
			}
			__finally0:
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->op);
				_g_object_unref0 (_data_->remote_list);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
				g_clear_error (&_data_->_inner_error0_);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
			_g_object_unref0 (_data_->op);
		}
	}
	_g_object_unref0 (_data_->remote_list);
	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_replay_queue_do_replay_local_async_data_free (gpointer _data)
{
	GearyImapEngineReplayQueueDoReplayLocalAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapEngineReplayQueueDoReplayLocalAsyncData, _data_);
}

static void
geary_imap_engine_replay_queue_do_replay_local_async (GearyImapEngineReplayQueue* self,
                                                      GAsyncReadyCallback _callback_,
                                                      gpointer _user_data_)
{
	GearyImapEngineReplayQueueDoReplayLocalAsyncData* _data_;
	GearyImapEngineReplayQueue* _tmp0_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_QUEUE (self));
	_data_ = g_slice_new0 (GearyImapEngineReplayQueueDoReplayLocalAsyncData);
	_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_replay_queue_do_replay_local_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	geary_imap_engine_replay_queue_do_replay_local_async_co (_data_);
}

static void
geary_imap_engine_replay_queue_do_replay_local_finish (GearyImapEngineReplayQueue* self,
                                                       GAsyncResult* _res_)
{
	GearyImapEngineReplayQueueDoReplayLocalAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
geary_imap_engine_replay_queue_do_replay_local_async_ready (GObject* source_object,
                                                            GAsyncResult* _res_,
                                                            gpointer _user_data_)
{
	GearyImapEngineReplayQueueDoReplayLocalAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_engine_replay_queue_do_replay_local_async_co (_data_);
}

static gboolean
geary_imap_engine_replay_queue_do_replay_local_async_co (GearyImapEngineReplayQueueDoReplayLocalAsyncData* _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_->queue_running = TRUE;
	while (TRUE) {
		if (!_data_->queue_running) {
			break;
		}
		{
			_data_->_tmp1_ = _data_->self->priv->local_queue;
			_data_->_state_ = 1;
			geary_nonblocking_queue_receive (_data_->_tmp1_, NULL, geary_imap_engine_replay_queue_do_replay_local_async_ready, _data_);
			return FALSE;
			_state_1:
			_data_->_tmp2_ = geary_nonblocking_queue_receive_finish (_data_->_tmp1_, _data_->_res_, &_data_->_inner_error0_);
			_data_->_tmp0_ = (GearyImapEngineReplayOperation*) _data_->_tmp2_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_data_->_tmp3_ = _data_->_tmp0_;
			_data_->_tmp0_ = NULL;
			_g_object_unref0 (_data_->op);
			_data_->op = _data_->_tmp3_;
			_g_object_unref0 (_data_->_tmp0_);
		}
		goto __finally0;
		__catch0_g_error:
		{
			_data_->recv_err = _data_->_inner_error0_;
			_data_->_inner_error0_ = NULL;
			_data_->_tmp4_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
			_data_->_tmp5_ = _data_->_tmp4_;
			_data_->_tmp6_ = _data_->recv_err;
			_data_->_tmp7_ = _data_->_tmp6_->message;
			geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Unable to receive next replay operation on local queue %s: %s", _data_->_tmp5_, _data_->_tmp7_);
			_g_free0 (_data_->_tmp5_);
			_g_error_free0 (_data_->recv_err);
			_g_object_unref0 (_data_->op);
			break;
		}
		__finally0:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->op);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp8_ = _data_->op;
		_data_->_tmp9_ = _g_object_ref0 (_data_->_tmp8_);
		_g_object_unref0 (_data_->self->priv->local_op_active);
		_data_->self->priv->local_op_active = _data_->_tmp9_;
		_data_->_tmp10_ = _data_->op;
		if (GEARY_IMAP_ENGINE_REPLAY_QUEUE_IS_CLOSE_REPLAY_QUEUE (_data_->_tmp10_)) {
			_data_->queue_running = FALSE;
		}
		_data_->local_execute = FALSE;
		_data_->remote_enqueue = FALSE;
		_data_->_tmp11_ = _data_->op;
		_data_->_tmp12_ = geary_imap_engine_replay_operation_get_scope (_data_->_tmp11_);
		_data_->_tmp13_ = _data_->_tmp12_;
		switch (_data_->_tmp13_) {
			case GEARY_IMAP_ENGINE_REPLAY_OPERATION_SCOPE_LOCAL_AND_REMOTE:
			{
				_data_->local_execute = TRUE;
				_data_->remote_enqueue = TRUE;
				break;
			}
			case GEARY_IMAP_ENGINE_REPLAY_OPERATION_SCOPE_LOCAL_ONLY:
			{
				_data_->local_execute = TRUE;
				_data_->remote_enqueue = FALSE;
				break;
			}
			case GEARY_IMAP_ENGINE_REPLAY_OPERATION_SCOPE_REMOTE_ONLY:
			{
				_data_->local_execute = FALSE;
				_data_->remote_enqueue = TRUE;
				break;
			}
			default:
			{
				g_assert_not_reached ();
			}
		}
		if (_data_->local_execute) {
			_data_->_tmp14_ = _data_->op;
			g_signal_emit (_data_->self, geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_LOCALLY_EXECUTING_SIGNAL], 0, _data_->_tmp14_);
			{
				_data_->_tmp16_ = _data_->op;
				_data_->_state_ = 2;
				geary_imap_engine_replay_operation_replay_local_async (_data_->_tmp16_, geary_imap_engine_replay_queue_do_replay_local_async_ready, _data_);
				return FALSE;
				_state_2:
				_data_->_tmp15_ = geary_imap_engine_replay_operation_replay_local_finish (_data_->_tmp16_, _data_->_res_, &_data_->_inner_error0_);
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					goto __catch1_g_error;
				}
				switch (_data_->_tmp15_) {
					case GEARY_IMAP_ENGINE_REPLAY_OPERATION_STATUS_COMPLETED:
					{
						_data_->remote_enqueue = FALSE;
						_data_->_tmp17_ = _data_->op;
						geary_imap_engine_replay_operation_notify_ready (_data_->_tmp17_, NULL);
						break;
					}
					case GEARY_IMAP_ENGINE_REPLAY_OPERATION_STATUS_CONTINUE:
					{
						if (!_data_->remote_enqueue) {
							_data_->_tmp18_ = _data_->op;
							geary_imap_engine_replay_operation_notify_ready (_data_->_tmp18_, NULL);
						}
						break;
					}
					default:
					{
						g_assert_not_reached ();
					}
				}
			}
			goto __finally1;
			__catch1_g_error:
			{
				_data_->replay_err = _data_->_inner_error0_;
				_data_->_inner_error0_ = NULL;
				_data_->_tmp19_ = _data_->op;
				_data_->_tmp20_ = geary_imap_engine_replay_operation_to_string (_data_->_tmp19_);
				_data_->_tmp21_ = _data_->_tmp20_;
				_data_->_tmp22_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
				_data_->_tmp23_ = _data_->_tmp22_;
				_data_->_tmp24_ = _data_->replay_err;
				_data_->_tmp25_ = _data_->_tmp24_->message;
				geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Replay local error for %s on %s: %s", _data_->_tmp21_, _data_->_tmp23_, _data_->_tmp25_);
				_g_free0 (_data_->_tmp23_);
				_g_free0 (_data_->_tmp21_);
				_data_->_tmp26_ = _data_->op;
				_data_->_tmp27_ = _data_->replay_err;
				geary_imap_engine_replay_operation_notify_ready (_data_->_tmp26_, _data_->_tmp27_);
				_data_->remote_enqueue = FALSE;
				_g_error_free0 (_data_->replay_err);
			}
			__finally1:
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->op);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
				g_clear_error (&_data_->_inner_error0_);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
		}
		if (_data_->remote_enqueue) {
			_data_->_tmp28_ = _data_->self->priv->remote_queue;
			_data_->_tmp29_ = _data_->op;
			if (!geary_nonblocking_queue_send (_data_->_tmp28_, _data_->_tmp29_)) {
				_data_->_tmp30_ = _data_->op;
				_data_->_tmp31_ = geary_imap_engine_replay_operation_to_string (_data_->_tmp30_);
				_data_->_tmp32_ = _data_->_tmp31_;
				_data_->_tmp33_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
				_data_->_tmp34_ = _data_->_tmp33_;
				geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Unable to enqueue operation %s for %s remote operation", _data_->_tmp32_, _data_->_tmp34_);
				_g_free0 (_data_->_tmp34_);
				_g_free0 (_data_->_tmp32_);
			}
		} else {
			_data_->_tmp35_ = _data_->op;
			_data_->_tmp36_ = geary_imap_engine_replay_operation_get_notified (_data_->_tmp35_);
			_data_->_tmp37_ = _data_->_tmp36_;
			_vala_assert (_data_->_tmp37_, "op.notified");
		}
		if (_data_->local_execute) {
			_data_->_tmp38_ = _data_->op;
			g_signal_emit (_data_->self, geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_LOCALLY_EXECUTED_SIGNAL], 0, _data_->_tmp38_, _data_->remote_enqueue);
		}
		if (!_data_->remote_enqueue) {
			_data_->_tmp39_ = _data_->op;
			_data_->_tmp40_ = geary_imap_engine_replay_operation_get_err (_data_->_tmp39_);
			_data_->_tmp41_ = _data_->_tmp40_;
			if (_data_->_tmp41_ == NULL) {
				_data_->_tmp42_ = _data_->op;
				g_signal_emit (_data_->self, geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_COMPLETED_SIGNAL], 0, _data_->_tmp42_);
			} else {
				_data_->_tmp43_ = _data_->op;
				g_signal_emit (_data_->self, geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_FAILED_SIGNAL], 0, _data_->_tmp43_);
			}
		}
		_g_object_unref0 (_data_->self->priv->local_op_active);
		_data_->self->priv->local_op_active = NULL;
		_g_object_unref0 (_data_->op);
	}
	_data_->_tmp44_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
	_data_->_tmp45_ = _data_->_tmp44_;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "ReplayQueue.do_replay_local_async %s exiting", _data_->_tmp45_);
	_g_free0 (_data_->_tmp45_);
	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_replay_queue_do_replay_remote_async_data_free (gpointer _data)
{
	GearyImapEngineReplayQueueDoReplayRemoteAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapEngineReplayQueueDoReplayRemoteAsyncData, _data_);
}

static void
geary_imap_engine_replay_queue_do_replay_remote_async (GearyImapEngineReplayQueue* self,
                                                       GAsyncReadyCallback _callback_,
                                                       gpointer _user_data_)
{
	GearyImapEngineReplayQueueDoReplayRemoteAsyncData* _data_;
	GearyImapEngineReplayQueue* _tmp0_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_REPLAY_QUEUE (self));
	_data_ = g_slice_new0 (GearyImapEngineReplayQueueDoReplayRemoteAsyncData);
	_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_replay_queue_do_replay_remote_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	geary_imap_engine_replay_queue_do_replay_remote_async_co (_data_);
}

static void
geary_imap_engine_replay_queue_do_replay_remote_finish (GearyImapEngineReplayQueue* self,
                                                        GAsyncResult* _res_)
{
	GearyImapEngineReplayQueueDoReplayRemoteAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
geary_imap_engine_replay_queue_do_replay_remote_async_ready (GObject* source_object,
                                                             GAsyncResult* _res_,
                                                             gpointer _user_data_)
{
	GearyImapEngineReplayQueueDoReplayRemoteAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_engine_replay_queue_do_replay_remote_async_co (_data_);
}

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

static gboolean
geary_imap_engine_replay_queue_do_replay_remote_async_co (GearyImapEngineReplayQueueDoReplayRemoteAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		case 4:
		goto _state_4;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->folder_opened = TRUE;
	_data_->queue_running = TRUE;
	while (TRUE) {
		if (!_data_->queue_running) {
			break;
		}
		{
			_data_->_tmp1_ = _data_->self->priv->remote_queue;
			_data_->_state_ = 1;
			geary_nonblocking_queue_receive (_data_->_tmp1_, NULL, geary_imap_engine_replay_queue_do_replay_remote_async_ready, _data_);
			return FALSE;
			_state_1:
			_data_->_tmp2_ = geary_nonblocking_queue_receive_finish (_data_->_tmp1_, _data_->_res_, &_data_->_inner_error0_);
			_data_->_tmp0_ = (GearyImapEngineReplayOperation*) _data_->_tmp2_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_data_->_tmp3_ = _data_->_tmp0_;
			_data_->_tmp0_ = NULL;
			_g_object_unref0 (_data_->op);
			_data_->op = _data_->_tmp3_;
			_g_object_unref0 (_data_->_tmp0_);
		}
		goto __finally0;
		__catch0_g_error:
		{
			_data_->recv_err = _data_->_inner_error0_;
			_data_->_inner_error0_ = NULL;
			_data_->_tmp4_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
			_data_->_tmp5_ = _data_->_tmp4_;
			_data_->_tmp6_ = _data_->recv_err;
			_data_->_tmp7_ = _data_->_tmp6_->message;
			geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Unable to receive next replay operation on remote queue %s: %s", _data_->_tmp5_, _data_->_tmp7_);
			_g_free0 (_data_->_tmp5_);
			_g_error_free0 (_data_->recv_err);
			_g_object_unref0 (_data_->op);
			break;
		}
		__finally0:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->op);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp8_ = _data_->op;
		_data_->_tmp9_ = _g_object_ref0 (_data_->_tmp8_);
		_g_object_unref0 (_data_->self->priv->remote_op_active);
		_data_->self->priv->remote_op_active = _data_->_tmp9_;
		_data_->_tmp10_ = _data_->op;
		_data_->is_close_op = GEARY_IMAP_ENGINE_REPLAY_QUEUE_IS_CLOSE_REPLAY_QUEUE (_data_->_tmp10_);
		if (_data_->is_close_op) {
			_data_->queue_running = FALSE;
		}
		_data_->remote = NULL;
		{
			if (!_data_->is_close_op) {
				_data_->_tmp12_ = _data_->folder_opened;
			} else {
				_data_->_tmp12_ = FALSE;
			}
			if (_data_->_tmp12_) {
				_data_->_tmp11_ = _data_->self->priv->state != GEARY_IMAP_ENGINE_REPLAY_QUEUE_STATE_CLOSED;
			} else {
				_data_->_tmp11_ = FALSE;
			}
			if (_data_->_tmp11_) {
				_data_->_tmp14_ = _data_->self->priv->owner;
				_data_->_tmp15_ = _data_->self->priv->remote_wait_cancellable;
				_data_->_state_ = 2;
				geary_imap_engine_minimal_folder_claim_remote_session (_data_->_tmp14_, _data_->_tmp15_, geary_imap_engine_replay_queue_do_replay_remote_async_ready, _data_);
				return FALSE;
				_state_2:
				_data_->_tmp16_ = geary_imap_engine_minimal_folder_claim_remote_session_finish (_data_->_tmp14_, _data_->_res_, &_data_->_inner_error0_);
				_data_->_tmp13_ = _data_->_tmp16_;
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					goto __catch1_g_error;
				}
				_data_->_tmp17_ = _data_->_tmp13_;
				_data_->_tmp13_ = NULL;
				_g_object_unref0 (_data_->remote);
				_data_->remote = _data_->_tmp17_;
				_g_object_unref0 (_data_->_tmp13_);
			}
		}
		goto __finally1;
		__catch1_g_error:
		{
			_data_->remote_err = _data_->_inner_error0_;
			_data_->_inner_error0_ = NULL;
			_data_->_tmp18_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
			_data_->_tmp19_ = _data_->_tmp18_;
			_data_->_tmp20_ = _data_->remote_err;
			_data_->_tmp21_ = _data_->_tmp20_->message;
			geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Folder %s closed or failed to open, remote replay queue closing: %s", _data_->_tmp19_, _data_->_tmp21_);
			_g_free0 (_data_->_tmp19_);
			_data_->folder_opened = FALSE;
			_g_error_free0 (_data_->remote_err);
		}
		__finally1:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->remote);
			_g_object_unref0 (_data_->op);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp22_ = _data_->op;
		g_signal_emit (_data_->self, geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_REMOTELY_EXECUTING_SIGNAL], 0, _data_->_tmp22_);
		_data_->_vala1_remote_err = NULL;
		_data_->_tmp23_ = _data_->remote;
		if (_data_->_tmp23_ != NULL) {
			_data_->_tmp24_ = _data_->op;
			_data_->_tmp25_ = geary_imap_engine_replay_operation_get_remote_retry_count (_data_->_tmp24_);
			_data_->_tmp26_ = _data_->_tmp25_;
			if (_data_->_tmp26_ > 0) {
				_data_->_tmp27_ = _data_->op;
				_data_->_tmp28_ = geary_imap_engine_replay_operation_to_string (_data_->_tmp27_);
				_data_->_tmp29_ = _data_->_tmp28_;
				_data_->_tmp30_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
				_data_->_tmp31_ = _data_->_tmp30_;
				geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Retrying op %s on %s", _data_->_tmp29_, _data_->_tmp31_);
				_g_free0 (_data_->_tmp31_);
				_g_free0 (_data_->_tmp29_);
			}
			{
				_data_->_tmp32_ = _data_->op;
				_data_->_tmp33_ = _data_->remote;
				_data_->_state_ = 3;
				geary_imap_engine_replay_operation_replay_remote_async (_data_->_tmp32_, _data_->_tmp33_, geary_imap_engine_replay_queue_do_replay_remote_async_ready, _data_);
				return FALSE;
				_state_3:
				geary_imap_engine_replay_operation_replay_remote_finish (_data_->_tmp32_, _data_->_res_, &_data_->_inner_error0_);
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					goto __catch2_g_error;
				}
			}
			goto __finally2;
			__catch2_g_error:
			{
				_data_->replay_err = _data_->_inner_error0_;
				_data_->_inner_error0_ = NULL;
				_data_->_tmp34_ = _data_->op;
				_data_->_tmp35_ = geary_imap_engine_replay_operation_to_string (_data_->_tmp34_);
				_data_->_tmp36_ = _data_->_tmp35_;
				_data_->_tmp37_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
				_data_->_tmp38_ = _data_->_tmp37_;
				_data_->_tmp39_ = _data_->replay_err;
				_data_->_tmp40_ = _data_->_tmp39_->message;
				_data_->_tmp41_ = _data_->op;
				_data_->_tmp42_ = geary_imap_engine_replay_operation_get_on_remote_error (_data_->_tmp41_);
				_data_->_tmp43_ = _data_->_tmp42_;
				_data_->_tmp44_ = g_enum_to_string (GEARY_IMAP_ENGINE_REPLAY_OPERATION_TYPE_ON_ERROR, _data_->_tmp43_);
				geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Replay remote error for %s on %s: %s (%s)", _data_->_tmp36_, _data_->_tmp38_, _data_->_tmp40_, _data_->_tmp44_);
				_g_free0 (_data_->_tmp44_);
				_g_free0 (_data_->_tmp38_);
				_g_free0 (_data_->_tmp36_);
				_data_->_tmp48_ = _data_->op;
				_data_->_tmp49_ = geary_imap_engine_replay_operation_get_on_remote_error (_data_->_tmp48_);
				_data_->_tmp50_ = _data_->_tmp49_;
				if (_data_->_tmp50_ == GEARY_IMAP_ENGINE_REPLAY_OPERATION_ON_ERROR_RETRY) {
					_data_->_tmp51_ = _data_->op;
					_data_->_tmp52_ = geary_imap_engine_replay_operation_get_remote_retry_count (_data_->_tmp51_);
					_data_->_tmp53_ = _data_->_tmp52_;
					_data_->_tmp47_ = _data_->_tmp53_ <= GEARY_IMAP_ENGINE_REPLAY_QUEUE_MAX_OP_RETRIES;
				} else {
					_data_->_tmp47_ = FALSE;
				}
				if (_data_->_tmp47_) {
					_data_->_tmp54_ = _data_->replay_err;
					_data_->_tmp46_ = geary_imap_engine_is_recoverable_failure (_data_->_tmp54_);
				} else {
					_data_->_tmp46_ = FALSE;
				}
				if (_data_->_tmp46_) {
					_data_->_tmp45_ = _data_->self->priv->state == GEARY_IMAP_ENGINE_REPLAY_QUEUE_STATE_OPEN;
				} else {
					_data_->_tmp45_ = FALSE;
				}
				if (_data_->_tmp45_) {
					_data_->_tmp55_ = _data_->op;
					_data_->_tmp56_ = geary_imap_engine_replay_operation_to_string (_data_->_tmp55_);
					_data_->_tmp57_ = _data_->_tmp56_;
					_data_->_tmp58_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
					_data_->_tmp59_ = _data_->_tmp58_;
					geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Schedule op retry %s on %s", _data_->_tmp57_, _data_->_tmp59_);
					_g_free0 (_data_->_tmp59_);
					_g_free0 (_data_->_tmp57_);
					_data_->_tmp60_ = _data_->op;
					_data_->_tmp61_ = geary_imap_engine_replay_operation_get_remote_retry_count (_data_->_tmp60_);
					_data_->_tmp62_ = _data_->_tmp61_;
					geary_imap_engine_replay_operation_set_remote_retry_count (_data_->_tmp60_, _data_->_tmp62_ + 1);
					_data_->_tmp63_ = _data_->self->priv->remote_queue;
					_data_->_tmp64_ = _data_->op;
					geary_nonblocking_queue_send (_data_->_tmp63_, _data_->_tmp64_);
					_g_error_free0 (_data_->replay_err);
					_g_error_free0 (_data_->_vala1_remote_err);
					_g_object_unref0 (_data_->remote);
					_g_object_unref0 (_data_->op);
					continue;
				} else {
					_data_->_tmp66_ = _data_->op;
					_data_->_tmp67_ = geary_imap_engine_replay_operation_get_on_remote_error (_data_->_tmp66_);
					_data_->_tmp68_ = _data_->_tmp67_;
					if (_data_->_tmp68_ == GEARY_IMAP_ENGINE_REPLAY_OPERATION_ON_ERROR_IGNORE_REMOTE) {
						_data_->_tmp69_ = _data_->replay_err;
						_data_->_tmp65_ = geary_imap_engine_is_remote_error (_data_->_tmp69_);
					} else {
						_data_->_tmp65_ = FALSE;
					}
					if (_data_->_tmp65_) {
						_data_->_tmp70_ = _data_->op;
						_data_->_tmp71_ = geary_imap_engine_replay_operation_to_string (_data_->_tmp70_);
						_data_->_tmp72_ = _data_->_tmp71_;
						_data_->_tmp73_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
						_data_->_tmp74_ = _data_->_tmp73_;
						geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Ignoring remote error op %s on %s", _data_->_tmp72_, _data_->_tmp74_);
						_g_free0 (_data_->_tmp74_);
						_g_free0 (_data_->_tmp72_);
					} else {
						_data_->_tmp75_ = _data_->op;
						_data_->_tmp76_ = geary_imap_engine_replay_operation_to_string (_data_->_tmp75_);
						_data_->_tmp77_ = _data_->_tmp76_;
						_data_->_tmp78_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
						_data_->_tmp79_ = _data_->_tmp78_;
						_data_->_tmp80_ = _data_->replay_err;
						_data_->_tmp81_ = _data_->_tmp80_->message;
						geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Throwing error for op %s on %s: %s", _data_->_tmp77_, _data_->_tmp79_, _data_->_tmp81_);
						_g_free0 (_data_->_tmp79_);
						_g_free0 (_data_->_tmp77_);
						_data_->_tmp82_ = _data_->replay_err;
						_data_->_tmp83_ = _g_error_copy0 (_data_->_tmp82_);
						_g_error_free0 (_data_->_vala1_remote_err);
						_data_->_vala1_remote_err = _data_->_tmp83_;
					}
				}
				_g_error_free0 (_data_->replay_err);
			}
			__finally2:
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_error_free0 (_data_->_vala1_remote_err);
				_g_object_unref0 (_data_->remote);
				_g_object_unref0 (_data_->op);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
				g_clear_error (&_data_->_inner_error0_);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
		} else {
			if (!_data_->is_close_op) {
				_data_->_tmp84_ = _data_->self->priv->owner;
				_data_->_tmp85_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp84_, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
				_data_->_tmp86_ = _data_->_tmp85_;
				_data_->_tmp87_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_SERVER_UNAVAILABLE, "Folder %s not available", _data_->_tmp86_);
				_g_error_free0 (_data_->_vala1_remote_err);
				_data_->_vala1_remote_err = _data_->_tmp87_;
				_g_free0 (_data_->_tmp86_);
			}
		}
		_data_->_tmp89_ = _data_->_vala1_remote_err;
		if (_data_->_tmp89_ != NULL) {
			_data_->_tmp88_ = !_data_->is_close_op;
		} else {
			_data_->_tmp88_ = FALSE;
		}
		if (_data_->_tmp88_) {
			{
				_data_->_tmp90_ = _data_->op;
				_data_->_tmp91_ = _data_->_vala1_remote_err;
				g_signal_emit (_data_->self, geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_BACKING_OUT_SIGNAL], 0, _data_->_tmp90_, _data_->_tmp91_);
				_data_->_tmp92_ = _data_->op;
				_data_->_state_ = 4;
				geary_imap_engine_replay_operation_backout_local_async (_data_->_tmp92_, geary_imap_engine_replay_queue_do_replay_remote_async_ready, _data_);
				return FALSE;
				_state_4:
				geary_imap_engine_replay_operation_backout_local_finish (_data_->_tmp92_, _data_->_res_, &_data_->_inner_error0_);
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					goto __catch3_g_error;
				}
				_data_->_tmp93_ = _data_->op;
				_data_->_tmp94_ = _data_->_vala1_remote_err;
				g_signal_emit (_data_->self, geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_BACKED_OUT_SIGNAL], 0, _data_->_tmp93_, _data_->_tmp94_);
			}
			goto __finally3;
			__catch3_g_error:
			{
				_data_->backout_err = _data_->_inner_error0_;
				_data_->_inner_error0_ = NULL;
				_data_->_tmp95_ = _data_->op;
				_data_->_tmp96_ = _data_->backout_err;
				g_signal_emit (_data_->self, geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_BACKOUT_FAILED_SIGNAL], 0, _data_->_tmp95_, _data_->_tmp96_);
				_g_error_free0 (_data_->backout_err);
			}
			__finally3:
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_error_free0 (_data_->_vala1_remote_err);
				_g_object_unref0 (_data_->remote);
				_g_object_unref0 (_data_->op);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
				g_clear_error (&_data_->_inner_error0_);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
		}
		_data_->_tmp97_ = _data_->op;
		_data_->_tmp98_ = _data_->_vala1_remote_err;
		geary_imap_engine_replay_operation_notify_ready (_data_->_tmp97_, _data_->_tmp98_);
		_data_->_tmp99_ = _data_->op;
		g_signal_emit (_data_->self, geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_REMOTELY_EXECUTED_SIGNAL], 0, _data_->_tmp99_);
		_data_->_tmp100_ = _data_->op;
		_data_->_tmp101_ = geary_imap_engine_replay_operation_get_err (_data_->_tmp100_);
		_data_->_tmp102_ = _data_->_tmp101_;
		if (_data_->_tmp102_ == NULL) {
			_data_->_tmp103_ = _data_->op;
			g_signal_emit (_data_->self, geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_COMPLETED_SIGNAL], 0, _data_->_tmp103_);
		} else {
			_data_->_tmp104_ = _data_->op;
			g_signal_emit (_data_->self, geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_FAILED_SIGNAL], 0, _data_->_tmp104_);
		}
		_g_object_unref0 (_data_->self->priv->remote_op_active);
		_data_->self->priv->remote_op_active = NULL;
		_g_error_free0 (_data_->_vala1_remote_err);
		_g_object_unref0 (_data_->remote);
		_g_object_unref0 (_data_->op);
	}
	_data_->_tmp105_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
	_data_->_tmp106_ = _data_->_tmp105_;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "ReplayQueue.do_replay_remote_async %s exiting", _data_->_tmp106_);
	_g_free0 (_data_->_tmp106_);
	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 inline gpointer
geary_imap_engine_replay_queue_close_replay_queue_get_instance_private (GearyImapEngineReplayQueueCloseReplayQueue* self)
{
	return G_STRUCT_MEMBER_P (self, GearyImapEngineReplayQueueCloseReplayQueue_private_offset);
}

static GearyImapEngineReplayQueueCloseReplayQueue*
geary_imap_engine_replay_queue_close_replay_queue_construct (GType object_type)
{
	GearyImapEngineReplayQueueCloseReplayQueue * self = NULL;
	self = (GearyImapEngineReplayQueueCloseReplayQueue*) geary_imap_engine_replay_operation_construct (object_type, "CloseReplayQueue", GEARY_IMAP_ENGINE_REPLAY_OPERATION_SCOPE_LOCAL_AND_REMOTE, GEARY_IMAP_ENGINE_REPLAY_OPERATION_ON_ERROR_IGNORE_REMOTE);
	return self;
}

static GearyImapEngineReplayQueueCloseReplayQueue*
geary_imap_engine_replay_queue_close_replay_queue_new (void)
{
	return geary_imap_engine_replay_queue_close_replay_queue_construct (GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_CLOSE_REPLAY_QUEUE);
}

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

static void
geary_imap_engine_replay_queue_close_replay_queue_real_replay_local_async (GearyImapEngineReplayOperation* base,
                                                                           GAsyncReadyCallback _callback_,
                                                                           gpointer _user_data_)
{
	GearyImapEngineReplayQueueCloseReplayQueue * self;
	GearyImapEngineReplayQueueCloseReplayQueueReplayLocalAsyncData* _data_;
	GearyImapEngineReplayQueueCloseReplayQueue* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_CLOSE_REPLAY_QUEUE, GearyImapEngineReplayQueueCloseReplayQueue);
	_data_ = g_slice_new0 (GearyImapEngineReplayQueueCloseReplayQueueReplayLocalAsyncData);
	_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_replay_queue_close_replay_queue_real_replay_local_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	geary_imap_engine_replay_queue_close_replay_queue_real_replay_local_async_co (_data_);
}

static GearyImapEngineReplayOperationStatus
geary_imap_engine_replay_queue_close_replay_queue_replay_local_finish (GearyImapEngineReplayOperation* base,
                                                                       GAsyncResult* _res_,
                                                                       GError** error)
{
	GearyImapEngineReplayOperationStatus result;
	GearyImapEngineReplayQueueCloseReplayQueueReplayLocalAsyncData* _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_replay_queue_close_replay_queue_real_replay_local_async_co (GearyImapEngineReplayQueueCloseReplayQueueReplayLocalAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->self->priv->local_closed = TRUE;
	_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_replay_queue_close_replay_queue_real_replay_remote_async_data_free (gpointer _data)
{
	GearyImapEngineReplayQueueCloseReplayQueueReplayRemoteAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->remote);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapEngineReplayQueueCloseReplayQueueReplayRemoteAsyncData, _data_);
}

static void
geary_imap_engine_replay_queue_close_replay_queue_real_replay_remote_async (GearyImapEngineReplayOperation* base,
                                                                            GearyImapFolderSession* remote,
                                                                            GAsyncReadyCallback _callback_,
                                                                            gpointer _user_data_)
{
	GearyImapEngineReplayQueueCloseReplayQueue * self;
	GearyImapEngineReplayQueueCloseReplayQueueReplayRemoteAsyncData* _data_;
	GearyImapEngineReplayQueueCloseReplayQueue* _tmp0_;
	GearyImapFolderSession* _tmp1_;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (remote));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_CLOSE_REPLAY_QUEUE, GearyImapEngineReplayQueueCloseReplayQueue);
	_data_ = g_slice_new0 (GearyImapEngineReplayQueueCloseReplayQueueReplayRemoteAsyncData);
	_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_replay_queue_close_replay_queue_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_replay_queue_close_replay_queue_real_replay_remote_async_co (_data_);
}

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

static gboolean
geary_imap_engine_replay_queue_close_replay_queue_real_replay_remote_async_co (GearyImapEngineReplayQueueCloseReplayQueueReplayRemoteAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->self->priv->remote_closed = TRUE;
	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_replay_queue_close_replay_queue_real_describe_state (GearyImapEngineReplayOperation* base)
{
	GearyImapEngineReplayQueueCloseReplayQueue * self;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_CLOSE_REPLAY_QUEUE, GearyImapEngineReplayQueueCloseReplayQueue);
	_tmp0_ = bool_to_string (self->priv->local_closed);
	_tmp1_ = _tmp0_;
	_tmp2_ = bool_to_string (self->priv->remote_closed);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strdup_printf ("local_closed: %s, remote_closed: %s", _tmp1_, _tmp3_);
	_tmp5_ = _tmp4_;
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
	result = _tmp5_;
	return result;
}

static void
geary_imap_engine_replay_queue_close_replay_queue_class_init (GearyImapEngineReplayQueueCloseReplayQueueClass * klass,
                                                              gpointer klass_data)
{
	geary_imap_engine_replay_queue_close_replay_queue_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GearyImapEngineReplayQueueCloseReplayQueue_private_offset);
	((GearyImapEngineReplayOperationClass *) klass)->replay_local_async = (void (*) (GearyImapEngineReplayOperation*, GAsyncReadyCallback, gpointer)) geary_imap_engine_replay_queue_close_replay_queue_real_replay_local_async;
	((GearyImapEngineReplayOperationClass *) klass)->replay_local_finish = (GearyImapEngineReplayOperationStatus (*) (GearyImapEngineReplayOperation*, GAsyncResult*, GError**)) geary_imap_engine_replay_queue_close_replay_queue_replay_local_finish;
	((GearyImapEngineReplayOperationClass *) klass)->replay_remote_async = (void (*) (GearyImapEngineReplayOperation*, GearyImapFolderSession*, GAsyncReadyCallback, gpointer)) geary_imap_engine_replay_queue_close_replay_queue_real_replay_remote_async;
	((GearyImapEngineReplayOperationClass *) klass)->replay_remote_finish = (void (*) (GearyImapEngineReplayOperation*, GAsyncResult*, GError**)) geary_imap_engine_replay_queue_close_replay_queue_replay_remote_finish;
	((GearyImapEngineReplayOperationClass *) klass)->describe_state = (gchar* (*) (GearyImapEngineReplayOperation*)) geary_imap_engine_replay_queue_close_replay_queue_real_describe_state;
	G_OBJECT_CLASS (klass)->finalize = geary_imap_engine_replay_queue_close_replay_queue_finalize;
}

static void
geary_imap_engine_replay_queue_close_replay_queue_instance_init (GearyImapEngineReplayQueueCloseReplayQueue * self,
                                                                 gpointer klass)
{
	self->priv = geary_imap_engine_replay_queue_close_replay_queue_get_instance_private (self);
	self->priv->local_closed = FALSE;
	self->priv->remote_closed = FALSE;
}

static void
geary_imap_engine_replay_queue_close_replay_queue_finalize (GObject * obj)
{
	GearyImapEngineReplayQueueCloseReplayQueue * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_CLOSE_REPLAY_QUEUE, GearyImapEngineReplayQueueCloseReplayQueue);
	G_OBJECT_CLASS (geary_imap_engine_replay_queue_close_replay_queue_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
geary_imap_engine_replay_queue_close_replay_queue_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapEngineReplayQueueCloseReplayQueueClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_engine_replay_queue_close_replay_queue_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapEngineReplayQueueCloseReplayQueue), 0, (GInstanceInitFunc) geary_imap_engine_replay_queue_close_replay_queue_instance_init, NULL };
	GType geary_imap_engine_replay_queue_close_replay_queue_type_id;
	geary_imap_engine_replay_queue_close_replay_queue_type_id = g_type_register_static (GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, "GearyImapEngineReplayQueueCloseReplayQueue", &g_define_type_info, 0);
	GearyImapEngineReplayQueueCloseReplayQueue_private_offset = g_type_add_instance_private (geary_imap_engine_replay_queue_close_replay_queue_type_id, sizeof (GearyImapEngineReplayQueueCloseReplayQueuePrivate));
	return geary_imap_engine_replay_queue_close_replay_queue_type_id;
}

static GType
geary_imap_engine_replay_queue_close_replay_queue_get_type (void)
{
	static gsize geary_imap_engine_replay_queue_close_replay_queue_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_engine_replay_queue_close_replay_queue_type_id__once)) {
		GType geary_imap_engine_replay_queue_close_replay_queue_type_id;
		geary_imap_engine_replay_queue_close_replay_queue_type_id = geary_imap_engine_replay_queue_close_replay_queue_get_type_once ();
		g_once_init_leave (&geary_imap_engine_replay_queue_close_replay_queue_type_id__once, geary_imap_engine_replay_queue_close_replay_queue_type_id);
	}
	return geary_imap_engine_replay_queue_close_replay_queue_type_id__once;
}

static GearyImapEngineReplayQueueWaitOperation*
geary_imap_engine_replay_queue_wait_operation_construct (GType object_type)
{
	GearyImapEngineReplayQueueWaitOperation * self = NULL;
	self = (GearyImapEngineReplayQueueWaitOperation*) geary_imap_engine_replay_operation_construct (object_type, "Wait", GEARY_IMAP_ENGINE_REPLAY_OPERATION_SCOPE_LOCAL_AND_REMOTE, GEARY_IMAP_ENGINE_REPLAY_OPERATION_ON_ERROR_IGNORE_REMOTE);
	return self;
}

static GearyImapEngineReplayQueueWaitOperation*
geary_imap_engine_replay_queue_wait_operation_new (void)
{
	return geary_imap_engine_replay_queue_wait_operation_construct (GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_WAIT_OPERATION);
}

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

static void
geary_imap_engine_replay_queue_wait_operation_real_replay_local_async (GearyImapEngineReplayOperation* base,
                                                                       GAsyncReadyCallback _callback_,
                                                                       gpointer _user_data_)
{
	GearyImapEngineReplayQueueWaitOperation * self;
	GearyImapEngineReplayQueueWaitOperationReplayLocalAsyncData* _data_;
	GearyImapEngineReplayQueueWaitOperation* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_WAIT_OPERATION, GearyImapEngineReplayQueueWaitOperation);
	_data_ = g_slice_new0 (GearyImapEngineReplayQueueWaitOperationReplayLocalAsyncData);
	_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_replay_queue_wait_operation_real_replay_local_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	geary_imap_engine_replay_queue_wait_operation_real_replay_local_async_co (_data_);
}

static GearyImapEngineReplayOperationStatus
geary_imap_engine_replay_queue_wait_operation_replay_local_finish (GearyImapEngineReplayOperation* base,
                                                                   GAsyncResult* _res_,
                                                                   GError** error)
{
	GearyImapEngineReplayOperationStatus result;
	GearyImapEngineReplayQueueWaitOperationReplayLocalAsyncData* _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_replay_queue_wait_operation_real_replay_local_async_co (GearyImapEngineReplayQueueWaitOperationReplayLocalAsyncData* _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_replay_queue_wait_operation_real_replay_remote_async_data_free (gpointer _data)
{
	GearyImapEngineReplayQueueWaitOperationReplayRemoteAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->remote);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapEngineReplayQueueWaitOperationReplayRemoteAsyncData, _data_);
}

static void
geary_imap_engine_replay_queue_wait_operation_real_replay_remote_async (GearyImapEngineReplayOperation* base,
                                                                        GearyImapFolderSession* remote,
                                                                        GAsyncReadyCallback _callback_,
                                                                        gpointer _user_data_)
{
	GearyImapEngineReplayQueueWaitOperation * self;
	GearyImapEngineReplayQueueWaitOperationReplayRemoteAsyncData* _data_;
	GearyImapEngineReplayQueueWaitOperation* _tmp0_;
	GearyImapFolderSession* _tmp1_;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (remote));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_WAIT_OPERATION, GearyImapEngineReplayQueueWaitOperation);
	_data_ = g_slice_new0 (GearyImapEngineReplayQueueWaitOperationReplayRemoteAsyncData);
	_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_replay_queue_wait_operation_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_replay_queue_wait_operation_real_replay_remote_async_co (_data_);
}

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

static gboolean
geary_imap_engine_replay_queue_wait_operation_real_replay_remote_async_co (GearyImapEngineReplayQueueWaitOperationReplayRemoteAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	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_replay_queue_wait_operation_real_describe_state (GearyImapEngineReplayOperation* base)
{
	GearyImapEngineReplayQueueWaitOperation * self;
	gchar* _tmp0_;
	gchar* result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_REPLAY_QUEUE_TYPE_WAIT_OPERATION, GearyImapEngineReplayQueueWaitOperation);
	_tmp0_ = g_strdup ("");
	result = _tmp0_;
	return result;
}

static void
geary_imap_engine_replay_queue_wait_operation_class_init (GearyImapEngineReplayQueueWaitOperationClass * klass,
                                                          gpointer klass_data)
{
	geary_imap_engine_replay_queue_wait_operation_parent_class = g_type_class_peek_parent (klass);
	((GearyImapEngineReplayOperationClass *) klass)->replay_local_async = (void (*) (GearyImapEngineReplayOperation*, GAsyncReadyCallback, gpointer)) geary_imap_engine_replay_queue_wait_operation_real_replay_local_async;
	((GearyImapEngineReplayOperationClass *) klass)->replay_local_finish = (GearyImapEngineReplayOperationStatus (*) (GearyImapEngineReplayOperation*, GAsyncResult*, GError**)) geary_imap_engine_replay_queue_wait_operation_replay_local_finish;
	((GearyImapEngineReplayOperationClass *) klass)->replay_remote_async = (void (*) (GearyImapEngineReplayOperation*, GearyImapFolderSession*, GAsyncReadyCallback, gpointer)) geary_imap_engine_replay_queue_wait_operation_real_replay_remote_async;
	((GearyImapEngineReplayOperationClass *) klass)->replay_remote_finish = (void (*) (GearyImapEngineReplayOperation*, GAsyncResult*, GError**)) geary_imap_engine_replay_queue_wait_operation_replay_remote_finish;
	((GearyImapEngineReplayOperationClass *) klass)->describe_state = (gchar* (*) (GearyImapEngineReplayOperation*)) geary_imap_engine_replay_queue_wait_operation_real_describe_state;
}

static void
geary_imap_engine_replay_queue_wait_operation_instance_init (GearyImapEngineReplayQueueWaitOperation * self,
                                                             gpointer klass)
{
}

 G_GNUC_NO_INLINE static GType
geary_imap_engine_replay_queue_wait_operation_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapEngineReplayQueueWaitOperationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_engine_replay_queue_wait_operation_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapEngineReplayQueueWaitOperation), 0, (GInstanceInitFunc) geary_imap_engine_replay_queue_wait_operation_instance_init, NULL };
	GType geary_imap_engine_replay_queue_wait_operation_type_id;
	geary_imap_engine_replay_queue_wait_operation_type_id = g_type_register_static (GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, "GearyImapEngineReplayQueueWaitOperation", &g_define_type_info, 0);
	return geary_imap_engine_replay_queue_wait_operation_type_id;
}

static GType
geary_imap_engine_replay_queue_wait_operation_get_type (void)
{
	static gsize geary_imap_engine_replay_queue_wait_operation_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_engine_replay_queue_wait_operation_type_id__once)) {
		GType geary_imap_engine_replay_queue_wait_operation_type_id;
		geary_imap_engine_replay_queue_wait_operation_type_id = geary_imap_engine_replay_queue_wait_operation_get_type_once ();
		g_once_init_leave (&geary_imap_engine_replay_queue_wait_operation_type_id__once, geary_imap_engine_replay_queue_wait_operation_type_id);
	}
	return geary_imap_engine_replay_queue_wait_operation_type_id__once;
}

static void
geary_imap_engine_replay_queue_class_init (GearyImapEngineReplayQueueClass * klass,
                                           gpointer klass_data)
{
	geary_imap_engine_replay_queue_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GearyImapEngineReplayQueue_private_offset);
	((GearyImapEngineReplayQueueClass *) klass)->scheduled = geary_imap_engine_replay_queue_real_scheduled;
	((GearyImapEngineReplayQueueClass *) klass)->locally_executing = geary_imap_engine_replay_queue_real_locally_executing;
	((GearyImapEngineReplayQueueClass *) klass)->locally_executed = geary_imap_engine_replay_queue_real_locally_executed;
	((GearyImapEngineReplayQueueClass *) klass)->remotely_executing = geary_imap_engine_replay_queue_real_remotely_executing;
	((GearyImapEngineReplayQueueClass *) klass)->remotely_executed = geary_imap_engine_replay_queue_real_remotely_executed;
	((GearyImapEngineReplayQueueClass *) klass)->backing_out = geary_imap_engine_replay_queue_real_backing_out;
	((GearyImapEngineReplayQueueClass *) klass)->backed_out = geary_imap_engine_replay_queue_real_backed_out;
	((GearyImapEngineReplayQueueClass *) klass)->backout_failed = geary_imap_engine_replay_queue_real_backout_failed;
	((GearyImapEngineReplayQueueClass *) klass)->completed = geary_imap_engine_replay_queue_real_completed;
	((GearyImapEngineReplayQueueClass *) klass)->failed = geary_imap_engine_replay_queue_real_failed;
	((GearyImapEngineReplayQueueClass *) klass)->closing = geary_imap_engine_replay_queue_real_closing;
	((GearyImapEngineReplayQueueClass *) klass)->closed = geary_imap_engine_replay_queue_real_closed;
	G_OBJECT_CLASS (klass)->get_property = _vala_geary_imap_engine_replay_queue_get_property;
	G_OBJECT_CLASS (klass)->finalize = geary_imap_engine_replay_queue_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_ENGINE_REPLAY_QUEUE_LOCAL_COUNT_PROPERTY, geary_imap_engine_replay_queue_properties[GEARY_IMAP_ENGINE_REPLAY_QUEUE_LOCAL_COUNT_PROPERTY] = g_param_spec_int ("local-count", "local-count", "local-count", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_ENGINE_REPLAY_QUEUE_REMOTE_COUNT_PROPERTY, geary_imap_engine_replay_queue_properties[GEARY_IMAP_ENGINE_REPLAY_QUEUE_REMOTE_COUNT_PROPERTY] = g_param_spec_int ("remote-count", "remote-count", "remote-count", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** {@inheritDoc} */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_ENGINE_REPLAY_QUEUE_LOGGING_PARENT_PROPERTY, geary_imap_engine_replay_queue_properties[GEARY_IMAP_ENGINE_REPLAY_QUEUE_LOGGING_PARENT_PROPERTY] = g_param_spec_object ("logging-parent", "logging-parent", "logging-parent", GEARY_LOGGING_TYPE_SOURCE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_SCHEDULED_SIGNAL] = g_signal_new ("scheduled", GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GearyImapEngineReplayQueueClass, scheduled), NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION);
	geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_LOCALLY_EXECUTING_SIGNAL] = g_signal_new ("locally-executing", GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GearyImapEngineReplayQueueClass, locally_executing), NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION);
	geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_LOCALLY_EXECUTED_SIGNAL] = g_signal_new ("locally-executed", GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GearyImapEngineReplayQueueClass, locally_executed), NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2, GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, G_TYPE_BOOLEAN);
	geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_REMOTELY_EXECUTING_SIGNAL] = g_signal_new ("remotely-executing", GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GearyImapEngineReplayQueueClass, remotely_executing), NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION);
	geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_REMOTELY_EXECUTED_SIGNAL] = g_signal_new ("remotely-executed", GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GearyImapEngineReplayQueueClass, remotely_executed), NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION);
	geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_BACKING_OUT_SIGNAL] = g_signal_new ("backing-out", GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GearyImapEngineReplayQueueClass, backing_out), NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_BOXED, G_TYPE_NONE, 2, GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, G_TYPE_ERROR);
	geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_BACKED_OUT_SIGNAL] = g_signal_new ("backed-out", GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GearyImapEngineReplayQueueClass, backed_out), NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_BOXED, G_TYPE_NONE, 2, GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, G_TYPE_ERROR);
	geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_BACKOUT_FAILED_SIGNAL] = g_signal_new ("backout-failed", GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GearyImapEngineReplayQueueClass, backout_failed), NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_BOXED, G_TYPE_NONE, 2, GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, G_TYPE_ERROR);
	geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_COMPLETED_SIGNAL] = g_signal_new ("completed", GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GearyImapEngineReplayQueueClass, completed), NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION);
	geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_FAILED_SIGNAL] = g_signal_new ("failed", GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GearyImapEngineReplayQueueClass, failed), NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION);
	geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_CLOSING_SIGNAL] = g_signal_new ("closing", GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GearyImapEngineReplayQueueClass, closing), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	geary_imap_engine_replay_queue_signals[GEARY_IMAP_ENGINE_REPLAY_QUEUE_CLOSED_SIGNAL] = g_signal_new ("closed", GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GearyImapEngineReplayQueueClass, closed), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
geary_imap_engine_replay_queue_geary_logging_source_interface_init (GearyLoggingSourceIface * iface,
                                                                    gpointer iface_data)
{
	geary_imap_engine_replay_queue_geary_logging_source_parent_iface = g_type_interface_peek_parent (iface);
	iface->to_logging_state = (GearyLoggingState* (*) (GearyLoggingSource*)) geary_imap_engine_replay_queue_real_to_logging_state;
	iface->get_logging_domain = geary_imap_engine_replay_queue_real_get_logging_domain;
	iface->get_logging_parent = geary_imap_engine_replay_queue_real_get_logging_parent;
}

static void
geary_imap_engine_replay_queue_instance_init (GearyImapEngineReplayQueue * self,
                                              gpointer klass)
{
	GearyNonblockingQueue* _tmp0_;
	GearyNonblockingQueue* _tmp1_;
	GeeArrayList* _tmp2_;
	GCancellable* _tmp3_;
	self->priv = geary_imap_engine_replay_queue_get_instance_private (self);
	_tmp0_ = geary_nonblocking_queue_new_fifo (GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->priv->local_queue = _tmp0_;
	_tmp1_ = geary_nonblocking_queue_new_fifo (GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->priv->remote_queue = _tmp1_;
	self->priv->local_op_active = NULL;
	self->priv->remote_op_active = NULL;
	_tmp2_ = gee_array_list_new (GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->priv->notification_queue = _tmp2_;
	self->priv->notification_timer = NULL;
	self->priv->next_submission_number = (gint64) 0;
	self->priv->state = GEARY_IMAP_ENGINE_REPLAY_QUEUE_STATE_OPEN;
	_tmp3_ = g_cancellable_new ();
	self->priv->remote_wait_cancellable = _tmp3_;
}

static void
geary_imap_engine_replay_queue_finalize (GObject * obj)
{
	GearyImapEngineReplayQueue * self;
	GearySchedulerScheduled* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, GearyImapEngineReplayQueue);
	_tmp0_ = self->priv->notification_timer;
	if (_tmp0_ != NULL) {
		GearySchedulerScheduled* _tmp1_;
		_tmp1_ = self->priv->notification_timer;
		geary_scheduler_scheduled_cancel (_tmp1_);
	}
	_g_object_unref0 (self->priv->local_queue);
	_g_object_unref0 (self->priv->remote_queue);
	_g_object_unref0 (self->priv->local_op_active);
	_g_object_unref0 (self->priv->remote_op_active);
	_g_object_unref0 (self->priv->notification_queue);
	_g_object_unref0 (self->priv->notification_timer);
	_g_object_unref0 (self->priv->remote_wait_cancellable);
	G_OBJECT_CLASS (geary_imap_engine_replay_queue_parent_class)->finalize (obj);
}

/**
 * Interleaves IMAP operations to maintain consistent sequence numbering.
 *
 * The replay queue manages and executes operations originating both
 * locally and from the server for a specific IMAP mailbox so as to
 * ensure the execution of the operations maintains consistent.
 */
 G_GNUC_NO_INLINE static GType
geary_imap_engine_replay_queue_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapEngineReplayQueueClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_engine_replay_queue_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapEngineReplayQueue), 0, (GInstanceInitFunc) geary_imap_engine_replay_queue_instance_init, NULL };
	static const GInterfaceInfo geary_logging_source_info = { (GInterfaceInitFunc) geary_imap_engine_replay_queue_geary_logging_source_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType geary_imap_engine_replay_queue_type_id;
	geary_imap_engine_replay_queue_type_id = g_type_register_static (GEARY_TYPE_BASE_OBJECT, "GearyImapEngineReplayQueue", &g_define_type_info, 0);
	g_type_add_interface_static (geary_imap_engine_replay_queue_type_id, GEARY_LOGGING_TYPE_SOURCE, &geary_logging_source_info);
	GearyImapEngineReplayQueue_private_offset = g_type_add_instance_private (geary_imap_engine_replay_queue_type_id, sizeof (GearyImapEngineReplayQueuePrivate));
	return geary_imap_engine_replay_queue_type_id;
}

GType
geary_imap_engine_replay_queue_get_type (void)
{
	static gsize geary_imap_engine_replay_queue_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_engine_replay_queue_type_id__once)) {
		GType geary_imap_engine_replay_queue_type_id;
		geary_imap_engine_replay_queue_type_id = geary_imap_engine_replay_queue_get_type_once ();
		g_once_init_leave (&geary_imap_engine_replay_queue_type_id__once, geary_imap_engine_replay_queue_type_id);
	}
	return geary_imap_engine_replay_queue_type_id__once;
}

static void
_vala_geary_imap_engine_replay_queue_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec)
{
	GearyImapEngineReplayQueue * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_ENGINE_TYPE_REPLAY_QUEUE, GearyImapEngineReplayQueue);
	switch (property_id) {
		case GEARY_IMAP_ENGINE_REPLAY_QUEUE_LOCAL_COUNT_PROPERTY:
		g_value_set_int (value, geary_imap_engine_replay_queue_get_local_count (self));
		break;
		case GEARY_IMAP_ENGINE_REPLAY_QUEUE_REMOTE_COUNT_PROPERTY:
		g_value_set_int (value, geary_imap_engine_replay_queue_get_remote_count (self));
		break;
		case GEARY_IMAP_ENGINE_REPLAY_QUEUE_LOGGING_PARENT_PROPERTY:
		g_value_set_object (value, geary_logging_source_get_logging_parent (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource)));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

