/* imap-folder-session.c generated by valac 0.56.19, the Vala compiler
 * generated from imap-folder-session.vala, do not modify */

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

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

#define GEARY_IMAP_FOLDER_SESSION_BASIC_FETCH_FIELDS ((((((GEARY_EMAIL_FIELD_ENVELOPE | GEARY_EMAIL_FIELD_DATE) | GEARY_EMAIL_FIELD_ORIGINATORS) | GEARY_EMAIL_FIELD_RECEIVERS) | GEARY_EMAIL_FIELD_REFERENCES) | GEARY_EMAIL_FIELD_SUBJECT) | GEARY_EMAIL_FIELD_HEADER)
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

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

typedef struct _GearyImapFolderSession GearyImapFolderSession;
typedef struct _GearyImapFolderSessionClass GearyImapFolderSessionClass;
typedef struct _GearyImapFolderSessionPrivate GearyImapFolderSessionPrivate;

#define GEARY_IMAP_TYPE_FOLDER (geary_imap_folder_get_type ())
#define GEARY_IMAP_FOLDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_TYPE_FOLDER, GearyImapFolder))
#define GEARY_IMAP_FOLDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_TYPE_FOLDER, GearyImapFolderClass))
#define GEARY_IMAP_IS_FOLDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_TYPE_FOLDER))
#define GEARY_IMAP_IS_FOLDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_TYPE_FOLDER))
#define GEARY_IMAP_FOLDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_TYPE_FOLDER, GearyImapFolderClass))

typedef struct _GearyImapFolder GearyImapFolder;
typedef struct _GearyImapFolderClass GearyImapFolderClass;
enum  {
	GEARY_IMAP_FOLDER_SESSION_0_PROPERTY,
	GEARY_IMAP_FOLDER_SESSION_FOLDER_PROPERTY,
	GEARY_IMAP_FOLDER_SESSION_READONLY_PROPERTY,
	GEARY_IMAP_FOLDER_SESSION_PERMANENT_FLAGS_PROPERTY,
	GEARY_IMAP_FOLDER_SESSION_ACCEPTS_USER_FLAGS_PROPERTY,
	GEARY_IMAP_FOLDER_SESSION_NUM_PROPERTIES
};
static GParamSpec* geary_imap_folder_session_properties[GEARY_IMAP_FOLDER_SESSION_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 _GearyImapFolderSessionNewData GearyImapFolderSessionNewData;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _GearyImapFolderSessionEnableIdleData GearyImapFolderSessionEnableIdleData;
typedef struct _GearyImapFolderSessionSendNoopData GearyImapFolderSessionSendNoopData;
typedef struct _GearyImapFolderSessionExecCommandsAsyncData GearyImapFolderSessionExecCommandsAsyncData;
typedef struct _GearyImapFolderSessionListUidsAsyncData GearyImapFolderSessionListUidsAsyncData;
typedef struct _Block28Data Block28Data;
typedef struct _GearyImapFolderSessionListEmailAsyncData GearyImapFolderSessionListEmailAsyncData;
typedef struct _GearyImapFolderSessionUidToPositionAsyncData GearyImapFolderSessionUidToPositionAsyncData;
typedef struct _GearyImapFolderSessionRemoveEmailAsyncData GearyImapFolderSessionRemoveEmailAsyncData;
typedef struct _GearyImapFolderSessionMarkEmailAsyncData GearyImapFolderSessionMarkEmailAsyncData;
typedef struct _GearyImapFolderSessionCopyEmailAsyncData GearyImapFolderSessionCopyEmailAsyncData;
typedef struct _GearyImapFolderSessionSearchAsyncData GearyImapFolderSessionSearchAsyncData;

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

typedef struct _GearyImapDBEmailIdentifier GearyImapDBEmailIdentifier;
typedef struct _GearyImapDBEmailIdentifierClass GearyImapDBEmailIdentifierClass;
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
typedef struct _GearyImapFolderSessionCreateEmailAsyncData GearyImapFolderSessionCreateEmailAsyncData;
#define _geary_logging_state_unref0(var) ((var == NULL) ? NULL : (var = (geary_logging_state_unref (var), NULL)))
enum  {
	GEARY_IMAP_FOLDER_SESSION_EXISTS_SIGNAL,
	GEARY_IMAP_FOLDER_SESSION_RECENT_SIGNAL,
	GEARY_IMAP_FOLDER_SESSION_EXPUNGE_SIGNAL,
	GEARY_IMAP_FOLDER_SESSION_APPENDED_SIGNAL,
	GEARY_IMAP_FOLDER_SESSION_UPDATED_SIGNAL,
	GEARY_IMAP_FOLDER_SESSION_REMOVED_SIGNAL,
	GEARY_IMAP_FOLDER_SESSION_NUM_SIGNALS
};
static guint geary_imap_folder_session_signals[GEARY_IMAP_FOLDER_SESSION_NUM_SIGNALS] = {0};

struct _GearyImapFolderSession {
	GearyImapSessionObject parent_instance;
	GearyImapFolderSessionPrivate * priv;
};

struct _GearyImapFolderSessionClass {
	GearyImapSessionObjectClass parent_class;
};

struct _GearyImapFolderSessionPrivate {
	GearyImapFolder* _folder;
	GearyTrillian _readonly;
	GearyImapMessageFlags* _permanent_flags;
	GearyTrillian _accepts_user_flags;
	GearyImapMailboxSpecifier* mailbox;
	GearyImapQuirks* quirks;
	GearyNonblockingMutex* cmd_mutex;
	GeeHashMap* fetch_accumulator;
	GeeSet* search_accumulator;
};

struct _GearyImapFolderSessionNewData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GType object_type;
	GearyImapFolderSession* self;
	GearyImapClientSession* session;
	GearyImapFolder* folder;
	GCancellable* cancellable;
	GearyImapQuirks* _tmp0_;
	GearyImapQuirks* _tmp1_;
	GearyImapQuirks* _tmp2_;
	GearyImapFolderProperties* _tmp3_;
	GearyImapFolderProperties* _tmp4_;
	GearyImapMailboxAttributes* _tmp5_;
	GearyImapMailboxAttributes* _tmp6_;
	gboolean _tmp7_;
	gboolean _tmp8_;
	GearyFolderPath* _tmp9_;
	GearyFolderPath* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	GError* _tmp13_;
	GError* _tmp14_;
	GearyImapFolderProperties* _tmp15_;
	GearyImapFolderProperties* _tmp16_;
	GearyImapCapabilities* _tmp17_;
	GearyImapCapabilities* _tmp18_;
	GearyImapMailboxSpecifier* _tmp19_;
	GearyFolderPath* _tmp20_;
	GearyFolderPath* _tmp21_;
	GearyImapMailboxSpecifier* _tmp22_;
	GearyImapMailboxSpecifier* _tmp23_;
	GearyImapStatusResponse* response;
	GearyImapMailboxSpecifier* _tmp24_;
	GearyImapStatusResponse* _tmp25_;
	GearyImapStatusResponse* _tmp26_;
	GearyImapFolder* _tmp27_;
	GearyFolderPath* _tmp28_;
	GearyFolderPath* _tmp29_;
	gchar* _tmp30_;
	gchar* _tmp31_;
	gchar* _tmp32_;
	gchar* _tmp33_;
	GearyTrillian _tmp34_;
	GError* _inner_error0_;
};

struct _GearyImapFolderSessionEnableIdleData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapFolderSession* self;
	GCancellable* cancellable;
	GearyImapClientSession* session;
	GearyImapClientSession* _tmp0_;
	gint token;
	GearyNonblockingMutex* _tmp1_;
	GError* cmd_err;
	GearyImapClientSession* _tmp2_;
	GError* err;
	GError* _tmp3_;
	GError* _tmp4_;
	GearyNonblockingMutex* _tmp5_;
	GError* _tmp6_;
	GError* _tmp7_;
	GError* _tmp8_;
	GError* _inner_error0_;
};

struct _GearyImapFolderSessionSendNoopData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapFolderSession* self;
	GCancellable* cancellable;
	GearyImapNoopCommand* _tmp0_;
	GearyImapNoopCommand* _tmp1_;
	GeeCollection* _tmp2_;
	GeeCollection* _tmp3_;
	GeeMap* _tmp4_;
	GeeMap* _tmp5_;
	GError* _inner_error0_;
};

struct _GearyImapFolderSessionExecCommandsAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapFolderSession* self;
	GeeCollection* cmds;
	GeeHashMap* fetch_results;
	GeeSet* search_results;
	GCancellable* cancellable;
	GeeMap* result;
	GearyImapClientSession* session;
	GearyImapClientSession* _tmp0_;
	GeeMap* responses;
	gint token;
	GearyNonblockingMutex* _tmp1_;
	GeeHashMap* _tmp2_;
	GeeSet* _tmp3_;
	GError* cmd_err;
	GeeMap* _tmp4_;
	GearyImapClientSession* _tmp5_;
	GeeMap* _tmp6_;
	GeeMap* _tmp7_;
	GError* err;
	GError* _tmp8_;
	GError* _tmp9_;
	GearyNonblockingMutex* _tmp10_;
	GError* _tmp11_;
	GError* _tmp12_;
	GError* _tmp13_;
	GeeIterator* _cmd_it;
	GeeMap* _tmp14_;
	GeeSet* _tmp15_;
	GeeSet* _tmp16_;
	GeeSet* _tmp17_;
	GeeIterator* _tmp18_;
	GeeIterator* _tmp19_;
	GeeIterator* _tmp20_;
	GearyImapCommand* cmd;
	GeeIterator* _tmp21_;
	gpointer _tmp22_;
	GeeMap* _tmp23_;
	GearyImapCommand* _tmp24_;
	gpointer _tmp25_;
	GearyImapStatusResponse* _tmp26_;
	GearyImapCommand* _tmp27_;
	gchar* _tmp28_;
	gchar* _tmp29_;
	GError* _inner_error0_;
};

struct _GearyImapFolderSessionListUidsAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapFolderSession* self;
	GearyImapMessageSet* msg_set;
	GCancellable* cancellable;
	GeeSet* result;
	GearyImapSearchCriteria* criteria;
	GearyImapSearchCriterion* _tmp0_;
	GearyImapSearchCriterion* _tmp1_;
	GearyImapSearchCriteria* _tmp2_;
	GearyImapSearchCriteria* _tmp3_;
	GearyImapSearchCommand* cmd;
	GearyImapSearchCommand* _tmp4_;
	GeeSet* search_results;
	GeeHashSet* _tmp5_;
	GearyIterable* _tmp6_;
	GearyIterable* _tmp7_;
	GeeArrayList* _tmp8_;
	GeeArrayList* _tmp9_;
	GeeMap* _tmp10_;
	GeeMap* _tmp11_;
	GeeSet* _tmp12_;
	gint _tmp13_;
	gint _tmp14_;
	GeeSet* _tmp15_;
	GError* _inner_error0_;
};

struct _Block28Data {
	int _ref_count_;
	GearyImapFolderSession* self;
	GeeHashMap* fetched;
	GearyImapFetchBodyDataSpecifier** header_specifiers;
	gint header_specifiers_length1;
	gint _header_specifiers_size_;
	GearyImapFetchBodyDataSpecifier* body_specifier;
	GearyImapFetchBodyDataSpecifier* preview_specifier;
	GearyImapFetchBodyDataSpecifier* preview_charset_specifier;
	GeeList* email_list;
	GearyEmailField fields;
	gpointer _async_data_;
};

struct _GearyImapFolderSessionListEmailAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapFolderSession* self;
	GearyImapMessageSet* msg_set;
	GearyEmailField fields;
	GCancellable* cancellable;
	GeeList* result;
	Block28Data* _data28_;
	GeeHashMap* _tmp0_;
	gboolean success;
	GeeCollection* cmds;
	GearyImapFetchBodyDataSpecifier** _tmp1_;
	gint _tmp2_;
	GearyImapFetchBodyDataSpecifier* _tmp3_;
	GearyImapFetchBodyDataSpecifier* _tmp4_;
	GearyImapFetchBodyDataSpecifier* _tmp5_;
	GeeCollection* _tmp6_;
	GeeCollection* _tmp7_;
	gint _tmp8_;
	gint _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	GError* _tmp14_;
	GError* _tmp15_;
	GeeCollection* _tmp16_;
	GeeHashMap* _tmp17_;
	GeeMap* _tmp18_;
	GeeMap* _tmp19_;
	GError* err;
	GeeCollection* _tmp20_;
	GError* _tmp21_;
	const gchar* _tmp22_;
	GError* _tmp23_;
	GError* _tmp24_;
	GeeHashMap* _tmp25_;
	gint _tmp26_;
	gint _tmp27_;
	GeeArrayList* _tmp28_;
	GearyNonblockingConcurrent* _tmp29_;
	GearyNonblockingConcurrent* _tmp30_;
	GeeList* _tmp31_;
	GeeList* _tmp32_;
	gint _tmp33_;
	gint _tmp34_;
	GeeList* _tmp35_;
	GeeList* _tmp36_;
	GError* _inner_error0_;
};

struct _GearyImapFolderSessionUidToPositionAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapFolderSession* self;
	GearyImapMessageSet* msg_set;
	GCancellable* cancellable;
	GeeMap* result;
	gboolean _tmp0_;
	gboolean _tmp1_;
	GError* _tmp2_;
	GeeList* cmds;
	GeeArrayList* _tmp3_;
	GeeList* _tmp4_;
	GearyImapFetchCommand* _tmp5_;
	GearyImapFetchCommand* _tmp6_;
	GeeHashMap* fetched;
	GeeHashMap* _tmp7_;
	GeeList* _tmp8_;
	GeeHashMap* _tmp9_;
	GeeMap* _tmp10_;
	GeeMap* _tmp11_;
	GeeHashMap* _tmp12_;
	gboolean _tmp13_;
	gboolean _tmp14_;
	GError* _tmp15_;
	GeeMap* map;
	GeeHashMap* _tmp16_;
	GeeIterator* _seq_num_it;
	GeeHashMap* _tmp17_;
	GeeSet* _tmp18_;
	GeeSet* _tmp19_;
	GeeSet* _tmp20_;
	GeeIterator* _tmp21_;
	GeeIterator* _tmp22_;
	GeeIterator* _tmp23_;
	GearyImapSequenceNumber* seq_num;
	GeeIterator* _tmp24_;
	gpointer _tmp25_;
	GeeMap* _tmp26_;
	GeeHashMap* _tmp27_;
	GearyImapSequenceNumber* _tmp28_;
	gpointer _tmp29_;
	GearyImapFetchedData* _tmp30_;
	GeeMap* _tmp31_;
	GeeMap* _tmp32_;
	gpointer _tmp33_;
	GearyImapUID* _tmp34_;
	GearyImapSequenceNumber* _tmp35_;
	GError* _inner_error0_;
};

struct _GearyImapFolderSessionRemoveEmailAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapFolderSession* self;
	GeeList* msg_sets;
	GCancellable* cancellable;
	GearyImapClientSession* session;
	GearyImapClientSession* _tmp0_;
	GeeList* flags;
	GeeArrayList* _tmp1_;
	GeeList* _tmp2_;
	GearyImapMessageFlag* _tmp3_;
	GearyImapMessageFlag* _tmp4_;
	GeeList* cmds;
	GeeArrayList* _tmp5_;
	gboolean all_uid;
	GeeList* _msg_set_list;
	gint _msg_set_size;
	GeeList* _tmp6_;
	gint _tmp7_;
	gint _tmp8_;
	gint _msg_set_index;
	gint _tmp9_;
	gint _tmp10_;
	GearyImapMessageSet* msg_set;
	GeeList* _tmp11_;
	gpointer _tmp12_;
	GearyImapMessageSet* _tmp13_;
	gboolean _tmp14_;
	gboolean _tmp15_;
	GeeList* _tmp16_;
	GearyImapMessageSet* _tmp17_;
	GeeList* _tmp18_;
	GearyImapStoreCommand* _tmp19_;
	GearyImapStoreCommand* _tmp20_;
	gboolean _tmp21_;
	GearyImapClientSession* _tmp22_;
	GearyImapCapabilities* _tmp23_;
	GearyImapCapabilities* _tmp24_;
	GeeList* _vala1__msg_set_list;
	gint _vala1__msg_set_size;
	GeeList* _tmp25_;
	gint _tmp26_;
	gint _tmp27_;
	gint _vala1__msg_set_index;
	gint _tmp28_;
	gint _tmp29_;
	GearyImapMessageSet* _vala1_msg_set;
	GeeList* _tmp30_;
	gpointer _tmp31_;
	GeeList* _tmp32_;
	GearyImapMessageSet* _tmp33_;
	GearyImapExpungeCommand* _tmp34_;
	GearyImapExpungeCommand* _tmp35_;
	GeeList* _tmp36_;
	GearyImapExpungeCommand* _tmp37_;
	GearyImapExpungeCommand* _tmp38_;
	GeeList* _tmp39_;
	GeeMap* _tmp40_;
	GeeMap* _tmp41_;
	GError* _inner_error0_;
};

struct _GearyImapFolderSessionMarkEmailAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapFolderSession* self;
	GeeList* msg_sets;
	GearyEmailFlags* flags_to_add;
	GearyEmailFlags* flags_to_remove;
	GCancellable* cancellable;
	GeeList* msg_flags_add;
	GeeArrayList* _tmp0_;
	GeeList* msg_flags_remove;
	GeeArrayList* _tmp1_;
	GeeList* _tmp2_;
	GeeList* _tmp3_;
	gboolean _tmp4_;
	GeeList* _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	GeeList* _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	GeeCollection* cmds;
	GeeArrayList* _tmp11_;
	GeeList* _msg_set_list;
	gint _msg_set_size;
	GeeList* _tmp12_;
	gint _tmp13_;
	gint _tmp14_;
	gint _msg_set_index;
	gint _tmp15_;
	gint _tmp16_;
	GearyImapMessageSet* msg_set;
	GeeList* _tmp17_;
	gpointer _tmp18_;
	GeeList* _tmp19_;
	gint _tmp20_;
	gint _tmp21_;
	GeeCollection* _tmp22_;
	GearyImapMessageSet* _tmp23_;
	GeeList* _tmp24_;
	GearyImapStoreCommand* _tmp25_;
	GearyImapStoreCommand* _tmp26_;
	GeeList* _tmp27_;
	gint _tmp28_;
	gint _tmp29_;
	GeeCollection* _tmp30_;
	GearyImapMessageSet* _tmp31_;
	GeeList* _tmp32_;
	GearyImapStoreCommand* _tmp33_;
	GearyImapStoreCommand* _tmp34_;
	GeeCollection* _tmp35_;
	GeeMap* _tmp36_;
	GeeMap* _tmp37_;
	GError* _inner_error0_;
};

struct _GearyImapFolderSessionCopyEmailAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapFolderSession* self;
	GearyImapMessageSet* msg_set;
	GearyFolderPath* destination;
	GCancellable* cancellable;
	GeeMap* result;
	GearyImapClientSession* session;
	GearyImapClientSession* _tmp0_;
	GearyImapMailboxSpecifier* mailbox;
	GearyImapClientSession* _tmp1_;
	GearyImapMailboxSpecifier* _tmp2_;
	GearyImapCopyCommand* cmd;
	GearyImapMailboxSpecifier* _tmp3_;
	GearyImapCopyCommand* _tmp4_;
	GeeMap* responses;
	GearyImapCopyCommand* _tmp5_;
	GearyIterable* _tmp6_;
	GearyIterable* _tmp7_;
	GeeArrayList* _tmp8_;
	GeeArrayList* _tmp9_;
	GeeMap* _tmp10_;
	GeeMap* _tmp11_;
	GeeMap* _tmp12_;
	GearyImapCopyCommand* _tmp13_;
	GearyImapStatusResponse* response;
	GeeMap* _tmp14_;
	GearyImapCopyCommand* _tmp15_;
	gpointer _tmp16_;
	gboolean _tmp17_;
	GearyImapStatusResponse* _tmp18_;
	GearyImapResponseCode* _tmp19_;
	GearyImapResponseCode* _tmp20_;
	gboolean _tmp21_;
	gboolean _tmp22_;
	GeeList* src_uids;
	GeeList* dst_uids;
	GearyImapStatusResponse* _tmp23_;
	GearyImapResponseCode* _tmp24_;
	GearyImapResponseCode* _tmp25_;
	GeeList* _tmp26_;
	GeeList* _tmp27_;
	GError* ierr;
	GError* _tmp28_;
	const gchar* _tmp29_;
	gboolean _tmp30_;
	gboolean _tmp31_;
	gboolean _tmp32_;
	GeeList* _tmp33_;
	GeeList* _tmp34_;
	gboolean _tmp35_;
	gboolean _tmp36_;
	GeeList* _tmp37_;
	GeeList* _tmp38_;
	gboolean _tmp39_;
	gboolean _tmp40_;
	GeeMap* copyuids;
	GeeHashMap* _tmp41_;
	gint ctr;
	gboolean _tmp42_;
	GearyImapUID* _tmp43_;
	GeeList* _tmp44_;
	gint _tmp45_;
	gint _tmp46_;
	GeeList* _tmp47_;
	gpointer _tmp48_;
	GearyImapUID* src_uid;
	GearyImapUID* _tmp49_;
	GearyImapUID* _tmp50_;
	GeeList* _tmp51_;
	gint _tmp52_;
	gint _tmp53_;
	GeeList* _tmp54_;
	gpointer _tmp55_;
	GearyImapUID* dst_uid;
	GearyImapUID* _tmp56_;
	gboolean _tmp57_;
	GearyImapUID* _tmp58_;
	GearyImapUID* _tmp59_;
	GeeMap* _tmp60_;
	GearyImapUID* _tmp61_;
	GearyImapUID* _tmp62_;
	gint _tmp63_;
	GeeMap* _tmp64_;
	gint _tmp65_;
	gint _tmp66_;
	GError* _inner_error0_;
};

struct _GearyImapFolderSessionSearchAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapFolderSession* self;
	GearyImapSearchCriteria* criteria;
	GCancellable* cancellable;
	GeeSortedSet* result;
	GeeCollection* cmds;
	GeeArrayList* _tmp0_;
	GearyImapSearchCommand* _tmp1_;
	GearyImapSearchCommand* _tmp2_;
	GeeSet* search_results;
	GeeHashSet* _tmp3_;
	GeeMap* _tmp4_;
	GeeMap* _tmp5_;
	GeeSortedSet* tree;
	gint _tmp6_;
	gint _tmp7_;
	GeeTreeSet* _tmp8_;
	GeeSortedSet* _tmp9_;
	GError* _inner_error0_;
};

struct _GearyImapFolderSessionCreateEmailAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapFolderSession* self;
	GearyRFC822Message* message;
	GearyEmailFlags* flags;
	GDateTime* date_received;
	GearyEmailIdentifier* result;
	GearyImapMessageFlags* msg_flags;
	GearyImapEmailFlags* imap_flags;
	GearyImapEmailFlags* _tmp0_;
	GearyImapEmailFlags* _tmp1_;
	GearyImapMessageFlags* _tmp2_;
	GearyImapMessageFlags* _tmp3_;
	GearyImapMessageFlags* _tmp4_;
	GearyImapMessageFlag* _tmp5_;
	GearyImapMessageFlag* _tmp6_;
	GearyIterable* _tmp7_;
	GearyIterable* _tmp8_;
	GeeArrayList* _tmp9_;
	GeeArrayList* _tmp10_;
	GearyImapMessageFlags* _tmp11_;
	GearyImapInternalDate* internaldate;
	GearyImapInternalDate* _tmp12_;
	GearyImapInternalDate* _tmp13_;
	GearyImapInternalDate* _tmp14_;
	GearyMemoryBuffer* _tmp15_;
	GearyMemoryBuffer* _tmp16_;
	GearyImapAppendCommand* cmd;
	GearyImapMailboxSpecifier* _tmp17_;
	GearyImapMessageFlags* _tmp18_;
	GearyImapInternalDate* _tmp19_;
	GearyImapAppendCommand* _tmp20_;
	GeeMap* responses;
	GearyImapAppendCommand* _tmp21_;
	GearyIterable* _tmp22_;
	GearyIterable* _tmp23_;
	GeeArrayList* _tmp24_;
	GeeArrayList* _tmp25_;
	GeeMap* _tmp26_;
	GeeMap* _tmp27_;
	GearyImapStatusResponse* response;
	GeeMap* _tmp28_;
	GearyImapAppendCommand* _tmp29_;
	gpointer _tmp30_;
	gboolean _tmp31_;
	gboolean _tmp32_;
	GearyImapStatusResponse* _tmp33_;
	GearyImapStatus _tmp34_;
	GearyImapStatus _tmp35_;
	GearyImapStatusResponse* _tmp36_;
	GearyImapResponseCode* _tmp37_;
	GearyImapResponseCode* _tmp38_;
	GearyImapResponseCodeType* _tmp39_;
	GearyImapStatusResponse* _tmp40_;
	GearyImapResponseCode* _tmp41_;
	GearyImapResponseCode* _tmp42_;
	GearyImapResponseCodeType* _tmp43_;
	GearyImapStringParameter* _tmp44_;
	GearyImapStatusResponse* _tmp45_;
	GearyImapResponseCode* _tmp46_;
	GearyImapResponseCode* _tmp47_;
	GearyImapStringParameter* _tmp48_;
	gint64 _tmp49_;
	GearyImapUID* new_id;
	GearyImapUID* _tmp50_;
	GearyImapUID* _tmp51_;
	GearyImapDBEmailIdentifier* _tmp52_;
	GError* _inner_error0_;
};

static gint GearyImapFolderSession_private_offset;
static gpointer geary_imap_folder_session_parent_class = NULL;

VALA_EXTERN GType geary_imap_folder_session_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_folder_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GearyImapFolder* geary_imap_folder_session_get_folder (GearyImapFolderSession* self);
static void geary_imap_folder_session_set_folder (GearyImapFolderSession* self,
                                           GearyImapFolder* value);
VALA_EXTERN GearyTrillian geary_imap_folder_session_get_readonly (GearyImapFolderSession* self);
static void geary_imap_folder_session_set_readonly (GearyImapFolderSession* self,
                                             GearyTrillian value);
VALA_EXTERN GearyImapMessageFlags* geary_imap_folder_session_get_permanent_flags (GearyImapFolderSession* self);
static void geary_imap_folder_session_set_permanent_flags (GearyImapFolderSession* self,
                                                    GearyImapMessageFlags* value);
VALA_EXTERN GearyTrillian geary_imap_folder_session_get_accepts_user_flags (GearyImapFolderSession* self);
static void geary_imap_folder_session_set_accepts_user_flags (GearyImapFolderSession* self,
                                                       GearyTrillian value);
static void g_cclosure_user_marshal_VOID__OBJECT_OBJECT (GClosure * closure,
                                                  GValue * return_value,
                                                  guint n_param_values,
                                                  const GValue * param_values,
                                                  gpointer invocation_hint,
                                                  gpointer marshal_data);
static void geary_imap_folder_session_construct_data_free (gpointer _data);
VALA_EXTERN void geary_imap_folder_session_new (GearyImapClientSession* session,
                                    GearyImapFolder* folder,
                                    GCancellable* cancellable,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_);
VALA_EXTERN GearyImapFolderSession* geary_imap_folder_session_new_finish (GAsyncResult* _res_,
                                                              GError** error);
VALA_EXTERN void geary_imap_folder_session_construct (GType object_type,
                                          GearyImapClientSession* session,
                                          GearyImapFolder* folder,
                                          GCancellable* cancellable,
                                          GAsyncReadyCallback _callback_,
                                          gpointer _user_data_);
VALA_EXTERN GearyImapFolderSession* geary_imap_folder_session_construct_finish (GAsyncResult* _res_,
                                                                    GError** error);
static gboolean geary_imap_folder_session_construct_co (GearyImapFolderSessionNewData* _data_);
VALA_EXTERN GearyImapQuirks* geary_imap_client_session_get_quirks (GearyImapClientSession* self);
VALA_EXTERN GearyImapFolderProperties* geary_imap_folder_get_properties (GearyImapFolder* self);
VALA_EXTERN GearyFolderPath* geary_imap_folder_get_path (GearyImapFolder* self);
static void geary_imap_folder_session_on_exists (GearyImapFolderSession* self,
                                          gint total);
static void _geary_imap_folder_session_on_exists_geary_imap_client_session_exists (GearyImapClientSession* _sender,
                                                                            gint count,
                                                                            gpointer self);
static void geary_imap_folder_session_on_expunge (GearyImapFolderSession* self,
                                           GearyImapSequenceNumber* pos);
static void _geary_imap_folder_session_on_expunge_geary_imap_client_session_expunge (GearyImapClientSession* _sender,
                                                                              GearyImapSequenceNumber* seq_num,
                                                                              gpointer self);
static void geary_imap_folder_session_on_fetch (GearyImapFolderSession* self,
                                         GearyImapFetchedData* data);
static void _geary_imap_folder_session_on_fetch_geary_imap_client_session_fetch (GearyImapClientSession* _sender,
                                                                          GearyImapFetchedData* fetched_data,
                                                                          gpointer self);
static void geary_imap_folder_session_on_recent (GearyImapFolderSession* self,
                                          gint total);
static void _geary_imap_folder_session_on_recent_geary_imap_client_session_recent (GearyImapClientSession* _sender,
                                                                            gint count,
                                                                            gpointer self);
static void geary_imap_folder_session_on_search (GearyImapFolderSession* self,
                                          gint64* seq_or_uid,
                                          gint seq_or_uid_length1);
static void _geary_imap_folder_session_on_search_geary_imap_client_session_search (GearyImapClientSession* _sender,
                                                                            gint64* seq_or_uid,
                                                                            gint seq_or_uid_length1,
                                                                            gpointer self);
static void geary_imap_folder_session_on_status_response (GearyImapFolderSession* self,
                                                   GearyImapStatusResponse* status_response);
static void _geary_imap_folder_session_on_status_response_geary_imap_client_session_status_response_received (GearyImapClientSession* _sender,
                                                                                                       GearyImapStatusResponse* status_response,
                                                                                                       gpointer self);
static void geary_imap_folder_session_new_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_);
static void geary_imap_folder_session_throw_on_not_ok (GearyImapFolderSession* self,
                                                GearyImapStatusResponse* response,
                                                const gchar* cmd,
                                                GError** error);
static void geary_imap_folder_session_enable_idle_data_free (gpointer _data);
VALA_EXTERN void geary_imap_folder_session_enable_idle (GearyImapFolderSession* self,
                                            GCancellable* cancellable,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_);
VALA_EXTERN void geary_imap_folder_session_enable_idle_finish (GearyImapFolderSession* self,
                                                   GAsyncResult* _res_,
                                                   GError** error);
static gboolean geary_imap_folder_session_enable_idle_co (GearyImapFolderSessionEnableIdleData* _data_);
static void geary_imap_folder_session_enable_idle_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_);
static GearyImapClientSession* geary_imap_folder_session_real_close (GearyImapSessionObject* base);
static void geary_imap_folder_session_send_noop_data_free (gpointer _data);
VALA_EXTERN void geary_imap_folder_session_send_noop (GearyImapFolderSession* self,
                                          GCancellable* cancellable,
                                          GAsyncReadyCallback _callback_,
                                          gpointer _user_data_);
VALA_EXTERN void geary_imap_folder_session_send_noop_finish (GearyImapFolderSession* self,
                                                 GAsyncResult* _res_,
                                                 GError** error);
static gboolean geary_imap_folder_session_send_noop_co (GearyImapFolderSessionSendNoopData* _data_);
static void geary_imap_folder_session_exec_commands_async (GearyImapFolderSession* self,
                                                    GeeCollection* cmds,
                                                    GeeHashMap* fetch_results,
                                                    GeeSet* search_results,
                                                    GCancellable* cancellable,
                                                    GAsyncReadyCallback _callback_,
                                                    gpointer _user_data_);
static GeeMap* geary_imap_folder_session_exec_commands_finish (GearyImapFolderSession* self,
                                                        GAsyncResult* _res_,
                                                        GError** error);
static void geary_imap_folder_session_send_noop_ready (GObject* source_object,
                                                GAsyncResult* _res_,
                                                gpointer _user_data_);
VALA_EXTERN void geary_imap_folder_properties_set_recent (GearyImapFolderProperties* self,
                                              gint value);
