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

/*
 * Copyright © 2016 Software Freedom Conservancy Inc.
 * Copyright © 2019-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.h>
#include <gee.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <gobject/gvaluecollector.h>

enum  {
	GEARY_IMAP_CLIENT_SESSION_0_PROPERTY,
	GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_PROPERTY,
	GEARY_IMAP_CLIENT_SESSION_DISCONNECTED_PROPERTY,
	GEARY_IMAP_CLIENT_SESSION_CAPABILITIES_PROPERTY,
	GEARY_IMAP_CLIENT_SESSION_IS_IDLE_SUPPORTED_PROPERTY,
	GEARY_IMAP_CLIENT_SESSION_SERVER_GREETING_PROPERTY,
	GEARY_IMAP_CLIENT_SESSION_LOGGING_PARENT_PROPERTY,
	GEARY_IMAP_CLIENT_SESSION_LAST_SEEN_PROPERTY,
	GEARY_IMAP_CLIENT_SESSION_INBOX_PROPERTY,
	GEARY_IMAP_CLIENT_SESSION_QUIRKS_PROPERTY,
	GEARY_IMAP_CLIENT_SESSION_NUM_PROPERTIES
};
static GParamSpec* geary_imap_client_session_properties[GEARY_IMAP_CLIENT_SESSION_NUM_PROPERTIES];
typedef enum  {
	GEARY_IMAP_CLIENT_SESSION_STATE_NOT_CONNECTED,
	GEARY_IMAP_CLIENT_SESSION_STATE_NOAUTH,
	GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZED,
	GEARY_IMAP_CLIENT_SESSION_STATE_SELECTED,
	GEARY_IMAP_CLIENT_SESSION_STATE_LOGOUT,
	GEARY_IMAP_CLIENT_SESSION_STATE_CONNECTING,
	GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZING,
	GEARY_IMAP_CLIENT_SESSION_STATE_SELECTING,
	GEARY_IMAP_CLIENT_SESSION_STATE_CLOSING_MAILBOX,
	GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED,
	GEARY_IMAP_CLIENT_SESSION_STATE_COUNT
} GearyImapClientSessionState;

#define GEARY_IMAP_CLIENT_SESSION_TYPE_STATE (geary_imap_client_session_state_get_type ())
typedef enum  {
	GEARY_IMAP_CLIENT_SESSION_EVENT_CONNECT,
	GEARY_IMAP_CLIENT_SESSION_EVENT_DISCONNECT,
	GEARY_IMAP_CLIENT_SESSION_EVENT_LOGIN,
	GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_CMD,
	GEARY_IMAP_CLIENT_SESSION_EVENT_SELECT,
	GEARY_IMAP_CLIENT_SESSION_EVENT_CLOSE_MAILBOX,
	GEARY_IMAP_CLIENT_SESSION_EVENT_LOGOUT,
	GEARY_IMAP_CLIENT_SESSION_EVENT_CONNECTED,
	GEARY_IMAP_CLIENT_SESSION_EVENT_DISCONNECTED,
	GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_STATUS,
	GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_COMPLETION,
	GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_ERROR,
	GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_ERROR,
	GEARY_IMAP_CLIENT_SESSION_EVENT_TIMEOUT,
	GEARY_IMAP_CLIENT_SESSION_EVENT_COUNT
} GearyImapClientSessionEvent;

#define GEARY_IMAP_CLIENT_SESSION_TYPE_EVENT (geary_imap_client_session_event_get_type ())
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#define GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS (geary_imap_client_session_machine_params_get_type ())
#define GEARY_IMAP_CLIENT_SESSION_MACHINE_PARAMS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS, GearyImapClientSessionMachineParams))
#define GEARY_IMAP_CLIENT_SESSION_MACHINE_PARAMS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS, GearyImapClientSessionMachineParamsClass))
#define GEARY_IMAP_CLIENT_SESSION_IS_MACHINE_PARAMS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS))
#define GEARY_IMAP_CLIENT_SESSION_IS_MACHINE_PARAMS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS))
#define GEARY_IMAP_CLIENT_SESSION_MACHINE_PARAMS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS, GearyImapClientSessionMachineParamsClass))

typedef struct _GearyImapClientSessionMachineParams GearyImapClientSessionMachineParams;
typedef struct _GearyImapClientSessionMachineParamsClass GearyImapClientSessionMachineParamsClass;
typedef struct _GearyImapClientSessionMachineParamsPrivate GearyImapClientSessionMachineParamsPrivate;
typedef struct _GearyImapClientSessionConnectAsyncData GearyImapClientSessionConnectAsyncData;
typedef struct _GearyImapClientSessionLoginAsyncData GearyImapClientSessionLoginAsyncData;
typedef struct _Block32Data Block32Data;
typedef struct _GearyImapClientSessionInitiateSessionAsyncData GearyImapClientSessionInitiateSessionAsyncData;
typedef struct _GearyImapClientSessionSendCommandAsyncData GearyImapClientSessionSendCommandAsyncData;

#define GEARY_IMAP_CLIENT_SESSION_TYPE_SEND_COMMAND_OPERATION (geary_imap_client_session_send_command_operation_get_type ())
#define GEARY_IMAP_CLIENT_SESSION_SEND_COMMAND_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_CLIENT_SESSION_TYPE_SEND_COMMAND_OPERATION, GearyImapClientSessionSendCommandOperation))
#define GEARY_IMAP_CLIENT_SESSION_SEND_COMMAND_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_CLIENT_SESSION_TYPE_SEND_COMMAND_OPERATION, GearyImapClientSessionSendCommandOperationClass))
#define GEARY_IMAP_CLIENT_SESSION_IS_SEND_COMMAND_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_CLIENT_SESSION_TYPE_SEND_COMMAND_OPERATION))
#define GEARY_IMAP_CLIENT_SESSION_IS_SEND_COMMAND_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_CLIENT_SESSION_TYPE_SEND_COMMAND_OPERATION))
#define GEARY_IMAP_CLIENT_SESSION_SEND_COMMAND_OPERATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_CLIENT_SESSION_TYPE_SEND_COMMAND_OPERATION, GearyImapClientSessionSendCommandOperationClass))

typedef struct _GearyImapClientSessionSendCommandOperation GearyImapClientSessionSendCommandOperation;
typedef struct _GearyImapClientSessionSendCommandOperationClass GearyImapClientSessionSendCommandOperationClass;
typedef struct _GearyImapClientSessionSendCommandOperationPrivate GearyImapClientSessionSendCommandOperationPrivate;
typedef struct _GearyImapClientSessionSendMultipleCommandsAsyncData GearyImapClientSessionSendMultipleCommandsAsyncData;
typedef struct _GearyImapClientSessionSelectAsyncData GearyImapClientSessionSelectAsyncData;
typedef struct _GearyImapClientSessionExamineAsyncData GearyImapClientSessionExamineAsyncData;
typedef struct _GearyImapClientSessionSelectExamineAsyncData GearyImapClientSessionSelectExamineAsyncData;
typedef struct _GearyImapClientSessionCloseMailboxAsyncData GearyImapClientSessionCloseMailboxAsyncData;
typedef struct _GearyImapClientSessionLogoutAsyncData GearyImapClientSessionLogoutAsyncData;
typedef struct _GearyImapClientSessionDisconnectAsyncData GearyImapClientSessionDisconnectAsyncData;
#define _geary_logging_state_unref0(var) ((var == NULL) ? NULL : (var = (geary_logging_state_unref (var), NULL)))
typedef struct _GearyImapClientSessionDoDisconnectData GearyImapClientSessionDoDisconnectData;
typedef struct _GearyImapClientSessionSubmitCommandData GearyImapClientSessionSubmitCommandData;
enum  {
	GEARY_IMAP_CLIENT_SESSION_MACHINE_PARAMS_0_PROPERTY,
	GEARY_IMAP_CLIENT_SESSION_MACHINE_PARAMS_NUM_PROPERTIES
};
static GParamSpec* geary_imap_client_session_machine_params_properties[GEARY_IMAP_CLIENT_SESSION_MACHINE_PARAMS_NUM_PROPERTIES];

#define GEARY_IMAP_CLIENT_SESSION_TYPE_COMMAND_CALLBACK (geary_imap_client_session_command_callback_get_type ())
#define GEARY_IMAP_CLIENT_SESSION_COMMAND_CALLBACK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_CLIENT_SESSION_TYPE_COMMAND_CALLBACK, GearyImapClientSessionCommandCallback))
#define GEARY_IMAP_CLIENT_SESSION_COMMAND_CALLBACK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_CLIENT_SESSION_TYPE_COMMAND_CALLBACK, GearyImapClientSessionCommandCallbackClass))
#define GEARY_IMAP_CLIENT_SESSION_IS_COMMAND_CALLBACK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_CLIENT_SESSION_TYPE_COMMAND_CALLBACK))
#define GEARY_IMAP_CLIENT_SESSION_IS_COMMAND_CALLBACK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_CLIENT_SESSION_TYPE_COMMAND_CALLBACK))
#define GEARY_IMAP_CLIENT_SESSION_COMMAND_CALLBACK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_CLIENT_SESSION_TYPE_COMMAND_CALLBACK, GearyImapClientSessionCommandCallbackClass))

typedef struct _GearyImapClientSessionCommandCallback GearyImapClientSessionCommandCallback;
typedef struct _GearyImapClientSessionCommandCallbackClass GearyImapClientSessionCommandCallbackClass;
typedef struct _GearyImapClientSessionCommandCallbackPrivate GearyImapClientSessionCommandCallbackPrivate;
typedef struct _GearyImapClientSessionParamSpecCommandCallback GearyImapClientSessionParamSpecCommandCallback;
enum  {
	GEARY_IMAP_CLIENT_SESSION_SEND_COMMAND_OPERATION_0_PROPERTY,
	GEARY_IMAP_CLIENT_SESSION_SEND_COMMAND_OPERATION_NUM_PROPERTIES
};
static GParamSpec* geary_imap_client_session_send_command_operation_properties[GEARY_IMAP_CLIENT_SESSION_SEND_COMMAND_OPERATION_NUM_PROPERTIES];
typedef struct _GearyImapClientSessionSendCommandOperationExecuteAsyncData GearyImapClientSessionSendCommandOperationExecuteAsyncData;
enum  {
	GEARY_IMAP_CLIENT_SESSION_STATUS_RESPONSE_RECEIVED_SIGNAL,
	GEARY_IMAP_CLIENT_SESSION_EXISTS_SIGNAL,
	GEARY_IMAP_CLIENT_SESSION_EXPUNGE_SIGNAL,
	GEARY_IMAP_CLIENT_SESSION_FETCH_SIGNAL,
	GEARY_IMAP_CLIENT_SESSION_FLAGS_SIGNAL,
	GEARY_IMAP_CLIENT_SESSION_LIST_SIGNAL,
	GEARY_IMAP_CLIENT_SESSION_RECENT_SIGNAL,
	GEARY_IMAP_CLIENT_SESSION_SEARCH_SIGNAL,
	GEARY_IMAP_CLIENT_SESSION_STATUS_SIGNAL,
	GEARY_IMAP_CLIENT_SESSION_NUM_SIGNALS
};
static guint geary_imap_client_session_signals[GEARY_IMAP_CLIENT_SESSION_NUM_SIGNALS] = {0};
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _GearyImapClientSessionPrivate {
	GearyImapClientSessionDisconnectReason _disconnected;
	GearyImapCapabilities* _capabilities;
	GearyImapStatusResponse* _server_greeting;
	GearyLoggingSource* _logging_parent;
	gint64 _last_seen;
	GearyImapMailboxInformation* _inbox;
	GearyImapQuirks* _quirks;
	GeeList* personal_namespaces;
	GeeList* user_namespaces;
	GeeList* shared_namespaces;
	GearyEndpoint* imap_endpoint;
	GearyStateMachine* fsm;
	GearyImapClientConnection* cx;
	guint keepalive_id;
	guint selected_keepalive_secs;
	guint unselected_keepalive_secs;
	guint selected_with_idle_keepalive_secs;
	GearyImapCommand* state_change_cmd;
	GearyNonblockingSemaphore* connect_waiter;
	GError* connect_err;
	GeeMap* namespaces;
};

struct _GearyImapClientSessionMachineParams {
	GObject parent_instance;
	GearyImapCommand* cmd;
	GError* err;
	gboolean proceed;
	GearyImapClientSessionMachineParamsPrivate * priv;
};

struct _GearyImapClientSessionMachineParamsClass {
	GObjectClass parent_class;
};

struct _GearyImapClientSessionConnectAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapClientSession* self;
	guint greeting_timeout_sec;
	GCancellable* cancellable;
	GearyImapClientSessionMachineParams* params;
	GearyImapClientSessionMachineParams* _tmp0_;
	GearyStateMachine* _tmp1_;
	GearyImapClientSessionMachineParams* _tmp2_;
	GearyImapClientSessionMachineParams* _tmp3_;
	GError* _tmp4_;
	GearyImapClientSessionMachineParams* _tmp5_;
	GError* _tmp6_;
	GError* _tmp7_;
	GearyImapClientSessionMachineParams* _tmp8_;
	GearyImapClientConnection* _tmp9_;
	GearyNonblockingSemaphore* _tmp10_;
	GearyImapClientConnection* _tmp11_;
	GearyStateMachine* _tmp12_;
	GError* err;
	GearyStateMachine* _tmp13_;
	GError* _tmp14_;
	GError* _tmp15_;
	GError* _tmp16_;
	GearySchedulerScheduled* timeout;
	GearySchedulerScheduled* _tmp17_;
	GearyNonblockingSemaphore* _tmp18_;
	GError* _vala1_err;
	GError* _tmp19_;
	GError* _tmp20_;
	GearySchedulerScheduled* _tmp21_;
	GError* _tmp22_;
	GError* _vala2_err;
	GError* _tmp23_;
	const gchar* _tmp24_;
	GError* _tmp25_;
	GError* _tmp26_;
	GError* _inner_error0_;
};

struct _GearyImapClientSessionLoginAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapClientSession* self;
	GearyCredentials* credentials;
	GCancellable* cancellable;
	GearyImapStatusResponse* result;
	GearyImapCommand* cmd;
	GearyCredentialsMethod _tmp0_;
	GearyCredentialsMethod _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	GearyImapLoginCommand* _tmp6_;
	GearyImapCapabilities* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	GError* _tmp10_;
	GError* _tmp11_;
	const gchar* _tmp12_;
	const gchar* _tmp13_;
	const gchar* _tmp14_;
	const gchar* _tmp15_;
	GearyImapAuthenticateCommand* _tmp16_;
	GearyCredentialsMethod _tmp17_;
	GearyCredentialsMethod _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	GError* _tmp23_;
	GError* _tmp24_;
	GearyImapClientSessionMachineParams* params;
	GearyImapCommand* _tmp25_;
	GearyImapClientSessionMachineParams* _tmp26_;
	GearyStateMachine* _tmp27_;
	GearyImapClientSessionMachineParams* _tmp28_;
	GearyImapClientSessionMachineParams* _tmp29_;
	GError* _tmp30_;
	GearyImapClientSessionMachineParams* _tmp31_;
	GError* _tmp32_;
	GError* _tmp33_;
	GearyImapClientSessionMachineParams* _tmp34_;
	GearyImapStatusResponse* response;
	GearyImapCommand* _tmp35_;
	GearyImapStatusResponse* _tmp36_;
	GearyImapStatusResponse* _tmp37_;
	GearyImapStatus _tmp38_;
	GearyImapStatus _tmp39_;
	GearyImapResponseCode* code;
	GearyImapStatusResponse* _tmp40_;
	GearyImapResponseCode* _tmp41_;
	GearyImapResponseCode* _tmp42_;
	GearyImapResponseCode* _tmp43_;
	GearyImapResponseCode* _tmp44_;
	GearyImapResponseCodeType* code_type;
	GearyImapResponseCode* _tmp45_;
	GearyImapResponseCodeType* _tmp46_;
	GearyImapResponseCodeType* _tmp47_;
	GearyImapResponseCodeType* _tmp48_;
	const gchar* _tmp49_;
	const gchar* _tmp50_;
	const gchar* _tmp51_;
	GQuark _tmp53_;
	GearyImapStatusResponse* _tmp54_;
	gchar* _tmp55_;
	gchar* _tmp56_;
	GError* _tmp57_;
	GError* _tmp58_;
	GearyImapStatusResponse* _tmp59_;
	gchar* _tmp60_;
	gchar* _tmp61_;
	GError* _tmp62_;
	GError* _tmp63_;
	GearyImapStatusResponse* _tmp64_;
	gchar* _tmp65_;
	gchar* _tmp66_;
	GError* _tmp67_;
	GError* _tmp68_;
	GearyImapCommand* _tmp69_;
	GearyImapStatusResponse* _tmp70_;
	GearyImapStatusResponse* _tmp71_;
	GearyImapStatusResponse* _tmp72_;
	GError* _inner_error0_;
};

struct _Block32Data {
	int _ref_count_;
	GearyImapClientSession* self;
	GeeArrayList* list_results;
	gpointer _async_data_;
};

struct _GearyImapClientSessionInitiateSessionAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapClientSession* self;
	GearyCredentials* credentials;
	GCancellable* cancellable;
	Block32Data* _data32_;
	GearyImapCapabilities* _tmp0_;
	GearyImapCapabilityCommand* _tmp1_;
	GearyImapCapabilityCommand* _tmp2_;
	GearyImapStatusResponse* _tmp3_;
	GearyImapStatusResponse* _tmp4_;
	gint last_capabilities;
	GearyImapCapabilities* _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	GearyEndpoint* _tmp8_;
	GearyTlsNegotiationMethod _tmp9_;
	GearyTlsNegotiationMethod _tmp10_;
	GearyImapCapabilities* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	GError* _tmp14_;
	GError* _tmp15_;
	GearyImapStatusResponse* resp;
	GearyImapStarttlsCommand* _tmp16_;
	GearyImapStarttlsCommand* _tmp17_;
	GearyImapStatusResponse* _tmp18_;
	GearyImapStatusResponse* _tmp19_;
	GearyImapStatusResponse* _tmp20_;
	GearyImapStatus _tmp21_;
	GearyImapStatus _tmp22_;
	GearyImapClientConnection* _tmp23_;
	gchar* _tmp24_;
	gchar* _tmp25_;
	GearyImapStatusResponse* _tmp26_;
	GearyImapStatus _tmp27_;
	GearyImapStatus _tmp28_;
	gchar* _tmp29_;
	gchar* _tmp30_;
	GError* _tmp31_;
	GError* _tmp32_;
	GearyImapCapabilities* _tmp33_;
	gint _tmp34_;
	gint _tmp35_;
	GearyImapCapabilityCommand* _tmp36_;
	GearyImapCapabilityCommand* _tmp37_;
	GearyImapStatusResponse* _tmp38_;
	GearyImapStatusResponse* _tmp39_;
	GearyImapCapabilities* _tmp40_;
	gint _tmp41_;
	gint _tmp42_;
	GearyImapStatusResponse* _tmp43_;
	GearyImapStatusResponse* _tmp44_;
	GearyImapCapabilities* _tmp45_;
	gint _tmp46_;
	gint _tmp47_;
	GearyImapCapabilityCommand* _tmp48_;
	GearyImapCapabilityCommand* _tmp49_;
	GearyImapStatusResponse* _tmp50_;
	GearyImapStatusResponse* _tmp51_;
	GeeArrayList* _tmp52_;
	gulong list_id;
	gulong _tmp53_;
	GearyImapStatusResponse* response;
	GearyImapMailboxSpecifier* _tmp54_;
	GearyImapMailboxSpecifier* _tmp55_;
	GearyImapListCommand* _tmp56_;
	GearyImapListCommand* _tmp57_;
	GearyImapStatusResponse* _tmp58_;
	GearyImapStatusResponse* _tmp59_;
	gboolean _tmp60_;
	GearyImapStatusResponse* _tmp61_;
	GearyImapStatus _tmp62_;
	GearyImapStatus _tmp63_;
	GeeArrayList* _tmp64_;
	gboolean _tmp65_;
	gboolean _tmp66_;
	GeeArrayList* _tmp67_;
	gpointer _tmp68_;
	GearyImapMailboxInformation* _tmp69_;
	GeeArrayList* _tmp70_;
	GearyImapMailboxInformation* _tmp71_;
	gchar* _tmp72_;
	gchar* _tmp73_;
	GError* _tmp74_;
	GearyImapCapabilities* _tmp75_;
	GearyImapStatusResponse* _tmp76_;
	GearyImapNamespaceCommand* _tmp77_;
	GearyImapNamespaceCommand* _tmp78_;
	GearyImapStatusResponse* _tmp79_;
	GearyImapStatusResponse* _tmp80_;
	GearyImapStatusResponse* _tmp81_;
	GearyImapStatusResponse* _tmp82_;
	GearyImapStatus _tmp83_;
	GearyImapStatus _tmp84_;
	GeeList* _tmp85_;
	gboolean _tmp86_;
	gboolean _tmp87_;
	GeeList* _tmp88_;
	gpointer _tmp89_;
	GearyImapNamespace* _tmp90_;
	gchar* _tmp91_;
	gchar* _tmp92_;
	gchar* prefix;
	gchar* _tmp93_;
	gchar* delim;
	GearyImapMailboxInformation* _tmp94_;
	const gchar* _tmp95_;
	const gchar* _tmp96_;
	gchar* _tmp97_;
	gboolean _tmp98_;
	GearyImapMailboxInformation* _tmp99_;
	GearyImapMailboxAttributes* _tmp100_;
	GearyImapMailboxAttributes* _tmp101_;
	GearyImapMailboxAttribute* _tmp102_;
	GearyImapMailboxAttribute* _tmp103_;
	GearyImapMailboxInformation* _tmp104_;
	const gchar* _tmp105_;
	const gchar* _tmp106_;
	GearyImapMailboxInformation* _tmp107_;
	GearyImapMailboxSpecifier* _tmp108_;
	GearyImapMailboxSpecifier* _tmp109_;
	const gchar* _tmp110_;
	const gchar* _tmp111_;
	gchar* _tmp112_;
	const gchar* _tmp113_;
	GearyImapStatusResponse* _tmp114_;
	const gchar* _tmp115_;
	GearyImapMailboxSpecifier* _tmp116_;
	GearyImapMailboxSpecifier* _tmp117_;
	GearyImapListCommand* _tmp118_;
	GearyImapListCommand* _tmp119_;
	GearyImapStatusResponse* _tmp120_;
	GearyImapStatusResponse* _tmp121_;
	GearyImapStatusResponse* _tmp122_;
	gboolean _tmp123_;
	GearyImapStatusResponse* _tmp124_;
	GearyImapStatus _tmp125_;
	GearyImapStatus _tmp126_;
	GeeArrayList* _tmp127_;
	gboolean _tmp128_;
	gboolean _tmp129_;
	GearyImapMailboxInformation* list;
	GeeArrayList* _tmp130_;
	gpointer _tmp131_;
	GearyImapMailboxInformation* _tmp132_;
	const gchar* _tmp133_;
	const gchar* _tmp134_;
	gchar* _tmp135_;
	GError* _tmp136_;
	GeeList* _tmp137_;
	const gchar* _tmp138_;
	const gchar* _tmp139_;
	GearyImapNamespace* _tmp140_;
	GearyImapNamespace* _tmp141_;
	GeeList* _tmp142_;
	gpointer _tmp143_;
	GearyImapNamespace* _tmp144_;
	gchar* _tmp145_;
	gchar* _tmp146_;
	GError* _inner_error1_;
	GError* _inner_error0_;
};

struct _GearyImapClientSessionSendCommandAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapClientSession* self;
	GearyImapCommand* cmd;
	GearyImapStatusResponse* result;
	GearyImapClientSessionMachineParams* params;
	GearyImapClientSessionMachineParams* _tmp0_;
	GearyStateMachine* _tmp1_;
	GearyImapClientSessionMachineParams* _tmp2_;
	GearyImapClientSessionMachineParams* _tmp3_;
	GError* _tmp4_;
	GearyImapClientSessionMachineParams* _tmp5_;
	GError* _tmp6_;
	GError* _tmp7_;
	GearyImapClientSessionMachineParams* _tmp8_;
	GearyImapStatusResponse* _tmp9_;
	GearyImapStatusResponse* _tmp10_;
	GearyImapStatusResponse* _tmp11_;
	GError* _inner_error0_;
};

struct _GearyImapClientSessionSendCommandOperation {
	GearyNonblockingBatchOperation parent_instance;
	GearyImapClientSession* owner;
	GearyImapCommand* cmd;
	GearyImapStatusResponse* response;
	GearyImapClientSessionSendCommandOperationPrivate * priv;
};

struct _GearyImapClientSessionSendCommandOperationClass {
	GearyNonblockingBatchOperationClass parent_class;
};

struct _GearyImapClientSessionSendMultipleCommandsAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapClientSession* self;
	GeeCollection* cmds;
	GCancellable* cancellable;
	GeeMap* result;
	gint _tmp0_;
	gint _tmp1_;
	GError* _tmp2_;
	GeeIterator* _cmd_it;
	GeeIterator* _tmp3_;
	GeeIterator* _tmp4_;
	GearyImapCommand* cmd;
	GeeIterator* _tmp5_;
	gpointer _tmp6_;
	GearyImapCommand* _tmp7_;
	GearyImapClientSessionMachineParams* params;
	gpointer _tmp8_;
	GearyImapCommand* _tmp9_;
	GearyImapClientSessionMachineParams* _tmp10_;
	GearyImapClientSessionMachineParams* _tmp11_;
	GearyStateMachine* _tmp12_;
	GearyImapClientSessionMachineParams* _tmp13_;
	GearyImapClientSessionMachineParams* _tmp14_;
	GError* _tmp15_;
	GearyImapClientSessionMachineParams* _tmp16_;
	GError* _tmp17_;
	GError* _tmp18_;
	GearyImapClientSessionMachineParams* _tmp19_;
	guint max_batch_size;
	GearyImapQuirks* _tmp20_;
	guint _tmp21_;
	guint _tmp22_;
	gint _tmp23_;
	gint _tmp24_;
	GeeIterator* cmd_remaining;
	GeeIterator* _tmp25_;
	GearyNonblockingBatch* batch;
	GeeMap* responses;
	GeeHashMap* _tmp26_;
	GeeIterator* _tmp27_;
	GearyNonblockingBatch* _tmp28_;
	gboolean _tmp29_;
	GeeIterator* _tmp30_;
	GearyNonblockingBatch* _tmp31_;
	gint _tmp32_;
	gint _tmp33_;
	GeeIterator* _tmp34_;
	GearyNonblockingBatch* _tmp35_;
	GeeIterator* _tmp36_;
	gpointer _tmp37_;
	GearyImapCommand* _tmp38_;
	GearyImapClientSessionSendCommandOperation* _tmp39_;
	GearyImapClientSessionSendCommandOperation* _tmp40_;
	GearyNonblockingBatch* _tmp41_;
	GearyNonblockingBatch* _tmp42_;
	GeeIterator* _id_it;
	GearyNonblockingBatch* _tmp43_;
	GeeSet* _tmp44_;
	GeeSet* _tmp45_;
	GeeIterator* _tmp46_;
	GeeIterator* _tmp47_;
	GeeIterator* _tmp48_;
	gint id;
	GeeIterator* _tmp49_;
	gpointer _tmp50_;
	GearyImapClientSessionSendCommandOperation* op;
	GearyNonblockingBatch* _tmp51_;
	GearyNonblockingBatchOperation* _tmp52_;
	GeeMap* _tmp53_;
	GearyImapClientSessionSendCommandOperation* _tmp54_;
	GearyImapCommand* _tmp55_;
	GearyImapClientSessionSendCommandOperation* _tmp56_;
	GearyImapStatusResponse* _tmp57_;
	GError* _inner_error0_;
};

struct _GearyImapClientSessionSelectAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapClientSession* self;
	GearyImapMailboxSpecifier* mailbox;
	GCancellable* cancellable;
	GearyImapStatusResponse* result;
	GearyImapStatusResponse* _tmp0_;
	GearyImapStatusResponse* _tmp1_;
	GearyImapStatusResponse* _tmp2_;
	GError* _inner_error0_;
};

struct _GearyImapClientSessionExamineAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapClientSession* self;
	GearyImapMailboxSpecifier* mailbox;
	GCancellable* cancellable;
	GearyImapStatusResponse* result;
	GearyImapStatusResponse* _tmp0_;
	GearyImapStatusResponse* _tmp1_;
	GearyImapStatusResponse* _tmp2_;
	GError* _inner_error0_;
};

struct _GearyImapClientSessionSelectExamineAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapClientSession* self;
	GearyImapMailboxSpecifier* mailbox;
	gboolean is_select;
	GCancellable* cancellable;
	GearyImapStatusResponse* result;
	GearyImapCommand* cmd;
	GearyImapSelectCommand* _tmp0_;
	GearyImapExamineCommand* _tmp1_;
	GearyImapClientSessionMachineParams* params;
	GearyImapCommand* _tmp2_;
	GearyImapClientSessionMachineParams* _tmp3_;
	GearyStateMachine* _tmp4_;
	GearyImapClientSessionMachineParams* _tmp5_;
	GearyImapClientSessionMachineParams* _tmp6_;
	GError* _tmp7_;
	GearyImapClientSessionMachineParams* _tmp8_;
	GError* _tmp9_;
	GError* _tmp10_;
	GearyImapClientSessionMachineParams* _tmp11_;
	GearyImapStatusResponse* _tmp12_;
	GearyImapCommand* _tmp13_;
	GearyImapStatusResponse* _tmp14_;
	GearyImapStatusResponse* _tmp15_;
	GError* _inner_error0_;
};

struct _GearyImapClientSessionCloseMailboxAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapClientSession* self;
	GCancellable* cancellable;
	GearyImapStatusResponse* result;
	GearyImapCloseCommand* cmd;
	GearyImapCloseCommand* _tmp0_;
	GearyImapClientSessionMachineParams* params;
	GearyImapCloseCommand* _tmp1_;
	GearyImapClientSessionMachineParams* _tmp2_;
	GearyStateMachine* _tmp3_;
	GearyImapClientSessionMachineParams* _tmp4_;
	GearyImapClientSessionMachineParams* _tmp5_;
	GError* _tmp6_;
	GearyImapClientSessionMachineParams* _tmp7_;
	GError* _tmp8_;
	GError* _tmp9_;
	GearyImapStatusResponse* _tmp10_;
	GearyImapCloseCommand* _tmp11_;
	GearyImapStatusResponse* _tmp12_;
	GearyImapStatusResponse* _tmp13_;
	GError* _inner_error0_;
};

struct _GearyImapClientSessionLogoutAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapClientSession* self;
	GCancellable* cancellable;
	GearyImapLogoutCommand* cmd;
	GearyImapLogoutCommand* _tmp0_;
	GearyImapClientSessionMachineParams* params;
	GearyImapClientSessionMachineParams* _tmp1_;
	GearyStateMachine* _tmp2_;
	GError* _tmp3_;
	GError* _tmp4_;
	GError* _tmp5_;
	GearyImapStatusResponse* _tmp6_;
	GearyImapStatusResponse* _tmp7_;
	GError* _inner_error0_;
};

struct _GearyImapClientSessionDisconnectAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapClientSession* self;
	GCancellable* cancellable;
	GearyImapClientSessionMachineParams* params;
	GearyImapClientSessionMachineParams* _tmp0_;
	GearyStateMachine* _tmp1_;
	GError* _tmp2_;
	GError* _tmp3_;
	GError* _tmp4_;
	GError* disconnect_err;
	GearyImapClientConnection* _tmp5_;
	GError* err;
	GError* _tmp6_;
	GError* _tmp7_;
	GError* _tmp8_;
	GError* _tmp9_;
	GError* _tmp10_;
	GError* _inner_error0_;
};

struct _GearyImapClientSessionDoDisconnectData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapClientSession* self;
	GearyImapClientSessionDisconnectReason reason;
	GearyImapClientConnection* _tmp0_;
	GError* err;
	GError* _tmp1_;
	const gchar* _tmp2_;
	GError* _inner_error0_;
};

struct _GearyImapClientSessionSubmitCommandData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapClientSession* self;
	GearyImapCommand* cmd;
	GearyImapStatusResponse* result;
	GearyImapClientConnection* _tmp0_;
	GearyEndpoint* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	GError* _tmp4_;
	GError* _tmp5_;
	GearyImapClientConnection* _tmp6_;
	GearyImapStatusResponse* _tmp7_;
	GearyImapStatusResponse* _tmp8_;
	GearyImapStatusResponse* _tmp9_;
	GError* _inner_error0_;
};

struct _GearyImapClientSessionCommandCallback {
	GTypeInstance parent_instance;
	volatile int ref_count;
	GSourceFunc callback;
	gpointer callback_target;
	GearyImapClientSessionCommandCallbackPrivate * priv;
};

struct _GearyImapClientSessionCommandCallbackClass {
	GTypeClass parent_class;
	void (*finalize) (GearyImapClientSessionCommandCallback *self);
};

struct _GearyImapClientSessionParamSpecCommandCallback {
	GParamSpec parent_instance;
};

struct _GearyImapClientSessionSendCommandOperationExecuteAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapClientSessionSendCommandOperation* self;
	GCancellable* cancellable;
	GObject* result;
	GearyImapStatusResponse* _tmp0_;
	GearyImapClientSession* _tmp1_;
	GearyImapCommand* _tmp2_;
	GearyImapStatusResponse* _tmp3_;
	GearyImapStatusResponse* _tmp4_;
	GearyImapStatusResponse* _tmp5_;
	GObject* _tmp6_;
	GError* _inner_error0_;
};

static gint GearyImapClientSession_private_offset;
static gpointer geary_imap_client_session_parent_class = NULL;
static GearyStateMachineDescriptor* geary_imap_client_session_machine_desc;
static GearyStateMachineDescriptor* geary_imap_client_session_machine_desc = NULL;
static gpointer geary_imap_client_session_machine_params_parent_class = NULL;
static gpointer geary_imap_client_session_command_callback_parent_class = NULL;
static gpointer geary_imap_client_session_send_command_operation_parent_class = NULL;
static GearyLoggingSourceIface * geary_imap_client_session_geary_logging_source_parent_iface = NULL;

static GType geary_imap_client_session_state_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static GType geary_imap_client_session_event_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static gchar* geary_imap_client_session_state_to_string (guint state);
static gchar* geary_imap_client_session_event_to_string (guint event);
static gchar* _geary_imap_client_session_state_to_string_geary_state_state_event_to_string (guint state_or_event,
                                                                                     gpointer self);
static gchar* _geary_imap_client_session_event_to_string_geary_state_state_event_to_string (guint state_or_event,
                                                                                     gpointer self);
static void geary_imap_client_session_set_disconnected (GearyImapClientSession* self,
                                                 GearyImapClientSessionDisconnectReason value);
static void geary_imap_client_session_set_capabilities (GearyImapClientSession* self,
                                                 GearyImapCapabilities* value);
static void geary_imap_client_session_set_server_greeting (GearyImapClientSession* self,
                                                    GearyImapStatusResponse* value);
VALA_EXTERN gint64 geary_imap_client_session_get_last_seen (GearyImapClientSession* self);
static void geary_imap_client_session_set_last_seen (GearyImapClientSession* self,
                                              gint64 value);
VALA_EXTERN GearyImapMailboxInformation* geary_imap_client_session_get_inbox (GearyImapClientSession* self);
static void geary_imap_client_session_set_inbox (GearyImapClientSession* self,
                                          GearyImapMailboxInformation* value);
VALA_EXTERN GearyImapQuirks* geary_imap_client_session_get_quirks (GearyImapClientSession* self);
VALA_EXTERN void geary_imap_client_session_set_quirks (GearyImapClientSession* self,
                                           GearyImapQuirks* value);
static void g_cclosure_user_marshal_VOID__POINTER_INT (GClosure * closure,
                                                GValue * return_value,
                                                guint n_param_values,
                                                const GValue * param_values,
                                                gpointer invocation_hint,
                                                gpointer marshal_data);
static guint geary_imap_client_session_on_connect (GearyImapClientSession* self,
                                            guint state,
                                            guint event,
                                            void* user,
                                            GObject* object);
static guint _geary_imap_client_session_on_connect_geary_state_transition (guint state,
                                                                    guint event,
                                                                    void* user,
                                                                    GObject* object,
                                                                    GError* err,
                                                                    gpointer self);
static guint geary_imap_client_session_on_early_command (GearyImapClientSession* self,
                                                  guint state,
                                                  guint event,
                                                  void* user,
                                                  GObject* object);
static guint _geary_imap_client_session_on_early_command_geary_state_transition (guint state,
                                                                          guint event,
                                                                          void* user,
                                                                          GObject* object,
                                                                          GError* err,
                                                                          gpointer self);
static guint _geary_state_nop_geary_state_transition (guint state,
                                               guint event,
                                               void* user,
                                               GObject* object,
                                               GError* err,
                                               gpointer self);
static guint geary_imap_client_session_on_already_connected (GearyImapClientSession* self,
                                                      guint state,
                                                      guint event,
                                                      void* user,
                                                      GObject* object);
static guint _geary_imap_client_session_on_already_connected_geary_state_transition (guint state,
                                                                              guint event,
                                                                              void* user,
                                                                              GObject* object,
                                                                              GError* err,
                                                                              gpointer self);
static guint geary_imap_client_session_on_disconnect (GearyImapClientSession* self,
                                               guint state,
                                               guint event,
                                               void* user,
                                               GObject* object,
                                               GError* err);
static guint _geary_imap_client_session_on_disconnect_geary_state_transition (guint state,
                                                                       guint event,
                                                                       void* user,
                                                                       GObject* object,
                                                                       GError* err,
                                                                       gpointer self);
static guint geary_imap_client_session_on_connected (GearyImapClientSession* self,
                                              guint state,
                                              guint event);
static guint _geary_imap_client_session_on_connected_geary_state_transition (guint state,
                                                                      guint event,
                                                                      void* user,
                                                                      GObject* object,
                                                                      GError* err,
                                                                      gpointer self);
static guint geary_imap_client_session_on_connecting_recv_status (GearyImapClientSession* self,
                                                           guint state,
                                                           guint event,
                                                           void* user,
                                                           GObject* object);
static guint _geary_imap_client_session_on_connecting_recv_status_geary_state_transition (guint state,
                                                                                   guint event,
                                                                                   void* user,
                                                                                   GObject* object,
                                                                                   GError* err,
                                                                                   gpointer self);
static guint geary_imap_client_session_on_dropped_response (GearyImapClientSession* self,
                                                     guint state,
                                                     guint event,
                                                     void* user,
                                                     GObject* object);
static guint _geary_imap_client_session_on_dropped_response_geary_state_transition (guint state,
                                                                             guint event,
                                                                             void* user,
                                                                             GObject* object,
                                                                             GError* err,
                                                                             gpointer self);
static guint geary_imap_client_session_on_connecting_send_recv_error (GearyImapClientSession* self,
                                                               guint state,
                                                               guint event,
                                                               void* user,
                                                               GObject* object,
                                                               GError* err);
static guint _geary_imap_client_session_on_connecting_send_recv_error_geary_state_transition (guint state,
                                                                                       guint event,
                                                                                       void* user,
                                                                                       GObject* object,
                                                                                       GError* err,
                                                                                       gpointer self);
static guint geary_imap_client_session_on_connecting_timeout (GearyImapClientSession* self,
                                                       guint state,
                                                       guint event);
static guint _geary_imap_client_session_on_connecting_timeout_geary_state_transition (guint state,
                                                                               guint event,
                                                                               void* user,
                                                                               GObject* object,
                                                                               GError* err,
                                                                               gpointer self);
static guint geary_imap_client_session_on_login (GearyImapClientSession* self,
                                          guint state,
                                          guint event,
                                          void* user,
                                          GObject* object);
static guint _geary_imap_client_session_on_login_geary_state_transition (guint state,
                                                                  guint event,
                                                                  void* user,
                                                                  GObject* object,
                                                                  GError* err,
                                                                  gpointer self);
static guint geary_imap_client_session_on_send_command (GearyImapClientSession* self,
                                                 guint state,
                                                 guint event,
                                                 void* user,
                                                 GObject* object);
static guint _geary_imap_client_session_on_send_command_geary_state_transition (guint state,
                                                                         guint event,
                                                                         void* user,
                                                                         GObject* object,
                                                                         GError* err,
                                                                         gpointer self);
static guint geary_imap_client_session_on_unauthenticated (GearyImapClientSession* self,
                                                    guint state,
                                                    guint event,
                                                    void* user,
                                                    GObject* object);
static guint _geary_imap_client_session_on_unauthenticated_geary_state_transition (guint state,
                                                                            guint event,
                                                                            void* user,
                                                                            GObject* object,
                                                                            GError* err,
                                                                            gpointer self);
static guint geary_imap_client_session_on_logout (GearyImapClientSession* self,
                                           guint state,
                                           guint event,
                                           void* user,
                                           GObject* object);
static guint _geary_imap_client_session_on_logout_geary_state_transition (guint state,
                                                                   guint event,
                                                                   void* user,
                                                                   GObject* object,
                                                                   GError* err,
                                                                   gpointer self);
static guint geary_imap_client_session_on_recv_status (GearyImapClientSession* self,
                                                guint state,
                                                guint event,
                                                void* user,
                                                GObject* object);
static guint _geary_imap_client_session_on_recv_status_geary_state_transition (guint state,
                                                                        guint event,
                                                                        void* user,
                                                                        GObject* object,
                                                                        GError* err,
                                                                        gpointer self);
static guint geary_imap_client_session_on_send_error (GearyImapClientSession* self,
                                               guint state,
                                               guint event,
                                               void* user,
                                               GObject* object,
                                               GError* err);
static guint _geary_imap_client_session_on_send_error_geary_state_transition (guint state,
                                                                       guint event,
                                                                       void* user,
                                                                       GObject* object,
                                                                       GError* err,
                                                                       gpointer self);
static guint geary_imap_client_session_on_recv_error (GearyImapClientSession* self,
                                               guint state,
                                               guint event,
                                               void* user,
                                               GObject* object,
                                               GError* err);
static guint _geary_imap_client_session_on_recv_error_geary_state_transition (guint state,
                                                                       guint event,
                                                                       void* user,
                                                                       GObject* object,
                                                                       GError* err,
                                                                       gpointer self);
static guint geary_imap_client_session_on_logging_in (GearyImapClientSession* self,
                                               guint state,
                                               guint event,
                                               void* user,
                                               GObject* object);
static guint _geary_imap_client_session_on_logging_in_geary_state_transition (guint state,
                                                                       guint event,
                                                                       void* user,
                                                                       GObject* object,
                                                                       GError* err,
                                                                       gpointer self);
static guint geary_imap_client_session_on_login_recv_completion (GearyImapClientSession* self,
                                                          guint state,
                                                          guint event,
                                                          void* user,
                                                          GObject* object);
static guint _geary_imap_client_session_on_login_recv_completion_geary_state_transition (guint state,
                                                                                  guint event,
                                                                                  void* user,
                                                                                  GObject* object,
                                                                                  GError* err,
                                                                                  gpointer self);
static guint geary_imap_client_session_on_already_logged_in (GearyImapClientSession* self,
                                                      guint state,
                                                      guint event,
                                                      void* user,
                                                      GObject* object);
static guint _geary_imap_client_session_on_already_logged_in_geary_state_transition (guint state,
                                                                              guint event,
                                                                              void* user,
                                                                              GObject* object,
                                                                              GError* err,
                                                                              gpointer self);
static guint geary_imap_client_session_on_select (GearyImapClientSession* self,
                                           guint state,
                                           guint event,
                                           void* user,
                                           GObject* object);
static guint _geary_imap_client_session_on_select_geary_state_transition (guint state,
                                                                   guint event,
                                                                   void* user,
                                                                   GObject* object,
                                                                   GError* err,
                                                                   gpointer self);
static guint geary_imap_client_session_on_not_selected (GearyImapClientSession* self,
                                                 guint state,
                                                 guint event,
                                                 void* user,
                                                 GObject* object);
static guint _geary_imap_client_session_on_not_selected_geary_state_transition (guint state,
                                                                         guint event,
                                                                         void* user,
                                                                         GObject* object,
                                                                         GError* err,
                                                                         gpointer self);
static guint geary_imap_client_session_on_close_mailbox (GearyImapClientSession* self,
                                                  guint state,
                                                  guint event,
                                                  void* user,
                                                  GObject* object);
static guint _geary_imap_client_session_on_close_mailbox_geary_state_transition (guint state,
                                                                          guint event,
                                                                          void* user,
                                                                          GObject* object,
                                                                          GError* err,
                                                                          gpointer self);
static guint geary_imap_client_session_on_selecting_recv_completion (GearyImapClientSession* self,
                                                              guint state,
                                                              guint event,
                                                              void* user,
                                                              GObject* object);
static guint _geary_imap_client_session_on_selecting_recv_completion_geary_state_transition (guint state,
                                                                                      guint event,
                                                                                      void* user,
                                                                                      GObject* object,
                                                                                      GError* err,
                                                                                      gpointer self);
static guint geary_imap_client_session_on_closing_recv_completion (GearyImapClientSession* self,
                                                            guint state,
                                                            guint event,
                                                            void* user,
                                                            GObject* object);
static guint _geary_imap_client_session_on_closing_recv_completion_geary_state_transition (guint state,
                                                                                    guint event,
                                                                                    void* user,
                                                                                    GObject* object,
                                                                                    GError* err,
                                                                                    gpointer self);
static guint geary_imap_client_session_on_late_command (GearyImapClientSession* self,
                                                 guint state,
                                                 guint event,
                                                 void* user,
                                                 GObject* object);
static guint _geary_imap_client_session_on_late_command_geary_state_transition (guint state,
                                                                         guint event,
                                                                         void* user,
                                                                         GObject* object,
                                                                         GError* err,
                                                                         gpointer self);
static guint geary_imap_client_session_on_logging_out_recv_status (GearyImapClientSession* self,
                                                            guint state,
                                                            guint event,
                                                            void* user,
                                                            GObject* object);
static guint _geary_imap_client_session_on_logging_out_recv_status_geary_state_transition (guint state,
                                                                                    guint event,
                                                                                    void* user,
                                                                                    GObject* object,
                                                                                    GError* err,
                                                                                    gpointer self);
static guint geary_imap_client_session_on_logging_out_recv_completion (GearyImapClientSession* self,
                                                                guint state,
                                                                guint event,
                                                                void* user,
                                                                GObject* object);
static guint _geary_imap_client_session_on_logging_out_recv_completion_geary_state_transition (guint state,
                                                                                        guint event,
                                                                                        void* user,
                                                                                        GObject* object,
                                                                                        GError* err,
                                                                                        gpointer self);
static guint geary_imap_client_session_on_ignored_transition (GearyImapClientSession* self,
                                                       guint state,
                                                       guint event);
static guint _geary_imap_client_session_on_ignored_transition_geary_state_transition (guint state,
                                                                               guint event,
                                                                               void* user,
                                                                               GObject* object,
                                                                               GError* err,
                                                                               gpointer self);
static void __lambda49_ (GearyImapClientSession* self);
static void ___lambda49__g_object_notify (GObject* _sender,
                                   GParamSpec* pspec,
                                   gpointer self);
static GType geary_imap_client_session_machine_params_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static gboolean geary_imap_client_session_reserve_state_change_cmd (GearyImapClientSession* self,
                                                             GearyImapClientSessionMachineParams* params,
                                                             guint state,
                                                             guint event);
static gboolean geary_imap_client_session_validate_state_change_cmd (GearyImapClientSession* self,
                                                              GearyImapServerResponse* response,
                                                              GearyImapCommand** cmd);
static void geary_imap_client_session_connect_async_data_free (gpointer _data);
static gboolean geary_imap_client_session_connect_async_co (GearyImapClientSessionConnectAsyncData* _data_);
static GearyImapClientSessionMachineParams* geary_imap_client_session_machine_params_new (GearyImapCommand* cmd);
static GearyImapClientSessionMachineParams* geary_imap_client_session_machine_params_construct (GType object_type,
                                                                                         GearyImapCommand* cmd);
static void geary_imap_client_session_connect_async_ready (GObject* source_object,
                                                    GAsyncResult* _res_,
                                                    gpointer _user_data_);
static gboolean geary_imap_client_session_on_greeting_timeout (GearyImapClientSession* self);
static gboolean _geary_imap_client_session_on_greeting_timeout_gsource_func (gpointer self);
VALA_EXTERN void geary_imap_client_connection_set_logging_parent (GearyImapClientConnection* self,
                                                      GearyLoggingSource* parent);
static void geary_imap_client_session_on_network_send_error (GearyImapClientSession* self,
                                                      GError* err);
static void _geary_imap_client_session_on_network_send_error_geary_imap_client_connection_send_failure (GearyImapClientConnection* _sender,
                                                                                                 GError* err,
                                                                                                 gpointer self);
static void geary_imap_client_session_on_received_status_response (GearyImapClientSession* self,
                                                            GearyImapStatusResponse* status_response);
static void _geary_imap_client_session_on_received_status_response_geary_imap_client_connection_received_status_response (GearyImapClientConnection* _sender,
                                                                                                                   GearyImapStatusResponse* status_response,
                                                                                                                   gpointer self);
static void geary_imap_client_session_on_received_server_data (GearyImapClientSession* self,
                                                        GearyImapServerData* server_data);
static void _geary_imap_client_session_on_received_server_data_geary_imap_client_connection_received_server_data (GearyImapClientConnection* _sender,
                                                                                                           GearyImapServerData* server_data,
                                                                                                           gpointer self);
static void geary_imap_client_session_on_received_bytes (GearyImapClientSession* self);
static void _geary_imap_client_session_on_received_bytes_geary_imap_client_connection_received_bytes (GearyImapClientConnection* _sender,
                                                                                               gsize bytes,
                                                                                               gpointer self);
static void geary_imap_client_session_on_received_bad_response (GearyImapClientSession* self,
                                                         GearyImapRootParameters* root,
                                                         GError* err);
static void _geary_imap_client_session_on_received_bad_response_geary_imap_client_connection_received_bad_response (GearyImapClientConnection* _sender,
                                                                                                             GearyImapRootParameters* root,
                                                                                                             GError* err,
                                                                                                             gpointer self);
static void geary_imap_client_session_on_network_receive_failure (GearyImapClientSession* self,
                                                           GError* err);
static void _geary_imap_client_session_on_network_receive_failure_geary_imap_client_connection_receive_failure (GearyImapClientConnection* _sender,
                                                                                                         GError* err,
                                                                                                         gpointer self);
static void geary_imap_client_session_drop_connection (GearyImapClientSession* self);
static gboolean geary_imap_client_session_unschedule_keepalive (GearyImapClientSession* self);
static void geary_imap_client_session_login_async_data_free (gpointer _data);
static gboolean geary_imap_client_session_login_async_co (GearyImapClientSessionLoginAsyncData* _data_);
static void geary_imap_client_session_submit_command (GearyImapClientSession* self,
                                               GearyImapCommand* cmd,
                                               GAsyncReadyCallback _callback_,
                                               gpointer _user_data_);
static GearyImapStatusResponse* geary_imap_client_session_submit_command_finish (GearyImapClientSession* self,
                                                                          GAsyncResult* _res_,
                                                                          GError** error);
static void geary_imap_client_session_login_async_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_);
static void geary_imap_client_session_initiate_session_async_data_free (gpointer _data);
static gboolean geary_imap_client_session_initiate_session_async_co (GearyImapClientSessionInitiateSessionAsyncData* _data_);
static Block32Data* block32_data_ref (Block32Data* _data32_);
static void block32_data_unref (void * _userdata_);
static void geary_imap_client_session_initiate_session_async_ready (GObject* source_object,
                                                             GAsyncResult* _res_,
                                                             gpointer _user_data_);
static void __lambda50_ (Block32Data* _data32_,
                  GearyImapMailboxInformation* mailbox);
static void ___lambda50__geary_imap_client_session_list (GearyImapClientSession* _sender,
                                                  GearyImapMailboxInformation* mailbox_info,
                                                  gpointer self);
static void geary_imap_client_session_schedule_keepalive (GearyImapClientSession* self);
static gboolean geary_imap_client_session_on_keepalive (GearyImapClientSession* self);
static gboolean _geary_imap_client_session_on_keepalive_gsource_func (gpointer self);
static void geary_imap_client_session_on_keepalive_completed (GearyImapClientSession* self,
                                                       GObject* source,
                                                       GAsyncResult* _result_);
static void _geary_imap_client_session_on_keepalive_completed_gasync_ready_callback (GObject* source_object,
                                                                              GAsyncResult* res,
                                                                              gpointer self);
static void geary_imap_client_session_send_command_async_data_free (gpointer _data);
static gboolean geary_imap_client_session_send_command_async_co (GearyImapClientSessionSendCommandAsyncData* _data_);
static void geary_imap_client_session_check_unsupported_send_command (GearyImapClientSession* self,
                                                               GearyImapCommand* cmd,
                                                               GError** error);
static void geary_imap_client_session_send_command_async_ready (GObject* source_object,
                                                         GAsyncResult* _res_,
                                                         gpointer _user_data_);
static void geary_imap_client_session_send_multiple_commands_async_data_free (gpointer _data);
static gboolean geary_imap_client_session_send_multiple_commands_async_co (GearyImapClientSessionSendMultipleCommandsAsyncData* _data_);
static GearyImapClientSessionSendCommandOperation* geary_imap_client_session_send_command_operation_new (GearyImapClientSession* owner,
                                                                                                  GearyImapCommand* cmd);
static GearyImapClientSessionSendCommandOperation* geary_imap_client_session_send_command_operation_construct (GType object_type,
                                                                                                        GearyImapClientSession* owner,
                                                                                                        GearyImapCommand* cmd);
static GType geary_imap_client_session_send_command_operation_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static void geary_imap_client_session_send_multiple_commands_async_ready (GObject* source_object,
                                                                   GAsyncResult* _res_,
                                                                   gpointer _user_data_);
static void geary_imap_client_session_do_disconnect (GearyImapClientSession* self,
                                              GearyImapClientSessionDisconnectReason reason,
                                              GAsyncReadyCallback _callback_,
                                              gpointer _user_data_);
static void geary_imap_client_session_do_disconnect_finish (GearyImapClientSession* self,
                                                     GAsyncResult* _res_);
static void geary_imap_client_session_select_async_data_free (gpointer _data);
static gboolean geary_imap_client_session_select_async_co (GearyImapClientSessionSelectAsyncData* _data_);
static void geary_imap_client_session_select_async_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_);
static void geary_imap_client_session_examine_async_data_free (gpointer _data);
static gboolean geary_imap_client_session_examine_async_co (GearyImapClientSessionExamineAsyncData* _data_);
static void geary_imap_client_session_examine_async_ready (GObject* source_object,
                                                    GAsyncResult* _res_,
                                                    gpointer _user_data_);
static void geary_imap_client_session_select_examine_async_data_free (gpointer _data);
static gboolean geary_imap_client_session_select_examine_async_co (GearyImapClientSessionSelectExamineAsyncData* _data_);
static void geary_imap_client_session_select_examine_async_ready (GObject* source_object,
                                                           GAsyncResult* _res_,
                                                           gpointer _user_data_);
static void geary_imap_client_session_close_mailbox_async_data_free (gpointer _data);
static gboolean geary_imap_client_session_close_mailbox_async_co (GearyImapClientSessionCloseMailboxAsyncData* _data_);
static void geary_imap_client_session_close_mailbox_async_ready (GObject* source_object,
                                                          GAsyncResult* _res_,
                                                          gpointer _user_data_);
static void geary_imap_client_session_logout_async_data_free (gpointer _data);
static gboolean geary_imap_client_session_logout_async_co (GearyImapClientSessionLogoutAsyncData* _data_);
static void geary_imap_client_session_logout_async_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_);
static void geary_imap_client_session_clear_namespaces (GearyImapClientSession* self);
static void geary_imap_client_session_disconnect_async_data_free (gpointer _data);
static gboolean geary_imap_client_session_disconnect_async_co (GearyImapClientSessionDisconnectAsyncData* _data_);
static void geary_imap_client_session_disconnect_async_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_);
static gchar* geary_imap_client_session_real_to_string (GearyLoggingSource* base);
static GearyLoggingState* geary_imap_client_session_real_to_logging_state (GearyLoggingSource* base);
VALA_EXTERN void geary_imap_client_session_set_logging_parent (GearyImapClientSession* self,
                                                   GearyLoggingSource* parent);
static void geary_imap_client_session_do_disconnect_data_free (gpointer _data);
static gboolean geary_imap_client_session_do_disconnect_co (GearyImapClientSessionDoDisconnectData* _data_);
static void geary_imap_client_session_do_disconnect_ready (GObject* source_object,
                                                    GAsyncResult* _res_,
                                                    gpointer _user_data_);
static void __lambda48_ (GearyImapClientSession* self);
static void ___lambda48__geary_state_post_transition (void* user,
                                               GObject* object,
                                               GError* err,
                                               gpointer self);
static void geary_imap_client_session_submit_command_data_free (gpointer _data);
static gboolean geary_imap_client_session_submit_command_co (GearyImapClientSessionSubmitCommandData* _data_);
static void geary_imap_client_session_submit_command_ready (GObject* source_object,
                                                     GAsyncResult* _res_,
                                                     gpointer _user_data_);
VALA_EXTERN GearyImapCommand* geary_imap_client_connection_get_sent_command (GearyImapClientConnection* self,
                                                                 GearyImapTag* tag);
static void geary_imap_client_session_notify_received_data (GearyImapClientSession* self,
                                                     GearyImapServerData* server_data,
                                                     GError** error);
static void geary_imap_client_session_update_namespaces (GearyImapClientSession* self,
                                                  GeeList* response,
                                                  GeeList* list);
static void geary_imap_client_session_machine_params_finalize (GObject * obj);
static GType geary_imap_client_session_machine_params_get_type_once (void);
static gpointer geary_imap_client_session_command_callback_ref (gpointer instance);
static void geary_imap_client_session_command_callback_unref (gpointer instance);
static GParamSpec* geary_imap_client_session_param_spec_command_callback (const gchar* name,
                                                                   const gchar* nick,
                                                                   const gchar* blurb,
                                                                   GType object_type,
                                                                   GParamFlags flags) G_GNUC_UNUSED ;
static void geary_imap_client_session_value_set_command_callback (GValue* value,
                                                           gpointer v_object) G_GNUC_UNUSED ;
static void geary_imap_client_session_value_take_command_callback (GValue* value,
                                                            gpointer v_object) G_GNUC_UNUSED ;
static gpointer geary_imap_client_session_value_get_command_callback (const GValue* value) G_GNUC_UNUSED ;
static GType geary_imap_client_session_command_callback_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static GearyImapClientSessionCommandCallback* geary_imap_client_session_command_callback_new (GSourceFunc callback,
                                                                                       gpointer callback_target);
static GearyImapClientSessionCommandCallback* geary_imap_client_session_command_callback_construct (GType object_type,
                                                                                             GSourceFunc callback,
                                                                                             gpointer callback_target);
static void geary_imap_client_session_command_callback_finalize (GearyImapClientSessionCommandCallback * obj);
static GType geary_imap_client_session_command_callback_get_type_once (void);
static void geary_imap_client_session_send_command_operation_real_execute_async_data_free (gpointer _data);
static void geary_imap_client_session_send_command_operation_real_execute_async (GearyNonblockingBatchOperation* base,
                                                                          GCancellable* cancellable,
                                                                          GAsyncReadyCallback _callback_,
                                                                          gpointer _user_data_);
static gboolean geary_imap_client_session_send_command_operation_real_execute_async_co (GearyImapClientSessionSendCommandOperationExecuteAsyncData* _data_);
static void geary_imap_client_session_send_command_operation_execute_async_ready (GObject* source_object,
                                                                           GAsyncResult* _res_,
                                                                           gpointer _user_data_);
static void geary_imap_client_session_send_command_operation_finalize (GObject * obj);
static GType geary_imap_client_session_send_command_operation_get_type_once (void);
static void geary_imap_client_session_finalize (GObject * obj);
static GType geary_imap_client_session_get_type_once (void);
static void _vala_geary_imap_client_session_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);
static void _vala_geary_imap_client_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_client_session_get_instance_private (GearyImapClientSession* self)
{
	return G_STRUCT_MEMBER_P (self, GearyImapClientSession_private_offset);
}

/**
     * The various states an IMAP {@link ClientSession} may be in at any moment.
     *
     * These don't exactly match the states in the IMAP specification.  For one, they count
     * transitions as states unto themselves (due to network latency and the asynchronous nature
     * of ClientSession's interface).  Also, the LOGOUT state has been melded
     * into {@link ProtocolState.NOT_CONNECTED} on the presumption that the nuances of a disconnected or
     * disconnecting session is uninteresting to the caller.
     *
     * See [[http://tools.ietf.org/html/rfc3501#section-3]]
     *
     * @see protocol_state
     */
 G_GNUC_NO_INLINE static GType
