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

/*
 * 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 "util.h"
#include "geary-engine.h"
#include <glib-object.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gee.h>

#define MAIL_MERGE_FOLDER_EMAIL_IDENTIFIER_VARIANT_TYPE "(y(x))"

#define MAIL_MERGE_FOLDER_TYPE_FOLDER_PROPERTIES (mail_merge_folder_folder_properties_get_type ())
#define MAIL_MERGE_FOLDER_FOLDER_PROPERTIES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAIL_MERGE_FOLDER_TYPE_FOLDER_PROPERTIES, MailMergeFolderFolderProperties))
#define MAIL_MERGE_FOLDER_FOLDER_PROPERTIES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MAIL_MERGE_FOLDER_TYPE_FOLDER_PROPERTIES, MailMergeFolderFolderPropertiesClass))
#define MAIL_MERGE_FOLDER_IS_FOLDER_PROPERTIES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MAIL_MERGE_FOLDER_TYPE_FOLDER_PROPERTIES))
#define MAIL_MERGE_FOLDER_IS_FOLDER_PROPERTIES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MAIL_MERGE_FOLDER_TYPE_FOLDER_PROPERTIES))
#define MAIL_MERGE_FOLDER_FOLDER_PROPERTIES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MAIL_MERGE_FOLDER_TYPE_FOLDER_PROPERTIES, MailMergeFolderFolderPropertiesClass))

typedef struct _MailMergeFolderFolderProperties MailMergeFolderFolderProperties;
typedef struct _MailMergeFolderFolderPropertiesClass MailMergeFolderFolderPropertiesClass;
enum  {
	MAIL_MERGE_FOLDER_0_PROPERTY,
	MAIL_MERGE_FOLDER_ACCOUNT_PROPERTY,
	MAIL_MERGE_FOLDER_PROPERTIES_PROPERTY,
	MAIL_MERGE_FOLDER_PATH_PROPERTY,
	MAIL_MERGE_FOLDER_USED_AS_PROPERTY,
	MAIL_MERGE_FOLDER_DATA_LOCATION_PROPERTY,
	MAIL_MERGE_FOLDER_DATA_DISPLAY_NAME_PROPERTY,
	MAIL_MERGE_FOLDER_EMAIL_SENT_PROPERTY,
	MAIL_MERGE_FOLDER_EMAIL_TOTAL_PROPERTY,
	MAIL_MERGE_FOLDER_IS_SENDING_PROPERTY,
	MAIL_MERGE_FOLDER_NUM_PROPERTIES
};
static GParamSpec* mail_merge_folder_properties[MAIL_MERGE_FOLDER_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))
typedef struct _MailMergeFolderNewData MailMergeFolderNewData;
typedef struct _MailMergeFolderCloseAsyncData MailMergeFolderCloseAsyncData;
typedef struct _MailMergeFolderContainsIdentifiersData MailMergeFolderContainsIdentifiersData;
typedef struct _MailMergeFolderFetchEmailAsyncData MailMergeFolderFetchEmailAsyncData;

#define MAIL_MERGE_FOLDER_TYPE_EMAIL_IDENTIFIER (mail_merge_folder_email_identifier_get_type ())
#define MAIL_MERGE_FOLDER_EMAIL_IDENTIFIER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAIL_MERGE_FOLDER_TYPE_EMAIL_IDENTIFIER, MailMergeFolderEmailIdentifier))
#define MAIL_MERGE_FOLDER_EMAIL_IDENTIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MAIL_MERGE_FOLDER_TYPE_EMAIL_IDENTIFIER, MailMergeFolderEmailIdentifierClass))
#define MAIL_MERGE_FOLDER_IS_EMAIL_IDENTIFIER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MAIL_MERGE_FOLDER_TYPE_EMAIL_IDENTIFIER))
#define MAIL_MERGE_FOLDER_IS_EMAIL_IDENTIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MAIL_MERGE_FOLDER_TYPE_EMAIL_IDENTIFIER))
#define MAIL_MERGE_FOLDER_EMAIL_IDENTIFIER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MAIL_MERGE_FOLDER_TYPE_EMAIL_IDENTIFIER, MailMergeFolderEmailIdentifierClass))

typedef struct _MailMergeFolderEmailIdentifier MailMergeFolderEmailIdentifier;
typedef struct _MailMergeFolderEmailIdentifierClass MailMergeFolderEmailIdentifierClass;
typedef struct _MailMergeFolderListEmailByIdAsyncData MailMergeFolderListEmailByIdAsyncData;
typedef struct _MailMergeFolderListEmailBySparseIdAsyncData MailMergeFolderListEmailBySparseIdAsyncData;
typedef struct _Block1Data Block1Data;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _MailMergeFolderLoadDataData MailMergeFolderLoadDataData;
typedef struct _MailMergeFolderLoadTemplateData MailMergeFolderLoadTemplateData;
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
#define _g_time_zone_unref0(var) ((var == NULL) ? NULL : (var = (g_time_zone_unref (var), NULL)))
typedef struct _MailMergeFolderSendLoopData MailMergeFolderSendLoopData;
typedef struct _MailMergeFolderEmailIdentifierPrivate MailMergeFolderEmailIdentifierPrivate;
enum  {
	MAIL_MERGE_FOLDER_EMAIL_IDENTIFIER_0_PROPERTY,
	MAIL_MERGE_FOLDER_EMAIL_IDENTIFIER_MESSAGE_ID_PROPERTY,
	MAIL_MERGE_FOLDER_EMAIL_IDENTIFIER_NUM_PROPERTIES
};
static GParamSpec* mail_merge_folder_email_identifier_properties[MAIL_MERGE_FOLDER_EMAIL_IDENTIFIER_NUM_PROPERTIES];
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
typedef struct _MailMergeFolderFolderPropertiesPrivate MailMergeFolderFolderPropertiesPrivate;
enum  {
	MAIL_MERGE_FOLDER_FOLDER_PROPERTIES_0_PROPERTY,
	MAIL_MERGE_FOLDER_FOLDER_PROPERTIES_NUM_PROPERTIES
};
static GParamSpec* mail_merge_folder_folder_properties_properties[MAIL_MERGE_FOLDER_FOLDER_PROPERTIES_NUM_PROPERTIES];
enum  {
	MAIL_MERGE_FOLDER_SEND_ERROR_SIGNAL,
	MAIL_MERGE_FOLDER_NUM_SIGNALS
};
static guint mail_merge_folder_signals[MAIL_MERGE_FOLDER_NUM_SIGNALS] = {0};

struct _MailMergeFolderPrivate {
	GearyAccount* _account;
	MailMergeFolderFolderProperties* _properties;
	GearyFolderPath* _path;
	GearyFolderSpecialUse _used_as;
	GFile* _data_location;
	gchar* _data_display_name;
	guint _email_sent;
	guint _email_total;
	gboolean _is_sending;
	GeeList* ids;
	GeeMap* composed;
	GeeMap* email;
	GearyEmail* template;
	MailMergeCsvReader* data;
	GCancellable* loading;
	GCancellable* sending;
};

struct _MailMergeFolderNewData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GType object_type;
	MailMergeFolder* self;
	GearyAccount* account;
	GearyFolderRoot* root;
	GearyEmail* template;
	GFile* data_location;
	MailMergeCsvReader* data;
	GearyAccount* _tmp0_;
	GearyFolderPath* _tmp1_;
	GearyEmail* _tmp2_;
	MailMergeCsvReader* _tmp3_;
	GFileInfo* info;
	GFileInfo* _tmp4_;
	const gchar* _tmp5_;
	GCancellable* _tmp6_;
	GError* _inner_error0_;
};

struct _MailMergeFolderCloseAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	MailMergeFolder* self;
	GCancellable* cancellable;
	gboolean result;
	gboolean is_closing;
	GCancellable* _tmp0_;
	GError* _inner_error0_;
};

struct _MailMergeFolderContainsIdentifiersData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	MailMergeFolder* self;
	GeeCollection* ids;
	GCancellable* cancellable;
	GeeCollection* result;
	GearyIterable* _tmp0_;
	GearyIterable* _tmp1_;
	GearyIterable* _tmp2_;
	GearyIterable* _tmp3_;
	GeeHashSet* _tmp4_;
	GeeCollection* _tmp5_;
};

struct _MailMergeFolderFetchEmailAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	MailMergeFolder* self;
	GearyEmailIdentifier* id;
	GearyEmailField required_fields;
	GearyFolderListFlags flags;
	GCancellable* cancellable;
	GearyEmail* result;
	GearyEmail* email;
	GeeMap* _tmp0_;
	gpointer _tmp1_;
	GearyEmail* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	GError* _tmp5_;
	GError* _tmp6_;
	GError* _inner_error0_;
};

struct _MailMergeFolderListEmailByIdAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	MailMergeFolder* self;
	GearyEmailIdentifier* initial_id;
	gint count;
	GearyEmailField required_fields;
	GearyFolderListFlags flags;
	GCancellable* cancellable;
	GeeList* result;
	MailMergeFolderEmailIdentifier* initial;
	MailMergeFolderEmailIdentifier* _tmp0_;
	gboolean _tmp1_;
	MailMergeFolderEmailIdentifier* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	GError* _tmp5_;
	GError* _tmp6_;
	GeeList* list;
	GeeArrayList* _tmp7_;
	gboolean _tmp8_;
	GeeList* _tmp9_;
	gboolean _tmp10_;
	gboolean _tmp11_;
	gint incr;
	gint next_index;
	MailMergeFolderEmailIdentifier* _tmp12_;
	GearyEmailIdentifier* _tmp13_;
	GeeList* _tmp14_;
	gpointer _tmp15_;
	GeeList* _tmp16_;
	gpointer _tmp17_;
	MailMergeFolderEmailIdentifier* _tmp18_;
	MailMergeFolderEmailIdentifier* _tmp19_;
	gint64 _tmp20_;
	gint64 _tmp21_;
	GeeList* _tmp22_;
	GeeMap* _tmp23_;
	GeeList* _tmp24_;
	MailMergeFolderEmailIdentifier* _tmp25_;
	gint64 _tmp26_;
	gint64 _tmp27_;
	gpointer _tmp28_;
	GearyEmailIdentifier* _tmp29_;
	gpointer _tmp30_;
	GearyEmail* _tmp31_;
	MailMergeFolderEmailIdentifier* _tmp32_;
	gint64 _tmp33_;
	gint64 _tmp34_;
	gboolean _tmp35_;
	gboolean _tmp36_;
	GeeList* _tmp37_;
	gint _tmp38_;
	gint _tmp39_;
	GeeList* _tmp40_;
	gint _tmp41_;
	gint _tmp42_;
	GeeList* _tmp43_;
	GeeMap* _tmp44_;
	GeeList* _tmp45_;
	gpointer _tmp46_;
	GearyEmailIdentifier* _tmp47_;
	gpointer _tmp48_;
	GearyEmail* _tmp49_;
	GeeList* _tmp50_;
	GeeList* _tmp51_;
	gint _tmp52_;
	gint _tmp53_;
	GeeList* _tmp54_;
	GeeList* _tmp55_;
	GError* _inner_error0_;
};

struct _MailMergeFolderListEmailBySparseIdAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	MailMergeFolder* self;
	GeeCollection* ids;
	GearyEmailField required_fields;
	GearyFolderListFlags flags;
	GCancellable* cancellable;
	GeeList* result;
	GeeList* list;
	GeeArrayList* _tmp0_;
	GeeIterator* _id_it;
	GeeIterator* _tmp1_;
	GeeIterator* _tmp2_;
	GearyEmailIdentifier* id;
	GeeIterator* _tmp3_;
	gpointer _tmp4_;
	GearyEmail* email;
	GeeMap* _tmp5_;
	GearyEmailIdentifier* _tmp6_;
	gpointer _tmp7_;
	GearyEmail* _tmp8_;
	GearyEmailIdentifier* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	GError* _tmp12_;
	GError* _tmp13_;
	GeeList* _tmp14_;
	GearyEmail* _tmp15_;
	GeeList* _tmp16_;
	GeeList* _tmp17_;
	gint _tmp18_;
	gint _tmp19_;
	GeeList* _tmp20_;
	GeeList* _tmp21_;
	GError* _inner_error0_;
};

struct _Block1Data {
	int _ref_count_;
	MailMergeFolder* self;
	GearyEmail* template;
	GearyMemoryBuffer* raw_rfc822;
};

struct _MailMergeFolderLoadDataData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	MailMergeFolder* self;
	GCancellable* cancellable;
	gint64 next_id;
	Block1Data* _data1_;
	GearyEmail* _tmp0_;
	GearyNonblockingConcurrent* _tmp1_;
	GearyNonblockingConcurrent* _tmp2_;
	gchar** headers;
	MailMergeCsvReader* _tmp3_;
	gint _tmp4_;
	gchar** _tmp5_;
	gint headers_length1;
	gint _headers_size_;
	GeeHashMap* fields;
	GeeHashMap* _tmp6_;
	gchar** record;
	MailMergeCsvReader* _tmp7_;
	gint _tmp8_;
	gchar** _tmp9_;
	gint record_length1;
	gint _record_size_;
	gchar** _tmp10_;
	gint _tmp10__length1;
	GeeHashMap* _tmp11_;
	gint i;
	gboolean _tmp12_;
	gint _tmp13_;
	gchar** _tmp14_;
	gint _tmp14__length1;
	GeeHashMap* _tmp15_;
	gchar** _tmp16_;
	gint _tmp16__length1;
	const gchar* _tmp17_;
	gchar** _tmp18_;
	gint _tmp18__length1;
	const gchar* _tmp19_;
	MailMergeProcessor* processor;
	GearyEmail* _tmp20_;
	MailMergeProcessor* _tmp21_;
	GearyComposedEmail* composed;
	MailMergeProcessor* _tmp22_;
	GeeHashMap* _tmp23_;
	GearyComposedEmail* _tmp24_;
	GearyRFC822Message* message;
	GearyComposedEmail* _tmp25_;
	GearyRFC822Message* _tmp26_;
	MailMergeFolderEmailIdentifier* id;
	gint64 _tmp27_;
	MailMergeFolderEmailIdentifier* _tmp28_;
	GearyEmail* email;
	MailMergeFolderEmailIdentifier* _tmp29_;
	GearyRFC822Message* _tmp30_;
	GearyEmail* _tmp31_;
	GearyEmail* _tmp32_;
	GearyEmail* _tmp33_;
	GearyEmailFlags* _tmp34_;
	GearyEmailFlags* _tmp35_;
	GeeList* _tmp36_;
	MailMergeFolderEmailIdentifier* _tmp37_;
	GeeMap* _tmp38_;
	MailMergeFolderEmailIdentifier* _tmp39_;
	GearyComposedEmail* _tmp40_;
	GeeMap* _tmp41_;
	MailMergeFolderEmailIdentifier* _tmp42_;
	GearyEmail* _tmp43_;
	MailMergeFolderFolderProperties* _tmp44_;
	MailMergeFolderEmailIdentifier* _tmp45_;
	GeeCollection* _tmp46_;
	GeeCollection* _tmp47_;
	gchar** _tmp48_;
	MailMergeCsvReader* _tmp49_;
	gint _tmp50_;
	gchar** _tmp51_;
	gint _tmp48__length1;
	gint __tmp48__size_;
	gchar** _tmp52_;
	gint _tmp52__length1;
	GError* err;
	GError* _tmp53_;
	const gchar* _tmp54_;
	GError* _inner_error0_;
};

struct _MailMergeFolderLoadTemplateData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	MailMergeFolder* self;
	GCancellable* cancellable;
	GearyEmail* result;
	GearyEmail* template;
	GearyEmail* _tmp0_;
	GearyEmail* _tmp1_;
	GearyEmail* _tmp2_;
	GearyEmailField _tmp3_;
	GearyEmailField _tmp4_;
	GearyEmail* _tmp5_;
	GearyAccount* _tmp6_;
	GearyAccount* _tmp7_;
	GearyEmail* _tmp8_;
	GearyEmailIdentifier* _tmp9_;
	GearyEmailIdentifier* _tmp10_;
	GearyEmail* _tmp11_;
	GearyEmail* _tmp12_;
	GError* _inner_error0_;
};

struct _MailMergeFolderSendLoopData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	MailMergeFolder* self;
	GCancellable* cancellable;
	GCancellable* _tmp0_;
	GCancellable* _tmp1_;
	GearySmtpClientService* smtp;
	GearyAccount* _tmp2_;
	GearyClientService* _tmp3_;
	GearyClientService* _tmp4_;
	GearySmtpClientService* _tmp5_;
	GearySmtpClientService* _tmp6_;
	gboolean _tmp7_;
	GeeList* _tmp8_;
	gboolean _tmp9_;
	gboolean _tmp10_;
	GCancellable* _tmp11_;
	gint last;
	GeeList* _tmp12_;
	gint _tmp13_;
	gint _tmp14_;
	GearyEmailIdentifier* id;
	GeeList* _tmp15_;
	gpointer _tmp16_;
	GearyComposedEmail* composed;
	GeeMap* _tmp17_;
	GearyEmailIdentifier* _tmp18_;
	gpointer _tmp19_;
	GearyComposedEmail* _tmp20_;
	GTimeZone* _tmp21_;
	GTimeZone* _tmp22_;
	GDateTime* _tmp23_;
	GDateTime* _tmp24_;
	GearyComposedEmail* _tmp25_;
	GearyComposedEmail* _tmp26_;
	GearySmtpClientService* _tmp27_;
	GearyComposedEmail* _tmp28_;
	GCancellable* _tmp29_;
	guint _tmp30_;
	GeeList* _tmp31_;
	gpointer _tmp32_;
	GearyEmailIdentifier* _tmp33_;
	GeeMap* _tmp34_;
	GearyEmailIdentifier* _tmp35_;
	GeeMap* _tmp36_;
	GearyEmailIdentifier* _tmp37_;
	MailMergeFolderFolderProperties* _tmp38_;
	GearyEmailIdentifier* _tmp39_;
	GeeCollection* _tmp40_;
	GeeCollection* _tmp41_;
	GError* err;
	GError* _tmp42_;
	const gchar* _tmp43_;
	GError* _tmp44_;
	GError* _inner_error0_;
};

struct _MailMergeFolderEmailIdentifier {
	GearyEmailIdentifier parent_instance;
	MailMergeFolderEmailIdentifierPrivate * priv;
};

struct _MailMergeFolderEmailIdentifierClass {
	GearyEmailIdentifierClass parent_class;
};

struct _MailMergeFolderEmailIdentifierPrivate {
	gint64 _message_id;
};

struct _MailMergeFolderFolderProperties {
	GearyFolderProperties parent_instance;
	MailMergeFolderFolderPropertiesPrivate * priv;
};

struct _MailMergeFolderFolderPropertiesClass {
	GearyFolderPropertiesClass parent_class;
};

static gint MailMergeFolder_private_offset;
static gpointer mail_merge_folder_parent_class = NULL;
static gint MailMergeFolderEmailIdentifier_private_offset;
static gpointer mail_merge_folder_email_identifier_parent_class = NULL;
static gpointer mail_merge_folder_folder_properties_parent_class = NULL;

static GType mail_merge_folder_folder_properties_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static MailMergeFolderFolderProperties* mail_merge_folder_folder_properties_new (void);
static MailMergeFolderFolderProperties* mail_merge_folder_folder_properties_construct (GType object_type);
static void mail_merge_folder_set_data_location (MailMergeFolder* self,
                                          GFile* value);
static void mail_merge_folder_set_data_display_name (MailMergeFolder* self,
                                              const gchar* value);
static void mail_merge_folder_set_email_sent (MailMergeFolder* self,
                                       guint value);
static void mail_merge_folder_set_email_total (MailMergeFolder* self,
                                        guint value);
static void mail_merge_folder_set_is_sending (MailMergeFolder* self,
                                       gboolean value);
static void mail_merge_folder_construct_data_free (gpointer _data);
static gboolean mail_merge_folder_construct_co (MailMergeFolderNewData* _data_);
static void mail_merge_folder_new_ready (GObject* source_object,
                                  GAsyncResult* _res_,
                                  gpointer _user_data_);
static void mail_merge_folder_load_data (MailMergeFolder* self,
                                  GCancellable* cancellable,
                                  GAsyncReadyCallback _callback_,
                                  gpointer _user_data_);
static void mail_merge_folder_load_data_finish (MailMergeFolder* self,
                                         GAsyncResult* _res_);
static void mail_merge_folder_send_loop (MailMergeFolder* self,
                                  GAsyncReadyCallback _callback_,
                                  gpointer _user_data_);
static void mail_merge_folder_send_loop_finish (MailMergeFolder* self,
                                         GAsyncResult* _res_);
static void mail_merge_folder_real_close_async_data_free (gpointer _data);
static void mail_merge_folder_real_close_async (GearyFolder* base,
                                         GCancellable* cancellable,
                                         GAsyncReadyCallback _callback_,
                                         gpointer _user_data_);
static gboolean mail_merge_folder_real_close_async_co (MailMergeFolderCloseAsyncData* _data_);
static void mail_merge_folder_close_async_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_);
static void mail_merge_folder_real_contains_identifiers_data_free (gpointer _data);
static void mail_merge_folder_real_contains_identifiers (GearyFolder* base,
                                                  GeeCollection* ids,
                                                  GCancellable* cancellable,
                                                  GAsyncReadyCallback _callback_,
                                                  gpointer _user_data_);
static gboolean mail_merge_folder_real_contains_identifiers_co (MailMergeFolderContainsIdentifiersData* _data_);
static gboolean __lambda5_ (MailMergeFolder* self,
                     GearyEmailIdentifier* id);
static gboolean ___lambda5__gee_predicate (gconstpointer g,
                                    gpointer self);
static void mail_merge_folder_real_fetch_email_async_data_free (gpointer _data);
static void mail_merge_folder_real_fetch_email_async (GearyFolder* base,
                                               GearyEmailIdentifier* id,
                                               GearyEmailField required_fields,
                                               GearyFolderListFlags flags,
                                               GCancellable* cancellable,
                                               GAsyncReadyCallback _callback_,
                                               gpointer _user_data_);
static gboolean mail_merge_folder_real_fetch_email_async_co (MailMergeFolderFetchEmailAsyncData* _data_);
static void mail_merge_folder_real_list_email_by_id_async_data_free (gpointer _data);
static void mail_merge_folder_real_list_email_by_id_async (GearyFolder* base,
                                                    GearyEmailIdentifier* initial_id,
                                                    gint count,
                                                    GearyEmailField required_fields,
                                                    GearyFolderListFlags flags,
                                                    GCancellable* cancellable,
                                                    GAsyncReadyCallback _callback_,
                                                    gpointer _user_data_);
static gboolean mail_merge_folder_real_list_email_by_id_async_co (MailMergeFolderListEmailByIdAsyncData* _data_);
static GType mail_merge_folder_email_identifier_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static gint64 mail_merge_folder_email_identifier_get_message_id (MailMergeFolderEmailIdentifier* self);
static void mail_merge_folder_real_list_email_by_sparse_id_async_data_free (gpointer _data);
static void mail_merge_folder_real_list_email_by_sparse_id_async (GearyFolder* base,
                                                           GeeCollection* ids,
                                                           GearyEmailField required_fields,
                                                           GearyFolderListFlags flags,
                                                           GCancellable* cancellable,
                                                           GAsyncReadyCallback _callback_,
                                                           gpointer _user_data_);
static gboolean mail_merge_folder_real_list_email_by_sparse_id_async_co (MailMergeFolderListEmailBySparseIdAsyncData* _data_);
static void mail_merge_folder_real_set_used_as_custom (GearyFolder* base,
                                                gboolean enabled,
                                                GError** error);
static void mail_merge_folder_load_data_data_free (gpointer _data);
static gboolean mail_merge_folder_load_data_co (MailMergeFolderLoadDataData* _data_);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void mail_merge_folder_load_template (MailMergeFolder* self,
                                      GCancellable* cancellable,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_);
static GearyEmail* mail_merge_folder_load_template_finish (MailMergeFolder* self,
                                                    GAsyncResult* _res_,
                                                    GError** error);
static void mail_merge_folder_load_data_ready (GObject* source_object,
                                        GAsyncResult* _res_,
                                        gpointer _user_data_);
static void ___lambda4_ (Block1Data* _data1_,
                  GCancellable* c,
                  GError** error);
static void ____lambda4__geary_nonblocking_concurrent_concurrent_callback (GCancellable* cancellable,
                                                                    gpointer self,
                                                                    GError** error);
static MailMergeFolderEmailIdentifier* mail_merge_folder_email_identifier_new (gint64 message_id);
static MailMergeFolderEmailIdentifier* mail_merge_folder_email_identifier_construct (GType object_type,
                                                                              gint64 message_id);
static void mail_merge_folder_folder_properties_set_total (MailMergeFolderFolderProperties* self,
                                                    gint total);
static void mail_merge_folder_load_template_data_free (gpointer _data);
static gboolean mail_merge_folder_load_template_co (MailMergeFolderLoadTemplateData* _data_);
static void mail_merge_folder_load_template_ready (GObject* source_object,
                                            GAsyncResult* _res_,
                                            gpointer _user_data_);
static void mail_merge_folder_send_loop_data_free (gpointer _data);
static gboolean mail_merge_folder_send_loop_co (MailMergeFolderSendLoopData* _data_);
static void mail_merge_folder_send_loop_ready (GObject* source_object,
                                        GAsyncResult* _res_,
                                        gpointer _user_data_);
static gboolean _mail_merge_folder_send_loop_co_gsource_func (gpointer self);
static void mail_merge_folder_email_identifier_set_message_id (MailMergeFolderEmailIdentifier* self,
                                                        gint64 value);
static MailMergeFolderEmailIdentifier* mail_merge_folder_email_identifier_new_from_variant (GVariant* serialised,
                                                                                     GError** error);
static MailMergeFolderEmailIdentifier* mail_merge_folder_email_identifier_construct_from_variant (GType object_type,
                                                                                           GVariant* serialised,
                                                                                           GError** error);
static guint mail_merge_folder_email_identifier_real_hash (GearyEmailIdentifier* base);
static gboolean mail_merge_folder_email_identifier_real_equal_to (GearyEmailIdentifier* base,
                                                           GearyEmailIdentifier* other);
static gchar* mail_merge_folder_email_identifier_real_to_string (GearyEmailIdentifier* base);
static gint mail_merge_folder_email_identifier_real_natural_sort_comparator (GearyEmailIdentifier* base,
                                                                      GearyEmailIdentifier* o);
static GVariant* mail_merge_folder_email_identifier_real_to_variant (GearyEmailIdentifier* base);
static void mail_merge_folder_email_identifier_finalize (GObject * obj);
static GType mail_merge_folder_email_identifier_get_type_once (void);
static void _vala_mail_merge_folder_email_identifier_get_property (GObject * object,
                                                            guint property_id,
                                                            GValue * value,
                                                            GParamSpec * pspec);
static void _vala_mail_merge_folder_email_identifier_set_property (GObject * object,
                                                            guint property_id,
                                                            const GValue * value,
                                                            GParamSpec * pspec);
static GType mail_merge_folder_folder_properties_get_type_once (void);
static void mail_merge_folder_finalize (GObject * obj);
static GType mail_merge_folder_get_type_once (void);
static void _vala_mail_merge_folder_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec);
static void _vala_mail_merge_folder_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

static inline gpointer
mail_merge_folder_get_instance_private (MailMergeFolder* self)
{
	return G_STRUCT_MEMBER_P (self, MailMergeFolder_private_offset);
}

static GearyAccount*
mail_merge_folder_real_get_account (GearyFolder* base)
{
	GearyAccount* result;
	MailMergeFolder* self;
	GearyAccount* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, MAIL_MERGE_TYPE_FOLDER, MailMergeFolder);
	_tmp0_ = self->priv->_account;
	result = _tmp0_;
	return result;
}

static GearyFolderProperties*
mail_merge_folder_real_get_properties (GearyFolder* base)
{
	GearyFolderProperties* result;
	MailMergeFolder* self;
	MailMergeFolderFolderProperties* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, MAIL_MERGE_TYPE_FOLDER, MailMergeFolder);
	_tmp0_ = self->priv->_properties;
	result = G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEARY_TYPE_FOLDER_PROPERTIES, GearyFolderProperties);
	return result;
}

static GearyFolderPath*
mail_merge_folder_real_get_path (GearyFolder* base)
{
	GearyFolderPath* result;
	MailMergeFolder* self;
	GearyFolderPath* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, MAIL_MERGE_TYPE_FOLDER, MailMergeFolder);
	_tmp0_ = self->priv->_path;
	result = _tmp0_;
	return result;
}

static GearyFolderSpecialUse
mail_merge_folder_real_get_used_as (GearyFolder* base)
{
	GearyFolderSpecialUse result;
	MailMergeFolder* self;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, MAIL_MERGE_TYPE_FOLDER, MailMergeFolder);
	result = self->priv->_used_as;
	return result;
}

GFile*
mail_merge_folder_get_data_location (MailMergeFolder* self)
{
	GFile* result;
	GFile* _tmp0_;
	g_return_val_if_fail (MAIL_MERGE_IS_FOLDER (self), NULL);
	_tmp0_ = self->priv->_data_location;
	result = _tmp0_;
	return result;
}

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

static void
mail_merge_folder_set_data_location (MailMergeFolder* self,
                                     GFile* value)
{
	GFile* old_value;
	g_return_if_fail (MAIL_MERGE_IS_FOLDER (self));
	old_value = mail_merge_folder_get_data_location (self);
	if (old_value != value) {
		GFile* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_data_location);
		self->priv->_data_location = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, mail_merge_folder_properties[MAIL_MERGE_FOLDER_DATA_LOCATION_PROPERTY]);
	}
}

const gchar*
mail_merge_folder_get_data_display_name (MailMergeFolder* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (MAIL_MERGE_IS_FOLDER (self), NULL);
	_tmp0_ = self->priv->_data_display_name;
	result = _tmp0_;
	return result;
}

static void
mail_merge_folder_set_data_display_name (MailMergeFolder* self,
                                         const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (MAIL_MERGE_IS_FOLDER (self));
	old_value = mail_merge_folder_get_data_display_name (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_data_display_name);
		self->priv->_data_display_name = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, mail_merge_folder_properties[MAIL_MERGE_FOLDER_DATA_DISPLAY_NAME_PROPERTY]);
	}
}

guint
mail_merge_folder_get_email_sent (MailMergeFolder* self)
{
	guint result;
	g_return_val_if_fail (MAIL_MERGE_IS_FOLDER (self), 0U);
	result = self->priv->_email_sent;
	return result;
}

static void
mail_merge_folder_set_email_sent (MailMergeFolder* self,
                                  guint value)
{
	guint old_value;
	g_return_if_fail (MAIL_MERGE_IS_FOLDER (self));
	old_value = mail_merge_folder_get_email_sent (self);
	if (old_value != value) {
		self->priv->_email_sent = value;
		g_object_notify_by_pspec ((GObject *) self, mail_merge_folder_properties[MAIL_MERGE_FOLDER_EMAIL_SENT_PROPERTY]);
	}
}

guint
mail_merge_folder_get_email_total (MailMergeFolder* self)
{
	guint result;
	g_return_val_if_fail (MAIL_MERGE_IS_FOLDER (self), 0U);
	result = self->priv->_email_total;
	return result;
}

static void
mail_merge_folder_set_email_total (MailMergeFolder* self,
                                   guint value)
{
	guint old_value;
	g_return_if_fail (MAIL_MERGE_IS_FOLDER (self));
	old_value = mail_merge_folder_get_email_total (self);
	if (old_value != value) {
		self->priv->_email_total = value;
		g_object_notify_by_pspec ((GObject *) self, mail_merge_folder_properties[MAIL_MERGE_FOLDER_EMAIL_TOTAL_PROPERTY]);
	}
}

gboolean
mail_merge_folder_get_is_sending (MailMergeFolder* self)
{
	gboolean result;
	g_return_val_if_fail (MAIL_MERGE_IS_FOLDER (self), FALSE);
	result = self->priv->_is_sending;
	return result;
}

static void
mail_merge_folder_set_is_sending (MailMergeFolder* self,
                                  gboolean value)
{
	gboolean old_value;
	g_return_if_fail (MAIL_MERGE_IS_FOLDER (self));
	old_value = mail_merge_folder_get_is_sending (self);
	if (old_value != value) {
		self->priv->_is_sending = value;
		g_object_notify_by_pspec ((GObject *) self, mail_merge_folder_properties[MAIL_MERGE_FOLDER_IS_SENDING_PROPERTY]);
	}
}

static void
mail_merge_folder_construct_data_free (gpointer _data)
{
	MailMergeFolderNewData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->account);
	_g_object_unref0 (_data_->root);
	_g_object_unref0 (_data_->template);
	_g_object_unref0 (_data_->data_location);
	_g_object_unref0 (_data_->data);
	_g_object_unref0 (_data_->self);
	g_slice_free (MailMergeFolderNewData, _data_);
}

void
mail_merge_folder_construct (GType object_type,
                             GearyAccount* account,
                             GearyFolderRoot* root,
                             GearyEmail* template,
                             GFile* data_location,
                             MailMergeCsvReader* data,
                             GAsyncReadyCallback _callback_,
                             gpointer _user_data_)
{
	MailMergeFolderNewData* _data_;
	GearyAccount* _tmp0_;
	GearyFolderRoot* _tmp1_;
	GearyEmail* _tmp2_;
	GFile* _tmp3_;
	MailMergeCsvReader* _tmp4_;
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (account, GEARY_TYPE_ACCOUNT));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (root, GEARY_TYPE_FOLDER_ROOT));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (template, GEARY_TYPE_EMAIL));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (data_location, g_file_get_type ()));
	g_return_if_fail (MAIL_MERGE_CSV_IS_READER (data));
	_data_ = g_slice_new0 (MailMergeFolderNewData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, mail_merge_folder_construct_data_free);
	_data_->object_type = object_type;
	_tmp0_ = _g_object_ref0 (account);
	_g_object_unref0 (_data_->account);
	_data_->account = _tmp0_;
	_tmp1_ = _g_object_ref0 (root);
	_g_object_unref0 (_data_->root);
	_data_->root = _tmp1_;
	_tmp2_ = _g_object_ref0 (template);
	_g_object_unref0 (_data_->template);
	_data_->template = _tmp2_;
	_tmp3_ = _g_object_ref0 (data_location);
	_g_object_unref0 (_data_->data_location);
	_data_->data_location = _tmp3_;
	_tmp4_ = _g_object_ref0 (data);
	_g_object_unref0 (_data_->data);
	_data_->data = _tmp4_;
	mail_merge_folder_construct_co (_data_);
}

MailMergeFolder*
mail_merge_folder_construct_finish (GAsyncResult* _res_,
                                    GError** error)
{
	MailMergeFolder* result;
	MailMergeFolderNewData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->self;
	_data_->self = NULL;
	return result;
}

static void
mail_merge_folder_new_ready (GObject* source_object,
                             GAsyncResult* _res_,
                             gpointer _user_data_)
{
	MailMergeFolderNewData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	mail_merge_folder_construct_co (_data_);
}

static gboolean
mail_merge_folder_construct_co (MailMergeFolderNewData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->self = (MailMergeFolder*) geary_abstract_local_folder_construct (_data_->object_type);
	_data_->_tmp0_ = _g_object_ref0 (_data_->account);
	_g_object_unref0 (_data_->self->priv->_account);
	_data_->self->priv->_account = _data_->_tmp0_;
	_data_->_tmp1_ = geary_folder_path_get_child (G_TYPE_CHECK_INSTANCE_CAST (_data_->root, GEARY_TYPE_FOLDER_PATH, GearyFolderPath), "$Plugin.MailMerge$", GEARY_TRILLIAN_UNKNOWN);
	_g_object_unref0 (_data_->self->priv->_path);
	_data_->self->priv->_path = _data_->_tmp1_;
	_data_->_tmp2_ = _g_object_ref0 (_data_->template);
	_g_object_unref0 (_data_->self->priv->template);
	_data_->self->priv->template = _data_->_tmp2_;
	mail_merge_folder_set_data_location (_data_->self, _data_->data_location);
	_data_->_tmp3_ = _g_object_ref0 (_data_->data);
	_g_object_unref0 (_data_->self->priv->data);
	_data_->self->priv->data = _data_->_tmp3_;
	_data_->_state_ = 1;
	g_file_query_info_async (_data_->data_location, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, NULL, mail_merge_folder_new_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp4_ = g_file_query_info_finish (_data_->data_location, _data_->_res_, &_data_->_inner_error0_);
	_data_->info = _data_->_tmp4_;
	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_->_tmp5_ = g_file_info_get_display_name (_data_->info);
	mail_merge_folder_set_data_display_name (_data_->self, _data_->_tmp5_);
	_data_->_tmp6_ = _data_->self->priv->loading;
	mail_merge_folder_load_data (_data_->self, _data_->_tmp6_, NULL, NULL);
	_g_object_unref0 (_data_->info);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

void
mail_merge_folder_new (GearyAccount* account,
                       GearyFolderRoot* root,
                       GearyEmail* template,
                       GFile* data_location,
                       MailMergeCsvReader* data,
                       GAsyncReadyCallback _callback_,
                       gpointer _user_data_)
{
	mail_merge_folder_construct (MAIL_MERGE_TYPE_FOLDER, account, root, template, data_location, data, _callback_, _user_data_);
}

MailMergeFolder*
mail_merge_folder_new_finish (GAsyncResult* _res_,
                              GError** error)
{
	return mail_merge_folder_construct_finish (_res_, error);
}

/** Starts or stops the folder sending mail. */
void
mail_merge_folder_set_sending (MailMergeFolder* self,
                               gboolean is_sending)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (MAIL_MERGE_IS_FOLDER (self));
	if (is_sending) {
		gboolean _tmp1_;
		_tmp1_ = self->priv->_is_sending;
		_tmp0_ = !_tmp1_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		mail_merge_folder_send_loop (self, NULL, NULL);
		mail_merge_folder_set_is_sending (self, TRUE);
	} else {
		gboolean _tmp2_ = FALSE;
		if (!is_sending) {
			gboolean _tmp3_;
			_tmp3_ = self->priv->_is_sending;
			_tmp2_ = _tmp3_;
		} else {
			_tmp2_ = FALSE;
		}
		if (_tmp2_) {
			GCancellable* _tmp4_;
			GCancellable* _tmp5_;
			_tmp4_ = self->priv->sending;
			g_cancellable_cancel (_tmp4_);
			_tmp5_ = g_cancellable_new ();
			_g_object_unref0 (self->priv->sending);
			self->priv->sending = _tmp5_;
		}
	}
}

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