VALA_EXTERN void geary_imap_folder_properties_set_uid_next (GearyImapFolderProperties* self,
                                                GearyImapUID* value);
VALA_EXTERN void geary_imap_folder_properties_set_uid_validity (GearyImapFolderProperties* self,
                                                    GearyImapUIDValidity* value);
static void geary_imap_folder_session_exec_commands_async_data_free (gpointer _data);
static gboolean geary_imap_folder_session_exec_commands_async_co (GearyImapFolderSessionExecCommandsAsyncData* _data_);
static void geary_imap_folder_session_exec_commands_async_ready (GObject* source_object,
                                                          GAsyncResult* _res_,
                                                          gpointer _user_data_);
static void geary_imap_folder_session_list_uids_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_folder_session_list_uids_async (GearyImapFolderSession* self,
                                                GearyImapMessageSet* msg_set,
                                                GCancellable* cancellable,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_);
VALA_EXTERN GeeSet* geary_imap_folder_session_list_uids_finish (GearyImapFolderSession* self,
                                                    GAsyncResult* _res_,
                                                    GError** error);
static gboolean geary_imap_folder_session_list_uids_async_co (GearyImapFolderSessionListUidsAsyncData* _data_);
static void geary_imap_folder_session_list_uids_async_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_);
static GeeCollection* geary_imap_folder_session_assemble_list_commands (GearyImapFolderSession* self,
                                                                 GearyImapMessageSet* msg_set,
                                                                 GearyEmailField fields,
                                                                 GCancellable* cancellable,
                                                                 GearyImapFetchBodyDataSpecifier*** header_specifiers,
                                                                 gint* header_specifiers_length1,
                                                                 GearyImapFetchBodyDataSpecifier** body_specifier,
                                                                 GearyImapFetchBodyDataSpecifier** preview_specifier,
                                                                 GearyImapFetchBodyDataSpecifier** preview_charset_specifier);
static void geary_imap_folder_session_fields_to_fetch_data_types (GearyImapFolderSession* self,
                                                           GearyEmailField fields,
                                                           GeeList* basic_types,
                                                           GeeList* header_fields);
static void geary_imap_folder_session_list_email_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_folder_session_list_email_async (GearyImapFolderSession* self,
                                                 GearyImapMessageSet* msg_set,
                                                 GearyEmailField fields,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
VALA_EXTERN GeeList* geary_imap_folder_session_list_email_finish (GearyImapFolderSession* self,
                                                      GAsyncResult* _res_,
                                                      GError** error);
static gboolean geary_imap_folder_session_list_email_async_co (GearyImapFolderSessionListEmailAsyncData* _data_);
static Block28Data* block28_data_ref (Block28Data* _data28_);
static void block28_data_unref (void * _userdata_);
static void geary_imap_folder_session_list_email_async_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_);
static gboolean geary_imap_folder_session_retry_bad_header_fields_response (GearyImapFolderSession* self,
                                                                     GeeCollection* cmds);
static void __lambda104_ (Block28Data* _data28_,
                   GError** error);
static GearyEmail* geary_imap_folder_session_fetched_data_to_email (GearyImapFolderSession* self,
                                                             GearyImapUID* uid,
                                                             GearyImapFetchedData* fetched_data,
                                                             GearyEmailField required_fields,
                                                             GearyImapFetchBodyDataSpecifier** header_specifiers,
                                                             gint header_specifiers_length1,
                                                             GearyImapFetchBodyDataSpecifier* body_specifier,
                                                             GearyImapFetchBodyDataSpecifier* preview_specifier,
                                                             GearyImapFetchBodyDataSpecifier* preview_charset_specifier,
                                                             GError** error);
static void ___lambda104__geary_nonblocking_concurrent_concurrent_callback (GCancellable* cancellable,
                                                                     gpointer self,
                                                                     GError** error);
static void geary_imap_folder_session_uid_to_position_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_folder_session_uid_to_position_async (GearyImapFolderSession* self,
                                                      GearyImapMessageSet* msg_set,
                                                      GCancellable* cancellable,
                                                      GAsyncReadyCallback _callback_,
                                                      gpointer _user_data_);
VALA_EXTERN GeeMap* geary_imap_folder_session_uid_to_position_finish (GearyImapFolderSession* self,
                                                          GAsyncResult* _res_,
                                                          GError** error);
static gboolean geary_imap_folder_session_uid_to_position_async_co (GearyImapFolderSessionUidToPositionAsyncData* _data_);
static void geary_imap_folder_session_uid_to_position_async_ready (GObject* source_object,
                                                            GAsyncResult* _res_,
                                                            gpointer _user_data_);
static void geary_imap_folder_session_remove_email_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_folder_session_remove_email_async (GearyImapFolderSession* self,
                                                   GeeList* msg_sets,
                                                   GCancellable* cancellable,
                                                   GAsyncReadyCallback _callback_,
                                                   gpointer _user_data_);
VALA_EXTERN void geary_imap_folder_session_remove_email_finish (GearyImapFolderSession* self,
                                                    GAsyncResult* _res_,
                                                    GError** error);
static gboolean geary_imap_folder_session_remove_email_async_co (GearyImapFolderSessionRemoveEmailAsyncData* _data_);
static void geary_imap_folder_session_remove_email_async_ready (GObject* source_object,
                                                         GAsyncResult* _res_,
                                                         gpointer _user_data_);
static void geary_imap_folder_session_mark_email_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_folder_session_mark_email_async (GearyImapFolderSession* self,
                                                 GeeList* msg_sets,
                                                 GearyEmailFlags* flags_to_add,
                                                 GearyEmailFlags* flags_to_remove,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
VALA_EXTERN void geary_imap_folder_session_mark_email_finish (GearyImapFolderSession* self,
                                                  GAsyncResult* _res_,
                                                  GError** error);
static gboolean geary_imap_folder_session_mark_email_async_co (GearyImapFolderSessionMarkEmailAsyncData* _data_);
static void geary_imap_folder_session_mark_email_async_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_);
static void geary_imap_folder_session_copy_email_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_folder_session_copy_email_async (GearyImapFolderSession* self,
                                                 GearyImapMessageSet* msg_set,
                                                 GearyFolderPath* destination,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
VALA_EXTERN GeeMap* geary_imap_folder_session_copy_email_finish (GearyImapFolderSession* self,
                                                     GAsyncResult* _res_,
                                                     GError** error);
static gboolean geary_imap_folder_session_copy_email_async_co (GearyImapFolderSessionCopyEmailAsyncData* _data_);
static void geary_imap_folder_session_copy_email_async_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_);
static void geary_imap_folder_session_search_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_folder_session_search_async (GearyImapFolderSession* self,
                                             GearyImapSearchCriteria* criteria,
                                             GCancellable* cancellable,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_);
VALA_EXTERN GeeSortedSet* geary_imap_folder_session_search_finish (GearyImapFolderSession* self,
                                                       GAsyncResult* _res_,
                                                       GError** error);
static gboolean geary_imap_folder_session_search_async_co (GearyImapFolderSessionSearchAsyncData* _data_);
static void geary_imap_folder_session_search_async_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_);
VALA_EXTERN GearyImapDBEmailIdentifier* geary_imap_db_email_identifier_new_no_message_id (GearyImapUID* uid);
VALA_EXTERN GearyImapDBEmailIdentifier* geary_imap_db_email_identifier_construct_no_message_id (GType object_type,
                                                                                    GearyImapUID* uid);
VALA_EXTERN GType geary_imap_db_email_identifier_get_type (void) G_GNUC_CONST ;
static guint _geary_string_stri_hash_gee_hash_data_func (gconstpointer v,
                                                  gpointer self);
static gboolean _geary_string_stri_equal_gee_equal_data_func (gconstpointer a,
                                                       gconstpointer b,
                                                       gpointer self);
static gboolean geary_imap_folder_session_required_but_not_set (GearyEmailField check,
                                                         GearyEmailField users_fields,
                                                         GearyEmail* email);
static GearyRFC822Date* geary_imap_folder_session_unflatten_date (GearyImapFolderSession* self,
                                                           const gchar* str);
static GearyRFC822MailboxAddresses* geary_imap_folder_session_unflatten_addresses (GearyImapFolderSession* self,
                                                                            const gchar* str);
static GearyRFC822MessageID* geary_imap_folder_session_unflatten_message_id (GearyImapFolderSession* self,
                                                                      const gchar* str);
static GearyRFC822MessageIDList* geary_imap_folder_session_unflatten_message_id_list (GearyImapFolderSession* self,
                                                                               const gchar* str);
static void geary_imap_folder_session_create_email_async_data_free (gpointer _data);
VALA_EXTERN void geary_imap_folder_session_create_email_async (GearyImapFolderSession* self,
                                                   GearyRFC822Message* message,
                                                   GearyEmailFlags* flags,
                                                   GDateTime* date_received,
                                                   GAsyncReadyCallback _callback_,
                                                   gpointer _user_data_);
VALA_EXTERN GearyEmailIdentifier* geary_imap_folder_session_create_email_finish (GearyImapFolderSession* self,
                                                                     GAsyncResult* _res_,
                                                                     GError** error);
static gboolean geary_imap_folder_session_create_email_async_co (GearyImapFolderSessionCreateEmailAsyncData* _data_);
static void geary_imap_folder_session_create_email_async_ready (GObject* source_object,
                                                         GAsyncResult* _res_,
                                                         gpointer _user_data_);
static GearyLoggingState* geary_imap_folder_session_real_to_logging_state (GearyImapSessionObject* base);
VALA_EXTERN gchar* geary_imap_folder_to_string (GearyImapFolder* self);
static GearyImapClientSession* geary_imap_folder_session_real_get_session (GearyImapSessionObject* base,
                                                                    GError** error);
static void geary_imap_folder_session_finalize (GObject * obj);
static GType geary_imap_folder_session_get_type_once (void);
static void _vala_geary_imap_folder_session_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);
static void _vala_geary_imap_folder_session_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
geary_imap_folder_session_get_instance_private (GearyImapFolderSession* self)
{
	return G_STRUCT_MEMBER_P (self, GearyImapFolderSession_private_offset);
}

GearyImapFolder*
geary_imap_folder_session_get_folder (GearyImapFolderSession* self)
{
	GearyImapFolder* result;
	GearyImapFolder* _tmp0_;
	g_return_val_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self), NULL);
	_tmp0_ = self->priv->_folder;
	result = _tmp0_;
	return result;
}

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

static void
geary_imap_folder_session_set_folder (GearyImapFolderSession* self,
                                      GearyImapFolder* value)
{
	GearyImapFolder* old_value;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	old_value = geary_imap_folder_session_get_folder (self);
	if (old_value != value) {
		GearyImapFolder* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_folder);
		self->priv->_folder = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_folder_session_properties[GEARY_IMAP_FOLDER_SESSION_FOLDER_PROPERTY]);
	}
}

GearyTrillian
geary_imap_folder_session_get_readonly (GearyImapFolderSession* self)
{
	GearyTrillian result;
	g_return_val_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self), 0);
	result = self->priv->_readonly;
	return result;
}

static void
geary_imap_folder_session_set_readonly (GearyImapFolderSession* self,
                                        GearyTrillian value)
{
	GearyTrillian old_value;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	old_value = geary_imap_folder_session_get_readonly (self);
	if (old_value != value) {
		self->priv->_readonly = value;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_folder_session_properties[GEARY_IMAP_FOLDER_SESSION_READONLY_PROPERTY]);
	}
}

GearyImapMessageFlags*
geary_imap_folder_session_get_permanent_flags (GearyImapFolderSession* self)
{
	GearyImapMessageFlags* result;
	GearyImapMessageFlags* _tmp0_;
	g_return_val_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self), NULL);
	_tmp0_ = self->priv->_permanent_flags;
	result = _tmp0_;
	return result;
}

static void
geary_imap_folder_session_set_permanent_flags (GearyImapFolderSession* self,
                                               GearyImapMessageFlags* value)
{
	GearyImapMessageFlags* old_value;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	old_value = geary_imap_folder_session_get_permanent_flags (self);
	if (old_value != value) {
		GearyImapMessageFlags* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_permanent_flags);
		self->priv->_permanent_flags = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_folder_session_properties[GEARY_IMAP_FOLDER_SESSION_PERMANENT_FLAGS_PROPERTY]);
	}
}

GearyTrillian
geary_imap_folder_session_get_accepts_user_flags (GearyImapFolderSession* self)
{
	GearyTrillian result;
	g_return_val_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self), 0);
	result = self->priv->_accepts_user_flags;
	return result;
}

static void
geary_imap_folder_session_set_accepts_user_flags (GearyImapFolderSession* self,
                                                  GearyTrillian value)
{
	GearyTrillian old_value;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	old_value = geary_imap_folder_session_get_accepts_user_flags (self);
	if (old_value != value) {
		self->priv->_accepts_user_flags = value;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_folder_session_properties[GEARY_IMAP_FOLDER_SESSION_ACCEPTS_USER_FLAGS_PROPERTY]);
	}
}

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

static void
geary_imap_folder_session_construct_data_free (gpointer _data)
{
	GearyImapFolderSessionNewData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->session);
	_g_object_unref0 (_data_->folder);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapFolderSessionNewData, _data_);
}

void
geary_imap_folder_session_construct (GType object_type,
                                     GearyImapClientSession* session,
                                     GearyImapFolder* folder,
                                     GCancellable* cancellable,
                                     GAsyncReadyCallback _callback_,
                                     gpointer _user_data_)
{
	GearyImapFolderSessionNewData* _data_;
	GearyImapClientSession* _tmp0_;
	GearyImapFolder* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (session));
	g_return_if_fail (GEARY_IMAP_IS_FOLDER (folder));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapFolderSessionNewData);
	_data_->_async_result = g_task_new (NULL, cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_folder_session_construct_data_free);
	_data_->object_type = object_type;
	_tmp0_ = _g_object_ref0 (session);
	_g_object_unref0 (_data_->session);
	_data_->session = _tmp0_;
	_tmp1_ = _g_object_ref0 (folder);
	_g_object_unref0 (_data_->folder);
	_data_->folder = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_folder_session_construct_co (_data_);
}

GearyImapFolderSession*
geary_imap_folder_session_construct_finish (GAsyncResult* _res_,
                                            GError** error)
{
	GearyImapFolderSession* result;
	GearyImapFolderSessionNewData* _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
_geary_imap_folder_session_on_exists_geary_imap_client_session_exists (GearyImapClientSession* _sender,
                                                                       gint count,
                                                                       gpointer self)
{
	geary_imap_folder_session_on_exists ((GearyImapFolderSession*) self, count);
}

static void
_geary_imap_folder_session_on_expunge_geary_imap_client_session_expunge (GearyImapClientSession* _sender,
                                                                         GearyImapSequenceNumber* seq_num,
                                                                         gpointer self)
{
	geary_imap_folder_session_on_expunge ((GearyImapFolderSession*) self, seq_num);
}

static void
_geary_imap_folder_session_on_fetch_geary_imap_client_session_fetch (GearyImapClientSession* _sender,
                                                                     GearyImapFetchedData* fetched_data,
                                                                     gpointer self)
{
	geary_imap_folder_session_on_fetch ((GearyImapFolderSession*) self, fetched_data);
}

static void
_geary_imap_folder_session_on_recent_geary_imap_client_session_recent (GearyImapClientSession* _sender,
                                                                       gint count,
                                                                       gpointer self)
{
	geary_imap_folder_session_on_recent ((GearyImapFolderSession*) self, count);
}

static void
_geary_imap_folder_session_on_search_geary_imap_client_session_search (GearyImapClientSession* _sender,
                                                                       gint64* seq_or_uid,
                                                                       gint seq_or_uid_length1,
                                                                       gpointer self)
{
	geary_imap_folder_session_on_search ((GearyImapFolderSession*) self, seq_or_uid, seq_or_uid_length1);
}

static void
_geary_imap_folder_session_on_status_response_geary_imap_client_session_status_response_received (GearyImapClientSession* _sender,
                                                                                                  GearyImapStatusResponse* status_response,
                                                                                                  gpointer self)
{
	geary_imap_folder_session_on_status_response ((GearyImapFolderSession*) self, status_response);
}

static void
geary_imap_folder_session_new_ready (GObject* source_object,
                                     GAsyncResult* _res_,
                                     gpointer _user_data_)
{
	GearyImapFolderSessionNewData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_folder_session_construct_co (_data_);
}

static gboolean
geary_imap_folder_session_construct_co (GearyImapFolderSessionNewData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->self = (GearyImapFolderSession*) geary_imap_session_object_construct (_data_->object_type, _data_->session);
	geary_imap_folder_session_set_folder (_data_->self, _data_->folder);
	_data_->_tmp0_ = geary_imap_client_session_get_quirks (_data_->session);
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = _g_object_ref0 (_data_->_tmp1_);
	_g_object_unref0 (_data_->self->priv->quirks);
	_data_->self->priv->quirks = _data_->_tmp2_;
	_data_->_tmp3_ = geary_imap_folder_get_properties (_data_->folder);
	_data_->_tmp4_ = _data_->_tmp3_;
	_data_->_tmp5_ = geary_imap_folder_properties_get_attrs (_data_->_tmp4_);
	_data_->_tmp6_ = _data_->_tmp5_;
	_data_->_tmp7_ = geary_imap_mailbox_attributes_get_is_no_select (_data_->_tmp6_);
	_data_->_tmp8_ = _data_->_tmp7_;
	if (_data_->_tmp8_) {
		_data_->_tmp9_ = geary_imap_folder_get_path (_data_->folder);
		_data_->_tmp10_ = _data_->_tmp9_;
		_data_->_tmp11_ = geary_folder_path_to_string (_data_->_tmp10_);
		_data_->_tmp12_ = _data_->_tmp11_;
		_data_->_tmp13_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_NOT_SUPPORTED, "Folder cannot be selected: %s", _data_->_tmp12_);
		_data_->_tmp14_ = _data_->_tmp13_;
		_g_free0 (_data_->_tmp12_);
		_data_->_inner_error0_ = _data_->_tmp14_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp15_ = geary_imap_folder_get_properties (_data_->folder);
	_data_->_tmp16_ = _data_->_tmp15_;
	_data_->_tmp17_ = geary_imap_client_session_get_capabilities (_data_->session);
	_data_->_tmp18_ = _data_->_tmp17_;
	geary_imap_folder_properties_set_from_session_capabilities (_data_->_tmp16_, _data_->_tmp18_);
	g_signal_connect_object (_data_->session, "exists", (GCallback) _geary_imap_folder_session_on_exists_geary_imap_client_session_exists, _data_->self, 0);
	g_signal_connect_object (_data_->session, "expunge", (GCallback) _geary_imap_folder_session_on_expunge_geary_imap_client_session_expunge, _data_->self, 0);
	g_signal_connect_object (_data_->session, "fetch", (GCallback) _geary_imap_folder_session_on_fetch_geary_imap_client_session_fetch, _data_->self, 0);
	g_signal_connect_object (_data_->session, "recent", (GCallback) _geary_imap_folder_session_on_recent_geary_imap_client_session_recent, _data_->self, 0);
	g_signal_connect_object (_data_->session, "search", (GCallback) _geary_imap_folder_session_on_search_geary_imap_client_session_search, _data_->self, 0);
	g_signal_connect_object (_data_->session, "status-response-received", (GCallback) _geary_imap_folder_session_on_status_response_geary_imap_client_session_status_response_received, _data_->self, 0);
	_data_->_tmp20_ = geary_imap_folder_get_path (_data_->folder);
	_data_->_tmp21_ = _data_->_tmp20_;
	_data_->_tmp22_ = geary_imap_client_session_get_mailbox_for_path (_data_->session, _data_->_tmp21_, &_data_->_inner_error0_);
	_data_->_tmp19_ = _data_->_tmp22_;
	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_->_tmp23_ = _data_->_tmp19_;
	_data_->_tmp19_ = NULL;
	_g_object_unref0 (_data_->self->priv->mailbox);
	_data_->self->priv->mailbox = _data_->_tmp23_;
	_data_->_tmp24_ = _data_->self->priv->mailbox;
	_data_->_state_ = 1;
	geary_imap_client_session_select_async (_data_->session, _data_->_tmp24_, _data_->cancellable, geary_imap_folder_session_new_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp25_ = geary_imap_client_session_select_finish (_data_->session, _data_->_res_, &_data_->_inner_error0_);
	_data_->response = _data_->_tmp25_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->_tmp19_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp26_ = _data_->response;
	_data_->_tmp27_ = _data_->self->priv->_folder;
	_data_->_tmp28_ = geary_imap_folder_get_path (_data_->_tmp27_);
	_data_->_tmp29_ = _data_->_tmp28_;
	_data_->_tmp30_ = geary_folder_path_to_string (_data_->_tmp29_);
	_data_->_tmp31_ = _data_->_tmp30_;
	_data_->_tmp32_ = g_strconcat ("SELECT ", _data_->_tmp31_, NULL);
	_data_->_tmp33_ = _data_->_tmp32_;
	geary_imap_folder_session_throw_on_not_ok (_data_->self, _data_->_tmp26_, _data_->_tmp33_, &_data_->_inner_error0_);
	_g_free0 (_data_->_tmp33_);
	_g_free0 (_data_->_tmp31_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->response);
		_g_object_unref0 (_data_->_tmp19_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp34_ = _data_->self->priv->_accepts_user_flags;
	if (_data_->_tmp34_ == GEARY_TRILLIAN_UNKNOWN) {
		geary_imap_folder_session_set_accepts_user_flags (_data_->self, GEARY_TRILLIAN_TRUE);
	}
	_g_object_unref0 (_data_->response);
	_g_object_unref0 (_data_->_tmp19_);
	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
geary_imap_folder_session_new (GearyImapClientSession* session,
                               GearyImapFolder* folder,
                               GCancellable* cancellable,
                               GAsyncReadyCallback _callback_,
                               gpointer _user_data_)
{
	geary_imap_folder_session_construct (GEARY_IMAP_TYPE_FOLDER_SESSION, session, folder, cancellable, _callback_, _user_data_);
}

GearyImapFolderSession*
geary_imap_folder_session_new_finish (GAsyncResult* _res_,
                                      GError** error)
{
	return geary_imap_folder_session_construct_finish (_res_, error);
}

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

void
geary_imap_folder_session_enable_idle (GearyImapFolderSession* self,
                                       GCancellable* cancellable,
                                       GAsyncReadyCallback _callback_,
                                       gpointer _user_data_)
{
	GearyImapFolderSessionEnableIdleData* _data_;
	GearyImapFolderSession* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapFolderSessionEnableIdleData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_folder_session_enable_idle_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_folder_session_enable_idle_co (_data_);
}

void
geary_imap_folder_session_enable_idle_finish (GearyImapFolderSession* self,
                                              GAsyncResult* _res_,
                                              GError** error)
{
	GearyImapFolderSessionEnableIdleData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

/**
     * Enables IMAP IDLE for the session, if supported.
     */
static void
geary_imap_folder_session_enable_idle_ready (GObject* source_object,
                                             GAsyncResult* _res_,
                                             gpointer _user_data_)
{
	GearyImapFolderSessionEnableIdleData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_folder_session_enable_idle_co (_data_);
}

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

static gboolean
geary_imap_folder_session_enable_idle_co (GearyImapFolderSessionEnableIdleData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = geary_imap_session_object_get_session (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_TYPE_SESSION_OBJECT, GearyImapSessionObject), &_data_->_inner_error0_);
	_data_->session = _data_->_tmp0_;
	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_->_tmp1_ = _data_->self->priv->cmd_mutex;
	_data_->_state_ = 1;
	geary_nonblocking_mutex_claim_async (_data_->_tmp1_, _data_->cancellable, geary_imap_folder_session_enable_idle_ready, _data_);
	return FALSE;
	_state_1:
	_data_->token = geary_nonblocking_mutex_claim_finish (_data_->_tmp1_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->session);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->cmd_err = NULL;
	{
		_data_->_tmp2_ = _data_->session;
		geary_imap_client_session_enable_idle (_data_->_tmp2_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->err = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp3_ = _data_->err;
		_data_->_tmp4_ = _g_error_copy0 (_data_->_tmp3_);
		_g_error_free0 (_data_->cmd_err);
		_data_->cmd_err = _data_->_tmp4_;
		_g_error_free0 (_data_->err);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_error_free0 (_data_->cmd_err);
		_g_object_unref0 (_data_->session);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp5_ = _data_->self->priv->cmd_mutex;
	geary_nonblocking_mutex_release (_data_->_tmp5_, &_data_->token, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_error_free0 (_data_->cmd_err);
		_g_object_unref0 (_data_->session);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp6_ = _data_->cmd_err;
	if (_data_->_tmp6_ != NULL) {
		_data_->_tmp7_ = _data_->cmd_err;
		_data_->_tmp8_ = _g_error_copy0 (_data_->_tmp7_);
		_data_->_inner_error0_ = _data_->_tmp8_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_error_free0 (_data_->cmd_err);
		_g_object_unref0 (_data_->session);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_error_free0 (_data_->cmd_err);
	_g_object_unref0 (_data_->session);
	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;
}

/** {@inheritDoc} */
static GearyImapClientSession*
geary_imap_folder_session_real_close (GearyImapSessionObject* base)
{
	GearyImapFolderSession * self;
	GearyImapClientSession* old_session = NULL;
	GearyImapClientSession* _tmp0_;
	GearyImapClientSession* _tmp1_;
	GearyImapClientSession* result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_TYPE_FOLDER_SESSION, GearyImapFolderSession);
	_tmp0_ = GEARY_IMAP_SESSION_OBJECT_CLASS (geary_imap_folder_session_parent_class)->close (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_IMAP_TYPE_SESSION_OBJECT, GearyImapSessionObject));
	old_session = _tmp0_;
	_tmp1_ = old_session;
	if (_tmp1_ != NULL) {
		GearyImapClientSession* _tmp2_;
		guint _tmp3_;
		GearyImapClientSession* _tmp4_;
		guint _tmp5_;
		GearyImapClientSession* _tmp6_;
		guint _tmp7_;
		GearyImapClientSession* _tmp8_;
		guint _tmp9_;
		GearyImapClientSession* _tmp10_;
		guint _tmp11_;
		GearyImapClientSession* _tmp12_;
		guint _tmp13_;
		_tmp2_ = old_session;
		g_signal_parse_name ("exists", GEARY_IMAP_TYPE_CLIENT_SESSION, &_tmp3_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp2_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp3_, 0, NULL, (GCallback) _geary_imap_folder_session_on_exists_geary_imap_client_session_exists, self);
		_tmp4_ = old_session;
		g_signal_parse_name ("expunge", GEARY_IMAP_TYPE_CLIENT_SESSION, &_tmp5_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp4_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp5_, 0, NULL, (GCallback) _geary_imap_folder_session_on_expunge_geary_imap_client_session_expunge, self);
		_tmp6_ = old_session;
		g_signal_parse_name ("fetch", GEARY_IMAP_TYPE_CLIENT_SESSION, &_tmp7_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp6_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp7_, 0, NULL, (GCallback) _geary_imap_folder_session_on_fetch_geary_imap_client_session_fetch, self);
		_tmp8_ = old_session;
		g_signal_parse_name ("recent", GEARY_IMAP_TYPE_CLIENT_SESSION, &_tmp9_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp8_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp9_, 0, NULL, (GCallback) _geary_imap_folder_session_on_recent_geary_imap_client_session_recent, self);
		_tmp10_ = old_session;
		g_signal_parse_name ("search", GEARY_IMAP_TYPE_CLIENT_SESSION, &_tmp11_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp10_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp11_, 0, NULL, (GCallback) _geary_imap_folder_session_on_search_geary_imap_client_session_search, self);
		_tmp12_ = old_session;
		g_signal_parse_name ("status-response-received", GEARY_IMAP_TYPE_CLIENT_SESSION, &_tmp13_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp12_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp13_, 0, NULL, (GCallback) _geary_imap_folder_session_on_status_response_geary_imap_client_session_status_response_received, self);
	}
	result = old_session;
	return result;
}

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

void
geary_imap_folder_session_send_noop (GearyImapFolderSession* self,
                                     GCancellable* cancellable,
                                     GAsyncReadyCallback _callback_,
                                     gpointer _user_data_)
{
	GearyImapFolderSessionSendNoopData* _data_;
	GearyImapFolderSession* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapFolderSessionSendNoopData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_folder_session_send_noop_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_folder_session_send_noop_co (_data_);
}

void
geary_imap_folder_session_send_noop_finish (GearyImapFolderSession* self,
                                            GAsyncResult* _res_,
                                            GError** error)
{
	GearyImapFolderSessionSendNoopData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

/** Sends a NOOP command. */
static void
geary_imap_folder_session_send_noop_ready (GObject* source_object,
                                           GAsyncResult* _res_,
                                           gpointer _user_data_)
{
	GearyImapFolderSessionSendNoopData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_folder_session_send_noop_co (_data_);
}

static gboolean
geary_imap_folder_session_send_noop_co (GearyImapFolderSessionSendNoopData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = geary_imap_noop_command_new (_data_->cancellable);
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = geary_collection_single (GEARY_IMAP_TYPE_NOOP_COMMAND, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->_tmp1_);
	_data_->_tmp3_ = _data_->_tmp2_;
	_data_->_state_ = 1;
	geary_imap_folder_session_exec_commands_async (_data_->self, _data_->_tmp3_, NULL, NULL, _data_->cancellable, geary_imap_folder_session_send_noop_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp4_ = geary_imap_folder_session_exec_commands_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp5_ = _data_->_tmp4_;
	_g_object_unref0 (_data_->_tmp5_);
	_g_object_unref0 (_data_->_tmp3_);
	_g_object_unref0 (_data_->_tmp1_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_folder_session_on_exists (GearyImapFolderSession* self,
                                     gint total)
{
	gint old_total = 0;
	GearyImapFolder* _tmp0_;
	GearyImapFolderProperties* _tmp1_;
	GearyImapFolderProperties* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	GearyImapFolder* _tmp5_;
	GearyImapFolderProperties* _tmp6_;
	GearyImapFolderProperties* _tmp7_;
	gboolean _tmp8_ = FALSE;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "EXISTS %d", total);
	_tmp0_ = self->priv->_folder;
	_tmp1_ = geary_imap_folder_get_properties (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = geary_imap_folder_properties_get_select_examine_messages (_tmp2_);
	_tmp4_ = _tmp3_;
	old_total = _tmp4_;
	_tmp5_ = self->priv->_folder;
	_tmp6_ = geary_imap_folder_get_properties (_tmp5_);
	_tmp7_ = _tmp6_;
	geary_imap_folder_properties_set_select_examine_message_count (_tmp7_, total);
	g_signal_emit (self, geary_imap_folder_session_signals[GEARY_IMAP_FOLDER_SESSION_EXISTS_SIGNAL], 0, total);
	if (old_total >= 0) {
		_tmp8_ = old_total < total;
	} else {
		_tmp8_ = FALSE;
	}
	if (_tmp8_) {
		g_signal_emit (self, geary_imap_folder_session_signals[GEARY_IMAP_FOLDER_SESSION_APPENDED_SIGNAL], 0, total - old_total);
	}
}

static void
geary_imap_folder_session_on_expunge (GearyImapFolderSession* self,
                                      GearyImapSequenceNumber* pos)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint old_total = 0;
	GearyImapFolder* _tmp2_;
	GearyImapFolderProperties* _tmp3_;
	GearyImapFolderProperties* _tmp4_;
	gint _tmp5_;
	gint _tmp6_;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	g_return_if_fail (GEARY_IMAP_IS_SEQUENCE_NUMBER (pos));
	_tmp0_ = geary_message_data_abstract_message_data_to_string (G_TYPE_CHECK_INSTANCE_CAST (pos, GEARY_MESSAGE_DATA_TYPE_ABSTRACT_MESSAGE_DATA, GearyMessageDataAbstractMessageData));
	_tmp1_ = _tmp0_;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "EXPUNGE %s", _tmp1_);
	_g_free0 (_tmp1_);
	_tmp2_ = self->priv->_folder;
	_tmp3_ = geary_imap_folder_get_properties (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = geary_imap_folder_properties_get_select_examine_messages (_tmp4_);
	_tmp6_ = _tmp5_;
	old_total = _tmp6_;
	if (old_total > 0) {
		GearyImapFolder* _tmp7_;
		GearyImapFolderProperties* _tmp8_;
		GearyImapFolderProperties* _tmp9_;
		_tmp7_ = self->priv->_folder;
		_tmp8_ = geary_imap_folder_get_properties (_tmp7_);
		_tmp9_ = _tmp8_;
		geary_imap_folder_properties_set_select_examine_message_count (_tmp9_, old_total - 1);
	}
	g_signal_emit (self, geary_imap_folder_session_signals[GEARY_IMAP_FOLDER_SESSION_EXPUNGE_SIGNAL], 0, pos);
	g_signal_emit (self, geary_imap_folder_session_signals[GEARY_IMAP_FOLDER_SESSION_REMOVED_SIGNAL], 0, pos);
}

static void
geary_imap_folder_session_on_fetch (GearyImapFolderSession* self,
                                    GearyImapFetchedData* data)
{
	GeeHashMap* _tmp0_;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	g_return_if_fail (GEARY_IMAP_IS_FETCHED_DATA (data));
	_tmp0_ = self->priv->fetch_accumulator;
	if (_tmp0_ != NULL) {
		GearyImapFetchedData* existing = NULL;
		GeeHashMap* _tmp1_;
		GearyImapSequenceNumber* _tmp2_;
		GearyImapSequenceNumber* _tmp3_;
		gpointer _tmp4_;
		GearyImapFetchedData* _tmp5_ = NULL;
		GearyImapFetchedData* _tmp6_;
		GeeHashMap* _tmp10_;
		GearyImapSequenceNumber* _tmp11_;
		GearyImapSequenceNumber* _tmp12_;
		_tmp1_ = self->priv->fetch_accumulator;
		_tmp2_ = geary_imap_fetched_data_get_seq_num (data);
		_tmp3_ = _tmp2_;
		_tmp4_ = gee_abstract_map_get (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _tmp3_);
		existing = (GearyImapFetchedData*) _tmp4_;
		_tmp6_ = existing;
		if (_tmp6_ != NULL) {
			GearyImapFetchedData* _tmp7_;
			GearyImapFetchedData* _tmp8_;
			_tmp7_ = existing;
			_tmp8_ = geary_imap_fetched_data_combine (data, _tmp7_);
			_g_object_unref0 (_tmp5_);
			_tmp5_ = _tmp8_;
		} else {
			GearyImapFetchedData* _tmp9_;
			_tmp9_ = _g_object_ref0 (data);
			_g_object_unref0 (_tmp5_);
			_tmp5_ = _tmp9_;
		}
		_tmp10_ = self->priv->fetch_accumulator;
		_tmp11_ = geary_imap_fetched_data_get_seq_num (data);
		_tmp12_ = _tmp11_;
		gee_abstract_map_set (G_TYPE_CHECK_INSTANCE_CAST (_tmp10_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _tmp12_, _tmp5_);
		_g_object_unref0 (_tmp5_);
		_g_object_unref0 (existing);
	} else {
		gchar* _tmp13_;
		gchar* _tmp14_;
		GearyImapSequenceNumber* _tmp15_;
		GearyImapSequenceNumber* _tmp16_;
		_tmp13_ = geary_imap_fetched_data_to_string (data);
		_tmp14_ = _tmp13_;
		geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "FETCH (unsolicited): %s:", _tmp14_);
		_g_free0 (_tmp14_);
		_tmp15_ = geary_imap_fetched_data_get_seq_num (data);
		_tmp16_ = _tmp15_;
		g_signal_emit (self, geary_imap_folder_session_signals[GEARY_IMAP_FOLDER_SESSION_UPDATED_SIGNAL], 0, _tmp16_, data);
	}
}

static void
geary_imap_folder_session_on_recent (GearyImapFolderSession* self,
                                     gint total)
{
	GearyImapFolder* _tmp0_;
	GearyImapFolderProperties* _tmp1_;
	GearyImapFolderProperties* _tmp2_;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "RECENT %d", total);
	_tmp0_ = self->priv->_folder;
	_tmp1_ = geary_imap_folder_get_properties (_tmp0_);
	_tmp2_ = _tmp1_;
	geary_imap_folder_properties_set_recent (_tmp2_, total);
	g_signal_emit (self, geary_imap_folder_session_signals[GEARY_IMAP_FOLDER_SESSION_RECENT_SIGNAL], 0, total);
}

static void
geary_imap_folder_session_on_search (GearyImapFolderSession* self,
                                     gint64* seq_or_uid,
                                     gint seq_or_uid_length1)
{
	GeeSet* _tmp0_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	_tmp0_ = self->priv->search_accumulator;
	if (_tmp0_ != NULL) {
		{
			gint64* uid_collection = NULL;
			gint uid_collection_length1 = 0;
			gint _uid_collection_size_ = 0;
			gint uid_it = 0;
			uid_collection = seq_or_uid;
			uid_collection_length1 = seq_or_uid_length1;
			for (uid_it = 0; uid_it < uid_collection_length1; uid_it = uid_it + 1) {
				gint64 uid = 0LL;
				uid = uid_collection[uid_it];
				{
					{
						GearyImapUID* _tmp1_ = NULL;
						GearyImapUID* _tmp2_;
						GeeSet* _tmp3_;
						_tmp2_ = geary_imap_uid_new_checked (uid, &_inner_error0_);
						_tmp1_ = _tmp2_;
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							if (_inner_error0_->domain == GEARY_IMAP_ERROR) {
								goto __catch0_geary_imap_error;
							}
							g_critical ("file %s: line %d: unexpected 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;
						}
						_tmp3_ = self->priv->search_accumulator;
						gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, GEE_TYPE_COLLECTION, GeeCollection), _tmp1_);
						_g_object_unref0 (_tmp1_);
					}
					goto __finally0;
					__catch0_geary_imap_error:
					{
						GError* imaperr = NULL;
						GError* _tmp4_;
						const gchar* _tmp5_;
						imaperr = _inner_error0_;
						_inner_error0_ = NULL;
						_tmp4_ = imaperr;
						_tmp5_ = _tmp4_->message;
						geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Unable to process SEARCH UID result: %s", _tmp5_);
						_g_error_free0 (imaperr);
					}
					__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;
					}
				}
			}
		}
	} else {
		geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Not handling unsolicited SEARCH response");
	}
}

static void
geary_imap_folder_session_on_status_response (GearyImapFolderSession* self,
                                              GearyImapStatusResponse* status_response)
{
	GearyImapResponseCode* response_code = NULL;
	GearyImapResponseCode* _tmp0_;
	GearyImapResponseCode* _tmp1_;
	GearyImapResponseCode* _tmp2_;
	GearyImapResponseCode* _tmp3_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	g_return_if_fail (GEARY_IMAP_IS_STATUS_RESPONSE (status_response));
	_tmp0_ = geary_imap_status_response_get_response_code (status_response);
	_tmp1_ = _tmp0_;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	response_code = _tmp2_;
	_tmp3_ = response_code;
	if (_tmp3_ == NULL) {
		_g_object_unref0 (response_code);
		return;
	}
	{
		GearyImapResponseCodeType* _tmp4_ = NULL;
		GearyImapResponseCode* _tmp5_;
		GearyImapResponseCodeType* _tmp6_;
		gchar* value = NULL;
		const gchar* _tmp7_;
		const gchar* _tmp8_;
		gchar* _tmp9_;
		const gchar* _tmp10_;
		const gchar* _tmp11_;
		GQuark _tmp13_ = 0U;
		static GQuark _tmp12_label0 = 0;
		static GQuark _tmp12_label1 = 0;
		static GQuark _tmp12_label2 = 0;
		static GQuark _tmp12_label3 = 0;
		static GQuark _tmp12_label4 = 0;
		static GQuark _tmp12_label5 = 0;
		_tmp5_ = response_code;
		_tmp6_ = geary_imap_response_code_get_response_code_type (_tmp5_, &_inner_error0_);
		_tmp4_ = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == GEARY_IMAP_ERROR) {
				goto __catch0_geary_imap_error;
			}
			_g_object_unref0 (response_code);
			g_critical ("file %s: line %d: unexpected 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;
		}
		_tmp7_ = geary_imap_response_code_type_get_value (_tmp4_);
		_tmp8_ = _tmp7_;
		_tmp9_ = g_strdup (_tmp8_);
		value = _tmp9_;
		_tmp10_ = value;
		_tmp11_ = _tmp10_;
		_tmp13_ = (NULL == _tmp11_) ? 0 : g_quark_from_string (_tmp11_);
		if (_tmp13_ == ((0 != _tmp12_label0) ? _tmp12_label0 : (_tmp12_label0 = g_quark_from_static_string (GEARY_IMAP_RESPONSE_CODE_TYPE_READONLY)))) {
			switch (0) {
				default:
				{
					geary_imap_folder_session_set_readonly (self, GEARY_TRILLIAN_TRUE);
					break;
				}
			}
		} else if (_tmp13_ == ((0 != _tmp12_label1) ? _tmp12_label1 : (_tmp12_label1 = g_quark_from_static_string (GEARY_IMAP_RESPONSE_CODE_TYPE_READWRITE)))) {
			switch (0) {
				default:
				{
					geary_imap_folder_session_set_readonly (self, GEARY_TRILLIAN_FALSE);
					break;
				}
			}
		} else if (_tmp13_ == ((0 != _tmp12_label2) ? _tmp12_label2 : (_tmp12_label2 = g_quark_from_static_string (GEARY_IMAP_RESPONSE_CODE_TYPE_UIDNEXT)))) {
			switch (0) {
				default:
				{
					{
						GearyImapUID* _tmp14_ = NULL;
						GearyImapResponseCode* _tmp15_;
						GearyImapUID* _tmp16_;
						GearyImapFolder* _tmp17_;
						GearyImapFolderProperties* _tmp18_;
						GearyImapFolderProperties* _tmp19_;
						_tmp15_ = response_code;
						_tmp16_ = geary_imap_response_code_get_uid_next (_tmp15_, &_inner_error0_);
						_tmp14_ = _tmp16_;
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							if (g_error_matches (_inner_error0_, GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_INVALID)) {
								goto __catch1_geary_imap_error_invalid;
							}
							goto __finally1;
						}
						_tmp17_ = self->priv->_folder;
						_tmp18_ = geary_imap_folder_get_properties (_tmp17_);
						_tmp19_ = _tmp18_;
						geary_imap_folder_properties_set_uid_next (_tmp19_, _tmp14_);
						_g_object_unref0 (_tmp14_);
					}
					goto __finally1;
					__catch1_geary_imap_error_invalid:
					{
						GError* err = NULL;
						GearyImapStringParameter* _tmp20_ = NULL;
						GearyImapResponseCode* _tmp21_;
						GearyImapStringParameter* _tmp22_;
						gint64 _tmp23_ = 0LL;
						err = _inner_error0_;
						_inner_error0_ = NULL;
						_tmp21_ = response_code;
						_tmp22_ = geary_imap_list_parameter_get_as_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp21_, GEARY_IMAP_TYPE_LIST_PARAMETER, GearyImapListParameter), 1, &_inner_error0_);
						_tmp20_ = _tmp22_;
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_g_error_free0 (err);
							goto __finally1;
						}
						_tmp23_ = geary_imap_string_parameter_as_int64 (_tmp20_, G_MININT64, G_MAXINT64, &_inner_error0_);
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_g_object_unref0 (_tmp20_);
							_g_error_free0 (err);
							goto __finally1;
						}
						if (_tmp23_ == ((gint64) 0)) {
							geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Ignoring bad UIDNEXT 0 from server");
						} else {
							GError* _tmp24_;
							GError* _tmp25_;
							_tmp24_ = err;
							_tmp25_ = _g_error_copy0 (_tmp24_);
							_inner_error0_ = _tmp25_;
							_g_object_unref0 (_tmp20_);
							_g_error_free0 (err);
							goto __finally1;
						}
						_g_object_unref0 (_tmp20_);
						_g_error_free0 (err);
					}
					__finally1:
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						_g_free0 (value);
						_g_object_unref0 (_tmp4_);
						if (_inner_error0_->domain == GEARY_IMAP_ERROR) {
							goto __catch0_geary_imap_error;
						}
						_g_object_unref0 (response_code);
						g_critical ("file %s: line %d: unexpected 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;
					}
					break;
				}
			}
		} else if (_tmp13_ == ((0 != _tmp12_label3) ? _tmp12_label3 : (_tmp12_label3 = g_quark_from_static_string (GEARY_IMAP_RESPONSE_CODE_TYPE_UIDVALIDITY)))) {
			switch (0) {
				default:
				{
					GearyImapUIDValidity* _tmp26_ = NULL;
					GearyImapResponseCode* _tmp27_;
					GearyImapUIDValidity* _tmp28_;
					GearyImapFolder* _tmp29_;
					GearyImapFolderProperties* _tmp30_;
					GearyImapFolderProperties* _tmp31_;
					_tmp27_ = response_code;
					_tmp28_ = geary_imap_response_code_get_uid_validity (_tmp27_, &_inner_error0_);
					_tmp26_ = _tmp28_;
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						_g_free0 (value);
						_g_object_unref0 (_tmp4_);
						if (_inner_error0_->domain == GEARY_IMAP_ERROR) {
							goto __catch0_geary_imap_error;
						}
						_g_object_unref0 (response_code);
						g_critical ("file %s: line %d: unexpected 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;
					}
					_tmp29_ = self->priv->_folder;
					_tmp30_ = geary_imap_folder_get_properties (_tmp29_);
					_tmp31_ = _tmp30_;
					geary_imap_folder_properties_set_uid_validity (_tmp31_, _tmp26_);
					_g_object_unref0 (_tmp26_);
					break;
				}
			}
		} else if (_tmp13_ == ((0 != _tmp12_label4) ? _tmp12_label4 : (_tmp12_label4 = g_quark_from_static_string (GEARY_IMAP_RESPONSE_CODE_TYPE_UNSEEN)))) {
			switch (0) {
				default:
				{
					break;
				}
			}
		} else if (_tmp13_ == ((0 != _tmp12_label5) ? _tmp12_label5 : (_tmp12_label5 = g_quark_from_static_string (GEARY_IMAP_RESPONSE_CODE_TYPE_PERMANENT_FLAGS)))) {
			switch (0) {
				default:
				{
					GearyImapMessageFlags* _tmp32_ = NULL;
					GearyImapResponseCode* _tmp33_;
					GearyImapMessageFlags* _tmp34_;
					GearyImapMessageFlags* _tmp35_;
					GearyImapMessageFlag* _tmp36_;
					GearyImapMessageFlag* _tmp37_;
					_tmp33_ = response_code;
					_tmp34_ = geary_imap_response_code_get_permanent_flags (_tmp33_, &_inner_error0_);
					_tmp32_ = _tmp34_;
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						_g_free0 (value);
						_g_object_unref0 (_tmp4_);
						if (_inner_error0_->domain == GEARY_IMAP_ERROR) {
							goto __catch0_geary_imap_error;
						}
						_g_object_unref0 (response_code);
						g_critical ("file %s: line %d: unexpected 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;
					}
					geary_imap_folder_session_set_permanent_flags (self, _tmp32_);
					_tmp35_ = self->priv->_permanent_flags;
					_tmp36_ = geary_imap_message_flag_get_ALLOWS_NEW ();
					_tmp37_ = _tmp36_;
					geary_imap_folder_session_set_accepts_user_flags (self, geary_trillian_from_boolean (geary_imap_flags_contains (G_TYPE_CHECK_INSTANCE_CAST (_tmp35_, GEARY_IMAP_TYPE_FLAGS, GearyImapFlags), G_TYPE_CHECK_INSTANCE_CAST (_tmp37_, GEARY_IMAP_TYPE_FLAG, GearyImapFlag))));
					_g_object_unref0 (_tmp32_);
					break;
				}
			}
		} else {
			switch (0) {
				default:
				{
					break;
				}
			}
		}
		_g_free0 (value);
		_g_object_unref0 (_tmp4_);
	}
	goto __finally0;
	__catch0_geary_imap_error:
	{
		GError* ierr = NULL;
		GearyImapResponseCode* _tmp38_;
		gchar* _tmp39_;
		gchar* _tmp40_;
		GError* _tmp41_;
		const gchar* _tmp42_;
		ierr = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp38_ = response_code;
		_tmp39_ = geary_imap_parameter_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp38_, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
		_tmp40_ = _tmp39_;
		_tmp41_ = ierr;
		_tmp42_ = _tmp41_->message;
		geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Unable to parse ResponseCode %s: %s", _tmp40_, _tmp42_);
		_g_free0 (_tmp40_);
		_g_error_free0 (ierr);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (response_code);
		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;
	}
	_g_object_unref0 (response_code);
}