geary_imap_client_session_protocol_state_get_type_once (void)
{
	static const GEnumValue values[] = {{GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_NOT_CONNECTED, "GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_NOT_CONNECTED", "not-connected"}, {GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_CONNECTING, "GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_CONNECTING", "connecting"}, {GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_UNAUTHORIZED, "GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_UNAUTHORIZED", "unauthorized"}, {GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_AUTHORIZING, "GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_AUTHORIZING", "authorizing"}, {GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_AUTHORIZED, "GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_AUTHORIZED", "authorized"}, {GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_SELECTING, "GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_SELECTING", "selecting"}, {GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_SELECTED, "GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_SELECTED", "selected"}, {GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_CLOSING_MAILBOX, "GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_CLOSING_MAILBOX", "closing-mailbox"}, {0, NULL, NULL}};
	GType geary_imap_client_session_protocol_state_type_id;
	geary_imap_client_session_protocol_state_type_id = g_enum_register_static ("GearyImapClientSessionProtocolState", values);
	return geary_imap_client_session_protocol_state_type_id;
}

GType
geary_imap_client_session_protocol_state_get_type (void)
{
	static gsize geary_imap_client_session_protocol_state_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_client_session_protocol_state_type_id__once)) {
		GType geary_imap_client_session_protocol_state_type_id;
		geary_imap_client_session_protocol_state_type_id = geary_imap_client_session_protocol_state_get_type_once ();
		g_once_init_leave (&geary_imap_client_session_protocol_state_type_id__once, geary_imap_client_session_protocol_state_type_id);
	}
	return geary_imap_client_session_protocol_state_type_id__once;
}

gboolean
geary_imap_client_session_disconnect_reason_is_error (GearyImapClientSessionDisconnectReason self)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	if (self == GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_LOCAL_ERROR) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = self == GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_REMOTE_ERROR;
	}
	result = _tmp0_;
	return result;
}

gboolean
geary_imap_client_session_disconnect_reason_is_remote (GearyImapClientSessionDisconnectReason self)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	if (self == GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_REMOTE_CLOSE) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = self == GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_REMOTE_ERROR;
	}
	result = _tmp0_;
	return result;
}

 G_GNUC_NO_INLINE static GType
geary_imap_client_session_disconnect_reason_get_type_once (void)
{
	static const GEnumValue values[] = {{GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_NULL, "GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_NULL", "null"}, {GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_LOCAL_CLOSE, "GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_LOCAL_CLOSE", "local-close"}, {GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_LOCAL_ERROR, "GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_LOCAL_ERROR", "local-error"}, {GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_REMOTE_CLOSE, "GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_REMOTE_CLOSE", "remote-close"}, {GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_REMOTE_ERROR, "GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_REMOTE_ERROR", "remote-error"}, {0, NULL, NULL}};
	GType geary_imap_client_session_disconnect_reason_type_id;
	geary_imap_client_session_disconnect_reason_type_id = g_enum_register_static ("GearyImapClientSessionDisconnectReason", values);
	return geary_imap_client_session_disconnect_reason_type_id;
}

GType
geary_imap_client_session_disconnect_reason_get_type (void)
{
	static gsize geary_imap_client_session_disconnect_reason_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_client_session_disconnect_reason_type_id__once)) {
		GType geary_imap_client_session_disconnect_reason_type_id;
		geary_imap_client_session_disconnect_reason_type_id = geary_imap_client_session_disconnect_reason_get_type_once ();
		g_once_init_leave (&geary_imap_client_session_disconnect_reason_type_id__once, geary_imap_client_session_disconnect_reason_type_id);
	}
	return geary_imap_client_session_disconnect_reason_type_id__once;
}

 G_GNUC_NO_INLINE static GType
geary_imap_client_session_state_get_type_once (void)
{
	static const GEnumValue values[] = {{GEARY_IMAP_CLIENT_SESSION_STATE_NOT_CONNECTED, "GEARY_IMAP_CLIENT_SESSION_STATE_NOT_CONNECTED", "not-connected"}, {GEARY_IMAP_CLIENT_SESSION_STATE_NOAUTH, "GEARY_IMAP_CLIENT_SESSION_STATE_NOAUTH", "noauth"}, {GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZED, "GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZED", "authorized"}, {GEARY_IMAP_CLIENT_SESSION_STATE_SELECTED, "GEARY_IMAP_CLIENT_SESSION_STATE_SELECTED", "selected"}, {GEARY_IMAP_CLIENT_SESSION_STATE_LOGOUT, "GEARY_IMAP_CLIENT_SESSION_STATE_LOGOUT", "logout"}, {GEARY_IMAP_CLIENT_SESSION_STATE_CONNECTING, "GEARY_IMAP_CLIENT_SESSION_STATE_CONNECTING", "connecting"}, {GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZING, "GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZING", "authorizing"}, {GEARY_IMAP_CLIENT_SESSION_STATE_SELECTING, "GEARY_IMAP_CLIENT_SESSION_STATE_SELECTING", "selecting"}, {GEARY_IMAP_CLIENT_SESSION_STATE_CLOSING_MAILBOX, "GEARY_IMAP_CLIENT_SESSION_STATE_CLOSING_MAILBOX", "closing-mailbox"}, {GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED, "GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED", "closed"}, {GEARY_IMAP_CLIENT_SESSION_STATE_COUNT, "GEARY_IMAP_CLIENT_SESSION_STATE_COUNT", "count"}, {0, NULL, NULL}};
	GType geary_imap_client_session_state_type_id;
	geary_imap_client_session_state_type_id = g_enum_register_static ("GearyImapClientSessionState", values);
	return geary_imap_client_session_state_type_id;
}

static GType
geary_imap_client_session_state_get_type (void)
{
	static gsize geary_imap_client_session_state_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_client_session_state_type_id__once)) {
		GType geary_imap_client_session_state_type_id;
		geary_imap_client_session_state_type_id = geary_imap_client_session_state_get_type_once ();
		g_once_init_leave (&geary_imap_client_session_state_type_id__once, geary_imap_client_session_state_type_id);
	}
	return geary_imap_client_session_state_type_id__once;
}

 G_GNUC_NO_INLINE static GType
geary_imap_client_session_event_get_type_once (void)
{
	static const GEnumValue values[] = {{GEARY_IMAP_CLIENT_SESSION_EVENT_CONNECT, "GEARY_IMAP_CLIENT_SESSION_EVENT_CONNECT", "connect"}, {GEARY_IMAP_CLIENT_SESSION_EVENT_DISCONNECT, "GEARY_IMAP_CLIENT_SESSION_EVENT_DISCONNECT", "disconnect"}, {GEARY_IMAP_CLIENT_SESSION_EVENT_LOGIN, "GEARY_IMAP_CLIENT_SESSION_EVENT_LOGIN", "login"}, {GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_CMD, "GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_CMD", "send-cmd"}, {GEARY_IMAP_CLIENT_SESSION_EVENT_SELECT, "GEARY_IMAP_CLIENT_SESSION_EVENT_SELECT", "select"}, {GEARY_IMAP_CLIENT_SESSION_EVENT_CLOSE_MAILBOX, "GEARY_IMAP_CLIENT_SESSION_EVENT_CLOSE_MAILBOX", "close-mailbox"}, {GEARY_IMAP_CLIENT_SESSION_EVENT_LOGOUT, "GEARY_IMAP_CLIENT_SESSION_EVENT_LOGOUT", "logout"}, {GEARY_IMAP_CLIENT_SESSION_EVENT_CONNECTED, "GEARY_IMAP_CLIENT_SESSION_EVENT_CONNECTED", "connected"}, {GEARY_IMAP_CLIENT_SESSION_EVENT_DISCONNECTED, "GEARY_IMAP_CLIENT_SESSION_EVENT_DISCONNECTED", "disconnected"}, {GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_STATUS, "GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_STATUS", "recv-status"}, {GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_COMPLETION, "GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_COMPLETION", "recv-completion"}, {GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_ERROR, "GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_ERROR", "recv-error"}, {GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_ERROR, "GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_ERROR", "send-error"}, {GEARY_IMAP_CLIENT_SESSION_EVENT_TIMEOUT, "GEARY_IMAP_CLIENT_SESSION_EVENT_TIMEOUT", "timeout"}, {GEARY_IMAP_CLIENT_SESSION_EVENT_COUNT, "GEARY_IMAP_CLIENT_SESSION_EVENT_COUNT", "count"}, {0, NULL, NULL}};
	GType geary_imap_client_session_event_type_id;
	geary_imap_client_session_event_type_id = g_enum_register_static ("GearyImapClientSessionEvent", values);
	return geary_imap_client_session_event_type_id;
}

static GType
geary_imap_client_session_event_get_type (void)
{
	static gsize geary_imap_client_session_event_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_client_session_event_type_id__once)) {
		GType geary_imap_client_session_event_type_id;
		geary_imap_client_session_event_type_id = geary_imap_client_session_event_get_type_once ();
		g_once_init_leave (&geary_imap_client_session_event_type_id__once, geary_imap_client_session_event_type_id);
	}
	return geary_imap_client_session_event_type_id__once;
}

static gchar*
geary_imap_client_session_state_to_string (guint state)
{
	gchar* _tmp0_;
	gchar* result;
	_tmp0_ = geary_object_utils_to_enum_nick (G_TYPE_UINT, NULL, NULL, GEARY_IMAP_CLIENT_SESSION_TYPE_STATE, (gpointer) ((guintptr) state));
	result = _tmp0_;
	return result;
}

static gchar*
geary_imap_client_session_event_to_string (guint event)
{
	gchar* result;
	result = g_enum_to_string (GEARY_IMAP_CLIENT_SESSION_TYPE_EVENT, (GearyImapClientSessionEvent) event);
	return result;
}

static gchar*
_geary_imap_client_session_state_to_string_geary_state_state_event_to_string (guint state_or_event,
                                                                              gpointer self)
{
	gchar* result;
	result = geary_imap_client_session_state_to_string (state_or_event);
	return result;
}

static gchar*
_geary_imap_client_session_event_to_string_geary_state_state_event_to_string (guint state_or_event,
                                                                              gpointer self)
{
	gchar* result;
	result = geary_imap_client_session_event_to_string (state_or_event);
	return result;
}

GearyImapClientSessionProtocolState
geary_imap_client_session_get_protocol_state (GearyImapClientSession* self)
{
	GearyImapClientSessionProtocolState result;
	GearyImapClientSessionProtocolState state = 0;
	GearyStateMachine* _tmp0_;
	guint _tmp1_;
	guint _tmp2_;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0);
	state = GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_NOT_CONNECTED;
	_tmp0_ = self->priv->fsm;
	_tmp1_ = geary_state_machine_get_state (_tmp0_);
	_tmp2_ = _tmp1_;
	switch (_tmp2_) {
		case GEARY_IMAP_CLIENT_SESSION_STATE_NOT_CONNECTED:
		case GEARY_IMAP_CLIENT_SESSION_STATE_LOGOUT:
		case GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED:
		{
			state = GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_NOT_CONNECTED;
			break;
		}
		case GEARY_IMAP_CLIENT_SESSION_STATE_NOAUTH:
		{
			state = GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_UNAUTHORIZED;
			break;
		}
		case GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZED:
		{
			state = GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_AUTHORIZED;
			break;
		}
		case GEARY_IMAP_CLIENT_SESSION_STATE_SELECTED:
		{
			state = GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_SELECTED;
			break;
		}
		case GEARY_IMAP_CLIENT_SESSION_STATE_CONNECTING:
		{
			state = GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_CONNECTING;
			break;
		}
		case GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZING:
		{
			state = GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_AUTHORIZING;
			break;
		}
		case GEARY_IMAP_CLIENT_SESSION_STATE_SELECTING:
		{
			state = GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_SELECTING;
			break;
		}
		case GEARY_IMAP_CLIENT_SESSION_STATE_CLOSING_MAILBOX:
		{
			state = GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_CLOSING_MAILBOX;
			break;
		}
		default:
		break;
	}
	result = state;
	return result;
}

GearyImapClientSessionDisconnectReason
geary_imap_client_session_get_disconnected (GearyImapClientSession* self)
{
	GearyImapClientSessionDisconnectReason result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0);
	result = self->priv->_disconnected;
	return result;
}

static void
geary_imap_client_session_set_disconnected (GearyImapClientSession* self,
                                            GearyImapClientSessionDisconnectReason value)
{
	GearyImapClientSessionDisconnectReason old_value;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	old_value = geary_imap_client_session_get_disconnected (self);
	if (old_value != value) {
		self->priv->_disconnected = value;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_client_session_properties[GEARY_IMAP_CLIENT_SESSION_DISCONNECTED_PROPERTY]);
	}
}

GearyImapCapabilities*
geary_imap_client_session_get_capabilities (GearyImapClientSession* self)
{
	GearyImapCapabilities* result;
	GearyImapCapabilities* _tmp0_;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), NULL);
	_tmp0_ = self->priv->_capabilities;
	result = _tmp0_;
	return result;
}

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

static void
geary_imap_client_session_set_capabilities (GearyImapClientSession* self,
                                            GearyImapCapabilities* value)
{
	GearyImapCapabilities* old_value;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	old_value = geary_imap_client_session_get_capabilities (self);
	if (old_value != value) {
		GearyImapCapabilities* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_capabilities);
		self->priv->_capabilities = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_client_session_properties[GEARY_IMAP_CLIENT_SESSION_CAPABILITIES_PROPERTY]);
	}
}

gboolean
geary_imap_client_session_get_is_idle_supported (GearyImapClientSession* self)
{
	gboolean result;
	GearyImapCapabilities* _tmp0_;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), FALSE);
	_tmp0_ = self->priv->_capabilities;
	result = geary_generic_capabilities_has_capability (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEARY_TYPE_GENERIC_CAPABILITIES, GearyGenericCapabilities), GEARY_IMAP_CAPABILITIES_IDLE);
	return result;
}

GearyImapStatusResponse*
geary_imap_client_session_get_server_greeting (GearyImapClientSession* self)
{
	GearyImapStatusResponse* result;
	GearyImapStatusResponse* _tmp0_;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), NULL);
	_tmp0_ = self->priv->_server_greeting;
	result = _tmp0_;
	return result;
}

static void
geary_imap_client_session_set_server_greeting (GearyImapClientSession* self,
                                               GearyImapStatusResponse* value)
{
	GearyImapStatusResponse* old_value;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	old_value = geary_imap_client_session_get_server_greeting (self);
	if (old_value != value) {
		GearyImapStatusResponse* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_server_greeting);
		self->priv->_server_greeting = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_client_session_properties[GEARY_IMAP_CLIENT_SESSION_SERVER_GREETING_PROPERTY]);
	}
}

static const gchar*
geary_imap_client_session_real_get_logging_domain (GearyLoggingSource* base)
{
	const gchar* result;
	GearyImapClientSession* self;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_TYPE_CLIENT_SESSION, GearyImapClientSession);
	result = GEARY_IMAP_CLIENT_SERVICE_LOGGING_DOMAIN;
	return result;
}

static GearyLoggingSource*
geary_imap_client_session_real_get_logging_parent (GearyLoggingSource* base)
{
	GearyLoggingSource* result;
	GearyImapClientSession* self;
	GearyLoggingSource* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_TYPE_CLIENT_SESSION, GearyImapClientSession);
	_tmp0_ = self->priv->_logging_parent;
	result = _tmp0_;
	return result;
}

gint64
geary_imap_client_session_get_last_seen (GearyImapClientSession* self)
{
	gint64 result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0LL);
	result = self->priv->_last_seen;
	return result;
}

static void
geary_imap_client_session_set_last_seen (GearyImapClientSession* self,
                                         gint64 value)
{
	gint64 old_value;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	old_value = geary_imap_client_session_get_last_seen (self);
	if (old_value != value) {
		self->priv->_last_seen = value;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_client_session_properties[GEARY_IMAP_CLIENT_SESSION_LAST_SEEN_PROPERTY]);
	}
}

