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

/* Copyright 2016 Software Freedom Conservancy Inc.
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later).  See the COPYING file in this distribution.
 */

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

#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_OPERATION (geary_imap_engine_replay_operation_get_type ())
#define GEARY_IMAP_ENGINE_REPLAY_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, GearyImapEngineReplayOperation))
#define GEARY_IMAP_ENGINE_REPLAY_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, GearyImapEngineReplayOperationClass))
#define GEARY_IMAP_ENGINE_IS_REPLAY_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION))
#define GEARY_IMAP_ENGINE_IS_REPLAY_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION))
#define GEARY_IMAP_ENGINE_REPLAY_OPERATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_ENGINE_TYPE_REPLAY_OPERATION, GearyImapEngineReplayOperationClass))

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

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

typedef struct _GearyImapDBEmailIdentifier GearyImapDBEmailIdentifier;
typedef struct _GearyImapDBEmailIdentifierClass GearyImapDBEmailIdentifierClass;
typedef enum  {
	GEARY_IMAP_ENGINE_REPLAY_OPERATION_STATUS_COMPLETED,
	GEARY_IMAP_ENGINE_REPLAY_OPERATION_STATUS_CONTINUE
} GearyImapEngineReplayOperationStatus;

#define GEARY_IMAP_ENGINE_REPLAY_OPERATION_TYPE_STATUS (geary_imap_engine_replay_operation_status_get_type ())

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

typedef struct _GearyImapFolderSession GearyImapFolderSession;
typedef struct _GearyImapFolderSessionClass GearyImapFolderSessionClass;

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

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

#define GEARY_IMAP_ENGINE_TYPE_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;
typedef struct _GearyImapEngineMarkEmailPrivate GearyImapEngineMarkEmailPrivate;

#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;
enum  {
	GEARY_IMAP_ENGINE_MARK_EMAIL_0_PROPERTY,
	GEARY_IMAP_ENGINE_MARK_EMAIL_UNREAD_CHANGE_PROPERTY,
	GEARY_IMAP_ENGINE_MARK_EMAIL_NUM_PROPERTIES
};
static GParamSpec* geary_imap_engine_mark_email_properties[GEARY_IMAP_ENGINE_MARK_EMAIL_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef enum  {
	GEARY_IMAP_ENGINE_REPLAY_OPERATION_ON_ERROR_THROW,
	GEARY_IMAP_ENGINE_REPLAY_OPERATION_ON_ERROR_RETRY,
	GEARY_IMAP_ENGINE_REPLAY_OPERATION_ON_ERROR_IGNORE_REMOTE
} GearyImapEngineReplayOperationOnError;

#define GEARY_IMAP_ENGINE_REPLAY_OPERATION_TYPE_ON_ERROR (geary_imap_engine_replay_operation_on_error_get_type ())

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

typedef struct _GearyImapDBFolder GearyImapDBFolder;
typedef struct _GearyImapDBFolderClass GearyImapDBFolderClass;
typedef struct _GearyImapEngineMarkEmailReplayLocalAsyncData GearyImapEngineMarkEmailReplayLocalAsyncData;
typedef struct _GearyImapEngineMarkEmailReplayRemoteAsyncData GearyImapEngineMarkEmailReplayRemoteAsyncData;
typedef struct _GearyImapEngineMarkEmailBackoutLocalAsyncData GearyImapEngineMarkEmailBackoutLocalAsyncData;
#define _g_free0(var) (var = (g_free (var), NULL))

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

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

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

struct _GearyImapEngineSendReplayOperationClass {
	GearyImapEngineReplayOperationClass parent_class;
};

struct _GearyImapEngineMarkEmail {
	GearyImapEngineSendReplayOperation parent_instance;
	GearyImapEngineMarkEmailPrivate * priv;
};

struct _GearyImapEngineMarkEmailClass {
	GearyImapEngineSendReplayOperationClass parent_class;
};

struct _GearyImapEngineMarkEmailPrivate {
	GearyImapEngineMinimalFolder* engine;
	GeeList* to_mark;
	GeeList* to_mark_uids;
	GearyEmailFlags* flags_to_add;
	GearyEmailFlags* flags_to_remove;
	GeeMap* original_flags;
	GCancellable* cancellable;
	gint _unread_change;
};

struct _GearyImapEngineMarkEmailReplayLocalAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineMarkEmail* self;
	GearyImapEngineReplayOperationStatus result;
	GeeList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	GeeMap* _tmp3_;
	GearyImapEngineMinimalFolder* _tmp4_;
	GearyImapDBFolder* _tmp5_;
	GearyImapDBFolder* _tmp6_;
	GeeList* _tmp7_;
	GCancellable* _tmp8_;
	GeeMap* _tmp9_;
	GeeMap* _tmp10_;
	gboolean _tmp11_;
	GeeMap* _tmp12_;
	GeeMap* _tmp13_;
	gint _tmp14_;
	gint _tmp15_;
	gint _tmp16_;
	GearyImapEngineMinimalFolder* _tmp17_;
	GearyImapDBFolder* _tmp18_;
	GearyImapDBFolder* _tmp19_;
	GeeMap* _tmp20_;
	GeeSet* _tmp21_;
	GeeSet* _tmp22_;
	GeeSet* _tmp23_;
	GearyEmailFlags* _tmp24_;
	GearyEmailFlags* _tmp25_;
	GCancellable* _tmp26_;
	gint _tmp27_;
	GeeList* _tmp28_;
	GearyImapEngineMinimalFolder* _tmp29_;
	GearyImapDBFolder* _tmp30_;
	GearyImapDBFolder* _tmp31_;
	GeeList* _tmp32_;
	GCancellable* _tmp33_;
	GeeList* _tmp34_;
	GeeList* _tmp35_;
	GeeMap* map;
	GearyImapEngineMinimalFolder* _tmp36_;
	GearyImapDBFolder* _tmp37_;
	GearyImapDBFolder* _tmp38_;
	GeeMap* _tmp39_;
	GeeSet* _tmp40_;
	GeeSet* _tmp41_;
	GeeSet* _tmp42_;
	GCancellable* _tmp43_;
	GeeMap* _tmp44_;
	GeeMap* _tmp45_;
	gboolean _tmp46_;
	GeeMap* _tmp47_;
	GeeMap* _tmp48_;
	gint _tmp49_;
	gint _tmp50_;
	GearyImapEngineMinimalFolder* _tmp51_;
	GeeMap* _tmp52_;
	GError* _inner_error0_;
};