static void
geary_imap_folder_session_exec_commands_async_data_free (gpointer _data)
{
	GearyImapFolderSessionExecCommandsAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cmds);
	_g_object_unref0 (_data_->fetch_results);
	_g_object_unref0 (_data_->search_results);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapFolderSessionExecCommandsAsyncData, _data_);
}

static void
geary_imap_folder_session_exec_commands_async (GearyImapFolderSession* self,
                                               GeeCollection* cmds,
                                               GeeHashMap* fetch_results,
                                               GeeSet* search_results,
                                               GCancellable* cancellable,
                                               GAsyncReadyCallback _callback_,
                                               gpointer _user_data_)
{
	GearyImapFolderSessionExecCommandsAsyncData* _data_;
	GearyImapFolderSession* _tmp0_;
	GeeCollection* _tmp1_;
	GeeHashMap* _tmp2_;
	GeeSet* _tmp3_;
	GCancellable* _tmp4_;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (cmds, GEE_TYPE_COLLECTION));
	g_return_if_fail ((fetch_results == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (fetch_results, GEE_TYPE_HASH_MAP));
	g_return_if_fail ((search_results == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (search_results, GEE_TYPE_SET));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapFolderSessionExecCommandsAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_folder_session_exec_commands_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cmds);
	_g_object_unref0 (_data_->cmds);
	_data_->cmds = _tmp1_;
	_tmp2_ = _g_object_ref0 (fetch_results);
	_g_object_unref0 (_data_->fetch_results);
	_data_->fetch_results = _tmp2_;
	_tmp3_ = _g_object_ref0 (search_results);
	_g_object_unref0 (_data_->search_results);
	_data_->search_results = _tmp3_;
	_tmp4_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp4_;
	geary_imap_folder_session_exec_commands_async_co (_data_);
}

