/* email-templates.c generated by valac 0.56.19, the Vala compiler
 * generated from email-templates.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 "email-templates.h"
#include <glib-object.h>
#include <glib.h>
#include <libpeas.h>
#include "geary-client-46.0.h"
#include <gio/gio.h>
#include <gee.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include "geary-engine.h"

#define PLUGIN_EMAIL_TEMPLATES_LOC_NAMES _ ("Templates | Template Mail | Template Email | Template E-Mail")
#define PLUGIN_EMAIL_TEMPLATES_UNLOC_NAMES "Templates | Template Mail | Template Email | Template E-Mail"
#define PLUGIN_EMAIL_TEMPLATES_ACTION_NEW "new-template"
#define PLUGIN_EMAIL_TEMPLATES_ACTION_EDIT "edit-template"
#define PLUGIN_EMAIL_TEMPLATES_ACTION_SEND "send-template"
#define PLUGIN_EMAIL_TEMPLATES_INFO_BAR_PRIORITY 0
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	PLUGIN_EMAIL_TEMPLATES_0_PROPERTY,
	PLUGIN_EMAIL_TEMPLATES_FOLDERS_PROPERTY,
	PLUGIN_EMAIL_TEMPLATES_EMAIL_PROPERTY,
	PLUGIN_EMAIL_TEMPLATES_NUM_PROPERTIES
};
static GParamSpec* plugin_email_templates_properties[PLUGIN_EMAIL_TEMPLATES_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _PluginEmailTemplatesActivateData PluginEmailTemplatesActivateData;
typedef struct _PluginEmailTemplatesDeactivateData PluginEmailTemplatesDeactivateData;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _PluginEmailTemplatesEditEmailData PluginEmailTemplatesEditEmailData;
typedef struct _PluginEmailTemplatesCreateFolderData PluginEmailTemplatesCreateFolderData;
typedef struct _PluginEmailTemplatesUpdateEmailData PluginEmailTemplatesUpdateEmailData;
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))

struct _PluginEmailTemplatesPrivate {
	PluginFolderContext* _folders;
	PluginEmailContext* _email;
	PluginFolderStore* folder_store;
	PluginEmailStore* email_store;
	GSimpleAction* new_action;
	GSimpleAction* edit_action;
	GSimpleAction* send_action;
	GeeMap* info_bars;
	GeeList* folder_names;
	GCancellable* cancellable;
};

struct _PluginEmailTemplatesActivateData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	PluginEmailTemplates* self;
	gboolean is_startup;
	gchar** _tmp0_;
	gchar** _tmp1_;
	gchar** _tmp2_;
	gint _tmp2__length1;
	GearyIterable* _tmp3_;
	GearyIterable* _tmp4_;
	GearyIterable* _tmp5_;
	GearyIterable* _tmp6_;
	GeeList* _tmp7_;
	GeeCollection* _tmp8_;
	GeeCollection* _tmp9_;
	gchar** _tmp10_;
	gchar** _tmp11_;
	gchar** _tmp12_;
	gint _tmp12__length1;
	GearyIterable* _tmp13_;
	GearyIterable* _tmp14_;
	GearyIterable* _tmp15_;
	GearyIterable* _tmp16_;
	GeeList* _tmp17_;
	GeeCollection* _tmp18_;
	GeeCollection* _tmp19_;
	PluginFolderStore* _tmp20_;
	PluginFolderContext* _tmp21_;
	PluginFolderContext* _tmp22_;
	PluginFolderStore* _tmp23_;
	PluginFolderStore* _tmp24_;
	PluginFolderStore* _tmp25_;
	PluginFolderStore* _tmp26_;
	PluginFolderStore* _tmp27_;
	PluginFolderStore* _tmp28_;
	PluginEmailStore* _tmp29_;
	PluginEmailContext* _tmp30_;
	PluginEmailContext* _tmp31_;
	PluginEmailStore* _tmp32_;
	PluginEmailStore* _tmp33_;
	PluginEmailStore* _tmp34_;
	PluginFolderStore* _tmp35_;
	const GVariantType* _tmp36_;
	const GVariantType* _tmp37_;
	GSimpleAction* _tmp38_;
	GSimpleAction* _tmp39_;
	PluginApplication* _tmp40_;
	PluginApplication* _tmp41_;
	GSimpleAction* _tmp42_;
	PluginEmailStore* _tmp43_;
	const GVariantType* _tmp44_;
	const GVariantType* _tmp45_;
	GSimpleAction* _tmp46_;
	GSimpleAction* _tmp47_;
	PluginApplication* _tmp48_;
	PluginApplication* _tmp49_;
	GSimpleAction* _tmp50_;
	PluginEmailStore* _tmp51_;
	const GVariantType* _tmp52_;
	const GVariantType* _tmp53_;
	GSimpleAction* _tmp54_;
	GSimpleAction* _tmp55_;
	PluginApplication* _tmp56_;
	PluginApplication* _tmp57_;
	GSimpleAction* _tmp58_;
	PluginFolderStore* _tmp59_;
	GeeCollection* _tmp60_;
	GeeCollection* _tmp61_;
	GError* _inner_error0_;
};

struct _PluginEmailTemplatesDeactivateData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	PluginEmailTemplates* self;
	gboolean is_shutdown;
	GCancellable* _tmp0_;
	GeeMap* _tmp1_;
	GeeSet* _tmp2_;
	GeeSet* _tmp3_;
	GeeSet* _tmp4_;
	gint _tmp5_;
	gpointer* _tmp6_;
	PluginFolder** _tmp7_;
	gint _tmp7__length1;
	PluginFolder** folder_collection;
	gint folder_collection_length1;
	gint _folder_collection_size_;
	gint folder_it;
	PluginFolder* _tmp8_;
	PluginFolder* folder;
	PluginFolder* _tmp9_;
	GeeMap* _tmp10_;
	GeeList* _tmp11_;
	PluginApplication* _tmp12_;
	PluginApplication* _tmp13_;
	GSimpleAction* _tmp14_;
	PluginApplication* _tmp15_;
	PluginApplication* _tmp16_;
	GSimpleAction* _tmp17_;
	PluginApplication* _tmp18_;
	PluginApplication* _tmp19_;
	GSimpleAction* _tmp20_;
	PluginFolderStore* _tmp21_;
	guint _tmp22_;
	PluginFolderStore* _tmp23_;
	guint _tmp24_;
	PluginFolderStore* _tmp25_;
	guint _tmp26_;
	PluginFolderStore* _tmp27_;
	guint _tmp28_;
	PluginEmailStore* _tmp29_;
	guint _tmp30_;
};

struct _PluginEmailTemplatesEditEmailData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	PluginEmailTemplates* self;
	PluginFolder* target;
	PluginEmailIdentifier* id;
	gboolean send;
	PluginAccount* _tmp0_;
	PluginAccount* _tmp1_;
	PluginAccount* _tmp2_;
	PluginAccount* _tmp3_;
	PluginAccount* _tmp4_;
	PluginAccount* account;
	PluginAccount* _tmp5_;
	PluginComposer* composer;
	PluginComposer* _tmp6_;
	PluginApplication* _tmp7_;
	PluginApplication* _tmp8_;
	PluginAccount* _tmp9_;
	PluginAccount* _tmp10_;
	PluginComposer* _tmp11_;
	PluginComposer* _tmp12_;
	PluginComposer* _tmp13_;
	PluginApplication* _tmp14_;
	PluginApplication* _tmp15_;
	PluginAccount* _tmp16_;
	PluginComposer* _tmp17_;
	PluginComposer* _tmp18_;
	PluginFolder* folder;
	PluginFolder* _tmp19_;
	gboolean _tmp20_;
	PluginFolder* _tmp21_;
	GeeCollection* containing;
	PluginFolderStore* _tmp22_;
	GCancellable* _tmp23_;
	GeeCollection* _tmp24_;
	GeeCollection* _tmp25_;
	gpointer _tmp26_;
	PluginComposer* _tmp27_;
	PluginFolder* _tmp28_;
	PluginComposer* _tmp29_;
	PluginComposer* _tmp30_;
	GError* err;
	GError* _tmp31_;
	const gchar* _tmp32_;
	GError* _inner_error0_;
};

struct _PluginEmailTemplatesCreateFolderData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	PluginEmailTemplates* self;
	PluginAccount* account;
	PluginFolderStore* _tmp0_;
	GeeList* _tmp1_;
	gpointer _tmp2_;
	gchar* _tmp3_;
	GCancellable* _tmp4_;
	PluginFolder* _tmp5_;
	PluginFolder* _tmp6_;
	GError* err;
	GError* _tmp7_;
	const gchar* _tmp8_;
	GError* _inner_error0_;
};

struct _PluginEmailTemplatesUpdateEmailData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	PluginEmailTemplates* self;
	PluginEmail* target;
	GeeCollection* containing;
	GeeCollection* _tmp0_;
	GeeCollection* _tmp1_;
	PluginFolderStore* _tmp2_;
	PluginEmailIdentifier* _tmp3_;
	PluginEmailIdentifier* _tmp4_;
	GCancellable* _tmp5_;
	GeeCollection* _tmp6_;
	GeeCollection* _tmp7_;
	GError* err;
	GError* _tmp8_;
	const gchar* _tmp9_;
	GeeCollection* _tmp10_;
	PluginEmailContext* _tmp11_;
	PluginEmailContext* _tmp12_;
	PluginEmailIdentifier* _tmp13_;
	PluginEmailIdentifier* _tmp14_;
	PluginEmailIdentifier* _tmp15_;
	PluginEmailIdentifier* _tmp16_;
	PluginInfoBar* _tmp17_;
	PluginInfoBar* _tmp18_;
	GError* _inner_error0_;
};

static gint PluginEmailTemplates_private_offset;
static gpointer plugin_email_templates_parent_class = NULL;
static PluginFolderExtensionIface * plugin_email_templates_plugin_folder_extension_parent_iface = NULL;
static PluginEmailExtensionIface * plugin_email_templates_plugin_email_extension_parent_iface = NULL;
static GType plugin_email_templates_type_id = 0;

static void plugin_email_templates_real_activate_data_free (gpointer _data);
static void plugin_email_templates_real_activate (PluginPluginBase* base,
                                           gboolean is_startup,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_);
static gboolean plugin_email_templates_real_activate_co (PluginEmailTemplatesActivateData* _data_);
static gchar* __lambda4_ (PluginEmailTemplates* self,
                   gchar* name);
static gpointer ___lambda4__gee_map_func (gpointer g,
                                   gpointer self);
static gchar* __lambda5_ (PluginEmailTemplates* self,
                   gchar* name);
static gpointer ___lambda5__gee_map_func (gpointer g,
                                   gpointer self);
static void plugin_email_templates_activate_ready (GObject* source_object,
                                            GAsyncResult* _res_,
                                            gpointer _user_data_);
static void plugin_email_templates_on_folders_available (PluginEmailTemplates* self,
                                                  GeeCollection* available);
static void _plugin_email_templates_on_folders_available_plugin_folder_store_folders_available (PluginFolderStore* _sender,
                                                                                         GeeCollection* available,
                                                                                         gpointer self);
static void plugin_email_templates_on_folders_unavailable (PluginEmailTemplates* self,
                                                    GeeCollection* unavailable);
static void _plugin_email_templates_on_folders_unavailable_plugin_folder_store_folders_unavailable (PluginFolderStore* _sender,
                                                                                             GeeCollection* unavailable,
                                                                                             gpointer self);
static void plugin_email_templates_on_folders_type_changed (PluginEmailTemplates* self,
                                                     GeeCollection* changed);
static void _plugin_email_templates_on_folders_type_changed_plugin_folder_store_folders_type_changed (PluginFolderStore* _sender,
                                                                                               GeeCollection* changed,
                                                                                               gpointer self);
static void plugin_email_templates_on_folder_selected (PluginEmailTemplates* self,
                                                PluginFolder* selected);
static void _plugin_email_templates_on_folder_selected_plugin_folder_store_folder_selected (PluginFolderStore* _sender,
                                                                                     PluginFolder* selected,
                                                                                     gpointer self);
static void plugin_email_templates_on_email_displayed (PluginEmailTemplates* self,
                                                PluginEmail* email);
static void _plugin_email_templates_on_email_displayed_plugin_email_store_email_displayed (PluginEmailStore* _sender,
                                                                                    PluginEmail* sent,
                                                                                    gpointer self);
static void plugin_email_templates_on_new_activated (PluginEmailTemplates* self,
                                              GAction* action,
                                              GVariant* target);
static void _plugin_email_templates_on_new_activated_g_simple_action_activate (GSimpleAction* _sender,
                                                                        GVariant* parameter,
                                                                        gpointer self);
static void plugin_email_templates_on_edit_activated (PluginEmailTemplates* self,
                                               GAction* action,
                                               GVariant* target);
static void _plugin_email_templates_on_edit_activated_g_simple_action_activate (GSimpleAction* _sender,
                                                                         GVariant* parameter,
                                                                         gpointer self);
static void plugin_email_templates_on_send_activated (PluginEmailTemplates* self,
                                               GAction* action,
                                               GVariant* target);
static void _plugin_email_templates_on_send_activated_g_simple_action_activate (GSimpleAction* _sender,
                                                                         GVariant* parameter,
                                                                         gpointer self);
static void plugin_email_templates_add_folders (PluginEmailTemplates* self,
                                         GeeCollection* to_add);
static void plugin_email_templates_real_deactivate_data_free (gpointer _data);
static void plugin_email_templates_real_deactivate (PluginPluginBase* base,
                                             gboolean is_shutdown,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_);
static gboolean plugin_email_templates_real_deactivate_co (PluginEmailTemplatesDeactivateData* _data_);
static void plugin_email_templates_unregister_folder (PluginEmailTemplates* self,
                                               PluginFolder* target);
static void plugin_email_templates_edit_email_data_free (gpointer _data);
static void plugin_email_templates_edit_email (PluginEmailTemplates* self,
                                        PluginFolder* target,
                                        PluginEmailIdentifier* id,
                                        gboolean send,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_);
static void plugin_email_templates_edit_email_finish (PluginEmailTemplates* self,
                                               GAsyncResult* _res_);
static gboolean plugin_email_templates_edit_email_co (PluginEmailTemplatesEditEmailData* _data_);
static void plugin_email_templates_edit_email_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_);
static gboolean _____lambda7_ (PluginEmailTemplates* self,
                        PluginFolder* f);
static gboolean ______lambda7__gee_predicate (gconstpointer g,
                                       gpointer self);
static void plugin_email_templates_register_folder (PluginEmailTemplates* self,
                                             PluginFolder* target);
static void plugin_email_templates_create_folder (PluginEmailTemplates* self,
                                           PluginAccount* account,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_);
static void plugin_email_templates_create_folder_finish (PluginEmailTemplates* self,
                                                  GAsyncResult* _res_);
static PluginInfoBar* plugin_email_templates_new_templates_folder_info_bar (PluginEmailTemplates* self,
                                                                     PluginFolder* target);
static void plugin_email_templates_create_folder_data_free (gpointer _data);
static gboolean plugin_email_templates_create_folder_co (PluginEmailTemplatesCreateFolderData* _data_);
static void plugin_email_templates_create_folder_ready (GObject* source_object,
                                                 GAsyncResult* _res_,
                                                 gpointer _user_data_);
static void plugin_email_templates_update_folder (PluginEmailTemplates* self,
                                           PluginFolder* target);
static void plugin_email_templates_update_email_data_free (gpointer _data);
static void plugin_email_templates_update_email (PluginEmailTemplates* self,
                                          PluginEmail* target,
                                          GAsyncReadyCallback _callback_,
                                          gpointer _user_data_);
static void plugin_email_templates_update_email_finish (PluginEmailTemplates* self,
                                                 GAsyncResult* _res_);
static gboolean plugin_email_templates_update_email_co (PluginEmailTemplatesUpdateEmailData* _data_);
static void plugin_email_templates_update_email_ready (GObject* source_object,
                                                GAsyncResult* _res_,
                                                gpointer _user_data_);
static gboolean __lambda6_ (PluginEmailTemplates* self,
                     PluginFolder* f);
static gboolean ___lambda6__gee_predicate (gconstpointer g,
                                    gpointer self);
static PluginInfoBar* plugin_email_templates_new_template_email_info_bar (PluginEmailTemplates* self,
                                                                   PluginEmailIdentifier* target);
static void plugin_email_templates_finalize (GObject * obj);
static void _vala_plugin_email_templates_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec);
static void _vala_plugin_email_templates_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 gssize _vala_array_length (gpointer array);

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

void
peas_register_types (GTypeModule* module)
{
	PeasObjectModule* obj = NULL;
	PeasObjectModule* _tmp0_;
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (module, g_type_module_get_type ()));
	plugin_email_templates_register_type (module);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (module, peas_object_module_get_type ()) ? ((PeasObjectModule*) module) : NULL);
	obj = _tmp0_;
	peas_object_module_register_extension_type (obj, PLUGIN_TYPE_PLUGIN_BASE, PLUGIN_TYPE_EMAIL_TEMPLATES);
	_g_object_unref0 (obj);
}

static inline gpointer
plugin_email_templates_get_instance_private (PluginEmailTemplates* self)
{
	return G_STRUCT_MEMBER_P (self, PluginEmailTemplates_private_offset);
}

static PluginFolderContext*
plugin_email_templates_real_get_folders (PluginFolderExtension* base)
{
	PluginFolderContext* result;
	PluginEmailTemplates* self;
	PluginFolderContext* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, PLUGIN_TYPE_EMAIL_TEMPLATES, PluginEmailTemplates);
	_tmp0_ = self->priv->_folders;
	result = _tmp0_;
	return result;
}

static void
plugin_email_templates_real_set_folders (PluginFolderExtension* base,
                                         PluginFolderContext* value)
{
	PluginEmailTemplates* self;
	PluginFolderContext* old_value;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, PLUGIN_TYPE_EMAIL_TEMPLATES, PluginEmailTemplates);
	old_value = plugin_email_templates_real_get_folders (base);
	if (old_value != value) {
		PluginFolderContext* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_folders);
		self->priv->_folders = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, plugin_email_templates_properties[PLUGIN_EMAIL_TEMPLATES_FOLDERS_PROPERTY]);
	}
}

static PluginEmailContext*
plugin_email_templates_real_get_email (PluginEmailExtension* base)
{
	PluginEmailContext* result;
	PluginEmailTemplates* self;
	PluginEmailContext* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, PLUGIN_TYPE_EMAIL_TEMPLATES, PluginEmailTemplates);
	_tmp0_ = self->priv->_email;
	result = _tmp0_;
	return result;
}

static void
plugin_email_templates_real_set_email (PluginEmailExtension* base,
                                       PluginEmailContext* value)
{
	PluginEmailTemplates* self;
	PluginEmailContext* old_value;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, PLUGIN_TYPE_EMAIL_TEMPLATES, PluginEmailTemplates);
	old_value = plugin_email_templates_real_get_email (base);
	if (old_value != value) {
		PluginEmailContext* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_email);
		self->priv->_email = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, plugin_email_templates_properties[PLUGIN_EMAIL_TEMPLATES_EMAIL_PROPERTY]);
	}
}

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

static void
plugin_email_templates_real_activate (PluginPluginBase* base,
                                      gboolean is_startup,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_)
{
	PluginEmailTemplates * self;
	PluginEmailTemplatesActivateData* _data_;
	PluginEmailTemplates* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, PLUGIN_TYPE_EMAIL_TEMPLATES, PluginEmailTemplates);
	_data_ = g_slice_new0 (PluginEmailTemplatesActivateData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, plugin_email_templates_real_activate_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->is_startup = is_startup;
	plugin_email_templates_real_activate_co (_data_);
}

static void
plugin_email_templates_activate_finish (PluginPluginBase* base,
                                        GAsyncResult* _res_,
                                        GError** error)
{
	PluginEmailTemplatesActivateData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

static gchar*
__lambda4_ (PluginEmailTemplates* self,
            gchar* name)
{
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = string_strip (name);
	result = _tmp0_;
	_g_free0 (name);
	return result;
}

static gpointer
___lambda4__gee_map_func (gpointer g,
                          gpointer self)
{
	gpointer result;
	result = __lambda4_ ((PluginEmailTemplates*) self, (gchar*) g);
	return result;
}

static gchar*
__lambda5_ (PluginEmailTemplates* self,
            gchar* name)
{
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = string_strip (name);
	result = _tmp0_;
	_g_free0 (name);
	return result;
}

static gpointer
___lambda5__gee_map_func (gpointer g,
                          gpointer self)
{
	gpointer result;
	result = __lambda5_ ((PluginEmailTemplates*) self, (gchar*) g);
	return result;
}

static void
plugin_email_templates_activate_ready (GObject* source_object,
                                       GAsyncResult* _res_,
                                       gpointer _user_data_)
{
	PluginEmailTemplatesActivateData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	plugin_email_templates_real_activate_co (_data_);
}

static void
_plugin_email_templates_on_folders_available_plugin_folder_store_folders_available (PluginFolderStore* _sender,
                                                                                    GeeCollection* available,
                                                                                    gpointer self)
{
	plugin_email_templates_on_folders_available ((PluginEmailTemplates*) self, available);
}

static void
_plugin_email_templates_on_folders_unavailable_plugin_folder_store_folders_unavailable (PluginFolderStore* _sender,
                                                                                        GeeCollection* unavailable,
                                                                                        gpointer self)
{
	plugin_email_templates_on_folders_unavailable ((PluginEmailTemplates*) self, unavailable);
}

static void
_plugin_email_templates_on_folders_type_changed_plugin_folder_store_folders_type_changed (PluginFolderStore* _sender,
                                                                                          GeeCollection* changed,
                                                                                          gpointer self)
{
	plugin_email_templates_on_folders_type_changed ((PluginEmailTemplates*) self, changed);
}

static void
_plugin_email_templates_on_folder_selected_plugin_folder_store_folder_selected (PluginFolderStore* _sender,
                                                                                PluginFolder* selected,
                                                                                gpointer self)
{
	plugin_email_templates_on_folder_selected ((PluginEmailTemplates*) self, selected);
}

static void
_plugin_email_templates_on_email_displayed_plugin_email_store_email_displayed (PluginEmailStore* _sender,
                                                                               PluginEmail* sent,
                                                                               gpointer self)
{
	plugin_email_templates_on_email_displayed ((PluginEmailTemplates*) self, sent);
}

static void
_plugin_email_templates_on_new_activated_g_simple_action_activate (GSimpleAction* _sender,
                                                                   GVariant* parameter,
                                                                   gpointer self)
{
	plugin_email_templates_on_new_activated ((PluginEmailTemplates*) self, _sender, parameter);
}

static void
_plugin_email_templates_on_edit_activated_g_simple_action_activate (GSimpleAction* _sender,
                                                                    GVariant* parameter,
                                                                    gpointer self)
{
	plugin_email_templates_on_edit_activated ((PluginEmailTemplates*) self, _sender, parameter);
}

static void
_plugin_email_templates_on_send_activated_g_simple_action_activate (GSimpleAction* _sender,
                                                                    GVariant* parameter,
                                                                    gpointer self)
{
	plugin_email_templates_on_send_activated ((PluginEmailTemplates*) self, _sender, parameter);
}

static gboolean
plugin_email_templates_real_activate_co (PluginEmailTemplatesActivateData* _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_->_tmp1_ = _data_->_tmp0_ = g_strsplit (PLUGIN_EMAIL_TEMPLATES_LOC_NAMES, "|", 0);
	_data_->_tmp2_ = _data_->_tmp1_;
	_data_->_tmp2__length1 = _vala_array_length (_data_->_tmp0_);
	_data_->_tmp3_ = geary_iterate_array (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _data_->_tmp2_, (gint) _vala_array_length (_data_->_tmp0_), NULL, NULL, NULL);
	_data_->_tmp4_ = _data_->_tmp3_;
	_data_->_tmp5_ = geary_iterable_map (_data_->_tmp4_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, ___lambda4__gee_map_func, _data_->self);
	_data_->_tmp6_ = _data_->_tmp5_;
	_data_->_tmp7_ = _data_->self->priv->folder_names;
	_data_->_tmp8_ = geary_iterable_add_all_to (_data_->_tmp6_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp7_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp9_ = _data_->_tmp8_;
	_g_object_unref0 (_data_->_tmp9_);
	_g_object_unref0 (_data_->_tmp6_);
	_g_object_unref0 (_data_->_tmp4_);
	_data_->_tmp2_ = (_vala_array_free (_data_->_tmp2_, _data_->_tmp2__length1, (GDestroyNotify) g_free), NULL);
	_data_->_tmp11_ = _data_->_tmp10_ = g_strsplit (PLUGIN_EMAIL_TEMPLATES_UNLOC_NAMES, "|", 0);
	_data_->_tmp12_ = _data_->_tmp11_;
	_data_->_tmp12__length1 = _vala_array_length (_data_->_tmp10_);
	_data_->_tmp13_ = geary_iterate_array (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _data_->_tmp12_, (gint) _vala_array_length (_data_->_tmp10_), NULL, NULL, NULL);
	_data_->_tmp14_ = _data_->_tmp13_;
	_data_->_tmp15_ = geary_iterable_map (_data_->_tmp14_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, ___lambda5__gee_map_func, _data_->self);
	_data_->_tmp16_ = _data_->_tmp15_;
	_data_->_tmp17_ = _data_->self->priv->folder_names;
	_data_->_tmp18_ = geary_iterable_add_all_to (_data_->_tmp16_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp17_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp19_ = _data_->_tmp18_;
	_g_object_unref0 (_data_->_tmp19_);
	_g_object_unref0 (_data_->_tmp16_);
	_g_object_unref0 (_data_->_tmp14_);
	_data_->_tmp12_ = (_vala_array_free (_data_->_tmp12_, _data_->_tmp12__length1, (GDestroyNotify) g_free), NULL);
	_data_->_tmp21_ = plugin_folder_extension_get_folders (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, PLUGIN_TYPE_FOLDER_EXTENSION, PluginFolderExtension));
	_data_->_tmp22_ = _data_->_tmp21_;
	_data_->_state_ = 1;
	plugin_folder_context_get_folder_store (_data_->_tmp22_, plugin_email_templates_activate_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp23_ = plugin_folder_context_get_folder_store_finish (_data_->_tmp22_, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp20_ = _data_->_tmp23_;
	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_->_tmp24_ = _data_->_tmp20_;
	_data_->_tmp20_ = NULL;
	_g_object_unref0 (_data_->self->priv->folder_store);
	_data_->self->priv->folder_store = _data_->_tmp24_;
	_data_->_tmp25_ = _data_->self->priv->folder_store;
	g_signal_connect_object (_data_->_tmp25_, "folders-available", (GCallback) _plugin_email_templates_on_folders_available_plugin_folder_store_folders_available, _data_->self, 0);
	_data_->_tmp26_ = _data_->self->priv->folder_store;
	g_signal_connect_object (_data_->_tmp26_, "folders-unavailable", (GCallback) _plugin_email_templates_on_folders_unavailable_plugin_folder_store_folders_unavailable, _data_->self, 0);
	_data_->_tmp27_ = _data_->self->priv->folder_store;
	g_signal_connect_object (_data_->_tmp27_, "folders-type-changed", (GCallback) _plugin_email_templates_on_folders_type_changed_plugin_folder_store_folders_type_changed, _data_->self, 0);
	_data_->_tmp28_ = _data_->self->priv->folder_store;
	g_signal_connect_object (_data_->_tmp28_, "folder-selected", (GCallback) _plugin_email_templates_on_folder_selected_plugin_folder_store_folder_selected, _data_->self, 0);
	_data_->_tmp30_ = plugin_email_extension_get_email (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, PLUGIN_TYPE_EMAIL_EXTENSION, PluginEmailExtension));
	_data_->_tmp31_ = _data_->_tmp30_;
	_data_->_state_ = 2;
	plugin_email_context_get_email_store (_data_->_tmp31_, plugin_email_templates_activate_ready, _data_);
	return FALSE;
	_state_2:
	_data_->_tmp32_ = plugin_email_context_get_email_store_finish (_data_->_tmp31_, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp29_ = _data_->_tmp32_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->_tmp20_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp33_ = _data_->_tmp29_;
	_data_->_tmp29_ = NULL;
	_g_object_unref0 (_data_->self->priv->email_store);
	_data_->self->priv->email_store = _data_->_tmp33_;
	_data_->_tmp34_ = _data_->self->priv->email_store;
	g_signal_connect_object (_data_->_tmp34_, "email-displayed", (GCallback) _plugin_email_templates_on_email_displayed_plugin_email_store_email_displayed, _data_->self, 0);
	_data_->_tmp35_ = _data_->self->priv->folder_store;
	_data_->_tmp36_ = plugin_folder_store_get_folder_variant_type (_data_->_tmp35_);
	_data_->_tmp37_ = _data_->_tmp36_;
	_data_->_tmp38_ = g_simple_action_new (PLUGIN_EMAIL_TEMPLATES_ACTION_NEW, _data_->_tmp37_);
	_g_object_unref0 (_data_->self->priv->new_action);
	_data_->self->priv->new_action = _data_->_tmp38_;
	_data_->_tmp39_ = _data_->self->priv->new_action;
	g_signal_connect_object (_data_->_tmp39_, "activate", (GCallback) _plugin_email_templates_on_new_activated_g_simple_action_activate, _data_->self, 0);
	_data_->_tmp40_ = plugin_plugin_base_get_plugin_application (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, PLUGIN_TYPE_PLUGIN_BASE, PluginPluginBase));
	_data_->_tmp41_ = _data_->_tmp40_;
	_data_->_tmp42_ = _data_->self->priv->new_action;
	plugin_application_register_action (_data_->_tmp41_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp42_, g_action_get_type (), GAction));
	_data_->_tmp43_ = _data_->self->priv->email_store;
	_data_->_tmp44_ = plugin_email_store_get_email_identifier_variant_type (_data_->_tmp43_);
	_data_->_tmp45_ = _data_->_tmp44_;
	_data_->_tmp46_ = g_simple_action_new (PLUGIN_EMAIL_TEMPLATES_ACTION_EDIT, _data_->_tmp45_);
	_g_object_unref0 (_data_->self->priv->edit_action);
	_data_->self->priv->edit_action = _data_->_tmp46_;
	_data_->_tmp47_ = _data_->self->priv->edit_action;
	g_signal_connect_object (_data_->_tmp47_, "activate", (GCallback) _plugin_email_templates_on_edit_activated_g_simple_action_activate, _data_->self, 0);
	_data_->_tmp48_ = plugin_plugin_base_get_plugin_application (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, PLUGIN_TYPE_PLUGIN_BASE, PluginPluginBase));
	_data_->_tmp49_ = _data_->_tmp48_;
	_data_->_tmp50_ = _data_->self->priv->edit_action;
	plugin_application_register_action (_data_->_tmp49_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp50_, g_action_get_type (), GAction));
	_data_->_tmp51_ = _data_->self->priv->email_store;
	_data_->_tmp52_ = plugin_email_store_get_email_identifier_variant_type (_data_->_tmp51_);
	_data_->_tmp53_ = _data_->_tmp52_;
	_data_->_tmp54_ = g_simple_action_new (PLUGIN_EMAIL_TEMPLATES_ACTION_SEND, _data_->_tmp53_);
	_g_object_unref0 (_data_->self->priv->send_action);
	_data_->self->priv->send_action = _data_->_tmp54_;
	_data_->_tmp55_ = _data_->self->priv->send_action;
	g_signal_connect_object (_data_->_tmp55_, "activate", (GCallback) _plugin_email_templates_on_send_activated_g_simple_action_activate, _data_->self, 0);
	_data_->_tmp56_ = plugin_plugin_base_get_plugin_application (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, PLUGIN_TYPE_PLUGIN_BASE, PluginPluginBase));
	_data_->_tmp57_ = _data_->_tmp56_;
	_data_->_tmp58_ = _data_->self->priv->send_action;
	plugin_application_register_action (_data_->_tmp57_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp58_, g_action_get_type (), GAction));
	_data_->_tmp59_ = _data_->self->priv->folder_store;
	_data_->_tmp60_ = plugin_folder_store_get_folders (_data_->_tmp59_);
	_data_->_tmp61_ = _data_->_tmp60_;
	plugin_email_templates_add_folders (_data_->self, _data_->_tmp61_);
	_g_object_unref0 (_data_->_tmp61_);
	_g_object_unref0 (_data_->_tmp29_);
	_g_object_unref0 (_data_->_tmp20_);
	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
plugin_email_templates_real_deactivate_data_free (gpointer _data)
{
	PluginEmailTemplatesDeactivateData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (PluginEmailTemplatesDeactivateData, _data_);
}

static void
plugin_email_templates_real_deactivate (PluginPluginBase* base,
                                        gboolean is_shutdown,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_)
{
	PluginEmailTemplates * self;
	PluginEmailTemplatesDeactivateData* _data_;
	PluginEmailTemplates* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, PLUGIN_TYPE_EMAIL_TEMPLATES, PluginEmailTemplates);
	_data_ = g_slice_new0 (PluginEmailTemplatesDeactivateData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, plugin_email_templates_real_deactivate_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->is_shutdown = is_shutdown;
	plugin_email_templates_real_deactivate_co (_data_);
}

static void
plugin_email_templates_deactivate_finish (PluginPluginBase* base,
                                          GAsyncResult* _res_,
                                          GError** error)
{
	PluginEmailTemplatesDeactivateData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static gboolean
plugin_email_templates_real_deactivate_co (PluginEmailTemplatesDeactivateData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->cancellable;
	g_cancellable_cancel (_data_->_tmp0_);
	_data_->_tmp1_ = _data_->self->priv->info_bars;
	_data_->_tmp2_ = gee_map_get_keys (_data_->_tmp1_);
	_data_->_tmp3_ = _data_->_tmp2_;
	_data_->_tmp4_ = _data_->_tmp3_;
	_data_->_tmp5_ = 0;
	_data_->_tmp6_ = gee_collection_to_array (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp4_, GEE_TYPE_COLLECTION, GeeCollection), &_data_->_tmp5_);
	_data_->_tmp7_ = _data_->_tmp6_;
	_data_->_tmp7__length1 = _data_->_tmp5_;
	_g_object_unref0 (_data_->_tmp4_);
	{
		_data_->folder_collection_length1 = 0;
		_data_->_folder_collection_size_ = 0;
		_data_->folder_collection = _data_->_tmp7_;
		_data_->folder_collection_length1 = _data_->_tmp7__length1;
		for (_data_->folder_it = 0; _data_->folder_it < _data_->folder_collection_length1; _data_->folder_it = _data_->folder_it + 1) {
			_data_->_tmp8_ = _g_object_ref0 (_data_->folder_collection[_data_->folder_it]);
			_data_->folder = _data_->_tmp8_;
			{
				_data_->_tmp9_ = _data_->folder;
				plugin_email_templates_unregister_folder (_data_->self, _data_->_tmp9_);
				_g_object_unref0 (_data_->folder);
			}
		}
		_data_->folder_collection = (_vala_array_free (_data_->folder_collection, _data_->folder_collection_length1, (GDestroyNotify) g_object_unref), NULL);
	}
	_data_->_tmp10_ = _data_->self->priv->info_bars;
	gee_map_clear (_data_->_tmp10_);
	_data_->_tmp11_ = _data_->self->priv->folder_names;
	gee_collection_clear (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp11_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp12_ = plugin_plugin_base_get_plugin_application (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, PLUGIN_TYPE_PLUGIN_BASE, PluginPluginBase));
	_data_->_tmp13_ = _data_->_tmp12_;
	_data_->_tmp14_ = _data_->self->priv->new_action;
	plugin_application_deregister_action (_data_->_tmp13_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp14_, g_action_get_type (), GAction));
	_g_object_unref0 (_data_->self->priv->new_action);
	_data_->self->priv->new_action = NULL;
	_data_->_tmp15_ = plugin_plugin_base_get_plugin_application (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, PLUGIN_TYPE_PLUGIN_BASE, PluginPluginBase));
	_data_->_tmp16_ = _data_->_tmp15_;
	_data_->_tmp17_ = _data_->self->priv->edit_action;
	plugin_application_deregister_action (_data_->_tmp16_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp17_, g_action_get_type (), GAction));
	_g_object_unref0 (_data_->self->priv->edit_action);
	_data_->self->priv->edit_action = NULL;
	_data_->_tmp18_ = plugin_plugin_base_get_plugin_application (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, PLUGIN_TYPE_PLUGIN_BASE, PluginPluginBase));
	_data_->_tmp19_ = _data_->_tmp18_;
	_data_->_tmp20_ = _data_->self->priv->send_action;
	plugin_application_deregister_action (_data_->_tmp19_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp20_, g_action_get_type (), GAction));
	_g_object_unref0 (_data_->self->priv->send_action);
	_data_->self->priv->send_action = NULL;
	_data_->_tmp21_ = _data_->self->priv->folder_store;
	g_signal_parse_name ("folders-available", PLUGIN_TYPE_FOLDER_STORE, &_data_->_tmp22_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (_data_->_tmp21_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _data_->_tmp22_, 0, NULL, (GCallback) _plugin_email_templates_on_folders_available_plugin_folder_store_folders_available, _data_->self);
	_data_->_tmp23_ = _data_->self->priv->folder_store;
	g_signal_parse_name ("folders-unavailable", PLUGIN_TYPE_FOLDER_STORE, &_data_->_tmp24_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (_data_->_tmp23_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _data_->_tmp24_, 0, NULL, (GCallback) _plugin_email_templates_on_folders_unavailable_plugin_folder_store_folders_unavailable, _data_->self);
	_data_->_tmp25_ = _data_->self->priv->folder_store;
	g_signal_parse_name ("folders-type-changed", PLUGIN_TYPE_FOLDER_STORE, &_data_->_tmp26_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (_data_->_tmp25_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _data_->_tmp26_, 0, NULL, (GCallback) _plugin_email_templates_on_folders_type_changed_plugin_folder_store_folders_type_changed, _data_->self);
	_data_->_tmp27_ = _data_->self->priv->folder_store;
	g_signal_parse_name ("folder-selected", PLUGIN_TYPE_FOLDER_STORE, &_data_->_tmp28_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (_data_->_tmp27_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _data_->_tmp28_, 0, NULL, (GCallback) _plugin_email_templates_on_folder_selected_plugin_folder_store_folder_selected, _data_->self);
	_g_object_unref0 (_data_->self->priv->folder_store);
	_data_->self->priv->folder_store = NULL;
	_data_->_tmp29_ = _data_->self->priv->email_store;
	g_signal_parse_name ("email-displayed", PLUGIN_TYPE_EMAIL_STORE, &_data_->_tmp30_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (_data_->_tmp29_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _data_->_tmp30_, 0, NULL, (GCallback) _plugin_email_templates_on_email_displayed_plugin_email_store_email_displayed, _data_->self);
	_g_object_unref0 (_data_->self->priv->email_store);
	_data_->self->priv->email_store = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
plugin_email_templates_edit_email_data_free (gpointer _data)
{
	PluginEmailTemplatesEditEmailData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->target);
	_g_object_unref0 (_data_->id);
	_g_object_unref0 (_data_->self);
	g_slice_free (PluginEmailTemplatesEditEmailData, _data_);
}

static void
plugin_email_templates_edit_email (PluginEmailTemplates* self,
                                   PluginFolder* target,
                                   PluginEmailIdentifier* id,
                                   gboolean send,
                                   GAsyncReadyCallback _callback_,
                                   gpointer _user_data_)
{
	PluginEmailTemplatesEditEmailData* _data_;
	PluginEmailTemplates* _tmp0_;
	PluginFolder* _tmp1_;
	PluginEmailIdentifier* _tmp2_;
	g_return_if_fail (PLUGIN_IS_EMAIL_TEMPLATES (self));
	g_return_if_fail ((target == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (target, PLUGIN_TYPE_FOLDER));
	g_return_if_fail ((id == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (id, PLUGIN_TYPE_EMAIL_IDENTIFIER));
	_data_ = g_slice_new0 (PluginEmailTemplatesEditEmailData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, plugin_email_templates_edit_email_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (target);
	_g_object_unref0 (_data_->target);
	_data_->target = _tmp1_;
	_tmp2_ = _g_object_ref0 (id);
	_g_object_unref0 (_data_->id);
	_data_->id = _tmp2_;
	_data_->send = send;
	plugin_email_templates_edit_email_co (_data_);
}

static void
plugin_email_templates_edit_email_finish (PluginEmailTemplates* self,
                                          GAsyncResult* _res_)
{
	PluginEmailTemplatesEditEmailData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
plugin_email_templates_edit_email_ready (GObject* source_object,
                                         GAsyncResult* _res_,
                                         gpointer _user_data_)
{
	PluginEmailTemplatesEditEmailData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	plugin_email_templates_edit_email_co (_data_);
}

static gboolean
_____lambda7_ (PluginEmailTemplates* self,
               PluginFolder* f)
{
	GeeMap* _tmp0_;
	gboolean result;
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (f, PLUGIN_TYPE_FOLDER), FALSE);
	_tmp0_ = self->priv->info_bars;
	result = gee_map_has_key (_tmp0_, f);
	return result;
}

static gboolean
______lambda7__gee_predicate (gconstpointer g,
                              gpointer self)
{
	gboolean result;
	result = _____lambda7_ ((PluginEmailTemplates*) self, (PluginFolder*) g);
	return result;
}

static gboolean
plugin_email_templates_edit_email_co (PluginEmailTemplatesEditEmailData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (_data_->target != NULL) {
		_data_->_tmp1_ = plugin_folder_get_account (_data_->target);
		_data_->_tmp2_ = _data_->_tmp1_;
		_data_->_tmp0_ = _data_->_tmp2_;
	} else {
		_data_->_tmp3_ = plugin_email_identifier_get_account (_data_->id);
		_data_->_tmp4_ = _data_->_tmp3_;
		_data_->_tmp0_ = _data_->_tmp4_;
	}
	_data_->_tmp5_ = _g_object_ref0 (_data_->_tmp0_);
	_data_->account = _data_->_tmp5_;
	{
		_data_->composer = NULL;
		if (_data_->id != NULL) {
			_data_->_tmp7_ = plugin_plugin_base_get_plugin_application (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, PLUGIN_TYPE_PLUGIN_BASE, PluginPluginBase));
			_data_->_tmp8_ = _data_->_tmp7_;
			_data_->_tmp9_ = plugin_email_identifier_get_account (_data_->id);
			_data_->_tmp10_ = _data_->_tmp9_;
			_data_->_state_ = 1;
			plugin_application_compose_with_context (_data_->_tmp8_, _data_->_tmp10_, PLUGIN_COMPOSER_CONTEXT_TYPE_EDIT, _data_->id, NULL, plugin_email_templates_edit_email_ready, _data_);
			return FALSE;
			_state_1:
			_data_->_tmp11_ = plugin_application_compose_with_context_finish (_data_->_tmp8_, _data_->_res_, &_data_->_inner_error0_);
			_data_->_tmp6_ = _data_->_tmp11_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->composer);
				goto __catch0_g_error;
			}
			_data_->_tmp12_ = _data_->_tmp6_;
			_data_->_tmp6_ = NULL;
			_g_object_unref0 (_data_->composer);
			_data_->composer = _data_->_tmp12_;
			_g_object_unref0 (_data_->_tmp6_);
		} else {
			_data_->_tmp14_ = plugin_plugin_base_get_plugin_application (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, PLUGIN_TYPE_PLUGIN_BASE, PluginPluginBase));
			_data_->_tmp15_ = _data_->_tmp14_;
			_data_->_tmp16_ = _data_->account;
			_data_->_state_ = 2;
			plugin_application_compose_blank (_data_->_tmp15_, _data_->_tmp16_, plugin_email_templates_edit_email_ready, _data_);
			return FALSE;
			_state_2:
			_data_->_tmp17_ = plugin_application_compose_blank_finish (_data_->_tmp15_, _data_->_res_, &_data_->_inner_error0_);
			_data_->_tmp13_ = _data_->_tmp17_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->composer);
				goto __catch0_g_error;
			}
			_data_->_tmp18_ = _data_->_tmp13_;
			_data_->_tmp13_ = NULL;
			_g_object_unref0 (_data_->composer);
			_data_->composer = _data_->_tmp18_;
			_g_object_unref0 (_data_->_tmp13_);
		}
		if (!_data_->send) {
			_data_->_tmp19_ = _g_object_ref0 (_data_->target);
			_data_->folder = _data_->_tmp19_;
			_data_->_tmp21_ = _data_->folder;
			if (_data_->_tmp21_ == NULL) {
				_data_->_tmp20_ = _data_->id != NULL;
			} else {
				_data_->_tmp20_ = FALSE;
			}
			if (_data_->_tmp20_) {
				_data_->_tmp22_ = _data_->self->priv->folder_store;
				_data_->_tmp23_ = _data_->self->priv->cancellable;
				_data_->_state_ = 3;
				plugin_folder_store_list_containing_folders (_data_->_tmp22_, _data_->id, _data_->_tmp23_, plugin_email_templates_edit_email_ready, _data_);
				return FALSE;
				_state_3:
				_data_->_tmp24_ = plugin_folder_store_list_containing_folders_finish (_data_->_tmp22_, _data_->_res_, &_data_->_inner_error0_);
				_data_->containing = _data_->_tmp24_;
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					_g_object_unref0 (_data_->folder);
					_g_object_unref0 (_data_->composer);
					goto __catch0_g_error;
				}
				_data_->_tmp25_ = _data_->containing;
				_data_->_tmp26_ = gee_traversable_first_match (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp25_, GEE_TYPE_TRAVERSABLE, GeeTraversable), ______lambda7__gee_predicate, g_object_ref (_data_->self), g_object_unref);
				_g_object_unref0 (_data_->folder);
				_data_->folder = (PluginFolder*) _data_->_tmp26_;
				_g_object_unref0 (_data_->containing);
			}
			_data_->_tmp27_ = _data_->composer;
			_data_->_tmp28_ = _data_->folder;
			plugin_composer_save_to_folder (_data_->_tmp27_, _data_->_tmp28_);
			_data_->_tmp29_ = _data_->composer;
			plugin_composer_set_can_send (_data_->_tmp29_, FALSE);
			_g_object_unref0 (_data_->folder);
		}
		_data_->_tmp30_ = _data_->composer;
		plugin_composer_present (_data_->_tmp30_);
		_g_object_unref0 (_data_->composer);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->err = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp31_ = _data_->err;
		_data_->_tmp32_ = _data_->_tmp31_->message;
		g_warning ("email-templates.vala:167: Unable to construct composer: %s", _data_->_tmp32_);
		_g_error_free0 (_data_->err);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->account);
		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_->account);
	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
plugin_email_templates_add_folders (PluginEmailTemplates* self,
                                    GeeCollection* to_add)
{
	PluginFolder* inbox = NULL;
	gboolean found_templates = FALSE;
	gboolean _tmp14_ = FALSE;
	g_return_if_fail (PLUGIN_IS_EMAIL_TEMPLATES (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (to_add, GEE_TYPE_COLLECTION));
	inbox = NULL;
	found_templates = FALSE;
	{
		GeeIterator* _folder_it = NULL;
		GeeIterator* _tmp0_;
		_tmp0_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (to_add, GEE_TYPE_ITERABLE, GeeIterable));
		_folder_it = _tmp0_;
		while (TRUE) {
			GeeIterator* _tmp1_;
			PluginFolder* folder = NULL;
			GeeIterator* _tmp2_;
			gpointer _tmp3_;
			PluginFolder* _tmp4_;
			GearyFolderSpecialUse _tmp5_;
			GearyFolderSpecialUse _tmp6_;
			_tmp1_ = _folder_it;
			if (!gee_iterator_next (_tmp1_)) {
				break;
			}
			_tmp2_ = _folder_it;
			_tmp3_ = gee_iterator_get (_tmp2_);
			folder = (PluginFolder*) _tmp3_;
			_tmp4_ = folder;
			_tmp5_ = plugin_folder_get_used_as (_tmp4_);
			_tmp6_ = _tmp5_;
			if (_tmp6_ == GEARY_FOLDER_SPECIAL_USE_INBOX) {
				PluginFolder* _tmp7_;
				PluginFolder* _tmp8_;
				_tmp7_ = folder;
				_tmp8_ = _g_object_ref0 (_tmp7_);
				_g_object_unref0 (inbox);
				inbox = _tmp8_;
			} else {
				GeeList* _tmp9_;
				PluginFolder* _tmp10_;
				const gchar* _tmp11_;
				const gchar* _tmp12_;
				_tmp9_ = self->priv->folder_names;
				_tmp10_ = folder;
				_tmp11_ = plugin_folder_get_display_name (_tmp10_);
				_tmp12_ = _tmp11_;
				if (gee_collection_contains (G_TYPE_CHECK_INSTANCE_CAST (_tmp9_, GEE_TYPE_COLLECTION, GeeCollection), _tmp12_)) {
					PluginFolder* _tmp13_;
					_tmp13_ = folder;
					plugin_email_templates_register_folder (self, _tmp13_);
					found_templates = TRUE;
				}
			}
			_g_object_unref0 (folder);
		}
		_g_object_unref0 (_folder_it);
	}
	if (!found_templates) {
		PluginFolder* _tmp15_;
		_tmp15_ = inbox;
		_tmp14_ = _tmp15_ != NULL;
	} else {
		_tmp14_ = FALSE;
	}
	if (_tmp14_) {
		PluginFolder* _tmp16_;
		PluginAccount* _tmp17_;
		PluginAccount* _tmp18_;
		g_debug ("email-templates.vala:190: Creating templates folder");
		_tmp16_ = inbox;
		_tmp17_ = plugin_folder_get_account (_tmp16_);
		_tmp18_ = _tmp17_;
		plugin_email_templates_create_folder (self, _tmp18_, NULL, NULL);
	}
	_g_object_unref0 (inbox);
}

static void
plugin_email_templates_register_folder (PluginEmailTemplates* self,
                                        PluginFolder* target)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (PLUGIN_IS_EMAIL_TEMPLATES (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (target, PLUGIN_TYPE_FOLDER));
	{
		PluginFolderContext* _tmp0_;
		PluginFolderContext* _tmp1_;
		GeeMap* _tmp2_;
		PluginInfoBar* _tmp3_;
		PluginInfoBar* _tmp4_;
		_tmp0_ = plugin_folder_extension_get_folders (G_TYPE_CHECK_INSTANCE_CAST (self, PLUGIN_TYPE_FOLDER_EXTENSION, PluginFolderExtension));
		_tmp1_ = _tmp0_;
		plugin_folder_context_register_folder_used_as (_tmp1_, target, _ ("Templates"), "folder-templates-symbolic", &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp2_ = self->priv->info_bars;
		_tmp3_ = plugin_email_templates_new_templates_folder_info_bar (self, target);
		_tmp4_ = _tmp3_;
		gee_map_set (_tmp2_, target, _tmp4_);
		_g_object_unref0 (_tmp4_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* err = NULL;
		const gchar* _tmp5_;
		const gchar* _tmp6_;
		GError* _tmp7_;
		const gchar* _tmp8_;
		err = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp5_ = plugin_folder_get_persistent_id (target);
		_tmp6_ = _tmp5_;
		_tmp7_ = err;
		_tmp8_ = _tmp7_->message;
		g_warning ("email-templates.vala:209: Failed to register %s as templates folder: %" \
"s", _tmp6_, _tmp8_);
		_g_error_free0 (err);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		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;
	}
}

static void
plugin_email_templates_unregister_folder (PluginEmailTemplates* self,
                                          PluginFolder* target)
{
	PluginInfoBar* info_bar = NULL;
	GeeMap* _tmp0_;
	gpointer _tmp1_;
	PluginInfoBar* _tmp2_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (PLUGIN_IS_EMAIL_TEMPLATES (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (target, PLUGIN_TYPE_FOLDER));
	_tmp0_ = self->priv->info_bars;
	_tmp1_ = gee_map_get (_tmp0_, target);
	info_bar = (PluginInfoBar*) _tmp1_;
	_tmp2_ = info_bar;
	if (_tmp2_ != NULL) {
		PluginFolderContext* _tmp9_;
		PluginFolderContext* _tmp10_;
		PluginInfoBar* _tmp11_;
		GeeMap* _tmp12_;
		{
			PluginFolderContext* _tmp3_;
			PluginFolderContext* _tmp4_;
			_tmp3_ = plugin_folder_extension_get_folders (G_TYPE_CHECK_INSTANCE_CAST (self, PLUGIN_TYPE_FOLDER_EXTENSION, PluginFolderExtension));
			_tmp4_ = _tmp3_;
			plugin_folder_context_unregister_folder_used_as (_tmp4_, target, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* err = NULL;
			const gchar* _tmp5_;
			const gchar* _tmp6_;
			GError* _tmp7_;
			const gchar* _tmp8_;
			err = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp5_ = plugin_folder_get_persistent_id (target);
			_tmp6_ = _tmp5_;
			_tmp7_ = err;
			_tmp8_ = _tmp7_->message;
			g_warning ("email-templates.vala:223: Failed to unregister %s as templates folder:" \
" %s", _tmp6_, _tmp8_);
			_g_error_free0 (err);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (info_bar);
			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;
		}
		_tmp9_ = plugin_folder_extension_get_folders (G_TYPE_CHECK_INSTANCE_CAST (self, PLUGIN_TYPE_FOLDER_EXTENSION, PluginFolderExtension));
		_tmp10_ = _tmp9_;
		_tmp11_ = info_bar;
		plugin_folder_context_remove_folder_info_bar (_tmp10_, target, _tmp11_);
		_tmp12_ = self->priv->info_bars;
		gee_map_unset (_tmp12_, target, NULL);
	}
	_g_object_unref0 (info_bar);
}

static void
plugin_email_templates_create_folder_data_free (gpointer _data)
{
	PluginEmailTemplatesCreateFolderData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->account);
	_g_object_unref0 (_data_->self);
	g_slice_free (PluginEmailTemplatesCreateFolderData, _data_);
}

static void
plugin_email_templates_create_folder (PluginEmailTemplates* self,
                                      PluginAccount* account,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_)
{
	PluginEmailTemplatesCreateFolderData* _data_;
	PluginEmailTemplates* _tmp0_;
	PluginAccount* _tmp1_;
	g_return_if_fail (PLUGIN_IS_EMAIL_TEMPLATES (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (account, PLUGIN_TYPE_ACCOUNT));
	_data_ = g_slice_new0 (PluginEmailTemplatesCreateFolderData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, plugin_email_templates_create_folder_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (account);
	_g_object_unref0 (_data_->account);
	_data_->account = _tmp1_;
	plugin_email_templates_create_folder_co (_data_);
}

static void
plugin_email_templates_create_folder_finish (PluginEmailTemplates* self,
                                             GAsyncResult* _res_)
{
	PluginEmailTemplatesCreateFolderData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
plugin_email_templates_create_folder_ready (GObject* source_object,
                                            GAsyncResult* _res_,
                                            gpointer _user_data_)
{
	PluginEmailTemplatesCreateFolderData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	plugin_email_templates_create_folder_co (_data_);
}

static gboolean
plugin_email_templates_create_folder_co (PluginEmailTemplatesCreateFolderData* _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->folder_store;
		_data_->_tmp1_ = _data_->self->priv->folder_names;
		_data_->_tmp2_ = gee_list_get (_data_->_tmp1_, 0);
		_data_->_tmp3_ = (gchar*) _data_->_tmp2_;
		_data_->_tmp4_ = _data_->self->priv->cancellable;
		_data_->_state_ = 1;
		plugin_folder_store_create_personal_folder (_data_->_tmp0_, _data_->account, _data_->_tmp3_, _data_->_tmp4_, plugin_email_templates_create_folder_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp5_ = plugin_folder_store_create_personal_folder_finish (_data_->_tmp0_, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp6_ = _data_->_tmp5_;
		_g_object_unref0 (_data_->_tmp6_);
		_g_free0 (_data_->_tmp3_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->err = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp7_ = _data_->err;
		_data_->_tmp8_ = _data_->_tmp7_->message;
		g_warning ("email-templates.vala:244: Failed to create templates folder: %s", _data_->_tmp8_);
		_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
plugin_email_templates_update_folder (PluginEmailTemplates* self,
                                      PluginFolder* target)
{
	PluginInfoBar* info_bar = NULL;
	GeeMap* _tmp0_;
	gpointer _tmp1_;
	PluginInfoBar* _tmp2_;
	g_return_if_fail (PLUGIN_IS_EMAIL_TEMPLATES (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (target, PLUGIN_TYPE_FOLDER));
	_tmp0_ = self->priv->info_bars;
	_tmp1_ = gee_map_get (_tmp0_, target);
	info_bar = (PluginInfoBar*) _tmp1_;
	_tmp2_ = info_bar;
	if (_tmp2_ != NULL) {
		PluginFolderContext* _tmp3_;
		PluginFolderContext* _tmp4_;
		PluginInfoBar* _tmp5_;
		_tmp3_ = plugin_folder_extension_get_folders (G_TYPE_CHECK_INSTANCE_CAST (self, PLUGIN_TYPE_FOLDER_EXTENSION, PluginFolderExtension));
		_tmp4_ = _tmp3_;
		_tmp5_ = info_bar;
		plugin_folder_context_add_folder_info_bar (_tmp4_, target, _tmp5_, (guint) PLUGIN_EMAIL_TEMPLATES_INFO_BAR_PRIORITY);
	}
	_g_object_unref0 (info_bar);
}

static void
plugin_email_templates_update_email_data_free (gpointer _data)
{
	PluginEmailTemplatesUpdateEmailData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->target);
	_g_object_unref0 (_data_->self);
	g_slice_free (PluginEmailTemplatesUpdateEmailData, _data_);
}

static void
plugin_email_templates_update_email (PluginEmailTemplates* self,
                                     PluginEmail* target,
                                     GAsyncReadyCallback _callback_,
                                     gpointer _user_data_)
{
	PluginEmailTemplatesUpdateEmailData* _data_;
	PluginEmailTemplates* _tmp0_;
	PluginEmail* _tmp1_;
	g_return_if_fail (PLUGIN_IS_EMAIL_TEMPLATES (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (target, PLUGIN_TYPE_EMAIL));
	_data_ = g_slice_new0 (PluginEmailTemplatesUpdateEmailData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, plugin_email_templates_update_email_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (target);
	_g_object_unref0 (_data_->target);
	_data_->target = _tmp1_;
	plugin_email_templates_update_email_co (_data_);
}

static void
plugin_email_templates_update_email_finish (PluginEmailTemplates* self,
                                            GAsyncResult* _res_)
{
	PluginEmailTemplatesUpdateEmailData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
plugin_email_templates_update_email_ready (GObject* source_object,
                                           GAsyncResult* _res_,
                                           gpointer _user_data_)
{
	PluginEmailTemplatesUpdateEmailData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	plugin_email_templates_update_email_co (_data_);
}

static gboolean
__lambda6_ (PluginEmailTemplates* self,
            PluginFolder* f)
{
	GeeMap* _tmp0_;
	gboolean result;
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (f, PLUGIN_TYPE_FOLDER), FALSE);
	_tmp0_ = self->priv->info_bars;
	result = gee_map_has_key (_tmp0_, f);
	return result;
}

static gboolean
___lambda6__gee_predicate (gconstpointer g,
                           gpointer self)
{
	gboolean result;
	result = __lambda6_ ((PluginEmailTemplates*) self, (PluginFolder*) g);
	return result;
}

static gboolean
plugin_email_templates_update_email_co (PluginEmailTemplatesUpdateEmailData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = gee_collection_empty (PLUGIN_TYPE_FOLDER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref);
	_data_->containing = _data_->_tmp0_;
	{
		_data_->_tmp2_ = _data_->self->priv->folder_store;
		_data_->_tmp3_ = plugin_email_get_identifier (_data_->target);
		_data_->_tmp4_ = _data_->_tmp3_;
		_data_->_tmp5_ = _data_->self->priv->cancellable;
		_data_->_state_ = 1;
		plugin_folder_store_list_containing_folders (_data_->_tmp2_, _data_->_tmp4_, _data_->_tmp5_, plugin_email_templates_update_email_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp6_ = plugin_folder_store_list_containing_folders_finish (_data_->_tmp2_, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp1_ = _data_->_tmp6_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp7_ = _data_->_tmp1_;
		_data_->_tmp1_ = NULL;
		_g_object_unref0 (_data_->containing);
		_data_->containing = _data_->_tmp7_;
		_g_object_unref0 (_data_->_tmp1_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->err = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp8_ = _data_->err;
		_data_->_tmp9_ = _data_->_tmp8_->message;
		g_warning ("email-templates.vala:264: Could not load folders for email: %s", _data_->_tmp9_);
		_g_error_free0 (_data_->err);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->containing);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp10_ = _data_->containing;
	if (gee_traversable_any_match (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp10_, GEE_TYPE_TRAVERSABLE, GeeTraversable), ___lambda6__gee_predicate, g_object_ref (_data_->self), g_object_unref)) {
		_data_->_tmp11_ = plugin_email_extension_get_email (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, PLUGIN_TYPE_EMAIL_EXTENSION, PluginEmailExtension));
		_data_->_tmp12_ = _data_->_tmp11_;
		_data_->_tmp13_ = plugin_email_get_identifier (_data_->target);
		_data_->_tmp14_ = _data_->_tmp13_;
		_data_->_tmp15_ = plugin_email_get_identifier (_data_->target);
		_data_->_tmp16_ = _data_->_tmp15_;
		_data_->_tmp17_ = plugin_email_templates_new_template_email_info_bar (_data_->self, _data_->_tmp16_);
		_data_->_tmp18_ = _data_->_tmp17_;
		plugin_email_context_add_email_info_bar (_data_->_tmp12_, _data_->_tmp14_, _data_->_tmp18_, (guint) PLUGIN_EMAIL_TEMPLATES_INFO_BAR_PRIORITY);
		_g_object_unref0 (_data_->_tmp18_);
	}
	_g_object_unref0 (_data_->containing);
	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 PluginInfoBar*
plugin_email_templates_new_templates_folder_info_bar (PluginEmailTemplates* self,
                                                      PluginFolder* target)
{
	PluginInfoBar* bar = NULL;
	GeeMap* _tmp0_;
	gpointer _tmp1_;
	PluginInfoBar* _tmp2_;
	PluginInfoBar* result;
	g_return_val_if_fail (PLUGIN_IS_EMAIL_TEMPLATES (self), NULL);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (target, PLUGIN_TYPE_FOLDER), NULL);
	_tmp0_ = self->priv->info_bars;
	_tmp1_ = gee_map_get (_tmp0_, target);
	bar = (PluginInfoBar*) _tmp1_;
	_tmp2_ = bar;
	if (_tmp2_ == NULL) {
		const gchar* _tmp3_;
		const gchar* _tmp4_;
		PluginInfoBar* _tmp5_;
		PluginInfoBar* _tmp6_;
		GSimpleAction* _tmp7_;
		GVariant* _tmp8_;
		GVariant* _tmp9_;
		PluginActionable* _tmp10_;
		PluginActionable* _tmp11_;
		GeeMap* _tmp12_;
		PluginInfoBar* _tmp13_;
		_tmp3_ = plugin_folder_get_display_name (target);
		_tmp4_ = _tmp3_;
		_tmp5_ = plugin_info_bar_new (_tmp4_, NULL);
		_g_object_unref0 (bar);
		bar = _tmp5_;
		_tmp6_ = bar;
		_tmp7_ = self->priv->new_action;
		_tmp8_ = plugin_folder_to_variant (target);
		_tmp9_ = _tmp8_;
		_tmp10_ = plugin_actionable_new (_ ("New"), G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, g_action_get_type (), GAction), _tmp9_);
		_tmp11_ = _tmp10_;
		plugin_info_bar_set_primary_button (_tmp6_, _tmp11_);
		_g_object_unref0 (_tmp11_);
		_g_variant_unref0 (_tmp9_);
		_tmp12_ = self->priv->info_bars;
		_tmp13_ = bar;
		gee_map_set (_tmp12_, target, _tmp13_);
	}
	result = bar;
	return result;
}

static PluginInfoBar*
plugin_email_templates_new_template_email_info_bar (PluginEmailTemplates* self,
                                                    PluginEmailIdentifier* target)
{
	PluginInfoBar* bar = NULL;
	PluginInfoBar* _tmp0_;
	GSimpleAction* _tmp1_;
	GVariant* _tmp2_;
	GVariant* _tmp3_;
	PluginActionable* _tmp4_;
	PluginActionable* _tmp5_;
	GeeBidirList* _tmp6_;
	GeeBidirList* _tmp7_;
	GSimpleAction* _tmp8_;
	GVariant* _tmp9_;
	GVariant* _tmp10_;
	PluginActionable* _tmp11_;
	PluginActionable* _tmp12_;
	PluginInfoBar* result;
	g_return_val_if_fail (PLUGIN_IS_EMAIL_TEMPLATES (self), NULL);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (target, PLUGIN_TYPE_EMAIL_IDENTIFIER), NULL);
	_tmp0_ = plugin_info_bar_new (_ ("Message template"), NULL);
	bar = _tmp0_;
	_tmp1_ = self->priv->send_action;
	_tmp2_ = plugin_email_identifier_to_variant (target);
	_tmp3_ = _tmp2_;
	_tmp4_ = plugin_actionable_new (_ ("Send"), G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, g_action_get_type (), GAction), _tmp3_);
	_tmp5_ = _tmp4_;
	plugin_info_bar_set_primary_button (bar, _tmp5_);
	_g_object_unref0 (_tmp5_);
	_g_variant_unref0 (_tmp3_);
	_tmp6_ = plugin_info_bar_get_secondary_buttons (bar);
	_tmp7_ = _tmp6_;
	_tmp8_ = self->priv->edit_action;
	_tmp9_ = plugin_email_identifier_to_variant (target);
	_tmp10_ = _tmp9_;
	_tmp11_ = plugin_actionable_new (_ ("Edit"), G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, g_action_get_type (), GAction), _tmp10_);
	_tmp12_ = _tmp11_;
	gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, GEE_TYPE_COLLECTION, GeeCollection), _tmp12_);
	_g_object_unref0 (_tmp12_);
	_g_variant_unref0 (_tmp10_);
	result = bar;
	return result;
}

static void
plugin_email_templates_on_folders_available (PluginEmailTemplates* self,
                                             GeeCollection* available)
{
	g_return_if_fail (PLUGIN_IS_EMAIL_TEMPLATES (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (available, GEE_TYPE_COLLECTION));
	plugin_email_templates_add_folders (self, available);
}

static void
plugin_email_templates_on_folders_unavailable (PluginEmailTemplates* self,
                                               GeeCollection* unavailable)
{
	g_return_if_fail (PLUGIN_IS_EMAIL_TEMPLATES (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (unavailable, GEE_TYPE_COLLECTION));
	{
		GeeIterator* _folder_it = NULL;
		GeeIterator* _tmp0_;
		_tmp0_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (unavailable, GEE_TYPE_ITERABLE, GeeIterable));
		_folder_it = _tmp0_;
		while (TRUE) {
			GeeIterator* _tmp1_;
			PluginFolder* folder = NULL;
			GeeIterator* _tmp2_;
			gpointer _tmp3_;
			PluginFolder* _tmp4_;
			_tmp1_ = _folder_it;
			if (!gee_iterator_next (_tmp1_)) {
				break;
			}
			_tmp2_ = _folder_it;
			_tmp3_ = gee_iterator_get (_tmp2_);
			folder = (PluginFolder*) _tmp3_;
			_tmp4_ = folder;
			plugin_email_templates_unregister_folder (self, _tmp4_);
			_g_object_unref0 (folder);
		}
		_g_object_unref0 (_folder_it);
	}
}

static void
plugin_email_templates_on_folders_type_changed (PluginEmailTemplates* self,
                                                GeeCollection* changed)
{
	g_return_if_fail (PLUGIN_IS_EMAIL_TEMPLATES (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (changed, GEE_TYPE_COLLECTION));
	{
		GeeIterator* _folder_it = NULL;
		GeeIterator* _tmp0_;
		_tmp0_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (changed, GEE_TYPE_ITERABLE, GeeIterable));
		_folder_it = _tmp0_;
		while (TRUE) {
			GeeIterator* _tmp1_;
			PluginFolder* folder = NULL;
			GeeIterator* _tmp2_;
			gpointer _tmp3_;
			PluginFolder* _tmp4_;
			GeeList* _tmp5_;
			PluginFolder* _tmp6_;
			const gchar* _tmp7_;
			const gchar* _tmp8_;
			PluginFolder* _tmp10_;
			_tmp1_ = _folder_it;
			if (!gee_iterator_next (_tmp1_)) {
				break;
			}
			_tmp2_ = _folder_it;
			_tmp3_ = gee_iterator_get (_tmp2_);
			folder = (PluginFolder*) _tmp3_;
			_tmp4_ = folder;
			plugin_email_templates_unregister_folder (self, _tmp4_);
			_tmp5_ = self->priv->folder_names;
			_tmp6_ = folder;
			_tmp7_ = plugin_folder_get_display_name (_tmp6_);
			_tmp8_ = _tmp7_;
			if (gee_collection_contains (G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, GEE_TYPE_COLLECTION, GeeCollection), _tmp8_)) {
				PluginFolder* _tmp9_;
				_tmp9_ = folder;
				plugin_email_templates_register_folder (self, _tmp9_);
			}
			_tmp10_ = folder;
			plugin_email_templates_update_folder (self, _tmp10_);
			_g_object_unref0 (folder);
		}
		_g_object_unref0 (_folder_it);
	}
}

static void
plugin_email_templates_on_folder_selected (PluginEmailTemplates* self,
                                           PluginFolder* selected)
{
	g_return_if_fail (PLUGIN_IS_EMAIL_TEMPLATES (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (selected, PLUGIN_TYPE_FOLDER));
	plugin_email_templates_update_folder (self, selected);
}

static void
plugin_email_templates_on_new_activated (PluginEmailTemplates* self,
                                         GAction* action,
                                         GVariant* target)
{
	gboolean _tmp0_ = FALSE;
	PluginFolderStore* _tmp1_;
	g_return_if_fail (PLUGIN_IS_EMAIL_TEMPLATES (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (action, g_action_get_type ()));
	_tmp1_ = self->priv->folder_store;
	if (_tmp1_ != NULL) {
		_tmp0_ = target != NULL;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		PluginFolder* folder = NULL;
		PluginFolderStore* _tmp2_;
		PluginFolder* _tmp3_;
		PluginFolder* _tmp4_;
		_tmp2_ = self->priv->folder_store;
		_tmp3_ = plugin_folder_store_get_folder_for_variant (_tmp2_, target);
		folder = _tmp3_;
		_tmp4_ = folder;
		if (_tmp4_ != NULL) {
			PluginFolder* _tmp5_;
			_tmp5_ = folder;
			plugin_email_templates_edit_email (self, _tmp5_, NULL, FALSE, NULL, NULL);
		}
		_g_object_unref0 (folder);
	}
}

static void
plugin_email_templates_on_edit_activated (PluginEmailTemplates* self,
                                          GAction* action,
                                          GVariant* target)
{
	gboolean _tmp0_ = FALSE;
	PluginEmailStore* _tmp1_;
	g_return_if_fail (PLUGIN_IS_EMAIL_TEMPLATES (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (action, g_action_get_type ()));
	_tmp1_ = self->priv->email_store;
	if (_tmp1_ != NULL) {
		_tmp0_ = target != NULL;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		PluginEmailIdentifier* id = NULL;
		PluginEmailStore* _tmp2_;
		PluginEmailIdentifier* _tmp3_;
		PluginEmailIdentifier* _tmp4_;
		_tmp2_ = self->priv->email_store;
		_tmp3_ = plugin_email_store_get_email_identifier_for_variant (_tmp2_, target);
		id = _tmp3_;
		_tmp4_ = id;
		if (_tmp4_ != NULL) {
			PluginEmailIdentifier* _tmp5_;
			_tmp5_ = id;
			plugin_email_templates_edit_email (self, NULL, _tmp5_, FALSE, NULL, NULL);
		}
		_g_object_unref0 (id);
	}
}

static void
plugin_email_templates_on_send_activated (PluginEmailTemplates* self,
                                          GAction* action,
                                          GVariant* target)
{
	gboolean _tmp0_ = FALSE;
	PluginEmailStore* _tmp1_;
	g_return_if_fail (PLUGIN_IS_EMAIL_TEMPLATES (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (action, g_action_get_type ()));
	_tmp1_ = self->priv->email_store;
	if (_tmp1_ != NULL) {
		_tmp0_ = target != NULL;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		PluginEmailIdentifier* id = NULL;
		PluginEmailStore* _tmp2_;
		PluginEmailIdentifier* _tmp3_;
		PluginEmailIdentifier* _tmp4_;
		_tmp2_ = self->priv->email_store;
		_tmp3_ = plugin_email_store_get_email_identifier_for_variant (_tmp2_, target);
		id = _tmp3_;
		_tmp4_ = id;
		if (_tmp4_ != NULL) {
			PluginEmailIdentifier* _tmp5_;
			_tmp5_ = id;
			plugin_email_templates_edit_email (self, NULL, _tmp5_, TRUE, NULL, NULL);
		}
		_g_object_unref0 (id);
	}
}

static void
plugin_email_templates_on_email_displayed (PluginEmailTemplates* self,
                                           PluginEmail* email)
{
	g_return_if_fail (PLUGIN_IS_EMAIL_TEMPLATES (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (email, PLUGIN_TYPE_EMAIL));
	plugin_email_templates_update_email (self, email, NULL, NULL);
}

PluginEmailTemplates*
plugin_email_templates_construct (GType object_type)
{
	PluginEmailTemplates * self = NULL;
	self = (PluginEmailTemplates*) plugin_plugin_base_construct (object_type);
	return self;
}

PluginEmailTemplates*
plugin_email_templates_new (void)
{
	return plugin_email_templates_construct (PLUGIN_TYPE_EMAIL_TEMPLATES);
}

static void
plugin_email_templates_class_init (PluginEmailTemplatesClass * klass,
                                   gpointer klass_data)
{
	plugin_email_templates_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &PluginEmailTemplates_private_offset);
	((PluginPluginBaseClass *) klass)->activate = (void (*) (PluginPluginBase*, gboolean, GAsyncReadyCallback, gpointer)) plugin_email_templates_real_activate;
	((PluginPluginBaseClass *) klass)->activate_finish = (void (*) (PluginPluginBase*, GAsyncResult*, GError**)) plugin_email_templates_activate_finish;
	((PluginPluginBaseClass *) klass)->deactivate = (void (*) (PluginPluginBase*, gboolean, GAsyncReadyCallback, gpointer)) plugin_email_templates_real_deactivate;
	((PluginPluginBaseClass *) klass)->deactivate_finish = (void (*) (PluginPluginBase*, GAsyncResult*, GError**)) plugin_email_templates_deactivate_finish;
	G_OBJECT_CLASS (klass)->get_property = _vala_plugin_email_templates_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_plugin_email_templates_set_property;
	G_OBJECT_CLASS (klass)->finalize = plugin_email_templates_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), PLUGIN_EMAIL_TEMPLATES_FOLDERS_PROPERTY, plugin_email_templates_properties[PLUGIN_EMAIL_TEMPLATES_FOLDERS_PROPERTY] = g_param_spec_object ("folders", "folders", "folders", PLUGIN_TYPE_FOLDER_CONTEXT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PLUGIN_EMAIL_TEMPLATES_EMAIL_PROPERTY, plugin_email_templates_properties[PLUGIN_EMAIL_TEMPLATES_EMAIL_PROPERTY] = g_param_spec_object ("email", "email", "email", PLUGIN_TYPE_EMAIL_CONTEXT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
}

static void
plugin_email_templates_plugin_folder_extension_interface_init (PluginFolderExtensionIface * iface,
                                                               gpointer iface_data)
{
	plugin_email_templates_plugin_folder_extension_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_folders = plugin_email_templates_real_get_folders;
	iface->set_folders = plugin_email_templates_real_set_folders;
}

static void
plugin_email_templates_plugin_email_extension_interface_init (PluginEmailExtensionIface * iface,
                                                              gpointer iface_data)
{
	plugin_email_templates_plugin_email_extension_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_email = plugin_email_templates_real_get_email;
	iface->set_email = plugin_email_templates_real_set_email;
}

static void
plugin_email_templates_instance_init (PluginEmailTemplates * self,
                                      gpointer klass)
{
	GeeHashMap* _tmp0_;
	GeeArrayList* _tmp1_;
	GCancellable* _tmp2_;
	self->priv = plugin_email_templates_get_instance_private (self);
	self->priv->folder_store = NULL;
	self->priv->email_store = NULL;
	self->priv->new_action = NULL;
	self->priv->edit_action = NULL;
	self->priv->send_action = NULL;
	_tmp0_ = gee_hash_map_new (PLUGIN_TYPE_FOLDER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, PLUGIN_TYPE_INFO_BAR, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->info_bars = G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEE_TYPE_MAP, GeeMap);
	_tmp1_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
	self->priv->folder_names = G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEE_TYPE_LIST, GeeList);
	_tmp2_ = g_cancellable_new ();
	self->priv->cancellable = _tmp2_;
}

static void
plugin_email_templates_finalize (GObject * obj)
{
	PluginEmailTemplates * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PLUGIN_TYPE_EMAIL_TEMPLATES, PluginEmailTemplates);
	_g_object_unref0 (self->priv->_folders);
	_g_object_unref0 (self->priv->_email);
	_g_object_unref0 (self->priv->folder_store);
	_g_object_unref0 (self->priv->email_store);
	_g_object_unref0 (self->priv->new_action);
	_g_object_unref0 (self->priv->edit_action);
	_g_object_unref0 (self->priv->send_action);
	_g_object_unref0 (self->priv->info_bars);
	_g_object_unref0 (self->priv->folder_names);
	_g_object_unref0 (self->priv->cancellable);
	G_OBJECT_CLASS (plugin_email_templates_parent_class)->finalize (obj);
}

/**
 * Enables editing and sending email templates.
 */