static void
mail_merge_folder_real_close_async (GearyFolder* base,
                                    GCancellable* cancellable,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_)
{
	MailMergeFolder * self;
	MailMergeFolderCloseAsyncData* _data_;
	MailMergeFolder* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, MAIL_MERGE_TYPE_FOLDER, MailMergeFolder);
	_data_ = g_slice_new0 (MailMergeFolderCloseAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, mail_merge_folder_real_close_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	mail_merge_folder_real_close_async_co (_data_);
}

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

/** {@inheritDoc} */
static void
mail_merge_folder_close_async_ready (GObject* source_object,
                                     GAsyncResult* _res_,
                                     gpointer _user_data_)
{
	MailMergeFolderCloseAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	mail_merge_folder_real_close_async_co (_data_);
}

static gboolean
mail_merge_folder_real_close_async_co (MailMergeFolderCloseAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_state_ = 1;
	GEARY_FOLDER_CLASS (mail_merge_folder_parent_class)->close_async (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_ABSTRACT_LOCAL_FOLDER, GearyAbstractLocalFolder), GEARY_TYPE_FOLDER, GearyFolder), _data_->cancellable, mail_merge_folder_close_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->is_closing = GEARY_FOLDER_CLASS (mail_merge_folder_parent_class)->close_finish (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_ABSTRACT_LOCAL_FOLDER, GearyAbstractLocalFolder), GEARY_TYPE_FOLDER, GearyFolder), _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (_data_->is_closing) {
		_data_->_tmp0_ = _data_->self->priv->loading;
		g_cancellable_cancel (_data_->_tmp0_);
		mail_merge_folder_set_sending (_data_->self, FALSE);
	}
	_data_->result = _data_->is_closing;
	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