static GeeMap*
geary_imap_folder_session_exec_commands_finish (GearyImapFolderSession* self,
                                                GAsyncResult* _res_,
                                                GError** error)
{
	GeeMap* result;
	GearyImapFolderSessionExecCommandsAsyncData* _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
geary_imap_folder_session_exec_commands_async_ready (GObject* source_object,
                                                     GAsyncResult* _res_,
                                                     gpointer _user_data_)
{
	GearyImapFolderSessionExecCommandsAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_folder_session_exec_commands_async_co (_data_);
}

static gboolean
geary_imap_folder_session_exec_commands_async_co (GearyImapFolderSessionExecCommandsAsyncData* _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_ = geary_imap_session_object_get_session (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_TYPE_SESSION_OBJECT, GearyImapSessionObject), &_data_->_inner_error0_);
	_data_->session = _data_->_tmp0_;
	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_->responses = NULL;
	_data_->_tmp1_ = _data_->self->priv->cmd_mutex;
	_data_->_state_ = 1;
	geary_nonblocking_mutex_claim_async (_data_->_tmp1_, _data_->cancellable, geary_imap_folder_session_exec_commands_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->token = geary_nonblocking_mutex_claim_finish (_data_->_tmp1_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->responses);
		_g_object_unref0 (_data_->session);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp2_ = _g_object_ref0 (_data_->fetch_results);
	_g_object_unref0 (_data_->self->priv->fetch_accumulator);
	_data_->self->priv->fetch_accumulator = _data_->_tmp2_;
	_data_->_tmp3_ = _g_object_ref0 (_data_->search_results);
	_g_object_unref0 (_data_->self->priv->search_accumulator);
	_data_->self->priv->search_accumulator = _data_->_tmp3_;
	_data_->cmd_err = NULL;
	{
		_data_->_tmp5_ = _data_->session;
		_data_->_state_ = 2;
		geary_imap_client_session_send_multiple_commands_async (_data_->_tmp5_, _data_->cmds, _data_->cancellable, geary_imap_folder_session_exec_commands_async_ready, _data_);
		return FALSE;
		_state_2:
		_data_->_tmp6_ = geary_imap_client_session_send_multiple_commands_finish (_data_->_tmp5_, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp4_ = _data_->_tmp6_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp7_ = _data_->_tmp4_;
		_data_->_tmp4_ = NULL;
		_g_object_unref0 (_data_->responses);
		_data_->responses = _data_->_tmp7_;
		_g_object_unref0 (_data_->_tmp4_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->err = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp8_ = _data_->err;
		_data_->_tmp9_ = _g_error_copy0 (_data_->_tmp8_);
		_g_error_free0 (_data_->cmd_err);
		_data_->cmd_err = _data_->_tmp9_;
		_g_error_free0 (_data_->err);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_error_free0 (_data_->cmd_err);
		_g_object_unref0 (_data_->responses);
		_g_object_unref0 (_data_->session);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_object_unref0 (_data_->self->priv->fetch_accumulator);
	_data_->self->priv->fetch_accumulator = NULL;
	_g_object_unref0 (_data_->self->priv->search_accumulator);
	_data_->self->priv->search_accumulator = NULL;
	_data_->_tmp10_ = _data_->self->priv->cmd_mutex;
	geary_nonblocking_mutex_release (_data_->_tmp10_, &_data_->token, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_error_free0 (_data_->cmd_err);
		_g_object_unref0 (_data_->responses);
		_g_object_unref0 (_data_->session);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp11_ = _data_->cmd_err;
	if (_data_->_tmp11_ != NULL) {
		_data_->_tmp12_ = _data_->cmd_err;
		_data_->_tmp13_ = _g_error_copy0 (_data_->_tmp12_);
		_data_->_inner_error0_ = _data_->_tmp13_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_error_free0 (_data_->cmd_err);
		_g_object_unref0 (_data_->responses);
		_g_object_unref0 (_data_->session);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	{
		_data_->_tmp14_ = _data_->responses;
		_data_->_tmp15_ = gee_map_get_keys (_data_->_tmp14_);
		_data_->_tmp16_ = _data_->_tmp15_;
		_data_->_tmp17_ = _data_->_tmp16_;
		_data_->_tmp18_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp17_, GEE_TYPE_ITERABLE, GeeIterable));
		_data_->_tmp19_ = _data_->_tmp18_;
		_g_object_unref0 (_data_->_tmp17_);
		_data_->_cmd_it = _data_->_tmp19_;
		while (TRUE) {
			_data_->_tmp20_ = _data_->_cmd_it;
			if (!gee_iterator_next (_data_->_tmp20_)) {
				break;
			}
			_data_->_tmp21_ = _data_->_cmd_it;
			_data_->_tmp22_ = gee_iterator_get (_data_->_tmp21_);
			_data_->cmd = (GearyImapCommand*) _data_->_tmp22_;
			_data_->_tmp23_ = _data_->responses;
			_data_->_tmp24_ = _data_->cmd;
			_data_->_tmp25_ = gee_map_get (_data_->_tmp23_, _data_->_tmp24_);
			_data_->_tmp26_ = (GearyImapStatusResponse*) _data_->_tmp25_;
			_data_->_tmp27_ = _data_->cmd;
			_data_->_tmp28_ = geary_imap_command_to_string (_data_->_tmp27_);
			_data_->_tmp29_ = _data_->_tmp28_;
			geary_imap_folder_session_throw_on_not_ok (_data_->self, _data_->_tmp26_, _data_->_tmp29_, &_data_->_inner_error0_);
			_g_free0 (_data_->_tmp29_);
			_g_object_unref0 (_data_->_tmp26_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
				_g_object_unref0 (_data_->cmd);
				_g_object_unref0 (_data_->_cmd_it);
				_g_error_free0 (_data_->cmd_err);
				_g_object_unref0 (_data_->responses);
				_g_object_unref0 (_data_->session);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
			_g_object_unref0 (_data_->cmd);
		}
		_g_object_unref0 (_data_->_cmd_it);
	}
	_data_->result = _data_->responses;
	_g_error_free0 (_data_->cmd_err);
	_g_object_unref0 (_data_->session);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_folder_session_list_uids_async_data_free (gpointer _data)
{
	GearyImapFolderSessionListUidsAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->msg_set);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapFolderSessionListUidsAsyncData, _data_);
}

void
geary_imap_folder_session_list_uids_async (GearyImapFolderSession* self,
                                           GearyImapMessageSet* msg_set,
                                           GCancellable* cancellable,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_)
{
	GearyImapFolderSessionListUidsAsyncData* _data_;
	GearyImapFolderSession* _tmp0_;
	GearyImapMessageSet* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	g_return_if_fail (GEARY_IMAP_IS_MESSAGE_SET (msg_set));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapFolderSessionListUidsAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_folder_session_list_uids_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (msg_set);
	_g_object_unref0 (_data_->msg_set);
	_data_->msg_set = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_folder_session_list_uids_async_co (_data_);
}

GeeSet*
geary_imap_folder_session_list_uids_finish (GearyImapFolderSession* self,
                                            GAsyncResult* _res_,
                                            GError** error)
{
	GeeSet* result;
	GearyImapFolderSessionListUidsAsyncData* _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
geary_imap_folder_session_list_uids_async_ready (GObject* source_object,
                                                 GAsyncResult* _res_,
                                                 gpointer _user_data_)
{
	GearyImapFolderSessionListUidsAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_folder_session_list_uids_async_co (_data_);
}

static gboolean
geary_imap_folder_session_list_uids_async_co (GearyImapFolderSessionListUidsAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = geary_imap_search_criterion_message_set (_data_->msg_set);
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = geary_imap_search_criteria_new (_data_->_tmp1_);
	_data_->_tmp3_ = _data_->_tmp2_;
	_g_object_unref0 (_data_->_tmp1_);
	_data_->criteria = _data_->_tmp3_;
	_data_->_tmp4_ = geary_imap_search_command_new_uid (_data_->criteria, _data_->cancellable);
	_data_->cmd = _data_->_tmp4_;
	_data_->_tmp5_ = gee_hash_set_new (GEARY_IMAP_TYPE_UID, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->search_results = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp5_, GEE_TYPE_SET, GeeSet);
	_data_->_tmp6_ = geary_iterate (GEARY_IMAP_TYPE_COMMAND, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, G_TYPE_CHECK_INSTANCE_CAST (_data_->cmd, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand), NULL);
	_data_->_tmp7_ = _data_->_tmp6_;
	_data_->_tmp8_ = geary_iterable_to_array_list (_data_->_tmp7_, NULL, NULL, NULL);
	_data_->_tmp9_ = _data_->_tmp8_;
	_data_->_state_ = 1;
	geary_imap_folder_session_exec_commands_async (_data_->self, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp9_, GEE_TYPE_COLLECTION, GeeCollection), NULL, _data_->search_results, _data_->cancellable, geary_imap_folder_session_list_uids_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp10_ = geary_imap_folder_session_exec_commands_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp11_ = _data_->_tmp10_;
	_g_object_unref0 (_data_->_tmp11_);
	_g_object_unref0 (_data_->_tmp9_);
	_g_object_unref0 (_data_->_tmp7_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->search_results);
		_g_object_unref0 (_data_->cmd);
		_g_object_unref0 (_data_->criteria);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp13_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->search_results, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp14_ = _data_->_tmp13_;
	if (_data_->_tmp14_ > 0) {
		_data_->_tmp12_ = _data_->search_results;
	} else {
		_data_->_tmp12_ = NULL;
	}
	_data_->_tmp15_ = _g_object_ref0 (_data_->_tmp12_);
	_data_->result = _data_->_tmp15_;
	_g_object_unref0 (_data_->search_results);
	_g_object_unref0 (_data_->cmd);
	_g_object_unref0 (_data_->criteria);
	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 GeeCollection*
geary_imap_folder_session_assemble_list_commands (GearyImapFolderSession* self,
                                                  GearyImapMessageSet* msg_set,
                                                  GearyEmailField fields,
                                                  GCancellable* cancellable,
                                                  GearyImapFetchBodyDataSpecifier*** header_specifiers,
                                                  gint* header_specifiers_length1,
                                                  GearyImapFetchBodyDataSpecifier** body_specifier,
                                                  GearyImapFetchBodyDataSpecifier** preview_specifier,
                                                  GearyImapFetchBodyDataSpecifier** preview_charset_specifier)
{
	GearyImapFetchBodyDataSpecifier** _vala_header_specifiers = NULL;
	gint _vala_header_specifiers_length1 = 0;
	GearyImapFetchBodyDataSpecifier* _vala_body_specifier = NULL;
	GearyImapFetchBodyDataSpecifier* _vala_preview_specifier = NULL;
	GearyImapFetchBodyDataSpecifier* _vala_preview_charset_specifier = NULL;
	GeeCollection* cmds = NULL;
	GeeArrayList* _tmp0_;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp69_ = FALSE;
	GeeCollection* result;
	g_return_val_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self), NULL);
	g_return_val_if_fail (GEARY_IMAP_IS_MESSAGE_SET (msg_set), NULL);
	g_return_val_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()), NULL);
	_tmp0_ = gee_array_list_new (GEARY_IMAP_TYPE_FETCH_COMMAND, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	cmds = G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEE_TYPE_COLLECTION, GeeCollection);
	_tmp2_ = geary_imap_message_set_get_is_uid (msg_set);
	_tmp3_ = _tmp2_;
	if (!_tmp3_) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = fields == GEARY_EMAIL_FIELD_NONE;
	}
	if (_tmp1_) {
		GeeCollection* _tmp4_;
		GearyImapFetchCommand* _tmp5_;
		GearyImapFetchCommand* _tmp6_;
		_tmp4_ = cmds;
		_tmp5_ = geary_imap_fetch_command_new_data_type (msg_set, GEARY_IMAP_FETCH_DATA_SPECIFIER_UID, cancellable);
		_tmp6_ = _tmp5_;
		gee_collection_add (_tmp4_, _tmp6_);
		_g_object_unref0 (_tmp6_);
	}
	_vala_header_specifiers = (_vala_array_free (_vala_header_specifiers, _vala_header_specifiers_length1, (GDestroyNotify) g_object_unref), NULL);
	_vala_header_specifiers = NULL;
	_vala_header_specifiers_length1 = 0;
	if (geary_email_field_requires_any (fields, GEARY_IMAP_FOLDER_SESSION_BASIC_FETCH_FIELDS)) {
		GeeList* basic_types = NULL;
		GeeLinkedList* _tmp7_;
		GeeList* header_fields = NULL;
		GeeLinkedList* _tmp8_;
		GeeList* _tmp9_;
		GeeList* _tmp10_;
		GeeList* _tmp11_;
		gboolean _tmp12_;
		gboolean _tmp13_;
		GeeList* _tmp18_;
		gboolean _tmp19_;
		gboolean _tmp20_;
		_tmp7_ = gee_linked_list_new (GEARY_IMAP_TYPE_FETCH_DATA_SPECIFIER, NULL, NULL, NULL, NULL, NULL);
		basic_types = G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, GEE_TYPE_LIST, GeeList);
		_tmp8_ = gee_linked_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
		header_fields = G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, GEE_TYPE_LIST, GeeList);
		_tmp9_ = basic_types;
		_tmp10_ = header_fields;
		geary_imap_folder_session_fields_to_fetch_data_types (self, fields, _tmp9_, _tmp10_);
		_tmp11_ = basic_types;
		_tmp12_ = gee_collection_get_is_empty (G_TYPE_CHECK_INSTANCE_CAST (_tmp11_, GEE_TYPE_COLLECTION, GeeCollection));
		_tmp13_ = _tmp12_;
		if (!_tmp13_) {
			GeeCollection* _tmp14_;
			GeeList* _tmp15_;
			GearyImapFetchCommand* _tmp16_;
			GearyImapFetchCommand* _tmp17_;
			_tmp14_ = cmds;
			_tmp15_ = basic_types;
			_tmp16_ = geary_imap_fetch_command_new (msg_set, _tmp15_, NULL, cancellable);
			_tmp17_ = _tmp16_;
			gee_collection_add (_tmp14_, _tmp17_);
			_g_object_unref0 (_tmp17_);
		}
		_tmp18_ = header_fields;
		_tmp19_ = gee_collection_get_is_empty (G_TYPE_CHECK_INSTANCE_CAST (_tmp18_, GEE_TYPE_COLLECTION, GeeCollection));
		_tmp20_ = _tmp19_;
		if (!_tmp20_) {
			gboolean _tmp21_ = FALSE;
			GearyImapQuirks* _tmp22_;
			gboolean _tmp23_;
			gboolean _tmp24_;
			GearyImapFetchBodyDataSpecifier** _tmp54_;
			gint _tmp54__length1;
			_tmp22_ = self->priv->quirks;
			_tmp23_ = geary_imap_quirks_get_fetch_header_part_no_space (_tmp22_);
			_tmp24_ = _tmp23_;
			if (!_tmp24_) {
				_tmp21_ = TRUE;
			} else {
				GeeList* _tmp25_;
				gint _tmp26_;
				gint _tmp27_;
				_tmp25_ = header_fields;
				_tmp26_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp25_, GEE_TYPE_COLLECTION, GeeCollection));
				_tmp27_ = _tmp26_;
				_tmp21_ = _tmp27_ == 1;
			}
			if (_tmp21_) {
				GearyImapFetchBodyDataSpecifier** _tmp28_;
				GearyImapFetchBodyDataSpecifier** _tmp29_;
				gint _tmp29__length1;
				GeeList* _tmp30_;
				gint _tmp31_ = 0;
				gpointer* _tmp32_;
				gchar** _tmp33_;
				gint _tmp33__length1;
				GearyImapFetchBodyDataSpecifier* _tmp34_;
				_tmp28_ = g_new0 (GearyImapFetchBodyDataSpecifier*, 1 + 1);
				_vala_header_specifiers = (_vala_array_free (_vala_header_specifiers, _vala_header_specifiers_length1, (GDestroyNotify) g_object_unref), NULL);
				_vala_header_specifiers = _tmp28_;
				_vala_header_specifiers_length1 = 1;
				_tmp29_ = _vala_header_specifiers;
				_tmp29__length1 = _vala_header_specifiers_length1;
				_tmp30_ = header_fields;
				_tmp32_ = gee_collection_to_array (G_TYPE_CHECK_INSTANCE_CAST (_tmp30_, GEE_TYPE_COLLECTION, GeeCollection), &_tmp31_);
				_tmp33_ = _tmp32_;
				_tmp33__length1 = _tmp31_;
				_tmp34_ = geary_imap_fetch_body_data_specifier_new_peek (GEARY_IMAP_FETCH_BODY_DATA_SPECIFIER_SECTION_PART_HEADER_FIELDS, NULL, 0, -1, -1, _tmp33_, _tmp31_);
				_g_object_unref0 (_tmp29_[0]);
				_tmp29_[0] = _tmp34_;
				_tmp33_ = (_vala_array_free (_tmp33_, _tmp33__length1, (GDestroyNotify) g_free), NULL);
			} else {
				GeeList* _tmp35_;
				gint _tmp36_;
				gint _tmp37_;
				GearyImapFetchBodyDataSpecifier** _tmp38_;
				gint i = 0;
				_tmp35_ = header_fields;
				_tmp36_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp35_, GEE_TYPE_COLLECTION, GeeCollection));
				_tmp37_ = _tmp36_;
				_tmp38_ = g_new0 (GearyImapFetchBodyDataSpecifier*, _tmp37_ + 1);
				_vala_header_specifiers = (_vala_array_free (_vala_header_specifiers, _vala_header_specifiers_length1, (GDestroyNotify) g_object_unref), NULL);
				_vala_header_specifiers = _tmp38_;
				_vala_header_specifiers_length1 = _tmp37_;
				i = 0;
				{
					GeeList* _name_list = NULL;
					GeeList* _tmp39_;
					gint _name_size = 0;
					GeeList* _tmp40_;
					gint _tmp41_;
					gint _tmp42_;
					gint _name_index = 0;
					_tmp39_ = header_fields;
					_name_list = _tmp39_;
					_tmp40_ = _name_list;
					_tmp41_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp40_, GEE_TYPE_COLLECTION, GeeCollection));
					_tmp42_ = _tmp41_;
					_name_size = _tmp42_;
					_name_index = -1;
					while (TRUE) {
						gint _tmp43_;
						gint _tmp44_;
						gchar* name = NULL;
						GeeList* _tmp45_;
						gpointer _tmp46_;
						GearyImapFetchBodyDataSpecifier** _tmp47_;
						gint _tmp47__length1;
						gint _tmp48_;
						const gchar* _tmp49_;
						gchar* _tmp50_;
						gchar** _tmp51_;
						gchar** _tmp52_;
						gint _tmp52__length1;
						GearyImapFetchBodyDataSpecifier* _tmp53_;
						_name_index = _name_index + 1;
						_tmp43_ = _name_index;
						_tmp44_ = _name_size;
						if (!(_tmp43_ < _tmp44_)) {
							break;
						}
						_tmp45_ = _name_list;
						_tmp46_ = gee_list_get (_tmp45_, _name_index);
						name = (gchar*) _tmp46_;
						_tmp47_ = _vala_header_specifiers;
						_tmp47__length1 = _vala_header_specifiers_length1;
						_tmp48_ = i;
						i = _tmp48_ + 1;
						_tmp49_ = name;
						_tmp50_ = g_strdup (_tmp49_);
						_tmp51_ = g_new0 (gchar*, 1 + 1);
						_tmp51_[0] = _tmp50_;
						_tmp52_ = _tmp51_;
						_tmp52__length1 = 1;
						_tmp53_ = geary_imap_fetch_body_data_specifier_new_peek (GEARY_IMAP_FETCH_BODY_DATA_SPECIFIER_SECTION_PART_HEADER_FIELDS, NULL, 0, -1, -1, _tmp52_, 1);
						_g_object_unref0 (_tmp47_[_tmp48_]);
						_tmp47_[_tmp48_] = _tmp53_;
						_tmp52_ = (_vala_array_free (_tmp52_, _tmp52__length1, (GDestroyNotify) g_free), NULL);
						_g_free0 (name);
					}
				}
			}
			_tmp54_ = _vala_header_specifiers;
			_tmp54__length1 = _vala_header_specifiers_length1;
			{
				GearyImapFetchBodyDataSpecifier** header_collection = NULL;
				gint header_collection_length1 = 0;
				gint _header_collection_size_ = 0;
				gint header_it = 0;
				header_collection = _tmp54_;
				header_collection_length1 = _tmp54__length1;
				for (header_it = 0; header_it < header_collection_length1; header_it = header_it + 1) {
					GearyImapFetchBodyDataSpecifier* _tmp55_;
					GearyImapFetchBodyDataSpecifier* header = NULL;
					_tmp55_ = _g_object_ref0 (header_collection[header_it]);
					header = _tmp55_;
					{
						GearyImapQuirks* _tmp56_;
						gboolean _tmp57_;
						gboolean _tmp58_;
						GeeCollection* _tmp60_;
						GearyImapFetchBodyDataSpecifier* _tmp61_;
						GearyImapFetchCommand* _tmp62_;
						GearyImapFetchCommand* _tmp63_;
						_tmp56_ = self->priv->quirks;
						_tmp57_ = geary_imap_quirks_get_fetch_header_part_no_space (_tmp56_);
						_tmp58_ = _tmp57_;
						if (_tmp58_) {
							GearyImapFetchBodyDataSpecifier* _tmp59_;
							_tmp59_ = header;
							geary_imap_fetch_body_data_specifier_omit_request_header_fields_space (_tmp59_);
						}
						_tmp60_ = cmds;
						_tmp61_ = header;
						_tmp62_ = geary_imap_fetch_command_new_body_data_type (msg_set, _tmp61_, cancellable);
						_tmp63_ = _tmp62_;
						gee_collection_add (_tmp60_, _tmp63_);
						_g_object_unref0 (_tmp63_);
						_g_object_unref0 (header);
					}
				}
			}
		}
		_g_object_unref0 (header_fields);
		_g_object_unref0 (basic_types);
	}
	if (geary_email_field_require (fields, GEARY_EMAIL_FIELD_BODY)) {
		GearyImapFetchBodyDataSpecifier* _tmp64_;
		GeeCollection* _tmp65_;
		GearyImapFetchBodyDataSpecifier* _tmp66_;
		GearyImapFetchCommand* _tmp67_;
		GearyImapFetchCommand* _tmp68_;
		_tmp64_ = geary_imap_fetch_body_data_specifier_new_peek (GEARY_IMAP_FETCH_BODY_DATA_SPECIFIER_SECTION_PART_TEXT, NULL, 0, -1, -1, NULL, 0);
		_g_object_unref0 (_vala_body_specifier);
		_vala_body_specifier = _tmp64_;
		_tmp65_ = cmds;
		_tmp66_ = _vala_body_specifier;
		_tmp67_ = geary_imap_fetch_command_new_body_data_type (msg_set, _tmp66_, cancellable);
		_tmp68_ = _tmp67_;
		gee_collection_add (_tmp65_, _tmp68_);
		_g_object_unref0 (_tmp68_);
	} else {
		_g_object_unref0 (_vala_body_specifier);
		_vala_body_specifier = NULL;
	}
	if (geary_email_field_require (fields, GEARY_EMAIL_FIELD_PREVIEW)) {
		_tmp69_ = !geary_email_field_require (fields, GEARY_EMAIL_REQUIRED_FOR_MESSAGE);
	} else {
		_tmp69_ = FALSE;
	}
	if (_tmp69_) {
		gint* _tmp70_;
		gint* _tmp71_;
		gint _tmp71__length1;
		GearyImapFetchBodyDataSpecifier* _tmp72_;
		GeeCollection* _tmp73_;
		GearyImapFetchBodyDataSpecifier* _tmp74_;
		GearyImapFetchCommand* _tmp75_;
		GearyImapFetchCommand* _tmp76_;
		gint* _tmp77_;
		gint* _tmp78_;
		gint _tmp78__length1;
		GearyImapFetchBodyDataSpecifier* _tmp79_;
		GeeCollection* _tmp80_;
		GearyImapFetchBodyDataSpecifier* _tmp81_;
		GearyImapFetchCommand* _tmp82_;
		GearyImapFetchCommand* _tmp83_;
		_tmp70_ = g_new0 (gint, 1);
		_tmp70_[0] = 1;
		_tmp71_ = _tmp70_;
		_tmp71__length1 = 1;
		_tmp72_ = geary_imap_fetch_body_data_specifier_new_peek (GEARY_IMAP_FETCH_BODY_DATA_SPECIFIER_SECTION_PART_NONE, _tmp71_, 1, 0, GEARY_EMAIL_MAX_PREVIEW_BYTES, NULL, 0);
		_g_object_unref0 (_vala_preview_specifier);
		_vala_preview_specifier = _tmp72_;
		_tmp71_ = (g_free (_tmp71_), NULL);
		_tmp73_ = cmds;
		_tmp74_ = _vala_preview_specifier;
		_tmp75_ = geary_imap_fetch_command_new_body_data_type (msg_set, _tmp74_, cancellable);
		_tmp76_ = _tmp75_;
		gee_collection_add (_tmp73_, _tmp76_);
		_g_object_unref0 (_tmp76_);
		_tmp77_ = g_new0 (gint, 1);
		_tmp77_[0] = 1;
		_tmp78_ = _tmp77_;
		_tmp78__length1 = 1;
		_tmp79_ = geary_imap_fetch_body_data_specifier_new_peek (GEARY_IMAP_FETCH_BODY_DATA_SPECIFIER_SECTION_PART_MIME, _tmp78_, 1, -1, -1, NULL, 0);
		_g_object_unref0 (_vala_preview_charset_specifier);
		_vala_preview_charset_specifier = _tmp79_;
		_tmp78_ = (g_free (_tmp78_), NULL);
		_tmp80_ = cmds;
		_tmp81_ = _vala_preview_charset_specifier;
		_tmp82_ = geary_imap_fetch_command_new_body_data_type (msg_set, _tmp81_, cancellable);
		_tmp83_ = _tmp82_;
		gee_collection_add (_tmp80_, _tmp83_);
		_g_object_unref0 (_tmp83_);
	} else {
		_g_object_unref0 (_vala_preview_specifier);
		_vala_preview_specifier = NULL;
		_g_object_unref0 (_vala_preview_charset_specifier);
		_vala_preview_charset_specifier = NULL;
	}
	if (geary_email_field_requires_any (fields, GEARY_EMAIL_FIELD_PROPERTIES | GEARY_EMAIL_FIELD_FLAGS)) {
		GeeList* data_types = NULL;
		GeeArrayList* _tmp84_;
		GeeCollection* _tmp88_;
		GeeList* _tmp89_;
		GearyImapFetchCommand* _tmp90_;
		GearyImapFetchCommand* _tmp91_;
		_tmp84_ = gee_array_list_new (GEARY_IMAP_TYPE_FETCH_DATA_SPECIFIER, NULL, NULL, NULL, NULL, NULL);
		data_types = G_TYPE_CHECK_INSTANCE_CAST (_tmp84_, GEE_TYPE_LIST, GeeList);
		if (geary_email_field_require (fields, GEARY_EMAIL_FIELD_PROPERTIES)) {
			GeeList* _tmp85_;
			GeeList* _tmp86_;
			_tmp85_ = data_types;
			gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp85_, GEE_TYPE_COLLECTION, GeeCollection), (gpointer) ((gintptr) GEARY_IMAP_FETCH_DATA_SPECIFIER_INTERNALDATE));
			_tmp86_ = data_types;
			gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp86_, GEE_TYPE_COLLECTION, GeeCollection), (gpointer) ((gintptr) GEARY_IMAP_FETCH_DATA_SPECIFIER_RFC822_SIZE));
		}
		if (geary_email_field_require (fields, GEARY_EMAIL_FIELD_FLAGS)) {
			GeeList* _tmp87_;
			_tmp87_ = data_types;
			gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp87_, GEE_TYPE_COLLECTION, GeeCollection), (gpointer) ((gintptr) GEARY_IMAP_FETCH_DATA_SPECIFIER_FLAGS));
		}
		_tmp88_ = cmds;
		_tmp89_ = data_types;
		_tmp90_ = geary_imap_fetch_command_new (msg_set, _tmp89_, NULL, cancellable);
		_tmp91_ = _tmp90_;
		gee_collection_add (_tmp88_, _tmp91_);
		_g_object_unref0 (_tmp91_);
		_g_object_unref0 (data_types);
	}
	result = cmds;
	if (header_specifiers) {
		*header_specifiers = _vala_header_specifiers;
	} else {
		_vala_header_specifiers = (_vala_array_free (_vala_header_specifiers, _vala_header_specifiers_length1, (GDestroyNotify) g_object_unref), NULL);
	}
	if (header_specifiers_length1) {
		*header_specifiers_length1 = _vala_header_specifiers_length1;
	}
	if (body_specifier) {
		*body_specifier = _vala_body_specifier;
	} else {
		_g_object_unref0 (_vala_body_specifier);
	}
	if (preview_specifier) {
		*preview_specifier = _vala_preview_specifier;
	} else {
		_g_object_unref0 (_vala_preview_specifier);
	}
	if (preview_charset_specifier) {
		*preview_charset_specifier = _vala_preview_charset_specifier;
	} else {
		_g_object_unref0 (_vala_preview_charset_specifier);
	}
	return result;
}

static void
geary_imap_folder_session_list_email_async_data_free (gpointer _data)
{
	GearyImapFolderSessionListEmailAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->msg_set);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapFolderSessionListEmailAsyncData, _data_);
}

void
geary_imap_folder_session_list_email_async (GearyImapFolderSession* self,
                                            GearyImapMessageSet* msg_set,
                                            GearyEmailField fields,
                                            GCancellable* cancellable,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_)
{
	GearyImapFolderSessionListEmailAsyncData* _data_;
	GearyImapFolderSession* _tmp0_;
	GearyImapMessageSet* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	g_return_if_fail (GEARY_IMAP_IS_MESSAGE_SET (msg_set));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapFolderSessionListEmailAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_folder_session_list_email_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (msg_set);
	_g_object_unref0 (_data_->msg_set);
	_data_->msg_set = _tmp1_;
	_data_->fields = fields;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_folder_session_list_email_async_co (_data_);
}

GeeList*
geary_imap_folder_session_list_email_finish (GearyImapFolderSession* self,
                                             GAsyncResult* _res_,
                                             GError** error)
{
	GeeList* result;
	GearyImapFolderSessionListEmailAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static Block28Data*
block28_data_ref (Block28Data* _data28_)
{
	g_atomic_int_inc (&_data28_->_ref_count_);
	return _data28_;
}

static void
block28_data_unref (void * _userdata_)
{
	Block28Data* _data28_;
	_data28_ = (Block28Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data28_->_ref_count_)) {
		GearyImapFolderSession* self;
		self = _data28_->self;
		_g_object_unref0 (_data28_->email_list);
		_g_object_unref0 (_data28_->preview_charset_specifier);
		_g_object_unref0 (_data28_->preview_specifier);
		_g_object_unref0 (_data28_->body_specifier);
		_data28_->header_specifiers = (_vala_array_free (_data28_->header_specifiers, _data28_->header_specifiers_length1, (GDestroyNotify) g_object_unref), NULL);
		_g_object_unref0 (_data28_->fetched);
		_g_object_unref0 (self);
		g_slice_free (Block28Data, _data28_);
	}
}

static void
geary_imap_folder_session_list_email_async_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_)
{
	GearyImapFolderSessionListEmailAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_folder_session_list_email_async_co (_data_);
}

static void
__lambda104_ (Block28Data* _data28_,
              GError** error)
{
	GearyImapFolderSession* self;
	GError* _inner_error0_ = NULL;
	self = _data28_->self;
	{
		GeeIterator* _seq_num_it = NULL;
		GeeHashMap* _tmp0_;
		GeeSet* _tmp1_;
		GeeSet* _tmp2_;
		GeeSet* _tmp3_;
		GeeIterator* _tmp4_;
		GeeIterator* _tmp5_;
		_tmp0_ = _data28_->fetched;
		_tmp1_ = gee_abstract_map_get_keys (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap));
		_tmp2_ = _tmp1_;
		_tmp3_ = _tmp2_;
		_tmp4_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, GEE_TYPE_ITERABLE, GeeIterable));
		_tmp5_ = _tmp4_;
		_g_object_unref0 (_tmp3_);
		_seq_num_it = _tmp5_;
		while (TRUE) {
			GeeIterator* _tmp6_;
			GearyImapSequenceNumber* seq_num = NULL;
			GeeIterator* _tmp7_;
			gpointer _tmp8_;
			GearyImapFetchedData* fetched_data = NULL;
			GeeHashMap* _tmp9_;
			GearyImapSequenceNumber* _tmp10_;
			gpointer _tmp11_;
			GearyImapUID* uid = NULL;
			GearyImapFetchedData* _tmp12_;
			GeeMap* _tmp13_;
			GeeMap* _tmp14_;
			gpointer _tmp15_;
			GearyImapMessageData* _tmp16_;
			GearyImapUID* _tmp17_;
			GearyImapUID* _tmp18_;
			_tmp6_ = _seq_num_it;
			if (!gee_iterator_next (_tmp6_)) {
				break;
			}
			_tmp7_ = _seq_num_it;
			_tmp8_ = gee_iterator_get (_tmp7_);
			seq_num = (GearyImapSequenceNumber*) _tmp8_;
			_tmp9_ = _data28_->fetched;
			_tmp10_ = seq_num;
			_tmp11_ = gee_abstract_map_get (G_TYPE_CHECK_INSTANCE_CAST (_tmp9_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _tmp10_);
			fetched_data = (GearyImapFetchedData*) _tmp11_;
			_tmp12_ = fetched_data;
			_tmp13_ = geary_imap_fetched_data_get_data_map (_tmp12_);
			_tmp14_ = _tmp13_;
			_tmp15_ = gee_map_get (_tmp14_, (gpointer) ((gintptr) GEARY_IMAP_FETCH_DATA_SPECIFIER_UID));
			_tmp16_ = (GearyImapMessageData*) _tmp15_;
			_tmp17_ = GEARY_IMAP_IS_UID (_tmp16_) ? ((GearyImapUID*) _tmp16_) : NULL;
			if (_tmp17_ == NULL) {
				_g_object_unref0 (_tmp16_);
			}
			uid = _tmp17_;
			_tmp18_ = uid;
			if (_tmp18_ == NULL) {
				GearyImapSequenceNumber* _tmp19_;
				gchar* _tmp20_;
				gchar* _tmp21_;
				_tmp19_ = seq_num;
				_tmp20_ = geary_message_data_abstract_message_data_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp19_, GEARY_MESSAGE_DATA_TYPE_ABSTRACT_MESSAGE_DATA, GearyMessageDataAbstractMessageData));
				_tmp21_ = _tmp20_;
				geary_logging_source_message (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Unable to list message #%s: No UID returned from server", _tmp21_);
				_g_free0 (_tmp21_);
				_g_object_unref0 (uid);
				_g_object_unref0 (fetched_data);
				_g_object_unref0 (seq_num);
				continue;
			}
			{
				GearyEmail* email = NULL;
				GearyImapUID* _tmp22_;
				GearyImapFetchedData* _tmp23_;
				GearyImapFetchBodyDataSpecifier** _tmp24_;
				gint _tmp24__length1;
				GearyImapFetchBodyDataSpecifier* _tmp25_;
				GearyImapFetchBodyDataSpecifier* _tmp26_;
				GearyImapFetchBodyDataSpecifier* _tmp27_;
				GearyEmail* _tmp28_;
				GearyEmail* _tmp29_;
				GearyEmailField _tmp30_;
				GearyEmailField _tmp31_;
				GeeList* _tmp45_;
				GearyEmail* _tmp46_;
				_tmp22_ = uid;
				_tmp23_ = fetched_data;
				_tmp24_ = _data28_->header_specifiers;
				_tmp24__length1 = _data28_->header_specifiers_length1;
				_tmp25_ = _data28_->body_specifier;
				_tmp26_ = _data28_->preview_specifier;
				_tmp27_ = _data28_->preview_charset_specifier;
				_tmp28_ = geary_imap_folder_session_fetched_data_to_email (self, _tmp22_, _tmp23_, _data28_->fields, _tmp24_, (gint) _tmp24__length1, _tmp25_, _tmp26_, _tmp27_, &_inner_error0_);
				email = _tmp28_;
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					goto __catch0_g_error;
				}
				_tmp29_ = email;
				_tmp30_ = geary_email_get_fields (_tmp29_);
				_tmp31_ = _tmp30_;
				if (!geary_email_field_fulfills (_tmp31_, _data28_->fields)) {
					GearyEmail* _tmp32_;
					GearyEmailIdentifier* _tmp33_;
					GearyEmailIdentifier* _tmp34_;
					gchar* _tmp35_;
					gchar* _tmp36_;
					GearyEmail* _tmp37_;
					GearyEmailField _tmp38_;
					GearyEmailField _tmp39_;
					gchar* _tmp40_;
					gchar* _tmp41_;
					GearyImapFetchedData* _tmp42_;
					gchar* _tmp43_;
					gchar* _tmp44_;
					_tmp32_ = email;
					_tmp33_ = geary_email_get_id (_tmp32_);
					_tmp34_ = _tmp33_;
					_tmp35_ = geary_email_identifier_to_string (_tmp34_);
					_tmp36_ = _tmp35_;
					_tmp37_ = email;
					_tmp38_ = geary_email_get_fields (_tmp37_);
					_tmp39_ = _tmp38_;
					_tmp40_ = geary_email_field_to_string (geary_email_field_clear (_data28_->fields, _tmp39_));
					_tmp41_ = _tmp40_;
					_tmp42_ = fetched_data;
					_tmp43_ = geary_imap_fetched_data_to_string (_tmp42_);
					_tmp44_ = _tmp43_;
					geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "%s missing=%s fetched=%s", _tmp36_, _tmp41_, _tmp44_);
					_g_free0 (_tmp44_);
					_g_free0 (_tmp41_);
					_g_free0 (_tmp36_);
					_g_object_unref0 (email);
					_g_object_unref0 (uid);
					_g_object_unref0 (fetched_data);
					_g_object_unref0 (seq_num);
					continue;
				}
				_tmp45_ = _data28_->email_list;
				_tmp46_ = email;
				gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp45_, GEE_TYPE_COLLECTION, GeeCollection), _tmp46_);
				_g_object_unref0 (email);
			}
			goto __finally0;
			__catch0_g_error:
			{
				GError* err = NULL;
				GearyImapUID* _tmp47_;
				gchar* _tmp48_;
				gchar* _tmp49_;
				GearyImapFetchedData* _tmp50_;
				gchar* _tmp51_;
				gchar* _tmp52_;
				GError* _tmp53_;
				const gchar* _tmp54_;
				err = _inner_error0_;
				_inner_error0_ = NULL;
				_tmp47_ = uid;
				_tmp48_ = geary_message_data_abstract_message_data_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp47_, GEARY_MESSAGE_DATA_TYPE_ABSTRACT_MESSAGE_DATA, GearyMessageDataAbstractMessageData));
				_tmp49_ = _tmp48_;
				_tmp50_ = fetched_data;
				_tmp51_ = geary_imap_fetched_data_to_string (_tmp50_);
				_tmp52_ = _tmp51_;
				_tmp53_ = err;
				_tmp54_ = _tmp53_->message;
				geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Unable to convert email for %s %s: %s", _tmp49_, _tmp52_, _tmp54_);
				_g_free0 (_tmp52_);
				_g_free0 (_tmp49_);
				_g_error_free0 (err);
			}
			__finally0:
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (uid);
				_g_object_unref0 (fetched_data);
				_g_object_unref0 (seq_num);
				_g_object_unref0 (_seq_num_it);
				return;
			}
			_g_object_unref0 (uid);
			_g_object_unref0 (fetched_data);
			_g_object_unref0 (seq_num);
		}
		_g_object_unref0 (_seq_num_it);
	}
}

static void
___lambda104__geary_nonblocking_concurrent_concurrent_callback (GCancellable* cancellable,
                                                                gpointer self,
                                                                GError** error)
{
	__lambda104_ (self, error);
}

static gboolean
geary_imap_folder_session_list_email_async_co (GearyImapFolderSessionListEmailAsyncData* _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_->_data28_ = g_slice_new0 (Block28Data);
	_data_->_data28_->_ref_count_ = 1;
	_data_->_data28_->self = g_object_ref (_data_->self);
	_data_->_data28_->fields = _data_->fields;
	_data_->_data28_->_async_data_ = _data_;
	_data_->_tmp0_ = gee_hash_map_new (GEARY_IMAP_TYPE_SEQUENCE_NUMBER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEARY_IMAP_TYPE_FETCHED_DATA, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->_data28_->fetched = _data_->_tmp0_;
	_data_->_data28_->header_specifiers = NULL;
	_data_->_data28_->header_specifiers_length1 = 0;
	_data_->_data28_->_header_specifiers_size_ = _data_->_data28_->header_specifiers_length1;
	_data_->_data28_->body_specifier = NULL;
	_data_->_data28_->preview_specifier = NULL;
	_data_->_data28_->preview_charset_specifier = NULL;
	_data_->success = FALSE;
	while (TRUE) {
		if (!(!_data_->success)) {
			break;
		}
		_data_->_tmp1_ = NULL;
		_data_->_tmp2_ = 0;
		_data_->_tmp3_ = NULL;
		_data_->_tmp4_ = NULL;
		_data_->_tmp5_ = NULL;
		_data_->_tmp6_ = geary_imap_folder_session_assemble_list_commands (_data_->self, _data_->msg_set, _data_->_data28_->fields, _data_->cancellable, &_data_->_tmp1_, &_data_->_tmp2_, &_data_->_tmp3_, &_data_->_tmp4_, &_data_->_tmp5_);
		_data_->_data28_->header_specifiers = (_vala_array_free (_data_->_data28_->header_specifiers, _data_->_data28_->header_specifiers_length1, (GDestroyNotify) g_object_unref), NULL);
		_data_->_data28_->header_specifiers = _data_->_tmp1_;
		_data_->_data28_->header_specifiers_length1 = _data_->_tmp2_;
		_data_->_data28_->_header_specifiers_size_ = _data_->_data28_->header_specifiers_length1;
		_g_object_unref0 (_data_->_data28_->body_specifier);
		_data_->_data28_->body_specifier = _data_->_tmp3_;
		_g_object_unref0 (_data_->_data28_->preview_specifier);
		_data_->_data28_->preview_specifier = _data_->_tmp4_;
		_g_object_unref0 (_data_->_data28_->preview_charset_specifier);
		_data_->_data28_->preview_charset_specifier = _data_->_tmp5_;
		_data_->cmds = _data_->_tmp6_;
		_data_->_tmp7_ = _data_->cmds;
		_data_->_tmp8_ = gee_collection_get_size (_data_->_tmp7_);
		_data_->_tmp9_ = _data_->_tmp8_;
		if (_data_->_tmp9_ == 0) {
			_data_->_tmp10_ = geary_imap_message_set_to_string (_data_->msg_set);
			_data_->_tmp11_ = _data_->_tmp10_;
			_data_->_tmp12_ = geary_email_field_to_string (_data_->_data28_->fields);
			_data_->_tmp13_ = _data_->_tmp12_;
			_data_->_tmp14_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_INVALID, "No FETCH commands generate for list request %s %s", _data_->_tmp11_, _data_->_tmp13_);
			_data_->_tmp15_ = _data_->_tmp14_;
			_g_free0 (_data_->_tmp13_);
			_g_free0 (_data_->_tmp11_);
			_data_->_inner_error0_ = _data_->_tmp15_;
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->cmds);
			block28_data_unref (_data_->_data28_);
			_data_->_data28_ = NULL;
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		{
			_data_->_tmp16_ = _data_->cmds;
			_data_->_tmp17_ = _data_->_data28_->fetched;
			_data_->_state_ = 1;
			geary_imap_folder_session_exec_commands_async (_data_->self, _data_->_tmp16_, _data_->_tmp17_, NULL, _data_->cancellable, geary_imap_folder_session_list_email_async_ready, _data_);
			return FALSE;
			_state_1:
			_data_->_tmp18_ = geary_imap_folder_session_exec_commands_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
			_data_->_tmp19_ = _data_->_tmp18_;
			_g_object_unref0 (_data_->_tmp19_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				if (g_error_matches (_data_->_inner_error0_, GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_SERVER_ERROR)) {
					goto __catch0_geary_imap_error_server_error;
				}
				goto __finally0;
			}
			_data_->success = TRUE;
		}
		goto __finally0;
		__catch0_geary_imap_error_server_error:
		{
			_data_->err = _data_->_inner_error0_;
			_data_->_inner_error0_ = NULL;
			_data_->_tmp20_ = _data_->cmds;
			if (geary_imap_folder_session_retry_bad_header_fields_response (_data_->self, _data_->_tmp20_)) {
				_data_->_tmp21_ = _data_->err;
				_data_->_tmp22_ = _data_->_tmp21_->message;
				geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Retryable server failure detected: %s", _data_->_tmp22_);
			} else {
				_data_->_tmp23_ = _data_->err;
				_data_->_tmp24_ = _g_error_copy0 (_data_->_tmp23_);
				_data_->_inner_error0_ = _data_->_tmp24_;
				_g_error_free0 (_data_->err);
				goto __finally0;
			}
			_g_error_free0 (_data_->err);
		}
		__finally0:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->cmds);
			block28_data_unref (_data_->_data28_);
			_data_->_data28_ = NULL;
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_g_object_unref0 (_data_->cmds);
	}
	_data_->_tmp25_ = _data_->_data28_->fetched;
	_data_->_tmp26_ = gee_abstract_map_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp25_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap));
	_data_->_tmp27_ = _data_->_tmp26_;
	if (_data_->_tmp27_ == 0) {
		_data_->result = NULL;
		block28_data_unref (_data_->_data28_);
		_data_->_data28_ = 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;
	}
	_data_->_tmp28_ = gee_array_list_new (GEARY_TYPE_EMAIL, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data_->_data28_->email_list = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp28_, GEE_TYPE_LIST, GeeList);
	_data_->_tmp29_ = geary_nonblocking_concurrent_get_global ();
	_data_->_tmp30_ = _data_->_tmp29_;
	_data_->_state_ = 2;
	geary_nonblocking_concurrent_schedule_async (_data_->_tmp30_, ___lambda104__geary_nonblocking_concurrent_concurrent_callback, _data_->_data28_, _data_->cancellable, geary_imap_folder_session_list_email_async_ready, _data_);
	return FALSE;
	_state_2:
	geary_nonblocking_concurrent_schedule_finish (_data_->_tmp30_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block28_data_unref (_data_->_data28_);
		_data_->_data28_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp32_ = _data_->_data28_->email_list;
	_data_->_tmp33_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp32_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp34_ = _data_->_tmp33_;
	if (_data_->_tmp34_ > 0) {
		_data_->_tmp35_ = _data_->_data28_->email_list;
		_data_->_tmp31_ = _data_->_tmp35_;
	} else {
		_data_->_tmp31_ = NULL;
	}
	_data_->_tmp36_ = _g_object_ref0 (_data_->_tmp31_);
	_data_->result = _data_->_tmp36_;
	block28_data_unref (_data_->_data28_);
	_data_->_data28_ = 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
geary_imap_folder_session_uid_to_position_async_data_free (gpointer _data)
{
	GearyImapFolderSessionUidToPositionAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->msg_set);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapFolderSessionUidToPositionAsyncData, _data_);
}