struct _GearyImapEngineMarkEmailReplayRemoteAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineMarkEmail* self;
	GearyImapFolderSession* remote;
	GeeList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	GeeList* msg_sets;
	GeeList* _tmp3_;
	GeeList* _tmp4_;
	GeeList* _tmp5_;
	GearyEmailFlags* _tmp6_;
	GearyEmailFlags* _tmp7_;
	GCancellable* _tmp8_;
	GError* _inner_error0_;
};

struct _GearyImapEngineMarkEmailBackoutLocalAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineMarkEmail* self;
	GeeMap* _tmp0_;
	GearyImapEngineMinimalFolder* _tmp1_;
	GearyImapDBFolder* _tmp2_;
	GearyImapDBFolder* _tmp3_;
	GeeMap* _tmp4_;
	GCancellable* _tmp5_;
	GError* _inner_error0_;
};

static gint GearyImapEngineMarkEmail_private_offset;
static gpointer geary_imap_engine_mark_email_parent_class = NULL;

VALA_EXTERN GType geary_imap_engine_replay_operation_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_db_email_identifier_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_engine_replay_operation_status_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_folder_session_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_engine_send_replay_operation_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_engine_mark_email_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_engine_minimal_folder_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void geary_imap_engine_replay_operation_notify_remote_removed_ids (GearyImapEngineReplayOperation* self,
                                                                   GeeCollection* ids);
VALA_EXTERN void geary_imap_engine_replay_operation_replay_local_async (GearyImapEngineReplayOperation* self,
                                                            GAsyncReadyCallback _callback_,
                                                            gpointer _user_data_);
VALA_EXTERN GearyImapEngineReplayOperationStatus geary_imap_engine_replay_operation_replay_local_finish (GearyImapEngineReplayOperation* self,
                                                                                             GAsyncResult* _res_,
                                                                                             GError** error);
VALA_EXTERN void geary_imap_engine_replay_operation_replay_remote_async (GearyImapEngineReplayOperation* self,
                                                             GearyImapFolderSession* remote,
                                                             GAsyncReadyCallback _callback_,
                                                             gpointer _user_data_);
VALA_EXTERN void geary_imap_engine_replay_operation_replay_remote_finish (GearyImapEngineReplayOperation* self,
                                                              GAsyncResult* _res_,
                                                              GError** error);
VALA_EXTERN 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);
VALA_EXTERN gchar* geary_imap_engine_replay_operation_describe_state (GearyImapEngineReplayOperation* self);
VALA_EXTERN gint geary_imap_engine_mark_email_get_unread_change (GearyImapEngineMarkEmail* self);
static void geary_imap_engine_mark_email_set_unread_change (GearyImapEngineMarkEmail* self,
                                                     gint value);
VALA_EXTERN GearyImapEngineMarkEmail* geary_imap_engine_mark_email_new (GearyImapEngineMinimalFolder* engine,
                                                            GeeCollection* to_mark,
                                                            GearyEmailFlags* flags_to_add,
                                                            GearyEmailFlags* flags_to_remove,
                                                            GCancellable* cancellable);
VALA_EXTERN GearyImapEngineMarkEmail* geary_imap_engine_mark_email_construct (GType object_type,
                                                                  GearyImapEngineMinimalFolder* engine,
                                                                  GeeCollection* to_mark,
                                                                  GearyEmailFlags* flags_to_add,
                                                                  GearyEmailFlags* flags_to_remove,
                                                                  GCancellable* cancellable);
VALA_EXTERN GType geary_imap_engine_replay_operation_on_error_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GearyImapEngineSendReplayOperation* geary_imap_engine_send_replay_operation_construct (GType object_type,
                                                                                       const gchar* name,
                                                                                       GearyImapEngineReplayOperationOnError on_remote_error);