mail_merge_folder_real_contains_identifiers_data_free (gpointer _data)
{
	MailMergeFolderContainsIdentifiersData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->ids);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (MailMergeFolderContainsIdentifiersData, _data_);
}

static void
mail_merge_folder_real_contains_identifiers (GearyFolder* base,
                                             GeeCollection* ids,
                                             GCancellable* cancellable,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_)
{
	MailMergeFolder * self;
	MailMergeFolderContainsIdentifiersData* _data_;
	MailMergeFolder* _tmp0_;
	GeeCollection* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, MAIL_MERGE_TYPE_FOLDER, MailMergeFolder);
	_data_ = g_slice_new0 (MailMergeFolderContainsIdentifiersData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, mail_merge_folder_real_contains_identifiers_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (ids);
	_g_object_unref0 (_data_->ids);
	_data_->ids = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	mail_merge_folder_real_contains_identifiers_co (_data_);
}

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

/** {@inheritDoc} */
static gboolean
__lambda5_ (MailMergeFolder* self,
            GearyEmailIdentifier* id)
{
	GeeMap* _tmp0_;
	gboolean result;
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (id, GEARY_TYPE_EMAIL_IDENTIFIER), FALSE);
	_tmp0_ = self->priv->email;
	result = gee_map_has_key (_tmp0_, id);
	return result;
}

static gboolean
___lambda5__gee_predicate (gconstpointer g,
                           gpointer self)
{
	gboolean result;
	result = __lambda5_ ((MailMergeFolder*) self, (GearyEmailIdentifier*) g);
	return result;
}

static gboolean
mail_merge_folder_real_contains_identifiers_co (MailMergeFolderContainsIdentifiersData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = geary_traverse (GEARY_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, G_TYPE_CHECK_INSTANCE_CAST (_data_->ids, GEE_TYPE_ITERABLE, GeeIterable));
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = geary_iterable_filter (_data_->_tmp1_, ___lambda5__gee_predicate, g_object_ref (_data_->self), g_object_unref);
	_data_->_tmp3_ = _data_->_tmp2_;
	_data_->_tmp4_ = geary_iterable_to_hash_set (_data_->_tmp3_, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->_tmp5_ = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp4_, GEE_TYPE_COLLECTION, GeeCollection);
	_g_object_unref0 (_data_->_tmp3_);
	_g_object_unref0 (_data_->_tmp1_);
	_data_->result = _data_->_tmp5_;
	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
mail_merge_folder_real_fetch_email_async_data_free (gpointer _data)
{
	MailMergeFolderFetchEmailAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->id);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (MailMergeFolderFetchEmailAsyncData, _data_);
}