GType
plugin_email_templates_get_type (void)
{
	return plugin_email_templates_type_id;
}

GType
plugin_email_templates_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (PluginEmailTemplatesClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) plugin_email_templates_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PluginEmailTemplates), 0, (GInstanceInitFunc) plugin_email_templates_instance_init, NULL };
	static const GInterfaceInfo plugin_folder_extension_info = { (GInterfaceInitFunc) plugin_email_templates_plugin_folder_extension_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	static const GInterfaceInfo plugin_email_extension_info = { (GInterfaceInitFunc) plugin_email_templates_plugin_email_extension_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	plugin_email_templates_type_id = g_type_module_register_type (module, PLUGIN_TYPE_PLUGIN_BASE, "PluginEmailTemplates", &g_define_type_info, 0);
	g_type_module_add_interface (module, plugin_email_templates_type_id, PLUGIN_TYPE_FOLDER_EXTENSION, &plugin_folder_extension_info);
	g_type_module_add_interface (module, plugin_email_templates_type_id, PLUGIN_TYPE_EMAIL_EXTENSION, &plugin_email_extension_info);
	PluginEmailTemplates_private_offset = sizeof (PluginEmailTemplatesPrivate);
	return plugin_email_templates_type_id;
}

static void
_vala_plugin_email_templates_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec)
{
	PluginEmailTemplates * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PLUGIN_TYPE_EMAIL_TEMPLATES, PluginEmailTemplates);
	switch (property_id) {
		case PLUGIN_EMAIL_TEMPLATES_FOLDERS_PROPERTY:
		g_value_set_object (value, plugin_folder_extension_get_folders (G_TYPE_CHECK_INSTANCE_CAST (self, PLUGIN_TYPE_FOLDER_EXTENSION, PluginFolderExtension)));
		break;
		case PLUGIN_EMAIL_TEMPLATES_EMAIL_PROPERTY:
		g_value_set_object (value, plugin_email_extension_get_email (G_TYPE_CHECK_INSTANCE_CAST (self, PLUGIN_TYPE_EMAIL_EXTENSION, PluginEmailExtension)));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_plugin_email_templates_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec)
{
	PluginEmailTemplates * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PLUGIN_TYPE_EMAIL_TEMPLATES, PluginEmailTemplates);
	switch (property_id) {
		case PLUGIN_EMAIL_TEMPLATES_FOLDERS_PROPERTY:
		plugin_folder_extension_set_folders (G_TYPE_CHECK_INSTANCE_CAST (self, PLUGIN_TYPE_FOLDER_EXTENSION, PluginFolderExtension), g_value_get_object (value));
		break;
		case PLUGIN_EMAIL_TEMPLATES_EMAIL_PROPERTY:
		plugin_email_extension_set_email (G_TYPE_CHECK_INSTANCE_CAST (self, PLUGIN_TYPE_EMAIL_EXTENSION, PluginEmailExtension), g_value_get_object (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);
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