static void geary_imap_engine_mark_email_real_notify_remote_removed_ids (GearyImapEngineReplayOperation* base,
                                                                  GeeCollection* ids);
static void geary_imap_engine_mark_email_real_replay_local_async_data_free (gpointer _data);
static void geary_imap_engine_mark_email_real_replay_local_async (GearyImapEngineReplayOperation* base,
                                                           GAsyncReadyCallback _callback_,
                                                           gpointer _user_data_);
static gboolean geary_imap_engine_mark_email_real_replay_local_async_co (GearyImapEngineMarkEmailReplayLocalAsyncData* _data_);
VALA_EXTERN GType geary_imap_db_folder_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GearyImapDBFolder* geary_imap_engine_minimal_folder_get_local_folder (GearyImapEngineMinimalFolder* self);
VALA_EXTERN void geary_imap_db_folder_get_email_flags_async (GearyImapDBFolder* self,
                                                 GeeCollection* ids,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
VALA_EXTERN GeeMap* geary_imap_db_folder_get_email_flags_finish (GearyImapDBFolder* self,
                                                     GAsyncResult* _res_,
                                                     GError** error);
static void geary_imap_engine_mark_email_replay_local_async_ready (GObject* source_object,
                                                            GAsyncResult* _res_,
                                                            gpointer _user_data_);
VALA_EXTERN void geary_imap_db_folder_mark_email_async (GearyImapDBFolder* self,
                                            GeeCollection* to_mark,
                                            GearyEmailFlags* flags_to_add,
                                            GearyEmailFlags* flags_to_remove,
                                            GCancellable* cancellable,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_);
VALA_EXTERN gint geary_imap_db_folder_mark_email_finish (GearyImapDBFolder* self,
                                             GAsyncResult* _res_,
                                             GError** error);
VALA_EXTERN void geary_imap_db_folder_get_email_uids_async (GearyImapDBFolder* self,
                                                GeeCollection* ids,
                                                GCancellable* cancellable,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_);
VALA_EXTERN GeeList* geary_imap_db_folder_get_email_uids_finish (GearyImapDBFolder* self,
                                                     GAsyncResult* _res_,
                                                     GError** error);
VALA_EXTERN void geary_imap_engine_minimal_folder_replay_notify_email_flags_changed (GearyImapEngineMinimalFolder* self,
                                                                         GeeMap* flag_map);
static void geary_imap_engine_mark_email_real_replay_remote_async_data_free (gpointer _data);
static void geary_imap_engine_mark_email_real_replay_remote_async (GearyImapEngineReplayOperation* base,
                                                            GearyImapFolderSession* remote,
                                                            GAsyncReadyCallback _callback_,
                                                            gpointer _user_data_);
static gboolean geary_imap_engine_mark_email_real_replay_remote_async_co (GearyImapEngineMarkEmailReplayRemoteAsyncData* _data_);
VALA_EXTERN void geary_imap_folder_session_mark_email_async (GearyImapFolderSession* self,
                                                 GeeList* msg_sets,
                                                 GearyEmailFlags* flags_to_add,
                                                 GearyEmailFlags* flags_to_remove,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
VALA_EXTERN void geary_imap_folder_session_mark_email_finish (GearyImapFolderSession* self,
                                                  GAsyncResult* _res_,
                                                  GError** error);
static void geary_imap_engine_mark_email_replay_remote_async_ready (GObject* source_object,
                                                             GAsyncResult* _res_,
                                                             gpointer _user_data_);
static void geary_imap_engine_mark_email_real_backout_local_async_data_free (gpointer _data);
static void geary_imap_engine_mark_email_real_backout_local_async (GearyImapEngineReplayOperation* base,
                                                            GAsyncReadyCallback _callback_,
                                                            gpointer _user_data_);
static gboolean geary_imap_engine_mark_email_real_backout_local_async_co (GearyImapEngineMarkEmailBackoutLocalAsyncData* _data_);
VALA_EXTERN void geary_imap_db_folder_set_email_flags_async (GearyImapDBFolder* self,
                                                 GeeMap* map,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
VALA_EXTERN void geary_imap_db_folder_set_email_flags_finish (GearyImapDBFolder* self,
                                                  GAsyncResult* _res_,
                                                  GError** error);
static void geary_imap_engine_mark_email_backout_local_async_ready (GObject* source_object,
                                                             GAsyncResult* _res_,
                                                             gpointer _user_data_);
static gchar* geary_imap_engine_mark_email_real_describe_state (GearyImapEngineReplayOperation* base);
static void geary_imap_engine_mark_email_finalize (GObject * obj);
static GType geary_imap_engine_mark_email_get_type_once (void);
static void _vala_geary_imap_engine_mark_email_get_property (GObject * object,
                                                      guint property_id,
                                                      GValue * value,
                                                      GParamSpec * pspec);
static void _vala_geary_imap_engine_mark_email_set_property (GObject * object,
                                                      guint property_id,
                                                      const GValue * value,
                                                      GParamSpec * pspec);

static inline gpointer
geary_imap_engine_mark_email_get_instance_private (GearyImapEngineMarkEmail* self)
{
	return G_STRUCT_MEMBER_P (self, GearyImapEngineMarkEmail_private_offset);
}

gint
geary_imap_engine_mark_email_get_unread_change (GearyImapEngineMarkEmail* self)
{
	gint result;
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_MARK_EMAIL (self), -1);
	result = self->priv->_unread_change;
	return result;
}

static void
geary_imap_engine_mark_email_set_unread_change (GearyImapEngineMarkEmail* self,
                                                gint value)
{
	gint old_value;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_MARK_EMAIL (self));
	old_value = geary_imap_engine_mark_email_get_unread_change (self);
	if (old_value != value) {
		self->priv->_unread_change = value;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_engine_mark_email_properties[GEARY_IMAP_ENGINE_MARK_EMAIL_UNREAD_CHANGE_PROPERTY]);
	}
}

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