static void
mail_merge_folder_real_fetch_email_async (GearyFolder* base,
                                          GearyEmailIdentifier* id,
                                          GearyEmailField required_fields,
                                          GearyFolderListFlags flags,
                                          GCancellable* cancellable,
                                          GAsyncReadyCallback _callback_,
                                          gpointer _user_data_)
{
	MailMergeFolder * self;
	MailMergeFolderFetchEmailAsyncData* _data_;
	MailMergeFolder* _tmp0_;
	GearyEmailIdentifier* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (id, GEARY_TYPE_EMAIL_IDENTIFIER));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, MAIL_MERGE_TYPE_FOLDER, MailMergeFolder);
	_data_ = g_slice_new0 (MailMergeFolderFetchEmailAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, mail_merge_folder_real_fetch_email_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (id);
	_g_object_unref0 (_data_->id);
	_data_->id = _tmp1_;
	_data_->required_fields = required_fields;
	_data_->flags = flags;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	mail_merge_folder_real_fetch_email_async_co (_data_);
}

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

static gboolean
mail_merge_folder_real_fetch_email_async_co (MailMergeFolderFetchEmailAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	geary_abstract_local_folder_check_open (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_ABSTRACT_LOCAL_FOLDER, GearyAbstractLocalFolder), &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp0_ = _data_->self->priv->email;
	_data_->_tmp1_ = gee_map_get (_data_->_tmp0_, _data_->id);
	_data_->email = (GearyEmail*) _data_->_tmp1_;
	_data_->_tmp2_ = _data_->email;
	if (_data_->_tmp2_ == NULL) {
		_data_->_tmp3_ = geary_email_identifier_to_string (_data_->id);
		_data_->_tmp4_ = _data_->_tmp3_;
		_data_->_tmp5_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_NOT_FOUND, "No email with ID %s in merge", _data_->_tmp4_);
		_data_->_tmp6_ = _data_->_tmp5_;
		_g_free0 (_data_->_tmp4_);
		_data_->_inner_error0_ = _data_->_tmp6_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->email);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->result = _data_->email;
	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
mail_merge_folder_real_list_email_by_id_async_data_free (gpointer _data)
{
	MailMergeFolderListEmailByIdAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->initial_id);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (MailMergeFolderListEmailByIdAsyncData, _data_);
}

static void
mail_merge_folder_real_list_email_by_id_async (GearyFolder* base,
                                               GearyEmailIdentifier* initial_id,
                                               gint count,
                                               GearyEmailField required_fields,
                                               GearyFolderListFlags flags,
                                               GCancellable* cancellable,
                                               GAsyncReadyCallback _callback_,
                                               gpointer _user_data_)
{
	MailMergeFolder * self;
	MailMergeFolderListEmailByIdAsyncData* _data_;
	MailMergeFolder* _tmp0_;
	GearyEmailIdentifier* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail ((initial_id == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (initial_id, GEARY_TYPE_EMAIL_IDENTIFIER));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, MAIL_MERGE_TYPE_FOLDER, MailMergeFolder);
	_data_ = g_slice_new0 (MailMergeFolderListEmailByIdAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, mail_merge_folder_real_list_email_by_id_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (initial_id);
	_g_object_unref0 (_data_->initial_id);
	_data_->initial_id = _tmp1_;
	_data_->count = count;
	_data_->required_fields = required_fields;
	_data_->flags = flags;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	mail_merge_folder_real_list_email_by_id_async_co (_data_);
}

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

static gboolean
mail_merge_folder_real_list_email_by_id_async_co (MailMergeFolderListEmailByIdAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	geary_abstract_local_folder_check_open (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_ABSTRACT_LOCAL_FOLDER, GearyAbstractLocalFolder), &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp0_ = _g_object_ref0 (MAIL_MERGE_FOLDER_IS_EMAIL_IDENTIFIER (_data_->initial_id) ? ((MailMergeFolderEmailIdentifier*) _data_->initial_id) : NULL);
	_data_->initial = _data_->_tmp0_;
	if (_data_->initial_id != NULL) {
		_data_->_tmp2_ = _data_->initial;
		_data_->_tmp1_ = _data_->_tmp2_ == NULL;
	} else {
		_data_->_tmp1_ = FALSE;
	}
	if (_data_->_tmp1_) {
		_data_->_tmp3_ = geary_email_identifier_to_string (_data_->initial_id);
		_data_->_tmp4_ = _data_->_tmp3_;
		_data_->_tmp5_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_BAD_PARAMETERS, "EmailIdentifier %s not from merge", _data_->_tmp4_);
		_data_->_tmp6_ = _data_->_tmp5_;
		_g_free0 (_data_->_tmp4_);
		_data_->_inner_error0_ = _data_->_tmp6_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->initial);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp7_ = gee_array_list_new (GEARY_TYPE_EMAIL, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data_->list = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp7_, GEE_TYPE_LIST, GeeList);
	_data_->_tmp9_ = _data_->self->priv->ids;
	_data_->_tmp10_ = gee_collection_get_is_empty (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp9_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp11_ = _data_->_tmp10_;
	if (!_data_->_tmp11_) {
		_data_->_tmp8_ = _data_->count > 0;
	} else {
		_data_->_tmp8_ = FALSE;
	}
	if (_data_->_tmp8_) {
		_data_->incr = 1;
		if ((_data_->flags & GEARY_FOLDER_LIST_FLAGS_OLDEST_TO_NEWEST) == GEARY_FOLDER_LIST_FLAGS_OLDEST_TO_NEWEST) {
			_data_->incr = -1;
		}
		_data_->next_index = -1;
		_data_->_tmp12_ = _data_->initial;
		if (_data_->_tmp12_ == NULL) {
			if (_data_->incr > 0) {
				_data_->_tmp14_ = _data_->self->priv->ids;
				_data_->_tmp15_ = gee_list_first (_data_->_tmp14_);
				_g_object_unref0 (_data_->_tmp13_);
				_data_->_tmp13_ = (GearyEmailIdentifier*) _data_->_tmp15_;
			} else {
				_data_->_tmp16_ = _data_->self->priv->ids;
				_data_->_tmp17_ = gee_list_last (_data_->_tmp16_);
				_g_object_unref0 (_data_->_tmp13_);
				_data_->_tmp13_ = (GearyEmailIdentifier*) _data_->_tmp17_;
			}
			_data_->_tmp18_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp13_, MAIL_MERGE_FOLDER_TYPE_EMAIL_IDENTIFIER, MailMergeFolderEmailIdentifier));
			_g_object_unref0 (_data_->initial);
			_data_->initial = _data_->_tmp18_;
			_data_->_tmp19_ = _data_->initial;
			_data_->_tmp20_ = mail_merge_folder_email_identifier_get_message_id (_data_->_tmp19_);
			_data_->_tmp21_ = _data_->_tmp20_;
			_data_->next_index = (gint) _data_->_tmp21_;
			_g_object_unref0 (_data_->_tmp13_);
		} else {
			if ((_data_->flags & GEARY_FOLDER_LIST_FLAGS_INCLUDING_ID) == GEARY_FOLDER_LIST_FLAGS_INCLUDING_ID) {
				_data_->_tmp22_ = _data_->list;
				_data_->_tmp23_ = _data_->self->priv->email;
				_data_->_tmp24_ = _data_->self->priv->ids;
				_data_->_tmp25_ = _data_->initial;
				_data_->_tmp26_ = mail_merge_folder_email_identifier_get_message_id (_data_->_tmp25_);
				_data_->_tmp27_ = _data_->_tmp26_;
				_data_->_tmp28_ = gee_list_get (_data_->_tmp24_, (gint) _data_->_tmp27_);
				_data_->_tmp29_ = (GearyEmailIdentifier*) _data_->_tmp28_;
				_data_->_tmp30_ = gee_map_get (_data_->_tmp23_, _data_->_tmp29_);
				_data_->_tmp31_ = (GearyEmail*) _data_->_tmp30_;
				gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp22_, GEE_TYPE_COLLECTION, GeeCollection), _data_->_tmp31_);
				_g_object_unref0 (_data_->_tmp31_);
				_g_object_unref0 (_data_->_tmp29_);
			}
			_data_->_tmp32_ = _data_->initial;
			_data_->_tmp33_ = mail_merge_folder_email_identifier_get_message_id (_data_->_tmp32_);
			_data_->_tmp34_ = _data_->_tmp33_;
			_data_->next_index = (gint) _data_->_tmp34_;
			_data_->next_index += _data_->incr;
		}
		while (TRUE) {
			_data_->_tmp37_ = _data_->list;
			_data_->_tmp38_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp37_, GEE_TYPE_COLLECTION, GeeCollection));
			_data_->_tmp39_ = _data_->_tmp38_;
			if (_data_->_tmp39_ < _data_->count) {
				_data_->_tmp36_ = _data_->next_index >= 0;
			} else {
				_data_->_tmp36_ = FALSE;
			}
			if (_data_->_tmp36_) {
				_data_->_tmp40_ = _data_->self->priv->ids;
				_data_->_tmp41_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp40_, GEE_TYPE_COLLECTION, GeeCollection));
				_data_->_tmp42_ = _data_->_tmp41_;
				_data_->_tmp35_ = _data_->next_index < _data_->_tmp42_;
			} else {
				_data_->_tmp35_ = FALSE;
			}
			if (!_data_->_tmp35_) {
				break;
			}
			_data_->_tmp43_ = _data_->list;
			_data_->_tmp44_ = _data_->self->priv->email;
			_data_->_tmp45_ = _data_->self->priv->ids;
			_data_->_tmp46_ = gee_list_get (_data_->_tmp45_, _data_->next_index);
			_data_->_tmp47_ = (GearyEmailIdentifier*) _data_->_tmp46_;
			_data_->_tmp48_ = gee_map_get (_data_->_tmp44_, _data_->_tmp47_);
			_data_->_tmp49_ = (GearyEmail*) _data_->_tmp48_;
			gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp43_, GEE_TYPE_COLLECTION, GeeCollection), _data_->_tmp49_);
			_g_object_unref0 (_data_->_tmp49_);
			_g_object_unref0 (_data_->_tmp47_);
			_data_->next_index += _data_->incr;
		}
	}
	_data_->_tmp51_ = _data_->list;
	_data_->_tmp52_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp51_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp53_ = _data_->_tmp52_;
	if (_data_->_tmp53_ > 0) {
		_data_->_tmp54_ = _data_->list;
		_data_->_tmp50_ = _data_->_tmp54_;
	} else {
		_data_->_tmp50_ = NULL;
	}
	_data_->_tmp55_ = _g_object_ref0 (_data_->_tmp50_);
	_data_->result = _data_->_tmp55_;
	_g_object_unref0 (_data_->list);
	_g_object_unref0 (_data_->initial);
	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
mail_merge_folder_real_list_email_by_sparse_id_async_data_free (gpointer _data)
{
	MailMergeFolderListEmailBySparseIdAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->ids);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (MailMergeFolderListEmailBySparseIdAsyncData, _data_);
}

static void
mail_merge_folder_real_list_email_by_sparse_id_async (GearyFolder* base,
                                                      GeeCollection* ids,
                                                      GearyEmailField required_fields,
                                                      GearyFolderListFlags flags,
                                                      GCancellable* cancellable,
                                                      GAsyncReadyCallback _callback_,
                                                      gpointer _user_data_)
{
	MailMergeFolder * self;
	MailMergeFolderListEmailBySparseIdAsyncData* _data_;
	MailMergeFolder* _tmp0_;
	GeeCollection* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, MAIL_MERGE_TYPE_FOLDER, MailMergeFolder);
	_data_ = g_slice_new0 (MailMergeFolderListEmailBySparseIdAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, mail_merge_folder_real_list_email_by_sparse_id_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (ids);
	_g_object_unref0 (_data_->ids);
	_data_->ids = _tmp1_;
	_data_->required_fields = required_fields;
	_data_->flags = flags;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	mail_merge_folder_real_list_email_by_sparse_id_async_co (_data_);
}

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

static gboolean
mail_merge_folder_real_list_email_by_sparse_id_async_co (MailMergeFolderListEmailBySparseIdAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	geary_abstract_local_folder_check_open (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_ABSTRACT_LOCAL_FOLDER, GearyAbstractLocalFolder), &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp0_ = gee_array_list_new (GEARY_TYPE_EMAIL, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data_->list = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEE_TYPE_LIST, GeeList);
	{
		_data_->_tmp1_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_data_->ids, GEE_TYPE_ITERABLE, GeeIterable));
		_data_->_id_it = _data_->_tmp1_;
		while (TRUE) {
			_data_->_tmp2_ = _data_->_id_it;
			if (!gee_iterator_next (_data_->_tmp2_)) {
				break;
			}
			_data_->_tmp3_ = _data_->_id_it;
			_data_->_tmp4_ = gee_iterator_get (_data_->_tmp3_);
			_data_->id = (GearyEmailIdentifier*) _data_->_tmp4_;
			_data_->_tmp5_ = _data_->self->priv->email;
			_data_->_tmp6_ = _data_->id;
			_data_->_tmp7_ = gee_map_get (_data_->_tmp5_, _data_->_tmp6_);
			_data_->email = (GearyEmail*) _data_->_tmp7_;
			_data_->_tmp8_ = _data_->email;
			if (_data_->_tmp8_ == NULL) {
				_data_->_tmp9_ = _data_->id;
				_data_->_tmp10_ = geary_email_identifier_to_string (_data_->_tmp9_);
				_data_->_tmp11_ = _data_->_tmp10_;
				_data_->_tmp12_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_NOT_FOUND, "No email with ID %s in merge", _data_->_tmp11_);
				_data_->_tmp13_ = _data_->_tmp12_;
				_g_free0 (_data_->_tmp11_);
				_data_->_inner_error0_ = _data_->_tmp13_;
				g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
				_g_object_unref0 (_data_->email);
				_g_object_unref0 (_data_->id);
				_g_object_unref0 (_data_->_id_it);
				_g_object_unref0 (_data_->list);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
			_data_->_tmp14_ = _data_->list;
			_data_->_tmp15_ = _data_->email;
			gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp14_, GEE_TYPE_COLLECTION, GeeCollection), _data_->_tmp15_);
			_g_object_unref0 (_data_->email);
			_g_object_unref0 (_data_->id);
		}
		_g_object_unref0 (_data_->_id_it);
	}
	_data_->_tmp17_ = _data_->list;
	_data_->_tmp18_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp17_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp19_ = _data_->_tmp18_;
	if (_data_->_tmp19_ > 0) {
		_data_->_tmp20_ = _data_->list;
		_data_->_tmp16_ = _data_->_tmp20_;
	} else {
		_data_->_tmp16_ = NULL;
	}
	_data_->_tmp21_ = _g_object_ref0 (_data_->_tmp16_);
	_data_->result = _data_->_tmp21_;
	_g_object_unref0 (_data_->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
mail_merge_folder_real_set_used_as_custom (GearyFolder* base,
                                           gboolean enabled,
                                           GError** error)
{
	MailMergeFolder * self;
	GearyFolderSpecialUse _tmp0_ = 0;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, MAIL_MERGE_TYPE_FOLDER, MailMergeFolder);
	if (enabled) {
		_tmp0_ = GEARY_FOLDER_SPECIAL_USE_CUSTOM;
	} else {
		_tmp0_ = GEARY_FOLDER_SPECIAL_USE_NONE;
	}
	self->priv->_used_as = _tmp0_;
}

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