void
geary_imap_folder_session_uid_to_position_async (GearyImapFolderSession* self,
                                                 GearyImapMessageSet* msg_set,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_)
{
	GearyImapFolderSessionUidToPositionAsyncData* _data_;
	GearyImapFolderSession* _tmp0_;
	GearyImapMessageSet* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	g_return_if_fail (GEARY_IMAP_IS_MESSAGE_SET (msg_set));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapFolderSessionUidToPositionAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_folder_session_uid_to_position_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (msg_set);
	_g_object_unref0 (_data_->msg_set);
	_data_->msg_set = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_folder_session_uid_to_position_async_co (_data_);
}

GeeMap*
geary_imap_folder_session_uid_to_position_finish (GearyImapFolderSession* self,
                                                  GAsyncResult* _res_,
                                                  GError** error)
{
	GeeMap* result;
	GearyImapFolderSessionUidToPositionAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

/**
     * Returns the sequence numbers for a set of UIDs.
     *
     * The `msg_set` parameter must be a set containing UIDs. An error
     * is thrown if the sequence numbers cannot be determined.
     */
static void
geary_imap_folder_session_uid_to_position_async_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_)
{
	GearyImapFolderSessionUidToPositionAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_folder_session_uid_to_position_async_co (_data_);
}

static gboolean
geary_imap_folder_session_uid_to_position_async_co (GearyImapFolderSessionUidToPositionAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = geary_imap_message_set_get_is_uid (_data_->msg_set);
	_data_->_tmp1_ = _data_->_tmp0_;
	if (!_data_->_tmp1_) {
		_data_->_tmp2_ = g_error_new_literal (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_NOT_SUPPORTED, "Message set must contain UIDs");
		_data_->_inner_error0_ = _data_->_tmp2_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp3_ = gee_array_list_new (GEARY_IMAP_TYPE_COMMAND, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data_->cmds = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp3_, GEE_TYPE_LIST, GeeList);
	_data_->_tmp4_ = _data_->cmds;
	_data_->_tmp5_ = geary_imap_fetch_command_new_data_type (_data_->msg_set, GEARY_IMAP_FETCH_DATA_SPECIFIER_UID, _data_->cancellable);
	_data_->_tmp6_ = _data_->_tmp5_;
	gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp4_, GEE_TYPE_COLLECTION, GeeCollection), G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp6_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand));
	_g_object_unref0 (_data_->_tmp6_);
	_data_->_tmp7_ = gee_hash_map_new (GEARY_IMAP_TYPE_SEQUENCE_NUMBER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEARY_IMAP_TYPE_FETCHED_DATA, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->fetched = _data_->_tmp7_;
	_data_->_tmp8_ = _data_->cmds;
	_data_->_tmp9_ = _data_->fetched;
	_data_->_state_ = 1;
	geary_imap_folder_session_exec_commands_async (_data_->self, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp8_, GEE_TYPE_COLLECTION, GeeCollection), _data_->_tmp9_, NULL, _data_->cancellable, geary_imap_folder_session_uid_to_position_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp10_ = geary_imap_folder_session_exec_commands_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp11_ = _data_->_tmp10_;
	_g_object_unref0 (_data_->_tmp11_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->fetched);
		_g_object_unref0 (_data_->cmds);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp12_ = _data_->fetched;
	_data_->_tmp13_ = gee_map_get_is_empty (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp12_, GEE_TYPE_MAP, GeeMap));
	_data_->_tmp14_ = _data_->_tmp13_;
	if (_data_->_tmp14_) {
		_data_->_tmp15_ = g_error_new_literal (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_INVALID, "Server returned no sequence numbers");
		_data_->_inner_error0_ = _data_->_tmp15_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->fetched);
		_g_object_unref0 (_data_->cmds);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp16_ = gee_hash_map_new (GEARY_IMAP_TYPE_UID, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEARY_IMAP_TYPE_SEQUENCE_NUMBER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->map = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp16_, GEE_TYPE_MAP, GeeMap);
	{
		_data_->_tmp17_ = _data_->fetched;
		_data_->_tmp18_ = gee_abstract_map_get_keys (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp17_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap));
		_data_->_tmp19_ = _data_->_tmp18_;
		_data_->_tmp20_ = _data_->_tmp19_;
		_data_->_tmp21_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp20_, GEE_TYPE_ITERABLE, GeeIterable));
		_data_->_tmp22_ = _data_->_tmp21_;
		_g_object_unref0 (_data_->_tmp20_);
		_data_->_seq_num_it = _data_->_tmp22_;
		while (TRUE) {
			_data_->_tmp23_ = _data_->_seq_num_it;
			if (!gee_iterator_next (_data_->_tmp23_)) {
				break;
			}
			_data_->_tmp24_ = _data_->_seq_num_it;
			_data_->_tmp25_ = gee_iterator_get (_data_->_tmp24_);
			_data_->seq_num = (GearyImapSequenceNumber*) _data_->_tmp25_;
			_data_->_tmp26_ = _data_->map;
			_data_->_tmp27_ = _data_->fetched;
			_data_->_tmp28_ = _data_->seq_num;
			_data_->_tmp29_ = gee_abstract_map_get (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp27_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _data_->_tmp28_);
			_data_->_tmp30_ = (GearyImapFetchedData*) _data_->_tmp29_;
			_data_->_tmp31_ = geary_imap_fetched_data_get_data_map (_data_->_tmp30_);
			_data_->_tmp32_ = _data_->_tmp31_;
			_data_->_tmp33_ = gee_map_get (_data_->_tmp32_, (gpointer) ((gintptr) GEARY_IMAP_FETCH_DATA_SPECIFIER_UID));
			_data_->_tmp34_ = G_TYPE_CHECK_INSTANCE_CAST ((GearyImapMessageData*) _data_->_tmp33_, GEARY_IMAP_TYPE_UID, GearyImapUID);
			_data_->_tmp35_ = _data_->seq_num;
			gee_map_set (_data_->_tmp26_, _data_->_tmp34_, _data_->_tmp35_);
			_g_object_unref0 (_data_->_tmp34_);
			_g_object_unref0 (_data_->_tmp30_);
			_g_object_unref0 (_data_->seq_num);
		}
		_g_object_unref0 (_data_->_seq_num_it);
	}
	_data_->result = _data_->map;
	_g_object_unref0 (_data_->fetched);
	_g_object_unref0 (_data_->cmds);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_folder_session_remove_email_async_data_free (gpointer _data)
{
	GearyImapFolderSessionRemoveEmailAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->msg_sets);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapFolderSessionRemoveEmailAsyncData, _data_);
}

void
geary_imap_folder_session_remove_email_async (GearyImapFolderSession* self,
                                              GeeList* msg_sets,
                                              GCancellable* cancellable,
                                              GAsyncReadyCallback _callback_,
                                              gpointer _user_data_)
{
	GearyImapFolderSessionRemoveEmailAsyncData* _data_;
	GearyImapFolderSession* _tmp0_;
	GeeList* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (msg_sets, GEE_TYPE_LIST));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapFolderSessionRemoveEmailAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_folder_session_remove_email_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (msg_sets);
	_g_object_unref0 (_data_->msg_sets);
	_data_->msg_sets = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_folder_session_remove_email_async_co (_data_);
}

void
geary_imap_folder_session_remove_email_finish (GearyImapFolderSession* self,
                                               GAsyncResult* _res_,
                                               GError** error)
{
	GearyImapFolderSessionRemoveEmailAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
geary_imap_folder_session_remove_email_async_ready (GObject* source_object,
                                                    GAsyncResult* _res_,
                                                    gpointer _user_data_)
{
	GearyImapFolderSessionRemoveEmailAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_folder_session_remove_email_async_co (_data_);
}

static gboolean
geary_imap_folder_session_remove_email_async_co (GearyImapFolderSessionRemoveEmailAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = geary_imap_session_object_get_session (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_TYPE_SESSION_OBJECT, GearyImapSessionObject), &_data_->_inner_error0_);
	_data_->session = _data_->_tmp0_;
	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_->_tmp1_ = gee_array_list_new (GEARY_IMAP_TYPE_MESSAGE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data_->flags = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, GEE_TYPE_LIST, GeeList);
	_data_->_tmp2_ = _data_->flags;
	_data_->_tmp3_ = geary_imap_message_flag_get_DELETED ();
	_data_->_tmp4_ = _data_->_tmp3_;
	gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, GEE_TYPE_COLLECTION, GeeCollection), _data_->_tmp4_);
	_data_->_tmp5_ = gee_array_list_new (GEARY_IMAP_TYPE_COMMAND, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data_->cmds = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp5_, GEE_TYPE_LIST, GeeList);
	_data_->all_uid = TRUE;
	{
		_data_->_msg_set_list = _data_->msg_sets;
		_data_->_tmp6_ = _data_->_msg_set_list;
		_data_->_tmp7_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp6_, GEE_TYPE_COLLECTION, GeeCollection));
		_data_->_tmp8_ = _data_->_tmp7_;
		_data_->_msg_set_size = _data_->_tmp8_;
		_data_->_msg_set_index = -1;
		while (TRUE) {
			_data_->_msg_set_index = _data_->_msg_set_index + 1;
			_data_->_tmp9_ = _data_->_msg_set_index;
			_data_->_tmp10_ = _data_->_msg_set_size;
			if (!(_data_->_tmp9_ < _data_->_tmp10_)) {
				break;
			}
			_data_->_tmp11_ = _data_->_msg_set_list;
			_data_->_tmp12_ = gee_list_get (_data_->_tmp11_, _data_->_msg_set_index);
			_data_->msg_set = (GearyImapMessageSet*) _data_->_tmp12_;
			_data_->_tmp13_ = _data_->msg_set;
			_data_->_tmp14_ = geary_imap_message_set_get_is_uid (_data_->_tmp13_);
			_data_->_tmp15_ = _data_->_tmp14_;
			if (!_data_->_tmp15_) {
				_data_->all_uid = FALSE;
			}
			_data_->_tmp16_ = _data_->cmds;
			_data_->_tmp17_ = _data_->msg_set;
			_data_->_tmp18_ = _data_->flags;
			_data_->_tmp19_ = geary_imap_store_command_new (_data_->_tmp17_, GEARY_IMAP_STORE_COMMAND_MODE_ADD_FLAGS, GEARY_IMAP_STORE_COMMAND_OPTIONS_SILENT, _data_->_tmp18_, _data_->cancellable);
			_data_->_tmp20_ = _data_->_tmp19_;
			gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp16_, GEE_TYPE_COLLECTION, GeeCollection), G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp20_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand));
			_g_object_unref0 (_data_->_tmp20_);
			_g_object_unref0 (_data_->msg_set);
		}
	}
	if (_data_->all_uid) {
		_data_->_tmp22_ = _data_->session;
		_data_->_tmp23_ = geary_imap_client_session_get_capabilities (_data_->_tmp22_);
		_data_->_tmp24_ = _data_->_tmp23_;
		_data_->_tmp21_ = geary_imap_capabilities_supports_uidplus (_data_->_tmp24_);
	} else {
		_data_->_tmp21_ = FALSE;
	}
	if (_data_->_tmp21_) {
		{
			_data_->_vala1__msg_set_list = _data_->msg_sets;
			_data_->_tmp25_ = _data_->_vala1__msg_set_list;
			_data_->_tmp26_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp25_, GEE_TYPE_COLLECTION, GeeCollection));
			_data_->_tmp27_ = _data_->_tmp26_;
			_data_->_vala1__msg_set_size = _data_->_tmp27_;
			_data_->_vala1__msg_set_index = -1;
			while (TRUE) {
				_data_->_vala1__msg_set_index = _data_->_vala1__msg_set_index + 1;
				_data_->_tmp28_ = _data_->_vala1__msg_set_index;
				_data_->_tmp29_ = _data_->_vala1__msg_set_size;
				if (!(_data_->_tmp28_ < _data_->_tmp29_)) {
					break;
				}
				_data_->_tmp30_ = _data_->_vala1__msg_set_list;
				_data_->_tmp31_ = gee_list_get (_data_->_tmp30_, _data_->_vala1__msg_set_index);
				_data_->_vala1_msg_set = (GearyImapMessageSet*) _data_->_tmp31_;
				_data_->_tmp32_ = _data_->cmds;
				_data_->_tmp33_ = _data_->_vala1_msg_set;
				_data_->_tmp34_ = geary_imap_expunge_command_new_uid (_data_->_tmp33_, _data_->cancellable);
				_data_->_tmp35_ = _data_->_tmp34_;
				gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp32_, GEE_TYPE_COLLECTION, GeeCollection), G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp35_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand));
				_g_object_unref0 (_data_->_tmp35_);
				_g_object_unref0 (_data_->_vala1_msg_set);
			}
		}
	} else {
		_data_->_tmp36_ = _data_->cmds;
		_data_->_tmp37_ = geary_imap_expunge_command_new (_data_->cancellable);
		_data_->_tmp38_ = _data_->_tmp37_;
		gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp36_, GEE_TYPE_COLLECTION, GeeCollection), G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp38_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand));
		_g_object_unref0 (_data_->_tmp38_);
	}
	_data_->_tmp39_ = _data_->cmds;
	_data_->_state_ = 1;
	geary_imap_folder_session_exec_commands_async (_data_->self, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp39_, GEE_TYPE_COLLECTION, GeeCollection), NULL, NULL, _data_->cancellable, geary_imap_folder_session_remove_email_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp40_ = geary_imap_folder_session_exec_commands_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp41_ = _data_->_tmp40_;
	_g_object_unref0 (_data_->_tmp41_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->cmds);
		_g_object_unref0 (_data_->flags);
		_g_object_unref0 (_data_->session);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_object_unref0 (_data_->cmds);
	_g_object_unref0 (_data_->flags);
	_g_object_unref0 (_data_->session);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_folder_session_mark_email_async_data_free (gpointer _data)
{
	GearyImapFolderSessionMarkEmailAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->msg_sets);
	_g_object_unref0 (_data_->flags_to_add);
	_g_object_unref0 (_data_->flags_to_remove);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapFolderSessionMarkEmailAsyncData, _data_);
}

void
geary_imap_folder_session_mark_email_async (GearyImapFolderSession* self,
                                            GeeList* msg_sets,
                                            GearyEmailFlags* flags_to_add,
                                            GearyEmailFlags* flags_to_remove,
                                            GCancellable* cancellable,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_)
{
	GearyImapFolderSessionMarkEmailAsyncData* _data_;
	GearyImapFolderSession* _tmp0_;
	GeeList* _tmp1_;
	GearyEmailFlags* _tmp2_;
	GearyEmailFlags* _tmp3_;
	GCancellable* _tmp4_;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (msg_sets, GEE_TYPE_LIST));
	g_return_if_fail ((flags_to_add == NULL) || GEARY_IS_EMAIL_FLAGS (flags_to_add));
	g_return_if_fail ((flags_to_remove == NULL) || GEARY_IS_EMAIL_FLAGS (flags_to_remove));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapFolderSessionMarkEmailAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_folder_session_mark_email_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (msg_sets);
	_g_object_unref0 (_data_->msg_sets);
	_data_->msg_sets = _tmp1_;
	_tmp2_ = _g_object_ref0 (flags_to_add);
	_g_object_unref0 (_data_->flags_to_add);
	_data_->flags_to_add = _tmp2_;
	_tmp3_ = _g_object_ref0 (flags_to_remove);
	_g_object_unref0 (_data_->flags_to_remove);
	_data_->flags_to_remove = _tmp3_;
	_tmp4_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp4_;
	geary_imap_folder_session_mark_email_async_co (_data_);
}

void
geary_imap_folder_session_mark_email_finish (GearyImapFolderSession* self,
                                             GAsyncResult* _res_,
                                             GError** error)
{
	GearyImapFolderSessionMarkEmailAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
geary_imap_folder_session_mark_email_async_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_)
{
	GearyImapFolderSessionMarkEmailAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_folder_session_mark_email_async_co (_data_);
}

static gboolean
geary_imap_folder_session_mark_email_async_co (GearyImapFolderSessionMarkEmailAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = gee_array_list_new (GEARY_IMAP_TYPE_MESSAGE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data_->msg_flags_add = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEE_TYPE_LIST, GeeList);
	_data_->_tmp1_ = gee_array_list_new (GEARY_IMAP_TYPE_MESSAGE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data_->msg_flags_remove = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, GEE_TYPE_LIST, GeeList);
	_data_->_tmp2_ = NULL;
	_data_->_tmp3_ = NULL;
	geary_imap_message_flag_from_email_flags (_data_->flags_to_add, _data_->flags_to_remove, &_data_->_tmp2_, &_data_->_tmp3_);
	_g_object_unref0 (_data_->msg_flags_add);
	_data_->msg_flags_add = _data_->_tmp2_;
	_g_object_unref0 (_data_->msg_flags_remove);
	_data_->msg_flags_remove = _data_->_tmp3_;
	_data_->_tmp5_ = _data_->msg_flags_add;
	_data_->_tmp6_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp5_, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp7_ = _data_->_tmp6_;
	if (_data_->_tmp7_ == 0) {
		_data_->_tmp8_ = _data_->msg_flags_remove;
		_data_->_tmp9_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp8_, GEE_TYPE_COLLECTION, GeeCollection));
		_data_->_tmp10_ = _data_->_tmp9_;
		_data_->_tmp4_ = _data_->_tmp10_ == 0;
	} else {
		_data_->_tmp4_ = FALSE;
	}
	if (_data_->_tmp4_) {
		_g_object_unref0 (_data_->msg_flags_remove);
		_g_object_unref0 (_data_->msg_flags_add);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp11_ = gee_array_list_new (GEARY_IMAP_TYPE_COMMAND, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data_->cmds = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp11_, GEE_TYPE_COLLECTION, GeeCollection);
	{
		_data_->_msg_set_list = _data_->msg_sets;
		_data_->_tmp12_ = _data_->_msg_set_list;
		_data_->_tmp13_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp12_, GEE_TYPE_COLLECTION, GeeCollection));
		_data_->_tmp14_ = _data_->_tmp13_;
		_data_->_msg_set_size = _data_->_tmp14_;
		_data_->_msg_set_index = -1;
		while (TRUE) {
			_data_->_msg_set_index = _data_->_msg_set_index + 1;
			_data_->_tmp15_ = _data_->_msg_set_index;
			_data_->_tmp16_ = _data_->_msg_set_size;
			if (!(_data_->_tmp15_ < _data_->_tmp16_)) {
				break;
			}
			_data_->_tmp17_ = _data_->_msg_set_list;
			_data_->_tmp18_ = gee_list_get (_data_->_tmp17_, _data_->_msg_set_index);
			_data_->msg_set = (GearyImapMessageSet*) _data_->_tmp18_;
			_data_->_tmp19_ = _data_->msg_flags_add;
			_data_->_tmp20_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp19_, GEE_TYPE_COLLECTION, GeeCollection));
			_data_->_tmp21_ = _data_->_tmp20_;
			if (_data_->_tmp21_ > 0) {
				_data_->_tmp22_ = _data_->cmds;
				_data_->_tmp23_ = _data_->msg_set;
				_data_->_tmp24_ = _data_->msg_flags_add;
				_data_->_tmp25_ = geary_imap_store_command_new (_data_->_tmp23_, GEARY_IMAP_STORE_COMMAND_MODE_ADD_FLAGS, GEARY_IMAP_STORE_COMMAND_OPTIONS_SILENT, _data_->_tmp24_, _data_->cancellable);
				_data_->_tmp26_ = _data_->_tmp25_;
				gee_collection_add (_data_->_tmp22_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp26_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand));
				_g_object_unref0 (_data_->_tmp26_);
			}
			_data_->_tmp27_ = _data_->msg_flags_remove;
			_data_->_tmp28_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp27_, GEE_TYPE_COLLECTION, GeeCollection));
			_data_->_tmp29_ = _data_->_tmp28_;
			if (_data_->_tmp29_ > 0) {
				_data_->_tmp30_ = _data_->cmds;
				_data_->_tmp31_ = _data_->msg_set;
				_data_->_tmp32_ = _data_->msg_flags_remove;
				_data_->_tmp33_ = geary_imap_store_command_new (_data_->_tmp31_, GEARY_IMAP_STORE_COMMAND_MODE_REMOVE_FLAGS, GEARY_IMAP_STORE_COMMAND_OPTIONS_SILENT, _data_->_tmp32_, _data_->cancellable);
				_data_->_tmp34_ = _data_->_tmp33_;
				gee_collection_add (_data_->_tmp30_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp34_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand));
				_g_object_unref0 (_data_->_tmp34_);
			}
			_g_object_unref0 (_data_->msg_set);
		}
	}
	_data_->_tmp35_ = _data_->cmds;
	_data_->_state_ = 1;
	geary_imap_folder_session_exec_commands_async (_data_->self, _data_->_tmp35_, NULL, NULL, _data_->cancellable, geary_imap_folder_session_mark_email_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp36_ = geary_imap_folder_session_exec_commands_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp37_ = _data_->_tmp36_;
	_g_object_unref0 (_data_->_tmp37_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->cmds);
		_g_object_unref0 (_data_->msg_flags_remove);
		_g_object_unref0 (_data_->msg_flags_add);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_object_unref0 (_data_->cmds);
	_g_object_unref0 (_data_->msg_flags_remove);
	_g_object_unref0 (_data_->msg_flags_add);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_folder_session_copy_email_async_data_free (gpointer _data)
{
	GearyImapFolderSessionCopyEmailAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->msg_set);
	_g_object_unref0 (_data_->destination);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapFolderSessionCopyEmailAsyncData, _data_);
}

void
geary_imap_folder_session_copy_email_async (GearyImapFolderSession* self,
                                            GearyImapMessageSet* msg_set,
                                            GearyFolderPath* destination,
                                            GCancellable* cancellable,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_)
{
	GearyImapFolderSessionCopyEmailAsyncData* _data_;
	GearyImapFolderSession* _tmp0_;
	GearyImapMessageSet* _tmp1_;
	GearyFolderPath* _tmp2_;
	GCancellable* _tmp3_;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	g_return_if_fail (GEARY_IMAP_IS_MESSAGE_SET (msg_set));
	g_return_if_fail (GEARY_IS_FOLDER_PATH (destination));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapFolderSessionCopyEmailAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_folder_session_copy_email_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (msg_set);
	_g_object_unref0 (_data_->msg_set);
	_data_->msg_set = _tmp1_;
	_tmp2_ = _g_object_ref0 (destination);
	_g_object_unref0 (_data_->destination);
	_data_->destination = _tmp2_;
	_tmp3_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp3_;
	geary_imap_folder_session_copy_email_async_co (_data_);
}

GeeMap*
geary_imap_folder_session_copy_email_finish (GearyImapFolderSession* self,
                                             GAsyncResult* _res_,
                                             GError** error)
{
	GeeMap* result;
	GearyImapFolderSessionCopyEmailAsyncData* _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
geary_imap_folder_session_copy_email_async_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_)
{
	GearyImapFolderSessionCopyEmailAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_folder_session_copy_email_async_co (_data_);
}

static gboolean
geary_imap_folder_session_copy_email_async_co (GearyImapFolderSessionCopyEmailAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = geary_imap_session_object_get_session (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_TYPE_SESSION_OBJECT, GearyImapSessionObject), &_data_->_inner_error0_);
	_data_->session = _data_->_tmp0_;
	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_->_tmp1_ = _data_->session;
	_data_->_tmp2_ = geary_imap_client_session_get_mailbox_for_path (_data_->_tmp1_, _data_->destination, &_data_->_inner_error0_);
	_data_->mailbox = _data_->_tmp2_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->session);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp3_ = _data_->mailbox;
	_data_->_tmp4_ = geary_imap_copy_command_new (_data_->msg_set, _data_->_tmp3_, _data_->cancellable);
	_data_->cmd = _data_->_tmp4_;
	_data_->_tmp5_ = _data_->cmd;
	_data_->_tmp6_ = geary_iterate (GEARY_IMAP_TYPE_COMMAND, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp5_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand), NULL);
	_data_->_tmp7_ = _data_->_tmp6_;
	_data_->_tmp8_ = geary_iterable_to_array_list (_data_->_tmp7_, NULL, NULL, NULL);
	_data_->_tmp9_ = _data_->_tmp8_;
	_data_->_state_ = 1;
	geary_imap_folder_session_exec_commands_async (_data_->self, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp9_, GEE_TYPE_COLLECTION, GeeCollection), NULL, NULL, _data_->cancellable, geary_imap_folder_session_copy_email_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp10_ = geary_imap_folder_session_exec_commands_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp11_ = _data_->_tmp10_;
	_g_object_unref0 (_data_->_tmp9_);
	_g_object_unref0 (_data_->_tmp7_);
	_data_->responses = _data_->_tmp11_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->cmd);
		_g_object_unref0 (_data_->mailbox);
		_g_object_unref0 (_data_->session);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp12_ = _data_->responses;
	_data_->_tmp13_ = _data_->cmd;
	if (!gee_map_has_key (_data_->_tmp12_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp13_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand))) {
		_data_->result = NULL;
		_g_object_unref0 (_data_->responses);
		_g_object_unref0 (_data_->cmd);
		_g_object_unref0 (_data_->mailbox);
		_g_object_unref0 (_data_->session);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp14_ = _data_->responses;
	_data_->_tmp15_ = _data_->cmd;
	_data_->_tmp16_ = gee_map_get (_data_->_tmp14_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp15_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand));
	_data_->response = (GearyImapStatusResponse*) _data_->_tmp16_;
	_data_->_tmp18_ = _data_->response;
	_data_->_tmp19_ = geary_imap_status_response_get_response_code (_data_->_tmp18_);
	_data_->_tmp20_ = _data_->_tmp19_;
	if (_data_->_tmp20_ != NULL) {
		_data_->_tmp21_ = geary_imap_message_set_get_is_uid (_data_->msg_set);
		_data_->_tmp22_ = _data_->_tmp21_;
		_data_->_tmp17_ = _data_->_tmp22_;
	} else {
		_data_->_tmp17_ = FALSE;
	}
	if (_data_->_tmp17_) {
		_data_->src_uids = NULL;
		_data_->dst_uids = NULL;
		{
			_data_->_tmp23_ = _data_->response;
			_data_->_tmp24_ = geary_imap_status_response_get_response_code (_data_->_tmp23_);
			_data_->_tmp25_ = _data_->_tmp24_;
			_data_->_tmp26_ = NULL;
			_data_->_tmp27_ = NULL;
			geary_imap_response_code_get_copyuid (_data_->_tmp25_, NULL, &_data_->_tmp26_, &_data_->_tmp27_, &_data_->_inner_error0_);
			_g_object_unref0 (_data_->src_uids);
			_data_->src_uids = _data_->_tmp26_;
			_g_object_unref0 (_data_->dst_uids);
			_data_->dst_uids = _data_->_tmp27_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				if (_data_->_inner_error0_->domain == GEARY_IMAP_ERROR) {
					goto __catch0_geary_imap_error;
				}
				_g_object_unref0 (_data_->dst_uids);
				_g_object_unref0 (_data_->src_uids);
				_g_object_unref0 (_data_->response);
				_g_object_unref0 (_data_->responses);
				_g_object_unref0 (_data_->cmd);
				_g_object_unref0 (_data_->mailbox);
				_g_object_unref0 (_data_->session);
				g_critical ("file %s: line %d: unexpected 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;
			}
		}
		goto __finally0;
		__catch0_geary_imap_error:
		{
			_data_->ierr = _data_->_inner_error0_;
			_data_->_inner_error0_ = NULL;
			_data_->_tmp28_ = _data_->ierr;
			_data_->_tmp29_ = _data_->_tmp28_->message;
			geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Unable to retrieve COPYUID UIDs: %s", _data_->_tmp29_);
			_g_error_free0 (_data_->ierr);
		}
		__finally0:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->dst_uids);
			_g_object_unref0 (_data_->src_uids);
			_g_object_unref0 (_data_->response);
			_g_object_unref0 (_data_->responses);
			_g_object_unref0 (_data_->cmd);
			_g_object_unref0 (_data_->mailbox);
			_g_object_unref0 (_data_->session);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp33_ = _data_->src_uids;
		if (_data_->_tmp33_ != NULL) {
			_data_->_tmp34_ = _data_->src_uids;
			_data_->_tmp35_ = gee_collection_get_is_empty (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp34_, GEE_TYPE_COLLECTION, GeeCollection));
			_data_->_tmp36_ = _data_->_tmp35_;
			_data_->_tmp32_ = !_data_->_tmp36_;
		} else {
			_data_->_tmp32_ = FALSE;
		}
		if (_data_->_tmp32_) {
			_data_->_tmp37_ = _data_->dst_uids;
			_data_->_tmp31_ = _data_->_tmp37_ != NULL;
		} else {
			_data_->_tmp31_ = FALSE;
		}
		if (_data_->_tmp31_) {
			_data_->_tmp38_ = _data_->dst_uids;
			_data_->_tmp39_ = gee_collection_get_is_empty (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp38_, GEE_TYPE_COLLECTION, GeeCollection));
			_data_->_tmp40_ = _data_->_tmp39_;
			_data_->_tmp30_ = !_data_->_tmp40_;
		} else {
			_data_->_tmp30_ = FALSE;
		}
		if (_data_->_tmp30_) {
			_data_->_tmp41_ = gee_hash_map_new (GEARY_IMAP_TYPE_UID, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEARY_IMAP_TYPE_UID, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
			_data_->copyuids = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp41_, GEE_TYPE_MAP, GeeMap);
			_data_->ctr = 0;
			{
				_data_->_tmp42_ = TRUE;
				while (TRUE) {
					if (!_data_->_tmp42_) {
					}
					_data_->_tmp42_ = FALSE;
					_data_->_tmp44_ = _data_->src_uids;
					_data_->_tmp45_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp44_, GEE_TYPE_COLLECTION, GeeCollection));
					_data_->_tmp46_ = _data_->_tmp45_;
					if (_data_->ctr < _data_->_tmp46_) {
						_data_->_tmp47_ = _data_->src_uids;
						_data_->_tmp48_ = gee_list_get (_data_->_tmp47_, _data_->ctr);
						_g_object_unref0 (_data_->_tmp43_);
						_data_->_tmp43_ = (GearyImapUID*) _data_->_tmp48_;
					} else {
						_g_object_unref0 (_data_->_tmp43_);
						_data_->_tmp43_ = NULL;
					}
					_data_->_tmp49_ = _data_->_tmp43_;
					_data_->_tmp43_ = NULL;
					_data_->src_uid = _data_->_tmp49_;
					_data_->_tmp51_ = _data_->dst_uids;
					_data_->_tmp52_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp51_, GEE_TYPE_COLLECTION, GeeCollection));
					_data_->_tmp53_ = _data_->_tmp52_;
					if (_data_->ctr < _data_->_tmp53_) {
						_data_->_tmp54_ = _data_->dst_uids;
						_data_->_tmp55_ = gee_list_get (_data_->_tmp54_, _data_->ctr);
						_g_object_unref0 (_data_->_tmp50_);
						_data_->_tmp50_ = (GearyImapUID*) _data_->_tmp55_;
					} else {
						_g_object_unref0 (_data_->_tmp50_);
						_data_->_tmp50_ = NULL;
					}
					_data_->_tmp56_ = _data_->_tmp50_;
					_data_->_tmp50_ = NULL;
					_data_->dst_uid = _data_->_tmp56_;
					_data_->_tmp58_ = _data_->src_uid;
					if (_data_->_tmp58_ != NULL) {
						_data_->_tmp59_ = _data_->dst_uid;
						_data_->_tmp57_ = _data_->_tmp59_ != NULL;
					} else {
						_data_->_tmp57_ = FALSE;
					}
					if (_data_->_tmp57_) {
						_data_->_tmp60_ = _data_->copyuids;
						_data_->_tmp61_ = _data_->src_uid;
						_data_->_tmp62_ = _data_->dst_uid;
						gee_map_set (_data_->_tmp60_, _data_->_tmp61_, _data_->_tmp62_);
					} else {
						_g_object_unref0 (_data_->dst_uid);
						_g_object_unref0 (_data_->_tmp50_);
						_g_object_unref0 (_data_->src_uid);
						_g_object_unref0 (_data_->_tmp43_);
						break;
					}
					_data_->_tmp63_ = _data_->ctr;
					_data_->ctr = _data_->_tmp63_ + 1;
					_g_object_unref0 (_data_->dst_uid);
					_g_object_unref0 (_data_->_tmp50_);
					_g_object_unref0 (_data_->src_uid);
					_g_object_unref0 (_data_->_tmp43_);
				}
			}
			_data_->_tmp64_ = _data_->copyuids;
			_data_->_tmp65_ = gee_map_get_size (_data_->_tmp64_);
			_data_->_tmp66_ = _data_->_tmp65_;
			if (_data_->_tmp66_ > 0) {
				_data_->result = _data_->copyuids;
				_g_object_unref0 (_data_->dst_uids);
				_g_object_unref0 (_data_->src_uids);
				_g_object_unref0 (_data_->response);
				_g_object_unref0 (_data_->responses);
				_g_object_unref0 (_data_->cmd);
				_g_object_unref0 (_data_->mailbox);
				_g_object_unref0 (_data_->session);
				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;
			}
			_g_object_unref0 (_data_->copyuids);
		}
		_g_object_unref0 (_data_->dst_uids);
		_g_object_unref0 (_data_->src_uids);
	}
	_data_->result = NULL;
	_g_object_unref0 (_data_->response);
	_g_object_unref0 (_data_->responses);
	_g_object_unref0 (_data_->cmd);
	_g_object_unref0 (_data_->mailbox);
	_g_object_unref0 (_data_->session);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_folder_session_search_async_data_free (gpointer _data)
{
	GearyImapFolderSessionSearchAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->criteria);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapFolderSessionSearchAsyncData, _data_);
}