GearyImapMailboxInformation*
geary_imap_client_session_get_inbox (GearyImapClientSession* self)
{
	GearyImapMailboxInformation* result;
	GearyImapMailboxInformation* _tmp0_;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), NULL);
	_tmp0_ = self->priv->_inbox;
	result = _tmp0_;
	return result;
}

static void
geary_imap_client_session_set_inbox (GearyImapClientSession* self,
                                     GearyImapMailboxInformation* value)
{
	GearyImapMailboxInformation* old_value;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	old_value = geary_imap_client_session_get_inbox (self);
	if (old_value != value) {
		GearyImapMailboxInformation* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_inbox);
		self->priv->_inbox = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_client_session_properties[GEARY_IMAP_CLIENT_SESSION_INBOX_PROPERTY]);
	}
}

GearyImapQuirks*
geary_imap_client_session_get_quirks (GearyImapClientSession* self)
{
	GearyImapQuirks* result;
	GearyImapQuirks* _tmp0_;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), NULL);
	_tmp0_ = self->priv->_quirks;
	result = _tmp0_;
	return result;
}

void
geary_imap_client_session_set_quirks (GearyImapClientSession* self,
                                      GearyImapQuirks* value)
{
	GearyImapQuirks* old_value;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	old_value = geary_imap_client_session_get_quirks (self);
	if (old_value != value) {
		GearyImapQuirks* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_quirks);
		self->priv->_quirks = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_client_session_properties[GEARY_IMAP_CLIENT_SESSION_QUIRKS_PROPERTY]);
	}
}

static void
g_cclosure_user_marshal_VOID__POINTER_INT (GClosure * closure,
                                           GValue * return_value,
                                           guint n_param_values,
                                           const GValue * param_values,
                                           gpointer invocation_hint,
                                           gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__POINTER_INT) (gpointer data1, gpointer arg_1, gint arg_2, gpointer data2);
	register GMarshalFunc_VOID__POINTER_INT 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__POINTER_INT) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_pointer (param_values + 1), g_value_get_int (param_values + 2), data2);
}

static guint
_geary_imap_client_session_on_connect_geary_state_transition (guint state,
                                                              guint event,
                                                              void* user,
                                                              GObject* object,
                                                              GError* err,
                                                              gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_connect ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_imap_client_session_on_early_command_geary_state_transition (guint state,
                                                                    guint event,
                                                                    void* user,
                                                                    GObject* object,
                                                                    GError* err,
                                                                    gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_early_command ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_state_nop_geary_state_transition (guint state,
                                         guint event,
                                         void* user,
                                         GObject* object,
                                         GError* err,
                                         gpointer self)
{
	guint result;
	result = geary_state_nop (state, event);
	return result;
}

static guint
_geary_imap_client_session_on_already_connected_geary_state_transition (guint state,
                                                                        guint event,
                                                                        void* user,
                                                                        GObject* object,
                                                                        GError* err,
                                                                        gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_already_connected ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_imap_client_session_on_disconnect_geary_state_transition (guint state,
                                                                 guint event,
                                                                 void* user,
                                                                 GObject* object,
                                                                 GError* err,
                                                                 gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_disconnect ((GearyImapClientSession*) self, state, event, user, object, err);
	return result;
}

static guint
_geary_imap_client_session_on_connected_geary_state_transition (guint state,
                                                                guint event,
                                                                void* user,
                                                                GObject* object,
                                                                GError* err,
                                                                gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_connected ((GearyImapClientSession*) self, state, event);
	return result;
}

static guint
_geary_imap_client_session_on_connecting_recv_status_geary_state_transition (guint state,
                                                                             guint event,
                                                                             void* user,
                                                                             GObject* object,
                                                                             GError* err,
                                                                             gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_connecting_recv_status ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_imap_client_session_on_dropped_response_geary_state_transition (guint state,
                                                                       guint event,
                                                                       void* user,
                                                                       GObject* object,
                                                                       GError* err,
                                                                       gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_dropped_response ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_imap_client_session_on_connecting_send_recv_error_geary_state_transition (guint state,
                                                                                 guint event,
                                                                                 void* user,
                                                                                 GObject* object,
                                                                                 GError* err,
                                                                                 gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_connecting_send_recv_error ((GearyImapClientSession*) self, state, event, user, object, err);
	return result;
}

static guint
_geary_imap_client_session_on_connecting_timeout_geary_state_transition (guint state,
                                                                         guint event,
                                                                         void* user,
                                                                         GObject* object,
                                                                         GError* err,
                                                                         gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_connecting_timeout ((GearyImapClientSession*) self, state, event);
	return result;
}

static guint
_geary_imap_client_session_on_login_geary_state_transition (guint state,
                                                            guint event,
                                                            void* user,
                                                            GObject* object,
                                                            GError* err,
                                                            gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_login ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_imap_client_session_on_send_command_geary_state_transition (guint state,
                                                                   guint event,
                                                                   void* user,
                                                                   GObject* object,
                                                                   GError* err,
                                                                   gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_send_command ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_imap_client_session_on_unauthenticated_geary_state_transition (guint state,
                                                                      guint event,
                                                                      void* user,
                                                                      GObject* object,
                                                                      GError* err,
                                                                      gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_unauthenticated ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_imap_client_session_on_logout_geary_state_transition (guint state,
                                                             guint event,
                                                             void* user,
                                                             GObject* object,
                                                             GError* err,
                                                             gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_logout ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_imap_client_session_on_recv_status_geary_state_transition (guint state,
                                                                  guint event,
                                                                  void* user,
                                                                  GObject* object,
                                                                  GError* err,
                                                                  gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_recv_status ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_imap_client_session_on_send_error_geary_state_transition (guint state,
                                                                 guint event,
                                                                 void* user,
                                                                 GObject* object,
                                                                 GError* err,
                                                                 gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_send_error ((GearyImapClientSession*) self, state, event, user, object, err);
	return result;
}

static guint
_geary_imap_client_session_on_recv_error_geary_state_transition (guint state,
                                                                 guint event,
                                                                 void* user,
                                                                 GObject* object,
                                                                 GError* err,
                                                                 gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_recv_error ((GearyImapClientSession*) self, state, event, user, object, err);
	return result;
}

static guint
_geary_imap_client_session_on_logging_in_geary_state_transition (guint state,
                                                                 guint event,
                                                                 void* user,
                                                                 GObject* object,
                                                                 GError* err,
                                                                 gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_logging_in ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_imap_client_session_on_login_recv_completion_geary_state_transition (guint state,
                                                                            guint event,
                                                                            void* user,
                                                                            GObject* object,
                                                                            GError* err,
                                                                            gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_login_recv_completion ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_imap_client_session_on_already_logged_in_geary_state_transition (guint state,
                                                                        guint event,
                                                                        void* user,
                                                                        GObject* object,
                                                                        GError* err,
                                                                        gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_already_logged_in ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_imap_client_session_on_select_geary_state_transition (guint state,
                                                             guint event,
                                                             void* user,
                                                             GObject* object,
                                                             GError* err,
                                                             gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_select ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_imap_client_session_on_not_selected_geary_state_transition (guint state,
                                                                   guint event,
                                                                   void* user,
                                                                   GObject* object,
                                                                   GError* err,
                                                                   gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_not_selected ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_imap_client_session_on_close_mailbox_geary_state_transition (guint state,
                                                                    guint event,
                                                                    void* user,
                                                                    GObject* object,
                                                                    GError* err,
                                                                    gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_close_mailbox ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_imap_client_session_on_selecting_recv_completion_geary_state_transition (guint state,
                                                                                guint event,
                                                                                void* user,
                                                                                GObject* object,
                                                                                GError* err,
                                                                                gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_selecting_recv_completion ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_imap_client_session_on_closing_recv_completion_geary_state_transition (guint state,
                                                                              guint event,
                                                                              void* user,
                                                                              GObject* object,
                                                                              GError* err,
                                                                              gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_closing_recv_completion ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_imap_client_session_on_late_command_geary_state_transition (guint state,
                                                                   guint event,
                                                                   void* user,
                                                                   GObject* object,
                                                                   GError* err,
                                                                   gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_late_command ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_imap_client_session_on_logging_out_recv_status_geary_state_transition (guint state,
                                                                              guint event,
                                                                              void* user,
                                                                              GObject* object,
                                                                              GError* err,
                                                                              gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_logging_out_recv_status ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_imap_client_session_on_logging_out_recv_completion_geary_state_transition (guint state,
                                                                                  guint event,
                                                                                  void* user,
                                                                                  GObject* object,
                                                                                  GError* err,
                                                                                  gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_logging_out_recv_completion ((GearyImapClientSession*) self, state, event, user, object);
	return result;
}

static guint
_geary_imap_client_session_on_ignored_transition_geary_state_transition (guint state,
                                                                         guint event,
                                                                         void* user,
                                                                         GObject* object,
                                                                         GError* err,
                                                                         gpointer self)
{
	guint result;
	result = geary_imap_client_session_on_ignored_transition ((GearyImapClientSession*) self, state, event);
	return result;
}

static void
__lambda49_ (GearyImapClientSession* self)
{
	g_object_notify (G_TYPE_CHECK_INSTANCE_CAST (self, G_TYPE_OBJECT, GObject), "protocol_state");
}

static void
___lambda49__g_object_notify (GObject* _sender,
                              GParamSpec* pspec,
                              gpointer self)
{
	__lambda49_ ((GearyImapClientSession*) self);
}

GearyImapClientSession*
geary_imap_client_session_construct (GType object_type,
                                     GearyEndpoint* imap_endpoint,
                                     GearyImapQuirks* quirks)
{
	GearyImapClientSession * self = NULL;
	GearyEndpoint* _tmp0_;
	GearyStateMapping** mappings = NULL;
	GearyStateMapping* _tmp1_;
	GearyStateMapping* _tmp2_;
	GearyStateMapping* _tmp3_;
	GearyStateMapping* _tmp4_;
	GearyStateMapping* _tmp5_;
	GearyStateMapping* _tmp6_;
	GearyStateMapping* _tmp7_;
	GearyStateMapping* _tmp8_;
	GearyStateMapping* _tmp9_;
	GearyStateMapping* _tmp10_;
	GearyStateMapping* _tmp11_;
	GearyStateMapping* _tmp12_;
	GearyStateMapping* _tmp13_;
	GearyStateMapping* _tmp14_;
	GearyStateMapping* _tmp15_;
	GearyStateMapping* _tmp16_;
	GearyStateMapping* _tmp17_;
	GearyStateMapping* _tmp18_;
	GearyStateMapping* _tmp19_;
	GearyStateMapping* _tmp20_;
	GearyStateMapping* _tmp21_;
	GearyStateMapping* _tmp22_;
	GearyStateMapping* _tmp23_;
	GearyStateMapping* _tmp24_;
	GearyStateMapping* _tmp25_;
	GearyStateMapping* _tmp26_;
	GearyStateMapping* _tmp27_;
	GearyStateMapping* _tmp28_;
	GearyStateMapping* _tmp29_;
	GearyStateMapping* _tmp30_;
	GearyStateMapping* _tmp31_;
	GearyStateMapping* _tmp32_;
	GearyStateMapping* _tmp33_;
	GearyStateMapping* _tmp34_;
	GearyStateMapping* _tmp35_;
	GearyStateMapping* _tmp36_;
	GearyStateMapping* _tmp37_;
	GearyStateMapping* _tmp38_;
	GearyStateMapping* _tmp39_;
	GearyStateMapping* _tmp40_;
	GearyStateMapping* _tmp41_;
	GearyStateMapping* _tmp42_;
	GearyStateMapping* _tmp43_;
	GearyStateMapping* _tmp44_;
	GearyStateMapping* _tmp45_;
	GearyStateMapping* _tmp46_;
	GearyStateMapping* _tmp47_;
	GearyStateMapping* _tmp48_;
	GearyStateMapping* _tmp49_;
	GearyStateMapping* _tmp50_;
	GearyStateMapping* _tmp51_;
	GearyStateMapping* _tmp52_;
	GearyStateMapping* _tmp53_;
	GearyStateMapping* _tmp54_;
	GearyStateMapping* _tmp55_;
	GearyStateMapping* _tmp56_;
	GearyStateMapping* _tmp57_;
	GearyStateMapping* _tmp58_;
	GearyStateMapping* _tmp59_;
	GearyStateMapping* _tmp60_;
	GearyStateMapping* _tmp61_;
	GearyStateMapping* _tmp62_;
	GearyStateMapping* _tmp63_;
	GearyStateMapping* _tmp64_;
	GearyStateMapping* _tmp65_;
	GearyStateMapping* _tmp66_;
	GearyStateMapping* _tmp67_;
	GearyStateMapping* _tmp68_;
	GearyStateMapping* _tmp69_;
	GearyStateMapping* _tmp70_;
	GearyStateMapping* _tmp71_;
	GearyStateMapping* _tmp72_;
	GearyStateMapping* _tmp73_;
	GearyStateMapping* _tmp74_;
	GearyStateMapping* _tmp75_;
	GearyStateMapping* _tmp76_;
	GearyStateMapping* _tmp77_;
	GearyStateMapping* _tmp78_;
	GearyStateMapping* _tmp79_;
	GearyStateMapping* _tmp80_;
	GearyStateMapping* _tmp81_;
	GearyStateMapping* _tmp82_;
	GearyStateMapping* _tmp83_;
	GearyStateMapping* _tmp84_;
	GearyStateMapping* _tmp85_;
	GearyStateMapping* _tmp86_;
	GearyStateMapping* _tmp87_;
	GearyStateMapping* _tmp88_;
	GearyStateMapping* _tmp89_;
	GearyStateMapping* _tmp90_;
	GearyStateMapping* _tmp91_;
	GearyStateMapping* _tmp92_;
	GearyStateMapping* _tmp93_;
	GearyStateMapping* _tmp94_;
	GearyStateMapping* _tmp95_;
	GearyStateMapping* _tmp96_;
	GearyStateMapping* _tmp97_;
	GearyStateMapping* _tmp98_;
	GearyStateMapping* _tmp99_;
	GearyStateMapping* _tmp100_;
	GearyStateMapping* _tmp101_;
	GearyStateMapping* _tmp102_;
	GearyStateMapping* _tmp103_;
	GearyStateMapping* _tmp104_;
	GearyStateMapping* _tmp105_;
	GearyStateMapping* _tmp106_;
	GearyStateMapping* _tmp107_;
	GearyStateMapping* _tmp108_;
	GearyStateMapping** _tmp109_;
	gint mappings_length1;
	gint _mappings_size_;
	GearyStateMachineDescriptor* _tmp110_;
	GearyStateMachine* _tmp111_;
	GearyStateMachine* _tmp112_;
	g_return_val_if_fail (GEARY_IS_ENDPOINT (imap_endpoint), NULL);
	g_return_val_if_fail (GEARY_IMAP_IS_QUIRKS (quirks), NULL);
	self = (GearyImapClientSession*) geary_base_object_construct (object_type);
	_tmp0_ = _g_object_ref0 (imap_endpoint);
	_g_object_unref0 (self->priv->imap_endpoint);
	self->priv->imap_endpoint = _tmp0_;
	geary_imap_client_session_set_quirks (self, quirks);
	_tmp1_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOT_CONNECTED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CONNECT, _geary_imap_client_session_on_connect_geary_state_transition, self);
	_tmp2_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOT_CONNECTED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGIN, _geary_imap_client_session_on_early_command_geary_state_transition, self);
	_tmp3_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOT_CONNECTED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_CMD, _geary_imap_client_session_on_early_command_geary_state_transition, self);
	_tmp4_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOT_CONNECTED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SELECT, _geary_imap_client_session_on_early_command_geary_state_transition, self);
	_tmp5_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOT_CONNECTED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CLOSE_MAILBOX, _geary_imap_client_session_on_early_command_geary_state_transition, self);
	_tmp6_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOT_CONNECTED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGOUT, _geary_imap_client_session_on_early_command_geary_state_transition, self);
	_tmp7_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOT_CONNECTED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_DISCONNECT, _geary_state_nop_geary_state_transition, NULL);
	_tmp8_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CONNECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CONNECT, _geary_imap_client_session_on_already_connected_geary_state_transition, self);
	_tmp9_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CONNECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_DISCONNECT, _geary_imap_client_session_on_disconnect_geary_state_transition, self);
	_tmp10_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CONNECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGIN, _geary_imap_client_session_on_early_command_geary_state_transition, self);
	_tmp11_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CONNECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_CMD, _geary_imap_client_session_on_early_command_geary_state_transition, self);
	_tmp12_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CONNECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SELECT, _geary_imap_client_session_on_early_command_geary_state_transition, self);
	_tmp13_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CONNECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CLOSE_MAILBOX, _geary_imap_client_session_on_early_command_geary_state_transition, self);
	_tmp14_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CONNECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGOUT, _geary_imap_client_session_on_early_command_geary_state_transition, self);
	_tmp15_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CONNECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CONNECTED, _geary_imap_client_session_on_connected_geary_state_transition, self);
	_tmp16_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CONNECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_STATUS, _geary_imap_client_session_on_connecting_recv_status_geary_state_transition, self);
	_tmp17_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CONNECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_COMPLETION, _geary_imap_client_session_on_dropped_response_geary_state_transition, self);
	_tmp18_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CONNECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_ERROR, _geary_imap_client_session_on_connecting_send_recv_error_geary_state_transition, self);
	_tmp19_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CONNECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_ERROR, _geary_imap_client_session_on_connecting_send_recv_error_geary_state_transition, self);
	_tmp20_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CONNECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_TIMEOUT, _geary_imap_client_session_on_connecting_timeout_geary_state_transition, self);
	_tmp21_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOAUTH, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CONNECT, _geary_imap_client_session_on_already_connected_geary_state_transition, self);
	_tmp22_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOAUTH, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_DISCONNECT, _geary_imap_client_session_on_disconnect_geary_state_transition, self);
	_tmp23_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOAUTH, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGIN, _geary_imap_client_session_on_login_geary_state_transition, self);
	_tmp24_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOAUTH, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_CMD, _geary_imap_client_session_on_send_command_geary_state_transition, self);
	_tmp25_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOAUTH, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SELECT, _geary_imap_client_session_on_unauthenticated_geary_state_transition, self);
	_tmp26_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOAUTH, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CLOSE_MAILBOX, _geary_imap_client_session_on_unauthenticated_geary_state_transition, self);
	_tmp27_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOAUTH, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGOUT, _geary_imap_client_session_on_logout_geary_state_transition, self);
	_tmp28_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOAUTH, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_STATUS, _geary_imap_client_session_on_recv_status_geary_state_transition, self);
	_tmp29_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOAUTH, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_COMPLETION, _geary_imap_client_session_on_recv_status_geary_state_transition, self);
	_tmp30_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOAUTH, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_ERROR, _geary_imap_client_session_on_send_error_geary_state_transition, self);
	_tmp31_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOAUTH, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_ERROR, _geary_imap_client_session_on_recv_error_geary_state_transition, self);
	_tmp32_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CONNECT, _geary_imap_client_session_on_already_connected_geary_state_transition, self);
	_tmp33_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_DISCONNECT, _geary_imap_client_session_on_disconnect_geary_state_transition, self);
	_tmp34_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGIN, _geary_imap_client_session_on_logging_in_geary_state_transition, self);
	_tmp35_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_CMD, _geary_imap_client_session_on_unauthenticated_geary_state_transition, self);
	_tmp36_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SELECT, _geary_imap_client_session_on_unauthenticated_geary_state_transition, self);
	_tmp37_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CLOSE_MAILBOX, _geary_imap_client_session_on_unauthenticated_geary_state_transition, self);
	_tmp38_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGOUT, _geary_imap_client_session_on_logout_geary_state_transition, self);
	_tmp39_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_STATUS, _geary_imap_client_session_on_recv_status_geary_state_transition, self);
	_tmp40_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_COMPLETION, _geary_imap_client_session_on_login_recv_completion_geary_state_transition, self);
	_tmp41_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_ERROR, _geary_imap_client_session_on_send_error_geary_state_transition, self);
	_tmp42_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_ERROR, _geary_imap_client_session_on_recv_error_geary_state_transition, self);
	_tmp43_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CONNECT, _geary_imap_client_session_on_already_connected_geary_state_transition, self);
	_tmp44_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_DISCONNECT, _geary_imap_client_session_on_disconnect_geary_state_transition, self);
	_tmp45_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGIN, _geary_imap_client_session_on_already_logged_in_geary_state_transition, self);
	_tmp46_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_CMD, _geary_imap_client_session_on_send_command_geary_state_transition, self);
	_tmp47_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SELECT, _geary_imap_client_session_on_select_geary_state_transition, self);
	_tmp48_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CLOSE_MAILBOX, _geary_imap_client_session_on_not_selected_geary_state_transition, self);
	_tmp49_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGOUT, _geary_imap_client_session_on_logout_geary_state_transition, self);
	_tmp50_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_STATUS, _geary_imap_client_session_on_recv_status_geary_state_transition, self);
	_tmp51_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_COMPLETION, _geary_imap_client_session_on_recv_status_geary_state_transition, self);
	_tmp52_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_ERROR, _geary_imap_client_session_on_send_error_geary_state_transition, self);
	_tmp53_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_ERROR, _geary_imap_client_session_on_recv_error_geary_state_transition, self);
	_tmp54_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CONNECT, _geary_imap_client_session_on_already_connected_geary_state_transition, self);
	_tmp55_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_DISCONNECT, _geary_imap_client_session_on_disconnect_geary_state_transition, self);
	_tmp56_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGIN, _geary_imap_client_session_on_already_logged_in_geary_state_transition, self);
	_tmp57_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_CMD, _geary_imap_client_session_on_send_command_geary_state_transition, self);
	_tmp58_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SELECT, _geary_imap_client_session_on_select_geary_state_transition, self);
	_tmp59_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CLOSE_MAILBOX, _geary_imap_client_session_on_close_mailbox_geary_state_transition, self);
	_tmp60_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGOUT, _geary_imap_client_session_on_logout_geary_state_transition, self);
	_tmp61_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_STATUS, _geary_imap_client_session_on_recv_status_geary_state_transition, self);
	_tmp62_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_COMPLETION, _geary_imap_client_session_on_selecting_recv_completion_geary_state_transition, self);
	_tmp63_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_ERROR, _geary_imap_client_session_on_send_error_geary_state_transition, self);
	_tmp64_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTING, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_ERROR, _geary_imap_client_session_on_recv_error_geary_state_transition, self);
	_tmp65_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CONNECT, _geary_imap_client_session_on_already_connected_geary_state_transition, self);
	_tmp66_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_DISCONNECT, _geary_imap_client_session_on_disconnect_geary_state_transition, self);
	_tmp67_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGIN, _geary_imap_client_session_on_already_logged_in_geary_state_transition, self);
	_tmp68_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_CMD, _geary_imap_client_session_on_send_command_geary_state_transition, self);
	_tmp69_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SELECT, _geary_imap_client_session_on_select_geary_state_transition, self);
	_tmp70_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CLOSE_MAILBOX, _geary_imap_client_session_on_close_mailbox_geary_state_transition, self);
	_tmp71_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGOUT, _geary_imap_client_session_on_logout_geary_state_transition, self);
	_tmp72_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_STATUS, _geary_imap_client_session_on_recv_status_geary_state_transition, self);
	_tmp73_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_COMPLETION, _geary_imap_client_session_on_recv_status_geary_state_transition, self);
	_tmp74_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_ERROR, _geary_imap_client_session_on_send_error_geary_state_transition, self);
	_tmp75_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_ERROR, _geary_imap_client_session_on_recv_error_geary_state_transition, self);
	_tmp76_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSING_MAILBOX, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CONNECT, _geary_imap_client_session_on_already_connected_geary_state_transition, self);
	_tmp77_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSING_MAILBOX, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_DISCONNECT, _geary_imap_client_session_on_disconnect_geary_state_transition, self);
	_tmp78_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSING_MAILBOX, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGIN, _geary_imap_client_session_on_already_logged_in_geary_state_transition, self);
	_tmp79_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSING_MAILBOX, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_CMD, _geary_imap_client_session_on_send_command_geary_state_transition, self);
	_tmp80_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSING_MAILBOX, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SELECT, _geary_imap_client_session_on_select_geary_state_transition, self);
	_tmp81_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSING_MAILBOX, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CLOSE_MAILBOX, _geary_imap_client_session_on_not_selected_geary_state_transition, self);
	_tmp82_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSING_MAILBOX, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGOUT, _geary_imap_client_session_on_logout_geary_state_transition, self);
	_tmp83_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSING_MAILBOX, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_STATUS, _geary_imap_client_session_on_recv_status_geary_state_transition, self);
	_tmp84_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSING_MAILBOX, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_COMPLETION, _geary_imap_client_session_on_closing_recv_completion_geary_state_transition, self);
	_tmp85_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSING_MAILBOX, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_ERROR, _geary_imap_client_session_on_send_error_geary_state_transition, self);
	_tmp86_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSING_MAILBOX, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_ERROR, _geary_imap_client_session_on_recv_error_geary_state_transition, self);
	_tmp87_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_LOGOUT, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CONNECT, _geary_imap_client_session_on_already_connected_geary_state_transition, self);
	_tmp88_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_LOGOUT, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_DISCONNECT, _geary_imap_client_session_on_disconnect_geary_state_transition, self);
	_tmp89_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_LOGOUT, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGIN, _geary_imap_client_session_on_already_logged_in_geary_state_transition, self);
	_tmp90_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_LOGOUT, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_CMD, _geary_imap_client_session_on_late_command_geary_state_transition, self);
	_tmp91_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_LOGOUT, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SELECT, _geary_imap_client_session_on_late_command_geary_state_transition, self);
	_tmp92_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_LOGOUT, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CLOSE_MAILBOX, _geary_imap_client_session_on_late_command_geary_state_transition, self);
	_tmp93_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_LOGOUT, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGOUT, _geary_imap_client_session_on_late_command_geary_state_transition, self);
	_tmp94_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_LOGOUT, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_STATUS, _geary_imap_client_session_on_logging_out_recv_status_geary_state_transition, self);
	_tmp95_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_LOGOUT, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_COMPLETION, _geary_imap_client_session_on_logging_out_recv_completion_geary_state_transition, self);
	_tmp96_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_LOGOUT, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_ERROR, _geary_imap_client_session_on_recv_error_geary_state_transition, self);
	_tmp97_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_LOGOUT, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_ERROR, _geary_imap_client_session_on_send_error_geary_state_transition, self);
	_tmp98_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CONNECT, _geary_imap_client_session_on_late_command_geary_state_transition, self);
	_tmp99_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_DISCONNECT, _geary_state_nop_geary_state_transition, NULL);
	_tmp100_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGIN, _geary_imap_client_session_on_late_command_geary_state_transition, self);
	_tmp101_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_CMD, _geary_imap_client_session_on_late_command_geary_state_transition, self);
	_tmp102_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SELECT, _geary_imap_client_session_on_late_command_geary_state_transition, self);
	_tmp103_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CLOSE_MAILBOX, _geary_imap_client_session_on_late_command_geary_state_transition, self);
	_tmp104_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGOUT, _geary_imap_client_session_on_late_command_geary_state_transition, self);
	_tmp105_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_STATUS, _geary_imap_client_session_on_dropped_response_geary_state_transition, self);
	_tmp106_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_COMPLETION, _geary_imap_client_session_on_dropped_response_geary_state_transition, self);
	_tmp107_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_ERROR, _geary_state_nop_geary_state_transition, NULL);
	_tmp108_ = geary_state_mapping_new ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_ERROR, _geary_state_nop_geary_state_transition, NULL);
	_tmp109_ = g_new0 (GearyStateMapping*, 108 + 1);
	_tmp109_[0] = _tmp1_;
	_tmp109_[1] = _tmp2_;
	_tmp109_[2] = _tmp3_;
	_tmp109_[3] = _tmp4_;
	_tmp109_[4] = _tmp5_;
	_tmp109_[5] = _tmp6_;
	_tmp109_[6] = _tmp7_;
	_tmp109_[7] = _tmp8_;
	_tmp109_[8] = _tmp9_;
	_tmp109_[9] = _tmp10_;
	_tmp109_[10] = _tmp11_;
	_tmp109_[11] = _tmp12_;
	_tmp109_[12] = _tmp13_;
	_tmp109_[13] = _tmp14_;
	_tmp109_[14] = _tmp15_;
	_tmp109_[15] = _tmp16_;
	_tmp109_[16] = _tmp17_;
	_tmp109_[17] = _tmp18_;
	_tmp109_[18] = _tmp19_;
	_tmp109_[19] = _tmp20_;
	_tmp109_[20] = _tmp21_;
	_tmp109_[21] = _tmp22_;
	_tmp109_[22] = _tmp23_;
	_tmp109_[23] = _tmp24_;
	_tmp109_[24] = _tmp25_;
	_tmp109_[25] = _tmp26_;
	_tmp109_[26] = _tmp27_;
	_tmp109_[27] = _tmp28_;
	_tmp109_[28] = _tmp29_;
	_tmp109_[29] = _tmp30_;
	_tmp109_[30] = _tmp31_;
	_tmp109_[31] = _tmp32_;
	_tmp109_[32] = _tmp33_;
	_tmp109_[33] = _tmp34_;
	_tmp109_[34] = _tmp35_;
	_tmp109_[35] = _tmp36_;
	_tmp109_[36] = _tmp37_;
	_tmp109_[37] = _tmp38_;
	_tmp109_[38] = _tmp39_;
	_tmp109_[39] = _tmp40_;
	_tmp109_[40] = _tmp41_;
	_tmp109_[41] = _tmp42_;
	_tmp109_[42] = _tmp43_;
	_tmp109_[43] = _tmp44_;
	_tmp109_[44] = _tmp45_;
	_tmp109_[45] = _tmp46_;
	_tmp109_[46] = _tmp47_;
	_tmp109_[47] = _tmp48_;
	_tmp109_[48] = _tmp49_;
	_tmp109_[49] = _tmp50_;
	_tmp109_[50] = _tmp51_;
	_tmp109_[51] = _tmp52_;
	_tmp109_[52] = _tmp53_;
	_tmp109_[53] = _tmp54_;
	_tmp109_[54] = _tmp55_;
	_tmp109_[55] = _tmp56_;
	_tmp109_[56] = _tmp57_;
	_tmp109_[57] = _tmp58_;
	_tmp109_[58] = _tmp59_;
	_tmp109_[59] = _tmp60_;
	_tmp109_[60] = _tmp61_;
	_tmp109_[61] = _tmp62_;
	_tmp109_[62] = _tmp63_;
	_tmp109_[63] = _tmp64_;
	_tmp109_[64] = _tmp65_;
	_tmp109_[65] = _tmp66_;
	_tmp109_[66] = _tmp67_;
	_tmp109_[67] = _tmp68_;
	_tmp109_[68] = _tmp69_;
	_tmp109_[69] = _tmp70_;
	_tmp109_[70] = _tmp71_;
	_tmp109_[71] = _tmp72_;
	_tmp109_[72] = _tmp73_;
	_tmp109_[73] = _tmp74_;
	_tmp109_[74] = _tmp75_;
	_tmp109_[75] = _tmp76_;
	_tmp109_[76] = _tmp77_;
	_tmp109_[77] = _tmp78_;
	_tmp109_[78] = _tmp79_;
	_tmp109_[79] = _tmp80_;
	_tmp109_[80] = _tmp81_;
	_tmp109_[81] = _tmp82_;
	_tmp109_[82] = _tmp83_;
	_tmp109_[83] = _tmp84_;
	_tmp109_[84] = _tmp85_;
	_tmp109_[85] = _tmp86_;
	_tmp109_[86] = _tmp87_;
	_tmp109_[87] = _tmp88_;
	_tmp109_[88] = _tmp89_;
	_tmp109_[89] = _tmp90_;
	_tmp109_[90] = _tmp91_;
	_tmp109_[91] = _tmp92_;
	_tmp109_[92] = _tmp93_;
	_tmp109_[93] = _tmp94_;
	_tmp109_[94] = _tmp95_;
	_tmp109_[95] = _tmp96_;
	_tmp109_[96] = _tmp97_;
	_tmp109_[97] = _tmp98_;
	_tmp109_[98] = _tmp99_;
	_tmp109_[99] = _tmp100_;
	_tmp109_[100] = _tmp101_;
	_tmp109_[101] = _tmp102_;
	_tmp109_[102] = _tmp103_;
	_tmp109_[103] = _tmp104_;
	_tmp109_[104] = _tmp105_;
	_tmp109_[105] = _tmp106_;
	_tmp109_[106] = _tmp107_;
	_tmp109_[107] = _tmp108_;
	mappings = _tmp109_;
	mappings_length1 = 108;
	_mappings_size_ = mappings_length1;
	_tmp110_ = geary_imap_client_session_machine_desc;
	_tmp111_ = geary_state_machine_new (_tmp110_, mappings, mappings_length1, _geary_imap_client_session_on_ignored_transition_geary_state_transition, self);
	_g_object_unref0 (self->priv->fsm);
	self->priv->fsm = _tmp111_;
	_tmp112_ = self->priv->fsm;
	g_signal_connect_object (G_TYPE_CHECK_INSTANCE_CAST (_tmp112_, G_TYPE_OBJECT, GObject), "notify::state", (GCallback) ___lambda49__g_object_notify, self, 0);
	mappings = (_vala_array_free (mappings, mappings_length1, (GDestroyNotify) g_object_unref), NULL);
	return self;
}

GearyImapClientSession*
geary_imap_client_session_new (GearyEndpoint* imap_endpoint,
                               GearyImapQuirks* quirks)
{
	return geary_imap_client_session_construct (GEARY_IMAP_TYPE_CLIENT_SESSION, imap_endpoint, quirks);
}

/**
     * Returns the list of known personal mailbox namespaces.
     *
     * A personal namespace is a common prefix of a set of mailboxes
     * that belong to the currently authenticated account. It may
     * contain the account's Inbox and Sent mailboxes, for example.
     *
     * The list will be empty when the session is not in the
     * authenticated or selected states, it will contain at least one
     * after having successfully logged in.
     *
     * See [[https://tools.ietf.org/html/rfc2342|RFC 2342]] for more
     * information.
     */
GeeList*
geary_imap_client_session_get_personal_namespaces (GearyImapClientSession* self)
{
	GeeList* _tmp0_;
	GeeList* _tmp1_;
	GeeList* _tmp2_;
	GeeList* result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), NULL);
	_tmp0_ = self->priv->personal_namespaces;
	_tmp1_ = gee_list_get_read_only_view (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

/**
     * Returns the list of known shared mailbox namespaces.
     *
     * A shared namespace is a common prefix of a set of mailboxes
     * that are normally accessible by multiple accounts on the
     * server, for example shared email mailboxes and NNTP news
     * mailboxes.
     *
     * The list will be empty when the session is not in the
     * authenticated or selected states, it will only be non-empty
     * after having successfully logged in and if the server supports
     * shared mailboxes.
     *
     * See [[https://tools.ietf.org/html/rfc2342|RFC 2342]] for more
     * information.
     */
GeeList*
geary_imap_client_session_get_shared_namespaces (GearyImapClientSession* self)
{
	GeeList* _tmp0_;
	GeeList* _tmp1_;
	GeeList* _tmp2_;
	GeeList* result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), NULL);
	_tmp0_ = self->priv->shared_namespaces;
	_tmp1_ = gee_list_get_read_only_view (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

/**
     * Returns the list of known other-users mailbox namespaces.
     *
     * An other-user namespace is a common prefix of a set of
     * mailboxes that are the personal mailboxes of other accounts on
     * the server. These would not normally be accessible to the
     * currently authenticated account unless the account has
     * administration privileges.
     *
     * The list will be empty when the session is not in the
     * authenticated or selected states, it will only be non-empty
     * after having successfully logged in and if the server or
     * account supports accessing other account's mailboxes.
     *
     * See [[https://tools.ietf.org/html/rfc2342|RFC 2342]] for more
     * information.
     */
GeeList*
geary_imap_client_session_get_other_users_namespaces (GearyImapClientSession* self)
{
	GeeList* _tmp0_;
	GeeList* _tmp1_;
	GeeList* _tmp2_;
	GeeList* result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), NULL);
	_tmp0_ = self->priv->user_namespaces;
	_tmp1_ = gee_list_get_read_only_view (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

/**
     * Determines the SELECT-able mailbox name for a specific folder path.
     */
GearyImapMailboxSpecifier*
geary_imap_client_session_get_mailbox_for_path (GearyImapClientSession* self,
                                                GearyFolderPath* path,
                                                GError** error)
{
	gchar* delim = NULL;
	gchar* _tmp0_;
	GearyImapMailboxSpecifier* _tmp1_ = NULL;
	GearyImapMailboxInformation* _tmp2_;
	GearyImapMailboxSpecifier* _tmp3_;
	GearyImapMailboxSpecifier* _tmp4_;
	const gchar* _tmp5_;
	GearyImapMailboxSpecifier* _tmp6_;
	GearyImapMailboxSpecifier* _tmp7_;
	GError* _inner_error0_ = NULL;
	GearyImapMailboxSpecifier* result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), NULL);
	g_return_val_if_fail (GEARY_IS_FOLDER_PATH (path), NULL);
	_tmp0_ = geary_imap_client_session_get_delimiter_for_path (self, path, &_inner_error0_);
	delim = _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_ = self->priv->_inbox;
	_tmp3_ = geary_imap_mailbox_information_get_mailbox (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = delim;
	_tmp6_ = geary_imap_mailbox_specifier_new_from_folder_path (path, _tmp4_, _tmp5_, &_inner_error0_);
	_tmp1_ = _tmp6_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == GEARY_IMAP_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_free0 (delim);
			return NULL;
		} else {
			_g_free0 (delim);
			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;
		}
	}
	_tmp7_ = _tmp1_;
	_tmp1_ = NULL;
	result = _tmp7_;
	_g_object_unref0 (_tmp1_);
	_g_free0 (delim);
	return result;
}

/**
     * Determines the folder path for a mailbox name.
     */