GearyImapEngineMarkEmail*
geary_imap_engine_mark_email_construct (GType object_type,
                                        GearyImapEngineMinimalFolder* engine,
                                        GeeCollection* to_mark,
                                        GearyEmailFlags* flags_to_add,
                                        GearyEmailFlags* flags_to_remove,
                                        GCancellable* cancellable)
{
	GearyImapEngineMarkEmail * self = NULL;
	GearyImapEngineMinimalFolder* _tmp0_;
	GeeList* _tmp1_;
	GearyEmailFlags* _tmp2_;
	GearyEmailFlags* _tmp3_;
	GCancellable* _tmp4_;
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_MINIMAL_FOLDER (engine), NULL);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (to_mark, GEE_TYPE_COLLECTION), NULL);
	g_return_val_if_fail ((flags_to_add == NULL) || GEARY_IS_EMAIL_FLAGS (flags_to_add), NULL);
	g_return_val_if_fail ((flags_to_remove == NULL) || GEARY_IS_EMAIL_FLAGS (flags_to_remove), NULL);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), NULL);
	self = (GearyImapEngineMarkEmail*) geary_imap_engine_send_replay_operation_construct (object_type, "MarkEmail", GEARY_IMAP_ENGINE_REPLAY_OPERATION_ON_ERROR_RETRY);
	_tmp0_ = _g_object_ref0 (engine);
	_g_object_unref0 (self->priv->engine);
	self->priv->engine = _tmp0_;
	_tmp1_ = self->priv->to_mark;
	gee_collection_add_all (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEE_TYPE_COLLECTION, GeeCollection), to_mark);
	_tmp2_ = _g_object_ref0 (flags_to_add);
	_g_object_unref0 (self->priv->flags_to_add);
	self->priv->flags_to_add = _tmp2_;
	_tmp3_ = _g_object_ref0 (flags_to_remove);
	_g_object_unref0 (self->priv->flags_to_remove);
	self->priv->flags_to_remove = _tmp3_;
	_tmp4_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (self->priv->cancellable);
	self->priv->cancellable = _tmp4_;
	return self;
}

GearyImapEngineMarkEmail*
geary_imap_engine_mark_email_new (GearyImapEngineMinimalFolder* engine,
                                  GeeCollection* to_mark,
                                  GearyEmailFlags* flags_to_add,
                                  GearyEmailFlags* flags_to_remove,
                                  GCancellable* cancellable)
{
	return geary_imap_engine_mark_email_construct (GEARY_IMAP_ENGINE_TYPE_MARK_EMAIL, engine, to_mark, flags_to_add, flags_to_remove, cancellable);
}

static void
geary_imap_engine_mark_email_real_notify_remote_removed_ids (GearyImapEngineReplayOperation* base,
                                                             GeeCollection* ids)
{
	GearyImapEngineMarkEmail * self;
	GeeMap* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_TYPE_MARK_EMAIL, GearyImapEngineMarkEmail);
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION));
	_tmp0_ = self->priv->original_flags;
	if (_tmp0_ != NULL) {
		GeeMap* _tmp1_;
		_tmp1_ = self->priv->original_flags;
		geary_collection_map_unset_all_keys (GEARY_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEARY_TYPE_EMAIL_FLAGS, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp1_, ids);
	}
}

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

static void
geary_imap_engine_mark_email_real_replay_local_async (GearyImapEngineReplayOperation* base,
                                                      GAsyncReadyCallback _callback_,
                                                      gpointer _user_data_)
{
	GearyImapEngineMarkEmail * self;
	GearyImapEngineMarkEmailReplayLocalAsyncData* _data_;
	GearyImapEngineMarkEmail* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_TYPE_MARK_EMAIL, GearyImapEngineMarkEmail);
	_data_ = g_slice_new0 (GearyImapEngineMarkEmailReplayLocalAsyncData);
	_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_mark_email_real_replay_local_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	geary_imap_engine_mark_email_real_replay_local_async_co (_data_);
}

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

static void
geary_imap_engine_mark_email_replay_local_async_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_)
{
	GearyImapEngineMarkEmailReplayLocalAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_engine_mark_email_real_replay_local_async_co (_data_);
}