void
geary_imap_folder_session_search_async (GearyImapFolderSession* self,
                                        GearyImapSearchCriteria* criteria,
                                        GCancellable* cancellable,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_)
{
	GearyImapFolderSessionSearchAsyncData* _data_;
	GearyImapFolderSession* _tmp0_;
	GearyImapSearchCriteria* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	g_return_if_fail (GEARY_IMAP_IS_SEARCH_CRITERIA (criteria));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapFolderSessionSearchAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_folder_session_search_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (criteria);
	_g_object_unref0 (_data_->criteria);
	_data_->criteria = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_folder_session_search_async_co (_data_);
}

GeeSortedSet*
geary_imap_folder_session_search_finish (GearyImapFolderSession* self,
                                         GAsyncResult* _res_,
                                         GError** error)
{
	GeeSortedSet* result;
	GearyImapFolderSessionSearchAsyncData* _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
geary_imap_folder_session_search_async_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_)
{
	GearyImapFolderSessionSearchAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_folder_session_search_async_co (_data_);
}

static gboolean
geary_imap_folder_session_search_async_co (GearyImapFolderSessionSearchAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = gee_array_list_new (GEARY_IMAP_TYPE_COMMAND, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data_->cmds = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEE_TYPE_COLLECTION, GeeCollection);
	_data_->_tmp1_ = geary_imap_search_command_new_uid (_data_->criteria, _data_->cancellable);
	_data_->_tmp2_ = _data_->_tmp1_;
	gee_collection_add (_data_->cmds, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand));
	_g_object_unref0 (_data_->_tmp2_);
	_data_->_tmp3_ = gee_hash_set_new (GEARY_IMAP_TYPE_UID, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->search_results = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp3_, GEE_TYPE_SET, GeeSet);
	_data_->_state_ = 1;
	geary_imap_folder_session_exec_commands_async (_data_->self, _data_->cmds, NULL, _data_->search_results, _data_->cancellable, geary_imap_folder_session_search_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp4_ = geary_imap_folder_session_exec_commands_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp5_ = _data_->_tmp4_;
	_g_object_unref0 (_data_->_tmp5_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->search_results);
		_g_object_unref0 (_data_->cmds);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->tree = NULL;
	_data_->_tmp6_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->search_results, GEE_TYPE_COLLECTION, GeeCollection));
	_data_->_tmp7_ = _data_->_tmp6_;
	if (_data_->_tmp7_ > 0) {
		_data_->_tmp8_ = gee_tree_set_new (GEARY_IMAP_TYPE_UID, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
		_g_object_unref0 (_data_->tree);
		_data_->tree = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp8_, GEE_TYPE_SORTED_SET, GeeSortedSet);
		_data_->_tmp9_ = _data_->tree;
		gee_collection_add_all (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp9_, GEE_TYPE_COLLECTION, GeeCollection), G_TYPE_CHECK_INSTANCE_CAST (_data_->search_results, GEE_TYPE_COLLECTION, GeeCollection));
	}
	_data_->result = _data_->tree;
	_g_object_unref0 (_data_->search_results);
	_g_object_unref0 (_data_->cmds);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_folder_session_fields_to_fetch_data_types (GearyImapFolderSession* self,
                                                      GearyEmailField fields,
                                                      GeeList* basic_types,
                                                      GeeList* header_fields)
{
	gint _tmp0_ = 0;
	GearyEmailField* _tmp1_;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (basic_types, GEE_TYPE_LIST));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (header_fields, GEE_TYPE_LIST));
	if (geary_email_field_is_all_set (fields, GEARY_EMAIL_FIELD_ENVELOPE)) {
		gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (basic_types, GEE_TYPE_COLLECTION, GeeCollection), (gpointer) ((gintptr) GEARY_IMAP_FETCH_DATA_SPECIFIER_ENVELOPE));
		gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (header_fields, GEE_TYPE_COLLECTION, GeeCollection), "References");
		fields = geary_email_field_clear (fields, GEARY_EMAIL_FIELD_ENVELOPE);
	}
	_tmp1_ = geary_email_field_all (&_tmp0_);
	{
		GearyEmailField* field_collection = NULL;
		gint field_collection_length1 = 0;
		gint _field_collection_size_ = 0;
		gint field_it = 0;
		field_collection = _tmp1_;
		field_collection_length1 = _tmp0_;
		for (field_it = 0; field_it < field_collection_length1; field_it = field_it + 1) {
			GearyEmailField field = 0;
			field = field_collection[field_it];
			{
				switch (fields & field) {
					case GEARY_EMAIL_FIELD_DATE:
					{
						gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (header_fields, GEE_TYPE_COLLECTION, GeeCollection), "Date");
						break;
					}
					case GEARY_EMAIL_FIELD_ORIGINATORS:
					{
						gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (header_fields, GEE_TYPE_COLLECTION, GeeCollection), "From");
						gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (header_fields, GEE_TYPE_COLLECTION, GeeCollection), "Sender");
						gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (header_fields, GEE_TYPE_COLLECTION, GeeCollection), "Reply-To");
						break;
					}
					case GEARY_EMAIL_FIELD_RECEIVERS:
					{
						gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (header_fields, GEE_TYPE_COLLECTION, GeeCollection), "To");
						gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (header_fields, GEE_TYPE_COLLECTION, GeeCollection), "Cc");
						gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (header_fields, GEE_TYPE_COLLECTION, GeeCollection), "Bcc");
						break;
					}
					case GEARY_EMAIL_FIELD_REFERENCES:
					{
						gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (header_fields, GEE_TYPE_COLLECTION, GeeCollection), "References");
						gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (header_fields, GEE_TYPE_COLLECTION, GeeCollection), "Message-ID");
						gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (header_fields, GEE_TYPE_COLLECTION, GeeCollection), "In-Reply-To");
						break;
					}
					case GEARY_EMAIL_FIELD_SUBJECT:
					{
						gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (header_fields, GEE_TYPE_COLLECTION, GeeCollection), "Subject");
						break;
					}
					case GEARY_EMAIL_FIELD_HEADER:
					{
						gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (basic_types, GEE_TYPE_COLLECTION, GeeCollection), (gpointer) ((gintptr) GEARY_IMAP_FETCH_DATA_SPECIFIER_RFC822_HEADER));
						break;
					}
					case GEARY_EMAIL_FIELD_NONE:
					case GEARY_EMAIL_FIELD_BODY:
					case GEARY_EMAIL_FIELD_PROPERTIES:
					case GEARY_EMAIL_FIELD_FLAGS:
					case GEARY_EMAIL_FIELD_PREVIEW:
					{
						break;
					}
					default:
					{
						g_assert_not_reached ();
					}
				}
			}
		}
		field_collection = (g_free (field_collection), NULL);
	}
}

static guint
_geary_string_stri_hash_gee_hash_data_func (gconstpointer v,
                                            gpointer self)
{
	guint result;
	result = geary_string_stri_hash ((const gchar*) v);
	return result;
}

static gboolean
_geary_string_stri_equal_gee_equal_data_func (gconstpointer a,
                                              gconstpointer b,
                                              gpointer self)
{
	gboolean result;
	result = geary_string_stri_equal ((const gchar*) a, (const gchar*) b);
	return result;
}