GearyFolderPath*
geary_imap_client_session_get_path_for_mailbox (GearyImapClientSession* self,
                                                GearyImapFolderRoot* root,
                                                GearyImapMailboxSpecifier* mailbox,
                                                GError** error)
{
	gchar* delim = NULL;
	gchar* _tmp0_;
	GearyImapMailboxInformation* _tmp1_;
	GearyImapMailboxSpecifier* _tmp2_;
	GearyImapMailboxSpecifier* _tmp3_;
	GearyFolderPath* _tmp4_;
	GError* _inner_error0_ = NULL;
	GearyFolderPath* result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), NULL);
	g_return_val_if_fail (GEARY_IMAP_IS_FOLDER_ROOT (root), NULL);
	g_return_val_if_fail (GEARY_IMAP_IS_MAILBOX_SPECIFIER (mailbox), NULL);
	_tmp0_ = geary_imap_client_session_get_delimiter_for_mailbox (self, mailbox, &_inner_error0_);
	delim = _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;
		}
	}
	_tmp1_ = self->priv->_inbox;
	_tmp2_ = geary_imap_mailbox_information_get_mailbox (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = geary_imap_mailbox_specifier_to_folder_path (mailbox, root, delim, _tmp3_);
	result = _tmp4_;
	_g_free0 (delim);
	return result;
}

/**
     * Determines the mailbox hierarchy delimiter for a given folder path.
     *
     * The returned delimiter be null if a namespace (INBOX, personal,
     * etc) for the path does not exist, or if the namespace is flat.
     */
gchar*
geary_imap_client_session_get_delimiter_for_path (GearyImapClientSession* self,
                                                  GearyFolderPath* path,
                                                  GError** error)
{
	gchar* delim = NULL;
	GearyImapFolderRoot* root = NULL;
	GearyFolderRoot* _tmp0_;
	gboolean _tmp1_ = FALSE;
	GearyImapFolderRoot* _tmp2_;
	GearyFolderPath* _tmp3_;
	GearyFolderPath* _tmp4_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), NULL);
	g_return_val_if_fail (GEARY_IS_FOLDER_PATH (path), NULL);
	delim = NULL;
	_tmp0_ = geary_folder_path_get_root (path);
	root = G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEARY_IMAP_TYPE_FOLDER_ROOT, GearyImapFolderRoot);
	_tmp2_ = root;
	_tmp3_ = geary_imap_folder_root_get_inbox (_tmp2_);
	_tmp4_ = _tmp3_;
	if (gee_hashable_equal_to (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, GEE_TYPE_HASHABLE, GeeHashable), path)) {
		_tmp1_ = TRUE;
	} else {
		GearyImapFolderRoot* _tmp5_;
		GearyFolderPath* _tmp6_;
		GearyFolderPath* _tmp7_;
		_tmp5_ = root;
		_tmp6_ = geary_imap_folder_root_get_inbox (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp1_ = geary_folder_path_is_descendant (_tmp7_, path);
	}
	if (_tmp1_) {
		GearyImapMailboxInformation* _tmp8_;
		const gchar* _tmp9_;
		const gchar* _tmp10_;
		gchar* _tmp11_;
		_tmp8_ = self->priv->_inbox;
		_tmp9_ = geary_imap_mailbox_information_get_delim (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp11_ = g_strdup (_tmp10_);
		_g_free0 (delim);
		delim = _tmp11_;
	} else {
		GearyImapNamespace* ns = NULL;
		GearyFolderPath* search = NULL;
		GearyFolderPath* _tmp12_;
		GearyImapNamespace* _tmp25_;
		GearyImapNamespace* _tmp32_;
		const gchar* _tmp33_;
		const gchar* _tmp34_;
		gchar* _tmp35_;
		ns = NULL;
		_tmp12_ = _g_object_ref0 (path);
		search = _tmp12_;
		while (TRUE) {
			gboolean _tmp13_ = FALSE;
			GearyImapNamespace* _tmp14_;
			GeeMap* _tmp16_;
			GearyFolderPath* _tmp17_;
			const gchar* _tmp18_;
			const gchar* _tmp19_;
			gpointer _tmp20_;
			GearyFolderPath* _tmp21_;
			GearyFolderPath* _tmp22_;
			GearyFolderPath* _tmp23_;
			GearyFolderPath* _tmp24_;
			_tmp14_ = ns;
			if (_tmp14_ == NULL) {
				GearyFolderPath* _tmp15_;
				_tmp15_ = search;
				_tmp13_ = _tmp15_ != NULL;
			} else {
				_tmp13_ = FALSE;
			}
			if (!_tmp13_) {
				break;
			}
			_tmp16_ = self->priv->namespaces;
			_tmp17_ = search;
			_tmp18_ = geary_folder_path_get_name (_tmp17_);
			_tmp19_ = _tmp18_;
			_tmp20_ = gee_map_get (_tmp16_, _tmp19_);
			_g_object_unref0 (ns);
			ns = (GearyImapNamespace*) _tmp20_;
			_tmp21_ = search;
			_tmp22_ = geary_folder_path_get_parent (_tmp21_);
			_tmp23_ = _tmp22_;
			_tmp24_ = _g_object_ref0 (_tmp23_);
			_g_object_unref0 (search);
			search = _tmp24_;
		}
		_tmp25_ = ns;
		if (_tmp25_ == NULL) {
			GeeList* _tmp26_;
			gboolean _tmp27_;
			gboolean _tmp28_;
			GeeList* _tmp30_;
			gpointer _tmp31_;
			_tmp26_ = self->priv->personal_namespaces;
			_tmp27_ = gee_collection_get_is_empty (G_TYPE_CHECK_INSTANCE_CAST (_tmp26_, GEE_TYPE_COLLECTION, GeeCollection));
			_tmp28_ = _tmp27_;
			if (_tmp28_) {
				GError* _tmp29_;
				_tmp29_ = g_error_new_literal (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_UNAVAILABLE, "No personal namespace");
				_inner_error0_ = _tmp29_;
				if (_inner_error0_->domain == GEARY_IMAP_ERROR) {
					g_propagate_error (error, _inner_error0_);
					_g_object_unref0 (search);
					_g_object_unref0 (ns);
					_g_object_unref0 (root);
					_g_free0 (delim);
					return NULL;
				} else {
					_g_object_unref0 (search);
					_g_object_unref0 (ns);
					_g_object_unref0 (root);
					_g_free0 (delim);
					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;
				}
			}
			_tmp30_ = self->priv->personal_namespaces;
			_tmp31_ = gee_list_get (_tmp30_, 0);
			_g_object_unref0 (ns);
			ns = (GearyImapNamespace*) _tmp31_;
		}
		_tmp32_ = ns;
		_tmp33_ = geary_imap_namespace_get_delim (_tmp32_);
		_tmp34_ = _tmp33_;
		_tmp35_ = g_strdup (_tmp34_);
		_g_free0 (delim);
		delim = _tmp35_;
		_g_object_unref0 (search);
		_g_object_unref0 (ns);
	}
	result = delim;
	_g_object_unref0 (root);
	return result;
}

/**
     * Determines the mailbox hierarchy delimiter for a given mailbox name.
     *
     * The returned delimiter be null if a namespace (INBOX, personal,
     * etc) for the mailbox does not exist, or if the namespace is flat.
     */
gchar*
geary_imap_client_session_get_delimiter_for_mailbox (GearyImapClientSession* self,
                                                     GearyImapMailboxSpecifier* mailbox,
                                                     GError** error)
{
	gchar* name = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* delim = NULL;
	gchar* inbox_name = NULL;
	GearyImapMailboxInformation* _tmp3_;
	GearyImapMailboxSpecifier* _tmp4_;
	GearyImapMailboxSpecifier* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* inbox_delim = NULL;
	GearyImapMailboxInformation* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	gboolean _tmp13_ = FALSE;
	const gchar* _tmp14_;
	const gchar* _tmp15_;
	gchar* result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), NULL);
	g_return_val_if_fail (GEARY_IMAP_IS_MAILBOX_SPECIFIER (mailbox), NULL);
	_tmp0_ = geary_imap_mailbox_specifier_get_name (mailbox);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strdup (_tmp1_);
	name = _tmp2_;
	delim = NULL;
	_tmp3_ = self->priv->_inbox;
	_tmp4_ = geary_imap_mailbox_information_get_mailbox (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = geary_imap_mailbox_specifier_get_name (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_strdup (_tmp7_);
	inbox_name = _tmp8_;
	_tmp9_ = self->priv->_inbox;
	_tmp10_ = geary_imap_mailbox_information_get_delim (_tmp9_);
	_tmp11_ = _tmp10_;
	_tmp12_ = g_strdup (_tmp11_);
	inbox_delim = _tmp12_;
	_tmp14_ = inbox_name;
	_tmp15_ = name;
	if (g_strcmp0 (_tmp14_, _tmp15_) == 0) {
		_tmp13_ = TRUE;
	} else {
		gboolean _tmp16_ = FALSE;
		const gchar* _tmp17_;
		_tmp17_ = inbox_delim;
		if (_tmp17_ != NULL) {
			const gchar* _tmp18_;
			const gchar* _tmp19_;
			const gchar* _tmp20_;
			gchar* _tmp21_;
			gchar* _tmp22_;
			_tmp18_ = inbox_name;
			_tmp19_ = name;
			_tmp20_ = inbox_delim;
			_tmp21_ = g_strconcat (_tmp19_, _tmp20_, NULL);
			_tmp22_ = _tmp21_;
			_tmp16_ = g_str_has_prefix (_tmp18_, _tmp22_);
			_g_free0 (_tmp22_);
		} else {
			_tmp16_ = FALSE;
		}
		_tmp13_ = _tmp16_;
	}
	if (_tmp13_) {
		GearyImapMailboxInformation* _tmp23_;
		const gchar* _tmp24_;
		const gchar* _tmp25_;
		gchar* _tmp26_;
		_tmp23_ = self->priv->_inbox;
		_tmp24_ = geary_imap_mailbox_information_get_delim (_tmp23_);
		_tmp25_ = _tmp24_;
		_tmp26_ = g_strdup (_tmp25_);
		_g_free0 (delim);
		delim = _tmp26_;
	} else {
		{
			GeeIterator* _ns_it = NULL;
			GeeMap* _tmp27_;
			GeeCollection* _tmp28_;
			GeeCollection* _tmp29_;
			GeeCollection* _tmp30_;
			GeeIterator* _tmp31_;
			GeeIterator* _tmp32_;
			_tmp27_ = self->priv->namespaces;
			_tmp28_ = gee_map_get_values (_tmp27_);
			_tmp29_ = _tmp28_;
			_tmp30_ = _tmp29_;
			_tmp31_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp30_, GEE_TYPE_ITERABLE, GeeIterable));
			_tmp32_ = _tmp31_;
			_g_object_unref0 (_tmp30_);
			_ns_it = _tmp32_;
			while (TRUE) {
				GeeIterator* _tmp33_;
				GearyImapNamespace* ns = NULL;
				GeeIterator* _tmp34_;
				gpointer _tmp35_;
				const gchar* _tmp36_;
				GearyImapNamespace* _tmp37_;
				const gchar* _tmp38_;
				const gchar* _tmp39_;
				_tmp33_ = _ns_it;
				if (!gee_iterator_next (_tmp33_)) {
					break;
				}
				_tmp34_ = _ns_it;
				_tmp35_ = gee_iterator_get (_tmp34_);
				ns = (GearyImapNamespace*) _tmp35_;
				_tmp36_ = name;
				_tmp37_ = ns;
				_tmp38_ = geary_imap_namespace_get_prefix (_tmp37_);
				_tmp39_ = _tmp38_;
				if (g_str_has_prefix (_tmp36_, _tmp39_)) {
					GearyImapNamespace* _tmp40_;
					const gchar* _tmp41_;
					const gchar* _tmp42_;
					gchar* _tmp43_;
					_tmp40_ = ns;
					_tmp41_ = geary_imap_namespace_get_delim (_tmp40_);
					_tmp42_ = _tmp41_;
					_tmp43_ = g_strdup (_tmp42_);
					_g_free0 (delim);
					delim = _tmp43_;
					_g_object_unref0 (ns);
					break;
				}
				_g_object_unref0 (ns);
			}
			_g_object_unref0 (_ns_it);
		}
	}
	result = delim;
	_g_free0 (inbox_delim);
	_g_free0 (inbox_name);
	_g_free0 (name);
	return result;
}

static gboolean
geary_imap_client_session_reserve_state_change_cmd (GearyImapClientSession* self,
                                                    GearyImapClientSessionMachineParams* params,
                                                    guint state,
                                                    guint event)
{
	gboolean _tmp0_ = FALSE;
	GearyImapCommand* _tmp1_;
	GearyImapCommand* _tmp10_;
	GearyImapCommand* _tmp11_;
	gboolean result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), FALSE);
	g_return_val_if_fail (GEARY_IMAP_CLIENT_SESSION_IS_MACHINE_PARAMS (params), FALSE);
	_tmp1_ = self->priv->state_change_cmd;
	if (_tmp1_ != NULL) {
		_tmp0_ = TRUE;
	} else {
		GearyImapCommand* _tmp2_;
		_tmp2_ = params->cmd;
		_tmp0_ = _tmp2_ == NULL;
	}
	if (_tmp0_) {
		GearyStateMachine* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		GearyStateMachine* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		GError* _tmp9_;
		params->proceed = FALSE;
		_tmp3_ = self->priv->fsm;
		_tmp4_ = geary_state_machine_get_event_string (_tmp3_, event);
		_tmp5_ = _tmp4_;
		_tmp6_ = self->priv->fsm;
		_tmp7_ = geary_state_machine_get_state_string (_tmp6_, state);
		_tmp8_ = _tmp7_;
		_tmp9_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_NOT_SUPPORTED, "Cannot perform operation %s while session is %s", _tmp5_, _tmp8_);
		_g_error_free0 (params->err);
		params->err = _tmp9_;
		_g_free0 (_tmp8_);
		_g_free0 (_tmp5_);
		result = FALSE;
		return result;
	}
	_tmp10_ = params->cmd;
	_tmp11_ = _g_object_ref0 (_tmp10_);
	_g_object_unref0 (self->priv->state_change_cmd);
	self->priv->state_change_cmd = _tmp11_;
	params->proceed = TRUE;
	result = TRUE;
	return result;
}

static gboolean
geary_imap_client_session_validate_state_change_cmd (GearyImapClientSession* self,
                                                     GearyImapServerResponse* response,
                                                     GearyImapCommand** cmd)
{
	GearyImapCommand* _vala_cmd = NULL;
	GearyImapCommand* _tmp0_;
	GearyImapCommand* _tmp1_;
	gboolean _tmp2_ = FALSE;
	GearyImapCommand* _tmp3_;
	gboolean result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), FALSE);
	g_return_val_if_fail (GEARY_IMAP_IS_SERVER_RESPONSE (response), FALSE);
	_tmp0_ = self->priv->state_change_cmd;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (_vala_cmd);
	_vala_cmd = _tmp1_;
	_tmp3_ = self->priv->state_change_cmd;
	if (_tmp3_ == NULL) {
		_tmp2_ = TRUE;
	} else {
		GearyImapCommand* _tmp4_;
		GearyImapTag* _tmp5_;
		GearyImapTag* _tmp6_;
		GearyImapTag* _tmp7_;
		GearyImapTag* _tmp8_;
		_tmp4_ = self->priv->state_change_cmd;
		_tmp5_ = geary_imap_command_get_tag (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = geary_imap_server_response_get_tag (response);
		_tmp8_ = _tmp7_;
		_tmp2_ = !gee_hashable_equal_to (G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, GEE_TYPE_HASHABLE, GeeHashable), _tmp8_);
	}
	if (_tmp2_) {
		result = FALSE;
		if (cmd) {
			*cmd = _vala_cmd;
		} else {
			_g_object_unref0 (_vala_cmd);
		}
		return result;
	}
	_g_object_unref0 (self->priv->state_change_cmd);
	self->priv->state_change_cmd = NULL;
	result = TRUE;
	if (cmd) {
		*cmd = _vala_cmd;
	} else {
		_g_object_unref0 (_vala_cmd);
	}
	return result;
}

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

void
geary_imap_client_session_connect_async (GearyImapClientSession* self,
                                         guint greeting_timeout_sec,
                                         GCancellable* cancellable,
                                         GAsyncReadyCallback _callback_,
                                         gpointer _user_data_)
{
	GearyImapClientSessionConnectAsyncData* _data_;
	GearyImapClientSession* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapClientSessionConnectAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_client_session_connect_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->greeting_timeout_sec = greeting_timeout_sec;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_client_session_connect_async_co (_data_);
}

void
geary_imap_client_session_connect_finish (GearyImapClientSession* self,
                                          GAsyncResult* _res_,
                                          GError** error)
{
	GearyImapClientSessionConnectAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

/**
     * Connect to the server.
     *
     * This performs no transaction or session initiation with the
     * server.  See {@link login_async} and {@link
     * initiate_session_async} for next steps.
     *
     * If the connection fails (if this call throws an Error) the
     * ClientSession will be disconnected, even if the error was from
     * the server (that is, not a network problem).  The {@link
     * ClientSession} should be discarded.
     */
static gpointer
_g_error_copy0 (gpointer self)
{
	return self ? g_error_copy (self) : NULL;
}

static void
geary_imap_client_session_connect_async_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_)
{
	GearyImapClientSessionConnectAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_client_session_connect_async_co (_data_);
}

static gboolean
_geary_imap_client_session_on_greeting_timeout_gsource_func (gpointer self)
{
	gboolean result;
	result = geary_imap_client_session_on_greeting_timeout ((GearyImapClientSession*) self);
	return result;
}

static gboolean
geary_imap_client_session_connect_async_co (GearyImapClientSessionConnectAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = geary_imap_client_session_machine_params_new (NULL);
	_data_->params = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->self->priv->fsm;
	_data_->_tmp2_ = _data_->params;
	geary_state_machine_issue (_data_->_tmp1_, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CONNECT, NULL, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, G_TYPE_OBJECT, GObject), NULL);
	_data_->_tmp3_ = _data_->params;
	_data_->_tmp4_ = _data_->_tmp3_->err;
	if (_data_->_tmp4_ != NULL) {
		_data_->_tmp5_ = _data_->params;
		_data_->_tmp6_ = _data_->_tmp5_->err;
		_data_->_tmp7_ = _g_error_copy0 (_data_->_tmp6_);
		_data_->_inner_error0_ = _data_->_tmp7_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->params);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp8_ = _data_->params;
	_vala_assert (_data_->_tmp8_->proceed, "params.proceed");
	_data_->_tmp9_ = _data_->self->priv->cx;
	_vala_assert (_data_->_tmp9_ != NULL, "cx != null");
	_data_->_tmp10_ = _data_->self->priv->connect_waiter;
	_vala_assert (_data_->_tmp10_ != NULL, "connect_waiter != null");
	{
		_data_->_tmp11_ = _data_->self->priv->cx;
		_data_->_state_ = 1;
		geary_imap_client_connection_connect_async (_data_->_tmp11_, _data_->cancellable, geary_imap_client_session_connect_async_ready, _data_);
		return FALSE;
		_state_1:
		geary_imap_client_connection_connect_finish (_data_->_tmp11_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp12_ = _data_->self->priv->fsm;
		geary_state_machine_issue (_data_->_tmp12_, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CONNECTED, NULL, NULL, NULL);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->err = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp13_ = _data_->self->priv->fsm;
		_data_->_tmp14_ = _data_->err;
		geary_state_machine_issue (_data_->_tmp13_, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_ERROR, NULL, NULL, _data_->_tmp14_);
		_data_->_tmp15_ = _data_->err;
		_data_->_tmp16_ = _g_error_copy0 (_data_->_tmp15_);
		_data_->_inner_error0_ = _data_->_tmp16_;
		_g_error_free0 (_data_->err);
		goto __finally0;
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->params);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp17_ = geary_scheduler_after_sec (_data_->greeting_timeout_sec, _geary_imap_client_session_on_greeting_timeout_gsource_func, _data_->self, G_PRIORITY_DEFAULT);
	_data_->timeout = _data_->_tmp17_;
	{
		_data_->_tmp18_ = _data_->self->priv->connect_waiter;
		_data_->_state_ = 2;
		geary_nonblocking_lock_wait_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp18_, GEARY_NONBLOCKING_TYPE_LOCK, GearyNonblockingLock), _data_->cancellable, geary_imap_client_session_connect_async_ready, _data_);
		return FALSE;
		_state_2:
		geary_nonblocking_lock_wait_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp18_, GEARY_NONBLOCKING_TYPE_LOCK, GearyNonblockingLock), _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			if (g_error_matches (_data_->_inner_error0_, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
				goto __catch1_g_io_error_cancelled;
			}
			goto __finally1;
		}
	}
	goto __finally1;
	__catch1_g_io_error_cancelled:
	{
		_data_->_vala1_err = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp19_ = _data_->_vala1_err;
		_data_->_tmp20_ = _g_error_copy0 (_data_->_tmp19_);
		_g_error_free0 (_data_->self->priv->connect_err);
		_data_->self->priv->connect_err = _data_->_tmp20_;
		_g_error_free0 (_data_->_vala1_err);
	}
	__finally1:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->timeout);
		_g_object_unref0 (_data_->params);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp21_ = _data_->timeout;
	geary_scheduler_scheduled_cancel (_data_->_tmp21_);
	_data_->_tmp22_ = _data_->self->priv->connect_err;
	if (_data_->_tmp22_ != NULL) {
		{
			_data_->_state_ = 3;
			geary_imap_client_session_disconnect_async (_data_->self, _data_->cancellable, geary_imap_client_session_connect_async_ready, _data_);
			return FALSE;
			_state_3:
			geary_imap_client_session_disconnect_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch2_g_error;
			}
		}
		goto __finally2;
		__catch2_g_error:
		{
			_data_->_vala2_err = _data_->_inner_error0_;
			_data_->_inner_error0_ = NULL;
			_data_->_tmp23_ = _data_->_vala2_err;
			_data_->_tmp24_ = _data_->_tmp23_->message;
			geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Error disconnecting after a failed connect attempt: %s", _data_->_tmp24_);
			_g_error_free0 (_data_->_vala2_err);
		}
		__finally2:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->timeout);
			_g_object_unref0 (_data_->params);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp25_ = _data_->self->priv->connect_err;
		_data_->_tmp26_ = _g_error_copy0 (_data_->_tmp25_);
		_data_->_inner_error0_ = _data_->_tmp26_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->timeout);
		_g_object_unref0 (_data_->params);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_object_unref0 (_data_->timeout);
	_g_object_unref0 (_data_->params);
	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 gboolean
geary_imap_client_session_on_greeting_timeout (GearyImapClientSession* self)
{
	GearyStateMachine* _tmp0_;
	guint _tmp1_;
	guint _tmp2_;
	gboolean result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), FALSE);
	_tmp0_ = self->priv->fsm;
	_tmp1_ = geary_state_machine_get_state (_tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_ == ((guint) GEARY_IMAP_CLIENT_SESSION_STATE_CONNECTING)) {
		GearyStateMachine* _tmp3_;
		_tmp3_ = self->priv->fsm;
		geary_state_machine_issue (_tmp3_, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_TIMEOUT, NULL, NULL, NULL);
	}
	result = FALSE;
	return result;
}

static void
_geary_imap_client_session_on_network_send_error_geary_imap_client_connection_send_failure (GearyImapClientConnection* _sender,
                                                                                            GError* err,
                                                                                            gpointer self)
{
	geary_imap_client_session_on_network_send_error ((GearyImapClientSession*) self, err);
}

static void
_geary_imap_client_session_on_received_status_response_geary_imap_client_connection_received_status_response (GearyImapClientConnection* _sender,
                                                                                                              GearyImapStatusResponse* status_response,
                                                                                                              gpointer self)
{
	geary_imap_client_session_on_received_status_response ((GearyImapClientSession*) self, status_response);
}

static void
_geary_imap_client_session_on_received_server_data_geary_imap_client_connection_received_server_data (GearyImapClientConnection* _sender,
                                                                                                      GearyImapServerData* server_data,
                                                                                                      gpointer self)
{
	geary_imap_client_session_on_received_server_data ((GearyImapClientSession*) self, server_data);
}

static void
_geary_imap_client_session_on_received_bytes_geary_imap_client_connection_received_bytes (GearyImapClientConnection* _sender,
                                                                                          gsize bytes,
                                                                                          gpointer self)
{
	geary_imap_client_session_on_received_bytes ((GearyImapClientSession*) self);
}

static void
_geary_imap_client_session_on_received_bad_response_geary_imap_client_connection_received_bad_response (GearyImapClientConnection* _sender,
                                                                                                        GearyImapRootParameters* root,
                                                                                                        GError* err,
                                                                                                        gpointer self)
{
	geary_imap_client_session_on_received_bad_response ((GearyImapClientSession*) self, root, err);
}

static void
_geary_imap_client_session_on_network_receive_failure_geary_imap_client_connection_receive_failure (GearyImapClientConnection* _sender,
                                                                                                    GError* err,
                                                                                                    gpointer self)
{
	geary_imap_client_session_on_network_receive_failure ((GearyImapClientSession*) self, err);
}

static guint
geary_imap_client_session_on_connect (GearyImapClientSession* self,
                                      guint state,
                                      guint event,
                                      void* user,
                                      GObject* object)
{
	GearyImapClientSessionMachineParams* params = NULL;
	GearyImapClientSessionMachineParams* _tmp0_;
	GearyImapClientConnection* _tmp1_;
	GearyEndpoint* _tmp2_;
	GearyImapQuirks* _tmp3_;
	GearyImapClientConnection* _tmp4_;
	GearyImapClientConnection* _tmp5_;
	GearyImapClientConnection* _tmp6_;
	GearyImapClientConnection* _tmp7_;
	GearyImapClientConnection* _tmp8_;
	GearyImapClientConnection* _tmp9_;
	GearyImapClientConnection* _tmp10_;
	GearyImapClientConnection* _tmp11_;
	GearyNonblockingSemaphore* _tmp12_;
	GearyNonblockingSemaphore* _tmp13_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS, GearyImapClientSessionMachineParams));
	params = _tmp0_;
	_tmp1_ = self->priv->cx;
	_vala_assert (_tmp1_ == NULL, "cx == null");
	_tmp2_ = self->priv->imap_endpoint;
	_tmp3_ = self->priv->_quirks;
	_tmp4_ = geary_imap_client_connection_new (_tmp2_, _tmp3_, GEARY_IMAP_COMMAND_DEFAULT_RESPONSE_TIMEOUT_SEC, GEARY_IMAP_CLIENT_CONNECTION_DEFAULT_IDLE_TIMEOUT_SEC);
	_g_object_unref0 (self->priv->cx);
	self->priv->cx = _tmp4_;
	_tmp5_ = self->priv->cx;
	geary_imap_client_connection_set_logging_parent (_tmp5_, G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
	_tmp6_ = self->priv->cx;
	g_signal_connect_object (_tmp6_, "send-failure", (GCallback) _geary_imap_client_session_on_network_send_error_geary_imap_client_connection_send_failure, self, 0);
	_tmp7_ = self->priv->cx;
	g_signal_connect_object (_tmp7_, "received-status-response", (GCallback) _geary_imap_client_session_on_received_status_response_geary_imap_client_connection_received_status_response, self, 0);
	_tmp8_ = self->priv->cx;
	g_signal_connect_object (_tmp8_, "received-server-data", (GCallback) _geary_imap_client_session_on_received_server_data_geary_imap_client_connection_received_server_data, self, 0);
	_tmp9_ = self->priv->cx;
	g_signal_connect_object (_tmp9_, "received-bytes", (GCallback) _geary_imap_client_session_on_received_bytes_geary_imap_client_connection_received_bytes, self, 0);
	_tmp10_ = self->priv->cx;
	g_signal_connect_object (_tmp10_, "received-bad-response", (GCallback) _geary_imap_client_session_on_received_bad_response_geary_imap_client_connection_received_bad_response, self, 0);
	_tmp11_ = self->priv->cx;
	g_signal_connect_object (_tmp11_, "receive-failure", (GCallback) _geary_imap_client_session_on_network_receive_failure_geary_imap_client_connection_receive_failure, self, 0);
	_tmp12_ = self->priv->connect_waiter;
	_vala_assert (_tmp12_ == NULL, "connect_waiter == null");
	_tmp13_ = geary_nonblocking_semaphore_new (NULL);
	_g_object_unref0 (self->priv->connect_waiter);
	self->priv->connect_waiter = _tmp13_;
	params->proceed = TRUE;
	result = (guint) GEARY_IMAP_CLIENT_SESSION_STATE_CONNECTING;
	_g_object_unref0 (params);
	return result;
}

static void
geary_imap_client_session_drop_connection (GearyImapClientSession* self)
{
	GearyImapClientConnection* _tmp0_;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	geary_imap_client_session_unschedule_keepalive (self);
	_tmp0_ = self->priv->cx;
	if (_tmp0_ != NULL) {
		GearyImapClientConnection* _tmp1_;
		guint _tmp2_;
		GearyImapClientConnection* _tmp3_;
		guint _tmp4_;
		GearyImapClientConnection* _tmp5_;
		guint _tmp6_;
		GearyImapClientConnection* _tmp7_;
		guint _tmp8_;
		GearyImapClientConnection* _tmp9_;
		guint _tmp10_;
		_tmp1_ = self->priv->cx;
		g_signal_parse_name ("received-status-response", GEARY_IMAP_TYPE_CLIENT_CONNECTION, &_tmp2_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp1_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp2_, 0, NULL, (GCallback) _geary_imap_client_session_on_received_status_response_geary_imap_client_connection_received_status_response, self);
		_tmp3_ = self->priv->cx;
		g_signal_parse_name ("received-server-data", GEARY_IMAP_TYPE_CLIENT_CONNECTION, &_tmp4_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp3_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp4_, 0, NULL, (GCallback) _geary_imap_client_session_on_received_server_data_geary_imap_client_connection_received_server_data, self);
		_tmp5_ = self->priv->cx;
		g_signal_parse_name ("received-bytes", GEARY_IMAP_TYPE_CLIENT_CONNECTION, &_tmp6_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp5_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp6_, 0, NULL, (GCallback) _geary_imap_client_session_on_received_bytes_geary_imap_client_connection_received_bytes, self);
		_tmp7_ = self->priv->cx;
		g_signal_parse_name ("received-bad-response", GEARY_IMAP_TYPE_CLIENT_CONNECTION, &_tmp8_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp7_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp8_, 0, NULL, (GCallback) _geary_imap_client_session_on_received_bad_response_geary_imap_client_connection_received_bad_response, self);
		_tmp9_ = self->priv->cx;
		g_signal_parse_name ("receive-failure", GEARY_IMAP_TYPE_CLIENT_CONNECTION, &_tmp10_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp9_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp10_, 0, NULL, (GCallback) _geary_imap_client_session_on_network_receive_failure_geary_imap_client_connection_receive_failure, self);
		_g_object_unref0 (self->priv->cx);
		self->priv->cx = NULL;
	}
}

static guint
geary_imap_client_session_on_connected (GearyImapClientSession* self,
                                        guint state,
                                        guint event)
{
	GearyEndpoint* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	_tmp0_ = self->priv->imap_endpoint;
	_tmp1_ = geary_endpoint_to_string (_tmp0_);
	_tmp2_ = _tmp1_;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Connected to %s", _tmp2_);
	_g_free0 (_tmp2_);
	result = state;
	return result;
}

static guint
geary_imap_client_session_on_disconnect (GearyImapClientSession* self,
                                         guint state,
                                         guint event,
                                         void* user,
                                         GObject* object,
                                         GError* err)
{
	GearyEndpoint* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	GearyImapClientSessionMachineParams* params = NULL;
	GearyImapClientSessionMachineParams* _tmp3_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_tmp0_ = self->priv->imap_endpoint;
	_tmp1_ = geary_endpoint_to_string (_tmp0_);
	_tmp2_ = _tmp1_;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Disconnected from %s", _tmp2_);
	_g_free0 (_tmp2_);
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS, GearyImapClientSessionMachineParams));
	params = _tmp3_;
	params->proceed = TRUE;
	result = (guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED;
	_g_object_unref0 (params);
	return result;
}

static guint
geary_imap_client_session_on_connecting_recv_status (GearyImapClientSession* self,
                                                     guint state,
                                                     guint event,
                                                     void* user,
                                                     GObject* object)
{
	GearyImapStatusResponse* status_response = NULL;
	GearyImapStatusResponse* _tmp0_;
	guint new_state = 0U;
	GearyImapStatusResponse* _tmp1_;
	GearyImapStatus _tmp2_;
	GearyImapStatus _tmp3_;
	GearyImapStatusResponse* _tmp8_;
	GearyImapStatusResponse* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	GError* _inner_error0_ = NULL;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_TYPE_STATUS_RESPONSE, GearyImapStatusResponse));
	status_response = _tmp0_;
	new_state = (guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOAUTH;
	_tmp1_ = status_response;
	_tmp2_ = geary_imap_status_response_get_status (_tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_ != GEARY_IMAP_STATUS_OK) {
		GearyImapStatusResponse* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		GError* _tmp7_;
		_tmp4_ = status_response;
		_tmp5_ = geary_imap_status_response_get_text (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_UNAVAILABLE, "Session denied: %s", _tmp6_);
		_g_error_free0 (self->priv->connect_err);
		self->priv->connect_err = _tmp7_;
		_g_free0 (_tmp6_);
		new_state = (guint) GEARY_IMAP_CLIENT_SESSION_STATE_LOGOUT;
	}
	_tmp8_ = status_response;
	geary_imap_client_session_set_server_greeting (self, _tmp8_);
	_tmp9_ = status_response;
	_tmp10_ = geary_imap_status_response_get_text (_tmp9_);
	_tmp11_ = _tmp10_;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Server greeting: %s", _tmp11_);
	_g_free0 (_tmp11_);
	{
		GearyNonblockingSemaphore* _tmp12_;
		_tmp12_ = self->priv->connect_waiter;
		geary_nonblocking_lock_notify (G_TYPE_CHECK_INSTANCE_CAST (_tmp12_, GEARY_NONBLOCKING_TYPE_LOCK, GearyNonblockingLock), &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* err = NULL;
		GError* _tmp13_;
		const gchar* _tmp14_;
		err = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp13_ = err;
		_tmp14_ = _tmp13_->message;
		geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Unable to notify connect_waiter of connection: %s", _tmp14_);
		_g_error_free0 (err);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		guint _tmp15_ = 0U;
		_g_object_unref0 (status_response);
		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 _tmp15_;
	}
	result = new_state;
	_g_object_unref0 (status_response);
	return result;
}

static guint
geary_imap_client_session_on_connecting_timeout (GearyImapClientSession* self,
                                                 guint state,
                                                 guint event)
{
	GError* _tmp0_;
	GError* _inner_error0_ = NULL;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	_tmp0_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_TIMED_OUT, "Session greeting not sent");
	_g_error_free0 (self->priv->connect_err);
	self->priv->connect_err = _tmp0_;
	{
		GearyNonblockingSemaphore* _tmp1_;
		_tmp1_ = self->priv->connect_waiter;
		geary_nonblocking_lock_notify (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEARY_NONBLOCKING_TYPE_LOCK, GearyNonblockingLock), &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* err = NULL;
		GError* _tmp2_;
		const gchar* _tmp3_;
		err = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp2_ = err;
		_tmp3_ = _tmp2_->message;
		geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Unable to notify connect_waiter of timeout: %s", _tmp3_);
		_g_error_free0 (err);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		guint _tmp4_ = 0U;
		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 _tmp4_;
	}
	result = (guint) GEARY_IMAP_CLIENT_SESSION_STATE_LOGOUT;
	return result;
}

static void
geary_imap_client_session_login_async_data_free (gpointer _data)
{
	GearyImapClientSessionLoginAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->credentials);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapClientSessionLoginAsyncData, _data_);
}

void
geary_imap_client_session_login_async (GearyImapClientSession* self,
                                       GearyCredentials* credentials,
                                       GCancellable* cancellable,
                                       GAsyncReadyCallback _callback_,
                                       gpointer _user_data_)
{
	GearyImapClientSessionLoginAsyncData* _data_;
	GearyImapClientSession* _tmp0_;
	GearyCredentials* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail (GEARY_IS_CREDENTIALS (credentials));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapClientSessionLoginAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_client_session_login_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (credentials);
	_g_object_unref0 (_data_->credentials);
	_data_->credentials = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_client_session_login_async_co (_data_);
}