static gboolean
geary_imap_engine_mark_email_real_replay_local_async_co (GearyImapEngineMarkEmailReplayLocalAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		case 4:
		goto _state_4;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->to_mark;
	_data_->_tmp1_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp2_ = _data_->_tmp1_;
	if (_data_->_tmp2_ == 0) {
		_data_->result = GEARY_IMAP_ENGINE_REPLAY_OPERATION_STATUS_COMPLETED;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp4_ = _data_->self->priv->engine;
	_data_->_tmp5_ = geary_imap_engine_minimal_folder_get_local_folder (_data_->_tmp4_);
	_data_->_tmp6_ = _data_->_tmp5_;
	_data_->_tmp7_ = _data_->self->priv->to_mark;
	_data_->_tmp8_ = _data_->self->priv->cancellable;
	_data_->_state_ = 1;
	geary_imap_db_folder_get_email_flags_async (_data_->_tmp6_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp7_, GEE_TYPE_COLLECTION, GeeCollection), _data_->_tmp8_, geary_imap_engine_mark_email_replay_local_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp9_ = geary_imap_db_folder_get_email_flags_finish (_data_->_tmp6_, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp3_ = _data_->_tmp9_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp10_ = _data_->_tmp3_;
	_data_->_tmp3_ = NULL;
	_g_object_unref0 (_data_->self->priv->original_flags);
	_data_->self->priv->original_flags = _data_->_tmp10_;
	_data_->_tmp12_ = _data_->self->priv->original_flags;
	if (_data_->_tmp12_ == NULL) {
		_data_->_tmp11_ = TRUE;
	} else {
		_data_->_tmp13_ = _data_->self->priv->original_flags;
		_data_->_tmp14_ = gee_map_get_size (_data_->_tmp13_);
		_data_->_tmp15_ = _data_->_tmp14_;
		_data_->_tmp11_ = _data_->_tmp15_ == 0;
	}
	if (_data_->_tmp11_) {
		_data_->result = GEARY_IMAP_ENGINE_REPLAY_OPERATION_STATUS_COMPLETED;
		_g_object_unref0 (_data_->_tmp3_);
		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_->_tmp17_ = _data_->self->priv->engine;
	_data_->_tmp18_ = geary_imap_engine_minimal_folder_get_local_folder (_data_->_tmp17_);
	_data_->_tmp19_ = _data_->_tmp18_;
	_data_->_tmp20_ = _data_->self->priv->original_flags;
	_data_->_tmp21_ = gee_map_get_keys (_data_->_tmp20_);
	_data_->_tmp22_ = _data_->_tmp21_;
	_data_->_tmp23_ = _data_->_tmp22_;
	_data_->_tmp24_ = _data_->self->priv->flags_to_add;
	_data_->_tmp25_ = _data_->self->priv->flags_to_remove;
	_data_->_tmp26_ = _data_->self->priv->cancellable;
	_data_->_state_ = 2;
	geary_imap_db_folder_mark_email_async (_data_->_tmp19_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp23_, GEE_TYPE_COLLECTION, GeeCollection), _data_->_tmp24_, _data_->_tmp25_, _data_->_tmp26_, geary_imap_engine_mark_email_replay_local_async_ready, _data_);
	return FALSE;
	_state_2:
	_data_->_tmp27_ = geary_imap_db_folder_mark_email_finish (_data_->_tmp19_, _data_->_res_, &_data_->_inner_error0_);
	_g_object_unref0 (_data_->_tmp23_);
	_data_->_tmp16_ = _data_->_tmp27_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->_tmp3_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	geary_imap_engine_mark_email_set_unread_change (_data_->self, _data_->_tmp16_);
	_data_->_tmp29_ = _data_->self->priv->engine;
	_data_->_tmp30_ = geary_imap_engine_minimal_folder_get_local_folder (_data_->_tmp29_);
	_data_->_tmp31_ = _data_->_tmp30_;
	_data_->_tmp32_ = _data_->self->priv->to_mark;
	_data_->_tmp33_ = _data_->self->priv->cancellable;
	_data_->_state_ = 3;
	geary_imap_db_folder_get_email_uids_async (_data_->_tmp31_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp32_, GEE_TYPE_COLLECTION, GeeCollection), _data_->_tmp33_, geary_imap_engine_mark_email_replay_local_async_ready, _data_);
	return FALSE;
	_state_3:
	_data_->_tmp34_ = geary_imap_db_folder_get_email_uids_finish (_data_->_tmp31_, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp28_ = _data_->_tmp34_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->_tmp3_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp35_ = _data_->_tmp28_;
	_data_->_tmp28_ = NULL;
	_g_object_unref0 (_data_->self->priv->to_mark_uids);
	_data_->self->priv->to_mark_uids = _data_->_tmp35_;
	_data_->_tmp36_ = _data_->self->priv->engine;
	_data_->_tmp37_ = geary_imap_engine_minimal_folder_get_local_folder (_data_->_tmp36_);
	_data_->_tmp38_ = _data_->_tmp37_;
	_data_->_tmp39_ = _data_->self->priv->original_flags;
	_data_->_tmp40_ = gee_map_get_keys (_data_->_tmp39_);
	_data_->_tmp41_ = _data_->_tmp40_;
	_data_->_tmp42_ = _data_->_tmp41_;
	_data_->_tmp43_ = _data_->self->priv->cancellable;
	_data_->_state_ = 4;
	geary_imap_db_folder_get_email_flags_async (_data_->_tmp38_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp42_, GEE_TYPE_COLLECTION, GeeCollection), _data_->_tmp43_, geary_imap_engine_mark_email_replay_local_async_ready, _data_);
	return FALSE;
	_state_4:
	_data_->_tmp44_ = geary_imap_db_folder_get_email_flags_finish (_data_->_tmp38_, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp45_ = _data_->_tmp44_;
	_g_object_unref0 (_data_->_tmp42_);
	_data_->map = _data_->_tmp45_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->_tmp28_);
		_g_object_unref0 (_data_->_tmp3_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp47_ = _data_->map;
	if (_data_->_tmp47_ != NULL) {
		_data_->_tmp48_ = _data_->map;
		_data_->_tmp49_ = gee_map_get_size (_data_->_tmp48_);
		_data_->_tmp50_ = _data_->_tmp49_;
		_data_->_tmp46_ = _data_->_tmp50_ > 0;
	} else {
		_data_->_tmp46_ = FALSE;
	}
	if (_data_->_tmp46_) {
		_data_->_tmp51_ = _data_->self->priv->engine;
		_data_->_tmp52_ = _data_->map;
		geary_imap_engine_minimal_folder_replay_notify_email_flags_changed (_data_->_tmp51_, _data_->_tmp52_);
	}
	_data_->result = GEARY_IMAP_ENGINE_REPLAY_OPERATION_STATUS_CONTINUE;
	_g_object_unref0 (_data_->map);
	_g_object_unref0 (_data_->_tmp28_);
	_g_object_unref0 (_data_->_tmp3_);
	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_mark_email_real_replay_remote_async_data_free (gpointer _data)
{
	GearyImapEngineMarkEmailReplayRemoteAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->remote);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapEngineMarkEmailReplayRemoteAsyncData, _data_);
}

static void
geary_imap_engine_mark_email_real_replay_remote_async (GearyImapEngineReplayOperation* base,
                                                       GearyImapFolderSession* remote,
                                                       GAsyncReadyCallback _callback_,
                                                       gpointer _user_data_)
{
	GearyImapEngineMarkEmail * self;
	GearyImapEngineMarkEmailReplayRemoteAsyncData* _data_;
	GearyImapEngineMarkEmail* _tmp0_;
	GearyImapFolderSession* _tmp1_;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (remote));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_TYPE_MARK_EMAIL, GearyImapEngineMarkEmail);
	_data_ = g_slice_new0 (GearyImapEngineMarkEmailReplayRemoteAsyncData);
	_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_mark_email_real_replay_remote_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (remote);
	_g_object_unref0 (_data_->remote);
	_data_->remote = _tmp1_;
	geary_imap_engine_mark_email_real_replay_remote_async_co (_data_);
}

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