static GearyEmail*
geary_imap_folder_session_fetched_data_to_email (GearyImapFolderSession* self,
                                                 GearyImapUID* uid,
                                                 GearyImapFetchedData* fetched_data,
                                                 GearyEmailField required_fields,
                                                 GearyImapFetchBodyDataSpecifier** header_specifiers,
                                                 gint header_specifiers_length1,
                                                 GearyImapFetchBodyDataSpecifier* body_specifier,
                                                 GearyImapFetchBodyDataSpecifier* preview_specifier,
                                                 GearyImapFetchBodyDataSpecifier* preview_charset_specifier,
                                                 GError** error)
{
	GearyEmail* email = NULL;
	GearyImapDBEmailIdentifier* _tmp0_;
	GearyImapDBEmailIdentifier* _tmp1_;
	GearyEmail* _tmp2_;
	GearyEmail* _tmp3_;
	GearyImapInternalDate* internaldate = NULL;
	GearyImapRFC822Size* rfc822_size = NULL;
	GearyRFC822MessageID* message_id = NULL;
	GearyRFC822MessageIDList* in_reply_to = NULL;
	GearyRFC822MessageIDList* references = NULL;
	gboolean _tmp89_ = FALSE;
	GearyImapInternalDate* _tmp90_;
	GearyEmail* _tmp204_;
	gboolean _tmp209_ = FALSE;
	GError* _inner_error0_ = NULL;
	GearyEmail* result;
	g_return_val_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self), NULL);
	g_return_val_if_fail (GEARY_IMAP_IS_UID (uid), NULL);
	g_return_val_if_fail (GEARY_IMAP_IS_FETCHED_DATA (fetched_data), NULL);
	g_return_val_if_fail ((body_specifier == NULL) || GEARY_IMAP_IS_FETCH_BODY_DATA_SPECIFIER (body_specifier), NULL);
	g_return_val_if_fail ((preview_specifier == NULL) || GEARY_IMAP_IS_FETCH_BODY_DATA_SPECIFIER (preview_specifier), NULL);
	g_return_val_if_fail ((preview_charset_specifier == NULL) || GEARY_IMAP_IS_FETCH_BODY_DATA_SPECIFIER (preview_charset_specifier), NULL);
	_tmp0_ = geary_imap_db_email_identifier_new_no_message_id (uid);
	_tmp1_ = _tmp0_;
	_tmp2_ = geary_email_new (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEARY_TYPE_EMAIL_IDENTIFIER, GearyEmailIdentifier));
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp1_);
	email = _tmp3_;
	internaldate = NULL;
	rfc822_size = NULL;
	message_id = NULL;
	in_reply_to = NULL;
	references = NULL;
	{
		GeeIterator* _data_type_it = NULL;
		GeeMap* _tmp4_;
		GeeMap* _tmp5_;
		GeeSet* _tmp6_;
		GeeSet* _tmp7_;
		GeeSet* _tmp8_;
		GeeIterator* _tmp9_;
		GeeIterator* _tmp10_;
		_tmp4_ = geary_imap_fetched_data_get_data_map (fetched_data);
		_tmp5_ = _tmp4_;
		_tmp6_ = gee_map_get_keys (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = _tmp7_;
		_tmp9_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, GEE_TYPE_ITERABLE, GeeIterable));
		_tmp10_ = _tmp9_;
		_g_object_unref0 (_tmp8_);
		_data_type_it = _tmp10_;
		while (TRUE) {
			GeeIterator* _tmp11_;
			GearyImapFetchDataSpecifier data_type = 0;
			GeeIterator* _tmp12_;
			gpointer _tmp13_;
			GearyImapMessageData* data = NULL;
			GeeMap* _tmp14_;
			GeeMap* _tmp15_;
			gpointer _tmp16_;
			GearyImapMessageData* _tmp17_;
			_tmp11_ = _data_type_it;
			if (!gee_iterator_next (_tmp11_)) {
				break;
			}
			_tmp12_ = _data_type_it;
			_tmp13_ = gee_iterator_get (_tmp12_);
			data_type = (GearyImapFetchDataSpecifier) ((gintptr) _tmp13_);
			_tmp14_ = geary_imap_fetched_data_get_data_map (fetched_data);
			_tmp15_ = _tmp14_;
			_tmp16_ = gee_map_get (_tmp15_, (gpointer) ((gintptr) data_type));
			data = (GearyImapMessageData*) _tmp16_;
			_tmp17_ = data;
			if (_tmp17_ == NULL) {
				_g_object_unref0 (data);
				continue;
			}
			switch (data_type) {
				case GEARY_IMAP_FETCH_DATA_SPECIFIER_ENVELOPE:
				{
					GearyImapEnvelope* envelope = NULL;
					GearyImapMessageData* _tmp18_;
					GearyImapEnvelope* _tmp19_;
					GearyEmail* _tmp20_;
					GearyImapEnvelope* _tmp21_;
					GearyRFC822Date* _tmp22_;
					GearyRFC822Date* _tmp23_;
					GearyEmail* _tmp24_;
					GearyImapEnvelope* _tmp25_;
					GearyRFC822Subject* _tmp26_;
					GearyRFC822Subject* _tmp27_;
					GearyRFC822MailboxAddress* _tmp28_ = NULL;
					gboolean _tmp29_ = FALSE;
					GearyImapEnvelope* _tmp30_;
					GearyRFC822MailboxAddresses* _tmp31_;
					GearyRFC822MailboxAddresses* _tmp32_;
					GearyImapEnvelope* _tmp33_;
					GearyRFC822MailboxAddresses* _tmp34_;
					GearyRFC822MailboxAddresses* _tmp35_;
					GearyRFC822MailboxAddresses* _tmp45_ = NULL;
					GearyImapEnvelope* _tmp46_;
					GearyRFC822MailboxAddresses* _tmp47_;
					GearyRFC822MailboxAddresses* _tmp48_;
					GearyImapEnvelope* _tmp49_;
					GearyRFC822MailboxAddresses* _tmp50_;
					GearyRFC822MailboxAddresses* _tmp51_;
					GearyEmail* _tmp55_;
					GearyImapEnvelope* _tmp56_;
					GearyRFC822MailboxAddresses* _tmp57_;
					GearyRFC822MailboxAddresses* _tmp58_;
					GearyEmail* _tmp59_;
					GearyImapEnvelope* _tmp60_;
					GearyRFC822MailboxAddresses* _tmp61_;
					GearyRFC822MailboxAddresses* _tmp62_;
					GearyImapEnvelope* _tmp63_;
					GearyRFC822MailboxAddresses* _tmp64_;
					GearyRFC822MailboxAddresses* _tmp65_;
					GearyImapEnvelope* _tmp66_;
					GearyRFC822MailboxAddresses* _tmp67_;
					GearyRFC822MailboxAddresses* _tmp68_;
					GearyImapEnvelope* _tmp69_;
					GearyRFC822MessageID* _tmp70_;
					GearyRFC822MessageID* _tmp71_;
					GearyRFC822MessageID* _tmp72_;
					GearyImapEnvelope* _tmp73_;
					GearyRFC822MessageIDList* _tmp74_;
					GearyRFC822MessageIDList* _tmp75_;
					GearyRFC822MessageIDList* _tmp76_;
					_tmp18_ = data;
					_tmp19_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp18_, GEARY_IMAP_TYPE_ENVELOPE, GearyImapEnvelope));
					envelope = _tmp19_;
					_tmp20_ = email;
					_tmp21_ = envelope;
					_tmp22_ = geary_imap_envelope_get_sent (_tmp21_);
					_tmp23_ = _tmp22_;
					geary_email_set_send_date (_tmp20_, _tmp23_);
					_tmp24_ = email;
					_tmp25_ = envelope;
					_tmp26_ = geary_imap_envelope_get_subject (_tmp25_);
					_tmp27_ = _tmp26_;
					geary_email_set_message_subject (_tmp24_, _tmp27_);
					_tmp30_ = envelope;
					_tmp31_ = geary_imap_envelope_get_sender (_tmp30_);
					_tmp32_ = _tmp31_;
					_tmp33_ = envelope;
					_tmp34_ = geary_imap_envelope_get_from (_tmp33_);
					_tmp35_ = _tmp34_;
					if (gee_hashable_equal_to (G_TYPE_CHECK_INSTANCE_CAST (_tmp32_, GEE_TYPE_HASHABLE, GeeHashable), _tmp35_)) {
						_tmp29_ = TRUE;
					} else {
						GearyImapEnvelope* _tmp36_;
						GearyRFC822MailboxAddresses* _tmp37_;
						GearyRFC822MailboxAddresses* _tmp38_;
						gint _tmp39_;
						gint _tmp40_;
						_tmp36_ = envelope;
						_tmp37_ = geary_imap_envelope_get_sender (_tmp36_);
						_tmp38_ = _tmp37_;
						_tmp39_ = geary_rf_c822_mailbox_addresses_get_size (_tmp38_);
						_tmp40_ = _tmp39_;
						_tmp29_ = _tmp40_ == 0;
					}
					if (_tmp29_) {
						_g_object_unref0 (_tmp28_);
						_tmp28_ = NULL;
					} else {
						GearyImapEnvelope* _tmp41_;
						GearyRFC822MailboxAddresses* _tmp42_;
						GearyRFC822MailboxAddresses* _tmp43_;
						GearyRFC822MailboxAddress* _tmp44_;
						_tmp41_ = envelope;
						_tmp42_ = geary_imap_envelope_get_sender (_tmp41_);
						_tmp43_ = _tmp42_;
						_tmp44_ = geary_rf_c822_mailbox_addresses_get (_tmp43_, 0);
						_g_object_unref0 (_tmp28_);
						_tmp28_ = _tmp44_;
					}
					_tmp46_ = envelope;
					_tmp47_ = geary_imap_envelope_get_reply_to (_tmp46_);
					_tmp48_ = _tmp47_;
					_tmp49_ = envelope;
					_tmp50_ = geary_imap_envelope_get_from (_tmp49_);
					_tmp51_ = _tmp50_;
					if (gee_hashable_equal_to (G_TYPE_CHECK_INSTANCE_CAST (_tmp48_, GEE_TYPE_HASHABLE, GeeHashable), _tmp51_)) {
						_tmp45_ = NULL;
					} else {
						GearyImapEnvelope* _tmp52_;
						GearyRFC822MailboxAddresses* _tmp53_;
						GearyRFC822MailboxAddresses* _tmp54_;
						_tmp52_ = envelope;
						_tmp53_ = geary_imap_envelope_get_reply_to (_tmp52_);
						_tmp54_ = _tmp53_;
						_tmp45_ = _tmp54_;
					}
					_tmp55_ = email;
					_tmp56_ = envelope;
					_tmp57_ = geary_imap_envelope_get_from (_tmp56_);
					_tmp58_ = _tmp57_;
					geary_email_set_originators (_tmp55_, _tmp58_, _tmp28_, _tmp45_, &_inner_error0_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						g_propagate_error (error, _inner_error0_);
						_g_object_unref0 (_tmp28_);
						_g_object_unref0 (envelope);
						_g_object_unref0 (data);
						_g_object_unref0 (_data_type_it);
						_g_object_unref0 (references);
						_g_object_unref0 (in_reply_to);
						_g_object_unref0 (message_id);
						_g_object_unref0 (rfc822_size);
						_g_object_unref0 (internaldate);
						_g_object_unref0 (email);
						return NULL;
					}
					_tmp59_ = email;
					_tmp60_ = envelope;
					_tmp61_ = geary_imap_envelope_get_to (_tmp60_);
					_tmp62_ = _tmp61_;
					_tmp63_ = envelope;
					_tmp64_ = geary_imap_envelope_get_cc (_tmp63_);
					_tmp65_ = _tmp64_;
					_tmp66_ = envelope;
					_tmp67_ = geary_imap_envelope_get_bcc (_tmp66_);
					_tmp68_ = _tmp67_;
					geary_email_set_receivers (_tmp59_, _tmp62_, _tmp65_, _tmp68_);
					_tmp69_ = envelope;
					_tmp70_ = geary_imap_envelope_get_message_id (_tmp69_);
					_tmp71_ = _tmp70_;
					_tmp72_ = _g_object_ref0 (_tmp71_);
					_g_object_unref0 (message_id);
					message_id = _tmp72_;
					_tmp73_ = envelope;
					_tmp74_ = geary_imap_envelope_get_in_reply_to (_tmp73_);
					_tmp75_ = _tmp74_;
					_tmp76_ = _g_object_ref0 (_tmp75_);
					_g_object_unref0 (in_reply_to);
					in_reply_to = _tmp76_;
					_g_object_unref0 (_tmp28_);
					_g_object_unref0 (envelope);
					break;
				}
				case GEARY_IMAP_FETCH_DATA_SPECIFIER_RFC822_HEADER:
				{
					GearyEmail* _tmp77_;
					GearyImapMessageData* _tmp78_;
					_tmp77_ = email;
					_tmp78_ = data;
					geary_email_set_message_header (_tmp77_, G_TYPE_CHECK_INSTANCE_CAST (_tmp78_, GEARY_RF_C822_TYPE_HEADER, GearyRFC822Header));
					break;
				}
				case GEARY_IMAP_FETCH_DATA_SPECIFIER_RFC822_TEXT:
				{
					GearyEmail* _tmp79_;
					GearyImapMessageData* _tmp80_;
					_tmp79_ = email;
					_tmp80_ = data;
					geary_email_set_message_body (_tmp79_, G_TYPE_CHECK_INSTANCE_CAST (_tmp80_, GEARY_RF_C822_TYPE_TEXT, GearyRFC822Text));
					break;
				}
				case GEARY_IMAP_FETCH_DATA_SPECIFIER_RFC822_SIZE:
				{
					GearyImapMessageData* _tmp81_;
					GearyImapRFC822Size* _tmp82_;
					_tmp81_ = data;
					_tmp82_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp81_, GEARY_IMAP_TYPE_RF_C822_SIZE, GearyImapRFC822Size));
					_g_object_unref0 (rfc822_size);
					rfc822_size = _tmp82_;
					break;
				}
				case GEARY_IMAP_FETCH_DATA_SPECIFIER_FLAGS:
				{
					GearyEmail* _tmp83_;
					GearyImapMessageData* _tmp84_;
					GearyImapEmailFlags* _tmp85_;
					GearyImapEmailFlags* _tmp86_;
					_tmp83_ = email;
					_tmp84_ = data;
					_tmp85_ = geary_imap_email_flags_new (G_TYPE_CHECK_INSTANCE_CAST (_tmp84_, GEARY_IMAP_TYPE_MESSAGE_FLAGS, GearyImapMessageFlags));
					_tmp86_ = _tmp85_;
					geary_email_set_flags (_tmp83_, G_TYPE_CHECK_INSTANCE_CAST (_tmp86_, GEARY_TYPE_EMAIL_FLAGS, GearyEmailFlags));
					_g_object_unref0 (_tmp86_);
					break;
				}
				case GEARY_IMAP_FETCH_DATA_SPECIFIER_INTERNALDATE:
				{
					GearyImapMessageData* _tmp87_;
					GearyImapInternalDate* _tmp88_;
					_tmp87_ = data;
					_tmp88_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp87_, GEARY_IMAP_TYPE_INTERNAL_DATE, GearyImapInternalDate));
					_g_object_unref0 (internaldate);
					internaldate = _tmp88_;
					break;
				}
				default:
				{
					break;
				}
			}
			_g_object_unref0 (data);
		}
		_g_object_unref0 (_data_type_it);
	}
	_tmp90_ = internaldate;
	if (_tmp90_ != NULL) {
		GearyImapRFC822Size* _tmp91_;
		_tmp91_ = rfc822_size;
		_tmp89_ = _tmp91_ != NULL;
	} else {
		_tmp89_ = FALSE;
	}
	if (_tmp89_) {
		GearyEmail* _tmp92_;
		GearyImapInternalDate* _tmp93_;
		GearyImapRFC822Size* _tmp94_;
		GearyImapEmailProperties* _tmp95_;
		GearyImapEmailProperties* _tmp96_;
		_tmp92_ = email;
		_tmp93_ = internaldate;
		_tmp94_ = rfc822_size;
		_tmp95_ = geary_imap_email_properties_new (_tmp93_, _tmp94_);
		_tmp96_ = _tmp95_;
		geary_email_set_email_properties (_tmp92_, G_TYPE_CHECK_INSTANCE_CAST (_tmp96_, GEARY_TYPE_EMAIL_PROPERTIES, GearyEmailProperties));
		_g_object_unref0 (_tmp96_);
	}
	if (header_specifiers != NULL) {
		GeeMap* headers = NULL;
		GeeHashMap* _tmp97_;
		GearyEmail* _tmp132_;
		GearyEmail* _tmp139_;
		GearyEmail* _tmp164_;
		GearyRFC822MessageID* _tmp181_;
		GearyRFC822MessageIDList* _tmp186_;
		GearyRFC822MessageIDList* _tmp191_;
		GearyEmail* _tmp196_;
		_tmp97_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _geary_string_stri_hash_gee_hash_data_func, NULL, NULL, _geary_string_stri_equal_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
		headers = G_TYPE_CHECK_INSTANCE_CAST (_tmp97_, GEE_TYPE_MAP, GeeMap);
		{
			GearyImapFetchBodyDataSpecifier** header_specifier_collection = NULL;
			gint header_specifier_collection_length1 = 0;
			gint _header_specifier_collection_size_ = 0;
			gint header_specifier_it = 0;
			header_specifier_collection = header_specifiers;
			header_specifier_collection_length1 = header_specifiers_length1;
			for (header_specifier_it = 0; header_specifier_it < header_specifier_collection_length1; header_specifier_it = header_specifier_it + 1) {
				GearyImapFetchBodyDataSpecifier* _tmp98_;
				GearyImapFetchBodyDataSpecifier* header_specifier = NULL;
				_tmp98_ = _g_object_ref0 (header_specifier_collection[header_specifier_it]);
				header_specifier = _tmp98_;
				{
					GearyMemoryBuffer* fetched_headers = NULL;
					GeeMap* _tmp99_;
					GeeMap* _tmp100_;
					GearyImapFetchBodyDataSpecifier* _tmp101_;
					gpointer _tmp102_;
					GearyMemoryBuffer* _tmp103_;
					_tmp99_ = geary_imap_fetched_data_get_body_data_map (fetched_data);
					_tmp100_ = _tmp99_;
					_tmp101_ = header_specifier;
					_tmp102_ = gee_map_get (_tmp100_, _tmp101_);
					fetched_headers = (GearyMemoryBuffer*) _tmp102_;
					_tmp103_ = fetched_headers;
					if (_tmp103_ != NULL) {
						GearyRFC822Header* parsed_headers = NULL;
						GearyMemoryBuffer* _tmp104_;
						GearyRFC822Header* _tmp105_;
						GearyRFC822Header* _tmp106_;
						gint _tmp107_ = 0;
						gchar** _tmp108_;
						_tmp104_ = fetched_headers;
						_tmp105_ = geary_rf_c822_header_new (_tmp104_, &_inner_error0_);
						parsed_headers = _tmp105_;
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							g_propagate_error (error, _inner_error0_);
							_g_object_unref0 (fetched_headers);
							_g_object_unref0 (header_specifier);
							_g_object_unref0 (headers);
							_g_object_unref0 (references);
							_g_object_unref0 (in_reply_to);
							_g_object_unref0 (message_id);
							_g_object_unref0 (rfc822_size);
							_g_object_unref0 (internaldate);
							_g_object_unref0 (email);
							return NULL;
						}
						_tmp106_ = parsed_headers;
						_tmp108_ = geary_rf_c822_header_get_header_names (_tmp106_, &_tmp107_);
						{
							gchar** name_collection = NULL;
							gint name_collection_length1 = 0;
							gint _name_collection_size_ = 0;
							gint name_it = 0;
							name_collection = _tmp108_;
							name_collection_length1 = _tmp107_;
							for (name_it = 0; name_it < name_collection_length1; name_it = name_it + 1) {
								gchar* _tmp109_;
								gchar* name = NULL;
								_tmp109_ = g_strdup (name_collection[name_it]);
								name = _tmp109_;
								{
									GeeMap* _tmp110_;
									const gchar* _tmp111_;
									GearyRFC822Header* _tmp112_;
									const gchar* _tmp113_;
									gchar* _tmp114_;
									gchar* _tmp115_;
									_tmp110_ = headers;
									_tmp111_ = name;
									_tmp112_ = parsed_headers;
									_tmp113_ = name;
									_tmp114_ = geary_rf_c822_header_get_raw_header (_tmp112_, _tmp113_);
									_tmp115_ = _tmp114_;
									gee_map_set (_tmp110_, _tmp111_, _tmp115_);
									_g_free0 (_tmp115_);
									_g_free0 (name);
								}
							}
							name_collection = (_vala_array_free (name_collection, name_collection_length1, (GDestroyNotify) g_free), NULL);
						}
						_g_object_unref0 (parsed_headers);
					} else {
						GearyImapFetchBodyDataSpecifier* _tmp116_;
						gchar* _tmp117_;
						gchar* _tmp118_;
						_tmp116_ = header_specifier;
						_tmp117_ = geary_imap_fetch_body_data_specifier_to_string (_tmp116_);
						_tmp118_ = _tmp117_;
						geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "No header specifier \"%s\" found in response:", _tmp118_);
						_g_free0 (_tmp118_);
						{
							GeeIterator* _specifier_it = NULL;
							GeeMap* _tmp119_;
							GeeMap* _tmp120_;
							GeeSet* _tmp121_;
							GeeSet* _tmp122_;
							GeeSet* _tmp123_;
							GeeIterator* _tmp124_;
							GeeIterator* _tmp125_;
							_tmp119_ = geary_imap_fetched_data_get_body_data_map (fetched_data);
							_tmp120_ = _tmp119_;
							_tmp121_ = gee_map_get_keys (_tmp120_);
							_tmp122_ = _tmp121_;
							_tmp123_ = _tmp122_;
							_tmp124_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp123_, GEE_TYPE_ITERABLE, GeeIterable));
							_tmp125_ = _tmp124_;
							_g_object_unref0 (_tmp123_);
							_specifier_it = _tmp125_;
							while (TRUE) {
								GeeIterator* _tmp126_;
								GearyImapFetchBodyDataSpecifier* specifier = NULL;
								GeeIterator* _tmp127_;
								gpointer _tmp128_;
								GearyImapFetchBodyDataSpecifier* _tmp129_;
								gchar* _tmp130_;
								gchar* _tmp131_;
								_tmp126_ = _specifier_it;
								if (!gee_iterator_next (_tmp126_)) {
									break;
								}
								_tmp127_ = _specifier_it;
								_tmp128_ = gee_iterator_get (_tmp127_);
								specifier = (GearyImapFetchBodyDataSpecifier*) _tmp128_;
								_tmp129_ = specifier;
								_tmp130_ = geary_imap_fetch_body_data_specifier_to_string (_tmp129_);
								_tmp131_ = _tmp130_;
								geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), " - has %s", _tmp131_);
								_g_free0 (_tmp131_);
								_g_object_unref0 (specifier);
							}
							_g_object_unref0 (_specifier_it);
						}
					}
					_g_object_unref0 (fetched_headers);
					_g_object_unref0 (header_specifier);
				}
			}
		}
		_tmp132_ = email;
		if (geary_imap_folder_session_required_but_not_set (GEARY_EMAIL_FIELD_DATE, required_fields, _tmp132_)) {
			GearyEmail* _tmp133_;
			GeeMap* _tmp134_;
			gpointer _tmp135_;
			gchar* _tmp136_;
			GearyRFC822Date* _tmp137_;
			GearyRFC822Date* _tmp138_;
			_tmp133_ = email;
			_tmp134_ = headers;
			_tmp135_ = gee_map_get (_tmp134_, "Date");
			_tmp136_ = (gchar*) _tmp135_;
			_tmp137_ = geary_imap_folder_session_unflatten_date (self, _tmp136_);
			_tmp138_ = _tmp137_;
			geary_email_set_send_date (_tmp133_, _tmp138_);
			_g_object_unref0 (_tmp138_);
			_g_free0 (_tmp136_);
		}
		_tmp139_ = email;
		if (geary_imap_folder_session_required_but_not_set (GEARY_EMAIL_FIELD_ORIGINATORS, required_fields, _tmp139_)) {
			GearyRFC822MailboxAddresses* sender = NULL;
			GeeMap* _tmp140_;
			gpointer _tmp141_;
			gchar* _tmp142_;
			GearyRFC822MailboxAddresses* _tmp143_;
			GearyRFC822MailboxAddresses* _tmp144_;
			GearyRFC822MailboxAddress* _tmp145_ = NULL;
			gboolean _tmp146_ = FALSE;
			GearyRFC822MailboxAddresses* _tmp147_;
			GearyEmail* _tmp153_;
			GeeMap* _tmp154_;
			gpointer _tmp155_;
			gchar* _tmp156_;
			GearyRFC822MailboxAddresses* _tmp157_;
			GearyRFC822MailboxAddresses* _tmp158_;
			GeeMap* _tmp159_;
			gpointer _tmp160_;
			gchar* _tmp161_;
			GearyRFC822MailboxAddresses* _tmp162_;
			GearyRFC822MailboxAddresses* _tmp163_;
			_tmp140_ = headers;
			_tmp141_ = gee_map_get (_tmp140_, "Sender");
			_tmp142_ = (gchar*) _tmp141_;
			_tmp143_ = geary_imap_folder_session_unflatten_addresses (self, _tmp142_);
			_tmp144_ = _tmp143_;
			_g_free0 (_tmp142_);
			sender = _tmp144_;
			_tmp147_ = sender;
			if (_tmp147_ != NULL) {
				GearyRFC822MailboxAddresses* _tmp148_;
				gboolean _tmp149_;
				gboolean _tmp150_;
				_tmp148_ = sender;
				_tmp149_ = geary_rf_c822_mailbox_addresses_get_is_empty (_tmp148_);
				_tmp150_ = _tmp149_;
				_tmp146_ = !_tmp150_;
			} else {
				_tmp146_ = FALSE;
			}
			if (_tmp146_) {
				GearyRFC822MailboxAddresses* _tmp151_;
				GearyRFC822MailboxAddress* _tmp152_;
				_tmp151_ = sender;
				_tmp152_ = geary_rf_c822_mailbox_addresses_get (_tmp151_, 0);
				_g_object_unref0 (_tmp145_);
				_tmp145_ = _tmp152_;
			} else {
				_g_object_unref0 (_tmp145_);
				_tmp145_ = NULL;
			}
			_tmp153_ = email;
			_tmp154_ = headers;
			_tmp155_ = gee_map_get (_tmp154_, "From");
			_tmp156_ = (gchar*) _tmp155_;
			_tmp157_ = geary_imap_folder_session_unflatten_addresses (self, _tmp156_);
			_tmp158_ = _tmp157_;
			_tmp159_ = headers;
			_tmp160_ = gee_map_get (_tmp159_, "Reply-To");
			_tmp161_ = (gchar*) _tmp160_;
			_tmp162_ = geary_imap_folder_session_unflatten_addresses (self, _tmp161_);
			_tmp163_ = _tmp162_;
			geary_email_set_originators (_tmp153_, _tmp158_, _tmp145_, _tmp163_, &_inner_error0_);
			_g_object_unref0 (_tmp163_);
			_g_free0 (_tmp161_);
			_g_object_unref0 (_tmp158_);
			_g_free0 (_tmp156_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (_tmp145_);
				_g_object_unref0 (sender);
				_g_object_unref0 (headers);
				_g_object_unref0 (references);
				_g_object_unref0 (in_reply_to);
				_g_object_unref0 (message_id);
				_g_object_unref0 (rfc822_size);
				_g_object_unref0 (internaldate);
				_g_object_unref0 (email);
				return NULL;
			}
			_g_object_unref0 (_tmp145_);
			_g_object_unref0 (sender);
		}
		_tmp164_ = email;
		if (geary_imap_folder_session_required_but_not_set (GEARY_EMAIL_FIELD_RECEIVERS, required_fields, _tmp164_)) {
			GearyEmail* _tmp165_;
			GeeMap* _tmp166_;
			gpointer _tmp167_;
			gchar* _tmp168_;
			GearyRFC822MailboxAddresses* _tmp169_;
			GearyRFC822MailboxAddresses* _tmp170_;
			GeeMap* _tmp171_;
			gpointer _tmp172_;
			gchar* _tmp173_;
			GearyRFC822MailboxAddresses* _tmp174_;
			GearyRFC822MailboxAddresses* _tmp175_;
			GeeMap* _tmp176_;
			gpointer _tmp177_;
			gchar* _tmp178_;
			GearyRFC822MailboxAddresses* _tmp179_;
			GearyRFC822MailboxAddresses* _tmp180_;
			_tmp165_ = email;
			_tmp166_ = headers;
			_tmp167_ = gee_map_get (_tmp166_, "To");
			_tmp168_ = (gchar*) _tmp167_;
			_tmp169_ = geary_imap_folder_session_unflatten_addresses (self, _tmp168_);
			_tmp170_ = _tmp169_;
			_tmp171_ = headers;
			_tmp172_ = gee_map_get (_tmp171_, "Cc");
			_tmp173_ = (gchar*) _tmp172_;
			_tmp174_ = geary_imap_folder_session_unflatten_addresses (self, _tmp173_);
			_tmp175_ = _tmp174_;
			_tmp176_ = headers;
			_tmp177_ = gee_map_get (_tmp176_, "Bcc");
			_tmp178_ = (gchar*) _tmp177_;
			_tmp179_ = geary_imap_folder_session_unflatten_addresses (self, _tmp178_);
			_tmp180_ = _tmp179_;
			geary_email_set_receivers (_tmp165_, _tmp170_, _tmp175_, _tmp180_);
			_g_object_unref0 (_tmp180_);
			_g_free0 (_tmp178_);
			_g_object_unref0 (_tmp175_);
			_g_free0 (_tmp173_);
			_g_object_unref0 (_tmp170_);
			_g_free0 (_tmp168_);
		}
		_tmp181_ = message_id;
		if (_tmp181_ == NULL) {
			GeeMap* _tmp182_;
			gpointer _tmp183_;
			gchar* _tmp184_;
			GearyRFC822MessageID* _tmp185_;
			_tmp182_ = headers;
			_tmp183_ = gee_map_get (_tmp182_, "Message-ID");
			_tmp184_ = (gchar*) _tmp183_;
			_tmp185_ = geary_imap_folder_session_unflatten_message_id (self, _tmp184_);
			_g_object_unref0 (message_id);
			message_id = _tmp185_;
			_g_free0 (_tmp184_);
		}
		_tmp186_ = in_reply_to;
		if (_tmp186_ == NULL) {
			GeeMap* _tmp187_;
			gpointer _tmp188_;
			gchar* _tmp189_;
			GearyRFC822MessageIDList* _tmp190_;
			_tmp187_ = headers;
			_tmp188_ = gee_map_get (_tmp187_, "In-Reply-To");
			_tmp189_ = (gchar*) _tmp188_;
			_tmp190_ = geary_imap_folder_session_unflatten_message_id_list (self, _tmp189_);
			_g_object_unref0 (in_reply_to);
			in_reply_to = _tmp190_;
			_g_free0 (_tmp189_);
		}
		_tmp191_ = references;
		if (_tmp191_ == NULL) {
			GeeMap* _tmp192_;
			gpointer _tmp193_;
			gchar* _tmp194_;
			GearyRFC822MessageIDList* _tmp195_;
			_tmp192_ = headers;
			_tmp193_ = gee_map_get (_tmp192_, "References");
			_tmp194_ = (gchar*) _tmp193_;
			_tmp195_ = geary_imap_folder_session_unflatten_message_id_list (self, _tmp194_);
			_g_object_unref0 (references);
			references = _tmp195_;
			_g_free0 (_tmp194_);
		}
		_tmp196_ = email;
		if (geary_imap_folder_session_required_but_not_set (GEARY_EMAIL_FIELD_SUBJECT, required_fields, _tmp196_)) {
			GearyRFC822Subject* subject = NULL;
			gchar* value = NULL;
			GeeMap* _tmp197_;
			gpointer _tmp198_;
			const gchar* _tmp199_;
			GearyEmail* _tmp202_;
			GearyRFC822Subject* _tmp203_;
			subject = NULL;
			_tmp197_ = headers;
			_tmp198_ = gee_map_get (_tmp197_, "Subject");
			value = (gchar*) _tmp198_;
			_tmp199_ = value;
			if (_tmp199_ != NULL) {
				const gchar* _tmp200_;
				GearyRFC822Subject* _tmp201_;
				_tmp200_ = value;
				_tmp201_ = geary_rf_c822_subject_new_from_rfc822_string (_tmp200_);
				_g_object_unref0 (subject);
				subject = _tmp201_;
			}
			_tmp202_ = email;
			_tmp203_ = subject;
			geary_email_set_message_subject (_tmp202_, _tmp203_);
			_g_free0 (value);
			_g_object_unref0 (subject);
		}
		_g_object_unref0 (headers);
	}
	_tmp204_ = email;
	if (geary_imap_folder_session_required_but_not_set (GEARY_EMAIL_FIELD_REFERENCES, required_fields, _tmp204_)) {
		GearyEmail* _tmp205_;
		GearyRFC822MessageID* _tmp206_;
		GearyRFC822MessageIDList* _tmp207_;
		GearyRFC822MessageIDList* _tmp208_;
		_tmp205_ = email;
		_tmp206_ = message_id;
		_tmp207_ = in_reply_to;
		_tmp208_ = references;
		geary_email_set_full_references (_tmp205_, _tmp206_, _tmp207_, _tmp208_);
	}
	if (preview_specifier != NULL) {
		_tmp209_ = TRUE;
	} else {
		_tmp209_ = preview_charset_specifier != NULL;
	}
	if (_tmp209_) {
		GearyMemoryBuffer* preview_headers = NULL;
		GeeMap* _tmp210_;
		GeeMap* _tmp211_;
		gpointer _tmp212_;
		GearyMemoryBuffer* preview_body = NULL;
		GeeMap* _tmp213_;
		GeeMap* _tmp214_;
		gpointer _tmp215_;
		GearyRFC822PreviewText* preview = NULL;
		GearyMemoryStringBuffer* _tmp216_;
		GearyMemoryStringBuffer* _tmp217_;
		GearyRFC822PreviewText* _tmp218_;
		GearyRFC822PreviewText* _tmp219_;
		gboolean _tmp220_ = FALSE;
		gboolean _tmp221_ = FALSE;
		gboolean _tmp222_ = FALSE;
		GearyMemoryBuffer* _tmp223_;
		GearyEmail* _tmp251_;
		GearyRFC822PreviewText* _tmp252_;
		_tmp210_ = geary_imap_fetched_data_get_body_data_map (fetched_data);
		_tmp211_ = _tmp210_;
		_tmp212_ = gee_map_get (_tmp211_, preview_charset_specifier);
		preview_headers = (GearyMemoryBuffer*) _tmp212_;
		_tmp213_ = geary_imap_fetched_data_get_body_data_map (fetched_data);
		_tmp214_ = _tmp213_;
		_tmp215_ = gee_map_get (_tmp214_, preview_specifier);
		preview_body = (GearyMemoryBuffer*) _tmp215_;
		_tmp216_ = geary_memory_string_buffer_new ("");
		_tmp217_ = _tmp216_;
		_tmp218_ = geary_rf_c822_preview_text_new (G_TYPE_CHECK_INSTANCE_CAST (_tmp217_, GEARY_MEMORY_TYPE_BUFFER, GearyMemoryBuffer));
		_tmp219_ = _tmp218_;
		_g_object_unref0 (_tmp217_);
		preview = _tmp219_;
		_tmp223_ = preview_headers;
		if (_tmp223_ != NULL) {
			GearyMemoryBuffer* _tmp224_;
			gsize _tmp225_;
			gsize _tmp226_;
			_tmp224_ = preview_headers;
			_tmp225_ = geary_memory_buffer_get_size (_tmp224_);
			_tmp226_ = _tmp225_;
			_tmp222_ = _tmp226_ > ((gsize) 0);
		} else {
			_tmp222_ = FALSE;
		}
		if (_tmp222_) {
			GearyMemoryBuffer* _tmp227_;
			_tmp227_ = preview_body;
			_tmp221_ = _tmp227_ != NULL;
		} else {
			_tmp221_ = FALSE;
		}
		if (_tmp221_) {
			GearyMemoryBuffer* _tmp228_;
			gsize _tmp229_;
			gsize _tmp230_;
			_tmp228_ = preview_body;
			_tmp229_ = geary_memory_buffer_get_size (_tmp228_);
			_tmp230_ = _tmp229_;
			_tmp220_ = _tmp230_ > ((gsize) 0);
		} else {
			_tmp220_ = FALSE;
		}
		if (_tmp220_) {
			GearyMemoryBuffer* _tmp231_;
			GearyMemoryBuffer* _tmp232_;
			GearyRFC822PreviewText* _tmp233_;
			_tmp231_ = preview_headers;
			_tmp232_ = preview_body;
			_tmp233_ = geary_rf_c822_preview_text_new_with_header (_tmp231_, _tmp232_);
			_g_object_unref0 (preview);
			preview = _tmp233_;
		} else {
			gchar* _tmp234_;
			gchar* _tmp235_;
			gchar* _tmp236_;
			gchar* _tmp237_;
			_tmp234_ = geary_imap_fetch_body_data_specifier_to_string (preview_specifier);
			_tmp235_ = _tmp234_;
			_tmp236_ = geary_imap_fetch_body_data_specifier_to_string (preview_charset_specifier);
			_tmp237_ = _tmp236_;
			geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "No preview specifiers \"%s\" and \"%s\" found", _tmp235_, _tmp237_);
			_g_free0 (_tmp237_);
			_g_free0 (_tmp235_);
			{
				GeeIterator* _specifier_it = NULL;
				GeeMap* _tmp238_;
				GeeMap* _tmp239_;
				GeeSet* _tmp240_;
				GeeSet* _tmp241_;
				GeeSet* _tmp242_;
				GeeIterator* _tmp243_;
				GeeIterator* _tmp244_;
				_tmp238_ = geary_imap_fetched_data_get_body_data_map (fetched_data);
				_tmp239_ = _tmp238_;
				_tmp240_ = gee_map_get_keys (_tmp239_);
				_tmp241_ = _tmp240_;
				_tmp242_ = _tmp241_;
				_tmp243_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp242_, GEE_TYPE_ITERABLE, GeeIterable));
				_tmp244_ = _tmp243_;
				_g_object_unref0 (_tmp242_);
				_specifier_it = _tmp244_;
				while (TRUE) {
					GeeIterator* _tmp245_;
					GearyImapFetchBodyDataSpecifier* specifier = NULL;
					GeeIterator* _tmp246_;
					gpointer _tmp247_;
					GearyImapFetchBodyDataSpecifier* _tmp248_;
					gchar* _tmp249_;
					gchar* _tmp250_;
					_tmp245_ = _specifier_it;
					if (!gee_iterator_next (_tmp245_)) {
						break;
					}
					_tmp246_ = _specifier_it;
					_tmp247_ = gee_iterator_get (_tmp246_);
					specifier = (GearyImapFetchBodyDataSpecifier*) _tmp247_;
					_tmp248_ = specifier;
					_tmp249_ = geary_imap_fetch_body_data_specifier_to_string (_tmp248_);
					_tmp250_ = _tmp249_;
					geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), " - has %s", _tmp250_);
					_g_free0 (_tmp250_);
					_g_object_unref0 (specifier);
				}
				_g_object_unref0 (_specifier_it);
			}
		}
		_tmp251_ = email;
		_tmp252_ = preview;
		geary_email_set_message_preview (_tmp251_, _tmp252_);
		_g_object_unref0 (preview);
		_g_object_unref0 (preview_body);
		_g_object_unref0 (preview_headers);
	}
	if (body_specifier != NULL) {
		GeeMap* _tmp253_;
		GeeMap* _tmp254_;
		_tmp253_ = geary_imap_fetched_data_get_body_data_map (fetched_data);
		_tmp254_ = _tmp253_;
		if (gee_map_has_key (_tmp254_, body_specifier)) {
			GearyEmail* _tmp255_;
			GeeMap* _tmp256_;
			GeeMap* _tmp257_;
			gpointer _tmp258_;
			GearyMemoryBuffer* _tmp259_;
			GearyRFC822Text* _tmp260_;
			GearyRFC822Text* _tmp261_;
			GearyRFC822Message* message = NULL;
			GearyRFC822Message* _tmp270_;
			_tmp255_ = email;
			_tmp256_ = geary_imap_fetched_data_get_body_data_map (fetched_data);
			_tmp257_ = _tmp256_;
			_tmp258_ = gee_map_get (_tmp257_, body_specifier);
			_tmp259_ = (GearyMemoryBuffer*) _tmp258_;
			_tmp260_ = geary_rf_c822_text_new (_tmp259_);
			_tmp261_ = _tmp260_;
			geary_email_set_message_body (_tmp255_, _tmp261_);
			_g_object_unref0 (_tmp261_);
			_g_object_unref0 (_tmp259_);
			message = NULL;
			{
				GearyRFC822Message* _tmp262_ = NULL;
				GearyEmail* _tmp263_;
				GearyRFC822Message* _tmp264_;
				GearyRFC822Message* _tmp265_;
				_tmp263_ = email;
				_tmp264_ = geary_email_get_message (_tmp263_, &_inner_error0_);
				_tmp262_ = _tmp264_;
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					if (g_error_matches (_inner_error0_, GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_INCOMPLETE_MESSAGE)) {
						goto __catch0_geary_engine_error_incomplete_message;
					}
					goto __catch0_g_error;
				}
				_tmp265_ = _tmp262_;
				_tmp262_ = NULL;
				_g_object_unref0 (message);
				message = _tmp265_;
				_g_object_unref0 (_tmp262_);
			}
			goto __finally0;
			__catch0_geary_engine_error_incomplete_message:
			{
				GError* err = NULL;
				GError* _tmp266_;
				const gchar* _tmp267_;
				err = _inner_error0_;
				_inner_error0_ = NULL;
				_tmp266_ = err;
				_tmp267_ = _tmp266_->message;
				geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Not enough fields to construct message for preview: %s", _tmp267_);
				_g_error_free0 (err);
			}
			goto __finally0;
			__catch0_g_error:
			{
				GError* err = NULL;
				GError* _tmp268_;
				const gchar* _tmp269_;
				err = _inner_error0_;
				_inner_error0_ = NULL;
				_tmp268_ = err;
				_tmp269_ = _tmp268_->message;
				geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Error constructing message for preview: %s", _tmp269_);
				_g_error_free0 (err);
			}
			__finally0:
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (message);
				_g_object_unref0 (references);
				_g_object_unref0 (in_reply_to);
				_g_object_unref0 (message_id);
				_g_object_unref0 (rfc822_size);
				_g_object_unref0 (internaldate);
				_g_object_unref0 (email);
				return NULL;
			}
			_tmp270_ = message;
			if (_tmp270_ != NULL) {
				gchar* preview = NULL;
				GearyRFC822Message* _tmp271_;
				gchar* _tmp272_;
				const gchar* _tmp273_;
				gint _tmp274_;
				gint _tmp275_;
				GearyEmail* _tmp278_;
				const gchar* _tmp279_;
				GearyRFC822PreviewText* _tmp280_;
				GearyRFC822PreviewText* _tmp281_;
				_tmp271_ = message;
				_tmp272_ = geary_rf_c822_message_get_preview (_tmp271_);
				preview = _tmp272_;
				_tmp273_ = preview;
				_tmp274_ = strlen (_tmp273_);
				_tmp275_ = _tmp274_;
				if (_tmp275_ > GEARY_EMAIL_MAX_PREVIEW_BYTES) {
					const gchar* _tmp276_;
					gchar* _tmp277_;
					_tmp276_ = preview;
					_tmp277_ = geary_string_safe_byte_substring (_tmp276_, (gssize) GEARY_EMAIL_MAX_PREVIEW_BYTES);
					_g_free0 (preview);
					preview = _tmp277_;
				}
				_tmp278_ = email;
				_tmp279_ = preview;
				_tmp280_ = geary_rf_c822_preview_text_new_from_string (_tmp279_);
				_tmp281_ = _tmp280_;
				geary_email_set_message_preview (_tmp278_, _tmp281_);
				_g_object_unref0 (_tmp281_);
				_g_free0 (preview);
			}
			_g_object_unref0 (message);
		} else {
			gchar* _tmp282_;
			gchar* _tmp283_;
			_tmp282_ = geary_imap_fetch_body_data_specifier_to_string (body_specifier);
			_tmp283_ = _tmp282_;
			geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "No body specifier \"%s\" found", _tmp283_);
			_g_free0 (_tmp283_);
			{
				GeeIterator* _specifier_it = NULL;
				GeeMap* _tmp284_;
				GeeMap* _tmp285_;
				GeeSet* _tmp286_;
				GeeSet* _tmp287_;
				GeeSet* _tmp288_;
				GeeIterator* _tmp289_;
				GeeIterator* _tmp290_;
				_tmp284_ = geary_imap_fetched_data_get_body_data_map (fetched_data);
				_tmp285_ = _tmp284_;
				_tmp286_ = gee_map_get_keys (_tmp285_);
				_tmp287_ = _tmp286_;
				_tmp288_ = _tmp287_;
				_tmp289_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp288_, GEE_TYPE_ITERABLE, GeeIterable));
				_tmp290_ = _tmp289_;
				_g_object_unref0 (_tmp288_);
				_specifier_it = _tmp290_;
				while (TRUE) {
					GeeIterator* _tmp291_;
					GearyImapFetchBodyDataSpecifier* specifier = NULL;
					GeeIterator* _tmp292_;
					gpointer _tmp293_;
					GearyImapFetchBodyDataSpecifier* _tmp294_;
					gchar* _tmp295_;
					gchar* _tmp296_;
					_tmp291_ = _specifier_it;
					if (!gee_iterator_next (_tmp291_)) {
						break;
					}
					_tmp292_ = _specifier_it;
					_tmp293_ = gee_iterator_get (_tmp292_);
					specifier = (GearyImapFetchBodyDataSpecifier*) _tmp293_;
					_tmp294_ = specifier;
					_tmp295_ = geary_imap_fetch_body_data_specifier_to_string (_tmp294_);
					_tmp296_ = _tmp295_;
					geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), " - has %s", _tmp296_);
					_g_free0 (_tmp296_);
					_g_object_unref0 (specifier);
				}
				_g_object_unref0 (_specifier_it);
			}
		}
	}
	result = email;
	_g_object_unref0 (references);
	_g_object_unref0 (in_reply_to);
	_g_object_unref0 (message_id);
	_g_object_unref0 (rfc822_size);
	_g_object_unref0 (internaldate);
	return result;
}

static void
geary_imap_folder_session_create_email_async_data_free (gpointer _data)
{
	GearyImapFolderSessionCreateEmailAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->message);
	_g_object_unref0 (_data_->flags);
	_g_date_time_unref0 (_data_->date_received);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapFolderSessionCreateEmailAsyncData, _data_);
}

static gpointer
_g_date_time_ref0 (gpointer self)
{
	return self ? g_date_time_ref (self) : NULL;
}

void
geary_imap_folder_session_create_email_async (GearyImapFolderSession* self,
                                              GearyRFC822Message* message,
                                              GearyEmailFlags* flags,
                                              GDateTime* date_received,
                                              GAsyncReadyCallback _callback_,
                                              gpointer _user_data_)
{
	GearyImapFolderSessionCreateEmailAsyncData* _data_;
	GearyImapFolderSession* _tmp0_;
	GearyRFC822Message* _tmp1_;
	GearyEmailFlags* _tmp2_;
	GDateTime* _tmp3_;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	g_return_if_fail (GEARY_RF_C822_IS_MESSAGE (message));
	g_return_if_fail ((flags == NULL) || GEARY_IS_EMAIL_FLAGS (flags));
	_data_ = g_slice_new0 (GearyImapFolderSessionCreateEmailAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_folder_session_create_email_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (message);
	_g_object_unref0 (_data_->message);
	_data_->message = _tmp1_;
	_tmp2_ = _g_object_ref0 (flags);
	_g_object_unref0 (_data_->flags);
	_data_->flags = _tmp2_;
	_tmp3_ = _g_date_time_ref0 (date_received);
	_g_date_time_unref0 (_data_->date_received);
	_data_->date_received = _tmp3_;
	geary_imap_folder_session_create_email_async_co (_data_);
}

GearyEmailIdentifier*
geary_imap_folder_session_create_email_finish (GearyImapFolderSession* self,
                                               GAsyncResult* _res_,
                                               GError** error)
{
	GearyEmailIdentifier* result;
	GearyImapFolderSessionCreateEmailAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

/**
     * Stores a new message in the remote mailbox.
     *
     * Returns a no-message-id ImapDB.EmailIdentifier with the UID
     * stored in it.
     *
     * This method does not take a cancellable; there is currently no
     * way to tell if an email was created or not if {@link
     * exec_commands_async} is cancelled during the append. For
     * atomicity's sake, callers need to remove the returned email ID
     * if a cancel occurred.
    */
static void
geary_imap_folder_session_create_email_async_ready (GObject* source_object,
                                                    GAsyncResult* _res_,
                                                    gpointer _user_data_)
{
	GearyImapFolderSessionCreateEmailAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_folder_session_create_email_async_co (_data_);
}

static gboolean
geary_imap_folder_session_create_email_async_co (GearyImapFolderSessionCreateEmailAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->msg_flags = NULL;
	if (_data_->flags != NULL) {
		_data_->_tmp0_ = geary_imap_email_flags_from_api_email_flags (_data_->flags);
		_data_->imap_flags = _data_->_tmp0_;
		_data_->_tmp1_ = _data_->imap_flags;
		_data_->_tmp2_ = geary_imap_email_flags_get_message_flags (_data_->_tmp1_);
		_data_->_tmp3_ = _data_->_tmp2_;
		_data_->_tmp4_ = _g_object_ref0 (_data_->_tmp3_);
		_g_object_unref0 (_data_->msg_flags);
		_data_->msg_flags = _data_->_tmp4_;
		_g_object_unref0 (_data_->imap_flags);
	} else {
		_data_->_tmp5_ = geary_imap_message_flag_get_SEEN ();
		_data_->_tmp6_ = _data_->_tmp5_;
		_data_->_tmp7_ = geary_iterate (GEARY_IMAP_TYPE_MESSAGE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->_tmp6_, NULL);
		_data_->_tmp8_ = _data_->_tmp7_;
		_data_->_tmp9_ = geary_iterable_to_array_list (_data_->_tmp8_, NULL, NULL, NULL);
		_data_->_tmp10_ = _data_->_tmp9_;
		_data_->_tmp11_ = geary_imap_message_flags_new (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp10_, GEE_TYPE_COLLECTION, GeeCollection));
		_g_object_unref0 (_data_->msg_flags);
		_data_->msg_flags = _data_->_tmp11_;
		_g_object_unref0 (_data_->_tmp10_);
		_g_object_unref0 (_data_->_tmp8_);
	}
	_data_->internaldate = NULL;
	if (_data_->date_received != NULL) {
		_data_->_tmp13_ = geary_imap_internal_date_new_from_date_time (_data_->date_received, &_data_->_inner_error0_);
		_data_->_tmp12_ = _data_->_tmp13_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->internaldate);
			_g_object_unref0 (_data_->msg_flags);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp14_ = _data_->_tmp12_;
		_data_->_tmp12_ = NULL;
		_g_object_unref0 (_data_->internaldate);
		_data_->internaldate = _data_->_tmp14_;
		_g_object_unref0 (_data_->_tmp12_);
	}
	_data_->_tmp16_ = geary_rf_c822_message_get_rfc822_buffer (_data_->message, GEARY_RF_C822_MESSAGE_RF_C822_FORMAT_OPTIONS_NONE, &_data_->_inner_error0_);
	_data_->_tmp15_ = _data_->_tmp16_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->internaldate);
		_g_object_unref0 (_data_->msg_flags);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp17_ = _data_->self->priv->mailbox;
	_data_->_tmp18_ = _data_->msg_flags;
	_data_->_tmp19_ = _data_->internaldate;
	_data_->_tmp20_ = geary_imap_append_command_new (_data_->_tmp17_, _data_->_tmp18_, _data_->_tmp19_, _data_->_tmp15_, NULL);
	_data_->cmd = _data_->_tmp20_;
	_data_->_tmp21_ = _data_->cmd;
	_data_->_tmp22_ = geary_iterate (GEARY_IMAP_TYPE_APPEND_COMMAND, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->_tmp21_, NULL);
	_data_->_tmp23_ = _data_->_tmp22_;
	_data_->_tmp24_ = geary_iterable_to_array_list (_data_->_tmp23_, NULL, NULL, NULL);
	_data_->_tmp25_ = _data_->_tmp24_;
	_data_->_state_ = 1;
	geary_imap_folder_session_exec_commands_async (_data_->self, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp25_, GEE_TYPE_COLLECTION, GeeCollection), NULL, NULL, NULL, geary_imap_folder_session_create_email_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp26_ = geary_imap_folder_session_exec_commands_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp27_ = _data_->_tmp26_;
	_g_object_unref0 (_data_->_tmp25_);
	_g_object_unref0 (_data_->_tmp23_);
	_data_->responses = _data_->_tmp27_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->cmd);
		_g_object_unref0 (_data_->_tmp15_);
		_g_object_unref0 (_data_->internaldate);
		_g_object_unref0 (_data_->msg_flags);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp28_ = _data_->responses;
	_data_->_tmp29_ = _data_->cmd;
	_data_->_tmp30_ = gee_map_get (_data_->_tmp28_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp29_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand));
	_data_->response = (GearyImapStatusResponse*) _data_->_tmp30_;
	_data_->_tmp33_ = _data_->response;
	_data_->_tmp34_ = geary_imap_status_response_get_status (_data_->_tmp33_);
	_data_->_tmp35_ = _data_->_tmp34_;
	if (_data_->_tmp35_ == GEARY_IMAP_STATUS_OK) {
		_data_->_tmp36_ = _data_->response;
		_data_->_tmp37_ = geary_imap_status_response_get_response_code (_data_->_tmp36_);
		_data_->_tmp38_ = _data_->_tmp37_;
		_data_->_tmp32_ = _data_->_tmp38_ != NULL;
	} else {
		_data_->_tmp32_ = FALSE;
	}
	if (_data_->_tmp32_) {
		_data_->_tmp40_ = _data_->response;
		_data_->_tmp41_ = geary_imap_status_response_get_response_code (_data_->_tmp40_);
		_data_->_tmp42_ = _data_->_tmp41_;
		_data_->_tmp43_ = geary_imap_response_code_get_response_code_type (_data_->_tmp42_, &_data_->_inner_error0_);
		_data_->_tmp39_ = _data_->_tmp43_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->response);
			_g_object_unref0 (_data_->responses);
			_g_object_unref0 (_data_->cmd);
			_g_object_unref0 (_data_->_tmp15_);
			_g_object_unref0 (_data_->internaldate);
			_g_object_unref0 (_data_->msg_flags);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp31_ = geary_imap_response_code_type_is_value (_data_->_tmp39_, "appenduid");
		_g_object_unref0 (_data_->_tmp39_);
	} else {
		_data_->_tmp31_ = FALSE;
	}
	if (_data_->_tmp31_) {
		_data_->_tmp45_ = _data_->response;
		_data_->_tmp46_ = geary_imap_status_response_get_response_code (_data_->_tmp45_);
		_data_->_tmp47_ = _data_->_tmp46_;
		_data_->_tmp48_ = geary_imap_list_parameter_get_as_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp47_, GEARY_IMAP_TYPE_LIST_PARAMETER, GearyImapListParameter), 2, &_data_->_inner_error0_);
		_data_->_tmp44_ = _data_->_tmp48_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->response);
			_g_object_unref0 (_data_->responses);
			_g_object_unref0 (_data_->cmd);
			_g_object_unref0 (_data_->_tmp15_);
			_g_object_unref0 (_data_->internaldate);
			_g_object_unref0 (_data_->msg_flags);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp49_ = geary_imap_string_parameter_as_int64 (_data_->_tmp44_, G_MININT64, G_MAXINT64, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->_tmp44_);
			_g_object_unref0 (_data_->response);
			_g_object_unref0 (_data_->responses);
			_g_object_unref0 (_data_->cmd);
			_g_object_unref0 (_data_->_tmp15_);
			_g_object_unref0 (_data_->internaldate);
			_g_object_unref0 (_data_->msg_flags);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp50_ = geary_imap_uid_new_checked (_data_->_tmp49_, &_data_->_inner_error0_);
		_data_->new_id = _data_->_tmp50_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->_tmp44_);
			_g_object_unref0 (_data_->response);
			_g_object_unref0 (_data_->responses);
			_g_object_unref0 (_data_->cmd);
			_g_object_unref0 (_data_->_tmp15_);
			_g_object_unref0 (_data_->internaldate);
			_g_object_unref0 (_data_->msg_flags);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp51_ = _data_->new_id;
		_data_->_tmp52_ = geary_imap_db_email_identifier_new_no_message_id (_data_->_tmp51_);
		_data_->result = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp52_, GEARY_TYPE_EMAIL_IDENTIFIER, GearyEmailIdentifier);
		_g_object_unref0 (_data_->new_id);
		_g_object_unref0 (_data_->_tmp44_);
		_g_object_unref0 (_data_->response);
		_g_object_unref0 (_data_->responses);
		_g_object_unref0 (_data_->cmd);
		_g_object_unref0 (_data_->_tmp15_);
		_g_object_unref0 (_data_->internaldate);
		_g_object_unref0 (_data_->msg_flags);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->result = NULL;
	_g_object_unref0 (_data_->response);
	_g_object_unref0 (_data_->responses);
	_g_object_unref0 (_data_->cmd);
	_g_object_unref0 (_data_->_tmp15_);
	_g_object_unref0 (_data_->internaldate);
	_g_object_unref0 (_data_->msg_flags);
	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;
}