GearyImapStatusResponse*
geary_imap_client_session_login_finish (GearyImapClientSession* self,
                                        GAsyncResult* _res_,
                                        GError** error)
{
	GearyImapStatusResponse* result;
	GearyImapClientSessionLoginAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

/**
     * Performs the LOGIN command using the supplied credentials.
     *
     * Throws {@link ImapError.UNAUTHENTICATED} if the credentials are
     * bad, unsupported, or if authentication actually failed. Returns
     * the status response for the command otherwise.
     *
     * @see initiate_session_async
     */
static void
geary_imap_client_session_login_async_ready (GObject* source_object,
                                             GAsyncResult* _res_,
                                             gpointer _user_data_)
{
	GearyImapClientSessionLoginAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_client_session_login_async_co (_data_);
}

static gboolean
geary_imap_client_session_login_async_co (GearyImapClientSessionLoginAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->cmd = NULL;
	_data_->_tmp0_ = geary_credentials_get_supported_method (_data_->credentials);
	_data_->_tmp1_ = _data_->_tmp0_;
	switch (_data_->_tmp1_) {
		case GEARY_CREDENTIALS_METHOD_PASSWORD:
		{
			_data_->_tmp2_ = geary_credentials_get_user (_data_->credentials);
			_data_->_tmp3_ = _data_->_tmp2_;
			_data_->_tmp4_ = geary_credentials_get_token (_data_->credentials);
			_data_->_tmp5_ = _data_->_tmp4_;
			_data_->_tmp6_ = geary_imap_login_command_new (_data_->_tmp3_, _data_->_tmp5_, _data_->cancellable);
			_g_object_unref0 (_data_->cmd);
			_data_->cmd = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp6_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand);
			break;
		}
		case GEARY_CREDENTIALS_METHOD_OAUTH2:
		{
			_data_->_tmp7_ = _data_->self->priv->_capabilities;
			if (!geary_generic_capabilities_has_setting (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp7_, GEARY_TYPE_GENERIC_CAPABILITIES, GearyGenericCapabilities), GEARY_IMAP_CAPABILITIES_AUTH, GEARY_IMAP_CAPABILITIES_AUTH_XOAUTH2)) {
				_data_->_tmp8_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
				_data_->_tmp9_ = _data_->_tmp8_;
				_data_->_tmp10_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_UNAUTHENTICATED, "OAuth2 authentication not supported for %s", _data_->_tmp9_);
				_data_->_tmp11_ = _data_->_tmp10_;
				_g_free0 (_data_->_tmp9_);
				_data_->_inner_error0_ = _data_->_tmp11_;
				g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
				_g_object_unref0 (_data_->cmd);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
			_data_->_tmp12_ = geary_credentials_get_user (_data_->credentials);
			_data_->_tmp13_ = _data_->_tmp12_;
			_data_->_tmp14_ = geary_credentials_get_token (_data_->credentials);
			_data_->_tmp15_ = _data_->_tmp14_;
			_data_->_tmp16_ = geary_imap_authenticate_command_new_oauth2 (_data_->_tmp13_, _data_->_tmp15_, _data_->cancellable);
			_g_object_unref0 (_data_->cmd);
			_data_->cmd = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp16_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand);
			break;
		}
		default:
		{
			_data_->_tmp17_ = geary_credentials_get_supported_method (_data_->credentials);
			_data_->_tmp18_ = _data_->_tmp17_;
			_data_->_tmp19_ = geary_credentials_method_to_string (_data_->_tmp18_);
			_data_->_tmp20_ = _data_->_tmp19_;
			_data_->_tmp21_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
			_data_->_tmp22_ = _data_->_tmp21_;
			_data_->_tmp23_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_UNAUTHENTICATED, "Credentials method %s not supported for: %s", _data_->_tmp20_, _data_->_tmp22_);
			_data_->_tmp24_ = _data_->_tmp23_;
			_g_free0 (_data_->_tmp22_);
			_g_free0 (_data_->_tmp20_);
			_data_->_inner_error0_ = _data_->_tmp24_;
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->cmd);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->_tmp25_ = _data_->cmd;
	_data_->_tmp26_ = geary_imap_client_session_machine_params_new (_data_->_tmp25_);
	_data_->params = _data_->_tmp26_;
	_data_->_tmp27_ = _data_->self->priv->fsm;
	_data_->_tmp28_ = _data_->params;
	geary_state_machine_issue (_data_->_tmp27_, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGIN, NULL, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp28_, G_TYPE_OBJECT, GObject), NULL);
	_data_->_tmp29_ = _data_->params;
	_data_->_tmp30_ = _data_->_tmp29_->err;
	if (_data_->_tmp30_ != NULL) {
		_data_->_tmp31_ = _data_->params;
		_data_->_tmp32_ = _data_->_tmp31_->err;
		_data_->_tmp33_ = _g_error_copy0 (_data_->_tmp32_);
		_data_->_inner_error0_ = _data_->_tmp33_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->params);
		_g_object_unref0 (_data_->cmd);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp34_ = _data_->params;
	_vala_assert (_data_->_tmp34_->proceed, "params.proceed");
	_data_->_tmp35_ = _data_->cmd;
	_data_->_state_ = 1;
	geary_imap_client_session_submit_command (_data_->self, _data_->_tmp35_, geary_imap_client_session_login_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp36_ = geary_imap_client_session_submit_command_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->response = _data_->_tmp36_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->params);
		_g_object_unref0 (_data_->cmd);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp37_ = _data_->response;
	_data_->_tmp38_ = geary_imap_status_response_get_status (_data_->_tmp37_);
	_data_->_tmp39_ = _data_->_tmp38_;
	if (_data_->_tmp39_ != GEARY_IMAP_STATUS_OK) {
		_data_->_tmp40_ = _data_->response;
		_data_->_tmp41_ = geary_imap_status_response_get_response_code (_data_->_tmp40_);
		_data_->_tmp42_ = _data_->_tmp41_;
		_data_->_tmp43_ = _g_object_ref0 (_data_->_tmp42_);
		_data_->code = _data_->_tmp43_;
		_data_->_tmp44_ = _data_->code;
		if (_data_->_tmp44_ != NULL) {
			_data_->_tmp45_ = _data_->code;
			_data_->_tmp46_ = geary_imap_response_code_get_response_code_type (_data_->_tmp45_, &_data_->_inner_error0_);
			_data_->code_type = _data_->_tmp46_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
				_g_object_unref0 (_data_->code);
				_g_object_unref0 (_data_->response);
				_g_object_unref0 (_data_->params);
				_g_object_unref0 (_data_->cmd);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
			_data_->_tmp47_ = _data_->code_type;
			if (_data_->_tmp47_ != NULL) {
				static GQuark _tmp52_label0 = 0;
				static GQuark _tmp52_label1 = 0;
				_data_->_tmp48_ = _data_->code_type;
				_data_->_tmp49_ = geary_imap_response_code_type_get_value (_data_->_tmp48_);
				_data_->_tmp50_ = _data_->_tmp49_;
				_data_->_tmp53_ = 0U;
				_data_->_tmp51_ = _data_->_tmp50_;
				_data_->_tmp53_ = (NULL == _data_->_tmp51_) ? 0 : g_quark_from_string (_data_->_tmp51_);
				if (_data_->_tmp53_ == ((0 != _tmp52_label0) ? _tmp52_label0 : (_tmp52_label0 = g_quark_from_static_string (GEARY_IMAP_RESPONSE_CODE_TYPE_UNAVAILABLE)))) {
					switch (0) {
						default:
						{
							_data_->_tmp54_ = _data_->response;
							_data_->_tmp55_ = geary_imap_parameter_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp54_, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
							_data_->_tmp56_ = _data_->_tmp55_;
							_data_->_tmp57_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_UNAVAILABLE, "Login restricted: %s: ", _data_->_tmp56_);
							_data_->_tmp58_ = _data_->_tmp57_;
							_g_free0 (_data_->_tmp56_);
							_data_->_inner_error0_ = _data_->_tmp58_;
							g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
							_g_object_unref0 (_data_->code_type);
							_g_object_unref0 (_data_->code);
							_g_object_unref0 (_data_->response);
							_g_object_unref0 (_data_->params);
							_g_object_unref0 (_data_->cmd);
							g_object_unref (_data_->_async_result);
							return FALSE;
						}
					}
				} else if (_data_->_tmp53_ == ((0 != _tmp52_label1) ? _tmp52_label1 : (_tmp52_label1 = g_quark_from_static_string (GEARY_IMAP_RESPONSE_CODE_TYPE_AUTHENTICATIONFAILED)))) {
					switch (0) {
						default:
						{
							break;
						}
					}
				} else {
					switch (0) {
						default:
						{
							_data_->_tmp59_ = _data_->response;
							_data_->_tmp60_ = geary_imap_parameter_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp59_, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
							_data_->_tmp61_ = _data_->_tmp60_;
							_data_->_tmp62_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_SERVER_ERROR, "Login error: %s: ", _data_->_tmp61_);
							_data_->_tmp63_ = _data_->_tmp62_;
							_g_free0 (_data_->_tmp61_);
							_data_->_inner_error0_ = _data_->_tmp63_;
							g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
							_g_object_unref0 (_data_->code_type);
							_g_object_unref0 (_data_->code);
							_g_object_unref0 (_data_->response);
							_g_object_unref0 (_data_->params);
							_g_object_unref0 (_data_->cmd);
							g_object_unref (_data_->_async_result);
							return FALSE;
						}
					}
				}
			}
			_g_object_unref0 (_data_->code_type);
		}
		_data_->_tmp64_ = _data_->response;
		_data_->_tmp65_ = geary_imap_parameter_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp64_, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
		_data_->_tmp66_ = _data_->_tmp65_;
		_data_->_tmp67_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_UNAUTHENTICATED, "Bad credentials: %s: ", _data_->_tmp66_);
		_data_->_tmp68_ = _data_->_tmp67_;
		_g_free0 (_data_->_tmp66_);
		_data_->_inner_error0_ = _data_->_tmp68_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->code);
		_g_object_unref0 (_data_->response);
		_g_object_unref0 (_data_->params);
		_g_object_unref0 (_data_->cmd);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp69_ = _data_->cmd;
	_data_->_tmp70_ = geary_imap_command_get_status (_data_->_tmp69_);
	_data_->_tmp71_ = _data_->_tmp70_;
	_data_->_tmp72_ = _g_object_ref0 (_data_->_tmp71_);
	_data_->result = _data_->_tmp72_;
	_g_object_unref0 (_data_->response);
	_g_object_unref0 (_data_->params);
	_g_object_unref0 (_data_->cmd);
	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_client_session_initiate_session_async_data_free (gpointer _data)
{
	GearyImapClientSessionInitiateSessionAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->credentials);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapClientSessionInitiateSessionAsyncData, _data_);
}

void
geary_imap_client_session_initiate_session_async (GearyImapClientSession* self,
                                                  GearyCredentials* credentials,
                                                  GCancellable* cancellable,
                                                  GAsyncReadyCallback _callback_,
                                                  gpointer _user_data_)
{
	GearyImapClientSessionInitiateSessionAsyncData* _data_;
	GearyImapClientSession* _tmp0_;
	GearyCredentials* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail (GEARY_IS_CREDENTIALS (credentials));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapClientSessionInitiateSessionAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_client_session_initiate_session_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (credentials);
	_g_object_unref0 (_data_->credentials);
	_data_->credentials = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_client_session_initiate_session_async_co (_data_);
}

void
geary_imap_client_session_initiate_session_finish (GearyImapClientSession* self,
                                                   GAsyncResult* _res_,
                                                   GError** error)
{
	GearyImapClientSessionInitiateSessionAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

/**
     * Prepares the connection and performs a login using the supplied credentials.
     *
     * Preparing the connection includes attempting compression and using STARTTLS if necessary.
     * {@link Capabilities} are also retrieved automatically at the right time to ensure the best
     * results are available with {@link capabilities}.
     */
static Block32Data*
block32_data_ref (Block32Data* _data32_)
{
	g_atomic_int_inc (&_data32_->_ref_count_);
	return _data32_;
}

static void
block32_data_unref (void * _userdata_)
{
	Block32Data* _data32_;
	_data32_ = (Block32Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data32_->_ref_count_)) {
		GearyImapClientSession* self;
		self = _data32_->self;
		_g_object_unref0 (_data32_->list_results);
		_g_object_unref0 (self);
		g_slice_free (Block32Data, _data32_);
	}
}

static void
geary_imap_client_session_initiate_session_async_ready (GObject* source_object,
                                                        GAsyncResult* _res_,
                                                        gpointer _user_data_)
{
	GearyImapClientSessionInitiateSessionAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_client_session_initiate_session_async_co (_data_);
}

static void
__lambda50_ (Block32Data* _data32_,
             GearyImapMailboxInformation* mailbox)
{
	GearyImapClientSession* self;
	GeeArrayList* _tmp0_;
	self = _data32_->self;
	g_return_if_fail (GEARY_IMAP_IS_MAILBOX_INFORMATION (mailbox));
	_tmp0_ = _data32_->list_results;
	gee_abstract_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection), mailbox);
}

static void
___lambda50__geary_imap_client_session_list (GearyImapClientSession* _sender,
                                             GearyImapMailboxInformation* mailbox_info,
                                             gpointer self)
{
	__lambda50_ (self, mailbox_info);
}

static gboolean
geary_imap_client_session_initiate_session_async_co (GearyImapClientSessionInitiateSessionAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		case 4:
		goto _state_4;
		case 5:
		goto _state_5;
		case 6:
		goto _state_6;
		case 7:
		goto _state_7;
		case 8:
		goto _state_8;
		case 9:
		goto _state_9;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data32_ = g_slice_new0 (Block32Data);
	_data_->_data32_->_ref_count_ = 1;
	_data_->_data32_->self = g_object_ref (_data_->self);
	_data_->_data32_->_async_data_ = _data_;
	_data_->_tmp0_ = _data_->self->priv->_capabilities;
	if (geary_generic_capabilities_is_empty (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEARY_TYPE_GENERIC_CAPABILITIES, GearyGenericCapabilities))) {
		_data_->_tmp1_ = geary_imap_capability_command_new (_data_->cancellable);
		_data_->_tmp2_ = _data_->_tmp1_;
		_data_->_state_ = 1;
		geary_imap_client_session_send_command_async (_data_->self, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand), geary_imap_client_session_initiate_session_async_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp3_ = geary_imap_client_session_send_command_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp4_ = _data_->_tmp3_;
		_g_object_unref0 (_data_->_tmp4_);
		_g_object_unref0 (_data_->_tmp2_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			block32_data_unref (_data_->_data32_);
			_data_->_data32_ = NULL;
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->_tmp5_ = _data_->self->priv->_capabilities;
	_data_->_tmp6_ = geary_imap_capabilities_get_revision (_data_->_tmp5_);
	_data_->_tmp7_ = _data_->_tmp6_;
	_data_->last_capabilities = _data_->_tmp7_;
	_data_->_tmp8_ = _data_->self->priv->imap_endpoint;
	_data_->_tmp9_ = geary_endpoint_get_tls_method (_data_->_tmp8_);
	_data_->_tmp10_ = _data_->_tmp9_;
	if (_data_->_tmp10_ == GEARY_TLS_NEGOTIATION_METHOD_START_TLS) {
		_data_->_tmp11_ = _data_->self->priv->_capabilities;
		if (!geary_generic_capabilities_has_capability (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp11_, GEARY_TYPE_GENERIC_CAPABILITIES, GearyGenericCapabilities), GEARY_IMAP_CAPABILITIES_STARTTLS)) {
			_data_->_tmp12_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
			_data_->_tmp13_ = _data_->_tmp12_;
			_data_->_tmp14_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_NOT_SUPPORTED, "STARTTLS unavailable for %s", _data_->_tmp13_);
			_data_->_tmp15_ = _data_->_tmp14_;
			_g_free0 (_data_->_tmp13_);
			_data_->_inner_error0_ = _data_->_tmp15_;
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			block32_data_unref (_data_->_data32_);
			_data_->_data32_ = NULL;
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Attempting STARTTLS...");
		_data_->_tmp16_ = geary_imap_starttls_command_new (_data_->cancellable);
		_data_->_tmp17_ = _data_->_tmp16_;
		_data_->_state_ = 2;
		geary_imap_client_session_send_command_async (_data_->self, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp17_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand), geary_imap_client_session_initiate_session_async_ready, _data_);
		return FALSE;
		_state_2:
		_data_->_tmp18_ = geary_imap_client_session_send_command_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp19_ = _data_->_tmp18_;
		_g_object_unref0 (_data_->_tmp17_);
		_data_->resp = _data_->_tmp19_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			block32_data_unref (_data_->_data32_);
			_data_->_data32_ = NULL;
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp20_ = _data_->resp;
		_data_->_tmp21_ = geary_imap_status_response_get_status (_data_->_tmp20_);
		_data_->_tmp22_ = _data_->_tmp21_;
		if (_data_->_tmp22_ == GEARY_IMAP_STATUS_OK) {
			_data_->_tmp23_ = _data_->self->priv->cx;
			_data_->_state_ = 3;
			geary_imap_client_connection_starttls_async (_data_->_tmp23_, _data_->cancellable, geary_imap_client_session_initiate_session_async_ready, _data_);
			return FALSE;
			_state_3:
			geary_imap_client_connection_starttls_finish (_data_->_tmp23_, _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_->resp);
				block32_data_unref (_data_->_data32_);
				_data_->_data32_ = NULL;
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
			geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "STARTTLS completed");
		} else {
			_data_->_tmp24_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
			_data_->_tmp25_ = _data_->_tmp24_;
			_data_->_tmp26_ = _data_->resp;
			_data_->_tmp27_ = geary_imap_status_response_get_status (_data_->_tmp26_);
			_data_->_tmp28_ = _data_->_tmp27_;
			_data_->_tmp29_ = geary_imap_status_to_string (_data_->_tmp28_);
			_data_->_tmp30_ = _data_->_tmp29_;
			_data_->_tmp31_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_NOT_SUPPORTED, "STARTTLS refused by %s: %s", _data_->_tmp25_, _data_->_tmp30_);
			_data_->_tmp32_ = _data_->_tmp31_;
			_g_free0 (_data_->_tmp30_);
			_g_free0 (_data_->_tmp25_);
			_data_->_inner_error0_ = _data_->_tmp32_;
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->resp);
			block32_data_unref (_data_->_data32_);
			_data_->_data32_ = NULL;
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp33_ = _data_->self->priv->_capabilities;
		_data_->_tmp34_ = geary_imap_capabilities_get_revision (_data_->_tmp33_);
		_data_->_tmp35_ = _data_->_tmp34_;
		if (_data_->last_capabilities == _data_->_tmp35_) {
			_data_->_tmp36_ = geary_imap_capability_command_new (_data_->cancellable);
			_data_->_tmp37_ = _data_->_tmp36_;
			_data_->_state_ = 4;
			geary_imap_client_session_send_command_async (_data_->self, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp37_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand), geary_imap_client_session_initiate_session_async_ready, _data_);
			return FALSE;
			_state_4:
			_data_->_tmp38_ = geary_imap_client_session_send_command_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
			_data_->_tmp39_ = _data_->_tmp38_;
			_g_object_unref0 (_data_->_tmp39_);
			_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_->resp);
				block32_data_unref (_data_->_data32_);
				_data_->_data32_ = NULL;
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
			_data_->_tmp40_ = _data_->self->priv->_capabilities;
			_data_->_tmp41_ = geary_imap_capabilities_get_revision (_data_->_tmp40_);
			_data_->_tmp42_ = _data_->_tmp41_;
			_data_->last_capabilities = _data_->_tmp42_;
		}
		_g_object_unref0 (_data_->resp);
	}
	_data_->_state_ = 5;
	geary_imap_client_session_login_async (_data_->self, _data_->credentials, _data_->cancellable, geary_imap_client_session_initiate_session_async_ready, _data_);
	return FALSE;
	_state_5:
	_data_->_tmp43_ = geary_imap_client_session_login_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp44_ = _data_->_tmp43_;
	_g_object_unref0 (_data_->_tmp44_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block32_data_unref (_data_->_data32_);
		_data_->_data32_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp45_ = _data_->self->priv->_capabilities;
	_data_->_tmp46_ = geary_imap_capabilities_get_revision (_data_->_tmp45_);
	_data_->_tmp47_ = _data_->_tmp46_;
	if (_data_->last_capabilities == _data_->_tmp47_) {
		_data_->_tmp48_ = geary_imap_capability_command_new (_data_->cancellable);
		_data_->_tmp49_ = _data_->_tmp48_;
		_data_->_state_ = 6;
		geary_imap_client_session_send_command_async (_data_->self, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp49_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand), geary_imap_client_session_initiate_session_async_ready, _data_);
		return FALSE;
		_state_6:
		_data_->_tmp50_ = geary_imap_client_session_send_command_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp51_ = _data_->_tmp50_;
		_g_object_unref0 (_data_->_tmp51_);
		_g_object_unref0 (_data_->_tmp49_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			block32_data_unref (_data_->_data32_);
			_data_->_data32_ = NULL;
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->_tmp52_ = gee_array_list_new (GEARY_IMAP_TYPE_MAILBOX_INFORMATION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data_->_data32_->list_results = _data_->_tmp52_;
	_data_->_tmp53_ = g_signal_connect_data (_data_->self, "list", (GCallback) ___lambda50__geary_imap_client_session_list, block32_data_ref (_data_->_data32_), (GClosureNotify) block32_data_unref, 0);
	_data_->list_id = _data_->_tmp53_;
	{
		_data_->_tmp54_ = geary_imap_mailbox_specifier_get_inbox ();
		_data_->_tmp55_ = _data_->_tmp54_;
		_data_->_tmp56_ = geary_imap_list_command_new (_data_->_tmp55_, FALSE, NULL, _data_->cancellable);
		_data_->_tmp57_ = _data_->_tmp56_;
		_data_->_state_ = 7;
		geary_imap_client_session_send_command_async (_data_->self, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp57_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand), geary_imap_client_session_initiate_session_async_ready, _data_);
		return FALSE;
		_state_7:
		_data_->_tmp58_ = geary_imap_client_session_send_command_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp59_ = _data_->_tmp58_;
		_g_object_unref0 (_data_->_tmp57_);
		_data_->response = _data_->_tmp59_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __finally0;
		}
		_data_->_tmp61_ = _data_->response;
		_data_->_tmp62_ = geary_imap_status_response_get_status (_data_->_tmp61_);
		_data_->_tmp63_ = _data_->_tmp62_;
		if (_data_->_tmp63_ == GEARY_IMAP_STATUS_OK) {
			_data_->_tmp64_ = _data_->_data32_->list_results;
			_data_->_tmp65_ = gee_collection_get_is_empty (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp64_, GEE_TYPE_COLLECTION, GeeCollection));
			_data_->_tmp66_ = _data_->_tmp65_;
			_data_->_tmp60_ = !_data_->_tmp66_;
		} else {
			_data_->_tmp60_ = FALSE;
		}
		if (_data_->_tmp60_) {
			_data_->_tmp67_ = _data_->_data32_->list_results;
			_data_->_tmp68_ = gee_abstract_list_get (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp67_, GEE_TYPE_ABSTRACT_LIST, GeeAbstractList), 0);
			_data_->_tmp69_ = (GearyImapMailboxInformation*) _data_->_tmp68_;
			geary_imap_client_session_set_inbox (_data_->self, _data_->_tmp69_);
			_g_object_unref0 (_data_->_tmp69_);
			_data_->_tmp70_ = _data_->_data32_->list_results;
			gee_abstract_collection_clear (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp70_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection));
			_data_->_tmp71_ = _data_->self->priv->_inbox;
			_data_->_tmp72_ = geary_imap_mailbox_information_to_string (_data_->_tmp71_);
			_data_->_tmp73_ = _data_->_tmp72_;
			geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Using INBOX: %s", _data_->_tmp73_);
			_g_free0 (_data_->_tmp73_);
		} else {
			_data_->_tmp74_ = g_error_new_literal (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_INVALID, "Unable to find INBOX");
			_data_->_inner_error0_ = _data_->_tmp74_;
			_g_object_unref0 (_data_->response);
			goto __finally0;
		}
		_data_->_tmp75_ = _data_->self->priv->_capabilities;
		if (geary_generic_capabilities_has_capability (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp75_, GEARY_TYPE_GENERIC_CAPABILITIES, GearyGenericCapabilities), GEARY_IMAP_CAPABILITIES_NAMESPACE)) {
			_data_->_tmp77_ = geary_imap_namespace_command_new (_data_->cancellable);
			_data_->_tmp78_ = _data_->_tmp77_;
			_data_->_state_ = 8;
			geary_imap_client_session_send_command_async (_data_->self, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp78_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand), geary_imap_client_session_initiate_session_async_ready, _data_);
			return FALSE;
			_state_8:
			_data_->_tmp79_ = geary_imap_client_session_send_command_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
			_data_->_tmp80_ = _data_->_tmp79_;
			_g_object_unref0 (_data_->_tmp78_);
			_data_->_tmp76_ = _data_->_tmp80_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->response);
				goto __finally0;
			}
			_data_->_tmp81_ = _data_->_tmp76_;
			_data_->_tmp76_ = NULL;
			_g_object_unref0 (_data_->response);
			_data_->response = _data_->_tmp81_;
			_data_->_tmp82_ = _data_->response;
			_data_->_tmp83_ = geary_imap_status_response_get_status (_data_->_tmp82_);
			_data_->_tmp84_ = _data_->_tmp83_;
			if (_data_->_tmp84_ != GEARY_IMAP_STATUS_OK) {
				geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "NAMESPACE command failed");
			}
			_g_object_unref0 (_data_->_tmp76_);
		}
		_data_->_tmp85_ = _data_->self->priv->personal_namespaces;
		_data_->_tmp86_ = gee_collection_get_is_empty (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp85_, GEE_TYPE_COLLECTION, GeeCollection));
		_data_->_tmp87_ = _data_->_tmp86_;
		if (!_data_->_tmp87_) {
			_data_->_tmp88_ = _data_->self->priv->personal_namespaces;
			_data_->_tmp89_ = gee_list_get (_data_->_tmp88_, 0);
			_data_->_tmp90_ = (GearyImapNamespace*) _data_->_tmp89_;
			_data_->_tmp91_ = geary_imap_namespace_to_string (_data_->_tmp90_);
			_data_->_tmp92_ = _data_->_tmp91_;
			geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Default personal namespace: %s", _data_->_tmp92_);
			_g_free0 (_data_->_tmp92_);
			_g_object_unref0 (_data_->_tmp90_);
		} else {
			_data_->_tmp93_ = g_strdup ("");
			_data_->prefix = _data_->_tmp93_;
			_data_->_tmp94_ = _data_->self->priv->_inbox;
			_data_->_tmp95_ = geary_imap_mailbox_information_get_delim (_data_->_tmp94_);
			_data_->_tmp96_ = _data_->_tmp95_;
			_data_->_tmp97_ = g_strdup (_data_->_tmp96_);
			_data_->delim = _data_->_tmp97_;
			_data_->_tmp99_ = _data_->self->priv->_inbox;
			_data_->_tmp100_ = geary_imap_mailbox_information_get_attrs (_data_->_tmp99_);
			_data_->_tmp101_ = _data_->_tmp100_;
			_data_->_tmp102_ = geary_imap_mailbox_attribute_get_NO_INFERIORS ();
			_data_->_tmp103_ = _data_->_tmp102_;
			if (!geary_imap_flags_contains (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp101_, GEARY_IMAP_TYPE_FLAGS, GearyImapFlags), G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp103_, GEARY_IMAP_TYPE_FLAG, GearyImapFlag))) {
				_data_->_tmp104_ = _data_->self->priv->_inbox;
				_data_->_tmp105_ = geary_imap_mailbox_information_get_delim (_data_->_tmp104_);
				_data_->_tmp106_ = _data_->_tmp105_;
				_data_->_tmp98_ = g_strcmp0 (_data_->_tmp106_, ".") == 0;
			} else {
				_data_->_tmp98_ = FALSE;
			}
			if (_data_->_tmp98_) {
				_data_->_tmp107_ = _data_->self->priv->_inbox;
				_data_->_tmp108_ = geary_imap_mailbox_information_get_mailbox (_data_->_tmp107_);
				_data_->_tmp109_ = _data_->_tmp108_;
				_data_->_tmp110_ = geary_imap_mailbox_specifier_get_name (_data_->_tmp109_);
				_data_->_tmp111_ = _data_->_tmp110_;
				_data_->_tmp112_ = g_strconcat (_data_->_tmp111_, ".", NULL);
				_g_free0 (_data_->prefix);
				_data_->prefix = _data_->_tmp112_;
			}
			_data_->_tmp113_ = _data_->delim;
			if (_data_->_tmp113_ == NULL) {
				_data_->_tmp115_ = _data_->prefix;
				_data_->_tmp116_ = geary_imap_mailbox_specifier_new (_data_->_tmp115_);
				_data_->_tmp117_ = _data_->_tmp116_;
				_data_->_tmp118_ = geary_imap_list_command_new (_data_->_tmp117_, FALSE, NULL, _data_->cancellable);
				_data_->_tmp119_ = _data_->_tmp118_;
				_data_->_state_ = 9;
				geary_imap_client_session_send_command_async (_data_->self, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp119_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand), geary_imap_client_session_initiate_session_async_ready, _data_);
				return FALSE;
				_state_9:
				_data_->_tmp120_ = geary_imap_client_session_send_command_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
				_data_->_tmp121_ = _data_->_tmp120_;
				_g_object_unref0 (_data_->_tmp119_);
				_g_object_unref0 (_data_->_tmp117_);
				_data_->_tmp114_ = _data_->_tmp121_;
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					_g_free0 (_data_->delim);
					_g_free0 (_data_->prefix);
					_g_object_unref0 (_data_->response);
					goto __finally0;
				}
				_data_->_tmp122_ = _data_->_tmp114_;
				_data_->_tmp114_ = NULL;
				_g_object_unref0 (_data_->response);
				_data_->response = _data_->_tmp122_;
				_data_->_tmp124_ = _data_->response;
				_data_->_tmp125_ = geary_imap_status_response_get_status (_data_->_tmp124_);
				_data_->_tmp126_ = _data_->_tmp125_;
				if (_data_->_tmp126_ == GEARY_IMAP_STATUS_OK) {
					_data_->_tmp127_ = _data_->_data32_->list_results;
					_data_->_tmp128_ = gee_collection_get_is_empty (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp127_, GEE_TYPE_COLLECTION, GeeCollection));
					_data_->_tmp129_ = _data_->_tmp128_;
					_data_->_tmp123_ = !_data_->_tmp129_;
				} else {
					_data_->_tmp123_ = FALSE;
				}
				if (_data_->_tmp123_) {
					_data_->_tmp130_ = _data_->_data32_->list_results;
					_data_->_tmp131_ = gee_abstract_list_get (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp130_, GEE_TYPE_ABSTRACT_LIST, GeeAbstractList), 0);
					_data_->list = (GearyImapMailboxInformation*) _data_->_tmp131_;
					_data_->_tmp132_ = _data_->list;
					_data_->_tmp133_ = geary_imap_mailbox_information_get_delim (_data_->_tmp132_);
					_data_->_tmp134_ = _data_->_tmp133_;
					_data_->_tmp135_ = g_strdup (_data_->_tmp134_);
					_g_free0 (_data_->delim);
					_data_->delim = _data_->_tmp135_;
					_g_object_unref0 (_data_->list);
				} else {
					_data_->_tmp136_ = g_error_new_literal (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_INVALID, "Unable to determine personal namespace delimiter");
					_data_->_inner_error0_ = _data_->_tmp136_;
					_g_object_unref0 (_data_->_tmp114_);
					_g_free0 (_data_->delim);
					_g_free0 (_data_->prefix);
					_g_object_unref0 (_data_->response);
					goto __finally0;
				}
				_g_object_unref0 (_data_->_tmp114_);
			}
			_data_->_tmp137_ = _data_->self->priv->personal_namespaces;
			_data_->_tmp138_ = _data_->prefix;
			_data_->_tmp139_ = _data_->delim;
			_data_->_tmp140_ = geary_imap_namespace_new (_data_->_tmp138_, _data_->_tmp139_);
			_data_->_tmp141_ = _data_->_tmp140_;
			gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp137_, GEE_TYPE_COLLECTION, GeeCollection), _data_->_tmp141_);
			_g_object_unref0 (_data_->_tmp141_);
			_data_->_tmp142_ = _data_->self->priv->personal_namespaces;
			_data_->_tmp143_ = gee_list_get (_data_->_tmp142_, 0);
			_data_->_tmp144_ = (GearyImapNamespace*) _data_->_tmp143_;
			_data_->_tmp145_ = geary_imap_namespace_to_string (_data_->_tmp144_);
			_data_->_tmp146_ = _data_->_tmp145_;
			geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Personal namespace not specified, guessed as: %s", _data_->_tmp146_);
			_g_free0 (_data_->_tmp146_);
			_g_object_unref0 (_data_->_tmp144_);
			_g_free0 (_data_->delim);
			_g_free0 (_data_->prefix);
		}
		_g_object_unref0 (_data_->response);
	}
	__finally0:
	{
		g_signal_handler_disconnect (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, G_TYPE_OBJECT, GObject), _data_->list_id);
	}
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block32_data_unref (_data_->_data32_);
		_data_->_data32_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	block32_data_unref (_data_->_data32_);
	_data_->_data32_ = 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 guint
geary_imap_client_session_on_login (GearyImapClientSession* self,
                                    guint state,
                                    guint event,
                                    void* user,
                                    GObject* object)
{
	GearyImapClientSessionMachineParams* params = NULL;
	GearyImapClientSessionMachineParams* _tmp0_;
	GearyImapClientSessionMachineParams* _tmp1_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS, GearyImapClientSessionMachineParams));
	params = _tmp0_;
	_tmp1_ = params;
	if (!geary_imap_client_session_reserve_state_change_cmd (self, _tmp1_, state, event)) {
		result = state;
		_g_object_unref0 (params);
		return result;
	}
	result = (guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZING;
	_g_object_unref0 (params);
	return result;
}

static guint
geary_imap_client_session_on_logging_in (GearyImapClientSession* self,
                                         guint state,
                                         guint event,
                                         void* user,
                                         GObject* object)
{
	GearyImapClientSessionMachineParams* params = NULL;
	GearyImapClientSessionMachineParams* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	GError* _tmp3_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS, GearyImapClientSessionMachineParams));
	params = _tmp0_;
	_tmp1_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
	_tmp2_ = _tmp1_;
	_tmp3_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_ALREADY_CONNECTED, "Already logging in to %s", _tmp2_);
	_g_error_free0 (params->err);
	params->err = _tmp3_;
	_g_free0 (_tmp2_);
	result = state;
	_g_object_unref0 (params);
	return result;
}

static guint
geary_imap_client_session_on_login_recv_completion (GearyImapClientSession* self,
                                                    guint state,
                                                    guint event,
                                                    void* user,
                                                    GObject* object)
{
	GearyImapStatusResponse* completion_response = NULL;
	GearyImapStatusResponse* _tmp0_;
	GearyImapStatusResponse* _tmp1_;
	guint new_state = 0U;
	GearyImapStatusResponse* _tmp2_;
	GearyImapStatus _tmp3_;
	GearyImapStatus _tmp4_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_TYPE_STATUS_RESPONSE, GearyImapStatusResponse));
	completion_response = _tmp0_;
	_tmp1_ = completion_response;
	if (!geary_imap_client_session_validate_state_change_cmd (self, G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEARY_IMAP_TYPE_SERVER_RESPONSE, GearyImapServerResponse), NULL)) {
		result = state;
		_g_object_unref0 (completion_response);
		return result;
	}
	new_state = (guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZED;
	_tmp2_ = completion_response;
	_tmp3_ = geary_imap_status_response_get_status (_tmp2_);
	_tmp4_ = _tmp3_;
	if (_tmp4_ != GEARY_IMAP_STATUS_OK) {
		GearyImapStatusResponse* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		_tmp5_ = completion_response;
		_tmp6_ = geary_imap_parameter_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
		_tmp7_ = _tmp6_;
		geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "LOGIN failed: %s", _tmp7_);
		_g_free0 (_tmp7_);
		new_state = (guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOAUTH;
	}
	result = new_state;
	_g_object_unref0 (completion_response);
	return result;
}

/**
     * Enables sending keep-alive commands for the sesion.
     *
     * Although keepalives can be enabled at any time, if they're
     * enabled and trigger sending a command prior to connection,
     * error signals may be fired.
     *
     * If values are negative or zero, keepalives will be disabled.
     * (This is not recommended.)
     */
void
geary_imap_client_session_enable_keepalives (GearyImapClientSession* self,
                                             guint seconds_while_selected,
                                             guint seconds_while_unselected,
                                             guint seconds_while_selected_with_idle)
{
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	self->priv->selected_keepalive_secs = seconds_while_selected;
	self->priv->selected_with_idle_keepalive_secs = seconds_while_selected_with_idle;
	self->priv->unselected_keepalive_secs = seconds_while_unselected;
	geary_imap_client_session_schedule_keepalive (self);
}

/**
     * Returns true if keepalives are disactivated, false if already disabled.
     */
gboolean
geary_imap_client_session_disable_keepalives (GearyImapClientSession* self)
{
	gboolean result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), FALSE);
	result = geary_imap_client_session_unschedule_keepalive (self);
	return result;
}

static gboolean
geary_imap_client_session_unschedule_keepalive (GearyImapClientSession* self)
{
	gboolean result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), FALSE);
	if (self->priv->keepalive_id == ((guint) 0)) {
		result = FALSE;
		return result;
	}
	g_source_remove (self->priv->keepalive_id);
	self->priv->keepalive_id = (guint) 0;
	result = TRUE;
	return result;
}

/**
     * Enables IMAP IDLE for the client session, if supported.
     *
     * If enabled, an IDLE command will be used for notification of
     * unsolicited server data whenever a mailbox is selected or
     * examined.  IDLE will only be used if ClientSession has seen a
     * CAPABILITY server data response with IDLE listed as a supported
     * extension.
     */
void
geary_imap_client_session_enable_idle (GearyImapClientSession* self,
                                       GError** error)
{
	gboolean _tmp0_;
	gboolean _tmp1_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	_tmp0_ = geary_imap_client_session_get_is_idle_supported (self);
	_tmp1_ = _tmp0_;
	if (_tmp1_) {
		GearyImapClientSessionProtocolState _tmp2_;
		GearyImapClientSessionProtocolState _tmp3_;
		_tmp2_ = geary_imap_client_session_get_protocol_state (self);
		_tmp3_ = _tmp2_;
		switch (_tmp3_) {
			case GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_AUTHORIZING:
			case GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_AUTHORIZED:
			case GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_SELECTED:
			case GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_SELECTING:
			{
				GearyImapClientConnection* _tmp4_;
				_tmp4_ = self->priv->cx;
				geary_imap_client_connection_enable_idle_when_quiet (_tmp4_, TRUE);
				break;
			}
			default:
			{
				GError* _tmp5_;
				_tmp5_ = g_error_new_literal (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_NOT_SUPPORTED, "IMAP IDLE only supported in AUTHORIZED or SELECTED states");
				_inner_error0_ = _tmp5_;
				g_propagate_error (error, _inner_error0_);
				return;
			}
		}
	}
}

static gboolean
_geary_imap_client_session_on_keepalive_gsource_func (gpointer self)
{
	gboolean result;
	result = geary_imap_client_session_on_keepalive ((GearyImapClientSession*) self);
	return result;
}

static void
geary_imap_client_session_schedule_keepalive (GearyImapClientSession* self)
{
	guint seconds = 0U;
	GearyImapClientSessionProtocolState _tmp0_;
	GearyImapClientSessionProtocolState _tmp1_;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	geary_imap_client_session_unschedule_keepalive (self);
	_tmp0_ = geary_imap_client_session_get_protocol_state (self);
	_tmp1_ = _tmp0_;
	switch (_tmp1_) {
		case GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_NOT_CONNECTED:
		case GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_CONNECTING:
		{
			return;
		}
		case GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_SELECTING:
		case GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_SELECTED:
		{
			guint _tmp2_ = 0U;
			gboolean _tmp3_ = FALSE;
			GearyImapClientConnection* _tmp4_;
			gboolean _tmp5_;
			gboolean _tmp6_;
			_tmp4_ = self->priv->cx;
			_tmp5_ = geary_imap_client_connection_get_idle_when_quiet (_tmp4_);
			_tmp6_ = _tmp5_;
			if (_tmp6_) {
				gboolean _tmp7_;
				gboolean _tmp8_;
				_tmp7_ = geary_imap_client_session_get_is_idle_supported (self);
				_tmp8_ = _tmp7_;
				_tmp3_ = _tmp8_;
			} else {
				_tmp3_ = FALSE;
			}
			if (_tmp3_) {
				_tmp2_ = self->priv->selected_with_idle_keepalive_secs;
			} else {
				_tmp2_ = self->priv->selected_keepalive_secs;
			}
			seconds = _tmp2_;
			break;
		}
		default:
		case GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_UNAUTHORIZED:
		case GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_AUTHORIZING:
		case GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_AUTHORIZED:
		case GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_CLOSING_MAILBOX:
		{
			seconds = self->priv->unselected_keepalive_secs;
			break;
		}
	}
	if (seconds > ((guint) 0)) {
		self->priv->keepalive_id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, seconds, _geary_imap_client_session_on_keepalive_gsource_func, g_object_ref (self), g_object_unref);
	}
}