static void
geary_imap_engine_mark_email_replay_remote_async_ready (GObject* source_object,
                                                        GAsyncResult* _res_,
                                                        gpointer _user_data_)
{
	GearyImapEngineMarkEmailReplayRemoteAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_engine_mark_email_real_replay_remote_async_co (_data_);
}

static gboolean
geary_imap_engine_mark_email_real_replay_remote_async_co (GearyImapEngineMarkEmailReplayRemoteAsyncData* _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->to_mark_uids;
	_data_->_tmp1_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp2_ = _data_->_tmp1_;
	if (_data_->_tmp2_ > 0) {
		_data_->_tmp3_ = _data_->self->priv->to_mark_uids;
		_data_->_tmp4_ = geary_imap_message_set_uid_sparse (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp3_, GEE_TYPE_COLLECTION, GeeCollection));
		_data_->msg_sets = _data_->_tmp4_;
		_data_->_tmp5_ = _data_->msg_sets;
		_data_->_tmp6_ = _data_->self->priv->flags_to_add;
		_data_->_tmp7_ = _data_->self->priv->flags_to_remove;
		_data_->_tmp8_ = _data_->self->priv->cancellable;
		_data_->_state_ = 1;
		geary_imap_folder_session_mark_email_async (_data_->remote, _data_->_tmp5_, _data_->_tmp6_, _data_->_tmp7_, _data_->_tmp8_, geary_imap_engine_mark_email_replay_remote_async_ready, _data_);
		return FALSE;
		_state_1:
		geary_imap_folder_session_mark_email_finish (_data_->remote, _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_->msg_sets);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_g_object_unref0 (_data_->msg_sets);
	}
	geary_imap_engine_mark_email_set_unread_change (_data_->self, 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 void
geary_imap_engine_mark_email_real_backout_local_async_data_free (gpointer _data)
{
	GearyImapEngineMarkEmailBackoutLocalAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapEngineMarkEmailBackoutLocalAsyncData, _data_);
}