static void
mail_merge_folder_load_data (MailMergeFolder* self,
                             GCancellable* cancellable,
                             GAsyncReadyCallback _callback_,
                             gpointer _user_data_)
{
	MailMergeFolderLoadDataData* _data_;
	MailMergeFolder* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (MAIL_MERGE_IS_FOLDER (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (MailMergeFolderLoadDataData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, mail_merge_folder_load_data_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	mail_merge_folder_load_data_co (_data_);
}

static void
mail_merge_folder_load_data_finish (MailMergeFolder* self,
                                    GAsyncResult* _res_)
{
	MailMergeFolderLoadDataData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return;
	}
}

static Block1Data*
block1_data_ref (Block1Data* _data1_)
{
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}

static void
block1_data_unref (void * _userdata_)
{
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		MailMergeFolder* self;
		self = _data1_->self;
		_g_object_unref0 (_data1_->raw_rfc822);
		_g_object_unref0 (_data1_->template);
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}

static void
mail_merge_folder_load_data_ready (GObject* source_object,
                                   GAsyncResult* _res_,
                                   gpointer _user_data_)
{
	MailMergeFolderLoadDataData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	mail_merge_folder_load_data_co (_data_);
}

static void
___lambda4_ (Block1Data* _data1_,
             GCancellable* c,
             GError** error)
{
	MailMergeFolder* self;
	GearyRFC822Message* _tmp0_ = NULL;
	GearyEmail* _tmp1_;
	GearyRFC822Message* _tmp2_;
	GearyMemoryBuffer* _tmp3_ = NULL;
	GearyMemoryBuffer* _tmp4_;
	GearyMemoryBuffer* _tmp5_;
	GError* _inner_error0_ = NULL;
	self = _data1_->self;
	g_return_if_fail ((c == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (c, g_cancellable_get_type ()));
	_tmp1_ = _data1_->template;
	_tmp2_ = geary_email_get_message (_tmp1_, &_inner_error0_);
	_tmp0_ = _tmp2_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	_tmp4_ = geary_rf_c822_message_get_rfc822_buffer (_tmp0_, GEARY_RF_C822_MESSAGE_RF_C822_FORMAT_OPTIONS_NONE, &_inner_error0_);
	_tmp3_ = _tmp4_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp0_);
		return;
	}
	_tmp5_ = _tmp3_;
	_tmp3_ = NULL;
	_g_object_unref0 (_data1_->raw_rfc822);
	_data1_->raw_rfc822 = _tmp5_;
	_g_object_unref0 (_tmp3_);
	_g_object_unref0 (_tmp0_);
}

static void
____lambda4__geary_nonblocking_concurrent_concurrent_callback (GCancellable* cancellable,
                                                               gpointer self,
                                                               GError** error)
{
	___lambda4_ (self, cancellable, error);
}

static gboolean
mail_merge_folder_load_data_co (MailMergeFolderLoadDataData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		case 4:
		goto _state_4;
		case 5:
		goto _state_5;
		case 6:
		goto _state_6;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->next_id = (gint64) 0;
	{
		_data_->_data1_ = g_slice_new0 (Block1Data);
		_data_->_data1_->_ref_count_ = 1;
		_data_->_data1_->self = g_object_ref (_data_->self);
		_data_->_state_ = 1;
		mail_merge_folder_load_template (_data_->self, _data_->cancellable, mail_merge_folder_load_data_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp0_ = mail_merge_folder_load_template_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
		_data_->_data1_->template = _data_->_tmp0_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			block1_data_unref (_data_->_data1_);
			_data_->_data1_ = NULL;
			goto __catch0_g_error;
		}
		_data_->_data1_->raw_rfc822 = NULL;
		_data_->_tmp1_ = geary_nonblocking_concurrent_get_global ();
		_data_->_tmp2_ = _data_->_tmp1_;
		_data_->_state_ = 2;
		geary_nonblocking_concurrent_schedule_async (_data_->_tmp2_, ____lambda4__geary_nonblocking_concurrent_concurrent_callback, _data_->_data1_, _data_->cancellable, mail_merge_folder_load_data_ready, _data_);
		return FALSE;
		_state_2:
		geary_nonblocking_concurrent_schedule_finish (_data_->_tmp2_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			block1_data_unref (_data_->_data1_);
			_data_->_data1_ = NULL;
			goto __catch0_g_error;
		}
		_data_->_tmp3_ = _data_->self->priv->data;
		_data_->_tmp4_ = 0;
		_data_->_state_ = 3;
		mail_merge_csv_reader_read_record (_data_->_tmp3_, mail_merge_folder_load_data_ready, _data_);
		return FALSE;
		_state_3:
		_data_->_tmp5_ = mail_merge_csv_reader_read_record_finish (_data_->_tmp3_, _data_->_res_, &_data_->_tmp4_, &_data_->_inner_error0_);
		_data_->headers = _data_->_tmp5_;
		_data_->headers_length1 = _data_->_tmp4_;
		_data_->_headers_size_ = _data_->headers_length1;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			block1_data_unref (_data_->_data1_);
			_data_->_data1_ = NULL;
			goto __catch0_g_error;
		}
		_data_->_tmp6_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
		_data_->fields = _data_->_tmp6_;
		_data_->_tmp7_ = _data_->self->priv->data;
		_data_->_tmp8_ = 0;
		_data_->_state_ = 4;
		mail_merge_csv_reader_read_record (_data_->_tmp7_, mail_merge_folder_load_data_ready, _data_);
		return FALSE;
		_state_4:
		_data_->_tmp9_ = mail_merge_csv_reader_read_record_finish (_data_->_tmp7_, _data_->_res_, &_data_->_tmp8_, &_data_->_inner_error0_);
		_data_->record = _data_->_tmp9_;
		_data_->record_length1 = _data_->_tmp8_;
		_data_->_record_size_ = _data_->record_length1;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->fields);
			_data_->headers = (_vala_array_free (_data_->headers, _data_->headers_length1, (GDestroyNotify) g_free), NULL);
			block1_data_unref (_data_->_data1_);
			_data_->_data1_ = NULL;
			goto __catch0_g_error;
		}
		while (TRUE) {
			_data_->_tmp10_ = _data_->record;
			_data_->_tmp10__length1 = _data_->record_length1;
			if (!(_data_->_tmp10_ != NULL)) {
				break;
			}
			_data_->_tmp11_ = _data_->fields;
			gee_abstract_map_clear (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp11_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap));
			{
				_data_->i = 0;
				{
					_data_->_tmp12_ = TRUE;
					while (TRUE) {
						if (!_data_->_tmp12_) {
							_data_->_tmp13_ = _data_->i;
							_data_->i = _data_->_tmp13_ + 1;
						}
						_data_->_tmp12_ = FALSE;
						_data_->_tmp14_ = _data_->headers;
						_data_->_tmp14__length1 = _data_->headers_length1;
						if (!(_data_->i < _data_->_tmp14__length1)) {
							break;
						}
						_data_->_tmp15_ = _data_->fields;
						_data_->_tmp16_ = _data_->headers;
						_data_->_tmp16__length1 = _data_->headers_length1;
						_data_->_tmp17_ = _data_->_tmp16_[_data_->i];
						_data_->_tmp18_ = _data_->record;
						_data_->_tmp18__length1 = _data_->record_length1;
						_data_->_tmp19_ = _data_->_tmp18_[_data_->i];
						gee_abstract_map_set (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp15_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _data_->_tmp17_, _data_->_tmp19_);
					}
				}
			}
			_data_->_tmp20_ = _data_->self->priv->template;
			_data_->_tmp21_ = mail_merge_processor_new (_data_->_tmp20_);
			_data_->processor = _data_->_tmp21_;
			_data_->_tmp22_ = _data_->processor;
			_data_->_tmp23_ = _data_->fields;
			_data_->_tmp24_ = mail_merge_processor_merge (_data_->_tmp22_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp23_, GEE_TYPE_MAP, GeeMap), &_data_->_inner_error0_);
			_data_->composed = _data_->_tmp24_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->processor);
				_data_->record = (_vala_array_free (_data_->record, _data_->record_length1, (GDestroyNotify) g_free), NULL);
				_g_object_unref0 (_data_->fields);
				_data_->headers = (_vala_array_free (_data_->headers, _data_->headers_length1, (GDestroyNotify) g_free), NULL);
				block1_data_unref (_data_->_data1_);
				_data_->_data1_ = NULL;
				goto __catch0_g_error;
			}
			_data_->_tmp25_ = _data_->composed;
			_data_->_state_ = 5;
			geary_rf_c822_message_new_from_composed_email (_data_->_tmp25_, NULL, _data_->cancellable, mail_merge_folder_load_data_ready, _data_);
			return FALSE;
			_state_5:
			_data_->_tmp26_ = geary_rf_c822_message_new_from_composed_email_finish (_data_->_res_, &_data_->_inner_error0_);
			_data_->message = _data_->_tmp26_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->composed);
				_g_object_unref0 (_data_->processor);
				_data_->record = (_vala_array_free (_data_->record, _data_->record_length1, (GDestroyNotify) g_free), NULL);
				_g_object_unref0 (_data_->fields);
				_data_->headers = (_vala_array_free (_data_->headers, _data_->headers_length1, (GDestroyNotify) g_free), NULL);
				block1_data_unref (_data_->_data1_);
				_data_->_data1_ = NULL;
				goto __catch0_g_error;
			}
			_data_->_tmp27_ = _data_->next_id;
			_data_->next_id = _data_->_tmp27_ + 1;
			_data_->_tmp28_ = mail_merge_folder_email_identifier_new (_data_->_tmp27_);
			_data_->id = _data_->_tmp28_;
			_data_->_tmp29_ = _data_->id;
			_data_->_tmp30_ = _data_->message;
			_data_->_tmp31_ = geary_email_new_from_message (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp29_, GEARY_TYPE_EMAIL_IDENTIFIER, GearyEmailIdentifier), _data_->_tmp30_, &_data_->_inner_error0_);
			_data_->email = _data_->_tmp31_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->id);
				_g_object_unref0 (_data_->message);
				_g_object_unref0 (_data_->composed);
				_g_object_unref0 (_data_->processor);
				_data_->record = (_vala_array_free (_data_->record, _data_->record_length1, (GDestroyNotify) g_free), NULL);
				_g_object_unref0 (_data_->fields);
				_data_->headers = (_vala_array_free (_data_->headers, _data_->headers_length1, (GDestroyNotify) g_free), NULL);
				block1_data_unref (_data_->_data1_);
				_data_->_data1_ = NULL;
				goto __catch0_g_error;
			}
			_data_->_tmp32_ = _data_->email;
			geary_email_set_send_date (_data_->_tmp32_, NULL);
			_data_->_tmp33_ = _data_->email;
			_data_->_tmp34_ = geary_email_flags_new ();
			_data_->_tmp35_ = _data_->_tmp34_;
			geary_email_set_flags (_data_->_tmp33_, _data_->_tmp35_);
			_g_object_unref0 (_data_->_tmp35_);
			_data_->_tmp36_ = _data_->self->priv->ids;
			_data_->_tmp37_ = _data_->id;
			gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp36_, GEE_TYPE_COLLECTION, GeeCollection), G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp37_, GEARY_TYPE_EMAIL_IDENTIFIER, GearyEmailIdentifier));
			_data_->_tmp38_ = _data_->self->priv->composed;
			_data_->_tmp39_ = _data_->id;
			_data_->_tmp40_ = _data_->composed;
			gee_map_set (_data_->_tmp38_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp39_, GEARY_TYPE_EMAIL_IDENTIFIER, GearyEmailIdentifier), _data_->_tmp40_);
			_data_->_tmp41_ = _data_->self->priv->email;
			_data_->_tmp42_ = _data_->id;
			_data_->_tmp43_ = _data_->email;
			gee_map_set (_data_->_tmp41_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp42_, GEARY_TYPE_EMAIL_IDENTIFIER, GearyEmailIdentifier), _data_->_tmp43_);
			_data_->_tmp44_ = _data_->self->priv->_properties;
			mail_merge_folder_folder_properties_set_total (_data_->_tmp44_, (gint) _data_->next_id);
			mail_merge_folder_set_email_total (_data_->self, (guint) _data_->next_id);
			_data_->_tmp45_ = _data_->id;
			_data_->_tmp46_ = geary_collection_single (MAIL_MERGE_FOLDER_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->_tmp45_);
			_data_->_tmp47_ = _data_->_tmp46_;
			geary_folder_notify_email_inserted (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_FOLDER, GearyFolder), _data_->_tmp47_);
			_g_object_unref0 (_data_->_tmp47_);
			_data_->_tmp49_ = _data_->self->priv->data;
			_data_->_tmp50_ = 0;
			_data_->_state_ = 6;
			mail_merge_csv_reader_read_record (_data_->_tmp49_, mail_merge_folder_load_data_ready, _data_);
			return FALSE;
			_state_6:
			_data_->_tmp51_ = mail_merge_csv_reader_read_record_finish (_data_->_tmp49_, _data_->_res_, &_data_->_tmp50_, &_data_->_inner_error0_);
			_data_->_tmp48_ = _data_->_tmp51_;
			_data_->_tmp48__length1 = _data_->_tmp50_;
			_data_->__tmp48__size_ = _data_->_tmp48__length1;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->email);
				_g_object_unref0 (_data_->id);
				_g_object_unref0 (_data_->message);
				_g_object_unref0 (_data_->composed);
				_g_object_unref0 (_data_->processor);
				_data_->record = (_vala_array_free (_data_->record, _data_->record_length1, (GDestroyNotify) g_free), NULL);
				_g_object_unref0 (_data_->fields);
				_data_->headers = (_vala_array_free (_data_->headers, _data_->headers_length1, (GDestroyNotify) g_free), NULL);
				block1_data_unref (_data_->_data1_);
				_data_->_data1_ = NULL;
				goto __catch0_g_error;
			}
			_data_->_tmp52_ = _data_->_tmp48_;
			_data_->_tmp52__length1 = _data_->_tmp48__length1;
			_data_->_tmp48_ = NULL;
			_data_->_tmp48__length1 = 0;
			_data_->record = (_vala_array_free (_data_->record, _data_->record_length1, (GDestroyNotify) g_free), NULL);
			_data_->record = _data_->_tmp52_;
			_data_->record_length1 = _data_->_tmp52__length1;
			_data_->_record_size_ = _data_->record_length1;
			_data_->_tmp48_ = (_vala_array_free (_data_->_tmp48_, _data_->_tmp48__length1, (GDestroyNotify) g_free), NULL);
			_g_object_unref0 (_data_->email);
			_g_object_unref0 (_data_->id);
			_g_object_unref0 (_data_->message);
			_g_object_unref0 (_data_->composed);
			_g_object_unref0 (_data_->processor);
		}
		_data_->record = (_vala_array_free (_data_->record, _data_->record_length1, (GDestroyNotify) g_free), NULL);
		_g_object_unref0 (_data_->fields);
		_data_->headers = (_vala_array_free (_data_->headers, _data_->headers_length1, (GDestroyNotify) g_free), NULL);
		block1_data_unref (_data_->_data1_);
		_data_->_data1_ = NULL;
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->err = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp53_ = _data_->err;
		_data_->_tmp54_ = _data_->_tmp53_->message;
		geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Error processing email for merge: %s", _data_->_tmp54_);
		_g_error_free0 (_data_->err);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		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_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