static void
_geary_imap_client_session_on_keepalive_completed_gasync_ready_callback (GObject* source_object,
                                                                         GAsyncResult* res,
                                                                         gpointer self)
{
	geary_imap_client_session_on_keepalive_completed ((GearyImapClientSession*) self, source_object, res);
	g_object_unref (self);
}

static gboolean
geary_imap_client_session_on_keepalive (GearyImapClientSession* self)
{
	GearyImapNoopCommand* _tmp0_;
	GearyImapNoopCommand* _tmp1_;
	gboolean result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), FALSE);
	self->priv->keepalive_id = (guint) 0;
	_tmp0_ = geary_imap_noop_command_new (NULL);
	_tmp1_ = _tmp0_;
	geary_imap_client_session_send_command_async (self, G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand), _geary_imap_client_session_on_keepalive_completed_gasync_ready_callback, g_object_ref (self));
	_g_object_unref0 (_tmp1_);
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Sending keepalive...");
	result = FALSE;
	return result;
}

static void
geary_imap_client_session_on_keepalive_completed (GearyImapClientSession* self,
                                                  GObject* source,
                                                  GAsyncResult* _result_)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail ((source == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (source, G_TYPE_OBJECT));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (_result_, g_async_result_get_type ()));
	{
		GearyImapStatusResponse* _tmp0_;
		GearyImapStatusResponse* _tmp1_;
		_tmp0_ = geary_imap_client_session_send_command_finish (self, _result_, &_inner_error0_);
		_tmp1_ = _tmp0_;
		_g_object_unref0 (_tmp1_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* err = NULL;
		GError* _tmp2_;
		const gchar* _tmp3_;
		err = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp2_ = err;
		_tmp3_ = _tmp2_->message;
		geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Keepalive error: %s", _tmp3_);
		_g_error_free0 (err);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
}

static void
geary_imap_client_session_send_command_async_data_free (gpointer _data)
{
	GearyImapClientSessionSendCommandAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cmd);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapClientSessionSendCommandAsyncData, _data_);
}

void
geary_imap_client_session_send_command_async (GearyImapClientSession* self,
                                              GearyImapCommand* cmd,
                                              GAsyncReadyCallback _callback_,
                                              gpointer _user_data_)
{
	GearyImapClientSessionSendCommandAsyncData* _data_;
	GearyImapClientSession* _tmp0_;
	GearyImapCommand* _tmp1_;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail (GEARY_IMAP_IS_COMMAND (cmd));
	_data_ = g_slice_new0 (GearyImapClientSessionSendCommandAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_client_session_send_command_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cmd);
	_g_object_unref0 (_data_->cmd);
	_data_->cmd = _tmp1_;
	geary_imap_client_session_send_command_async_co (_data_);
}

GearyImapStatusResponse*
geary_imap_client_session_send_command_finish (GearyImapClientSession* self,
                                               GAsyncResult* _res_,
                                               GError** error)
{
	GearyImapStatusResponse* result;
	GearyImapClientSessionSendCommandAsyncData* _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_client_session_send_command_async_ready (GObject* source_object,
                                                    GAsyncResult* _res_,
                                                    gpointer _user_data_)
{
	GearyImapClientSessionSendCommandAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_client_session_send_command_async_co (_data_);
}

static gboolean
geary_imap_client_session_send_command_async_co (GearyImapClientSessionSendCommandAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	geary_imap_client_session_check_unsupported_send_command (_data_->self, _data_->cmd, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp0_ = geary_imap_client_session_machine_params_new (_data_->cmd);
	_data_->params = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->self->priv->fsm;
	_data_->_tmp2_ = _data_->params;
	geary_state_machine_issue (_data_->_tmp1_, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_CMD, NULL, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, G_TYPE_OBJECT, GObject), NULL);
	_data_->_tmp3_ = _data_->params;
	_data_->_tmp4_ = _data_->_tmp3_->err;
	if (_data_->_tmp4_ != NULL) {
		_data_->_tmp5_ = _data_->params;
		_data_->_tmp6_ = _data_->_tmp5_->err;
		_data_->_tmp7_ = _g_error_copy0 (_data_->_tmp6_);
		_data_->_inner_error0_ = _data_->_tmp7_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->params);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp8_ = _data_->params;
	_vala_assert (_data_->_tmp8_->proceed, "params.proceed");
	_data_->_state_ = 1;
	geary_imap_client_session_submit_command (_data_->self, _data_->cmd, geary_imap_client_session_send_command_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp10_ = geary_imap_client_session_submit_command_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp9_ = _data_->_tmp10_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->params);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp11_ = _data_->_tmp9_;
	_data_->_tmp9_ = NULL;
	_data_->result = _data_->_tmp11_;
	_g_object_unref0 (_data_->_tmp9_);
	_g_object_unref0 (_data_->params);
	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_client_session_send_multiple_commands_async_data_free (gpointer _data)
{
	GearyImapClientSessionSendMultipleCommandsAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cmds);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapClientSessionSendMultipleCommandsAsyncData, _data_);
}

void
geary_imap_client_session_send_multiple_commands_async (GearyImapClientSession* self,
                                                        GeeCollection* cmds,
                                                        GCancellable* cancellable,
                                                        GAsyncReadyCallback _callback_,
                                                        gpointer _user_data_)
{
	GearyImapClientSessionSendMultipleCommandsAsyncData* _data_;
	GearyImapClientSession* _tmp0_;
	GeeCollection* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (cmds, GEE_TYPE_COLLECTION));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapClientSessionSendMultipleCommandsAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_client_session_send_multiple_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 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_client_session_send_multiple_commands_async_co (_data_);
}

GeeMap*
geary_imap_client_session_send_multiple_commands_finish (GearyImapClientSession* self,
                                                         GAsyncResult* _res_,
                                                         GError** error)
{
	GeeMap* result;
	GearyImapClientSessionSendMultipleCommandsAsyncData* _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_client_session_send_multiple_commands_async_ready (GObject* source_object,
                                                              GAsyncResult* _res_,
                                                              gpointer _user_data_)
{
	GearyImapClientSessionSendMultipleCommandsAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_client_session_send_multiple_commands_async_co (_data_);
}

static gboolean
geary_imap_client_session_send_multiple_commands_async_co (GearyImapClientSessionSendMultipleCommandsAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = gee_collection_get_size (_data_->cmds);
	_data_->_tmp1_ = _data_->_tmp0_;
	if (_data_->_tmp1_ == 0) {
		_data_->_tmp2_ = g_error_new_literal (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_INVALID, "Must supply at least one command");
		_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_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_data_->cmds, GEE_TYPE_ITERABLE, GeeIterable));
		_data_->_cmd_it = _data_->_tmp3_;
		while (TRUE) {
			_data_->_tmp4_ = _data_->_cmd_it;
			if (!gee_iterator_next (_data_->_tmp4_)) {
				break;
			}
			_data_->_tmp5_ = _data_->_cmd_it;
			_data_->_tmp6_ = gee_iterator_get (_data_->_tmp5_);
			_data_->cmd = (GearyImapCommand*) _data_->_tmp6_;
			_data_->_tmp7_ = _data_->cmd;
			geary_imap_client_session_check_unsupported_send_command (_data_->self, _data_->_tmp7_, &_data_->_inner_error0_);
			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_object_unref (_data_->_async_result);
				return FALSE;
			}
			_g_object_unref0 (_data_->cmd);
		}
		_g_object_unref0 (_data_->_cmd_it);
	}
	_data_->_tmp8_ = geary_collection_first (GEARY_IMAP_TYPE_COMMAND, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->cmds);
	_data_->_tmp9_ = (GearyImapCommand*) _data_->_tmp8_;
	_data_->_tmp10_ = geary_imap_client_session_machine_params_new (_data_->_tmp9_);
	_data_->_tmp11_ = _data_->_tmp10_;
	_g_object_unref0 (_data_->_tmp9_);
	_data_->params = _data_->_tmp11_;
	_data_->_tmp12_ = _data_->self->priv->fsm;
	_data_->_tmp13_ = _data_->params;
	geary_state_machine_issue (_data_->_tmp12_, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_CMD, NULL, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp13_, G_TYPE_OBJECT, GObject), NULL);
	_data_->_tmp14_ = _data_->params;
	_data_->_tmp15_ = _data_->_tmp14_->err;
	if (_data_->_tmp15_ != NULL) {
		_data_->_tmp16_ = _data_->params;
		_data_->_tmp17_ = _data_->_tmp16_->err;
		_data_->_tmp18_ = _g_error_copy0 (_data_->_tmp17_);
		_data_->_inner_error0_ = _data_->_tmp18_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->params);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp19_ = _data_->params;
	_vala_assert (_data_->_tmp19_->proceed, "params.proceed");
	_data_->_tmp20_ = _data_->self->priv->_quirks;
	_data_->_tmp21_ = geary_imap_quirks_get_max_pipeline_batch_size (_data_->_tmp20_);
	_data_->_tmp22_ = _data_->_tmp21_;
	_data_->max_batch_size = _data_->_tmp22_;
	if (_data_->max_batch_size < ((guint) 1)) {
		_data_->_tmp23_ = gee_collection_get_size (_data_->cmds);
		_data_->_tmp24_ = _data_->_tmp23_;
		_data_->max_batch_size = (guint) _data_->_tmp24_;
	}
	_data_->_tmp25_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_data_->cmds, GEE_TYPE_ITERABLE, GeeIterable));
	_data_->cmd_remaining = _data_->_tmp25_;
	_data_->batch = NULL;
	_data_->_tmp26_ = gee_hash_map_new (GEARY_IMAP_TYPE_COMMAND, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEARY_IMAP_TYPE_STATUS_RESPONSE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->responses = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp26_, GEE_TYPE_MAP, GeeMap);
	while (TRUE) {
		_data_->_tmp27_ = _data_->cmd_remaining;
		if (!gee_iterator_has_next (_data_->_tmp27_)) {
			break;
		}
		_data_->_tmp28_ = geary_nonblocking_batch_new ();
		_g_object_unref0 (_data_->batch);
		_data_->batch = _data_->_tmp28_;
		while (TRUE) {
			_data_->_tmp30_ = _data_->cmd_remaining;
			if (gee_iterator_has_next (_data_->_tmp30_)) {
				_data_->_tmp31_ = _data_->batch;
				_data_->_tmp32_ = geary_nonblocking_batch_get_size (_data_->_tmp31_);
				_data_->_tmp33_ = _data_->_tmp32_;
				_data_->_tmp29_ = ((guint) _data_->_tmp33_) < _data_->max_batch_size;
			} else {
				_data_->_tmp29_ = FALSE;
			}
			if (!_data_->_tmp29_) {
				break;
			}
			_data_->_tmp34_ = _data_->cmd_remaining;
			gee_iterator_next (_data_->_tmp34_);
			_data_->_tmp35_ = _data_->batch;
			_data_->_tmp36_ = _data_->cmd_remaining;
			_data_->_tmp37_ = gee_iterator_get (_data_->_tmp36_);
			_data_->_tmp38_ = (GearyImapCommand*) _data_->_tmp37_;
			_data_->_tmp39_ = geary_imap_client_session_send_command_operation_new (_data_->self, _data_->_tmp38_);
			_data_->_tmp40_ = _data_->_tmp39_;
			geary_nonblocking_batch_add (_data_->_tmp35_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp40_, GEARY_NONBLOCKING_TYPE_BATCH_OPERATION, GearyNonblockingBatchOperation));
			_g_object_unref0 (_data_->_tmp40_);
			_g_object_unref0 (_data_->_tmp38_);
		}
		_data_->_tmp41_ = _data_->batch;
		_data_->_state_ = 1;
		geary_nonblocking_batch_execute_all_async (_data_->_tmp41_, _data_->cancellable, geary_imap_client_session_send_multiple_commands_async_ready, _data_);
		return FALSE;
		_state_1:
		geary_nonblocking_batch_execute_all_finish (_data_->_tmp41_, _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_->batch);
			_g_object_unref0 (_data_->cmd_remaining);
			_g_object_unref0 (_data_->params);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp42_ = _data_->batch;
		geary_nonblocking_batch_throw_first_exception (_data_->_tmp42_, &_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_->batch);
			_g_object_unref0 (_data_->cmd_remaining);
			_g_object_unref0 (_data_->params);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		{
			_data_->_tmp43_ = _data_->batch;
			_data_->_tmp44_ = geary_nonblocking_batch_get_ids (_data_->_tmp43_);
			_data_->_tmp45_ = _data_->_tmp44_;
			_data_->_tmp46_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp45_, GEE_TYPE_ITERABLE, GeeIterable));
			_data_->_tmp47_ = _data_->_tmp46_;
			_g_object_unref0 (_data_->_tmp45_);
			_data_->_id_it = _data_->_tmp47_;
			while (TRUE) {
				_data_->_tmp48_ = _data_->_id_it;
				if (!gee_iterator_next (_data_->_tmp48_)) {
					break;
				}
				_data_->_tmp49_ = _data_->_id_it;
				_data_->_tmp50_ = gee_iterator_get (_data_->_tmp49_);
				_data_->id = (gint) ((gintptr) _data_->_tmp50_);
				_data_->_tmp51_ = _data_->batch;
				_data_->_tmp52_ = geary_nonblocking_batch_get_operation (_data_->_tmp51_, _data_->id);
				_data_->op = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp52_, GEARY_IMAP_CLIENT_SESSION_TYPE_SEND_COMMAND_OPERATION, GearyImapClientSessionSendCommandOperation);
				_data_->_tmp53_ = _data_->responses;
				_data_->_tmp54_ = _data_->op;
				_data_->_tmp55_ = _data_->_tmp54_->cmd;
				_data_->_tmp56_ = _data_->op;
				_data_->_tmp57_ = _data_->_tmp56_->response;
				gee_map_set (_data_->_tmp53_, _data_->_tmp55_, _data_->_tmp57_);
				_g_object_unref0 (_data_->op);
			}
			_g_object_unref0 (_data_->_id_it);
		}
	}
	_data_->result = _data_->responses;
	_g_object_unref0 (_data_->batch);
	_g_object_unref0 (_data_->cmd_remaining);
	_g_object_unref0 (_data_->params);
	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_client_session_check_unsupported_send_command (GearyImapClientSession* self,
                                                          GearyImapCommand* cmd,
                                                          GError** error)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_ = FALSE;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail (GEARY_IMAP_IS_COMMAND (cmd));
	if (geary_imap_command_has_name (cmd, GEARY_IMAP_LOGIN_COMMAND_NAME)) {
		_tmp4_ = TRUE;
	} else {
		_tmp4_ = geary_imap_command_has_name (cmd, GEARY_IMAP_AUTHENTICATE_COMMAND_NAME);
	}
	if (_tmp4_) {
		_tmp3_ = TRUE;
	} else {
		_tmp3_ = geary_imap_command_has_name (cmd, GEARY_IMAP_LOGOUT_COMMAND_NAME);
	}
	if (_tmp3_) {
		_tmp2_ = TRUE;
	} else {
		_tmp2_ = geary_imap_command_has_name (cmd, GEARY_IMAP_SELECT_COMMAND_NAME);
	}
	if (_tmp2_) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = geary_imap_command_has_name (cmd, GEARY_IMAP_EXAMINE_COMMAND_NAME);
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = geary_imap_command_has_name (cmd, GEARY_IMAP_CLOSE_COMMAND_NAME);
	}
	if (_tmp0_) {
		const gchar* _tmp5_;
		const gchar* _tmp6_;
		GError* _tmp7_;
		_tmp5_ = geary_imap_command_get_name (cmd);
		_tmp6_ = _tmp5_;
		_tmp7_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_NOT_SUPPORTED, "Use direct calls rather than commands for %s", _tmp6_);
		_inner_error0_ = _tmp7_;
		g_propagate_error (error, _inner_error0_);
		return;
	}
}

static guint
geary_imap_client_session_on_send_command (GearyImapClientSession* self,
                                           guint state,
                                           guint event,
                                           void* user,
                                           GObject* object)
{
	GearyImapClientSessionMachineParams* params = NULL;
	GearyImapClientSessionMachineParams* _tmp0_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS, GearyImapClientSessionMachineParams));
	params = _tmp0_;
	params->proceed = TRUE;
	result = state;
	_g_object_unref0 (params);
	return result;
}

static guint
geary_imap_client_session_on_recv_status (GearyImapClientSession* self,
                                          guint state,
                                          guint event,
                                          void* user,
                                          GObject* object)
{
	GearyImapStatusResponse* status_response = NULL;
	GearyImapStatusResponse* _tmp0_;
	GearyImapStatusResponse* _tmp1_;
	GearyImapStatus _tmp2_;
	GearyImapStatus _tmp3_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_TYPE_STATUS_RESPONSE, GearyImapStatusResponse));
	status_response = _tmp0_;
	_tmp1_ = status_response;
	_tmp2_ = geary_imap_status_response_get_status (_tmp1_);
	_tmp3_ = _tmp2_;
	switch (_tmp3_) {
		case GEARY_IMAP_STATUS_OK:
		{
			break;
		}
		case GEARY_IMAP_STATUS_BYE:
		{
			GearyImapStatusResponse* _tmp4_;
			gchar* _tmp5_;
			gchar* _tmp6_;
			_tmp4_ = status_response;
			_tmp5_ = geary_imap_parameter_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
			_tmp6_ = _tmp5_;
			geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Received unilateral BYE from server: %s", _tmp6_);
			_g_free0 (_tmp6_);
			geary_imap_client_session_do_disconnect (self, GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_REMOTE_CLOSE, NULL, NULL);
			state = (guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED;
			break;
		}
		default:
		{
			GearyImapStatusResponse* _tmp7_;
			gchar* _tmp8_;
			gchar* _tmp9_;
			_tmp7_ = status_response;
			_tmp8_ = geary_imap_parameter_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
			_tmp9_ = _tmp8_;
			geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Received error from server: %s", _tmp9_);
			_g_free0 (_tmp9_);
			break;
		}
	}
	result = state;
	_g_object_unref0 (status_response);
	return result;
}

static void
geary_imap_client_session_select_async_data_free (gpointer _data)
{
	GearyImapClientSessionSelectAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->mailbox);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapClientSessionSelectAsyncData, _data_);
}

void
geary_imap_client_session_select_async (GearyImapClientSession* self,
                                        GearyImapMailboxSpecifier* mailbox,
                                        GCancellable* cancellable,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_)
{
	GearyImapClientSessionSelectAsyncData* _data_;
	GearyImapClientSession* _tmp0_;
	GearyImapMailboxSpecifier* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail (GEARY_IMAP_IS_MAILBOX_SPECIFIER (mailbox));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapClientSessionSelectAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_client_session_select_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (mailbox);
	_g_object_unref0 (_data_->mailbox);
	_data_->mailbox = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_client_session_select_async_co (_data_);
}

GearyImapStatusResponse*
geary_imap_client_session_select_finish (GearyImapClientSession* self,
                                         GAsyncResult* _res_,
                                         GError** error)
{
	GearyImapStatusResponse* result;
	GearyImapClientSessionSelectAsyncData* _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_client_session_select_async_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_)
{
	GearyImapClientSessionSelectAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_client_session_select_async_co (_data_);
}

static gboolean
geary_imap_client_session_select_async_co (GearyImapClientSessionSelectAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_state_ = 1;
	geary_imap_client_session_select_examine_async (_data_->self, _data_->mailbox, TRUE, _data_->cancellable, geary_imap_client_session_select_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp1_ = geary_imap_client_session_select_examine_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp0_ = _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;
	}
	_data_->_tmp2_ = _data_->_tmp0_;
	_data_->_tmp0_ = NULL;
	_data_->result = _data_->_tmp2_;
	_g_object_unref0 (_data_->_tmp0_);
	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_client_session_examine_async_data_free (gpointer _data)
{
	GearyImapClientSessionExamineAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->mailbox);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapClientSessionExamineAsyncData, _data_);
}

void
geary_imap_client_session_examine_async (GearyImapClientSession* self,
                                         GearyImapMailboxSpecifier* mailbox,
                                         GCancellable* cancellable,
                                         GAsyncReadyCallback _callback_,
                                         gpointer _user_data_)
{
	GearyImapClientSessionExamineAsyncData* _data_;
	GearyImapClientSession* _tmp0_;
	GearyImapMailboxSpecifier* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail (GEARY_IMAP_IS_MAILBOX_SPECIFIER (mailbox));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapClientSessionExamineAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_client_session_examine_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (mailbox);
	_g_object_unref0 (_data_->mailbox);
	_data_->mailbox = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_client_session_examine_async_co (_data_);
}

GearyImapStatusResponse*
geary_imap_client_session_examine_finish (GearyImapClientSession* self,
                                          GAsyncResult* _res_,
                                          GError** error)
{
	GearyImapStatusResponse* result;
	GearyImapClientSessionExamineAsyncData* _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_client_session_examine_async_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_)
{
	GearyImapClientSessionExamineAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_client_session_examine_async_co (_data_);
}

static gboolean
geary_imap_client_session_examine_async_co (GearyImapClientSessionExamineAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_state_ = 1;
	geary_imap_client_session_select_examine_async (_data_->self, _data_->mailbox, FALSE, _data_->cancellable, geary_imap_client_session_examine_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp1_ = geary_imap_client_session_select_examine_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp0_ = _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;
	}
	_data_->_tmp2_ = _data_->_tmp0_;
	_data_->_tmp0_ = NULL;
	_data_->result = _data_->_tmp2_;
	_g_object_unref0 (_data_->_tmp0_);
	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_client_session_select_examine_async_data_free (gpointer _data)
{
	GearyImapClientSessionSelectExamineAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->mailbox);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapClientSessionSelectExamineAsyncData, _data_);
}

void
geary_imap_client_session_select_examine_async (GearyImapClientSession* self,
                                                GearyImapMailboxSpecifier* mailbox,
                                                gboolean is_select,
                                                GCancellable* cancellable,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_)
{
	GearyImapClientSessionSelectExamineAsyncData* _data_;
	GearyImapClientSession* _tmp0_;
	GearyImapMailboxSpecifier* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail (GEARY_IMAP_IS_MAILBOX_SPECIFIER (mailbox));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapClientSessionSelectExamineAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_client_session_select_examine_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (mailbox);
	_g_object_unref0 (_data_->mailbox);
	_data_->mailbox = _tmp1_;
	_data_->is_select = is_select;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_client_session_select_examine_async_co (_data_);
}

GearyImapStatusResponse*
geary_imap_client_session_select_examine_finish (GearyImapClientSession* self,
                                                 GAsyncResult* _res_,
                                                 GError** error)
{
	GearyImapStatusResponse* result;
	GearyImapClientSessionSelectExamineAsyncData* _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_client_session_select_examine_async_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_)
{
	GearyImapClientSessionSelectExamineAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_client_session_select_examine_async_co (_data_);
}

static gboolean
geary_imap_client_session_select_examine_async_co (GearyImapClientSessionSelectExamineAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (_data_->is_select) {
		_data_->_tmp0_ = geary_imap_select_command_new (_data_->mailbox, _data_->cancellable);
		_g_object_unref0 (_data_->cmd);
		_data_->cmd = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand);
	} else {
		_data_->_tmp1_ = geary_imap_examine_command_new (_data_->mailbox, _data_->cancellable);
		_g_object_unref0 (_data_->cmd);
		_data_->cmd = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand);
	}
	_data_->_tmp2_ = _data_->cmd;
	_data_->_tmp3_ = geary_imap_client_session_machine_params_new (_data_->_tmp2_);
	_data_->params = _data_->_tmp3_;
	_data_->_tmp4_ = _data_->self->priv->fsm;
	_data_->_tmp5_ = _data_->params;
	geary_state_machine_issue (_data_->_tmp4_, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SELECT, NULL, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp5_, G_TYPE_OBJECT, GObject), NULL);
	_data_->_tmp6_ = _data_->params;
	_data_->_tmp7_ = _data_->_tmp6_->err;
	if (_data_->_tmp7_ != NULL) {
		_data_->_tmp8_ = _data_->params;
		_data_->_tmp9_ = _data_->_tmp8_->err;
		_data_->_tmp10_ = _g_error_copy0 (_data_->_tmp9_);
		_data_->_inner_error0_ = _data_->_tmp10_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->params);
		_g_object_unref0 (_data_->cmd);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp11_ = _data_->params;
	_vala_assert (_data_->_tmp11_->proceed, "params.proceed");
	_data_->_tmp13_ = _data_->cmd;
	_data_->_state_ = 1;
	geary_imap_client_session_submit_command (_data_->self, _data_->_tmp13_, geary_imap_client_session_select_examine_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp14_ = geary_imap_client_session_submit_command_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp12_ = _data_->_tmp14_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->params);
		_g_object_unref0 (_data_->cmd);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp15_ = _data_->_tmp12_;
	_data_->_tmp12_ = NULL;
	_data_->result = _data_->_tmp15_;
	_g_object_unref0 (_data_->_tmp12_);
	_g_object_unref0 (_data_->params);
	_g_object_unref0 (_data_->cmd);
	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 guint
geary_imap_client_session_on_select (GearyImapClientSession* self,
                                     guint state,
                                     guint event,
                                     void* user,
                                     GObject* object)
{
	GearyImapClientSessionMachineParams* params = NULL;
	GearyImapClientSessionMachineParams* _tmp0_;
	GearyImapClientSessionMachineParams* _tmp1_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS, GearyImapClientSessionMachineParams));
	params = _tmp0_;
	_tmp1_ = params;
	if (!geary_imap_client_session_reserve_state_change_cmd (self, _tmp1_, state, event)) {
		result = state;
		_g_object_unref0 (params);
		return result;
	}
	result = (guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTING;
	_g_object_unref0 (params);
	return result;
}

static guint
geary_imap_client_session_on_not_selected (GearyImapClientSession* self,
                                           guint state,
                                           guint event,
                                           void* user,
                                           GObject* object)
{
	GearyImapClientSessionMachineParams* params = NULL;
	GearyImapClientSessionMachineParams* _tmp0_;
	GError* _tmp1_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS, GearyImapClientSessionMachineParams));
	params = _tmp0_;
	_tmp1_ = g_error_new_literal (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_INVALID, "Can't close mailbox, not selected");
	_g_error_free0 (params->err);
	params->err = _tmp1_;
	result = state;
	_g_object_unref0 (params);
	return result;
}

static guint
geary_imap_client_session_on_selecting_recv_completion (GearyImapClientSession* self,
                                                        guint state,
                                                        guint event,
                                                        void* user,
                                                        GObject* object)
{
	guint new_state = 0U;
	GearyImapStatusResponse* completion_response = NULL;
	GearyImapStatusResponse* _tmp0_;
	GearyImapCommand* cmd = NULL;
	GearyImapStatusResponse* _tmp1_;
	GearyImapCommand* _tmp2_ = NULL;
	gboolean _tmp3_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	new_state = state;
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_TYPE_STATUS_RESPONSE, GearyImapStatusResponse));
	completion_response = _tmp0_;
	cmd = NULL;
	_tmp1_ = completion_response;
	_tmp3_ = geary_imap_client_session_validate_state_change_cmd (self, G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEARY_IMAP_TYPE_SERVER_RESPONSE, GearyImapServerResponse), &_tmp2_);
	_g_object_unref0 (cmd);
	cmd = _tmp2_;
	if (_tmp3_) {
		GearyImapStatusResponse* _tmp4_;
		GearyImapStatus _tmp5_;
		GearyImapStatus _tmp6_;
		_tmp4_ = completion_response;
		_tmp5_ = geary_imap_status_response_get_status (_tmp4_);
		_tmp6_ = _tmp5_;
		switch (_tmp6_) {
			case GEARY_IMAP_STATUS_OK:
			{
				GearyImapCommand* _tmp7_;
				_tmp7_ = cmd;
				if (GEARY_IMAP_IS_SELECT_COMMAND (_tmp7_)) {
					GearyImapCommand* _tmp8_;
					GearyImapMailboxSpecifier* _tmp9_;
					GearyImapMailboxSpecifier* _tmp10_;
					GearyImapMailboxSpecifier* _tmp11_;
					_tmp8_ = cmd;
					_tmp9_ = geary_imap_select_command_get_mailbox (G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, GEARY_IMAP_TYPE_SELECT_COMMAND, GearyImapSelectCommand));
					_tmp10_ = _tmp9_;
					_tmp11_ = _g_object_ref0 (_tmp10_);
					_g_object_unref0 (self->selected_mailbox);
					self->selected_mailbox = _tmp11_;
					self->selected_readonly = FALSE;
				} else {
					GearyImapCommand* _tmp12_;
					_tmp12_ = cmd;
					if (GEARY_IMAP_IS_EXAMINE_COMMAND (_tmp12_)) {
						GearyImapCommand* _tmp13_;
						GearyImapMailboxSpecifier* _tmp14_;
						GearyImapMailboxSpecifier* _tmp15_;
						GearyImapMailboxSpecifier* _tmp16_;
						_tmp13_ = cmd;
						_tmp14_ = geary_imap_examine_command_get_mailbox (G_TYPE_CHECK_INSTANCE_CAST (_tmp13_, GEARY_IMAP_TYPE_EXAMINE_COMMAND, GearyImapExamineCommand));
						_tmp15_ = _tmp14_;
						_tmp16_ = _g_object_ref0 (_tmp15_);
						_g_object_unref0 (self->selected_mailbox);
						self->selected_mailbox = _tmp16_;
						self->selected_readonly = TRUE;
					}
				}
				new_state = (guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTED;
				break;
			}
			default:
			{
				GearyImapStatusResponse* _tmp17_;
				gchar* _tmp18_;
				gchar* _tmp19_;
				_g_object_unref0 (self->selected_mailbox);
				self->selected_mailbox = NULL;
				self->selected_readonly = FALSE;
				new_state = (guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZED;
				_tmp17_ = completion_response;
				_tmp18_ = geary_imap_parameter_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp17_, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
				_tmp19_ = _tmp18_;
				geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "SELECT/EXAMINE failed: %s", _tmp19_);
				_g_free0 (_tmp19_);
				break;
			}
		}
	}
	result = new_state;
	_g_object_unref0 (cmd);
	_g_object_unref0 (completion_response);
	return result;
}

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

void
geary_imap_client_session_close_mailbox_async (GearyImapClientSession* self,
                                               GCancellable* cancellable,
                                               GAsyncReadyCallback _callback_,
                                               gpointer _user_data_)
{
	GearyImapClientSessionCloseMailboxAsyncData* _data_;
	GearyImapClientSession* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapClientSessionCloseMailboxAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_client_session_close_mailbox_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_client_session_close_mailbox_async_co (_data_);
}

GearyImapStatusResponse*
geary_imap_client_session_close_mailbox_finish (GearyImapClientSession* self,
                                                GAsyncResult* _res_,
                                                GError** error)
{
	GearyImapStatusResponse* result;
	GearyImapClientSessionCloseMailboxAsyncData* _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_client_session_close_mailbox_async_ready (GObject* source_object,
                                                     GAsyncResult* _res_,
                                                     gpointer _user_data_)
{
	GearyImapClientSessionCloseMailboxAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_client_session_close_mailbox_async_co (_data_);
}

static gboolean
geary_imap_client_session_close_mailbox_async_co (GearyImapClientSessionCloseMailboxAsyncData* _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_close_command_new (_data_->cancellable);
	_data_->cmd = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->cmd;
	_data_->_tmp2_ = geary_imap_client_session_machine_params_new (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand));
	_data_->params = _data_->_tmp2_;
	_data_->_tmp3_ = _data_->self->priv->fsm;
	_data_->_tmp4_ = _data_->params;
	geary_state_machine_issue (_data_->_tmp3_, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_CLOSE_MAILBOX, NULL, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp4_, G_TYPE_OBJECT, GObject), NULL);
	_data_->_tmp5_ = _data_->params;
	_data_->_tmp6_ = _data_->_tmp5_->err;
	if (_data_->_tmp6_ != NULL) {
		_data_->_tmp7_ = _data_->params;
		_data_->_tmp8_ = _data_->_tmp7_->err;
		_data_->_tmp9_ = _g_error_copy0 (_data_->_tmp8_);
		_data_->_inner_error0_ = _data_->_tmp9_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->params);
		_g_object_unref0 (_data_->cmd);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp11_ = _data_->cmd;
	_data_->_state_ = 1;
	geary_imap_client_session_submit_command (_data_->self, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp11_, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand), geary_imap_client_session_close_mailbox_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp12_ = geary_imap_client_session_submit_command_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp10_ = _data_->_tmp12_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->params);
		_g_object_unref0 (_data_->cmd);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp13_ = _data_->_tmp10_;
	_data_->_tmp10_ = NULL;
	_data_->result = _data_->_tmp13_;
	_g_object_unref0 (_data_->_tmp10_);
	_g_object_unref0 (_data_->params);
	_g_object_unref0 (_data_->cmd);
	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 guint
geary_imap_client_session_on_close_mailbox (GearyImapClientSession* self,
                                            guint state,
                                            guint event,
                                            void* user,
                                            GObject* object)
{
	GearyImapClientSessionMachineParams* params = NULL;
	GearyImapClientSessionMachineParams* _tmp0_;
	GearyImapClientSessionMachineParams* _tmp1_;
	GearyImapCommand* _tmp2_;
	GearyImapClientSessionMachineParams* _tmp3_;
	GearyImapClientConnection* _tmp4_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS, GearyImapClientSessionMachineParams));
	params = _tmp0_;
	_tmp1_ = params;
	_tmp2_ = _tmp1_->cmd;
	_vala_assert (GEARY_IMAP_IS_CLOSE_COMMAND (_tmp2_), "params.cmd is CloseCommand");
	_tmp3_ = params;
	if (!geary_imap_client_session_reserve_state_change_cmd (self, _tmp3_, state, event)) {
		result = state;
		_g_object_unref0 (params);
		return result;
	}
	_tmp4_ = self->priv->cx;
	geary_imap_client_connection_enable_idle_when_quiet (_tmp4_, FALSE);
	result = (guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSING_MAILBOX;
	_g_object_unref0 (params);
	return result;
}

static guint
geary_imap_client_session_on_closing_recv_completion (GearyImapClientSession* self,
                                                      guint state,
                                                      guint event,
                                                      void* user,
                                                      GObject* object)
{
	GearyImapStatusResponse* completion_response = NULL;
	GearyImapStatusResponse* _tmp0_;
	GearyImapStatusResponse* _tmp1_;
	GearyImapStatusResponse* _tmp2_;
	GearyImapStatus _tmp3_;
	GearyImapStatus _tmp4_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_TYPE_STATUS_RESPONSE, GearyImapStatusResponse));
	completion_response = _tmp0_;
	_tmp1_ = completion_response;
	if (!geary_imap_client_session_validate_state_change_cmd (self, G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEARY_IMAP_TYPE_SERVER_RESPONSE, GearyImapServerResponse), NULL)) {
		result = state;
		_g_object_unref0 (completion_response);
		return result;
	}
	_tmp2_ = completion_response;
	_tmp3_ = geary_imap_status_response_get_status (_tmp2_);
	_tmp4_ = _tmp3_;
	switch (_tmp4_) {
		case GEARY_IMAP_STATUS_OK:
		{
			_g_object_unref0 (self->selected_mailbox);
			self->selected_mailbox = NULL;
			self->selected_readonly = FALSE;
			result = (guint) GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZED;
			_g_object_unref0 (completion_response);
			return result;
		}
		default:
		{
			GearyImapStatusResponse* _tmp5_;
			gchar* _tmp6_;
			gchar* _tmp7_;
			_tmp5_ = completion_response;
			_tmp6_ = geary_imap_parameter_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
			_tmp7_ = _tmp6_;
			geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "CLOSE failed: %s", _tmp7_);
			_g_free0 (_tmp7_);
			result = (guint) GEARY_IMAP_CLIENT_SESSION_STATE_SELECTED;
			_g_object_unref0 (completion_response);
			return result;
		}
	}
}

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

void
geary_imap_client_session_logout_async (GearyImapClientSession* self,
                                        GCancellable* cancellable,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_)
{
	GearyImapClientSessionLogoutAsyncData* _data_;
	GearyImapClientSession* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapClientSessionLogoutAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_client_session_logout_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_client_session_logout_async_co (_data_);
}

void
geary_imap_client_session_logout_finish (GearyImapClientSession* self,
                                         GAsyncResult* _res_,
                                         GError** error)
{
	GearyImapClientSessionLogoutAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

/**
     * Sends a logout command.
     *
     * If the connection is still available and the server still
     * responding, this will result in the connection being closed
     * gracefully. Thus unless an error occurs, {@link
     * disconnect_async} would not need to be called afterwards.
     */
static void
geary_imap_client_session_logout_async_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_)
{
	GearyImapClientSessionLogoutAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_client_session_logout_async_co (_data_);
}