static void
geary_imap_engine_mark_email_real_backout_local_async (GearyImapEngineReplayOperation* base,
                                                       GAsyncReadyCallback _callback_,
                                                       gpointer _user_data_)
{
	GearyImapEngineMarkEmail * self;
	GearyImapEngineMarkEmailBackoutLocalAsyncData* _data_;
	GearyImapEngineMarkEmail* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_TYPE_MARK_EMAIL, GearyImapEngineMarkEmail);
	_data_ = g_slice_new0 (GearyImapEngineMarkEmailBackoutLocalAsyncData);
	_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_mark_email_real_backout_local_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	geary_imap_engine_mark_email_real_backout_local_async_co (_data_);
}

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

static void
geary_imap_engine_mark_email_backout_local_async_ready (GObject* source_object,
                                                        GAsyncResult* _res_,
                                                        gpointer _user_data_)
{
	GearyImapEngineMarkEmailBackoutLocalAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_engine_mark_email_real_backout_local_async_co (_data_);
}

static gboolean
geary_imap_engine_mark_email_real_backout_local_async_co (GearyImapEngineMarkEmailBackoutLocalAsyncData* _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->original_flags;
	if (_data_->_tmp0_ != NULL) {
		_data_->_tmp1_ = _data_->self->priv->engine;
		_data_->_tmp2_ = geary_imap_engine_minimal_folder_get_local_folder (_data_->_tmp1_);
		_data_->_tmp3_ = _data_->_tmp2_;
		_data_->_tmp4_ = _data_->self->priv->original_flags;
		_data_->_tmp5_ = _data_->self->priv->cancellable;
		_data_->_state_ = 1;
		geary_imap_db_folder_set_email_flags_async (_data_->_tmp3_, _data_->_tmp4_, _data_->_tmp5_, geary_imap_engine_mark_email_backout_local_async_ready, _data_);
		return FALSE;
		_state_1:
		geary_imap_db_folder_set_email_flags_finish (_data_->_tmp3_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static gchar*
geary_imap_engine_mark_email_real_describe_state (GearyImapEngineReplayOperation* base)
{
	GearyImapEngineMarkEmail * self;
	gchar* _tmp0_ = NULL;
	GearyEmailFlags* _tmp1_;
	gchar* _tmp5_ = NULL;
	GearyEmailFlags* _tmp6_;
	GeeList* _tmp10_;
	gint _tmp11_;
	gint _tmp12_;
	gchar* _tmp13_;
	gchar* result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_TYPE_MARK_EMAIL, GearyImapEngineMarkEmail);
	_tmp1_ = self->priv->flags_to_add;
	if (_tmp1_ != NULL) {
		GearyEmailFlags* _tmp2_;
		gchar* _tmp3_;
		_tmp2_ = self->priv->flags_to_add;
		_tmp3_ = geary_named_flags_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags));
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp3_;
	} else {
		gchar* _tmp4_;
		_tmp4_ = g_strdup ("(none)");
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp4_;
	}
	_tmp6_ = self->priv->flags_to_remove;
	if (_tmp6_ != NULL) {
		GearyEmailFlags* _tmp7_;
		gchar* _tmp8_;
		_tmp7_ = self->priv->flags_to_remove;
		_tmp8_ = geary_named_flags_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags));
		_g_free0 (_tmp5_);
		_tmp5_ = _tmp8_;
	} else {
		gchar* _tmp9_;
		_tmp9_ = g_strdup ("(none)");
		_g_free0 (_tmp5_);
		_tmp5_ = _tmp9_;
	}
	_tmp10_ = self->priv->to_mark;
	_tmp11_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp10_, GEE_TYPE_COLLECTION, GeeCollection));
	_tmp12_ = _tmp11_;
	_tmp13_ = g_strdup_printf ("to_mark=%d flags_to_add=%s flags_to_remove=%s", _tmp12_, _tmp0_, _tmp5_);
	result = _tmp13_;
	_g_free0 (_tmp5_);
	_g_free0 (_tmp0_);
	return result;
}