mail_merge_folder_load_template_data_free (gpointer _data)
{
	MailMergeFolderLoadTemplateData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (MailMergeFolderLoadTemplateData, _data_);
}

static void
mail_merge_folder_load_template (MailMergeFolder* self,
                                 GCancellable* cancellable,
                                 GAsyncReadyCallback _callback_,
                                 gpointer _user_data_)
{
	MailMergeFolderLoadTemplateData* _data_;
	MailMergeFolder* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (MAIL_MERGE_IS_FOLDER (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (MailMergeFolderLoadTemplateData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, mail_merge_folder_load_template_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	mail_merge_folder_load_template_co (_data_);
}

static GearyEmail*
mail_merge_folder_load_template_finish (MailMergeFolder* self,
                                        GAsyncResult* _res_,
                                        GError** error)
{
	GearyEmail* result;
	MailMergeFolderLoadTemplateData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
mail_merge_folder_load_template_ready (GObject* source_object,
                                       GAsyncResult* _res_,
                                       gpointer _user_data_)
{
	MailMergeFolderLoadTemplateData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	mail_merge_folder_load_template_co (_data_);
}

static gboolean
mail_merge_folder_load_template_co (MailMergeFolderLoadTemplateData* _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->template;
	_data_->_tmp1_ = _g_object_ref0 (_data_->_tmp0_);
	_data_->template = _data_->_tmp1_;
	_data_->_tmp2_ = _data_->template;
	_data_->_tmp3_ = geary_email_get_fields (_data_->_tmp2_);
	_data_->_tmp4_ = _data_->_tmp3_;
	if (!geary_email_field_fulfills (_data_->_tmp4_, GEARY_EMAIL_REQUIRED_FOR_MESSAGE)) {
		_data_->_tmp6_ = geary_folder_get_account (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_FOLDER, GearyFolder));
		_data_->_tmp7_ = _data_->_tmp6_;
		_data_->_tmp8_ = _data_->template;
		_data_->_tmp9_ = geary_email_get_id (_data_->_tmp8_);
		_data_->_tmp10_ = _data_->_tmp9_;
		_data_->_state_ = 1;
		geary_account_local_fetch_email_async (_data_->_tmp7_, _data_->_tmp10_, GEARY_EMAIL_REQUIRED_FOR_MESSAGE, _data_->cancellable, mail_merge_folder_load_template_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp11_ = geary_account_local_fetch_email_finish (_data_->_tmp7_, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp5_ = _data_->_tmp11_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->template);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp12_ = _data_->_tmp5_;
		_data_->_tmp5_ = NULL;
		_g_object_unref0 (_data_->template);
		_data_->template = _data_->_tmp12_;
		_g_object_unref0 (_data_->_tmp5_);
	}
	_data_->result = _data_->template;
	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
mail_merge_folder_send_loop_data_free (gpointer _data)
{
	MailMergeFolderSendLoopData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (MailMergeFolderSendLoopData, _data_);
}

static void
mail_merge_folder_send_loop (MailMergeFolder* self,
                             GAsyncReadyCallback _callback_,
                             gpointer _user_data_)
{
	MailMergeFolderSendLoopData* _data_;
	MailMergeFolder* _tmp0_;
	g_return_if_fail (MAIL_MERGE_IS_FOLDER (self));
	_data_ = g_slice_new0 (MailMergeFolderSendLoopData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, mail_merge_folder_send_loop_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	mail_merge_folder_send_loop_co (_data_);
}

static void
mail_merge_folder_send_loop_finish (MailMergeFolder* self,
                                    GAsyncResult* _res_)
{
	MailMergeFolderSendLoopData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
mail_merge_folder_send_loop_ready (GObject* source_object,
                                   GAsyncResult* _res_,
                                   gpointer _user_data_)
{
	MailMergeFolderSendLoopData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	mail_merge_folder_send_loop_co (_data_);
}

static gboolean
_mail_merge_folder_send_loop_co_gsource_func (gpointer self)
{
	gboolean result;
	result = mail_merge_folder_send_loop_co (self);
	return result;
}

static gboolean
mail_merge_folder_send_loop_co (MailMergeFolderSendLoopData* _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_->_tmp0_ = _data_->self->priv->sending;
	_data_->_tmp1_ = _g_object_ref0 (_data_->_tmp0_);
	_data_->cancellable = _data_->_tmp1_;
	_data_->_tmp2_ = _data_->self->priv->_account;
	_data_->_tmp3_ = geary_account_get_outgoing (_data_->_tmp2_);
	_data_->_tmp4_ = _data_->_tmp3_;
	_data_->_tmp5_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_data_->_tmp4_, GEARY_SMTP_TYPE_CLIENT_SERVICE) ? ((GearySmtpClientService*) _data_->_tmp4_) : NULL);
	_data_->smtp = _data_->_tmp5_;
	_data_->_tmp6_ = _data_->smtp;
	if (_data_->_tmp6_ != NULL) {
		while (TRUE) {
			_data_->_tmp8_ = _data_->self->priv->ids;
			_data_->_tmp9_ = gee_collection_get_is_empty (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp8_, GEE_TYPE_COLLECTION, GeeCollection));
			_data_->_tmp10_ = _data_->_tmp9_;
			if (!_data_->_tmp10_) {
				_data_->_tmp11_ = _data_->self->priv->sending;
				_data_->_tmp7_ = !g_cancellable_is_cancelled (_data_->_tmp11_);
			} else {
				_data_->_tmp7_ = FALSE;
			}
			if (!_data_->_tmp7_) {
				break;
			}
			_data_->_tmp12_ = _data_->self->priv->ids;
			_data_->_tmp13_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp12_, GEE_TYPE_COLLECTION, GeeCollection));
			_data_->_tmp14_ = _data_->_tmp13_;
			_data_->last = _data_->_tmp14_ - 1;
			_data_->_tmp15_ = _data_->self->priv->ids;
			_data_->_tmp16_ = gee_list_get (_data_->_tmp15_, _data_->last);
			_data_->id = (GearyEmailIdentifier*) _data_->_tmp16_;
			{
				_data_->_tmp17_ = _data_->self->priv->composed;
				_data_->_tmp18_ = _data_->id;
				_data_->_tmp19_ = gee_map_get (_data_->_tmp17_, _data_->_tmp18_);
				_data_->composed = (GearyComposedEmail*) _data_->_tmp19_;
				_data_->_tmp20_ = _data_->composed;
				_data_->_tmp21_ = g_time_zone_new_local ();
				_data_->_tmp22_ = _data_->_tmp21_;
				_data_->_tmp23_ = g_date_time_new_now (_data_->_tmp22_);
				_data_->_tmp24_ = _data_->_tmp23_;
				_data_->_tmp25_ = geary_composed_email_set_date (_data_->_tmp20_, _data_->_tmp24_);
				_data_->_tmp26_ = _data_->_tmp25_;
				_g_object_unref0 (_data_->_tmp26_);
				_g_date_time_unref0 (_data_->_tmp24_);
				_g_time_zone_unref0 (_data_->_tmp22_);
				_data_->_tmp27_ = _data_->smtp;
				_data_->_tmp28_ = _data_->composed;
				_data_->_tmp29_ = _data_->cancellable;
				_data_->_state_ = 1;
				geary_smtp_client_service_send_email (_data_->_tmp27_, _data_->_tmp28_, _data_->_tmp29_, mail_merge_folder_send_loop_ready, _data_);
				return FALSE;
				_state_1:
				geary_smtp_client_service_send_email_finish (_data_->_tmp27_, _data_->_res_, &_data_->_inner_error0_);
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					_g_object_unref0 (_data_->composed);
					goto __catch0_g_error;
				}
				_data_->_tmp30_ = _data_->self->priv->_email_sent;
				mail_merge_folder_set_email_sent (_data_->self, _data_->_tmp30_ + 1);
				_data_->_tmp31_ = _data_->self->priv->ids;
				_data_->_tmp32_ = gee_list_remove_at (_data_->_tmp31_, _data_->last);
				_data_->_tmp33_ = (GearyEmailIdentifier*) _data_->_tmp32_;
				_g_object_unref0 (_data_->_tmp33_);
				_data_->_tmp34_ = _data_->self->priv->email;
				_data_->_tmp35_ = _data_->id;
				gee_map_unset (_data_->_tmp34_, _data_->_tmp35_, NULL);
				_data_->_tmp36_ = _data_->self->priv->composed;
				_data_->_tmp37_ = _data_->id;
				gee_map_unset (_data_->_tmp36_, _data_->_tmp37_, NULL);
				_data_->_tmp38_ = _data_->self->priv->_properties;
				mail_merge_folder_folder_properties_set_total (_data_->_tmp38_, _data_->last);
				_data_->_tmp39_ = _data_->id;
				_data_->_tmp40_ = geary_collection_single (GEARY_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->_tmp39_);
				_data_->_tmp41_ = _data_->_tmp40_;
				geary_folder_notify_email_removed (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_TYPE_FOLDER, GearyFolder), _data_->_tmp41_);
				_g_object_unref0 (_data_->_tmp41_);
				g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) 2, _mail_merge_folder_send_loop_co_gsource_func, _data_, NULL);
				_data_->_state_ = 2;
				return FALSE;
				_state_2:
				;
				_g_object_unref0 (_data_->composed);
			}
			goto __finally0;
			__catch0_g_error:
			{
				_data_->err = _data_->_inner_error0_;
				_data_->_inner_error0_ = NULL;
				_data_->_tmp42_ = _data_->err;
				_data_->_tmp43_ = _data_->_tmp42_->message;
				geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Error sending merge email: %s", _data_->_tmp43_);
				_data_->_tmp44_ = _data_->err;
				g_signal_emit (_data_->self, mail_merge_folder_signals[MAIL_MERGE_FOLDER_SEND_ERROR_SIGNAL], 0, _data_->_tmp44_);
				_g_error_free0 (_data_->err);
				_g_object_unref0 (_data_->id);
				break;
			}
			__finally0:
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->id);
				_g_object_unref0 (_data_->smtp);
				_g_object_unref0 (_data_->cancellable);
				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_->id);
		}
	} else {
		geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Account has no outgoing SMTP service");
	}
	mail_merge_folder_set_is_sending (_data_->self, FALSE);
	_g_object_unref0 (_data_->smtp);
	_g_object_unref0 (_data_->cancellable);
	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
mail_merge_folder_email_identifier_get_instance_private (MailMergeFolderEmailIdentifier* self)
{
	return G_STRUCT_MEMBER_P (self, MailMergeFolderEmailIdentifier_private_offset);
}

static gint64
mail_merge_folder_email_identifier_get_message_id (MailMergeFolderEmailIdentifier* self)
{
	gint64 result;
	g_return_val_if_fail (MAIL_MERGE_FOLDER_IS_EMAIL_IDENTIFIER (self), 0LL);
	result = self->priv->_message_id;
	return result;
}

static void
mail_merge_folder_email_identifier_set_message_id (MailMergeFolderEmailIdentifier* self,
                                                   gint64 value)
{
	gint64 old_value;
	g_return_if_fail (MAIL_MERGE_FOLDER_IS_EMAIL_IDENTIFIER (self));
	old_value = mail_merge_folder_email_identifier_get_message_id (self);
	if (old_value != value) {
		self->priv->_message_id = value;
		g_object_notify_by_pspec ((GObject *) self, mail_merge_folder_email_identifier_properties[MAIL_MERGE_FOLDER_EMAIL_IDENTIFIER_MESSAGE_ID_PROPERTY]);
	}
}

static MailMergeFolderEmailIdentifier*
mail_merge_folder_email_identifier_construct (GType object_type,
                                              gint64 message_id)
{
	MailMergeFolderEmailIdentifier * self = NULL;
	self = (MailMergeFolderEmailIdentifier*) geary_email_identifier_construct (object_type);
	mail_merge_folder_email_identifier_set_message_id (self, message_id);
	return self;
}

static MailMergeFolderEmailIdentifier*
mail_merge_folder_email_identifier_new (gint64 message_id)
{
	return mail_merge_folder_email_identifier_construct (MAIL_MERGE_FOLDER_TYPE_EMAIL_IDENTIFIER, message_id);
}