static gboolean
geary_imap_client_session_logout_async_co (GearyImapClientSessionLogoutAsyncData* _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_logout_command_new (_data_->cancellable);
	_data_->cmd = _data_->_tmp0_;
	_data_->_tmp1_ = geary_imap_client_session_machine_params_new (G_TYPE_CHECK_INSTANCE_CAST (_data_->cmd, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand));
	_data_->params = _data_->_tmp1_;
	_data_->_tmp2_ = _data_->self->priv->fsm;
	geary_state_machine_issue (_data_->_tmp2_, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_LOGOUT, NULL, G_TYPE_CHECK_INSTANCE_CAST (_data_->params, G_TYPE_OBJECT, GObject), NULL);
	_data_->_tmp3_ = _data_->params->err;
	if (_data_->_tmp3_ != NULL) {
		_data_->_tmp4_ = _data_->params->err;
		_data_->_tmp5_ = _g_error_copy0 (_data_->_tmp4_);
		_data_->_inner_error0_ = _data_->_tmp5_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->params);
		_g_object_unref0 (_data_->cmd);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (_data_->params->proceed) {
		_data_->_state_ = 1;
		geary_imap_client_session_submit_command (_data_->self, G_TYPE_CHECK_INSTANCE_CAST (_data_->cmd, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand), geary_imap_client_session_logout_async_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp6_ = geary_imap_client_session_submit_command_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp7_ = _data_->_tmp6_;
		_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_->params);
			_g_object_unref0 (_data_->cmd);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_state_ = 2;
		geary_imap_client_session_do_disconnect (_data_->self, GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_LOCAL_CLOSE, geary_imap_client_session_logout_async_ready, _data_);
		return FALSE;
		_state_2:
		geary_imap_client_session_do_disconnect_finish (_data_->self, _data_->_res_);
	}
	_g_object_unref0 (_data_->params);
	_g_object_unref0 (_data_->cmd);
	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 guint
geary_imap_client_session_on_logout (GearyImapClientSession* self,
                                     guint state,
                                     guint event,
                                     void* user,
                                     GObject* object)
{
	GearyImapClientSessionMachineParams* params = NULL;
	GearyImapClientSessionMachineParams* _tmp0_;
	GearyImapClientSessionMachineParams* _tmp1_;
	GearyImapCommand* _tmp2_;
	GearyImapClientSessionMachineParams* _tmp3_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS, GearyImapClientSessionMachineParams));
	params = _tmp0_;
	_tmp1_ = params;
	_tmp2_ = _tmp1_->cmd;
	_vala_assert (GEARY_IMAP_IS_LOGOUT_COMMAND (_tmp2_), "params.cmd is LogoutCommand");
	_tmp3_ = params;
	if (geary_imap_client_session_reserve_state_change_cmd (self, _tmp3_, state, event)) {
		state = (guint) GEARY_IMAP_CLIENT_SESSION_STATE_LOGOUT;
	}
	result = state;
	_g_object_unref0 (params);
	return result;
}

static guint
geary_imap_client_session_on_logging_out_recv_status (GearyImapClientSession* self,
                                                      guint state,
                                                      guint event,
                                                      void* user,
                                                      GObject* object)
{
	GearyImapStatusResponse* status_response = NULL;
	GearyImapStatusResponse* _tmp0_;
	GearyImapStatusResponse* _tmp1_;
	GearyImapStatus _tmp2_;
	GearyImapStatus _tmp3_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_TYPE_STATUS_RESPONSE, GearyImapStatusResponse));
	status_response = _tmp0_;
	_tmp1_ = status_response;
	_tmp2_ = geary_imap_status_response_get_status (_tmp1_);
	_tmp3_ = _tmp2_;
	switch (_tmp3_) {
		case GEARY_IMAP_STATUS_OK:
		{
			break;
		}
		case GEARY_IMAP_STATUS_BYE:
		{
			GearyImapStatusResponse* _tmp4_;
			gchar* _tmp5_;
			gchar* _tmp6_;
			_tmp4_ = status_response;
			_tmp5_ = geary_imap_parameter_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
			_tmp6_ = _tmp5_;
			geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Received bye from server on logout: %s", _tmp6_);
			_g_free0 (_tmp6_);
			break;
		}
		default:
		{
			GearyImapStatusResponse* _tmp7_;
			gchar* _tmp8_;
			gchar* _tmp9_;
			_tmp7_ = status_response;
			_tmp8_ = geary_imap_parameter_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
			_tmp9_ = _tmp8_;
			geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Received error from server on logout: %s", _tmp9_);
			_g_free0 (_tmp9_);
			break;
		}
	}
	result = state;
	_g_object_unref0 (status_response);
	return result;
}

static guint
geary_imap_client_session_on_logging_out_recv_completion (GearyImapClientSession* self,
                                                          guint state,
                                                          guint event,
                                                          void* user,
                                                          GObject* object)
{
	GearyImapStatusResponse* completion_response = NULL;
	GearyImapStatusResponse* _tmp0_;
	guint new_state = 0U;
	GearyImapStatusResponse* _tmp1_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_TYPE_STATUS_RESPONSE, GearyImapStatusResponse));
	completion_response = _tmp0_;
	new_state = state;
	_tmp1_ = completion_response;
	if (geary_imap_client_session_validate_state_change_cmd (self, G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEARY_IMAP_TYPE_SERVER_RESPONSE, GearyImapServerResponse), NULL)) {
		new_state = (guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED;
		geary_imap_client_session_clear_namespaces (self);
	}
	result = new_state;
	_g_object_unref0 (completion_response);
	return result;
}

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

void
geary_imap_client_session_disconnect_async (GearyImapClientSession* self,
                                            GCancellable* cancellable,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_)
{
	GearyImapClientSessionDisconnectAsyncData* _data_;
	GearyImapClientSession* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapClientSessionDisconnectAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_client_session_disconnect_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_client_session_disconnect_async_co (_data_);
}

void
geary_imap_client_session_disconnect_finish (GearyImapClientSession* self,
                                             GAsyncResult* _res_,
                                             GError** error)
{
	GearyImapClientSessionDisconnectAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
geary_imap_client_session_disconnect_async_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_)
{
	GearyImapClientSessionDisconnectAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_client_session_disconnect_async_co (_data_);
}

static gboolean
geary_imap_client_session_disconnect_async_co (GearyImapClientSessionDisconnectAsyncData* _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_client_session_machine_params_new (NULL);
	_data_->params = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->self->priv->fsm;
	geary_state_machine_issue (_data_->_tmp1_, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_DISCONNECT, NULL, G_TYPE_CHECK_INSTANCE_CAST (_data_->params, G_TYPE_OBJECT, GObject), NULL);
	_data_->_tmp2_ = _data_->params->err;
	if (_data_->_tmp2_ != NULL) {
		_data_->_tmp3_ = _data_->params->err;
		_data_->_tmp4_ = _g_error_copy0 (_data_->_tmp3_);
		_data_->_inner_error0_ = _data_->_tmp4_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->params);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (!_data_->params->proceed) {
		_g_object_unref0 (_data_->params);
		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_->disconnect_err = NULL;
	{
		_data_->_tmp5_ = _data_->self->priv->cx;
		_data_->_state_ = 1;
		geary_imap_client_connection_disconnect_async (_data_->_tmp5_, _data_->cancellable, geary_imap_client_session_disconnect_async_ready, _data_);
		return FALSE;
		_state_1:
		geary_imap_client_connection_disconnect_finish (_data_->_tmp5_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->err = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp6_ = _data_->err;
		_data_->_tmp7_ = _g_error_copy0 (_data_->_tmp6_);
		_g_error_free0 (_data_->disconnect_err);
		_data_->disconnect_err = _data_->_tmp7_;
		_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_->disconnect_err);
		_g_object_unref0 (_data_->params);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	geary_imap_client_session_drop_connection (_data_->self);
	geary_imap_client_session_set_disconnected (_data_->self, GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_LOCAL_CLOSE);
	_data_->_tmp8_ = _data_->disconnect_err;
	if (_data_->_tmp8_ != NULL) {
		_data_->_tmp9_ = _data_->disconnect_err;
		_data_->_tmp10_ = _g_error_copy0 (_data_->_tmp9_);
		_data_->_inner_error0_ = _data_->_tmp10_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_error_free0 (_data_->disconnect_err);
		_g_object_unref0 (_data_->params);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_error_free0 (_data_->disconnect_err);
	_g_object_unref0 (_data_->params);
	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 gchar*
geary_imap_client_session_real_to_string (GearyLoggingSource* base)
{
	GearyImapClientSession * self;
	gchar* _tmp0_ = NULL;
	GearyImapClientConnection* _tmp1_;
	gchar* cx = NULL;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_TYPE_CLIENT_SESSION, GearyImapClientSession);
	_tmp1_ = self->priv->cx;
	if (_tmp1_ != NULL) {
		GearyImapClientConnection* _tmp2_;
		gchar* _tmp3_;
		_tmp2_ = self->priv->cx;
		_tmp3_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp3_;
	} else {
		gchar* _tmp4_;
		_tmp4_ = g_strdup ("not connected");
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp4_;
	}
	_tmp5_ = g_strconcat (", ", _tmp0_, NULL);
	cx = _tmp5_;
	_tmp6_ = geary_logging_source_default_to_string (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), cx);
	result = _tmp6_;
	_g_free0 (cx);
	_g_free0 (_tmp0_);
	return result;
}

/** {@inheritDoc} */
static GearyLoggingState*
geary_imap_client_session_real_to_logging_state (GearyLoggingSource* base)
{
	GearyImapClientSession * self;
	GearyLoggingState* _tmp0_ = NULL;
	GearyImapMailboxSpecifier* _tmp1_;
	GearyLoggingState* result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_TYPE_CLIENT_SESSION, GearyImapClientSession);
	_tmp1_ = self->selected_mailbox;
	if (_tmp1_ == NULL) {
		GearyStateMachine* _tmp2_;
		GearyStateMachine* _tmp3_;
		guint _tmp4_;
		guint _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		GearyLoggingState* _tmp8_;
		_tmp2_ = self->priv->fsm;
		_tmp3_ = self->priv->fsm;
		_tmp4_ = geary_state_machine_get_state (_tmp3_);
		_tmp5_ = _tmp4_;
		_tmp6_ = geary_state_machine_get_state_string (_tmp2_, _tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = geary_logging_state_new (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "%s", _tmp7_);
		_geary_logging_state_unref0 (_tmp0_);
		_tmp0_ = _tmp8_;
		_g_free0 (_tmp7_);
	} else {
		const gchar* _tmp9_ = NULL;
		GearyStateMachine* _tmp10_;
		GearyStateMachine* _tmp11_;
		guint _tmp12_;
		guint _tmp13_;
		gchar* _tmp14_;
		gchar* _tmp15_;
		GearyImapMailboxSpecifier* _tmp16_;
		gchar* _tmp17_;
		gchar* _tmp18_;
		GearyLoggingState* _tmp19_;
		if (self->selected_readonly) {
			_tmp9_ = "RO";
		} else {
			_tmp9_ = "RW";
		}
		_tmp10_ = self->priv->fsm;
		_tmp11_ = self->priv->fsm;
		_tmp12_ = geary_state_machine_get_state (_tmp11_);
		_tmp13_ = _tmp12_;
		_tmp14_ = geary_state_machine_get_state_string (_tmp10_, _tmp13_);
		_tmp15_ = _tmp14_;
		_tmp16_ = self->selected_mailbox;
		_tmp17_ = geary_imap_mailbox_specifier_to_string (_tmp16_);
		_tmp18_ = _tmp17_;
		_tmp19_ = geary_logging_state_new (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "%s:%s selected %s", _tmp15_, _tmp18_, _tmp9_);
		_geary_logging_state_unref0 (_tmp0_);
		_tmp0_ = _tmp19_;
		_g_free0 (_tmp18_);
		_g_free0 (_tmp15_);
	}
	result = _tmp0_;
	return result;
}

/** Sets the connection's logging parent. */
void
geary_imap_client_session_set_logging_parent (GearyImapClientSession* self,
                                              GearyLoggingSource* parent)
{
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail (GEARY_LOGGING_IS_SOURCE (parent));
	self->priv->_logging_parent = parent;
}

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

static void
geary_imap_client_session_do_disconnect (GearyImapClientSession* self,
                                         GearyImapClientSessionDisconnectReason reason,
                                         GAsyncReadyCallback _callback_,
                                         gpointer _user_data_)
{
	GearyImapClientSessionDoDisconnectData* _data_;
	GearyImapClientSession* _tmp0_;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	_data_ = g_slice_new0 (GearyImapClientSessionDoDisconnectData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_client_session_do_disconnect_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->reason = reason;
	geary_imap_client_session_do_disconnect_co (_data_);
}

static void
geary_imap_client_session_do_disconnect_finish (GearyImapClientSession* self,
                                                GAsyncResult* _res_)
{
	GearyImapClientSessionDoDisconnectData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
geary_imap_client_session_do_disconnect_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_)
{
	GearyImapClientSessionDoDisconnectData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_client_session_do_disconnect_co (_data_);
}

static gboolean
geary_imap_client_session_do_disconnect_co (GearyImapClientSessionDoDisconnectData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	geary_imap_client_session_set_disconnected (_data_->self, _data_->reason);
	{
		_data_->_tmp0_ = _data_->self->priv->cx;
		_data_->_state_ = 1;
		geary_imap_client_connection_disconnect_async (_data_->_tmp0_, NULL, geary_imap_client_session_do_disconnect_ready, _data_);
		return FALSE;
		_state_1:
		geary_imap_client_connection_disconnect_finish (_data_->_tmp0_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->err = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp1_ = _data_->err;
		_data_->_tmp2_ = _data_->_tmp1_->message;
		geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "IMAP disconnect failed: %s", _data_->_tmp2_);
		_g_error_free0 (_data_->err);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	geary_imap_client_session_drop_connection (_data_->self);
	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
__lambda48_ (GearyImapClientSession* self)
{
	geary_imap_client_session_drop_connection (self);
}

static void
___lambda48__geary_state_post_transition (void* user,
                                          GObject* object,
                                          GError* err,
                                          gpointer self)
{
	__lambda48_ ((GearyImapClientSession*) self);
}

static guint
geary_imap_client_session_on_connecting_send_recv_error (GearyImapClientSession* self,
                                                         guint state,
                                                         guint event,
                                                         void* user,
                                                         GObject* object,
                                                         GError* err)
{
	const gchar* _tmp0_ = NULL;
	GearyStateMachine* _tmp2_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	if (err != NULL) {
		const gchar* _tmp1_;
		_tmp1_ = err->message;
		_tmp0_ = _tmp1_;
	} else {
		_tmp0_ = "(no error)";
	}
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Connecting send/recv error, dropping client connection: %s", _tmp0_);
	_tmp2_ = self->priv->fsm;
	geary_state_machine_do_post_transition (_tmp2_, ___lambda48__geary_state_post_transition, self, NULL, NULL, NULL);
	result = (guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED;
	return result;
}

static guint
geary_imap_client_session_on_send_error (GearyImapClientSession* self,
                                         guint state,
                                         guint event,
                                         void* user,
                                         GObject* object,
                                         GError* err)
{
	const gchar* _tmp0_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
		result = state;
		return result;
	}
	_tmp0_ = err->message;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Send error, disconnecting: %s", _tmp0_);
	geary_imap_client_session_do_disconnect (self, GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_LOCAL_ERROR, NULL, NULL);
	result = (guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED;
	return result;
}

static guint
geary_imap_client_session_on_recv_error (GearyImapClientSession* self,
                                         guint state,
                                         guint event,
                                         void* user,
                                         GObject* object,
                                         GError* err)
{
	const gchar* _tmp0_ = NULL;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	if (err != NULL) {
		const gchar* _tmp1_;
		_tmp1_ = err->message;
		_tmp0_ = _tmp1_;
	} else {
		_tmp0_ = "(no error)";
	}
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Receive error, disconnecting: %s", _tmp0_);
	geary_imap_client_session_do_disconnect (self, GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_REMOTE_ERROR, NULL, NULL);
	result = (guint) GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED;
	return result;
}

static guint
geary_imap_client_session_on_early_command (GearyImapClientSession* self,
                                            guint state,
                                            guint event,
                                            void* user,
                                            GObject* object)
{
	GearyImapClientSessionMachineParams* params = NULL;
	GearyImapClientSessionMachineParams* _tmp0_;
	GearyImapCommand* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GError* _tmp6_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_vala_assert (object != NULL, "object != null");
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS, GearyImapClientSessionMachineParams));
	params = _tmp0_;
	_tmp1_ = params->cmd;
	_tmp2_ = geary_imap_command_get_name (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
	_tmp5_ = _tmp4_;
	_tmp6_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_NOT_CONNECTED, "Command %s too early: not connected to %s", _tmp3_, _tmp5_);
	_g_error_free0 (params->err);
	params->err = _tmp6_;
	_g_free0 (_tmp5_);
	result = state;
	_g_object_unref0 (params);
	return result;
}

static guint
geary_imap_client_session_on_late_command (GearyImapClientSession* self,
                                           guint state,
                                           guint event,
                                           void* user,
                                           GObject* object)
{
	GearyImapClientSessionMachineParams* params = NULL;
	GearyImapClientSessionMachineParams* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	GError* _tmp3_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_vala_assert (object != NULL, "object != null");
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS, GearyImapClientSessionMachineParams));
	params = _tmp0_;
	_tmp1_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
	_tmp2_ = _tmp1_;
	_tmp3_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_NOT_CONNECTED, "Connection to %s closing or closed", _tmp2_);
	_g_error_free0 (params->err);
	params->err = _tmp3_;
	_g_free0 (_tmp2_);
	result = state;
	_g_object_unref0 (params);
	return result;
}

static guint
geary_imap_client_session_on_already_connected (GearyImapClientSession* self,
                                                guint state,
                                                guint event,
                                                void* user,
                                                GObject* object)
{
	GearyImapClientSessionMachineParams* params = NULL;
	GearyImapClientSessionMachineParams* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	GError* _tmp3_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_vala_assert (object != NULL, "object != null");
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS, GearyImapClientSessionMachineParams));
	params = _tmp0_;
	_tmp1_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
	_tmp2_ = _tmp1_;
	_tmp3_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_ALREADY_CONNECTED, "Already connected or connecting to %s", _tmp2_);
	_g_error_free0 (params->err);
	params->err = _tmp3_;
	_g_free0 (_tmp2_);
	result = state;
	_g_object_unref0 (params);
	return result;
}

static guint
geary_imap_client_session_on_already_logged_in (GearyImapClientSession* self,
                                                guint state,
                                                guint event,
                                                void* user,
                                                GObject* object)
{
	GearyImapClientSessionMachineParams* params = NULL;
	GearyImapClientSessionMachineParams* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	GError* _tmp3_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_vala_assert (object != NULL, "object != null");
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS, GearyImapClientSessionMachineParams));
	params = _tmp0_;
	_tmp1_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
	_tmp2_ = _tmp1_;
	_tmp3_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_ALREADY_CONNECTED, "Already logged in to %s", _tmp2_);
	_g_error_free0 (params->err);
	params->err = _tmp3_;
	_g_free0 (_tmp2_);
	result = state;
	_g_object_unref0 (params);
	return result;
}

static guint
geary_imap_client_session_on_dropped_response (GearyImapClientSession* self,
                                               guint state,
                                               guint event,
                                               void* user,
                                               GObject* object)
{
	GearyImapServerResponse* server_response = NULL;
	GearyImapServerResponse* _tmp0_;
	GearyStateMachine* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_TYPE_SERVER_RESPONSE, GearyImapServerResponse));
	server_response = _tmp0_;
	_tmp1_ = self->priv->fsm;
	_tmp2_ = geary_state_machine_get_event_issued_string (_tmp1_, state, event);
	_tmp3_ = _tmp2_;
	_tmp4_ = geary_imap_parameter_to_string (G_TYPE_CHECK_INSTANCE_CAST (server_response, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
	_tmp5_ = _tmp4_;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Dropped server response at %s: %s", _tmp3_, _tmp5_);
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
	result = state;
	_g_object_unref0 (server_response);
	return result;
}

static guint
geary_imap_client_session_on_unauthenticated (GearyImapClientSession* self,
                                              guint state,
                                              guint event,
                                              void* user,
                                              GObject* object)
{
	GearyImapClientSessionMachineParams* params = NULL;
	GearyImapClientSessionMachineParams* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	GError* _tmp3_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	g_return_val_if_fail ((object == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (object, G_TYPE_OBJECT), 0U);
	_vala_assert (object != NULL, "object != null");
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS, GearyImapClientSessionMachineParams));
	params = _tmp0_;
	_tmp1_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
	_tmp2_ = _tmp1_;
	_tmp3_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_UNAUTHENTICATED, "Not authenticated with %s", _tmp2_);
	_g_error_free0 (params->err);
	params->err = _tmp3_;
	_g_free0 (_tmp2_);
	result = state;
	_g_object_unref0 (params);
	return result;
}

static guint
geary_imap_client_session_on_ignored_transition (GearyImapClientSession* self,
                                                 guint state,
                                                 guint event)
{
	GearyStateMachine* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	guint result;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self), 0U);
	_tmp0_ = self->priv->fsm;
	_tmp1_ = geary_state_machine_get_event_issued_string (_tmp0_, state, event);
	_tmp2_ = _tmp1_;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Ignored transition: %s", _tmp2_);
	_g_free0 (_tmp2_);
	result = state;
	return result;
}

static void
geary_imap_client_session_submit_command_data_free (gpointer _data)
{
	GearyImapClientSessionSubmitCommandData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cmd);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapClientSessionSubmitCommandData, _data_);
}

static void
geary_imap_client_session_submit_command (GearyImapClientSession* self,
                                          GearyImapCommand* cmd,
                                          GAsyncReadyCallback _callback_,
                                          gpointer _user_data_)
{
	GearyImapClientSessionSubmitCommandData* _data_;
	GearyImapClientSession* _tmp0_;
	GearyImapCommand* _tmp1_;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail (GEARY_IMAP_IS_COMMAND (cmd));
	_data_ = g_slice_new0 (GearyImapClientSessionSubmitCommandData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_client_session_submit_command_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cmd);
	_g_object_unref0 (_data_->cmd);
	_data_->cmd = _tmp1_;
	geary_imap_client_session_submit_command_co (_data_);
}

static GearyImapStatusResponse*
geary_imap_client_session_submit_command_finish (GearyImapClientSession* self,
                                                 GAsyncResult* _res_,
                                                 GError** error)
{
	GearyImapStatusResponse* result;
	GearyImapClientSessionSubmitCommandData* _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_client_session_submit_command_ready (GObject* source_object,
                                                GAsyncResult* _res_,
                                                gpointer _user_data_)
{
	GearyImapClientSessionSubmitCommandData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_client_session_submit_command_co (_data_);
}

static gboolean
geary_imap_client_session_submit_command_co (GearyImapClientSessionSubmitCommandData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->cx;
	if (_data_->_tmp0_ == NULL) {
		_data_->_tmp1_ = _data_->self->priv->imap_endpoint;
		_data_->_tmp2_ = geary_endpoint_to_string (_data_->_tmp1_);
		_data_->_tmp3_ = _data_->_tmp2_;
		_data_->_tmp4_ = g_error_new (GEARY_IMAP_ERROR, GEARY_IMAP_ERROR_NOT_CONNECTED, "Not connected to %s", _data_->_tmp3_);
		_data_->_tmp5_ = _data_->_tmp4_;
		_g_free0 (_data_->_tmp3_);
		_data_->_inner_error0_ = _data_->_tmp5_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp6_ = _data_->self->priv->cx;
	geary_imap_client_connection_send_command (_data_->_tmp6_, _data_->cmd, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_state_ = 1;
	geary_imap_command_wait_until_complete (_data_->cmd, NULL, geary_imap_client_session_submit_command_ready, _data_);
	return FALSE;
	_state_1:
	geary_imap_command_wait_until_complete_finish (_data_->cmd, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp7_ = geary_imap_command_get_status (_data_->cmd);
	_data_->_tmp8_ = _data_->_tmp7_;
	_data_->_tmp9_ = _g_object_ref0 (_data_->_tmp8_);
	_data_->result = _data_->_tmp9_;
	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_client_session_on_network_send_error (GearyImapClientSession* self,
                                                 GError* err)
{
	GearyStateMachine* _tmp0_;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail (err != NULL);
	_tmp0_ = self->priv->fsm;
	geary_state_machine_issue (_tmp0_, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_SEND_ERROR, NULL, NULL, err);
}

static void
geary_imap_client_session_on_received_status_response (GearyImapClientSession* self,
                                                       GearyImapStatusResponse* status_response)
{
	GearyImapCommand* command = NULL;
	GearyImapClientConnection* _tmp0_;
	GearyImapTag* _tmp1_;
	GearyImapTag* _tmp2_;
	GearyImapCommand* _tmp3_;
	gboolean _tmp4_ = FALSE;
	GearyImapCommand* _tmp5_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail (GEARY_IMAP_IS_STATUS_RESPONSE (status_response));
	_tmp0_ = self->priv->cx;
	_tmp1_ = geary_imap_server_response_get_tag (G_TYPE_CHECK_INSTANCE_CAST (status_response, GEARY_IMAP_TYPE_SERVER_RESPONSE, GearyImapServerResponse));
	_tmp2_ = _tmp1_;
	_tmp3_ = geary_imap_client_connection_get_sent_command (_tmp0_, _tmp2_);
	command = _tmp3_;
	_tmp5_ = command;
	if (_tmp5_ == NULL) {
		_tmp4_ = TRUE;
	} else {
		GearyImapCommand* _tmp6_;
		_tmp6_ = command;
		_tmp4_ = !GEARY_IMAP_IS_IDLE_COMMAND (_tmp6_);
	}
	if (_tmp4_) {
		GearyImapResponseCode* response_code = NULL;
		GearyImapResponseCode* _tmp7_;
		GearyImapResponseCode* _tmp8_;
		GearyImapResponseCode* _tmp9_;
		GearyImapResponseCode* _tmp10_;
		gboolean _tmp29_;
		gboolean _tmp30_;
		_tmp7_ = geary_imap_status_response_get_response_code (status_response);
		_tmp8_ = _tmp7_;
		_tmp9_ = _g_object_ref0 (_tmp8_);
		response_code = _tmp9_;
		_tmp10_ = response_code;
		if (_tmp10_ != NULL) {
			{
				GearyImapResponseCodeType* _tmp11_ = NULL;
				GearyImapResponseCode* _tmp12_;
				GearyImapResponseCodeType* _tmp13_;
				_tmp12_ = response_code;
				_tmp13_ = geary_imap_response_code_get_response_code_type (_tmp12_, &_inner_error0_);
				_tmp11_ = _tmp13_;
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					goto __catch0_g_error;
				}
				if (geary_imap_response_code_type_is_value (_tmp11_, GEARY_IMAP_RESPONSE_CODE_TYPE_CAPABILITY)) {
					GearyImapCapabilities* _tmp14_ = NULL;
					GearyImapResponseCode* _tmp15_;
					GearyImapCapabilities* _tmp16_;
					gint _tmp17_;
					gint _tmp18_;
					GearyImapCapabilities* _tmp19_;
					GearyImapStatus _tmp20_;
					GearyImapStatus _tmp21_;
					gchar* _tmp22_;
					gchar* _tmp23_;
					GearyImapCapabilities* _tmp24_;
					gchar* _tmp25_;
					gchar* _tmp26_;
					_tmp15_ = response_code;
					_tmp16_ = self->priv->_capabilities;
					_tmp17_ = geary_imap_capabilities_get_revision (_tmp16_);
					_tmp18_ = _tmp17_;
					_tmp19_ = geary_imap_response_code_get_capabilities (_tmp15_, _tmp18_ + 1, &_inner_error0_);
					_tmp14_ = _tmp19_;
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						_g_object_unref0 (_tmp11_);
						goto __catch0_g_error;
					}
					geary_imap_client_session_set_capabilities (self, _tmp14_);
					_tmp20_ = geary_imap_status_response_get_status (status_response);
					_tmp21_ = _tmp20_;
					_tmp22_ = geary_imap_status_to_string (_tmp21_);
					_tmp23_ = _tmp22_;
					_tmp24_ = self->priv->_capabilities;
					_tmp25_ = geary_generic_capabilities_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp24_, GEARY_TYPE_GENERIC_CAPABILITIES, GearyGenericCapabilities));
					_tmp26_ = _tmp25_;
					geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "%s set capabilities to: %s", _tmp23_, _tmp26_);
					_g_free0 (_tmp26_);
					_g_free0 (_tmp23_);
					_g_object_unref0 (_tmp14_);
				}
				_g_object_unref0 (_tmp11_);
			}
			goto __finally0;
			__catch0_g_error:
			{
				GError* err = NULL;
				GError* _tmp27_;
				const gchar* _tmp28_;
				err = _inner_error0_;
				_inner_error0_ = NULL;
				_tmp27_ = err;
				_tmp28_ = _tmp27_->message;
				geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Unable to convert response code to capabilities: %s", _tmp28_);
				_g_error_free0 (err);
			}
			__finally0:
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_object_unref0 (response_code);
				_g_object_unref0 (command);
				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;
			}
		}
		_tmp29_ = geary_imap_status_response_get_is_completion (status_response);
		_tmp30_ = _tmp29_;
		if (_tmp30_) {
			GearyStateMachine* _tmp31_;
			_tmp31_ = self->priv->fsm;
			geary_state_machine_issue (_tmp31_, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_COMPLETION, NULL, G_TYPE_CHECK_INSTANCE_CAST (status_response, G_TYPE_OBJECT, GObject), NULL);
		} else {
			GearyStateMachine* _tmp32_;
			_tmp32_ = self->priv->fsm;
			geary_state_machine_issue (_tmp32_, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_STATUS, NULL, G_TYPE_CHECK_INSTANCE_CAST (status_response, G_TYPE_OBJECT, GObject), NULL);
		}
		g_signal_emit (self, geary_imap_client_session_signals[GEARY_IMAP_CLIENT_SESSION_STATUS_RESPONSE_RECEIVED_SIGNAL], 0, status_response);
		_g_object_unref0 (response_code);
	}
	_g_object_unref0 (command);
}

static void
geary_imap_client_session_notify_received_data (GearyImapClientSession* self,
                                                GearyImapServerData* server_data,
                                                GError** error)
{
	GearyImapServerDataType _tmp0_;
	GearyImapServerDataType _tmp1_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail (GEARY_IMAP_IS_SERVER_DATA (server_data));
	_tmp0_ = geary_imap_server_data_get_server_data_type (server_data);
	_tmp1_ = _tmp0_;
	switch (_tmp1_) {
		case GEARY_IMAP_SERVER_DATA_TYPE_CAPABILITY:
		{
			GearyImapCapabilities* _tmp2_ = NULL;
			GearyImapCapabilities* _tmp3_;
			gint _tmp4_;
			gint _tmp5_;
			GearyImapCapabilities* _tmp6_;
			GearyImapServerDataType _tmp7_;
			GearyImapServerDataType _tmp8_;
			gchar* _tmp9_;
			gchar* _tmp10_;
			GearyImapCapabilities* _tmp11_;
			gchar* _tmp12_;
			gchar* _tmp13_;
			_tmp3_ = self->priv->_capabilities;
			_tmp4_ = geary_imap_capabilities_get_revision (_tmp3_);
			_tmp5_ = _tmp4_;
			_tmp6_ = geary_imap_server_data_get_capabilities (server_data, _tmp5_ + 1, &_inner_error0_);
			_tmp2_ = _tmp6_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				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;
				}
			}
			geary_imap_client_session_set_capabilities (self, _tmp2_);
			_tmp7_ = geary_imap_server_data_get_server_data_type (server_data);
			_tmp8_ = _tmp7_;
			_tmp9_ = geary_imap_server_data_type_to_string (_tmp8_);
			_tmp10_ = _tmp9_;
			_tmp11_ = self->priv->_capabilities;
			_tmp12_ = geary_generic_capabilities_to_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp11_, GEARY_TYPE_GENERIC_CAPABILITIES, GearyGenericCapabilities));
			_tmp13_ = _tmp12_;
			geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "%s set capabilities to: %s", _tmp10_, _tmp13_);
			_g_free0 (_tmp13_);
			_g_free0 (_tmp10_);
			_g_object_unref0 (_tmp2_);
			break;
		}
		case GEARY_IMAP_SERVER_DATA_TYPE_EXISTS:
		{
			gint _tmp14_ = 0;
			_tmp14_ = geary_imap_server_data_get_exists (server_data, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				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;
				}
			}
			g_signal_emit (self, geary_imap_client_session_signals[GEARY_IMAP_CLIENT_SESSION_EXISTS_SIGNAL], 0, _tmp14_);
			break;
		}
		case GEARY_IMAP_SERVER_DATA_TYPE_EXPUNGE:
		{
			GearyImapSequenceNumber* _tmp15_ = NULL;
			GearyImapSequenceNumber* _tmp16_;
			_tmp16_ = geary_imap_server_data_get_expunge (server_data, &_inner_error0_);
			_tmp15_ = _tmp16_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				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;
				}
			}
			g_signal_emit (self, geary_imap_client_session_signals[GEARY_IMAP_CLIENT_SESSION_EXPUNGE_SIGNAL], 0, _tmp15_);
			_g_object_unref0 (_tmp15_);
			break;
		}
		case GEARY_IMAP_SERVER_DATA_TYPE_FETCH:
		{
			GearyImapFetchedData* _tmp17_ = NULL;
			GearyImapFetchedData* _tmp18_;
			_tmp18_ = geary_imap_server_data_get_fetch (server_data, &_inner_error0_);
			_tmp17_ = _tmp18_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				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;
				}
			}
			g_signal_emit (self, geary_imap_client_session_signals[GEARY_IMAP_CLIENT_SESSION_FETCH_SIGNAL], 0, _tmp17_);
			_g_object_unref0 (_tmp17_);
			break;
		}
		case GEARY_IMAP_SERVER_DATA_TYPE_FLAGS:
		{
			GearyImapMailboxAttributes* _tmp19_ = NULL;
			GearyImapMailboxAttributes* _tmp20_;
			_tmp20_ = geary_imap_server_data_get_flags (server_data, &_inner_error0_);
			_tmp19_ = _tmp20_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				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;
				}
			}
			g_signal_emit (self, geary_imap_client_session_signals[GEARY_IMAP_CLIENT_SESSION_FLAGS_SIGNAL], 0, _tmp19_);
			_g_object_unref0 (_tmp19_);
			break;
		}
		case GEARY_IMAP_SERVER_DATA_TYPE_LIST:
		case GEARY_IMAP_SERVER_DATA_TYPE_XLIST:
		{
			GearyImapMailboxInformation* _tmp21_ = NULL;
			GearyImapMailboxInformation* _tmp22_;
			_tmp22_ = geary_imap_server_data_get_list (server_data, &_inner_error0_);
			_tmp21_ = _tmp22_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				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;
				}
			}
			g_signal_emit (self, geary_imap_client_session_signals[GEARY_IMAP_CLIENT_SESSION_LIST_SIGNAL], 0, _tmp21_);
			_g_object_unref0 (_tmp21_);
			break;
		}
		case GEARY_IMAP_SERVER_DATA_TYPE_RECENT:
		{
			gint _tmp23_ = 0;
			_tmp23_ = geary_imap_server_data_get_recent (server_data, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				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;
				}
			}
			g_signal_emit (self, geary_imap_client_session_signals[GEARY_IMAP_CLIENT_SESSION_RECENT_SIGNAL], 0, _tmp23_);
			break;
		}
		case GEARY_IMAP_SERVER_DATA_TYPE_STATUS:
		{
			GearyImapStatusData* _tmp24_ = NULL;
			GearyImapStatusData* _tmp25_;
			_tmp25_ = geary_imap_server_data_get_status (server_data, &_inner_error0_);
			_tmp24_ = _tmp25_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				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;
				}
			}
			g_signal_emit (self, geary_imap_client_session_signals[GEARY_IMAP_CLIENT_SESSION_STATUS_SIGNAL], 0, _tmp24_);
			_g_object_unref0 (_tmp24_);
			break;
		}
		case GEARY_IMAP_SERVER_DATA_TYPE_SEARCH:
		{
			gint64* _tmp26_ = NULL;
			gint _tmp27_ = 0;
			gint64* _tmp28_;
			gint _tmp26__length1;
			gint __tmp26__size_;
			_tmp28_ = geary_imap_server_data_get_search (server_data, &_tmp27_, &_inner_error0_);
			_tmp26_ = _tmp28_;
			_tmp26__length1 = _tmp27_;
			__tmp26__size_ = _tmp26__length1;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				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;
				}
			}
			g_signal_emit (self, geary_imap_client_session_signals[GEARY_IMAP_CLIENT_SESSION_SEARCH_SIGNAL], 0, _tmp26_, (gint) _tmp26__length1);
			_tmp26_ = (g_free (_tmp26_), NULL);
			break;
		}
		case GEARY_IMAP_SERVER_DATA_TYPE_NAMESPACE:
		{
			GearyImapNamespaceResponse* ns = NULL;
			GearyImapNamespaceResponse* _tmp29_;
			GearyImapNamespaceResponse* _tmp30_;
			GeeList* _tmp31_;
			GeeList* _tmp32_;
			GeeList* _tmp33_;
			GearyImapNamespaceResponse* _tmp34_;
			GeeList* _tmp35_;
			GeeList* _tmp36_;
			GeeList* _tmp37_;
			GearyImapNamespaceResponse* _tmp38_;
			GeeList* _tmp39_;
			GeeList* _tmp40_;
			GeeList* _tmp41_;
			geary_imap_client_session_clear_namespaces (self);
			_tmp29_ = geary_imap_server_data_get_namespace (server_data, &_inner_error0_);
			ns = _tmp29_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				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;
				}
			}
			_tmp30_ = ns;
			_tmp31_ = geary_imap_namespace_response_get_personal (_tmp30_);
			_tmp32_ = _tmp31_;
			_tmp33_ = self->priv->personal_namespaces;
			geary_imap_client_session_update_namespaces (self, _tmp32_, _tmp33_);
			_tmp34_ = ns;
			_tmp35_ = geary_imap_namespace_response_get_shared (_tmp34_);
			_tmp36_ = _tmp35_;
			_tmp37_ = self->priv->shared_namespaces;
			geary_imap_client_session_update_namespaces (self, _tmp36_, _tmp37_);
			_tmp38_ = ns;
			_tmp39_ = geary_imap_namespace_response_get_user (_tmp38_);
			_tmp40_ = _tmp39_;
			_tmp41_ = self->priv->user_namespaces;
			geary_imap_client_session_update_namespaces (self, _tmp40_, _tmp41_);
			_g_object_unref0 (ns);
			break;
		}
		default:
		case GEARY_IMAP_SERVER_DATA_TYPE_LSUB:
		{
			gchar* _tmp42_;
			gchar* _tmp43_;
			_tmp42_ = geary_imap_parameter_to_string (G_TYPE_CHECK_INSTANCE_CAST (server_data, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
			_tmp43_ = _tmp42_;
			geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Not notifying of unhandled server data: %s", _tmp43_);
			_g_free0 (_tmp43_);
			break;
		}
	}
}