/** {@inheritDoc} */
static GearyLoggingState*
geary_imap_folder_session_real_to_logging_state (GearyImapSessionObject* base)
{
	GearyImapFolderSession * self;
	gchar* _tmp0_ = NULL;
	GearyImapMessageFlags* _tmp1_;
	GearyLoggingState* _tmp5_;
	GearyLoggingState* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	GearyImapFolder* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	GearyTrillian _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	GearyTrillian _tmp15_;
	gchar* _tmp16_;
	gchar* _tmp17_;
	GearyLoggingState* _tmp18_;
	GearyLoggingState* _tmp19_;
	GearyLoggingState* result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_TYPE_FOLDER_SESSION, GearyImapFolderSession);
	_tmp1_ = self->priv->_permanent_flags;
	if (_tmp1_ != NULL) {
		GearyImapMessageFlags* _tmp2_;
		gchar* _tmp3_;
		_tmp2_ = self->priv->_permanent_flags;
		_tmp3_ = geary_message_data_abstract_message_data_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, GEARY_MESSAGE_DATA_TYPE_ABSTRACT_MESSAGE_DATA, GearyMessageDataAbstractMessageData));
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp3_;
	} else {
		gchar* _tmp4_;
		_tmp4_ = g_strdup ("(none)");
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp4_;
	}
	_tmp5_ = GEARY_IMAP_SESSION_OBJECT_CLASS (geary_imap_folder_session_parent_class)->to_logging_state (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_IMAP_TYPE_SESSION_OBJECT, GearyImapSessionObject));
	_tmp6_ = _tmp5_;
	_tmp7_ = geary_logging_state_format_message (_tmp6_);
	_tmp8_ = _tmp7_;
	_tmp9_ = self->priv->_folder;
	_tmp10_ = geary_imap_folder_to_string (_tmp9_);
	_tmp11_ = _tmp10_;
	_tmp12_ = self->priv->_readonly;
	_tmp13_ = geary_trillian_to_string (_tmp12_);
	_tmp14_ = _tmp13_;
	_tmp15_ = self->priv->_accepts_user_flags;
	_tmp16_ = geary_trillian_to_string (_tmp15_);
	_tmp17_ = _tmp16_;
	_tmp18_ = geary_logging_state_new (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "%s, %s, ro: %s, permanent_flags: %s, accepts_user_flags: %s", _tmp8_, _tmp11_, _tmp14_, _tmp0_, _tmp17_);
	_tmp19_ = _tmp18_;
	_g_free0 (_tmp17_);
	_g_free0 (_tmp14_);
	_g_free0 (_tmp11_);
	_g_free0 (_tmp8_);
	_geary_logging_state_unref0 (_tmp6_);
	result = _tmp19_;
	_g_free0 (_tmp0_);
	return result;
}

/**
     * Returns a valid IMAP client session for use by this object.
     *
     * In addition to the checks made by {@link
     * SessionObject.get_session}, this method also ensures that the
     * IMAP session is in the SELECTED state for the correct mailbox.
     */
static GearyImapClientSession*
geary_imap_folder_session_real_get_session (GearyImapSessionObject* base,
                                            GError** error)
{
	GearyImapFolderSession * self;
	GearyImapClientSession* session = NULL;
	GearyImapClientSession* _tmp0_;
	gboolean _tmp1_ = FALSE;
	GearyImapClientSession* _tmp2_;
	GearyImapClientSessionProtocolState _tmp3_;
	GearyImapClientSessionProtocolState _tmp4_;
	GError* _inner_error0_ = NULL;
	GearyImapClientSession* result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_TYPE_FOLDER_SESSION, GearyImapFolderSession);
	_tmp0_ = GEARY_IMAP_SESSION_OBJECT_CLASS (geary_imap_folder_session_parent_class)->get_session (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_IMAP_TYPE_SESSION_OBJECT, GearyImapSessionObject), &_inner_error0_);
	session = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == GEARY_IMAP_ERROR) {
			g_propagate_error (error, _inner_error0_);
			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;
		}
	}
	_tmp2_ = session;
	_tmp3_ = geary_imap_client_session_get_protocol_state (_tmp2_);
	_tmp4_ = _tmp3_;
	if (_tmp4_ != GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_SELECTED) {
		GearyImapMailboxSpecifier* _tmp5_;
		GearyImapClientSession* _tmp6_;
		GearyImapMailboxSpecifier* _tmp7_;
		_tmp5_ = self->priv->mailbox;
		_tmp6_ = session;
		_tmp7_ = _tmp6_->selected_mailbox;
		_tmp1_ = !gee_hashable_equal_to (G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, GEE_TYPE_HASHABLE, GeeHashable), _tmp7_);
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		GearyImapMailboxSpecifier* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		GError* _tmp11_;
		GError* _tmp12_;
		_tmp8_ = self->priv->mailbox;
		_tmp9_ = geary_imap_mailbox_specifier_to_string (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp11_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_NOT_CONNECTED, "IMAP object no longer SELECTED for %s", _tmp10_);
		_tmp12_ = _tmp11_;
		_g_free0 (_tmp10_);
		_inner_error0_ = _tmp12_;
		if (_inner_error0_->domain == GEARY_IMAP_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (session);
			return NULL;
		} else {
			_g_object_unref0 (session);
			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;
		}
	}
	result = session;
	return result;
}

static gboolean
geary_imap_folder_session_retry_bad_header_fields_response (GearyImapFolderSession* self,
                                                            GeeCollection* cmds)
{
	gboolean result;
	g_return_val_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self), FALSE);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (cmds, GEE_TYPE_COLLECTION), FALSE);
	{
		GeeIterator* _fetch_it = NULL;
		GeeIterator* _tmp0_;
		_tmp0_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (cmds, GEE_TYPE_ITERABLE, GeeIterable));
		_fetch_it = _tmp0_;
		while (TRUE) {
			GeeIterator* _tmp1_;
			GearyImapFetchCommand* fetch = NULL;
			GeeIterator* _tmp2_;
			gpointer _tmp3_;
			GearyImapFetchCommand* _tmp4_;
			GearyImapStatusResponse* _tmp5_;
			GearyImapStatusResponse* _tmp6_;
			GearyImapStatus _tmp7_;
			GearyImapStatus _tmp8_;
			_tmp1_ = _fetch_it;
			if (!gee_iterator_next (_tmp1_)) {
				break;
			}
			_tmp2_ = _fetch_it;
			_tmp3_ = gee_iterator_get (_tmp2_);
			fetch = (GearyImapFetchCommand*) _tmp3_;
			_tmp4_ = fetch;
			_tmp5_ = geary_imap_command_get_status (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand));
			_tmp6_ = _tmp5_;
			_tmp7_ = geary_imap_status_response_get_status (_tmp6_);
			_tmp8_ = _tmp7_;
			if (_tmp8_ == GEARY_IMAP_STATUS_BAD) {
				{
					GeeList* _specifier_list = NULL;
					GearyImapFetchCommand* _tmp9_;
					GeeList* _tmp10_;
					GeeList* _tmp11_;
					gint _specifier_size = 0;
					GeeList* _tmp12_;
					gint _tmp13_;
					gint _tmp14_;
					gint _specifier_index = 0;
					_tmp9_ = fetch;
					_tmp10_ = geary_imap_fetch_command_get_for_body_data_specifiers (_tmp9_);
					_tmp11_ = _tmp10_;
					_specifier_list = _tmp11_;
					_tmp12_ = _specifier_list;
					_tmp13_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp12_, GEE_TYPE_COLLECTION, GeeCollection));
					_tmp14_ = _tmp13_;
					_specifier_size = _tmp14_;
					_specifier_index = -1;
					while (TRUE) {
						gint _tmp15_;
						gint _tmp16_;
						GearyImapFetchBodyDataSpecifier* specifier = NULL;
						GeeList* _tmp17_;
						gpointer _tmp18_;
						gboolean _tmp19_ = FALSE;
						GearyImapFetchBodyDataSpecifier* _tmp20_;
						GearyImapFetchBodyDataSpecifierSectionPart _tmp21_;
						GearyImapFetchBodyDataSpecifierSectionPart _tmp22_;
						_specifier_index = _specifier_index + 1;
						_tmp15_ = _specifier_index;
						_tmp16_ = _specifier_size;
						if (!(_tmp15_ < _tmp16_)) {
							break;
						}
						_tmp17_ = _specifier_list;
						_tmp18_ = gee_list_get (_tmp17_, _specifier_index);
						specifier = (GearyImapFetchBodyDataSpecifier*) _tmp18_;
						_tmp20_ = specifier;
						_tmp21_ = geary_imap_fetch_body_data_specifier_get_section_part (_tmp20_);
						_tmp22_ = _tmp21_;
						if (_tmp22_ == GEARY_IMAP_FETCH_BODY_DATA_SPECIFIER_SECTION_PART_HEADER_FIELDS) {
							_tmp19_ = TRUE;
						} else {
							GearyImapFetchBodyDataSpecifier* _tmp23_;
							GearyImapFetchBodyDataSpecifierSectionPart _tmp24_;
							GearyImapFetchBodyDataSpecifierSectionPart _tmp25_;
							_tmp23_ = specifier;
							_tmp24_ = geary_imap_fetch_body_data_specifier_get_section_part (_tmp23_);
							_tmp25_ = _tmp24_;
							_tmp19_ = _tmp25_ == GEARY_IMAP_FETCH_BODY_DATA_SPECIFIER_SECTION_PART_HEADER_FIELDS_NOT;
						}
						if (_tmp19_) {
							GearyImapFetchBodyDataSpecifier* _tmp26_;
							gboolean _tmp27_;
							gboolean _tmp28_;
							_tmp26_ = specifier;
							_tmp27_ = geary_imap_fetch_body_data_specifier_get_request_header_fields_space (_tmp26_);
							_tmp28_ = _tmp27_;
							if (_tmp28_) {
								GearyImapQuirks* _tmp29_;
								_tmp29_ = self->priv->quirks;
								geary_imap_quirks_set_fetch_header_part_no_space (_tmp29_, TRUE);
								result = TRUE;
								_g_object_unref0 (specifier);
								_g_object_unref0 (fetch);
								_g_object_unref0 (_fetch_it);
								return result;
							}
						}
						_g_object_unref0 (specifier);
					}
				}
			}
			_g_object_unref0 (fetch);
		}
		_g_object_unref0 (_fetch_it);
	}
	result = FALSE;
	return result;
}

static const gchar*
string_to_string (const gchar* self)
{
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}

static void
geary_imap_folder_session_throw_on_not_ok (GearyImapFolderSession* self,
                                           GearyImapStatusResponse* response,
                                           const gchar* cmd,
                                           GError** error)
{
	GearyImapStatus _tmp0_;
	GearyImapStatus _tmp1_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self));
	g_return_if_fail (GEARY_IMAP_IS_STATUS_RESPONSE (response));
	g_return_if_fail (cmd != NULL);
	_tmp0_ = geary_imap_status_response_get_status (response);
	_tmp1_ = _tmp0_;
	switch (_tmp1_) {
		case GEARY_IMAP_STATUS_OK:
		{
			break;
		}
		case GEARY_IMAP_STATUS_NO:
		{
			const gchar* _tmp2_;
			gchar* _tmp3_;
			gchar* _tmp4_;
			GError* _tmp5_;
			GError* _tmp6_;
			_tmp2_ = string_to_string (cmd);
			_tmp3_ = geary_imap_parameter_to_string (G_TYPE_CHECK_INSTANCE_CAST (response, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
			_tmp4_ = _tmp3_;
			_tmp5_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_NOT_SUPPORTED, "Request %s failed: %s", _tmp2_, _tmp4_);
			_tmp6_ = _tmp5_;
			_g_free0 (_tmp4_);
			_inner_error0_ = _tmp6_;
			if (_inner_error0_->domain == GEARY_IMAP_ERROR) {
				g_propagate_error (error, _inner_error0_);
				return;
			} 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;
			}
		}
		default:
		{
			const gchar* _tmp7_;
			gchar* _tmp8_;
			gchar* _tmp9_;
			GError* _tmp10_;
			GError* _tmp11_;
			_tmp7_ = string_to_string (cmd);
			_tmp8_ = geary_imap_parameter_to_string (G_TYPE_CHECK_INSTANCE_CAST (response, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
			_tmp9_ = _tmp8_;
			_tmp10_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_SERVER_ERROR, "Unknown response status to %s: %s", _tmp7_, _tmp9_);
			_tmp11_ = _tmp10_;
			_g_free0 (_tmp9_);
			_inner_error0_ = _tmp11_;
			if (_inner_error0_->domain == GEARY_IMAP_ERROR) {
				g_propagate_error (error, _inner_error0_);
				return;
			} 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;
			}
		}
	}
}

static gboolean
geary_imap_folder_session_required_but_not_set (GearyEmailField check,
                                                GearyEmailField users_fields,
                                                GearyEmail* email)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	g_return_val_if_fail (GEARY_IS_EMAIL (email), FALSE);
	if (geary_email_field_require (users_fields, check)) {
		GearyEmailField _tmp1_;
		GearyEmailField _tmp2_;
		_tmp1_ = geary_email_get_fields (email);
		_tmp2_ = _tmp1_;
		_tmp0_ = !geary_email_field_is_all_set (_tmp2_, check);
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

static GearyRFC822Date*
geary_imap_folder_session_unflatten_date (GearyImapFolderSession* self,
                                          const gchar* str)
{
	GearyRFC822Date* date = NULL;
	GError* _inner_error0_ = NULL;
	GearyRFC822Date* result;
	g_return_val_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self), NULL);
	date = NULL;
	if (!geary_string_is_empty_or_whitespace (str)) {
		{
			GearyRFC822Date* _tmp0_ = NULL;
			GearyRFC822Date* _tmp1_;
			GearyRFC822Date* _tmp2_;
			_tmp1_ = geary_rf_c822_date_new_from_rfc822_string (str, &_inner_error0_);
			_tmp0_ = _tmp1_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GEARY_RF_C822_ERROR) {
					goto __catch0_geary_rf_c822_error;
				}
				_g_object_unref0 (date);
				g_critical ("file %s: line %d: unexpected 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;
			}
			_tmp2_ = _tmp0_;
			_tmp0_ = NULL;
			_g_object_unref0 (date);
			date = _tmp2_;
			_g_object_unref0 (_tmp0_);
		}
		goto __finally0;
		__catch0_geary_rf_c822_error:
		{
			GError* err = NULL;
			GError* _tmp3_;
			const gchar* _tmp4_;
			err = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp3_ = err;
			_tmp4_ = _tmp3_->message;
			geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Invalid RFC822 date \"%s\": %s", str, _tmp4_);
			_g_error_free0 (err);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (date);
			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;
		}
	}
	result = date;
	return result;
}

static GearyRFC822MailboxAddresses*
geary_imap_folder_session_unflatten_addresses (GearyImapFolderSession* self,
                                               const gchar* str)
{
	GearyRFC822MailboxAddresses* addresses = NULL;
	GError* _inner_error0_ = NULL;
	GearyRFC822MailboxAddresses* result;
	g_return_val_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self), NULL);
	addresses = NULL;
	if (!geary_string_is_empty_or_whitespace (str)) {
		{
			GearyRFC822MailboxAddresses* _tmp0_ = NULL;
			GearyRFC822MailboxAddresses* _tmp1_;
			GearyRFC822MailboxAddresses* _tmp2_;
			_tmp1_ = geary_rf_c822_mailbox_addresses_new_from_rfc822_string (str, &_inner_error0_);
			_tmp0_ = _tmp1_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GEARY_RF_C822_ERROR) {
					goto __catch0_geary_rf_c822_error;
				}
				_g_object_unref0 (addresses);
				g_critical ("file %s: line %d: unexpected 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;
			}
			_tmp2_ = _tmp0_;
			_tmp0_ = NULL;
			_g_object_unref0 (addresses);
			addresses = _tmp2_;
			_g_object_unref0 (_tmp0_);
		}
		goto __finally0;
		__catch0_geary_rf_c822_error:
		{
			GError* err = NULL;
			GError* _tmp3_;
			const gchar* _tmp4_;
			err = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp3_ = err;
			_tmp4_ = _tmp3_->message;
			geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Invalid RFC822 mailbox addresses \"%s\": %s", str, _tmp4_);
			_g_error_free0 (err);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (addresses);
			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;
		}
	}
	result = addresses;
	return result;
}

static GearyRFC822MessageID*
geary_imap_folder_session_unflatten_message_id (GearyImapFolderSession* self,
                                                const gchar* str)
{
	GearyRFC822MessageID* id = NULL;
	GError* _inner_error0_ = NULL;
	GearyRFC822MessageID* result;
	g_return_val_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self), NULL);
	id = NULL;
	if (!geary_string_is_empty_or_whitespace (str)) {
		{
			GearyRFC822MessageID* _tmp0_ = NULL;
			GearyRFC822MessageID* _tmp1_;
			GearyRFC822MessageID* _tmp2_;
			_tmp1_ = geary_rf_c822_message_id_new_from_rfc822_string (str, &_inner_error0_);
			_tmp0_ = _tmp1_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GEARY_RF_C822_ERROR) {
					goto __catch0_geary_rf_c822_error;
				}
				_g_object_unref0 (id);
				g_critical ("file %s: line %d: unexpected 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;
			}
			_tmp2_ = _tmp0_;
			_tmp0_ = NULL;
			_g_object_unref0 (id);
			id = _tmp2_;
			_g_object_unref0 (_tmp0_);
		}
		goto __finally0;
		__catch0_geary_rf_c822_error:
		{
			GError* err = NULL;
			GError* _tmp3_;
			const gchar* _tmp4_;
			err = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp3_ = err;
			_tmp4_ = _tmp3_->message;
			geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Invalid RFC822 message id \"%s\": %s", str, _tmp4_);
			_g_error_free0 (err);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (id);
			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;
		}
	}
	result = id;
	return result;
}

static GearyRFC822MessageIDList*
geary_imap_folder_session_unflatten_message_id_list (GearyImapFolderSession* self,
                                                     const gchar* str)
{
	GearyRFC822MessageIDList* ids = NULL;
	GError* _inner_error0_ = NULL;
	GearyRFC822MessageIDList* result;
	g_return_val_if_fail (GEARY_IMAP_IS_FOLDER_SESSION (self), NULL);
	ids = NULL;
	if (!geary_string_is_empty_or_whitespace (str)) {
		{
			GearyRFC822MessageIDList* _tmp0_ = NULL;
			GearyRFC822MessageIDList* _tmp1_;
			GearyRFC822MessageIDList* _tmp2_;
			_tmp1_ = geary_rf_c822_message_id_list_new_from_rfc822_string (str, &_inner_error0_);
			_tmp0_ = _tmp1_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GEARY_RF_C822_ERROR) {
					goto __catch0_geary_rf_c822_error;
				}
				_g_object_unref0 (ids);
				g_critical ("file %s: line %d: unexpected 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;
			}
			_tmp2_ = _tmp0_;
			_tmp0_ = NULL;
			_g_object_unref0 (ids);
			ids = _tmp2_;
			_g_object_unref0 (_tmp0_);
		}
		goto __finally0;
		__catch0_geary_rf_c822_error:
		{
			GError* err = NULL;
			GError* _tmp3_;
			const gchar* _tmp4_;
			err = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp3_ = err;
			_tmp4_ = _tmp3_->message;
			geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Invalid RFC822 message id \"%s\": %s", str, _tmp4_);
			_g_error_free0 (err);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (ids);
			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;
		}
	}
	result = ids;
	return result;
}

static void
geary_imap_folder_session_class_init (GearyImapFolderSessionClass * klass,
                                      gpointer klass_data)
{
	geary_imap_folder_session_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GearyImapFolderSession_private_offset);
	((GearyImapSessionObjectClass *) klass)->close = (GearyImapClientSession* (*) (GearyImapSessionObject*)) geary_imap_folder_session_real_close;
	((GearyImapSessionObjectClass *) klass)->to_logging_state = (GearyLoggingState* (*) (GearyImapSessionObject*)) geary_imap_folder_session_real_to_logging_state;
	((GearyImapSessionObjectClass *) klass)->get_session = (GearyImapClientSession* (*) (GearyImapSessionObject*, GError**)) geary_imap_folder_session_real_get_session;
	G_OBJECT_CLASS (klass)->get_property = _vala_geary_imap_folder_session_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_geary_imap_folder_session_set_property;
	G_OBJECT_CLASS (klass)->finalize = geary_imap_folder_session_finalize;
	/** The folder this session operates on. */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_FOLDER_SESSION_FOLDER_PROPERTY, geary_imap_folder_session_properties[GEARY_IMAP_FOLDER_SESSION_FOLDER_PROPERTY] = g_param_spec_object ("folder", "folder", "folder", GEARY_IMAP_TYPE_FOLDER, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** Determines if this folder immutable. */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_FOLDER_SESSION_READONLY_PROPERTY, geary_imap_folder_session_properties[GEARY_IMAP_FOLDER_SESSION_READONLY_PROPERTY] = g_param_spec_enum ("readonly", "readonly", "readonly", GEARY_TYPE_TRILLIAN, GEARY_TRILLIAN_UNKNOWN, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** This folder's set of permanent IMAP flags. */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_FOLDER_SESSION_PERMANENT_FLAGS_PROPERTY, geary_imap_folder_session_properties[GEARY_IMAP_FOLDER_SESSION_PERMANENT_FLAGS_PROPERTY] = g_param_spec_object ("permanent-flags", "permanent-flags", "permanent-flags", GEARY_IMAP_TYPE_MESSAGE_FLAGS, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** Determines if this folder accepts custom IMAP flags. */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_FOLDER_SESSION_ACCEPTS_USER_FLAGS_PROPERTY, geary_imap_folder_session_properties[GEARY_IMAP_FOLDER_SESSION_ACCEPTS_USER_FLAGS_PROPERTY] = g_param_spec_enum ("accepts-user-flags", "accepts-user-flags", "accepts-user-flags", GEARY_TYPE_TRILLIAN, GEARY_TRILLIAN_UNKNOWN, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/**
	     * A (potentially unsolicited) response from the server.
	     *
	     * See [[http://tools.ietf.org/html/rfc3501#section-7.3.1]]
	     */
	geary_imap_folder_session_signals[GEARY_IMAP_FOLDER_SESSION_EXISTS_SIGNAL] = g_signal_new ("exists", GEARY_IMAP_TYPE_FOLDER_SESSION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
	/**
	     * A (potentially unsolicited) response from the server.
	     *
	     * See [[http://tools.ietf.org/html/rfc3501#section-7.3.2]]
	     */
	geary_imap_folder_session_signals[GEARY_IMAP_FOLDER_SESSION_RECENT_SIGNAL] = g_signal_new ("recent", GEARY_IMAP_TYPE_FOLDER_SESSION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
	/**
	     * A (potentially unsolicited) response from the server.
	     *
	     * See [[http://tools.ietf.org/html/rfc3501#section-7.4.1]]
	     */
	geary_imap_folder_session_signals[GEARY_IMAP_FOLDER_SESSION_EXPUNGE_SIGNAL] = g_signal_new ("expunge", GEARY_IMAP_TYPE_FOLDER_SESSION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GEARY_IMAP_TYPE_SEQUENCE_NUMBER);
	/**
	     * Fabricated from the IMAP signals and state obtained at open_async().
	     */
	geary_imap_folder_session_signals[GEARY_IMAP_FOLDER_SESSION_APPENDED_SIGNAL] = g_signal_new ("appended", GEARY_IMAP_TYPE_FOLDER_SESSION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
	/**
	     * Fabricated from the IMAP signals and state obtained at open_async().
	     */
	geary_imap_folder_session_signals[GEARY_IMAP_FOLDER_SESSION_UPDATED_SIGNAL] = g_signal_new ("updated", GEARY_IMAP_TYPE_FOLDER_SESSION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_OBJECT, G_TYPE_NONE, 2, GEARY_IMAP_TYPE_SEQUENCE_NUMBER, GEARY_IMAP_TYPE_FETCHED_DATA);
	/**
	     * Fabricated from the IMAP signals and state obtained at open_async().
	     */
	geary_imap_folder_session_signals[GEARY_IMAP_FOLDER_SESSION_REMOVED_SIGNAL] = g_signal_new ("removed", GEARY_IMAP_TYPE_FOLDER_SESSION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GEARY_IMAP_TYPE_SEQUENCE_NUMBER);
}

static void
geary_imap_folder_session_instance_init (GearyImapFolderSession * self,
                                         gpointer klass)
{
	GearyNonblockingMutex* _tmp0_;
	self->priv = geary_imap_folder_session_get_instance_private (self);
	self->priv->_readonly = GEARY_TRILLIAN_UNKNOWN;
	self->priv->_permanent_flags = NULL;
	self->priv->_accepts_user_flags = GEARY_TRILLIAN_UNKNOWN;
	_tmp0_ = geary_nonblocking_mutex_new ();
	self->priv->cmd_mutex = _tmp0_;
	self->priv->fetch_accumulator = NULL;
	self->priv->search_accumulator = NULL;
}

static void
geary_imap_folder_session_finalize (GObject * obj)
{
	GearyImapFolderSession * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_IMAP_TYPE_FOLDER_SESSION, GearyImapFolderSession);
	_g_object_unref0 (self->priv->_folder);
	_g_object_unref0 (self->priv->_permanent_flags);
	_g_object_unref0 (self->priv->mailbox);
	_g_object_unref0 (self->priv->quirks);
	_g_object_unref0 (self->priv->cmd_mutex);
	_g_object_unref0 (self->priv->fetch_accumulator);
	_g_object_unref0 (self->priv->search_accumulator);
	G_OBJECT_CLASS (geary_imap_folder_session_parent_class)->finalize (obj);
}

/**
 * An interface between the high-level engine API and an IMAP mailbox.
 *
 * Because of the complexities of the IMAP protocol, class takes
 * common operations that a Geary.Folder implementation would need
 * (in particular, {@link Geary.ImapEngine.MinimalFolder}) and makes
 * them into simple async calls.
 *
 * When constructed, this class will issue an IMAP SELECT command for
 * the mailbox represented by this folder, placing the session in the
 * Selected state.
 */
 G_GNUC_NO_INLINE static GType
geary_imap_folder_session_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapFolderSessionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_folder_session_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapFolderSession), 0, (GInstanceInitFunc) geary_imap_folder_session_instance_init, NULL };
	GType geary_imap_folder_session_type_id;
	geary_imap_folder_session_type_id = g_type_register_static (GEARY_IMAP_TYPE_SESSION_OBJECT, "GearyImapFolderSession", &g_define_type_info, 0);
	GearyImapFolderSession_private_offset = g_type_add_instance_private (geary_imap_folder_session_type_id, sizeof (GearyImapFolderSessionPrivate));
	return geary_imap_folder_session_type_id;
}

GType
geary_imap_folder_session_get_type (void)
{
	static gsize geary_imap_folder_session_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_folder_session_type_id__once)) {
		GType geary_imap_folder_session_type_id;
		geary_imap_folder_session_type_id = geary_imap_folder_session_get_type_once ();
		g_once_init_leave (&geary_imap_folder_session_type_id__once, geary_imap_folder_session_type_id);
	}
	return geary_imap_folder_session_type_id__once;
}

static void
_vala_geary_imap_folder_session_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	GearyImapFolderSession * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_TYPE_FOLDER_SESSION, GearyImapFolderSession);
	switch (property_id) {
		case GEARY_IMAP_FOLDER_SESSION_FOLDER_PROPERTY:
		g_value_set_object (value, geary_imap_folder_session_get_folder (self));
		break;
		case GEARY_IMAP_FOLDER_SESSION_READONLY_PROPERTY:
		g_value_set_enum (value, geary_imap_folder_session_get_readonly (self));
		break;
		case GEARY_IMAP_FOLDER_SESSION_PERMANENT_FLAGS_PROPERTY:
		g_value_set_object (value, geary_imap_folder_session_get_permanent_flags (self));
		break;
		case GEARY_IMAP_FOLDER_SESSION_ACCEPTS_USER_FLAGS_PROPERTY:
		g_value_set_enum (value, geary_imap_folder_session_get_accepts_user_flags (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_geary_imap_folder_session_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec)
{
	GearyImapFolderSession * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_TYPE_FOLDER_SESSION, GearyImapFolderSession);
	switch (property_id) {
		case GEARY_IMAP_FOLDER_SESSION_FOLDER_PROPERTY:
		geary_imap_folder_session_set_folder (self, g_value_get_object (value));
		break;
		case GEARY_IMAP_FOLDER_SESSION_READONLY_PROPERTY:
		geary_imap_folder_session_set_readonly (self, g_value_get_enum (value));
		break;
		case GEARY_IMAP_FOLDER_SESSION_PERMANENT_FLAGS_PROPERTY:
		geary_imap_folder_session_set_permanent_flags (self, g_value_get_object (value));
		break;
		case GEARY_IMAP_FOLDER_SESSION_ACCEPTS_USER_FLAGS_PROPERTY:
		geary_imap_folder_session_set_accepts_user_flags (self, g_value_get_enum (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);
}