static MailMergeFolderEmailIdentifier*
mail_merge_folder_email_identifier_construct_from_variant (GType object_type,
                                                           GVariant* serialised,
                                                           GError** error)
{
	MailMergeFolderEmailIdentifier * self = NULL;
	const gchar* _tmp0_;
	GVariant* inner = NULL;
	GVariant* _tmp3_;
	GVariant* mid = NULL;
	GVariant* _tmp4_;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (serialised != NULL, NULL);
	_tmp0_ = g_variant_get_type_string (serialised);
	if (g_strcmp0 (_tmp0_, MAIL_MERGE_FOLDER_EMAIL_IDENTIFIER_VARIANT_TYPE) != 0) {
		const gchar* _tmp1_;
		GError* _tmp2_;
		_tmp1_ = g_variant_get_type_string (serialised);
		_tmp2_ = g_error_new (GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_BAD_PARAMETERS, "Invalid serialised id type: %s", _tmp1_);
		_inner_error0_ = _tmp2_;
		if (_inner_error0_->domain == GEARY_ENGINE_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (self);
			return NULL;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
	}
	_tmp3_ = g_variant_get_child_value (serialised, (gsize) 1);
	inner = _tmp3_;
	_tmp4_ = g_variant_get_child_value (inner, (gsize) 0);
	mid = _tmp4_;
	self = (MailMergeFolderEmailIdentifier*) mail_merge_folder_email_identifier_construct (object_type, g_variant_get_int64 (mid));
	_g_variant_unref0 (mid);
	_g_variant_unref0 (inner);
	return self;
}

static MailMergeFolderEmailIdentifier*
mail_merge_folder_email_identifier_new_from_variant (GVariant* serialised,
                                                     GError** error)
{
	return mail_merge_folder_email_identifier_construct_from_variant (MAIL_MERGE_FOLDER_TYPE_EMAIL_IDENTIFIER, serialised, error);
}

/** {@inheritDoc} */
static guint
mail_merge_folder_email_identifier_real_hash (GearyEmailIdentifier* base)
{
	MailMergeFolderEmailIdentifier * self;
	GHashFunc _tmp0_;
	gint64 _tmp1_;
	guint result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, MAIL_MERGE_FOLDER_TYPE_EMAIL_IDENTIFIER, MailMergeFolderEmailIdentifier);
	_tmp0_ = g_int64_hash;
	_tmp1_ = self->priv->_message_id;
	result = _tmp0_ (&_tmp1_);
	return result;
}

/** {@inheritDoc} */
static gboolean
mail_merge_folder_email_identifier_real_equal_to (GearyEmailIdentifier* base,
                                                  GearyEmailIdentifier* other)
{
	MailMergeFolderEmailIdentifier * self;
	gboolean _tmp0_ = FALSE;
	gboolean result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, MAIL_MERGE_FOLDER_TYPE_EMAIL_IDENTIFIER, MailMergeFolderEmailIdentifier);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (other, GEARY_TYPE_EMAIL_IDENTIFIER), FALSE);
	if (G_TYPE_FROM_INSTANCE (G_TYPE_CHECK_INSTANCE_CAST (self, G_TYPE_OBJECT, GObject)) == G_TYPE_FROM_INSTANCE (G_TYPE_CHECK_INSTANCE_CAST (other, G_TYPE_OBJECT, GObject))) {
		gint64 _tmp1_;
		gint64 _tmp2_;
		_tmp1_ = self->priv->_message_id;
		_tmp2_ = G_TYPE_CHECK_INSTANCE_CAST (other, MAIL_MERGE_FOLDER_TYPE_EMAIL_IDENTIFIER, MailMergeFolderEmailIdentifier)->priv->_message_id;
		_tmp0_ = _tmp1_ == _tmp2_;
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

/** {@inheritDoc} */
static gchar*
mail_merge_folder_email_identifier_real_to_string (GearyEmailIdentifier* base)
{
	MailMergeFolderEmailIdentifier * self;
	const gchar* _tmp0_;
	gint64 _tmp1_;
	gchar* _tmp2_;
	gchar* result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, MAIL_MERGE_FOLDER_TYPE_EMAIL_IDENTIFIER, MailMergeFolderEmailIdentifier);
	_tmp0_ = g_type_name (G_TYPE_FROM_INSTANCE (G_TYPE_CHECK_INSTANCE_CAST (self, G_TYPE_OBJECT, GObject)));
	_tmp1_ = self->priv->_message_id;
	_tmp2_ = g_strdup_printf ("%s(%lld)", _tmp0_, _tmp1_);
	result = _tmp2_;
	return result;
}

static gint
mail_merge_folder_email_identifier_real_natural_sort_comparator (GearyEmailIdentifier* base,
                                                                 GearyEmailIdentifier* o)
{
	MailMergeFolderEmailIdentifier * self;
	MailMergeFolderEmailIdentifier* other = NULL;
	MailMergeFolderEmailIdentifier* _tmp0_;
	MailMergeFolderEmailIdentifier* _tmp1_;
	gint64 _tmp2_;
	MailMergeFolderEmailIdentifier* _tmp3_;
	gint64 _tmp4_;
	gint result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, MAIL_MERGE_FOLDER_TYPE_EMAIL_IDENTIFIER, MailMergeFolderEmailIdentifier);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (o, GEARY_TYPE_EMAIL_IDENTIFIER), 0);
	_tmp0_ = _g_object_ref0 (MAIL_MERGE_FOLDER_IS_EMAIL_IDENTIFIER (o) ? ((MailMergeFolderEmailIdentifier*) o) : NULL);
	other = _tmp0_;
	_tmp1_ = other;
	if (_tmp1_ == NULL) {
		result = 1;
		_g_object_unref0 (other);
		return result;
	}
	_tmp2_ = self->priv->_message_id;
	_tmp3_ = other;
	_tmp4_ = _tmp3_->priv->_message_id;
	result = (gint) CLAMP (_tmp2_ - _tmp4_, (gint64) -1, (gint64) 1);
	_g_object_unref0 (other);
	return result;
}

static GVariant*
mail_merge_folder_email_identifier_real_to_variant (GearyEmailIdentifier* base)
{
	MailMergeFolderEmailIdentifier * self;
	GVariant* _tmp0_;
	gint64 _tmp1_;
	GVariant* _tmp2_;
	GVariant** _tmp3_;
	GVariant** _tmp4_;
	gint _tmp4__length1;
	GVariant* _tmp5_;
	GVariant** _tmp6_;
	GVariant** _tmp7_;
	gint _tmp7__length1;
	GVariant* _tmp8_;
	GVariant* _tmp9_;
	GVariant* result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, MAIL_MERGE_FOLDER_TYPE_EMAIL_IDENTIFIER, MailMergeFolderEmailIdentifier);
	_tmp0_ = g_variant_new_byte ((guint8) 'm');
	g_variant_ref_sink (_tmp0_);
	_tmp1_ = self->priv->_message_id;
	_tmp2_ = g_variant_new_int64 (_tmp1_);
	g_variant_ref_sink (_tmp2_);
	_tmp3_ = g_new0 (GVariant*, 1 + 1);
	_tmp3_[0] = _tmp2_;
	_tmp4_ = _tmp3_;
	_tmp4__length1 = 1;
	_tmp5_ = g_variant_new_tuple (_tmp4_, 1);
	g_variant_ref_sink (_tmp5_);
	_tmp6_ = g_new0 (GVariant*, 2 + 1);
	_tmp6_[0] = _tmp0_;
	_tmp6_[1] = _tmp5_;
	_tmp7_ = _tmp6_;
	_tmp7__length1 = 2;
	_tmp8_ = g_variant_new_tuple (_tmp7_, 2);
	g_variant_ref_sink (_tmp8_);
	_tmp9_ = _tmp8_;
	_tmp7_ = (_vala_array_free (_tmp7_, _tmp7__length1, (GDestroyNotify) g_variant_unref), NULL);
	_tmp4_ = (_vala_array_free (_tmp4_, _tmp4__length1, (GDestroyNotify) g_variant_unref), NULL);
	result = _tmp9_;
	return result;
}

static void
mail_merge_folder_email_identifier_class_init (MailMergeFolderEmailIdentifierClass * klass,
                                               gpointer klass_data)
{
	mail_merge_folder_email_identifier_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &MailMergeFolderEmailIdentifier_private_offset);
	((GearyEmailIdentifierClass *) klass)->hash = (guint (*) (GearyEmailIdentifier*)) mail_merge_folder_email_identifier_real_hash;
	((GearyEmailIdentifierClass *) klass)->equal_to = (gboolean (*) (GearyEmailIdentifier*, GearyEmailIdentifier*)) mail_merge_folder_email_identifier_real_equal_to;
	((GearyEmailIdentifierClass *) klass)->to_string = (gchar* (*) (GearyEmailIdentifier*)) mail_merge_folder_email_identifier_real_to_string;
	((GearyEmailIdentifierClass *) klass)->natural_sort_comparator = (gint (*) (GearyEmailIdentifier*, GearyEmailIdentifier*)) mail_merge_folder_email_identifier_real_natural_sort_comparator;
	((GearyEmailIdentifierClass *) klass)->to_variant = (GVariant* (*) (GearyEmailIdentifier*)) mail_merge_folder_email_identifier_real_to_variant;
	G_OBJECT_CLASS (klass)->get_property = _vala_mail_merge_folder_email_identifier_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_mail_merge_folder_email_identifier_set_property;
	G_OBJECT_CLASS (klass)->finalize = mail_merge_folder_email_identifier_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), MAIL_MERGE_FOLDER_EMAIL_IDENTIFIER_MESSAGE_ID_PROPERTY, mail_merge_folder_email_identifier_properties[MAIL_MERGE_FOLDER_EMAIL_IDENTIFIER_MESSAGE_ID_PROPERTY] = g_param_spec_int64 ("message-id", "message-id", "message-id", G_MININT64, G_MAXINT64, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
mail_merge_folder_email_identifier_instance_init (MailMergeFolderEmailIdentifier * self,
                                                  gpointer klass)
{
	self->priv = mail_merge_folder_email_identifier_get_instance_private (self);
}

static void
mail_merge_folder_email_identifier_finalize (GObject * obj)
{
	MailMergeFolderEmailIdentifier * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, MAIL_MERGE_FOLDER_TYPE_EMAIL_IDENTIFIER, MailMergeFolderEmailIdentifier);
	G_OBJECT_CLASS (mail_merge_folder_email_identifier_parent_class)->finalize (obj);
}

static GType
mail_merge_folder_email_identifier_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (MailMergeFolderEmailIdentifierClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) mail_merge_folder_email_identifier_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MailMergeFolderEmailIdentifier), 0, (GInstanceInitFunc) mail_merge_folder_email_identifier_instance_init, NULL };
	GType mail_merge_folder_email_identifier_type_id;
	mail_merge_folder_email_identifier_type_id = g_type_register_static (GEARY_TYPE_EMAIL_IDENTIFIER, "MailMergeFolderEmailIdentifier", &g_define_type_info, 0);
	MailMergeFolderEmailIdentifier_private_offset = g_type_add_instance_private (mail_merge_folder_email_identifier_type_id, sizeof (MailMergeFolderEmailIdentifierPrivate));
	return mail_merge_folder_email_identifier_type_id;
}

static GType
mail_merge_folder_email_identifier_get_type (void)
{
	static volatile gsize mail_merge_folder_email_identifier_type_id__once = 0;
	if (g_once_init_enter (&mail_merge_folder_email_identifier_type_id__once)) {
		GType mail_merge_folder_email_identifier_type_id;
		mail_merge_folder_email_identifier_type_id = mail_merge_folder_email_identifier_get_type_once ();
		g_once_init_leave (&mail_merge_folder_email_identifier_type_id__once, mail_merge_folder_email_identifier_type_id);
	}
	return mail_merge_folder_email_identifier_type_id__once;
}