static void
geary_imap_client_session_clear_namespaces (GearyImapClientSession* self)
{
	GeeMap* _tmp0_;
	GeeList* _tmp1_;
	GeeList* _tmp2_;
	GeeList* _tmp3_;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	_tmp0_ = self->priv->namespaces;
	gee_map_clear (_tmp0_);
	_tmp1_ = self->priv->personal_namespaces;
	gee_collection_clear (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEE_TYPE_COLLECTION, GeeCollection));
	_tmp2_ = self->priv->shared_namespaces;
	gee_collection_clear (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, GEE_TYPE_COLLECTION, GeeCollection));
	_tmp3_ = self->priv->user_namespaces;
	gee_collection_clear (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, GEE_TYPE_COLLECTION, GeeCollection));
}

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < ((glong) 0)) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}

static void
geary_imap_client_session_update_namespaces (GearyImapClientSession* self,
                                             GeeList* response,
                                             GeeList* list)
{
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail ((response == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (response, GEE_TYPE_LIST));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (list, GEE_TYPE_LIST));
	if (response != NULL) {
		{
			GeeList* _ns_list = NULL;
			gint _ns_size = 0;
			GeeList* _tmp0_;
			gint _tmp1_;
			gint _tmp2_;
			gint _ns_index = 0;
			_ns_list = response;
			_tmp0_ = _ns_list;
			_tmp1_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEE_TYPE_COLLECTION, GeeCollection));
			_tmp2_ = _tmp1_;
			_ns_size = _tmp2_;
			_ns_index = -1;
			while (TRUE) {
				gint _tmp3_;
				gint _tmp4_;
				GearyImapNamespace* ns = NULL;
				GeeList* _tmp5_;
				gpointer _tmp6_;
				GearyImapNamespace* _tmp7_;
				gchar* prefix = NULL;
				GearyImapNamespace* _tmp8_;
				const gchar* _tmp9_;
				const gchar* _tmp10_;
				gchar* _tmp11_;
				gchar* delim = NULL;
				GearyImapNamespace* _tmp12_;
				const gchar* _tmp13_;
				const gchar* _tmp14_;
				gchar* _tmp15_;
				gboolean _tmp16_ = FALSE;
				const gchar* _tmp17_;
				GeeMap* _tmp28_;
				const gchar* _tmp29_;
				GearyImapNamespace* _tmp30_;
				_ns_index = _ns_index + 1;
				_tmp3_ = _ns_index;
				_tmp4_ = _ns_size;
				if (!(_tmp3_ < _tmp4_)) {
					break;
				}
				_tmp5_ = _ns_list;
				_tmp6_ = gee_list_get (_tmp5_, _ns_index);
				ns = (GearyImapNamespace*) _tmp6_;
				_tmp7_ = ns;
				gee_collection_add (G_TYPE_CHECK_INSTANCE_CAST (list, GEE_TYPE_COLLECTION, GeeCollection), _tmp7_);
				_tmp8_ = ns;
				_tmp9_ = geary_imap_namespace_get_prefix (_tmp8_);
				_tmp10_ = _tmp9_;
				_tmp11_ = g_strdup (_tmp10_);
				prefix = _tmp11_;
				_tmp12_ = ns;
				_tmp13_ = geary_imap_namespace_get_delim (_tmp12_);
				_tmp14_ = _tmp13_;
				_tmp15_ = g_strdup (_tmp14_);
				delim = _tmp15_;
				_tmp17_ = delim;
				if (_tmp17_ != NULL) {
					const gchar* _tmp18_;
					const gchar* _tmp19_;
					_tmp18_ = prefix;
					_tmp19_ = delim;
					_tmp16_ = g_str_has_suffix (_tmp18_, _tmp19_);
				} else {
					_tmp16_ = FALSE;
				}
				if (_tmp16_) {
					const gchar* _tmp20_;
					const gchar* _tmp21_;
					gint _tmp22_;
					gint _tmp23_;
					const gchar* _tmp24_;
					gint _tmp25_;
					gint _tmp26_;
					gchar* _tmp27_;
					_tmp20_ = prefix;
					_tmp21_ = prefix;
					_tmp22_ = strlen (_tmp21_);
					_tmp23_ = _tmp22_;
					_tmp24_ = delim;
					_tmp25_ = strlen (_tmp24_);
					_tmp26_ = _tmp25_;
					_tmp27_ = string_substring (_tmp20_, (glong) 0, (glong) (_tmp23_ - _tmp26_));
					_g_free0 (prefix);
					prefix = _tmp27_;
				}
				_tmp28_ = self->priv->namespaces;
				_tmp29_ = prefix;
				_tmp30_ = ns;
				gee_map_set (_tmp28_, _tmp29_, _tmp30_);
				_g_free0 (delim);
				_g_free0 (prefix);
				_g_object_unref0 (ns);
			}
		}
	}
}

static void
geary_imap_client_session_on_received_server_data (GearyImapClientSession* self,
                                                   GearyImapServerData* server_data)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail (GEARY_IMAP_IS_SERVER_DATA (server_data));
	{
		geary_imap_client_session_notify_received_data (self, server_data, &_inner_error0_);
		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;
		}
	}
	goto __finally0;
	__catch0_geary_imap_error:
	{
		GError* ierr = NULL;
		gchar* _tmp0_;
		gchar* _tmp1_;
		GError* _tmp2_;
		const gchar* _tmp3_;
		ierr = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp0_ = geary_imap_parameter_to_string (G_TYPE_CHECK_INSTANCE_CAST (server_data, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
		_tmp1_ = _tmp0_;
		_tmp2_ = ierr;
		_tmp3_ = _tmp2_->message;
		geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Failure notifying of server data: %s %s", _tmp1_, _tmp3_);
		_g_free0 (_tmp1_);
		_g_error_free0 (ierr);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
}

static void
geary_imap_client_session_on_received_bytes (GearyImapClientSession* self)
{
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	geary_imap_client_session_set_last_seen (self, g_get_real_time ());
	geary_imap_client_session_schedule_keepalive (self);
}

static void
geary_imap_client_session_on_received_bad_response (GearyImapClientSession* self,
                                                    GearyImapRootParameters* root,
                                                    GError* err)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	GearyStateMachine* _tmp3_;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail (GEARY_IMAP_IS_ROOT_PARAMETERS (root));
	_tmp0_ = geary_imap_parameter_to_string (G_TYPE_CHECK_INSTANCE_CAST (root, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
	_tmp1_ = _tmp0_;
	_tmp2_ = err->message;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Received bad response %s: %s", _tmp1_, _tmp2_);
	_g_free0 (_tmp1_);
	_tmp3_ = self->priv->fsm;
	geary_state_machine_issue (_tmp3_, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_ERROR, NULL, NULL, err);
}

static void
geary_imap_client_session_on_network_receive_failure (GearyImapClientSession* self,
                                                      GError* err)
{
	GearyStateMachine* _tmp0_;
	g_return_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (self));
	g_return_if_fail (err != NULL);
	_tmp0_ = self->priv->fsm;
	geary_state_machine_issue (_tmp0_, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_RECV_ERROR, NULL, NULL, err);
}

static GearyImapClientSessionMachineParams*
geary_imap_client_session_machine_params_construct (GType object_type,
                                                    GearyImapCommand* cmd)
{
	GearyImapClientSessionMachineParams * self = NULL;
	GearyImapCommand* _tmp0_;
	g_return_val_if_fail ((cmd == NULL) || GEARY_IMAP_IS_COMMAND (cmd), NULL);
	self = (GearyImapClientSessionMachineParams*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (cmd);
	_g_object_unref0 (self->cmd);
	self->cmd = _tmp0_;
	return self;
}

static GearyImapClientSessionMachineParams*
geary_imap_client_session_machine_params_new (GearyImapCommand* cmd)
{
	return geary_imap_client_session_machine_params_construct (GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS, cmd);
}

static void
geary_imap_client_session_machine_params_class_init (GearyImapClientSessionMachineParamsClass * klass,
                                                     gpointer klass_data)
{
	geary_imap_client_session_machine_params_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = geary_imap_client_session_machine_params_finalize;
}

static void
geary_imap_client_session_machine_params_instance_init (GearyImapClientSessionMachineParams * self,
                                                        gpointer klass)
{
	self->err = NULL;
	self->proceed = FALSE;
}

static void
geary_imap_client_session_machine_params_finalize (GObject * obj)
{
	GearyImapClientSessionMachineParams * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_IMAP_CLIENT_SESSION_TYPE_MACHINE_PARAMS, GearyImapClientSessionMachineParams);
	_g_object_unref0 (self->cmd);
	_g_error_free0 (self->err);
	G_OBJECT_CLASS (geary_imap_client_session_machine_params_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
geary_imap_client_session_machine_params_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapClientSessionMachineParamsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_client_session_machine_params_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapClientSessionMachineParams), 0, (GInstanceInitFunc) geary_imap_client_session_machine_params_instance_init, NULL };
	GType geary_imap_client_session_machine_params_type_id;
	geary_imap_client_session_machine_params_type_id = g_type_register_static (G_TYPE_OBJECT, "GearyImapClientSessionMachineParams", &g_define_type_info, 0);
	return geary_imap_client_session_machine_params_type_id;
}

static GType
geary_imap_client_session_machine_params_get_type (void)
{
	static gsize geary_imap_client_session_machine_params_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_client_session_machine_params_type_id__once)) {
		GType geary_imap_client_session_machine_params_type_id;
		geary_imap_client_session_machine_params_type_id = geary_imap_client_session_machine_params_get_type_once ();
		g_once_init_leave (&geary_imap_client_session_machine_params_type_id__once, geary_imap_client_session_machine_params_type_id);
	}
	return geary_imap_client_session_machine_params_type_id__once;
}

static GearyImapClientSessionCommandCallback*
geary_imap_client_session_command_callback_construct (GType object_type,
                                                      GSourceFunc callback,
                                                      gpointer callback_target)
{
	GearyImapClientSessionCommandCallback* self = NULL;
	self = (GearyImapClientSessionCommandCallback*) g_type_create_instance (object_type);
	self->callback = callback;
	self->callback_target = callback_target;
	return self;
}

static GearyImapClientSessionCommandCallback*
geary_imap_client_session_command_callback_new (GSourceFunc callback,
                                                gpointer callback_target)
{
	return geary_imap_client_session_command_callback_construct (GEARY_IMAP_CLIENT_SESSION_TYPE_COMMAND_CALLBACK, callback, callback_target);
}

static void
geary_imap_client_session_value_command_callback_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
geary_imap_client_session_value_command_callback_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		geary_imap_client_session_command_callback_unref (value->data[0].v_pointer);
	}
}

static void
geary_imap_client_session_value_command_callback_copy_value (const GValue* src_value,
                                                             GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = geary_imap_client_session_command_callback_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
geary_imap_client_session_value_command_callback_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
geary_imap_client_session_value_command_callback_collect_value (GValue* value,
                                                                guint n_collect_values,
                                                                GTypeCValue* collect_values,
                                                                guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		GearyImapClientSessionCommandCallback * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = geary_imap_client_session_command_callback_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
geary_imap_client_session_value_command_callback_lcopy_value (const GValue* value,
                                                              guint n_collect_values,
                                                              GTypeCValue* collect_values,
                                                              guint collect_flags)
{
	GearyImapClientSessionCommandCallback ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = geary_imap_client_session_command_callback_ref (value->data[0].v_pointer);
	}
	return NULL;
}

static GParamSpec*
geary_imap_client_session_param_spec_command_callback (const gchar* name,
                                                       const gchar* nick,
                                                       const gchar* blurb,
                                                       GType object_type,
                                                       GParamFlags flags)
{
	GearyImapClientSessionParamSpecCommandCallback* spec;
	g_return_val_if_fail (g_type_is_a (object_type, GEARY_IMAP_CLIENT_SESSION_TYPE_COMMAND_CALLBACK), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

static gpointer
geary_imap_client_session_value_get_command_callback (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GEARY_IMAP_CLIENT_SESSION_TYPE_COMMAND_CALLBACK), NULL);
	return value->data[0].v_pointer;
}

static void
geary_imap_client_session_value_set_command_callback (GValue* value,
                                                      gpointer v_object)
{
	GearyImapClientSessionCommandCallback * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GEARY_IMAP_CLIENT_SESSION_TYPE_COMMAND_CALLBACK));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GEARY_IMAP_CLIENT_SESSION_TYPE_COMMAND_CALLBACK));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		geary_imap_client_session_command_callback_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		geary_imap_client_session_command_callback_unref (old);
	}
}

static void
geary_imap_client_session_value_take_command_callback (GValue* value,
                                                       gpointer v_object)
{
	GearyImapClientSessionCommandCallback * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GEARY_IMAP_CLIENT_SESSION_TYPE_COMMAND_CALLBACK));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GEARY_IMAP_CLIENT_SESSION_TYPE_COMMAND_CALLBACK));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		geary_imap_client_session_command_callback_unref (old);
	}
}

static void
geary_imap_client_session_command_callback_class_init (GearyImapClientSessionCommandCallbackClass * klass,
                                                       gpointer klass_data)
{
	geary_imap_client_session_command_callback_parent_class = g_type_class_peek_parent (klass);
	((GearyImapClientSessionCommandCallbackClass *) klass)->finalize = geary_imap_client_session_command_callback_finalize;
}

static void
geary_imap_client_session_command_callback_instance_init (GearyImapClientSessionCommandCallback * self,
                                                          gpointer klass)
{
	self->ref_count = 1;
}

static void
geary_imap_client_session_command_callback_finalize (GearyImapClientSessionCommandCallback * obj)
{
	GearyImapClientSessionCommandCallback * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_IMAP_CLIENT_SESSION_TYPE_COMMAND_CALLBACK, GearyImapClientSessionCommandCallback);
	g_signal_handlers_destroy (self);
}

 G_GNUC_NO_INLINE static GType
geary_imap_client_session_command_callback_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { geary_imap_client_session_value_command_callback_init, geary_imap_client_session_value_command_callback_free_value, geary_imap_client_session_value_command_callback_copy_value, geary_imap_client_session_value_command_callback_peek_pointer, "p", geary_imap_client_session_value_command_callback_collect_value, "p", geary_imap_client_session_value_command_callback_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapClientSessionCommandCallbackClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_client_session_command_callback_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapClientSessionCommandCallback), 0, (GInstanceInitFunc) geary_imap_client_session_command_callback_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType geary_imap_client_session_command_callback_type_id;
	geary_imap_client_session_command_callback_type_id = g_type_register_fundamental (g_type_fundamental_next (), "GearyImapClientSessionCommandCallback", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return geary_imap_client_session_command_callback_type_id;
}

static GType
geary_imap_client_session_command_callback_get_type (void)
{
	static gsize geary_imap_client_session_command_callback_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_client_session_command_callback_type_id__once)) {
		GType geary_imap_client_session_command_callback_type_id;
		geary_imap_client_session_command_callback_type_id = geary_imap_client_session_command_callback_get_type_once ();
		g_once_init_leave (&geary_imap_client_session_command_callback_type_id__once, geary_imap_client_session_command_callback_type_id);
	}
	return geary_imap_client_session_command_callback_type_id__once;
}

static gpointer
geary_imap_client_session_command_callback_ref (gpointer instance)
{
	GearyImapClientSessionCommandCallback * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

static void
geary_imap_client_session_command_callback_unref (gpointer instance)
{
	GearyImapClientSessionCommandCallback * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		GEARY_IMAP_CLIENT_SESSION_COMMAND_CALLBACK_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static GearyImapClientSessionSendCommandOperation*
geary_imap_client_session_send_command_operation_construct (GType object_type,
                                                            GearyImapClientSession* owner,
                                                            GearyImapCommand* cmd)
{
	GearyImapClientSessionSendCommandOperation * self = NULL;
	GearyImapClientSession* _tmp0_;
	GearyImapCommand* _tmp1_;
	g_return_val_if_fail (GEARY_IMAP_IS_CLIENT_SESSION (owner), NULL);
	g_return_val_if_fail (GEARY_IMAP_IS_COMMAND (cmd), NULL);
	self = (GearyImapClientSessionSendCommandOperation*) geary_nonblocking_batch_operation_construct (object_type);
	_tmp0_ = _g_object_ref0 (owner);
	_g_object_unref0 (self->owner);
	self->owner = _tmp0_;
	_tmp1_ = _g_object_ref0 (cmd);
	_g_object_unref0 (self->cmd);
	self->cmd = _tmp1_;
	return self;
}

static GearyImapClientSessionSendCommandOperation*
geary_imap_client_session_send_command_operation_new (GearyImapClientSession* owner,
                                                      GearyImapCommand* cmd)
{
	return geary_imap_client_session_send_command_operation_construct (GEARY_IMAP_CLIENT_SESSION_TYPE_SEND_COMMAND_OPERATION, owner, cmd);
}

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

static void
geary_imap_client_session_send_command_operation_real_execute_async (GearyNonblockingBatchOperation* base,
                                                                     GCancellable* cancellable,
                                                                     GAsyncReadyCallback _callback_,
                                                                     gpointer _user_data_)
{
	GearyImapClientSessionSendCommandOperation * self;
	GearyImapClientSessionSendCommandOperationExecuteAsyncData* _data_;
	GearyImapClientSessionSendCommandOperation* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_CLIENT_SESSION_TYPE_SEND_COMMAND_OPERATION, GearyImapClientSessionSendCommandOperation);
	_data_ = g_slice_new0 (GearyImapClientSessionSendCommandOperationExecuteAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_client_session_send_command_operation_real_execute_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_imap_client_session_send_command_operation_real_execute_async_co (_data_);
}

static GObject*
geary_imap_client_session_send_command_operation_execute_finish (GearyNonblockingBatchOperation* base,
                                                                 GAsyncResult* _res_,
                                                                 GError** error)
{
	GObject* result;
	GearyImapClientSessionSendCommandOperationExecuteAsyncData* _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_client_session_send_command_operation_execute_async_ready (GObject* source_object,
                                                                      GAsyncResult* _res_,
                                                                      gpointer _user_data_)
{
	GearyImapClientSessionSendCommandOperationExecuteAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_client_session_send_command_operation_real_execute_async_co (_data_);
}

static gboolean
geary_imap_client_session_send_command_operation_real_execute_async_co (GearyImapClientSessionSendCommandOperationExecuteAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp1_ = _data_->self->owner;
	_data_->_tmp2_ = _data_->self->cmd;
	_data_->_state_ = 1;
	geary_imap_client_session_submit_command (_data_->_tmp1_, _data_->_tmp2_, geary_imap_client_session_send_command_operation_execute_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp3_ = geary_imap_client_session_submit_command_finish (_data_->_tmp1_, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp0_ = _data_->_tmp3_;
	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_->_tmp4_ = _data_->_tmp0_;
	_data_->_tmp0_ = NULL;
	_g_object_unref0 (_data_->self->response);
	_data_->self->response = _data_->_tmp4_;
	_data_->_tmp5_ = _data_->self->response;
	_data_->_tmp6_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp5_, G_TYPE_OBJECT, GObject));
	_data_->result = _data_->_tmp6_;
	_g_object_unref0 (_data_->_tmp0_);
	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_client_session_send_command_operation_class_init (GearyImapClientSessionSendCommandOperationClass * klass,
                                                             gpointer klass_data)
{
	geary_imap_client_session_send_command_operation_parent_class = g_type_class_peek_parent (klass);
	((GearyNonblockingBatchOperationClass *) klass)->execute_async = (void (*) (GearyNonblockingBatchOperation*, GCancellable*, GAsyncReadyCallback, gpointer)) geary_imap_client_session_send_command_operation_real_execute_async;
	((GearyNonblockingBatchOperationClass *) klass)->execute_finish = (GObject* (*) (GearyNonblockingBatchOperation*, GAsyncResult*, GError**)) geary_imap_client_session_send_command_operation_execute_finish;
	G_OBJECT_CLASS (klass)->finalize = geary_imap_client_session_send_command_operation_finalize;
}

static void
geary_imap_client_session_send_command_operation_instance_init (GearyImapClientSessionSendCommandOperation * self,
                                                                gpointer klass)
{
}

static void
geary_imap_client_session_send_command_operation_finalize (GObject * obj)
{
	GearyImapClientSessionSendCommandOperation * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_IMAP_CLIENT_SESSION_TYPE_SEND_COMMAND_OPERATION, GearyImapClientSessionSendCommandOperation);
	_g_object_unref0 (self->owner);
	_g_object_unref0 (self->cmd);
	_g_object_unref0 (self->response);
	G_OBJECT_CLASS (geary_imap_client_session_send_command_operation_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
geary_imap_client_session_send_command_operation_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapClientSessionSendCommandOperationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_client_session_send_command_operation_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapClientSessionSendCommandOperation), 0, (GInstanceInitFunc) geary_imap_client_session_send_command_operation_instance_init, NULL };
	GType geary_imap_client_session_send_command_operation_type_id;
	geary_imap_client_session_send_command_operation_type_id = g_type_register_static (GEARY_NONBLOCKING_TYPE_BATCH_OPERATION, "GearyImapClientSessionSendCommandOperation", &g_define_type_info, 0);
	return geary_imap_client_session_send_command_operation_type_id;
}

static GType
geary_imap_client_session_send_command_operation_get_type (void)
{
	static gsize geary_imap_client_session_send_command_operation_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_client_session_send_command_operation_type_id__once)) {
		GType geary_imap_client_session_send_command_operation_type_id;
		geary_imap_client_session_send_command_operation_type_id = geary_imap_client_session_send_command_operation_get_type_once ();
		g_once_init_leave (&geary_imap_client_session_send_command_operation_type_id__once, geary_imap_client_session_send_command_operation_type_id);
	}
	return geary_imap_client_session_send_command_operation_type_id__once;
}

static void
geary_imap_client_session_class_init (GearyImapClientSessionClass * klass,
                                      gpointer klass_data)
{
	GearyStateMachineDescriptor* _tmp0_;
	geary_imap_client_session_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GearyImapClientSession_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_geary_imap_client_session_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_geary_imap_client_session_set_property;
	G_OBJECT_CLASS (klass)->finalize = geary_imap_client_session_finalize;
	/**
	     * Returns the current IMAP protocol state for the session.
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_PROPERTY, geary_imap_client_session_properties[GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_PROPERTY] = g_param_spec_enum ("protocol-state", "protocol-state", "protocol-state", GEARY_IMAP_CLIENT_SESSION_TYPE_PROTOCOL_STATE, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** Specifies the reason the session was disconnected, if any. */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_CLIENT_SESSION_DISCONNECTED_PROPERTY, geary_imap_client_session_properties[GEARY_IMAP_CLIENT_SESSION_DISCONNECTED_PROPERTY] = g_param_spec_enum ("disconnected", "disconnected", "disconnected", GEARY_IMAP_CLIENT_SESSION_TYPE_DISCONNECT_REASON, GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/**
	     * Set of IMAP extensions reported as being supported by the server.
	     *
	     * The capabilities that an IMAP session offers changes over time,
	     * for example after login or STARTTLS. The instance assigned to
	     * this property will change as these change and the instance's
	     * {@link Capabilities.revision} property will also monotonically
	     * increase over the lifetime of a single session.
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_CLIENT_SESSION_CAPABILITIES_PROPERTY, geary_imap_client_session_properties[GEARY_IMAP_CLIENT_SESSION_CAPABILITIES_PROPERTY] = g_param_spec_object ("capabilities", "capabilities", "capabilities", GEARY_IMAP_TYPE_CAPABILITIES, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** Determines if this session supports the IMAP IDLE extension. */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_CLIENT_SESSION_IS_IDLE_SUPPORTED_PROPERTY, geary_imap_client_session_properties[GEARY_IMAP_CLIENT_SESSION_IS_IDLE_SUPPORTED_PROPERTY] = g_param_spec_boolean ("is-idle-supported", "is-idle-supported", "is-idle-supported", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/**
	     * The server's greeting, if any.
	     *
	     * This will be null up until the session has successfully
	     * connected and the server has responded with a greeting.
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_CLIENT_SESSION_SERVER_GREETING_PROPERTY, geary_imap_client_session_properties[GEARY_IMAP_CLIENT_SESSION_SERVER_GREETING_PROPERTY] = g_param_spec_object ("server-greeting", "server-greeting", "server-greeting", GEARY_IMAP_TYPE_STATUS_RESPONSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** {@inheritDoc} */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_CLIENT_SESSION_LOGGING_PARENT_PROPERTY, geary_imap_client_session_properties[GEARY_IMAP_CLIENT_SESSION_LOGGING_PARENT_PROPERTY] = g_param_spec_object ("logging-parent", "logging-parent", "logging-parent", GEARY_LOGGING_TYPE_SOURCE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/**
	     * Determines when the last successful command response was received.
	     *
	     * Returns the system wall clock time the last successful command
	     * response was received, in microseconds since the UNIX epoch.
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_CLIENT_SESSION_LAST_SEEN_PROPERTY, geary_imap_client_session_properties[GEARY_IMAP_CLIENT_SESSION_LAST_SEEN_PROPERTY] = g_param_spec_int64 ("last-seen", "last-seen", "last-seen", G_MININT64, G_MAXINT64, (gint64) 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** Records the actual name and delimiter used for the inbox */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_CLIENT_SESSION_INBOX_PROPERTY, geary_imap_client_session_properties[GEARY_IMAP_CLIENT_SESSION_INBOX_PROPERTY] = g_param_spec_object ("inbox", "inbox", "inbox", GEARY_IMAP_TYPE_MAILBOX_INFORMATION, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** The quirks being used by this session. */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_CLIENT_SESSION_QUIRKS_PROPERTY, geary_imap_client_session_properties[GEARY_IMAP_CLIENT_SESSION_QUIRKS_PROPERTY] = g_param_spec_object ("quirks", "quirks", "quirks", GEARY_IMAP_TYPE_QUIRKS, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	/** Emitted when an IMAP command status response is received. */
	geary_imap_client_session_signals[GEARY_IMAP_CLIENT_SESSION_STATUS_RESPONSE_RECEIVED_SIGNAL] = g_signal_new ("status-response-received", GEARY_IMAP_TYPE_CLIENT_SESSION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GEARY_IMAP_TYPE_STATUS_RESPONSE);
	geary_imap_client_session_signals[GEARY_IMAP_CLIENT_SESSION_EXISTS_SIGNAL] = g_signal_new ("exists", GEARY_IMAP_TYPE_CLIENT_SESSION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
	geary_imap_client_session_signals[GEARY_IMAP_CLIENT_SESSION_EXPUNGE_SIGNAL] = g_signal_new ("expunge", GEARY_IMAP_TYPE_CLIENT_SESSION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GEARY_IMAP_TYPE_SEQUENCE_NUMBER);
	geary_imap_client_session_signals[GEARY_IMAP_CLIENT_SESSION_FETCH_SIGNAL] = g_signal_new ("fetch", GEARY_IMAP_TYPE_CLIENT_SESSION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GEARY_IMAP_TYPE_FETCHED_DATA);
	geary_imap_client_session_signals[GEARY_IMAP_CLIENT_SESSION_FLAGS_SIGNAL] = g_signal_new ("flags", GEARY_IMAP_TYPE_CLIENT_SESSION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GEARY_IMAP_TYPE_MAILBOX_ATTRIBUTES);
	/**
	     * Fired when a LIST or XLIST {@link ServerData} is returned from the server.
	     */
	geary_imap_client_session_signals[GEARY_IMAP_CLIENT_SESSION_LIST_SIGNAL] = g_signal_new ("list", GEARY_IMAP_TYPE_CLIENT_SESSION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GEARY_IMAP_TYPE_MAILBOX_INFORMATION);
	geary_imap_client_session_signals[GEARY_IMAP_CLIENT_SESSION_RECENT_SIGNAL] = g_signal_new ("recent", GEARY_IMAP_TYPE_CLIENT_SESSION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
	geary_imap_client_session_signals[GEARY_IMAP_CLIENT_SESSION_SEARCH_SIGNAL] = g_signal_new ("search", GEARY_IMAP_TYPE_CLIENT_SESSION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__POINTER_INT, G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_INT);
	geary_imap_client_session_signals[GEARY_IMAP_CLIENT_SESSION_STATUS_SIGNAL] = g_signal_new ("status", GEARY_IMAP_TYPE_CLIENT_SESSION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GEARY_IMAP_TYPE_STATUS_DATA);
	_tmp0_ = geary_state_machine_descriptor_new ("Geary.Imap.ClientSession", (guint) GEARY_IMAP_CLIENT_SESSION_STATE_NOT_CONNECTED, (guint) GEARY_IMAP_CLIENT_SESSION_STATE_COUNT, (guint) GEARY_IMAP_CLIENT_SESSION_EVENT_COUNT, _geary_imap_client_session_state_to_string_geary_state_state_event_to_string, NULL, _geary_imap_client_session_event_to_string_geary_state_state_event_to_string, NULL);
	geary_imap_client_session_machine_desc = _tmp0_;
}

static void
geary_imap_client_session_geary_logging_source_interface_init (GearyLoggingSourceIface * iface,
                                                               gpointer iface_data)
{
	geary_imap_client_session_geary_logging_source_parent_iface = g_type_interface_peek_parent (iface);
	iface->to_string = (gchar* (*) (GearyLoggingSource*)) geary_imap_client_session_real_to_string;
	iface->to_logging_state = (GearyLoggingState* (*) (GearyLoggingSource*)) geary_imap_client_session_real_to_logging_state;
	iface->get_logging_domain = geary_imap_client_session_real_get_logging_domain;
	iface->get_logging_parent = geary_imap_client_session_real_get_logging_parent;
}

static void
geary_imap_client_session_instance_init (GearyImapClientSession * self,
                                         gpointer klass)
{
	GearyImapCapabilities* _tmp0_;
	GeeArrayList* _tmp1_;
	GeeArrayList* _tmp2_;
	GeeArrayList* _tmp3_;
	GeeHashMap* _tmp4_;
	self->priv = geary_imap_client_session_get_instance_private (self);
	self->priv->_disconnected = GEARY_IMAP_CLIENT_SESSION_DISCONNECT_REASON_NULL;
	_tmp0_ = geary_imap_capabilities_new_empty (0);
	self->priv->_capabilities = _tmp0_;
	self->priv->_server_greeting = NULL;
	self->selected_mailbox = NULL;
	self->selected_readonly = FALSE;
	self->priv->_logging_parent = NULL;
	self->priv->_last_seen = (gint64) 0;
	self->priv->_inbox = NULL;
	_tmp1_ = gee_array_list_new (GEARY_IMAP_TYPE_NAMESPACE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->priv->personal_namespaces = G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEE_TYPE_LIST, GeeList);
	_tmp2_ = gee_array_list_new (GEARY_IMAP_TYPE_NAMESPACE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->priv->user_namespaces = G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, GEE_TYPE_LIST, GeeList);
	_tmp3_ = gee_array_list_new (GEARY_IMAP_TYPE_NAMESPACE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->priv->shared_namespaces = G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, GEE_TYPE_LIST, GeeList);
	self->priv->cx = NULL;
	self->priv->keepalive_id = (guint) 0;
	self->priv->selected_keepalive_secs = (guint) 0;
	self->priv->unselected_keepalive_secs = (guint) 0;
	self->priv->selected_with_idle_keepalive_secs = (guint) 0;
	self->priv->state_change_cmd = NULL;
	self->priv->connect_waiter = NULL;
	self->priv->connect_err = NULL;
	_tmp4_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, GEARY_IMAP_TYPE_NAMESPACE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->namespaces = G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, GEE_TYPE_MAP, GeeMap);
}

static void
geary_imap_client_session_finalize (GObject * obj)
{
	GearyImapClientSession * self;
	GearyStateMachine* _tmp0_;
	guint _tmp1_;
	guint _tmp2_;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_IMAP_TYPE_CLIENT_SESSION, GearyImapClientSession);
	_tmp0_ = self->priv->fsm;
	_tmp1_ = geary_state_machine_get_state (_tmp0_);
	_tmp2_ = _tmp1_;
	switch (_tmp2_) {
		case GEARY_IMAP_CLIENT_SESSION_STATE_NOT_CONNECTED:
		case GEARY_IMAP_CLIENT_SESSION_STATE_CLOSED:
		{
			break;
		}
		default:
		{
			g_warning ("imap-client-session.vala:550: ClientSession ref dropped while still ac" \
"tive");
		}
	}
	_g_object_unref0 (self->priv->_capabilities);
	_g_object_unref0 (self->priv->_server_greeting);
	_g_object_unref0 (self->selected_mailbox);
	_g_object_unref0 (self->priv->_inbox);
	_g_object_unref0 (self->priv->_quirks);
	_g_object_unref0 (self->priv->personal_namespaces);
	_g_object_unref0 (self->priv->user_namespaces);
	_g_object_unref0 (self->priv->shared_namespaces);
	_g_object_unref0 (self->priv->imap_endpoint);
	_g_object_unref0 (self->priv->fsm);
	_g_object_unref0 (self->priv->cx);
	_g_object_unref0 (self->priv->state_change_cmd);
	_g_object_unref0 (self->priv->connect_waiter);
	_g_error_free0 (self->priv->connect_err);
	_g_object_unref0 (self->priv->namespaces);
	G_OBJECT_CLASS (geary_imap_client_session_parent_class)->finalize (obj);
}

/**
 * High-level interface to a single IMAP server connection.
 *
 * The client session is responsible for opening, maintaining and
 * closing a TCP connection to an IMAP server. When opening, the
 * session will obtain and maintain capabilities, establish a StartTLS
 * session if appropriate, authenticate, and obtain
 * connection-specific information about the server such as the name
 * used for the INBOX and any mailbox namespaces. When connecting has
 * completed successfully, the connection will be in the IMAP
 * authenticated state.
 *
 * Any IMAP commands that affect the IMAP connection's state (LOGIN,
 * LOGOUT, SELECT, etc) must be executed by calling the appropriate
 * method on this object. For example, call `login_async` rather than
 * sending a {@link LoginCommand}. Other commands can be sent via
 * {@link send_command_async} and {@link send_multiple_commands_async}.
 */
 G_GNUC_NO_INLINE static GType
geary_imap_client_session_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapClientSessionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_client_session_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapClientSession), 0, (GInstanceInitFunc) geary_imap_client_session_instance_init, NULL };
	static const GInterfaceInfo geary_logging_source_info = { (GInterfaceInitFunc) geary_imap_client_session_geary_logging_source_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType geary_imap_client_session_type_id;
	geary_imap_client_session_type_id = g_type_register_static (GEARY_TYPE_BASE_OBJECT, "GearyImapClientSession", &g_define_type_info, 0);
	g_type_add_interface_static (geary_imap_client_session_type_id, GEARY_LOGGING_TYPE_SOURCE, &geary_logging_source_info);
	GearyImapClientSession_private_offset = g_type_add_instance_private (geary_imap_client_session_type_id, sizeof (GearyImapClientSessionPrivate));
	return geary_imap_client_session_type_id;
}

GType
geary_imap_client_session_get_type (void)
{
	static gsize geary_imap_client_session_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_client_session_type_id__once)) {
		GType geary_imap_client_session_type_id;
		geary_imap_client_session_type_id = geary_imap_client_session_get_type_once ();
		g_once_init_leave (&geary_imap_client_session_type_id__once, geary_imap_client_session_type_id);
	}
	return geary_imap_client_session_type_id__once;
}

static void
_vala_geary_imap_client_session_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	GearyImapClientSession * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_TYPE_CLIENT_SESSION, GearyImapClientSession);
	switch (property_id) {
		case GEARY_IMAP_CLIENT_SESSION_PROTOCOL_STATE_PROPERTY:
		g_value_set_enum (value, geary_imap_client_session_get_protocol_state (self));
		break;
		case GEARY_IMAP_CLIENT_SESSION_DISCONNECTED_PROPERTY:
		g_value_set_enum (value, geary_imap_client_session_get_disconnected (self));
		break;
		case GEARY_IMAP_CLIENT_SESSION_CAPABILITIES_PROPERTY:
		g_value_set_object (value, geary_imap_client_session_get_capabilities (self));
		break;
		case GEARY_IMAP_CLIENT_SESSION_IS_IDLE_SUPPORTED_PROPERTY:
		g_value_set_boolean (value, geary_imap_client_session_get_is_idle_supported (self));
		break;
		case GEARY_IMAP_CLIENT_SESSION_SERVER_GREETING_PROPERTY:
		g_value_set_object (value, geary_imap_client_session_get_server_greeting (self));
		break;
		case GEARY_IMAP_CLIENT_SESSION_LOGGING_PARENT_PROPERTY:
		g_value_set_object (value, geary_logging_source_get_logging_parent (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource)));
		break;
		case GEARY_IMAP_CLIENT_SESSION_LAST_SEEN_PROPERTY:
		g_value_set_int64 (value, geary_imap_client_session_get_last_seen (self));
		break;
		case GEARY_IMAP_CLIENT_SESSION_INBOX_PROPERTY:
		g_value_set_object (value, geary_imap_client_session_get_inbox (self));
		break;
		case GEARY_IMAP_CLIENT_SESSION_QUIRKS_PROPERTY:
		g_value_set_object (value, geary_imap_client_session_get_quirks (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_geary_imap_client_session_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec)
{
	GearyImapClientSession * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_TYPE_CLIENT_SESSION, GearyImapClientSession);
	switch (property_id) {
		case GEARY_IMAP_CLIENT_SESSION_DISCONNECTED_PROPERTY:
		geary_imap_client_session_set_disconnected (self, g_value_get_enum (value));
		break;
		case GEARY_IMAP_CLIENT_SESSION_CAPABILITIES_PROPERTY:
		geary_imap_client_session_set_capabilities (self, g_value_get_object (value));
		break;
		case GEARY_IMAP_CLIENT_SESSION_SERVER_GREETING_PROPERTY:
		geary_imap_client_session_set_server_greeting (self, g_value_get_object (value));
		break;
		case GEARY_IMAP_CLIENT_SESSION_LAST_SEEN_PROPERTY:
		geary_imap_client_session_set_last_seen (self, g_value_get_int64 (value));
		break;
		case GEARY_IMAP_CLIENT_SESSION_INBOX_PROPERTY:
		geary_imap_client_session_set_inbox (self, g_value_get_object (value));
		break;
		case GEARY_IMAP_CLIENT_SESSION_QUIRKS_PROPERTY:
		geary_imap_client_session_set_quirks (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

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