static void
geary_imap_engine_mark_email_class_init (GearyImapEngineMarkEmailClass * klass,
                                         gpointer klass_data)
{
	geary_imap_engine_mark_email_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GearyImapEngineMarkEmail_private_offset);
	((GearyImapEngineReplayOperationClass *) klass)->notify_remote_removed_ids = (void (*) (GearyImapEngineReplayOperation*, GeeCollection*)) geary_imap_engine_mark_email_real_notify_remote_removed_ids;
	((GearyImapEngineReplayOperationClass *) klass)->replay_local_async = (void (*) (GearyImapEngineReplayOperation*, GAsyncReadyCallback, gpointer)) geary_imap_engine_mark_email_real_replay_local_async;
	((GearyImapEngineReplayOperationClass *) klass)->replay_local_finish = (GearyImapEngineReplayOperationStatus (*) (GearyImapEngineReplayOperation*, GAsyncResult*, GError**)) geary_imap_engine_mark_email_replay_local_finish;
	((GearyImapEngineReplayOperationClass *) klass)->replay_remote_async = (void (*) (GearyImapEngineReplayOperation*, GearyImapFolderSession*, GAsyncReadyCallback, gpointer)) geary_imap_engine_mark_email_real_replay_remote_async;
	((GearyImapEngineReplayOperationClass *) klass)->replay_remote_finish = (void (*) (GearyImapEngineReplayOperation*, GAsyncResult*, GError**)) geary_imap_engine_mark_email_replay_remote_finish;
	((GearyImapEngineReplayOperationClass *) klass)->backout_local_async = (void (*) (GearyImapEngineReplayOperation*, GAsyncReadyCallback, gpointer)) geary_imap_engine_mark_email_real_backout_local_async;
	((GearyImapEngineReplayOperationClass *) klass)->backout_local_finish = (void (*) (GearyImapEngineReplayOperation*, GAsyncResult*, GError**)) geary_imap_engine_mark_email_backout_local_finish;
	((GearyImapEngineReplayOperationClass *) klass)->describe_state = (gchar* (*) (GearyImapEngineReplayOperation*)) geary_imap_engine_mark_email_real_describe_state;
	G_OBJECT_CLASS (klass)->get_property = _vala_geary_imap_engine_mark_email_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_geary_imap_engine_mark_email_set_property;
	G_OBJECT_CLASS (klass)->finalize = geary_imap_engine_mark_email_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_ENGINE_MARK_EMAIL_UNREAD_CHANGE_PROPERTY, geary_imap_engine_mark_email_properties[GEARY_IMAP_ENGINE_MARK_EMAIL_UNREAD_CHANGE_PROPERTY] = g_param_spec_int ("unread-change", "unread-change", "unread-change", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
geary_imap_engine_mark_email_instance_init (GearyImapEngineMarkEmail * self,
                                            gpointer klass)
{
	GeeArrayList* _tmp0_;
	GeeArrayList* _tmp1_;
	self->priv = geary_imap_engine_mark_email_get_instance_private (self);
	_tmp0_ = gee_array_list_new (GEARY_IMAP_DB_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->priv->to_mark = G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEE_TYPE_LIST, GeeList);
	_tmp1_ = gee_array_list_new (GEARY_IMAP_TYPE_UID, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->priv->to_mark_uids = G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEE_TYPE_LIST, GeeList);
	self->priv->original_flags = NULL;
	self->priv->_unread_change = 0;
}

static void
geary_imap_engine_mark_email_finalize (GObject * obj)
{
	GearyImapEngineMarkEmail * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_IMAP_ENGINE_TYPE_MARK_EMAIL, GearyImapEngineMarkEmail);
	_g_object_unref0 (self->priv->engine);
	_g_object_unref0 (self->priv->to_mark);
	_g_object_unref0 (self->priv->to_mark_uids);
	_g_object_unref0 (self->priv->flags_to_add);
	_g_object_unref0 (self->priv->flags_to_remove);
	_g_object_unref0 (self->priv->original_flags);
	_g_object_unref0 (self->priv->cancellable);
	G_OBJECT_CLASS (geary_imap_engine_mark_email_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
geary_imap_engine_mark_email_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapEngineMarkEmailClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_engine_mark_email_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapEngineMarkEmail), 0, (GInstanceInitFunc) geary_imap_engine_mark_email_instance_init, NULL };
	GType geary_imap_engine_mark_email_type_id;
	geary_imap_engine_mark_email_type_id = g_type_register_static (GEARY_IMAP_ENGINE_TYPE_SEND_REPLAY_OPERATION, "GearyImapEngineMarkEmail", &g_define_type_info, 0);
	GearyImapEngineMarkEmail_private_offset = g_type_add_instance_private (geary_imap_engine_mark_email_type_id, sizeof (GearyImapEngineMarkEmailPrivate));
	return geary_imap_engine_mark_email_type_id;
}

GType
geary_imap_engine_mark_email_get_type (void)
{
	static gsize geary_imap_engine_mark_email_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_engine_mark_email_type_id__once)) {
		GType geary_imap_engine_mark_email_type_id;
		geary_imap_engine_mark_email_type_id = geary_imap_engine_mark_email_get_type_once ();
		g_once_init_leave (&geary_imap_engine_mark_email_type_id__once, geary_imap_engine_mark_email_type_id);
	}
	return geary_imap_engine_mark_email_type_id__once;
}

static void
_vala_geary_imap_engine_mark_email_get_property (GObject * object,
                                                 guint property_id,
                                                 GValue * value,
                                                 GParamSpec * pspec)
{
	GearyImapEngineMarkEmail * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_ENGINE_TYPE_MARK_EMAIL, GearyImapEngineMarkEmail);
	switch (property_id) {
		case GEARY_IMAP_ENGINE_MARK_EMAIL_UNREAD_CHANGE_PROPERTY:
		g_value_set_int (value, geary_imap_engine_mark_email_get_unread_change (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_geary_imap_engine_mark_email_set_property (GObject * object,
                                                 guint property_id,
                                                 const GValue * value,
                                                 GParamSpec * pspec)
{
	GearyImapEngineMarkEmail * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_ENGINE_TYPE_MARK_EMAIL, GearyImapEngineMarkEmail);
	switch (property_id) {
		case GEARY_IMAP_ENGINE_MARK_EMAIL_UNREAD_CHANGE_PROPERTY:
		geary_imap_engine_mark_email_set_unread_change (self, g_value_get_int (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