static void
_vala_mail_merge_folder_email_identifier_get_property (GObject * object,
                                                       guint property_id,
                                                       GValue * value,
                                                       GParamSpec * pspec)
{
	MailMergeFolderEmailIdentifier * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, MAIL_MERGE_FOLDER_TYPE_EMAIL_IDENTIFIER, MailMergeFolderEmailIdentifier);
	switch (property_id) {
		case MAIL_MERGE_FOLDER_EMAIL_IDENTIFIER_MESSAGE_ID_PROPERTY:
		g_value_set_int64 (value, mail_merge_folder_email_identifier_get_message_id (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_mail_merge_folder_email_identifier_set_property (GObject * object,
                                                       guint property_id,
                                                       const GValue * value,
                                                       GParamSpec * pspec)
{
	MailMergeFolderEmailIdentifier * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, MAIL_MERGE_FOLDER_TYPE_EMAIL_IDENTIFIER, MailMergeFolderEmailIdentifier);
	switch (property_id) {
		case MAIL_MERGE_FOLDER_EMAIL_IDENTIFIER_MESSAGE_ID_PROPERTY:
		mail_merge_folder_email_identifier_set_message_id (self, g_value_get_int64 (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static MailMergeFolderFolderProperties*
mail_merge_folder_folder_properties_construct (GType object_type)
{
	MailMergeFolderFolderProperties * self = NULL;
	self = (MailMergeFolderFolderProperties*) geary_folder_properties_construct (object_type, 0, 0, GEARY_TRILLIAN_FALSE, GEARY_TRILLIAN_FALSE, GEARY_TRILLIAN_TRUE, TRUE, FALSE, FALSE);
	return self;
}

static MailMergeFolderFolderProperties*
mail_merge_folder_folder_properties_new (void)
{
	return mail_merge_folder_folder_properties_construct (MAIL_MERGE_FOLDER_TYPE_FOLDER_PROPERTIES);
}

static void
mail_merge_folder_folder_properties_set_total (MailMergeFolderFolderProperties* self,
                                               gint total)
{
	g_return_if_fail (MAIL_MERGE_FOLDER_IS_FOLDER_PROPERTIES (self));
	geary_folder_properties_set_email_total (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_TYPE_FOLDER_PROPERTIES, GearyFolderProperties), total);
}

static void
mail_merge_folder_folder_properties_class_init (MailMergeFolderFolderPropertiesClass * klass,
                                                gpointer klass_data)
{
	mail_merge_folder_folder_properties_parent_class = g_type_class_peek_parent (klass);
}

static void
mail_merge_folder_folder_properties_instance_init (MailMergeFolderFolderProperties * self,
                                                   gpointer klass)
{
}

static GType
mail_merge_folder_folder_properties_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (MailMergeFolderFolderPropertiesClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) mail_merge_folder_folder_properties_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MailMergeFolderFolderProperties), 0, (GInstanceInitFunc) mail_merge_folder_folder_properties_instance_init, NULL };
	GType mail_merge_folder_folder_properties_type_id;
	mail_merge_folder_folder_properties_type_id = g_type_register_static (GEARY_TYPE_FOLDER_PROPERTIES, "MailMergeFolderFolderProperties", &g_define_type_info, 0);
	return mail_merge_folder_folder_properties_type_id;
}

static GType
mail_merge_folder_folder_properties_get_type (void)
{
	static volatile gsize mail_merge_folder_folder_properties_type_id__once = 0;
	if (g_once_init_enter (&mail_merge_folder_folder_properties_type_id__once)) {
		GType mail_merge_folder_folder_properties_type_id;
		mail_merge_folder_folder_properties_type_id = mail_merge_folder_folder_properties_get_type_once ();
		g_once_init_leave (&mail_merge_folder_folder_properties_type_id__once, mail_merge_folder_folder_properties_type_id);
	}
	return mail_merge_folder_folder_properties_type_id__once;
}

static void
mail_merge_folder_class_init (MailMergeFolderClass * klass,
                              gpointer klass_data)
{
	mail_merge_folder_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &MailMergeFolder_private_offset);
	((GearyFolderClass *) klass)->close_async = (void (*) (GearyFolder*, GCancellable*, GAsyncReadyCallback, gpointer)) mail_merge_folder_real_close_async;
	((GearyFolderClass *) klass)->close_finish = (gboolean (*) (GearyFolder*, GAsyncResult*, GError**)) mail_merge_folder_close_finish;
	((GearyFolderClass *) klass)->contains_identifiers = (void (*) (GearyFolder*, GeeCollection*, GCancellable*, GAsyncReadyCallback, gpointer)) mail_merge_folder_real_contains_identifiers;
	((GearyFolderClass *) klass)->contains_identifiers_finish = (GeeCollection* (*) (GearyFolder*, GAsyncResult*, GError**)) mail_merge_folder_contains_identifiers_finish;
	((GearyFolderClass *) klass)->fetch_email_async = (void (*) (GearyFolder*, GearyEmailIdentifier*, GearyEmailField, GearyFolderListFlags, GCancellable*, GAsyncReadyCallback, gpointer)) mail_merge_folder_real_fetch_email_async;
	((GearyFolderClass *) klass)->fetch_email_finish = (GearyEmail* (*) (GearyFolder*, GAsyncResult*, GError**)) mail_merge_folder_fetch_email_finish;
	((GearyFolderClass *) klass)->list_email_by_id_async = (void (*) (GearyFolder*, GearyEmailIdentifier*, gint, GearyEmailField, GearyFolderListFlags, GCancellable*, GAsyncReadyCallback, gpointer)) mail_merge_folder_real_list_email_by_id_async;
	((GearyFolderClass *) klass)->list_email_by_id_finish = (GeeList* (*) (GearyFolder*, GAsyncResult*, GError**)) mail_merge_folder_list_email_by_id_finish;
	((GearyFolderClass *) klass)->list_email_by_sparse_id_async = (void (*) (GearyFolder*, GeeCollection*, GearyEmailField, GearyFolderListFlags, GCancellable*, GAsyncReadyCallback, gpointer)) mail_merge_folder_real_list_email_by_sparse_id_async;
	((GearyFolderClass *) klass)->list_email_by_sparse_id_finish = (GeeList* (*) (GearyFolder*, GAsyncResult*, GError**)) mail_merge_folder_list_email_by_sparse_id_finish;
	((GearyFolderClass *) klass)->set_used_as_custom = (void (*) (GearyFolder*, gboolean, GError**)) mail_merge_folder_real_set_used_as_custom;
	GEARY_FOLDER_CLASS (klass)->get_account = mail_merge_folder_real_get_account;
	GEARY_FOLDER_CLASS (klass)->get_properties = mail_merge_folder_real_get_properties;
	GEARY_FOLDER_CLASS (klass)->get_path = mail_merge_folder_real_get_path;
	GEARY_FOLDER_CLASS (klass)->get_used_as = mail_merge_folder_real_get_used_as;
	G_OBJECT_CLASS (klass)->get_property = _vala_mail_merge_folder_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_mail_merge_folder_set_property;
	G_OBJECT_CLASS (klass)->finalize = mail_merge_folder_finalize;
	/** {@inheritDoc} */
	g_object_class_install_property (G_OBJECT_CLASS (klass), MAIL_MERGE_FOLDER_ACCOUNT_PROPERTY, mail_merge_folder_properties[MAIL_MERGE_FOLDER_ACCOUNT_PROPERTY] = g_param_spec_object ("account", "account", "account", GEARY_TYPE_ACCOUNT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** {@inheritDoc} */
	g_object_class_install_property (G_OBJECT_CLASS (klass), MAIL_MERGE_FOLDER_PROPERTIES_PROPERTY, mail_merge_folder_properties[MAIL_MERGE_FOLDER_PROPERTIES_PROPERTY] = g_param_spec_object ("properties", "properties", "properties", GEARY_TYPE_FOLDER_PROPERTIES, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** {@inheritDoc} */
	g_object_class_install_property (G_OBJECT_CLASS (klass), MAIL_MERGE_FOLDER_PATH_PROPERTY, mail_merge_folder_properties[MAIL_MERGE_FOLDER_PATH_PROPERTY] = g_param_spec_object ("path", "path", "path", GEARY_TYPE_FOLDER_PATH, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** {@inheritDoc} */
	g_object_class_install_property (G_OBJECT_CLASS (klass), MAIL_MERGE_FOLDER_USED_AS_PROPERTY, mail_merge_folder_properties[MAIL_MERGE_FOLDER_USED_AS_PROPERTY] = g_param_spec_enum ("used-as", "used-as", "used-as", GEARY_FOLDER_TYPE_SPECIAL_USE, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** The source data file used the folder. */
	g_object_class_install_property (G_OBJECT_CLASS (klass), MAIL_MERGE_FOLDER_DATA_LOCATION_PROPERTY, mail_merge_folder_properties[MAIL_MERGE_FOLDER_DATA_LOCATION_PROPERTY] = g_param_spec_object ("data-location", "data-location", "data-location", g_file_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** The display name for {@link data_location}. */
	g_object_class_install_property (G_OBJECT_CLASS (klass), MAIL_MERGE_FOLDER_DATA_DISPLAY_NAME_PROPERTY, mail_merge_folder_properties[MAIL_MERGE_FOLDER_DATA_DISPLAY_NAME_PROPERTY] = g_param_spec_string ("data-display-name", "data-display-name", "data-display-name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** The number of email that have been sent. */
	g_object_class_install_property (G_OBJECT_CLASS (klass), MAIL_MERGE_FOLDER_EMAIL_SENT_PROPERTY, mail_merge_folder_properties[MAIL_MERGE_FOLDER_EMAIL_SENT_PROPERTY] = g_param_spec_uint ("email-sent", "email-sent", "email-sent", 0, G_MAXUINT, (guint) 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** The number of email in total. */
	g_object_class_install_property (G_OBJECT_CLASS (klass), MAIL_MERGE_FOLDER_EMAIL_TOTAL_PROPERTY, mail_merge_folder_properties[MAIL_MERGE_FOLDER_EMAIL_TOTAL_PROPERTY] = g_param_spec_uint ("email-total", "email-total", "email-total", 0, G_MAXUINT, (guint) 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** Specifies if the merged mail is currently being sent. */
	g_object_class_install_property (G_OBJECT_CLASS (klass), MAIL_MERGE_FOLDER_IS_SENDING_PROPERTY, mail_merge_folder_properties[MAIL_MERGE_FOLDER_IS_SENDING_PROPERTY] = g_param_spec_boolean ("is-sending", "is-sending", "is-sending", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** Emitted when an error sending an email is reported. */
	mail_merge_folder_signals[MAIL_MERGE_FOLDER_SEND_ERROR_SIGNAL] = g_signal_new ("send-error", MAIL_MERGE_TYPE_FOLDER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
}

static void
mail_merge_folder_instance_init (MailMergeFolder * self,
                                 gpointer klass)
{
	MailMergeFolderFolderProperties* _tmp0_;
	GeeArrayList* _tmp1_;
	GeeHashMap* _tmp2_;
	GeeHashMap* _tmp3_;
	GCancellable* _tmp4_;
	GCancellable* _tmp5_;
	self->priv = mail_merge_folder_get_instance_private (self);
	_tmp0_ = mail_merge_folder_folder_properties_new ();
	self->priv->_properties = _tmp0_;
	self->priv->_used_as = GEARY_FOLDER_SPECIAL_USE_NONE;
	self->priv->_email_sent = (guint) 0;
	self->priv->_email_total = (guint) 0;
	self->priv->_is_sending = FALSE;
	_tmp1_ = gee_array_list_new (GEARY_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->priv->ids = G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEE_TYPE_LIST, GeeList);
	_tmp2_ = gee_hash_map_new (GEARY_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEARY_TYPE_COMPOSED_EMAIL, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->composed = G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, GEE_TYPE_MAP, GeeMap);
	_tmp3_ = gee_hash_map_new (GEARY_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEARY_TYPE_EMAIL, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->email = G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, GEE_TYPE_MAP, GeeMap);
	_tmp4_ = g_cancellable_new ();
	self->priv->loading = _tmp4_;
	_tmp5_ = g_cancellable_new ();
	self->priv->sending = _tmp5_;
}

static void
mail_merge_folder_finalize (GObject * obj)
{
	MailMergeFolder * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, MAIL_MERGE_TYPE_FOLDER, MailMergeFolder);
	_g_object_unref0 (self->priv->_account);
	_g_object_unref0 (self->priv->_properties);
	_g_object_unref0 (self->priv->_path);
	_g_object_unref0 (self->priv->_data_location);
	_g_free0 (self->priv->_data_display_name);
	_g_object_unref0 (self->priv->ids);
	_g_object_unref0 (self->priv->composed);
	_g_object_unref0 (self->priv->email);
	_g_object_unref0 (self->priv->template);
	_g_object_unref0 (self->priv->data);
	_g_object_unref0 (self->priv->loading);
	_g_object_unref0 (self->priv->sending);
	G_OBJECT_CLASS (mail_merge_folder_parent_class)->finalize (obj);
}

/**
 * Plugin to Fill in and send email templates using a spreadsheet.
 */
static GType
mail_merge_folder_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (MailMergeFolderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) mail_merge_folder_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MailMergeFolder), 0, (GInstanceInitFunc) mail_merge_folder_instance_init, NULL };
	GType mail_merge_folder_type_id;
	mail_merge_folder_type_id = g_type_register_static (GEARY_TYPE_ABSTRACT_LOCAL_FOLDER, "MailMergeFolder", &g_define_type_info, 0);
	MailMergeFolder_private_offset = g_type_add_instance_private (mail_merge_folder_type_id, sizeof (MailMergeFolderPrivate));
	return mail_merge_folder_type_id;
}

GType
mail_merge_folder_get_type (void)
{
	static volatile gsize mail_merge_folder_type_id__once = 0;
	if (g_once_init_enter (&mail_merge_folder_type_id__once)) {
		GType mail_merge_folder_type_id;
		mail_merge_folder_type_id = mail_merge_folder_get_type_once ();
		g_once_init_leave (&mail_merge_folder_type_id__once, mail_merge_folder_type_id);
	}
	return mail_merge_folder_type_id__once;
}

static void
_vala_mail_merge_folder_get_property (GObject * object,
                                      guint property_id,
                                      GValue * value,
                                      GParamSpec * pspec)
{
	MailMergeFolder * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, MAIL_MERGE_TYPE_FOLDER, MailMergeFolder);
	switch (property_id) {
		case MAIL_MERGE_FOLDER_ACCOUNT_PROPERTY:
		g_value_set_object (value, geary_folder_get_account (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_TYPE_FOLDER, GearyFolder)));
		break;
		case MAIL_MERGE_FOLDER_PROPERTIES_PROPERTY:
		g_value_set_object (value, geary_folder_get_properties (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_TYPE_FOLDER, GearyFolder)));
		break;
		case MAIL_MERGE_FOLDER_PATH_PROPERTY:
		g_value_set_object (value, geary_folder_get_path (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_TYPE_FOLDER, GearyFolder)));
		break;
		case MAIL_MERGE_FOLDER_USED_AS_PROPERTY:
		g_value_set_enum (value, geary_folder_get_used_as (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_TYPE_FOLDER, GearyFolder)));
		break;
		case MAIL_MERGE_FOLDER_DATA_LOCATION_PROPERTY:
		g_value_set_object (value, mail_merge_folder_get_data_location (self));
		break;
		case MAIL_MERGE_FOLDER_DATA_DISPLAY_NAME_PROPERTY:
		g_value_set_string (value, mail_merge_folder_get_data_display_name (self));
		break;
		case MAIL_MERGE_FOLDER_EMAIL_SENT_PROPERTY:
		g_value_set_uint (value, mail_merge_folder_get_email_sent (self));
		break;
		case MAIL_MERGE_FOLDER_EMAIL_TOTAL_PROPERTY:
		g_value_set_uint (value, mail_merge_folder_get_email_total (self));
		break;
		case MAIL_MERGE_FOLDER_IS_SENDING_PROPERTY:
		g_value_set_boolean (value, mail_merge_folder_get_is_sending (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_mail_merge_folder_set_property (GObject * object,
                                      guint property_id,
                                      const GValue * value,
                                      GParamSpec * pspec)
{
	MailMergeFolder * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, MAIL_MERGE_TYPE_FOLDER, MailMergeFolder);
	switch (property_id) {
		case MAIL_MERGE_FOLDER_DATA_LOCATION_PROPERTY:
		mail_merge_folder_set_data_location (self, g_value_get_object (value));
		break;
		case MAIL_MERGE_FOLDER_DATA_DISPLAY_NAME_PROPERTY:
		mail_merge_folder_set_data_display_name (self, g_value_get_string (value));
		break;
		case MAIL_MERGE_FOLDER_EMAIL_SENT_PROPERTY:
		mail_merge_folder_set_email_sent (self, g_value_get_uint (value));
		break;
		case MAIL_MERGE_FOLDER_EMAIL_TOTAL_PROPERTY:
		mail_merge_folder_set_email_total (self, g_value_get_uint (value));
		break;
		case MAIL_MERGE_FOLDER_IS_SENDING_PROPERTY:
		mail_merge_folder_set_is_sending (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

