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

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

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

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define GEARY_IMAP_ENGINE_TYPE_ACCOUNT_SYNCHRONIZER (geary_imap_engine_account_synchronizer_get_type ())
#define GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_ENGINE_TYPE_ACCOUNT_SYNCHRONIZER, GearyImapEngineAccountSynchronizer))
#define GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_ENGINE_TYPE_ACCOUNT_SYNCHRONIZER, GearyImapEngineAccountSynchronizerClass))
#define GEARY_IMAP_ENGINE_IS_ACCOUNT_SYNCHRONIZER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_ENGINE_TYPE_ACCOUNT_SYNCHRONIZER))
#define GEARY_IMAP_ENGINE_IS_ACCOUNT_SYNCHRONIZER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_ENGINE_TYPE_ACCOUNT_SYNCHRONIZER))
#define GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_ENGINE_TYPE_ACCOUNT_SYNCHRONIZER, GearyImapEngineAccountSynchronizerClass))

typedef struct _GearyImapEngineAccountSynchronizer GearyImapEngineAccountSynchronizer;
typedef struct _GearyImapEngineAccountSynchronizerClass GearyImapEngineAccountSynchronizerClass;
typedef struct _GearyImapEngineAccountSynchronizerPrivate GearyImapEngineAccountSynchronizerPrivate;

#define GEARY_IMAP_ENGINE_TYPE_GENERIC_ACCOUNT (geary_imap_engine_generic_account_get_type ())
#define GEARY_IMAP_ENGINE_GENERIC_ACCOUNT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_ENGINE_TYPE_GENERIC_ACCOUNT, GearyImapEngineGenericAccount))
#define GEARY_IMAP_ENGINE_GENERIC_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_ENGINE_TYPE_GENERIC_ACCOUNT, GearyImapEngineGenericAccountClass))
#define GEARY_IMAP_ENGINE_IS_GENERIC_ACCOUNT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_ENGINE_TYPE_GENERIC_ACCOUNT))
#define GEARY_IMAP_ENGINE_IS_GENERIC_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_ENGINE_TYPE_GENERIC_ACCOUNT))
#define GEARY_IMAP_ENGINE_GENERIC_ACCOUNT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_ENGINE_TYPE_GENERIC_ACCOUNT, GearyImapEngineGenericAccountClass))

typedef struct _GearyImapEngineGenericAccount GearyImapEngineGenericAccount;
typedef struct _GearyImapEngineGenericAccountClass GearyImapEngineGenericAccountClass;
enum  {
	GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_0_PROPERTY,
	GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_LOGGING_PARENT_PROPERTY,
	GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_NUM_PROPERTIES
};
static GParamSpec* geary_imap_engine_account_synchronizer_properties[GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_NUM_PROPERTIES];
typedef enum  {
	GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_REASON_REFRESH_CONTENTS,
	GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_REASON_FULL_SYNC,
	GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_REASON_TRUNCATE_TO_EPOCH
} GearyImapEngineAccountSynchronizerReason;

#define GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_TYPE_REASON (geary_imap_engine_account_synchronizer_reason_get_type ())
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_time_zone_unref0(var) ((var == NULL) ? NULL : (var = (g_time_zone_unref (var), NULL)))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#define GEARY_IMAP_ENGINE_TYPE_IDLE_GARBAGE_COLLECTION (geary_imap_engine_idle_garbage_collection_get_type ())
#define GEARY_IMAP_ENGINE_IDLE_GARBAGE_COLLECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_ENGINE_TYPE_IDLE_GARBAGE_COLLECTION, GearyImapEngineIdleGarbageCollection))
#define GEARY_IMAP_ENGINE_IDLE_GARBAGE_COLLECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_ENGINE_TYPE_IDLE_GARBAGE_COLLECTION, GearyImapEngineIdleGarbageCollectionClass))
#define GEARY_IMAP_ENGINE_IS_IDLE_GARBAGE_COLLECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_ENGINE_TYPE_IDLE_GARBAGE_COLLECTION))
#define GEARY_IMAP_ENGINE_IS_IDLE_GARBAGE_COLLECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_ENGINE_TYPE_IDLE_GARBAGE_COLLECTION))
#define GEARY_IMAP_ENGINE_IDLE_GARBAGE_COLLECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_ENGINE_TYPE_IDLE_GARBAGE_COLLECTION, GearyImapEngineIdleGarbageCollectionClass))

typedef struct _GearyImapEngineIdleGarbageCollection GearyImapEngineIdleGarbageCollection;
typedef struct _GearyImapEngineIdleGarbageCollectionClass GearyImapEngineIdleGarbageCollectionClass;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

#define GEARY_IMAP_ENGINE_TYPE_MINIMAL_FOLDER (geary_imap_engine_minimal_folder_get_type ())
#define GEARY_IMAP_ENGINE_MINIMAL_FOLDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_ENGINE_TYPE_MINIMAL_FOLDER, GearyImapEngineMinimalFolder))
#define GEARY_IMAP_ENGINE_MINIMAL_FOLDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_ENGINE_TYPE_MINIMAL_FOLDER, GearyImapEngineMinimalFolderClass))
#define GEARY_IMAP_ENGINE_IS_MINIMAL_FOLDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_ENGINE_TYPE_MINIMAL_FOLDER))
#define GEARY_IMAP_ENGINE_IS_MINIMAL_FOLDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_ENGINE_TYPE_MINIMAL_FOLDER))
#define GEARY_IMAP_ENGINE_MINIMAL_FOLDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_ENGINE_TYPE_MINIMAL_FOLDER, GearyImapEngineMinimalFolderClass))

typedef struct _GearyImapEngineMinimalFolder GearyImapEngineMinimalFolder;
typedef struct _GearyImapEngineMinimalFolderClass GearyImapEngineMinimalFolderClass;

#define GEARY_IMAP_ENGINE_TYPE_FOLDER_SYNC (geary_imap_engine_folder_sync_get_type ())
#define GEARY_IMAP_ENGINE_FOLDER_SYNC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_ENGINE_TYPE_FOLDER_SYNC, GearyImapEngineFolderSync))
#define GEARY_IMAP_ENGINE_FOLDER_SYNC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_ENGINE_TYPE_FOLDER_SYNC, GearyImapEngineFolderSyncClass))
#define GEARY_IMAP_ENGINE_IS_FOLDER_SYNC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_ENGINE_TYPE_FOLDER_SYNC))
#define GEARY_IMAP_ENGINE_IS_FOLDER_SYNC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_ENGINE_TYPE_FOLDER_SYNC))
#define GEARY_IMAP_ENGINE_FOLDER_SYNC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_ENGINE_TYPE_FOLDER_SYNC, GearyImapEngineFolderSyncClass))

typedef struct _GearyImapEngineFolderSync GearyImapEngineFolderSync;
typedef struct _GearyImapEngineFolderSyncClass GearyImapEngineFolderSyncClass;

#define GEARY_IMAP_ENGINE_TYPE_REFRESH_FOLDER_SYNC (geary_imap_engine_refresh_folder_sync_get_type ())
#define GEARY_IMAP_ENGINE_REFRESH_FOLDER_SYNC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_ENGINE_TYPE_REFRESH_FOLDER_SYNC, GearyImapEngineRefreshFolderSync))
#define GEARY_IMAP_ENGINE_REFRESH_FOLDER_SYNC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_ENGINE_TYPE_REFRESH_FOLDER_SYNC, GearyImapEngineRefreshFolderSyncClass))
#define GEARY_IMAP_ENGINE_IS_REFRESH_FOLDER_SYNC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_ENGINE_TYPE_REFRESH_FOLDER_SYNC))
#define GEARY_IMAP_ENGINE_IS_REFRESH_FOLDER_SYNC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_ENGINE_TYPE_REFRESH_FOLDER_SYNC))
#define GEARY_IMAP_ENGINE_REFRESH_FOLDER_SYNC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_ENGINE_TYPE_REFRESH_FOLDER_SYNC, GearyImapEngineRefreshFolderSyncClass))

typedef struct _GearyImapEngineRefreshFolderSync GearyImapEngineRefreshFolderSync;
typedef struct _GearyImapEngineRefreshFolderSyncClass GearyImapEngineRefreshFolderSyncClass;

#define GEARY_IMAP_ENGINE_TYPE_FULL_FOLDER_SYNC (geary_imap_engine_full_folder_sync_get_type ())
#define GEARY_IMAP_ENGINE_FULL_FOLDER_SYNC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_ENGINE_TYPE_FULL_FOLDER_SYNC, GearyImapEngineFullFolderSync))
#define GEARY_IMAP_ENGINE_FULL_FOLDER_SYNC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_ENGINE_TYPE_FULL_FOLDER_SYNC, GearyImapEngineFullFolderSyncClass))
#define GEARY_IMAP_ENGINE_IS_FULL_FOLDER_SYNC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_ENGINE_TYPE_FULL_FOLDER_SYNC))
#define GEARY_IMAP_ENGINE_IS_FULL_FOLDER_SYNC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_ENGINE_TYPE_FULL_FOLDER_SYNC))
#define GEARY_IMAP_ENGINE_FULL_FOLDER_SYNC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_ENGINE_TYPE_FULL_FOLDER_SYNC, GearyImapEngineFullFolderSyncClass))

typedef struct _GearyImapEngineFullFolderSync GearyImapEngineFullFolderSync;
typedef struct _GearyImapEngineFullFolderSyncClass GearyImapEngineFullFolderSyncClass;

#define GEARY_IMAP_ENGINE_TYPE_TRUNCATE_TO_EPOCH_FOLDER_SYNC (geary_imap_engine_truncate_to_epoch_folder_sync_get_type ())
#define GEARY_IMAP_ENGINE_TRUNCATE_TO_EPOCH_FOLDER_SYNC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_ENGINE_TYPE_TRUNCATE_TO_EPOCH_FOLDER_SYNC, GearyImapEngineTruncateToEpochFolderSync))
#define GEARY_IMAP_ENGINE_TRUNCATE_TO_EPOCH_FOLDER_SYNC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_ENGINE_TYPE_TRUNCATE_TO_EPOCH_FOLDER_SYNC, GearyImapEngineTruncateToEpochFolderSyncClass))
#define GEARY_IMAP_ENGINE_IS_TRUNCATE_TO_EPOCH_FOLDER_SYNC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_ENGINE_TYPE_TRUNCATE_TO_EPOCH_FOLDER_SYNC))
#define GEARY_IMAP_ENGINE_IS_TRUNCATE_TO_EPOCH_FOLDER_SYNC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_ENGINE_TYPE_TRUNCATE_TO_EPOCH_FOLDER_SYNC))
#define GEARY_IMAP_ENGINE_TRUNCATE_TO_EPOCH_FOLDER_SYNC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_ENGINE_TYPE_TRUNCATE_TO_EPOCH_FOLDER_SYNC, GearyImapEngineTruncateToEpochFolderSyncClass))

typedef struct _GearyImapEngineTruncateToEpochFolderSync GearyImapEngineTruncateToEpochFolderSync;
typedef struct _GearyImapEngineTruncateToEpochFolderSyncClass GearyImapEngineTruncateToEpochFolderSyncClass;
typedef struct _GearyImapEngineFolderSyncPrivate GearyImapEngineFolderSyncPrivate;
enum  {
	GEARY_IMAP_ENGINE_FOLDER_SYNC_0_PROPERTY,
	GEARY_IMAP_ENGINE_FOLDER_SYNC_SYNC_MAX_EPOCH_PROPERTY,
	GEARY_IMAP_ENGINE_FOLDER_SYNC_NUM_PROPERTIES
};
static GParamSpec* geary_imap_engine_folder_sync_properties[GEARY_IMAP_ENGINE_FOLDER_SYNC_NUM_PROPERTIES];
typedef struct _GearyImapEngineFolderSyncExecuteData GearyImapEngineFolderSyncExecuteData;
typedef struct _GearyImapEngineRefreshFolderSyncPrivate GearyImapEngineRefreshFolderSyncPrivate;
enum  {
	GEARY_IMAP_ENGINE_REFRESH_FOLDER_SYNC_0_PROPERTY,
	GEARY_IMAP_ENGINE_REFRESH_FOLDER_SYNC_NUM_PROPERTIES
};
static GParamSpec* geary_imap_engine_refresh_folder_sync_properties[GEARY_IMAP_ENGINE_REFRESH_FOLDER_SYNC_NUM_PROPERTIES];
typedef struct _GearyImapEngineRefreshFolderSyncSyncFolderData GearyImapEngineRefreshFolderSyncSyncFolderData;
typedef struct _GearyImapEngineFullFolderSyncPrivate GearyImapEngineFullFolderSyncPrivate;
enum  {
	GEARY_IMAP_ENGINE_FULL_FOLDER_SYNC_0_PROPERTY,
	GEARY_IMAP_ENGINE_FULL_FOLDER_SYNC_NUM_PROPERTIES
};
static GParamSpec* geary_imap_engine_full_folder_sync_properties[GEARY_IMAP_ENGINE_FULL_FOLDER_SYNC_NUM_PROPERTIES];

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

typedef struct _GearyImapDBFolder GearyImapDBFolder;
typedef struct _GearyImapDBFolderClass GearyImapDBFolderClass;

#define GEARY_IMAP_ENGINE_TYPE_FOREGROUND_GARBAGE_COLLECTION (geary_imap_engine_foreground_garbage_collection_get_type ())
#define GEARY_IMAP_ENGINE_FOREGROUND_GARBAGE_COLLECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_ENGINE_TYPE_FOREGROUND_GARBAGE_COLLECTION, GearyImapEngineForegroundGarbageCollection))
#define GEARY_IMAP_ENGINE_FOREGROUND_GARBAGE_COLLECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_ENGINE_TYPE_FOREGROUND_GARBAGE_COLLECTION, GearyImapEngineForegroundGarbageCollectionClass))
#define GEARY_IMAP_ENGINE_IS_FOREGROUND_GARBAGE_COLLECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_ENGINE_TYPE_FOREGROUND_GARBAGE_COLLECTION))
#define GEARY_IMAP_ENGINE_IS_FOREGROUND_GARBAGE_COLLECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_ENGINE_TYPE_FOREGROUND_GARBAGE_COLLECTION))
#define GEARY_IMAP_ENGINE_FOREGROUND_GARBAGE_COLLECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_ENGINE_TYPE_FOREGROUND_GARBAGE_COLLECTION, GearyImapEngineForegroundGarbageCollectionClass))

typedef struct _GearyImapEngineForegroundGarbageCollection GearyImapEngineForegroundGarbageCollection;
typedef struct _GearyImapEngineForegroundGarbageCollectionClass GearyImapEngineForegroundGarbageCollectionClass;

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

typedef struct _GearyImapDBEmailIdentifier GearyImapDBEmailIdentifier;
typedef struct _GearyImapDBEmailIdentifierClass GearyImapDBEmailIdentifierClass;
typedef enum  {
	GEARY_IMAP_DB_FOLDER_LIST_FLAGS_NONE = 0,
	GEARY_IMAP_DB_FOLDER_LIST_FLAGS_PARTIAL_OK = 1 << 0,
	GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDE_MARKED_FOR_REMOVE = 1 << 1,
	GEARY_IMAP_DB_FOLDER_LIST_FLAGS_INCLUDING_ID = 1 << 2,
	GEARY_IMAP_DB_FOLDER_LIST_FLAGS_OLDEST_TO_NEWEST = 1 << 3,
	GEARY_IMAP_DB_FOLDER_LIST_FLAGS_ONLY_INCOMPLETE = 1 << 4
} GearyImapDBFolderListFlags;

#define GEARY_IMAP_DB_FOLDER_TYPE_LIST_FLAGS (geary_imap_db_folder_list_flags_get_type ())
typedef struct _GearyImapEngineFullFolderSyncSyncFolderData GearyImapEngineFullFolderSyncSyncFolderData;
typedef struct _GearyImapEngineFullFolderSyncExpandVectorData GearyImapEngineFullFolderSyncExpandVectorData;
typedef struct _GearyImapEngineFullFolderSyncExpandToPreviousData GearyImapEngineFullFolderSyncExpandToPreviousData;
typedef struct _GearyImapEngineFullFolderSyncExpandCompleteVectorData GearyImapEngineFullFolderSyncExpandCompleteVectorData;
typedef struct _GearyImapEngineTruncateToEpochFolderSyncPrivate GearyImapEngineTruncateToEpochFolderSyncPrivate;
enum  {
	GEARY_IMAP_ENGINE_TRUNCATE_TO_EPOCH_FOLDER_SYNC_0_PROPERTY,
	GEARY_IMAP_ENGINE_TRUNCATE_TO_EPOCH_FOLDER_SYNC_NUM_PROPERTIES
};
static GParamSpec* geary_imap_engine_truncate_to_epoch_folder_sync_properties[GEARY_IMAP_ENGINE_TRUNCATE_TO_EPOCH_FOLDER_SYNC_NUM_PROPERTIES];
typedef struct _GearyImapEngineTruncateToEpochFolderSyncSyncFolderData GearyImapEngineTruncateToEpochFolderSyncSyncFolderData;
typedef struct _GearyImapEngineForegroundGarbageCollectionPrivate GearyImapEngineForegroundGarbageCollectionPrivate;
enum  {
	GEARY_IMAP_ENGINE_FOREGROUND_GARBAGE_COLLECTION_0_PROPERTY,
	GEARY_IMAP_ENGINE_FOREGROUND_GARBAGE_COLLECTION_NUM_PROPERTIES
};
static GParamSpec* geary_imap_engine_foreground_garbage_collection_properties[GEARY_IMAP_ENGINE_FOREGROUND_GARBAGE_COLLECTION_NUM_PROPERTIES];

#define GEARY_IMAP_DB_TYPE_ACCOUNT (geary_imap_db_account_get_type ())
#define GEARY_IMAP_DB_ACCOUNT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_DB_TYPE_ACCOUNT, GearyImapDBAccount))
#define GEARY_IMAP_DB_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_DB_TYPE_ACCOUNT, GearyImapDBAccountClass))
#define GEARY_IMAP_DB_IS_ACCOUNT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_DB_TYPE_ACCOUNT))
#define GEARY_IMAP_DB_IS_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_DB_TYPE_ACCOUNT))
#define GEARY_IMAP_DB_ACCOUNT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_DB_TYPE_ACCOUNT, GearyImapDBAccountClass))

typedef struct _GearyImapDBAccount GearyImapDBAccount;
typedef struct _GearyImapDBAccountClass GearyImapDBAccountClass;

#define GEARY_IMAP_DB_TYPE_DATABASE (geary_imap_db_database_get_type ())
#define GEARY_IMAP_DB_DATABASE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_DB_TYPE_DATABASE, GearyImapDBDatabase))
#define GEARY_IMAP_DB_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_DB_TYPE_DATABASE, GearyImapDBDatabaseClass))
#define GEARY_IMAP_DB_IS_DATABASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_DB_TYPE_DATABASE))
#define GEARY_IMAP_DB_IS_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_DB_TYPE_DATABASE))
#define GEARY_IMAP_DB_DATABASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_DB_TYPE_DATABASE, GearyImapDBDatabaseClass))

typedef struct _GearyImapDBDatabase GearyImapDBDatabase;
typedef struct _GearyImapDBDatabaseClass GearyImapDBDatabaseClass;
typedef enum  {
	GEARY_IMAP_DB_DATABASE_GARBAGE_COLLECTION_OPTIONS_NONE = 1 << 0,
	GEARY_IMAP_DB_DATABASE_GARBAGE_COLLECTION_OPTIONS_FORCE_REAP = 1 << 1,
	GEARY_IMAP_DB_DATABASE_GARBAGE_COLLECTION_OPTIONS_ALLOW_VACUUM = 1 << 2
} GearyImapDBDatabaseGarbageCollectionOptions;

#define GEARY_IMAP_DB_DATABASE_TYPE_GARBAGE_COLLECTION_OPTIONS (geary_imap_db_database_garbage_collection_options_get_type ())
typedef struct _GearyImapEngineForegroundGarbageCollectionExecuteData GearyImapEngineForegroundGarbageCollectionExecuteData;
typedef struct _GearyImapEngineIdleGarbageCollectionPrivate GearyImapEngineIdleGarbageCollectionPrivate;
enum  {
	GEARY_IMAP_ENGINE_IDLE_GARBAGE_COLLECTION_0_PROPERTY,
	GEARY_IMAP_ENGINE_IDLE_GARBAGE_COLLECTION_NUM_PROPERTIES
};
static GParamSpec* geary_imap_engine_idle_garbage_collection_properties[GEARY_IMAP_ENGINE_IDLE_GARBAGE_COLLECTION_NUM_PROPERTIES];
typedef struct _GearyImapEngineIdleGarbageCollectionExecuteData GearyImapEngineIdleGarbageCollectionExecuteData;

struct _GearyImapEngineAccountSynchronizer {
	GearyBaseObject parent_instance;
	GearyImapEngineAccountSynchronizerPrivate * priv;
};

struct _GearyImapEngineAccountSynchronizerClass {
	GearyBaseObjectClass parent_class;
	GearyLoggingState* (*to_logging_state) (GearyImapEngineAccountSynchronizer* self);
};

struct _GearyImapEngineAccountSynchronizerPrivate {
	GearyImapEngineGenericAccount* _account;
	GearyTimeoutManager* prefetch_timer;
	GDateTime* max_epoch;
};

struct _GearyImapEngineFolderSync {
	GearyImapEngineFolderOperation parent_instance;
	GearyImapEngineFolderSyncPrivate * priv;
};

struct _GearyImapEngineFolderSyncClass {
	GearyImapEngineFolderOperationClass parent_class;
	void (*sync_folder) (GearyImapEngineFolderSync* self, GDateTime* max_epoch, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*sync_folder_finish) (GearyImapEngineFolderSync* self, GAsyncResult* _res_, GError** error);
};

struct _GearyImapEngineFolderSyncPrivate {
	GDateTime* _sync_max_epoch;
	GearyFolderOpenFlags open_flags;
	GCancellable* closed_cancellable;
};

struct _GearyImapEngineFolderSyncExecuteData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineFolderSync* self;
	GCancellable* cancellable;
	GCancellable* _tmp0_;
	gboolean was_opened;
	GearyImapEngineMinimalFolder* minimal;
	GearyFolder* _tmp1_;
	GearyFolder* _tmp2_;
	GearyImapEngineMinimalFolder* _tmp3_;
	GearyImapEngineMinimalFolder* _tmp4_;
	GDateTime* actual_max_epoch;
	GearyAccount* _tmp5_;
	GearyAccount* _tmp6_;
	GearyAccountInformation* _tmp7_;
	GearyAccountInformation* _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	GDateTime* _tmp11_;
	GDateTime* _tmp12_;
	GearyAccount* _tmp13_;
	GearyAccount* _tmp14_;
	GearyAccountInformation* _tmp15_;
	GearyAccountInformation* _tmp16_;
	gint _tmp17_;
	gint _tmp18_;
	GDateTime* _tmp19_;
	GDateTime* _tmp20_;
	GDateTime* _tmp21_;
	GDateTime* _tmp22_;
	GError* err;
	GearyImapEngineMinimalFolder* _tmp23_;
	gchar* _tmp24_;
	gchar* _tmp25_;
	GError* _tmp26_;
	const gchar* _tmp27_;
	GError* _vala1_err;
	GearyAccount* _tmp28_;
	GearyAccount* _tmp29_;
	GearyAccount* _tmp30_;
	GearyAccount* _tmp31_;
	GearyAccountInformation* _tmp32_;
	GearyAccountInformation* _tmp33_;
	GearyAccount* _tmp34_;
	GearyAccount* _tmp35_;
	GearyAccountInformation* _tmp36_;
	GearyAccountInformation* _tmp37_;
	GearyServiceInformation* _tmp38_;
	GearyServiceInformation* _tmp39_;
	GError* _tmp40_;
	GearyServiceProblemReport* _tmp41_;
	GearyServiceProblemReport* _tmp42_;
	gboolean _tmp43_;
	GearyFolder* _tmp44_;
	GearyFolder* _tmp45_;
	GearyFolder* _tmp46_;
	GearyFolder* _tmp47_;
	GError* _vala2_err;
	GearyAccount* _tmp48_;
	GearyAccount* _tmp49_;
	gchar* _tmp50_;
	gchar* _tmp51_;
	GearyFolder* _tmp52_;
	GearyFolder* _tmp53_;
	gchar* _tmp54_;
	gchar* _tmp55_;
	GError* _tmp56_;
	const gchar* _tmp57_;
	GError* _inner_error0_;
};

struct _GearyImapEngineRefreshFolderSync {
	GearyImapEngineFolderSync parent_instance;
	GearyImapEngineRefreshFolderSyncPrivate * priv;
};

struct _GearyImapEngineRefreshFolderSyncClass {
	GearyImapEngineFolderSyncClass parent_class;
};

struct _GearyImapEngineRefreshFolderSyncSyncFolderData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineRefreshFolderSync* self;
	GDateTime* max_epoch;
	GCancellable* cancellable;
	GearyFolder* _tmp0_;
	GearyFolder* _tmp1_;
	GError* _inner_error0_;
};

struct _GearyImapEngineFullFolderSync {
	GearyImapEngineRefreshFolderSync parent_instance;
	GearyImapEngineFullFolderSyncPrivate * priv;
};

struct _GearyImapEngineFullFolderSyncClass {
	GearyImapEngineRefreshFolderSyncClass parent_class;
};

struct _GearyImapEngineFullFolderSyncSyncFolderData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineFullFolderSync* self;
	GDateTime* max_epoch;
	GCancellable* cancellable;
	GearyImapDBFolder* local_folder;
	GearyFolder* _tmp0_;
	GearyFolder* _tmp1_;
	GearyImapDBFolder* _tmp2_;
	GearyImapDBFolder* _tmp3_;
	GearyImapDBFolder* _tmp4_;
	GearyAccount* _tmp5_;
	GearyAccount* _tmp6_;
	GearyAccountInformation* _tmp7_;
	GearyAccountInformation* _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	GeeCollection* detached_ids;
	GearyImapDBFolder* _tmp11_;
	GeeCollection* _tmp12_;
	GeeCollection* _tmp13_;
	GearyAccount* _tmp14_;
	GearyAccount* _tmp15_;
	GearyFolder* _tmp16_;
	GearyFolder* _tmp17_;
	GeeCollection* _tmp18_;
	GearyFolder* _tmp19_;
	GearyFolder* _tmp20_;
	GeeCollection* _tmp21_;
	GearyImapEngineGenericAccount* imap_account;
	GearyAccount* _tmp22_;
	GearyAccount* _tmp23_;
	GearyImapEngineGenericAccount* _tmp24_;
	GearyImapEngineGenericAccount* _tmp25_;
	GearyImapEngineGenericAccount* _tmp26_;
	GearyImapEngineForegroundGarbageCollection* _tmp27_;
	GearyImapEngineForegroundGarbageCollection* _tmp28_;
	GeeList* list;
	GearyImapDBFolder* _tmp29_;
	GeeList* _tmp30_;
	GearyEmail* current_oldest;
	gboolean _tmp31_;
	GeeList* _tmp32_;
	GeeList* _tmp33_;
	gint _tmp34_;
	gint _tmp35_;
	GeeList* _tmp36_;
	gpointer _tmp37_;
	GDateTime* _tmp38_;
	GearyEmail* _tmp39_;
	GearyEmail* _tmp40_;
	GearyEmailProperties* _tmp41_;
	GearyEmailProperties* _tmp42_;
	GDateTime* _tmp43_;
	GDateTime* _tmp44_;
	GDateTime* oldest_date;
	GDateTime* _tmp45_;
	GDateTime* _tmp46_;
	GDateTime* _tmp47_;
	GDateTime* next_epoch;
	GDateTime* _tmp48_;
	GDateTime* _tmp49_;
	GDateTime* _tmp50_;
	gint local_count;
	GearyImapDBFolder* _tmp51_;
	GDateTime* _tmp52_;
	GDateTime* _tmp53_;
	GDateTime* _tmp54_;
	GDateTime* _tmp55_;
	GDateTime* _tmp56_;
	gchar* _tmp57_;
	gchar* _tmp58_;
	gboolean _tmp59_;
	GearyFolder* _tmp60_;
	GearyFolder* _tmp61_;
	GearyFolderProperties* _tmp62_;
	GearyFolderProperties* _tmp63_;
	gint _tmp64_;
	gint _tmp65_;
	GDateTime* _tmp66_;
	GDateTime* _tmp67_;
	GDateTime* _tmp68_;
	GDateTime* _tmp69_;
	GearyEmail* _tmp70_;
	GDateTime* _tmp71_;
	GearyEmail* _tmp72_;
	GearyEmail* _tmp73_;
	GearyEmail* _tmp74_;
	gboolean _tmp75_;
	GearyEmail* _tmp76_;
	GDateTime* _tmp77_;
	GearyEmail* _tmp78_;
	GDateTime* _tmp79_;
	GDateTime* _tmp80_;
	GDateTime* _tmp81_;
	GError* _inner_error0_;
};

struct _GearyImapEngineFullFolderSyncExpandVectorData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineFullFolderSync* self;
	GDateTime* next_epoch;
	GearyEmail* current_oldest;
	GCancellable* cancellable;
	GearyEmail* result;
	gchar* _tmp0_;
	gchar* _tmp1_;
	GearyEmailIdentifier* _tmp2_;
	GearyEmailIdentifier* _tmp3_;
	GearyEmailIdentifier* _tmp4_;
	GearyEmail* _tmp5_;
	GearyFolder* _tmp6_;
	GearyFolder* _tmp7_;
	GearyEmail* _tmp8_;
	GearyEmail* _tmp9_;
	GError* _inner_error0_;
};

struct _GearyImapEngineFullFolderSyncExpandToPreviousData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineFullFolderSync* self;
	GearyEmail* current_oldest;
	GCancellable* cancellable;
	GearyEmailIdentifier* _tmp0_;
	GearyEmailIdentifier* _tmp1_;
	GearyEmailIdentifier* _tmp2_;
	GearyEmailIdentifier* id;
	GearyEmailIdentifier* _tmp3_;
	const gchar* _tmp4_;
	GearyEmailIdentifier* _tmp5_;
	GearyFolder* _tmp6_;
	GearyFolder* _tmp7_;
	GearyEmailIdentifier* _tmp8_;
	GeeList* _tmp9_;
	GeeList* _tmp10_;
	GError* _inner_error0_;
};

struct _GearyImapEngineFullFolderSyncExpandCompleteVectorData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineFullFolderSync* self;
	GCancellable* cancellable;
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	GearyFolder* _tmp4_;
	GearyFolder* _tmp5_;
	GeeList* _tmp6_;
	GeeList* _tmp7_;
	GError* _inner_error0_;
};

struct _GearyImapEngineTruncateToEpochFolderSync {
	GearyImapEngineFolderSync parent_instance;
	GearyImapEngineTruncateToEpochFolderSyncPrivate * priv;
};

struct _GearyImapEngineTruncateToEpochFolderSyncClass {
	GearyImapEngineFolderSyncClass parent_class;
};

struct _GearyImapEngineTruncateToEpochFolderSyncPrivate {
	GearyImapEngineIdleGarbageCollection* post_idle_detach_op;
};

struct _GearyImapEngineTruncateToEpochFolderSyncSyncFolderData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineTruncateToEpochFolderSync* self;
	GDateTime* max_epoch;
	GCancellable* cancellable;
	GearyImapDBFolder* local_folder;
	GearyFolder* _tmp0_;
	GearyFolder* _tmp1_;
	GearyImapDBFolder* _tmp2_;
	GearyImapDBFolder* _tmp3_;
	GearyImapDBFolder* _tmp4_;
	GearyAccount* _tmp5_;
	GearyAccount* _tmp6_;
	GearyAccountInformation* _tmp7_;
	GearyAccountInformation* _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	GeeCollection* detached_ids;
	GearyImapDBFolder* _tmp11_;
	GeeCollection* _tmp12_;
	GeeCollection* _tmp13_;
	GearyAccount* _tmp14_;
	GearyAccount* _tmp15_;
	GearyFolder* _tmp16_;
	GearyFolder* _tmp17_;
	GeeCollection* _tmp18_;
	GearyFolder* _tmp19_;
	GearyFolder* _tmp20_;
	GeeCollection* _tmp21_;
	GearyImapEngineIdleGarbageCollection* _tmp22_;
	GError* _inner_error0_;
};

struct _GearyImapEngineForegroundGarbageCollection {
	GearyImapEngineAccountOperation parent_instance;
	GearyImapEngineForegroundGarbageCollectionPrivate * priv;
};

struct _GearyImapEngineForegroundGarbageCollectionClass {
	GearyImapEngineAccountOperationClass parent_class;
};

struct _GearyImapEngineForegroundGarbageCollectionExecuteData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineForegroundGarbageCollection* self;
	GCancellable* cancellable;
	GearyImapEngineGenericAccount* generic_account;
	GearyAccount* _tmp0_;
	GearyAccount* _tmp1_;
	GearyImapEngineGenericAccount* _tmp2_;
	GearyImapEngineGenericAccount* _tmp3_;
	GearyImapDBAccount* _tmp4_;
	GearyImapDBAccount* _tmp5_;
	GearyImapDBDatabase* _tmp6_;
	GearyImapDBDatabase* _tmp7_;
	GError* _inner_error0_;
};

struct _GearyImapEngineIdleGarbageCollection {
	GearyImapEngineAccountOperation parent_instance;
	GearyImapEngineIdleGarbageCollectionPrivate * priv;
};

struct _GearyImapEngineIdleGarbageCollectionClass {
	GearyImapEngineAccountOperationClass parent_class;
};

struct _GearyImapEngineIdleGarbageCollectionPrivate {
	GearyImapDBDatabaseGarbageCollectionOptions options;
};

struct _GearyImapEngineIdleGarbageCollectionExecuteData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyImapEngineIdleGarbageCollection* self;
	GCancellable* cancellable;
	GearyImapEngineGenericAccount* generic_account;
	GearyAccount* _tmp0_;
	GearyAccount* _tmp1_;
	GearyImapEngineGenericAccount* _tmp2_;
	GearyImapEngineGenericAccount* _tmp3_;
	GearyImapDBAccount* _tmp4_;
	GearyImapDBAccount* _tmp5_;
	GearyImapDBDatabase* _tmp6_;
	GearyImapDBDatabase* _tmp7_;
	GearyImapEngineGenericAccount* _tmp8_;
	GearyImapClientService* _tmp9_;
	GearyImapClientService* _tmp10_;
	GearyClientService* _tmp11_;
	GearyImapEngineGenericAccount* _tmp12_;
	GearySmtpClientService* _tmp13_;
	GearySmtpClientService* _tmp14_;
	GearyClientService* _tmp15_;
	GearyClientService** _tmp16_;
	GeeArrayList* _tmp17_;
	GeeArrayList* _tmp18_;
};

static gint GearyImapEngineAccountSynchronizer_private_offset;
static gpointer geary_imap_engine_account_synchronizer_parent_class = NULL;
static GearyLoggingSourceIface * geary_imap_engine_account_synchronizer_geary_logging_source_parent_iface = NULL;
static gint GearyImapEngineFolderSync_private_offset;
static gpointer geary_imap_engine_folder_sync_parent_class = NULL;
static gpointer geary_imap_engine_refresh_folder_sync_parent_class = NULL;
static gpointer geary_imap_engine_full_folder_sync_parent_class = NULL;
static gint GearyImapEngineTruncateToEpochFolderSync_private_offset;
static gpointer geary_imap_engine_truncate_to_epoch_folder_sync_parent_class = NULL;
static gpointer geary_imap_engine_foreground_garbage_collection_parent_class = NULL;
static gint GearyImapEngineIdleGarbageCollection_private_offset;
static gpointer geary_imap_engine_idle_garbage_collection_parent_class = NULL;

VALA_EXTERN GType geary_imap_engine_account_synchronizer_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_engine_generic_account_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GearyLoggingState* geary_imap_engine_account_synchronizer_to_logging_state (GearyImapEngineAccountSynchronizer* self);
static GType geary_imap_engine_account_synchronizer_reason_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static GearyImapEngineGenericAccount* geary_imap_engine_account_synchronizer_get_account (GearyImapEngineAccountSynchronizer* self);
static void geary_imap_engine_account_synchronizer_set_account (GearyImapEngineAccountSynchronizer* self,
                                                         GearyImapEngineGenericAccount* value);
VALA_EXTERN GearyImapEngineAccountSynchronizer* geary_imap_engine_account_synchronizer_new (GearyImapEngineGenericAccount* account);
VALA_EXTERN GearyImapEngineAccountSynchronizer* geary_imap_engine_account_synchronizer_construct (GType object_type,
                                                                                      GearyImapEngineGenericAccount* account);
static void geary_imap_engine_account_synchronizer_do_prefetch_changed (GearyImapEngineAccountSynchronizer* self);
static void _geary_imap_engine_account_synchronizer_do_prefetch_changed_geary_timeout_manager_timeout_func (GearyTimeoutManager* manager,
                                                                                                     gpointer self);
static void geary_imap_engine_account_synchronizer_on_account_prefetch_changed (GearyImapEngineAccountSynchronizer* self);
static void _geary_imap_engine_account_synchronizer_on_account_prefetch_changed_g_object_notify (GObject* _sender,
                                                                                          GParamSpec* pspec,
                                                                                          gpointer self);
static void geary_imap_engine_account_synchronizer_on_folders_discovered (GearyImapEngineAccountSynchronizer* self,
                                                                   GeeCollection* available,
                                                                   GeeCollection* unavailable);
static void _geary_imap_engine_account_synchronizer_on_folders_discovered_geary_account_folders_available_unavailable (GearyAccount* _sender,
                                                                                                                GeeBidirSortedSet* available,
                                                                                                                GeeBidirSortedSet* unavailable,
                                                                                                                gpointer self);
static GearyLoggingState* geary_imap_engine_account_synchronizer_real_to_logging_state (GearyImapEngineAccountSynchronizer* self);
VALA_EXTERN void geary_imap_engine_account_synchronizer_folders_discovered (GearyImapEngineAccountSynchronizer* self,
                                                                GeeCollection* available);
VALA_EXTERN GearyImapClientService* geary_imap_engine_generic_account_get_imap (GearyImapEngineGenericAccount* self);
VALA_EXTERN GType geary_imap_engine_idle_garbage_collection_get_type (void) G_GNUC_CONST ;
static void geary_imap_engine_account_synchronizer_send_all (GearyImapEngineAccountSynchronizer* self,
                                                      GeeCollection* folders,
                                                      GearyImapEngineAccountSynchronizerReason reason,
                                                      GearyImapEngineIdleGarbageCollection* post_idle_detach_op);
VALA_EXTERN void geary_imap_engine_account_synchronizer_folders_contents_altered (GearyImapEngineAccountSynchronizer* self,
                                                                      GeeCollection* altered);
VALA_EXTERN void geary_imap_engine_account_synchronizer_cleanup_storage (GearyImapEngineAccountSynchronizer* self);
VALA_EXTERN GearyImapEngineIdleGarbageCollection* geary_imap_engine_idle_garbage_collection_new (GearyImapEngineGenericAccount* account);
VALA_EXTERN GearyImapEngineIdleGarbageCollection* geary_imap_engine_idle_garbage_collection_construct (GType object_type,
                                                                                           GearyImapEngineGenericAccount* account);
VALA_EXTERN void geary_imap_engine_generic_account_queue_operation (GearyImapEngineGenericAccount* self,
                                                        GearyImapEngineAccountOperation* op,
                                                        GError** error);
VALA_EXTERN GType geary_imap_engine_minimal_folder_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GearyImapEngineRefreshFolderSync* geary_imap_engine_refresh_folder_sync_new (GearyImapEngineGenericAccount* account,
                                                                             GearyImapEngineMinimalFolder* folder,
                                                                             GDateTime* sync_max_epoch);
VALA_EXTERN GearyImapEngineRefreshFolderSync* geary_imap_engine_refresh_folder_sync_construct (GType object_type,
                                                                                   GearyImapEngineGenericAccount* account,
                                                                                   GearyImapEngineMinimalFolder* folder,
                                                                                   GDateTime* sync_max_epoch);
VALA_EXTERN GType geary_imap_engine_folder_sync_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_engine_refresh_folder_sync_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GearyImapEngineFullFolderSync* geary_imap_engine_full_folder_sync_new (GearyImapEngineGenericAccount* account,
                                                                       GearyImapEngineMinimalFolder* folder,
                                                                       GDateTime* sync_max_epoch);
VALA_EXTERN GearyImapEngineFullFolderSync* geary_imap_engine_full_folder_sync_construct (GType object_type,
                                                                             GearyImapEngineGenericAccount* account,
                                                                             GearyImapEngineMinimalFolder* folder,
                                                                             GDateTime* sync_max_epoch);
VALA_EXTERN GType geary_imap_engine_full_folder_sync_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GearyImapEngineTruncateToEpochFolderSync* geary_imap_engine_truncate_to_epoch_folder_sync_new (GearyImapEngineGenericAccount* account,
                                                                                               GearyImapEngineMinimalFolder* folder,
                                                                                               GDateTime* sync_max_epoch,
                                                                                               GearyImapEngineIdleGarbageCollection* post_idle_detach_op);
VALA_EXTERN GearyImapEngineTruncateToEpochFolderSync* geary_imap_engine_truncate_to_epoch_folder_sync_construct (GType object_type,
                                                                                                     GearyImapEngineGenericAccount* account,
                                                                                                     GearyImapEngineMinimalFolder* folder,
                                                                                                     GDateTime* sync_max_epoch,
                                                                                                     GearyImapEngineIdleGarbageCollection* post_idle_detach_op);
VALA_EXTERN GType geary_imap_engine_truncate_to_epoch_folder_sync_get_type (void) G_GNUC_CONST ;
static void geary_imap_engine_account_synchronizer_finalize (GObject * obj);
static GType geary_imap_engine_account_synchronizer_get_type_once (void);
static void _vala_geary_imap_engine_account_synchronizer_get_property (GObject * object,
                                                                guint property_id,
                                                                GValue * value,
                                                                GParamSpec * pspec);
static void _vala_geary_imap_engine_account_synchronizer_set_property (GObject * object,
                                                                guint property_id,
                                                                const GValue * value,
                                                                GParamSpec * pspec);
static void geary_imap_engine_folder_sync_on_folder_close (GearyImapEngineFolderSync* self);
static void _geary_imap_engine_folder_sync_on_folder_close_geary_folder_closed (GearyFolder* _sender,
                                                                         GearyFolderCloseReason reason,
                                                                         gpointer self);
VALA_EXTERN GDateTime* geary_imap_engine_folder_sync_get_sync_max_epoch (GearyImapEngineFolderSync* self);
static void geary_imap_engine_folder_sync_set_sync_max_epoch (GearyImapEngineFolderSync* self,
                                                       GDateTime* value);
VALA_EXTERN GearyImapEngineFolderSync* geary_imap_engine_folder_sync_construct (GType object_type,
                                                                    GearyImapEngineGenericAccount* account,
                                                                    GearyImapEngineMinimalFolder* folder,
                                                                    GDateTime* sync_max_epoch,
                                                                    GearyFolderOpenFlags open_flags);
static void geary_imap_engine_folder_sync_real_execute_data_free (gpointer _data);
static void geary_imap_engine_folder_sync_real_execute (GearyImapEngineAccountOperation* base,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
static gboolean geary_imap_engine_folder_sync_real_execute_co (GearyImapEngineFolderSyncExecuteData* _data_);
static void geary_imap_engine_folder_sync_execute_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_);
VALA_EXTERN void geary_imap_engine_folder_sync_sync_folder (GearyImapEngineFolderSync* self,
                                                GDateTime* max_epoch,
                                                GCancellable* cancellable,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_);
VALA_EXTERN void geary_imap_engine_folder_sync_sync_folder_finish (GearyImapEngineFolderSync* self,
                                                       GAsyncResult* _res_,
                                                       GError** error);
static void geary_imap_engine_folder_sync_finalize (GObject * obj);
static GType geary_imap_engine_folder_sync_get_type_once (void);
static void _vala_geary_imap_engine_folder_sync_get_property (GObject * object,
                                                       guint property_id,
                                                       GValue * value,
                                                       GParamSpec * pspec);
static void _vala_geary_imap_engine_folder_sync_set_property (GObject * object,
                                                       guint property_id,
                                                       const GValue * value,
                                                       GParamSpec * pspec);
static void geary_imap_engine_refresh_folder_sync_real_sync_folder_data_free (gpointer _data);
static void geary_imap_engine_refresh_folder_sync_real_sync_folder (GearyImapEngineFolderSync* base,
                                                             GDateTime* max_epoch,
                                                             GCancellable* cancellable,
                                                             GAsyncReadyCallback _callback_,
                                                             gpointer _user_data_);
static gboolean geary_imap_engine_refresh_folder_sync_real_sync_folder_co (GearyImapEngineRefreshFolderSyncSyncFolderData* _data_);
static void geary_imap_engine_refresh_folder_sync_sync_folder_ready (GObject* source_object,
                                                              GAsyncResult* _res_,
                                                              gpointer _user_data_);
static GType geary_imap_engine_refresh_folder_sync_get_type_once (void);
static void geary_imap_engine_full_folder_sync_real_sync_folder_data_free (gpointer _data);
static void geary_imap_engine_full_folder_sync_real_sync_folder (GearyImapEngineFolderSync* base,
                                                          GDateTime* max_epoch,
                                                          GCancellable* cancellable,
                                                          GAsyncReadyCallback _callback_,
                                                          gpointer _user_data_);
static gboolean geary_imap_engine_full_folder_sync_real_sync_folder_co (GearyImapEngineFullFolderSyncSyncFolderData* _data_);
VALA_EXTERN GType geary_imap_db_folder_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GearyImapDBFolder* geary_imap_engine_minimal_folder_get_local_folder (GearyImapEngineMinimalFolder* self);
VALA_EXTERN void geary_imap_db_folder_detach_emails_before_timestamp (GearyImapDBFolder* self,
                                                          GDateTime* cutoff,
                                                          GCancellable* cancellable,
                                                          GAsyncReadyCallback _callback_,
                                                          gpointer _user_data_);
VALA_EXTERN GeeCollection* geary_imap_db_folder_detach_emails_before_timestamp_finish (GearyImapDBFolder* self,
                                                                           GAsyncResult* _res_,
                                                                           GError** error);
static void geary_imap_engine_full_folder_sync_sync_folder_ready (GObject* source_object,
                                                           GAsyncResult* _res_,
                                                           gpointer _user_data_);
VALA_EXTERN GearyImapEngineForegroundGarbageCollection* geary_imap_engine_foreground_garbage_collection_new (GearyImapEngineGenericAccount* account);
VALA_EXTERN GearyImapEngineForegroundGarbageCollection* geary_imap_engine_foreground_garbage_collection_construct (GType object_type,
                                                                                                       GearyImapEngineGenericAccount* account);
VALA_EXTERN GType geary_imap_engine_foreground_garbage_collection_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_db_email_identifier_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_imap_db_folder_list_flags_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void geary_imap_db_folder_list_email_by_id_async (GearyImapDBFolder* self,
                                                  GearyImapDBEmailIdentifier* initial_id,
                                                  gint count,
                                                  GearyEmailField required_fields,
                                                  GearyImapDBFolderListFlags flags,
                                                  GCancellable* cancellable,
                                                  GAsyncReadyCallback _callback_,
                                                  gpointer _user_data_);
VALA_EXTERN GeeList* geary_imap_db_folder_list_email_by_id_finish (GearyImapDBFolder* self,
                                                       GAsyncResult* _res_,
                                                       GError** error);
VALA_EXTERN void geary_imap_db_folder_get_email_count_async (GearyImapDBFolder* self,
                                                 GearyImapDBFolderListFlags flags,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
VALA_EXTERN gint geary_imap_db_folder_get_email_count_finish (GearyImapDBFolder* self,
                                                  GAsyncResult* _res_,
                                                  GError** error);
static void geary_imap_engine_full_folder_sync_expand_vector (GearyImapEngineFullFolderSync* self,
                                                       GDateTime* next_epoch,
                                                       GearyEmail* current_oldest,
                                                       GCancellable* cancellable,
                                                       GAsyncReadyCallback _callback_,
                                                       gpointer _user_data_);
static GearyEmail* geary_imap_engine_full_folder_sync_expand_vector_finish (GearyImapEngineFullFolderSync* self,
                                                                     GAsyncResult* _res_,
                                                                     GError** error);
static void geary_imap_engine_full_folder_sync_expand_to_previous (GearyImapEngineFullFolderSync* self,
                                                            GearyEmail* current_oldest,
                                                            GCancellable* cancellable,
                                                            GAsyncReadyCallback _callback_,
                                                            gpointer _user_data_);
static void geary_imap_engine_full_folder_sync_expand_to_previous_finish (GearyImapEngineFullFolderSync* self,
                                                                   GAsyncResult* _res_,
                                                                   GError** error);
static void geary_imap_engine_full_folder_sync_expand_complete_vector (GearyImapEngineFullFolderSync* self,
                                                                GCancellable* cancellable,
                                                                GAsyncReadyCallback _callback_,
                                                                gpointer _user_data_);
static void geary_imap_engine_full_folder_sync_expand_complete_vector_finish (GearyImapEngineFullFolderSync* self,
                                                                       GAsyncResult* _res_,
                                                                       GError** error);
static void geary_imap_engine_full_folder_sync_expand_vector_data_free (gpointer _data);
static gboolean geary_imap_engine_full_folder_sync_expand_vector_co (GearyImapEngineFullFolderSyncExpandVectorData* _data_);
VALA_EXTERN void geary_imap_engine_minimal_folder_find_earliest_email_async (GearyImapEngineMinimalFolder* self,
                                                                 GDateTime* datetime,
                                                                 GearyEmailIdentifier* before_id,
                                                                 GCancellable* cancellable,
                                                                 GAsyncReadyCallback _callback_,
                                                                 gpointer _user_data_);
VALA_EXTERN GearyEmail* geary_imap_engine_minimal_folder_find_earliest_email_finish (GearyImapEngineMinimalFolder* self,
                                                                         GAsyncResult* _res_,
                                                                         GError** error);
static void geary_imap_engine_full_folder_sync_expand_vector_ready (GObject* source_object,
                                                             GAsyncResult* _res_,
                                                             gpointer _user_data_);
static void geary_imap_engine_full_folder_sync_expand_to_previous_data_free (gpointer _data);
static gboolean geary_imap_engine_full_folder_sync_expand_to_previous_co (GearyImapEngineFullFolderSyncExpandToPreviousData* _data_);
static void geary_imap_engine_full_folder_sync_expand_to_previous_ready (GObject* source_object,
                                                                  GAsyncResult* _res_,
                                                                  gpointer _user_data_);
static void geary_imap_engine_full_folder_sync_expand_complete_vector_data_free (gpointer _data);
static gboolean geary_imap_engine_full_folder_sync_expand_complete_vector_co (GearyImapEngineFullFolderSyncExpandCompleteVectorData* _data_);
static void geary_imap_engine_full_folder_sync_expand_complete_vector_ready (GObject* source_object,
                                                                      GAsyncResult* _res_,
                                                                      gpointer _user_data_);
static GType geary_imap_engine_full_folder_sync_get_type_once (void);
static void geary_imap_engine_truncate_to_epoch_folder_sync_real_sync_folder_data_free (gpointer _data);
static void geary_imap_engine_truncate_to_epoch_folder_sync_real_sync_folder (GearyImapEngineFolderSync* base,
                                                                       GDateTime* max_epoch,
                                                                       GCancellable* cancellable,
                                                                       GAsyncReadyCallback _callback_,
                                                                       gpointer _user_data_);
static gboolean geary_imap_engine_truncate_to_epoch_folder_sync_real_sync_folder_co (GearyImapEngineTruncateToEpochFolderSyncSyncFolderData* _data_);
static void geary_imap_engine_truncate_to_epoch_folder_sync_sync_folder_ready (GObject* source_object,
                                                                        GAsyncResult* _res_,
                                                                        gpointer _user_data_);
VALA_EXTERN void geary_imap_engine_idle_garbage_collection_messages_detached (GearyImapEngineIdleGarbageCollection* self);
static void geary_imap_engine_truncate_to_epoch_folder_sync_finalize (GObject * obj);
static GType geary_imap_engine_truncate_to_epoch_folder_sync_get_type_once (void);
static void geary_imap_engine_foreground_garbage_collection_real_execute_data_free (gpointer _data);
static void geary_imap_engine_foreground_garbage_collection_real_execute (GearyImapEngineAccountOperation* base,
                                                                   GCancellable* cancellable,
                                                                   GAsyncReadyCallback _callback_,
                                                                   gpointer _user_data_);
static gboolean geary_imap_engine_foreground_garbage_collection_real_execute_co (GearyImapEngineForegroundGarbageCollectionExecuteData* _data_);
VALA_EXTERN GType geary_imap_db_account_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GearyImapDBAccount* geary_imap_engine_generic_account_get_local (GearyImapEngineGenericAccount* self);
VALA_EXTERN GType geary_imap_db_database_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GearyImapDBDatabase* geary_imap_db_account_get_db (GearyImapDBAccount* self);
VALA_EXTERN GType geary_imap_db_database_garbage_collection_options_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void geary_imap_db_database_run_gc (GearyImapDBDatabase* self,
                                    GearyImapDBDatabaseGarbageCollectionOptions options,
                                    GeeCollection* to_pause,
                                    GCancellable* cancellable,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_);
VALA_EXTERN void geary_imap_db_database_run_gc_finish (GearyImapDBDatabase* self,
                                           GAsyncResult* _res_,
                                           GError** error);
static void geary_imap_engine_foreground_garbage_collection_execute_ready (GObject* source_object,
                                                                    GAsyncResult* _res_,
                                                                    gpointer _user_data_);
static gboolean geary_imap_engine_foreground_garbage_collection_real_equal_to (GearyImapEngineAccountOperation* base,
                                                                        GearyImapEngineAccountOperation* op);
static GType geary_imap_engine_foreground_garbage_collection_get_type_once (void);
static void geary_imap_engine_idle_garbage_collection_real_execute_data_free (gpointer _data);
static void geary_imap_engine_idle_garbage_collection_real_execute (GearyImapEngineAccountOperation* base,
                                                             GCancellable* cancellable,
                                                             GAsyncReadyCallback _callback_,
                                                             gpointer _user_data_);
static gboolean geary_imap_engine_idle_garbage_collection_real_execute_co (GearyImapEngineIdleGarbageCollectionExecuteData* _data_);
VALA_EXTERN GearySmtpClientService* geary_imap_engine_generic_account_get_smtp (GearyImapEngineGenericAccount* self);
static void geary_imap_engine_idle_garbage_collection_finalize (GObject * obj);
static GType geary_imap_engine_idle_garbage_collection_get_type_once (void);

static inline gpointer
geary_imap_engine_account_synchronizer_get_instance_private (GearyImapEngineAccountSynchronizer* self)
{
	return G_STRUCT_MEMBER_P (self, GearyImapEngineAccountSynchronizer_private_offset);
}

 G_GNUC_NO_INLINE static GType
geary_imap_engine_account_synchronizer_reason_get_type_once (void)
{
	static const GEnumValue values[] = {{GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_REASON_REFRESH_CONTENTS, "GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_REASON_REFRESH_CONTENTS", "refresh-contents"}, {GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_REASON_FULL_SYNC, "GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_REASON_FULL_SYNC", "full-sync"}, {GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_REASON_TRUNCATE_TO_EPOCH, "GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_REASON_TRUNCATE_TO_EPOCH", "truncate-to-epoch"}, {0, NULL, NULL}};
	GType geary_imap_engine_account_synchronizer_reason_type_id;
	geary_imap_engine_account_synchronizer_reason_type_id = g_enum_register_static ("GearyImapEngineAccountSynchronizerReason", values);
	return geary_imap_engine_account_synchronizer_reason_type_id;
}

static GType
geary_imap_engine_account_synchronizer_reason_get_type (void)
{
	static gsize geary_imap_engine_account_synchronizer_reason_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_engine_account_synchronizer_reason_type_id__once)) {
		GType geary_imap_engine_account_synchronizer_reason_type_id;
		geary_imap_engine_account_synchronizer_reason_type_id = geary_imap_engine_account_synchronizer_reason_get_type_once ();
		g_once_init_leave (&geary_imap_engine_account_synchronizer_reason_type_id__once, geary_imap_engine_account_synchronizer_reason_type_id);
	}
	return geary_imap_engine_account_synchronizer_reason_type_id__once;
}

static GearyImapEngineGenericAccount*
geary_imap_engine_account_synchronizer_get_account (GearyImapEngineAccountSynchronizer* self)
{
	GearyImapEngineGenericAccount* result;
	GearyImapEngineGenericAccount* _tmp0_;
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_ACCOUNT_SYNCHRONIZER (self), NULL);
	_tmp0_ = self->priv->_account;
	result = _tmp0_;
	return result;
}

static void
geary_imap_engine_account_synchronizer_set_account (GearyImapEngineAccountSynchronizer* self,
                                                    GearyImapEngineGenericAccount* value)
{
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_ACCOUNT_SYNCHRONIZER (self));
	self->priv->_account = value;
}

static void
_geary_imap_engine_account_synchronizer_do_prefetch_changed_geary_timeout_manager_timeout_func (GearyTimeoutManager* manager,
                                                                                                gpointer self)
{
	geary_imap_engine_account_synchronizer_do_prefetch_changed ((GearyImapEngineAccountSynchronizer*) self);
}

static void
_geary_imap_engine_account_synchronizer_on_account_prefetch_changed_g_object_notify (GObject* _sender,
                                                                                     GParamSpec* pspec,
                                                                                     gpointer self)
{
	geary_imap_engine_account_synchronizer_on_account_prefetch_changed ((GearyImapEngineAccountSynchronizer*) self);
}

static void
_geary_imap_engine_account_synchronizer_on_folders_discovered_geary_account_folders_available_unavailable (GearyAccount* _sender,
                                                                                                           GeeBidirSortedSet* available,
                                                                                                           GeeBidirSortedSet* unavailable,
                                                                                                           gpointer self)
{
	geary_imap_engine_account_synchronizer_on_folders_discovered ((GearyImapEngineAccountSynchronizer*) self, available, unavailable);
}

GearyImapEngineAccountSynchronizer*
geary_imap_engine_account_synchronizer_construct (GType object_type,
                                                  GearyImapEngineGenericAccount* account)
{
	GearyImapEngineAccountSynchronizer * self = NULL;
	GearyTimeoutManager* _tmp0_;
	GearyImapEngineGenericAccount* _tmp1_;
	GearyAccountInformation* _tmp2_;
	GearyAccountInformation* _tmp3_;
	GearyImapEngineGenericAccount* _tmp4_;
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_GENERIC_ACCOUNT (account), NULL);
	self = (GearyImapEngineAccountSynchronizer*) geary_base_object_construct (object_type);
	geary_imap_engine_account_synchronizer_set_account (self, account);
	_tmp0_ = geary_timeout_manager_new_seconds ((guint) 10, _geary_imap_engine_account_synchronizer_do_prefetch_changed_geary_timeout_manager_timeout_func, self);
	_g_object_unref0 (self->priv->prefetch_timer);
	self->priv->prefetch_timer = _tmp0_;
	_tmp1_ = self->priv->_account;
	_tmp2_ = geary_account_get_information (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEARY_TYPE_ACCOUNT, GearyAccount));
	_tmp3_ = _tmp2_;
	g_signal_connect_object (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, G_TYPE_OBJECT, GObject), "notify::prefetch-period-days", (GCallback) _geary_imap_engine_account_synchronizer_on_account_prefetch_changed_g_object_notify, self, 0);
	_tmp4_ = self->priv->_account;
	g_signal_connect_object (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, GEARY_TYPE_ACCOUNT, GearyAccount), "folders-available-unavailable", (GCallback) _geary_imap_engine_account_synchronizer_on_folders_discovered_geary_account_folders_available_unavailable, self, 0);
	return self;
}

GearyImapEngineAccountSynchronizer*
geary_imap_engine_account_synchronizer_new (GearyImapEngineGenericAccount* account)
{
	return geary_imap_engine_account_synchronizer_construct (GEARY_IMAP_ENGINE_TYPE_ACCOUNT_SYNCHRONIZER, account);
}

static GearyLoggingSource*
geary_imap_engine_account_synchronizer_real_get_logging_parent (GearyLoggingSource* base)
{
	GearyLoggingSource* result;
	GearyImapEngineAccountSynchronizer* self;
	GearyImapEngineGenericAccount* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_SYNCHRONIZER, GearyImapEngineAccountSynchronizer);
	_tmp0_ = self->priv->_account;
	result = G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource);
	return result;
}

/** {@inheritDoc} */
static gchar*
g_date_time_to_string (GDateTime* self)
{
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_date_time_format (self, "%FT%H:%M:%S%z");
	result = _tmp0_;
	return result;
}

static GearyLoggingState*
geary_imap_engine_account_synchronizer_real_to_logging_state (GearyImapEngineAccountSynchronizer* self)
{
	GearyImapEngineGenericAccount* _tmp0_;
	GearyAccountInformation* _tmp1_;
	GearyAccountInformation* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	GDateTime* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	GearyLoggingState* _tmp8_;
	GearyLoggingState* _tmp9_;
	GearyLoggingState* result;
	_tmp0_ = self->priv->_account;
	_tmp1_ = geary_account_get_information (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GEARY_TYPE_ACCOUNT, GearyAccount));
	_tmp2_ = _tmp1_;
	_tmp3_ = geary_account_information_get_id (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = self->priv->max_epoch;
	_tmp6_ = g_date_time_to_string (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = geary_logging_state_new (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "%s, %s", _tmp4_, _tmp7_);
	_tmp9_ = _tmp8_;
	_g_free0 (_tmp7_);
	result = _tmp9_;
	return result;
}

GearyLoggingState*
geary_imap_engine_account_synchronizer_to_logging_state (GearyImapEngineAccountSynchronizer* self)
{
	GearyImapEngineAccountSynchronizerClass* _klass_;
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_ACCOUNT_SYNCHRONIZER (self), NULL);
	_klass_ = GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_GET_CLASS (self);
	if (_klass_->to_logging_state) {
		return _klass_->to_logging_state (self);
	}
	return NULL;
}

void
geary_imap_engine_account_synchronizer_folders_discovered (GearyImapEngineAccountSynchronizer* self,
                                                           GeeCollection* available)
{
	GearyImapEngineGenericAccount* _tmp0_;
	GearyImapClientService* _tmp1_;
	GearyImapClientService* _tmp2_;
	GearyClientServiceStatus _tmp3_;
	GearyClientServiceStatus _tmp4_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_ACCOUNT_SYNCHRONIZER (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (available, GEE_TYPE_COLLECTION));
	_tmp0_ = self->priv->_account;
	_tmp1_ = geary_imap_engine_generic_account_get_imap (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = geary_client_service_get_current_status (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, GEARY_TYPE_CLIENT_SERVICE, GearyClientService));
	_tmp4_ = _tmp3_;
	if (_tmp4_ == GEARY_CLIENT_SERVICE_STATUS_CONNECTED) {
		geary_imap_engine_account_synchronizer_send_all (self, available, GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_REASON_FULL_SYNC, NULL);
	}
}

void
geary_imap_engine_account_synchronizer_folders_contents_altered (GearyImapEngineAccountSynchronizer* self,
                                                                 GeeCollection* altered)
{
	GearyImapEngineGenericAccount* _tmp0_;
	GearyImapClientService* _tmp1_;
	GearyImapClientService* _tmp2_;
	GearyClientServiceStatus _tmp3_;
	GearyClientServiceStatus _tmp4_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_ACCOUNT_SYNCHRONIZER (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (altered, GEE_TYPE_COLLECTION));
	_tmp0_ = self->priv->_account;
	_tmp1_ = geary_imap_engine_generic_account_get_imap (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = geary_client_service_get_current_status (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, GEARY_TYPE_CLIENT_SERVICE, GearyClientService));
	_tmp4_ = _tmp3_;
	if (_tmp4_ == GEARY_CLIENT_SERVICE_STATUS_CONNECTED) {
		geary_imap_engine_account_synchronizer_send_all (self, altered, GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_REASON_REFRESH_CONTENTS, NULL);
	}
}

void
geary_imap_engine_account_synchronizer_cleanup_storage (GearyImapEngineAccountSynchronizer* self)
{
	GearyImapEngineIdleGarbageCollection* op = NULL;
	GearyImapEngineGenericAccount* _tmp0_;
	GearyImapEngineIdleGarbageCollection* _tmp1_;
	GearyImapEngineGenericAccount* _tmp2_;
	GeeCollection* _tmp3_;
	GeeCollection* _tmp4_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_ACCOUNT_SYNCHRONIZER (self));
	_tmp0_ = self->priv->_account;
	_tmp1_ = geary_imap_engine_idle_garbage_collection_new (_tmp0_);
	op = _tmp1_;
	_tmp2_ = self->priv->_account;
	_tmp3_ = geary_account_list_folders (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, GEARY_TYPE_ACCOUNT, GearyAccount));
	_tmp4_ = _tmp3_;
	geary_imap_engine_account_synchronizer_send_all (self, _tmp4_, GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_REASON_TRUNCATE_TO_EPOCH, op);
	_g_object_unref0 (_tmp4_);
	{
		GearyImapEngineGenericAccount* _tmp5_;
		_tmp5_ = self->priv->_account;
		geary_imap_engine_generic_account_queue_operation (_tmp5_, G_TYPE_CHECK_INSTANCE_CAST (op, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, GearyImapEngineAccountOperation), &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* err = NULL;
		GError* _tmp6_;
		const gchar* _tmp7_;
		err = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp6_ = err;
		_tmp7_ = _tmp6_->message;
		geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Failed to queue sync operation: %s", _tmp7_);
		_g_error_free0 (err);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (op);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	_g_object_unref0 (op);
}

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

static void
geary_imap_engine_account_synchronizer_send_all (GearyImapEngineAccountSynchronizer* self,
                                                 GeeCollection* folders,
                                                 GearyImapEngineAccountSynchronizerReason reason,
                                                 GearyImapEngineIdleGarbageCollection* post_idle_detach_op)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_ACCOUNT_SYNCHRONIZER (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (folders, GEE_TYPE_COLLECTION));
	g_return_if_fail ((post_idle_detach_op == NULL) || GEARY_IMAP_ENGINE_IS_IDLE_GARBAGE_COLLECTION (post_idle_detach_op));
	{
		GeeIterator* _folder_it = NULL;
		GeeIterator* _tmp0_;
		_tmp0_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (folders, GEE_TYPE_ITERABLE, GeeIterable));
		_folder_it = _tmp0_;
		while (TRUE) {
			GeeIterator* _tmp1_;
			GearyFolder* folder = NULL;
			GeeIterator* _tmp2_;
			gpointer _tmp3_;
			GearyImapEngineMinimalFolder* imap_folder = NULL;
			GearyFolder* _tmp4_;
			GearyImapEngineMinimalFolder* _tmp5_;
			gboolean _tmp6_ = FALSE;
			gboolean _tmp7_ = FALSE;
			gboolean _tmp8_ = FALSE;
			GearyImapEngineMinimalFolder* _tmp9_;
			_tmp1_ = _folder_it;
			if (!gee_iterator_next (_tmp1_)) {
				break;
			}
			_tmp2_ = _folder_it;
			_tmp3_ = gee_iterator_get (_tmp2_);
			folder = (GearyFolder*) _tmp3_;
			_tmp4_ = folder;
			_tmp5_ = _g_object_ref0 (GEARY_IMAP_ENGINE_IS_MINIMAL_FOLDER (_tmp4_) ? ((GearyImapEngineMinimalFolder*) _tmp4_) : NULL);
			imap_folder = _tmp5_;
			_tmp9_ = imap_folder;
			if (_tmp9_ != NULL) {
				GearyFolder* _tmp10_;
				GearyFolderProperties* _tmp11_;
				GearyFolderProperties* _tmp12_;
				GearyTrillian _tmp13_;
				GearyTrillian _tmp14_;
				_tmp10_ = folder;
				_tmp11_ = geary_folder_get_properties (_tmp10_);
				_tmp12_ = _tmp11_;
				_tmp13_ = geary_folder_properties_get_is_openable (_tmp12_);
				_tmp14_ = _tmp13_;
				_tmp8_ = geary_trillian_is_possible (_tmp14_);
			} else {
				_tmp8_ = FALSE;
			}
			if (_tmp8_) {
				GearyFolder* _tmp15_;
				GearyFolderProperties* _tmp16_;
				GearyFolderProperties* _tmp17_;
				gboolean _tmp18_;
				gboolean _tmp19_;
				_tmp15_ = folder;
				_tmp16_ = geary_folder_get_properties (_tmp15_);
				_tmp17_ = _tmp16_;
				_tmp18_ = geary_folder_properties_get_is_local_only (_tmp17_);
				_tmp19_ = _tmp18_;
				_tmp7_ = !_tmp19_;
			} else {
				_tmp7_ = FALSE;
			}
			if (_tmp7_) {
				GearyFolder* _tmp20_;
				GearyFolderProperties* _tmp21_;
				GearyFolderProperties* _tmp22_;
				gboolean _tmp23_;
				gboolean _tmp24_;
				_tmp20_ = folder;
				_tmp21_ = geary_folder_get_properties (_tmp20_);
				_tmp22_ = _tmp21_;
				_tmp23_ = geary_folder_properties_get_is_virtual (_tmp22_);
				_tmp24_ = _tmp23_;
				_tmp6_ = !_tmp24_;
			} else {
				_tmp6_ = FALSE;
			}
			if (_tmp6_) {
				GearyImapEngineAccountOperation* op = NULL;
				op = NULL;
				switch (reason) {
					case GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_REASON_REFRESH_CONTENTS:
					{
						GearyImapEngineGenericAccount* _tmp25_;
						GearyImapEngineMinimalFolder* _tmp26_;
						GDateTime* _tmp27_;
						GearyImapEngineRefreshFolderSync* _tmp28_;
						_tmp25_ = self->priv->_account;
						_tmp26_ = imap_folder;
						_tmp27_ = self->priv->max_epoch;
						_tmp28_ = geary_imap_engine_refresh_folder_sync_new (_tmp25_, _tmp26_, _tmp27_);
						_g_object_unref0 (op);
						op = G_TYPE_CHECK_INSTANCE_CAST (_tmp28_, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, GearyImapEngineAccountOperation);
						break;
					}
					case GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_REASON_FULL_SYNC:
					{
						GearyImapEngineGenericAccount* _tmp29_;
						GearyImapEngineMinimalFolder* _tmp30_;
						GDateTime* _tmp31_;
						GearyImapEngineFullFolderSync* _tmp32_;
						_tmp29_ = self->priv->_account;
						_tmp30_ = imap_folder;
						_tmp31_ = self->priv->max_epoch;
						_tmp32_ = geary_imap_engine_full_folder_sync_new (_tmp29_, _tmp30_, _tmp31_);
						_g_object_unref0 (op);
						op = G_TYPE_CHECK_INSTANCE_CAST (_tmp32_, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, GearyImapEngineAccountOperation);
						break;
					}
					case GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_REASON_TRUNCATE_TO_EPOCH:
					{
						GearyImapEngineGenericAccount* _tmp33_;
						GearyImapEngineMinimalFolder* _tmp34_;
						GDateTime* _tmp35_;
						GearyImapEngineTruncateToEpochFolderSync* _tmp36_;
						_tmp33_ = self->priv->_account;
						_tmp34_ = imap_folder;
						_tmp35_ = self->priv->max_epoch;
						_tmp36_ = geary_imap_engine_truncate_to_epoch_folder_sync_new (_tmp33_, _tmp34_, _tmp35_, post_idle_detach_op);
						_g_object_unref0 (op);
						op = G_TYPE_CHECK_INSTANCE_CAST (_tmp36_, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, GearyImapEngineAccountOperation);
						break;
					}
					default:
					break;
				}
				{
					GearyImapEngineGenericAccount* _tmp37_;
					GearyImapEngineAccountOperation* _tmp38_;
					_tmp37_ = self->priv->_account;
					_tmp38_ = op;
					geary_imap_engine_generic_account_queue_operation (_tmp37_, _tmp38_, &_inner_error0_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						goto __catch0_g_error;
					}
				}
				goto __finally0;
				__catch0_g_error:
				{
					GError* err = NULL;
					GError* _tmp39_;
					const gchar* _tmp40_;
					err = _inner_error0_;
					_inner_error0_ = NULL;
					_tmp39_ = err;
					_tmp40_ = _tmp39_->message;
					geary_logging_source_warning (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Failed to queue sync operation: %s", _tmp40_);
					_g_error_free0 (err);
				}
				__finally0:
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					_g_object_unref0 (op);
					_g_object_unref0 (imap_folder);
					_g_object_unref0 (folder);
					_g_object_unref0 (_folder_it);
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return;
				}
				_g_object_unref0 (op);
			}
			_g_object_unref0 (imap_folder);
			_g_object_unref0 (folder);
		}
		_g_object_unref0 (_folder_it);
	}
}

static void
geary_imap_engine_account_synchronizer_do_prefetch_changed (GearyImapEngineAccountSynchronizer* self)
{
	gboolean _tmp0_ = FALSE;
	GearyImapEngineGenericAccount* _tmp1_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_ACCOUNT_SYNCHRONIZER (self));
	_tmp1_ = self->priv->_account;
	if (geary_account_is_open (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEARY_TYPE_ACCOUNT, GearyAccount))) {
		GearyImapEngineGenericAccount* _tmp2_;
		GearyImapClientService* _tmp3_;
		GearyImapClientService* _tmp4_;
		GearyClientServiceStatus _tmp5_;
		GearyClientServiceStatus _tmp6_;
		_tmp2_ = self->priv->_account;
		_tmp3_ = geary_imap_engine_generic_account_get_imap (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp5_ = geary_client_service_get_current_status (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, GEARY_TYPE_CLIENT_SERVICE, GearyClientService));
		_tmp6_ = _tmp5_;
		_tmp0_ = _tmp6_ == GEARY_CLIENT_SERVICE_STATUS_CONNECTED;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		GearyImapEngineGenericAccount* _tmp7_;
		GeeCollection* _tmp8_;
		GeeCollection* _tmp9_;
		_tmp7_ = self->priv->_account;
		_tmp8_ = geary_account_list_folders (G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, GEARY_TYPE_ACCOUNT, GearyAccount));
		_tmp9_ = _tmp8_;
		geary_imap_engine_account_synchronizer_send_all (self, _tmp9_, GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_REASON_FULL_SYNC, NULL);
		_g_object_unref0 (_tmp9_);
	}
}

static void
geary_imap_engine_account_synchronizer_on_account_prefetch_changed (GearyImapEngineAccountSynchronizer* self)
{
	GearyTimeoutManager* _tmp0_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_ACCOUNT_SYNCHRONIZER (self));
	_tmp0_ = self->priv->prefetch_timer;
	geary_timeout_manager_start (_tmp0_);
}

static void
geary_imap_engine_account_synchronizer_on_folders_discovered (GearyImapEngineAccountSynchronizer* self,
                                                              GeeCollection* available,
                                                              GeeCollection* unavailable)
{
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_ACCOUNT_SYNCHRONIZER (self));
	g_return_if_fail ((available == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (available, GEE_TYPE_COLLECTION));
	g_return_if_fail ((unavailable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (unavailable, GEE_TYPE_COLLECTION));
	if (available != NULL) {
		geary_imap_engine_account_synchronizer_folders_discovered (self, available);
	}
}

static void
geary_imap_engine_account_synchronizer_class_init (GearyImapEngineAccountSynchronizerClass * klass,
                                                   gpointer klass_data)
{
	geary_imap_engine_account_synchronizer_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GearyImapEngineAccountSynchronizer_private_offset);
	((GearyImapEngineAccountSynchronizerClass *) klass)->to_logging_state = (GearyLoggingState* (*) (GearyImapEngineAccountSynchronizer*)) geary_imap_engine_account_synchronizer_real_to_logging_state;
	G_OBJECT_CLASS (klass)->get_property = _vala_geary_imap_engine_account_synchronizer_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_geary_imap_engine_account_synchronizer_set_property;
	G_OBJECT_CLASS (klass)->finalize = geary_imap_engine_account_synchronizer_finalize;
	/** {@inheritDoc} */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_LOGGING_PARENT_PROPERTY, geary_imap_engine_account_synchronizer_properties[GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_LOGGING_PARENT_PROPERTY] = g_param_spec_object ("logging-parent", "logging-parent", "logging-parent", GEARY_LOGGING_TYPE_SOURCE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
geary_imap_engine_account_synchronizer_geary_logging_source_interface_init (GearyLoggingSourceIface * iface,
                                                                            gpointer iface_data)
{
	geary_imap_engine_account_synchronizer_geary_logging_source_parent_iface = g_type_interface_peek_parent (iface);
	iface->to_logging_state = (GearyLoggingState* (*) (GearyLoggingSource*)) geary_imap_engine_account_synchronizer_to_logging_state;
	iface->get_logging_parent = geary_imap_engine_account_synchronizer_real_get_logging_parent;
}

static void
geary_imap_engine_account_synchronizer_instance_init (GearyImapEngineAccountSynchronizer * self,
                                                      gpointer klass)
{
	GTimeZone* _tmp0_;
	GTimeZone* _tmp1_;
	GDateTime* _tmp2_;
	self->priv = geary_imap_engine_account_synchronizer_get_instance_private (self);
	_tmp0_ = g_time_zone_new_local ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_date_time_new (_tmp1_, 2000, 1, 1, 0, 0, 0.0);
	self->priv->max_epoch = _tmp2_;
	_g_time_zone_unref0 (_tmp1_);
}

static void
geary_imap_engine_account_synchronizer_finalize (GObject * obj)
{
	GearyImapEngineAccountSynchronizer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_SYNCHRONIZER, GearyImapEngineAccountSynchronizer);
	_g_object_unref0 (self->priv->prefetch_timer);
	_g_date_time_unref0 (self->priv->max_epoch);
	G_OBJECT_CLASS (geary_imap_engine_account_synchronizer_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
geary_imap_engine_account_synchronizer_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapEngineAccountSynchronizerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_engine_account_synchronizer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapEngineAccountSynchronizer), 0, (GInstanceInitFunc) geary_imap_engine_account_synchronizer_instance_init, NULL };
	static const GInterfaceInfo geary_logging_source_info = { (GInterfaceInitFunc) geary_imap_engine_account_synchronizer_geary_logging_source_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType geary_imap_engine_account_synchronizer_type_id;
	geary_imap_engine_account_synchronizer_type_id = g_type_register_static (GEARY_TYPE_BASE_OBJECT, "GearyImapEngineAccountSynchronizer", &g_define_type_info, 0);
	g_type_add_interface_static (geary_imap_engine_account_synchronizer_type_id, GEARY_LOGGING_TYPE_SOURCE, &geary_logging_source_info);
	GearyImapEngineAccountSynchronizer_private_offset = g_type_add_instance_private (geary_imap_engine_account_synchronizer_type_id, sizeof (GearyImapEngineAccountSynchronizerPrivate));
	return geary_imap_engine_account_synchronizer_type_id;
}

GType
geary_imap_engine_account_synchronizer_get_type (void)
{
	static gsize geary_imap_engine_account_synchronizer_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_engine_account_synchronizer_type_id__once)) {
		GType geary_imap_engine_account_synchronizer_type_id;
		geary_imap_engine_account_synchronizer_type_id = geary_imap_engine_account_synchronizer_get_type_once ();
		g_once_init_leave (&geary_imap_engine_account_synchronizer_type_id__once, geary_imap_engine_account_synchronizer_type_id);
	}
	return geary_imap_engine_account_synchronizer_type_id__once;
}

static void
_vala_geary_imap_engine_account_synchronizer_get_property (GObject * object,
                                                           guint property_id,
                                                           GValue * value,
                                                           GParamSpec * pspec)
{
	GearyImapEngineAccountSynchronizer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_SYNCHRONIZER, GearyImapEngineAccountSynchronizer);
	switch (property_id) {
		case GEARY_IMAP_ENGINE_ACCOUNT_SYNCHRONIZER_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;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_geary_imap_engine_account_synchronizer_set_property (GObject * object,
                                                           guint property_id,
                                                           const GValue * value,
                                                           GParamSpec * pspec)
{
	GearyImapEngineAccountSynchronizer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_SYNCHRONIZER, GearyImapEngineAccountSynchronizer);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
geary_imap_engine_folder_sync_get_instance_private (GearyImapEngineFolderSync* self)
{
	return G_STRUCT_MEMBER_P (self, GearyImapEngineFolderSync_private_offset);
}

static void
_geary_imap_engine_folder_sync_on_folder_close_geary_folder_closed (GearyFolder* _sender,
                                                                    GearyFolderCloseReason reason,
                                                                    gpointer self)
{
	geary_imap_engine_folder_sync_on_folder_close ((GearyImapEngineFolderSync*) self);
}

GDateTime*
geary_imap_engine_folder_sync_get_sync_max_epoch (GearyImapEngineFolderSync* self)
{
	GDateTime* result;
	GDateTime* _tmp0_;
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_FOLDER_SYNC (self), NULL);
	_tmp0_ = self->priv->_sync_max_epoch;
	result = _tmp0_;
	return result;
}

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

static void
geary_imap_engine_folder_sync_set_sync_max_epoch (GearyImapEngineFolderSync* self,
                                                  GDateTime* value)
{
	GDateTime* old_value;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_FOLDER_SYNC (self));
	old_value = geary_imap_engine_folder_sync_get_sync_max_epoch (self);
	if (old_value != value) {
		GDateTime* _tmp0_;
		_tmp0_ = _g_date_time_ref0 (value);
		_g_date_time_unref0 (self->priv->_sync_max_epoch);
		self->priv->_sync_max_epoch = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_engine_folder_sync_properties[GEARY_IMAP_ENGINE_FOLDER_SYNC_SYNC_MAX_EPOCH_PROPERTY]);
	}
}

GearyImapEngineFolderSync*
geary_imap_engine_folder_sync_construct (GType object_type,
                                         GearyImapEngineGenericAccount* account,
                                         GearyImapEngineMinimalFolder* folder,
                                         GDateTime* sync_max_epoch,
                                         GearyFolderOpenFlags open_flags)
{
	GearyImapEngineFolderSync * self = NULL;
	GearyFolder* _tmp0_;
	GearyFolder* _tmp1_;
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_GENERIC_ACCOUNT (account), NULL);
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_MINIMAL_FOLDER (folder), NULL);
	g_return_val_if_fail (sync_max_epoch != NULL, NULL);
	self = (GearyImapEngineFolderSync*) geary_imap_engine_folder_operation_construct (object_type, G_TYPE_CHECK_INSTANCE_CAST (account, GEARY_TYPE_ACCOUNT, GearyAccount), G_TYPE_CHECK_INSTANCE_CAST (folder, GEARY_TYPE_FOLDER, GearyFolder));
	geary_imap_engine_folder_sync_set_sync_max_epoch (self, sync_max_epoch);
	self->priv->open_flags = open_flags;
	_tmp0_ = geary_imap_engine_folder_operation_get_folder (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_IMAP_ENGINE_TYPE_FOLDER_OPERATION, GearyImapEngineFolderOperation));
	_tmp1_ = _tmp0_;
	g_signal_connect_object (_tmp1_, "closed", (GCallback) _geary_imap_engine_folder_sync_on_folder_close_geary_folder_closed, self, 0);
	return self;
}

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

static void
geary_imap_engine_folder_sync_real_execute (GearyImapEngineAccountOperation* base,
                                            GCancellable* cancellable,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_)
{
	GearyImapEngineFolderSync * self;
	GearyImapEngineFolderSyncExecuteData* _data_;
	GearyImapEngineFolderSync* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_TYPE_FOLDER_SYNC, GearyImapEngineFolderSync);
	_data_ = g_slice_new0 (GearyImapEngineFolderSyncExecuteData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_engine_folder_sync_real_execute_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_engine_folder_sync_real_execute_co (_data_);
}

static void
geary_imap_engine_folder_sync_execute_finish (GearyImapEngineAccountOperation* base,
                                              GAsyncResult* _res_,
                                              GError** error)
{
	GearyImapEngineFolderSyncExecuteData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
geary_imap_engine_folder_sync_execute_ready (GObject* source_object,
                                             GAsyncResult* _res_,
                                             gpointer _user_data_)
{
	GearyImapEngineFolderSyncExecuteData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_engine_folder_sync_real_execute_co (_data_);
}

static gboolean
geary_imap_engine_folder_sync_real_execute_co (GearyImapEngineFolderSyncExecuteData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		case 4:
		goto _state_4;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _g_object_ref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self->priv->closed_cancellable);
	_data_->self->priv->closed_cancellable = _data_->_tmp0_;
	_data_->was_opened = FALSE;
	_data_->_tmp1_ = geary_imap_engine_folder_operation_get_folder (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_FOLDER_OPERATION, GearyImapEngineFolderOperation));
	_data_->_tmp2_ = _data_->_tmp1_;
	_data_->_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, GEARY_IMAP_ENGINE_TYPE_MINIMAL_FOLDER, GearyImapEngineMinimalFolder));
	_data_->minimal = _data_->_tmp3_;
	{
		_data_->_tmp4_ = _data_->minimal;
		_data_->_state_ = 1;
		geary_folder_open_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp4_, GEARY_TYPE_FOLDER, GearyFolder), _data_->self->priv->open_flags, _data_->cancellable, geary_imap_engine_folder_sync_execute_ready, _data_);
		return FALSE;
		_state_1:
		geary_folder_open_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp4_, GEARY_TYPE_FOLDER, GearyFolder), _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 __catch0_g_io_error_cancelled;
			}
			if (g_error_matches (_data_->_inner_error0_, GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_ALREADY_CLOSED)) {
				goto __catch0_geary_engine_error_already_closed;
			}
			goto __catch0_g_error;
		}
		_data_->was_opened = TRUE;
		geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Synchronising");
		_data_->_tmp5_ = geary_imap_engine_account_operation_get_account (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, GearyImapEngineAccountOperation));
		_data_->_tmp6_ = _data_->_tmp5_;
		_data_->_tmp7_ = geary_account_get_information (_data_->_tmp6_);
		_data_->_tmp8_ = _data_->_tmp7_;
		_data_->_tmp9_ = geary_account_information_get_prefetch_period_days (_data_->_tmp8_);
		_data_->_tmp10_ = _data_->_tmp9_;
		if (_data_->_tmp10_ >= 0) {
			_data_->_tmp11_ = g_date_time_new_now_local ();
			_g_date_time_unref0 (_data_->actual_max_epoch);
			_data_->actual_max_epoch = _data_->_tmp11_;
			_data_->_tmp12_ = _data_->actual_max_epoch;
			_data_->_tmp13_ = geary_imap_engine_account_operation_get_account (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, GearyImapEngineAccountOperation));
			_data_->_tmp14_ = _data_->_tmp13_;
			_data_->_tmp15_ = geary_account_get_information (_data_->_tmp14_);
			_data_->_tmp16_ = _data_->_tmp15_;
			_data_->_tmp17_ = geary_account_information_get_prefetch_period_days (_data_->_tmp16_);
			_data_->_tmp18_ = _data_->_tmp17_;
			_data_->_tmp19_ = g_date_time_add_days (_data_->_tmp12_, 0 - _data_->_tmp18_);
			_g_date_time_unref0 (_data_->actual_max_epoch);
			_data_->actual_max_epoch = _data_->_tmp19_;
		} else {
			_data_->_tmp20_ = _data_->self->priv->_sync_max_epoch;
			_data_->_tmp21_ = _g_date_time_ref0 (_data_->_tmp20_);
			_g_date_time_unref0 (_data_->actual_max_epoch);
			_data_->actual_max_epoch = _data_->_tmp21_;
		}
		_data_->_tmp22_ = _data_->actual_max_epoch;
		_data_->_state_ = 2;
		geary_imap_engine_folder_sync_sync_folder (_data_->self, _data_->_tmp22_, _data_->cancellable, geary_imap_engine_folder_sync_execute_ready, _data_);
		return FALSE;
		_state_2:
		geary_imap_engine_folder_sync_sync_folder_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_date_time_unref0 (_data_->actual_max_epoch);
			if (g_error_matches (_data_->_inner_error0_, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
				goto __catch0_g_io_error_cancelled;
			}
			if (g_error_matches (_data_->_inner_error0_, GEARY_ENGINE_ERROR, GEARY_ENGINE_ERROR_ALREADY_CLOSED)) {
				goto __catch0_geary_engine_error_already_closed;
			}
			goto __catch0_g_error;
		}
		_g_date_time_unref0 (_data_->actual_max_epoch);
	}
	goto __finally0;
	__catch0_g_io_error_cancelled:
	{
		g_clear_error (&_data_->_inner_error0_);
	}
	goto __finally0;
	__catch0_geary_engine_error_already_closed:
	{
		_data_->err = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp23_ = _data_->minimal;
		_data_->_tmp24_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp23_, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
		_data_->_tmp25_ = _data_->_tmp24_;
		_data_->_tmp26_ = _data_->err;
		_data_->_tmp27_ = _data_->_tmp26_->message;
		geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Folder failed to open %s: %s", _data_->_tmp25_, _data_->_tmp27_);
		_g_free0 (_data_->_tmp25_);
		_g_error_free0 (_data_->err);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->_vala1_err = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp28_ = geary_imap_engine_account_operation_get_account (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, GearyImapEngineAccountOperation));
		_data_->_tmp29_ = _data_->_tmp28_;
		_data_->_tmp30_ = geary_imap_engine_account_operation_get_account (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, GearyImapEngineAccountOperation));
		_data_->_tmp31_ = _data_->_tmp30_;
		_data_->_tmp32_ = geary_account_get_information (_data_->_tmp31_);
		_data_->_tmp33_ = _data_->_tmp32_;
		_data_->_tmp34_ = geary_imap_engine_account_operation_get_account (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, GearyImapEngineAccountOperation));
		_data_->_tmp35_ = _data_->_tmp34_;
		_data_->_tmp36_ = geary_account_get_information (_data_->_tmp35_);
		_data_->_tmp37_ = _data_->_tmp36_;
		_data_->_tmp38_ = geary_account_information_get_incoming (_data_->_tmp37_);
		_data_->_tmp39_ = _data_->_tmp38_;
		_data_->_tmp40_ = _data_->_vala1_err;
		_data_->_tmp41_ = geary_service_problem_report_new (_data_->_tmp33_, _data_->_tmp39_, _data_->_tmp40_);
		_data_->_tmp42_ = _data_->_tmp41_;
		g_signal_emit_by_name (_data_->_tmp29_, "report-problem", G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp42_, GEARY_TYPE_PROBLEM_REPORT, GearyProblemReport));
		_g_object_unref0 (_data_->_tmp42_);
		_g_error_free0 (_data_->_vala1_err);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->minimal);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_object_unref0 (_data_->self->priv->closed_cancellable);
	_data_->self->priv->closed_cancellable = NULL;
	if (_data_->was_opened) {
		{
			_data_->_tmp44_ = geary_imap_engine_folder_operation_get_folder (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_FOLDER_OPERATION, GearyImapEngineFolderOperation));
			_data_->_tmp45_ = _data_->_tmp44_;
			_data_->_state_ = 3;
			geary_folder_close_async (_data_->_tmp45_, NULL, geary_imap_engine_folder_sync_execute_ready, _data_);
			return FALSE;
			_state_3:
			_data_->_tmp43_ = geary_folder_close_finish (_data_->_tmp45_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch1_g_error;
			}
			if (_data_->_tmp43_) {
				_data_->_tmp46_ = geary_imap_engine_folder_operation_get_folder (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_FOLDER_OPERATION, GearyImapEngineFolderOperation));
				_data_->_tmp47_ = _data_->_tmp46_;
				_data_->_state_ = 4;
				geary_folder_wait_for_close_async (_data_->_tmp47_, _data_->cancellable, geary_imap_engine_folder_sync_execute_ready, _data_);
				return FALSE;
				_state_4:
				geary_folder_wait_for_close_finish (_data_->_tmp47_, _data_->_res_, &_data_->_inner_error0_);
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					goto __catch1_g_error;
				}
			}
		}
		goto __finally1;
		__catch1_g_error:
		{
			_data_->_vala2_err = _data_->_inner_error0_;
			_data_->_inner_error0_ = NULL;
			_data_->_tmp48_ = geary_imap_engine_account_operation_get_account (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, GearyImapEngineAccountOperation));
			_data_->_tmp49_ = _data_->_tmp48_;
			_data_->_tmp50_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp49_, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
			_data_->_tmp51_ = _data_->_tmp50_;
			_data_->_tmp52_ = geary_imap_engine_folder_operation_get_folder (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_FOLDER_OPERATION, GearyImapEngineFolderOperation));
			_data_->_tmp53_ = _data_->_tmp52_;
			_data_->_tmp54_ = geary_logging_source_to_string (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp53_, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource));
			_data_->_tmp55_ = _data_->_tmp54_;
			_data_->_tmp56_ = _data_->_vala2_err;
			_data_->_tmp57_ = _data_->_tmp56_->message;
			geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "%s: Error closing folder %s: %s", _data_->_tmp51_, _data_->_tmp55_, _data_->_tmp57_);
			_g_free0 (_data_->_tmp55_);
			_g_free0 (_data_->_tmp51_);
			_g_error_free0 (_data_->_vala2_err);
		}
		__finally1:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->minimal);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_g_object_unref0 (_data_->minimal);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

void
geary_imap_engine_folder_sync_sync_folder (GearyImapEngineFolderSync* self,
                                           GDateTime* max_epoch,
                                           GCancellable* cancellable,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_)
{
	GearyImapEngineFolderSyncClass* _klass_;
	_klass_ = GEARY_IMAP_ENGINE_FOLDER_SYNC_GET_CLASS (self);
	if (_klass_->sync_folder) {
		_klass_->sync_folder (self, max_epoch, cancellable, _callback_, _user_data_);
	}
}

void
geary_imap_engine_folder_sync_sync_folder_finish (GearyImapEngineFolderSync* self,
                                                  GAsyncResult* _res_,
                                                  GError** error)
{
	GearyImapEngineFolderSyncClass* _klass_;
	_klass_ = GEARY_IMAP_ENGINE_FOLDER_SYNC_GET_CLASS (self);
	if (_klass_->sync_folder_finish) {
		_klass_->sync_folder_finish (self, _res_, error);
	}
}

static void
geary_imap_engine_folder_sync_on_folder_close (GearyImapEngineFolderSync* self)
{
	GCancellable* _tmp0_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_FOLDER_SYNC (self));
	_tmp0_ = self->priv->closed_cancellable;
	if (_tmp0_ != NULL) {
		GCancellable* _tmp1_;
		_tmp1_ = self->priv->closed_cancellable;
		g_cancellable_cancel (_tmp1_);
	}
}

static void
geary_imap_engine_folder_sync_class_init (GearyImapEngineFolderSyncClass * klass,
                                          gpointer klass_data)
{
	geary_imap_engine_folder_sync_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GearyImapEngineFolderSync_private_offset);
	((GearyImapEngineAccountOperationClass *) klass)->execute = (void (*) (GearyImapEngineAccountOperation*, GCancellable*, GAsyncReadyCallback, gpointer)) geary_imap_engine_folder_sync_real_execute;
	((GearyImapEngineAccountOperationClass *) klass)->execute_finish = (void (*) (GearyImapEngineAccountOperation*, GAsyncResult*, GError**)) geary_imap_engine_folder_sync_execute_finish;
	G_OBJECT_CLASS (klass)->get_property = _vala_geary_imap_engine_folder_sync_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_geary_imap_engine_folder_sync_set_property;
	G_OBJECT_CLASS (klass)->finalize = geary_imap_engine_folder_sync_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_ENGINE_FOLDER_SYNC_SYNC_MAX_EPOCH_PROPERTY, geary_imap_engine_folder_sync_properties[GEARY_IMAP_ENGINE_FOLDER_SYNC_SYNC_MAX_EPOCH_PROPERTY] = g_param_spec_boxed ("sync-max-epoch", "sync-max-epoch", "sync-max-epoch", G_TYPE_DATE_TIME, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
geary_imap_engine_folder_sync_instance_init (GearyImapEngineFolderSync * self,
                                             gpointer klass)
{
	self->priv = geary_imap_engine_folder_sync_get_instance_private (self);
	self->priv->closed_cancellable = NULL;
}

static void
geary_imap_engine_folder_sync_finalize (GObject * obj)
{
	GearyImapEngineFolderSync * self;
	GearyFolder* folder = NULL;
	GearyFolder* _tmp0_;
	GearyFolder* _tmp1_;
	GearyFolder* _tmp2_;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_IMAP_ENGINE_TYPE_FOLDER_SYNC, GearyImapEngineFolderSync);
	_tmp0_ = geary_imap_engine_folder_operation_get_folder (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_IMAP_ENGINE_TYPE_FOLDER_OPERATION, GearyImapEngineFolderOperation));
	_tmp1_ = _tmp0_;
	folder = _tmp1_;
	_tmp2_ = folder;
	if (_tmp2_ != NULL) {
		GearyFolder* _tmp3_;
		GearyFolder* _tmp4_;
		guint _tmp5_;
		_tmp3_ = geary_imap_engine_folder_operation_get_folder (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_IMAP_ENGINE_TYPE_FOLDER_OPERATION, GearyImapEngineFolderOperation));
		_tmp4_ = _tmp3_;
		g_signal_parse_name ("closed", GEARY_TYPE_FOLDER, &_tmp5_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp4_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp5_, 0, NULL, (GCallback) _geary_imap_engine_folder_sync_on_folder_close_geary_folder_closed, self);
	}
	_g_date_time_unref0 (self->priv->_sync_max_epoch);
	_g_object_unref0 (self->priv->closed_cancellable);
	G_OBJECT_CLASS (geary_imap_engine_folder_sync_parent_class)->finalize (obj);
}

/**
 * Base class for folder synchronisation account operations.
 */
 G_GNUC_NO_INLINE static GType
geary_imap_engine_folder_sync_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapEngineFolderSyncClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_engine_folder_sync_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapEngineFolderSync), 0, (GInstanceInitFunc) geary_imap_engine_folder_sync_instance_init, NULL };
	GType geary_imap_engine_folder_sync_type_id;
	geary_imap_engine_folder_sync_type_id = g_type_register_static (GEARY_IMAP_ENGINE_TYPE_FOLDER_OPERATION, "GearyImapEngineFolderSync", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	GearyImapEngineFolderSync_private_offset = g_type_add_instance_private (geary_imap_engine_folder_sync_type_id, sizeof (GearyImapEngineFolderSyncPrivate));
	return geary_imap_engine_folder_sync_type_id;
}

GType
geary_imap_engine_folder_sync_get_type (void)
{
	static gsize geary_imap_engine_folder_sync_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_engine_folder_sync_type_id__once)) {
		GType geary_imap_engine_folder_sync_type_id;
		geary_imap_engine_folder_sync_type_id = geary_imap_engine_folder_sync_get_type_once ();
		g_once_init_leave (&geary_imap_engine_folder_sync_type_id__once, geary_imap_engine_folder_sync_type_id);
	}
	return geary_imap_engine_folder_sync_type_id__once;
}

static void
_vala_geary_imap_engine_folder_sync_get_property (GObject * object,
                                                  guint property_id,
                                                  GValue * value,
                                                  GParamSpec * pspec)
{
	GearyImapEngineFolderSync * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_ENGINE_TYPE_FOLDER_SYNC, GearyImapEngineFolderSync);
	switch (property_id) {
		case GEARY_IMAP_ENGINE_FOLDER_SYNC_SYNC_MAX_EPOCH_PROPERTY:
		g_value_set_boxed (value, geary_imap_engine_folder_sync_get_sync_max_epoch (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_geary_imap_engine_folder_sync_set_property (GObject * object,
                                                  guint property_id,
                                                  const GValue * value,
                                                  GParamSpec * pspec)
{
	GearyImapEngineFolderSync * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_ENGINE_TYPE_FOLDER_SYNC, GearyImapEngineFolderSync);
	switch (property_id) {
		case GEARY_IMAP_ENGINE_FOLDER_SYNC_SYNC_MAX_EPOCH_PROPERTY:
		geary_imap_engine_folder_sync_set_sync_max_epoch (self, g_value_get_boxed (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

GearyImapEngineRefreshFolderSync*
geary_imap_engine_refresh_folder_sync_construct (GType object_type,
                                                 GearyImapEngineGenericAccount* account,
                                                 GearyImapEngineMinimalFolder* folder,
                                                 GDateTime* sync_max_epoch)
{
	GearyImapEngineRefreshFolderSync * self = NULL;
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_GENERIC_ACCOUNT (account), NULL);
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_MINIMAL_FOLDER (folder), NULL);
	g_return_val_if_fail (sync_max_epoch != NULL, NULL);
	self = (GearyImapEngineRefreshFolderSync*) geary_imap_engine_folder_sync_construct (object_type, account, folder, sync_max_epoch, GEARY_FOLDER_OPEN_FLAGS_NO_DELAY);
	return self;
}

GearyImapEngineRefreshFolderSync*
geary_imap_engine_refresh_folder_sync_new (GearyImapEngineGenericAccount* account,
                                           GearyImapEngineMinimalFolder* folder,
                                           GDateTime* sync_max_epoch)
{
	return geary_imap_engine_refresh_folder_sync_construct (GEARY_IMAP_ENGINE_TYPE_REFRESH_FOLDER_SYNC, account, folder, sync_max_epoch);
}

static void
geary_imap_engine_refresh_folder_sync_real_sync_folder_data_free (gpointer _data)
{
	GearyImapEngineRefreshFolderSyncSyncFolderData* _data_;
	_data_ = _data;
	_g_date_time_unref0 (_data_->max_epoch);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapEngineRefreshFolderSyncSyncFolderData, _data_);
}

static void
geary_imap_engine_refresh_folder_sync_real_sync_folder (GearyImapEngineFolderSync* base,
                                                        GDateTime* max_epoch,
                                                        GCancellable* cancellable,
                                                        GAsyncReadyCallback _callback_,
                                                        gpointer _user_data_)
{
	GearyImapEngineRefreshFolderSync * self;
	GearyImapEngineRefreshFolderSyncSyncFolderData* _data_;
	GearyImapEngineRefreshFolderSync* _tmp0_;
	GDateTime* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (max_epoch != NULL);
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_TYPE_REFRESH_FOLDER_SYNC, GearyImapEngineRefreshFolderSync);
	_data_ = g_slice_new0 (GearyImapEngineRefreshFolderSyncSyncFolderData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_engine_refresh_folder_sync_real_sync_folder_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_date_time_ref0 (max_epoch);
	_g_date_time_unref0 (_data_->max_epoch);
	_data_->max_epoch = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_engine_refresh_folder_sync_real_sync_folder_co (_data_);
}

static void
geary_imap_engine_refresh_folder_sync_sync_folder_finish (GearyImapEngineFolderSync* base,
                                                          GAsyncResult* _res_,
                                                          GError** error)
{
	GearyImapEngineRefreshFolderSyncSyncFolderData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
geary_imap_engine_refresh_folder_sync_sync_folder_ready (GObject* source_object,
                                                         GAsyncResult* _res_,
                                                         gpointer _user_data_)
{
	GearyImapEngineRefreshFolderSyncSyncFolderData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_engine_refresh_folder_sync_real_sync_folder_co (_data_);
}

static gboolean
geary_imap_engine_refresh_folder_sync_real_sync_folder_co (GearyImapEngineRefreshFolderSyncSyncFolderData* _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_engine_folder_operation_get_folder (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_FOLDER_OPERATION, GearyImapEngineFolderOperation));
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_state_ = 1;
	geary_folder_synchronise_remote (_data_->_tmp1_, _data_->cancellable, geary_imap_engine_refresh_folder_sync_sync_folder_ready, _data_);
	return FALSE;
	_state_1:
	geary_folder_synchronise_remote_finish (_data_->_tmp1_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_engine_refresh_folder_sync_class_init (GearyImapEngineRefreshFolderSyncClass * klass,
                                                  gpointer klass_data)
{
	geary_imap_engine_refresh_folder_sync_parent_class = g_type_class_peek_parent (klass);
	((GearyImapEngineFolderSyncClass *) klass)->sync_folder = (void (*) (GearyImapEngineFolderSync*, GDateTime*, GCancellable*, GAsyncReadyCallback, gpointer)) geary_imap_engine_refresh_folder_sync_real_sync_folder;
	((GearyImapEngineFolderSyncClass *) klass)->sync_folder_finish = (void (*) (GearyImapEngineFolderSync*, GAsyncResult*, GError**)) geary_imap_engine_refresh_folder_sync_sync_folder_finish;
}

static void
geary_imap_engine_refresh_folder_sync_instance_init (GearyImapEngineRefreshFolderSync * self,
                                                     gpointer klass)
{
}

/**
 * Refreshes a folder's contents after they have changed.
 *
 * This synchronisation process simply opens the remote folder, waits
 * for it to finish opening for normalisation and pre-fetching to
 * complete, then closes it again.
 */
 G_GNUC_NO_INLINE static GType
geary_imap_engine_refresh_folder_sync_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapEngineRefreshFolderSyncClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_engine_refresh_folder_sync_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapEngineRefreshFolderSync), 0, (GInstanceInitFunc) geary_imap_engine_refresh_folder_sync_instance_init, NULL };
	GType geary_imap_engine_refresh_folder_sync_type_id;
	geary_imap_engine_refresh_folder_sync_type_id = g_type_register_static (GEARY_IMAP_ENGINE_TYPE_FOLDER_SYNC, "GearyImapEngineRefreshFolderSync", &g_define_type_info, 0);
	return geary_imap_engine_refresh_folder_sync_type_id;
}

GType
geary_imap_engine_refresh_folder_sync_get_type (void)
{
	static gsize geary_imap_engine_refresh_folder_sync_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_engine_refresh_folder_sync_type_id__once)) {
		GType geary_imap_engine_refresh_folder_sync_type_id;
		geary_imap_engine_refresh_folder_sync_type_id = geary_imap_engine_refresh_folder_sync_get_type_once ();
		g_once_init_leave (&geary_imap_engine_refresh_folder_sync_type_id__once, geary_imap_engine_refresh_folder_sync_type_id);
	}
	return geary_imap_engine_refresh_folder_sync_type_id__once;
}

GearyImapEngineFullFolderSync*
geary_imap_engine_full_folder_sync_construct (GType object_type,
                                              GearyImapEngineGenericAccount* account,
                                              GearyImapEngineMinimalFolder* folder,
                                              GDateTime* sync_max_epoch)
{
	GearyImapEngineFullFolderSync * self = NULL;
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_GENERIC_ACCOUNT (account), NULL);
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_MINIMAL_FOLDER (folder), NULL);
	g_return_val_if_fail (sync_max_epoch != NULL, NULL);
	self = (GearyImapEngineFullFolderSync*) geary_imap_engine_refresh_folder_sync_construct (object_type, account, folder, sync_max_epoch);
	return self;
}

GearyImapEngineFullFolderSync*
geary_imap_engine_full_folder_sync_new (GearyImapEngineGenericAccount* account,
                                        GearyImapEngineMinimalFolder* folder,
                                        GDateTime* sync_max_epoch)
{
	return geary_imap_engine_full_folder_sync_construct (GEARY_IMAP_ENGINE_TYPE_FULL_FOLDER_SYNC, account, folder, sync_max_epoch);
}

static void
geary_imap_engine_full_folder_sync_real_sync_folder_data_free (gpointer _data)
{
	GearyImapEngineFullFolderSyncSyncFolderData* _data_;
	_data_ = _data;
	_g_date_time_unref0 (_data_->max_epoch);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapEngineFullFolderSyncSyncFolderData, _data_);
}

static void
geary_imap_engine_full_folder_sync_real_sync_folder (GearyImapEngineFolderSync* base,
                                                     GDateTime* max_epoch,
                                                     GCancellable* cancellable,
                                                     GAsyncReadyCallback _callback_,
                                                     gpointer _user_data_)
{
	GearyImapEngineFullFolderSync * self;
	GearyImapEngineFullFolderSyncSyncFolderData* _data_;
	GearyImapEngineFullFolderSync* _tmp0_;
	GDateTime* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (max_epoch != NULL);
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_TYPE_FULL_FOLDER_SYNC, GearyImapEngineFullFolderSync);
	_data_ = g_slice_new0 (GearyImapEngineFullFolderSyncSyncFolderData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_engine_full_folder_sync_real_sync_folder_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_date_time_ref0 (max_epoch);
	_g_date_time_unref0 (_data_->max_epoch);
	_data_->max_epoch = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_engine_full_folder_sync_real_sync_folder_co (_data_);
}

static void
geary_imap_engine_full_folder_sync_sync_folder_finish (GearyImapEngineFolderSync* base,
                                                       GAsyncResult* _res_,
                                                       GError** error)
{
	GearyImapEngineFullFolderSyncSyncFolderData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
geary_imap_engine_full_folder_sync_sync_folder_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_)
{
	GearyImapEngineFullFolderSyncSyncFolderData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_engine_full_folder_sync_real_sync_folder_co (_data_);
}

static gboolean
geary_imap_engine_full_folder_sync_real_sync_folder_co (GearyImapEngineFullFolderSyncSyncFolderData* _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;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = geary_imap_engine_folder_operation_get_folder (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_FOLDER_OPERATION, GearyImapEngineFolderOperation));
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = geary_imap_engine_minimal_folder_get_local_folder (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, GEARY_IMAP_ENGINE_TYPE_MINIMAL_FOLDER, GearyImapEngineMinimalFolder));
	_data_->_tmp3_ = _data_->_tmp2_;
	_data_->_tmp4_ = _g_object_ref0 (_data_->_tmp3_);
	_data_->local_folder = _data_->_tmp4_;
	_data_->_tmp5_ = geary_imap_engine_account_operation_get_account (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, GearyImapEngineAccountOperation));
	_data_->_tmp6_ = _data_->_tmp5_;
	_data_->_tmp7_ = geary_account_get_information (_data_->_tmp6_);
	_data_->_tmp8_ = _data_->_tmp7_;
	_data_->_tmp9_ = geary_account_information_get_prefetch_period_days (_data_->_tmp8_);
	_data_->_tmp10_ = _data_->_tmp9_;
	if (_data_->_tmp10_ >= 0) {
		_data_->_tmp11_ = _data_->local_folder;
		_data_->_state_ = 1;
		geary_imap_db_folder_detach_emails_before_timestamp (_data_->_tmp11_, _data_->max_epoch, _data_->cancellable, geary_imap_engine_full_folder_sync_sync_folder_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp12_ = geary_imap_db_folder_detach_emails_before_timestamp_finish (_data_->_tmp11_, _data_->_res_, &_data_->_inner_error0_);
		_data_->detached_ids = _data_->_tmp12_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->local_folder);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp13_ = _data_->detached_ids;
		if (_data_->_tmp13_ != NULL) {
			_data_->_tmp14_ = geary_imap_engine_account_operation_get_account (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, GearyImapEngineAccountOperation));
			_data_->_tmp15_ = _data_->_tmp14_;
			_data_->_tmp16_ = geary_imap_engine_folder_operation_get_folder (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_FOLDER_OPERATION, GearyImapEngineFolderOperation));
			_data_->_tmp17_ = _data_->_tmp16_;
			_data_->_tmp18_ = _data_->detached_ids;
			g_signal_emit_by_name (_data_->_tmp15_, "email-locally-removed", _data_->_tmp17_, _data_->_tmp18_);
			_data_->_tmp19_ = geary_imap_engine_folder_operation_get_folder (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_FOLDER_OPERATION, GearyImapEngineFolderOperation));
			_data_->_tmp20_ = _data_->_tmp19_;
			_data_->_tmp21_ = _data_->detached_ids;
			g_signal_emit_by_name (_data_->_tmp20_, "email-locally-removed", _data_->_tmp21_);
			_data_->_tmp22_ = geary_imap_engine_account_operation_get_account (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, GearyImapEngineAccountOperation));
			_data_->_tmp23_ = _data_->_tmp22_;
			_data_->_tmp24_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp23_, GEARY_IMAP_ENGINE_TYPE_GENERIC_ACCOUNT, GearyImapEngineGenericAccount));
			_data_->imap_account = _data_->_tmp24_;
			_data_->_tmp25_ = _data_->imap_account;
			_data_->_tmp26_ = _data_->imap_account;
			_data_->_tmp27_ = geary_imap_engine_foreground_garbage_collection_new (_data_->_tmp26_);
			_data_->_tmp28_ = _data_->_tmp27_;
			geary_imap_engine_generic_account_queue_operation (_data_->_tmp25_, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp28_, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, GearyImapEngineAccountOperation), &_data_->_inner_error0_);
			_g_object_unref0 (_data_->_tmp28_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
				_g_object_unref0 (_data_->imap_account);
				_g_object_unref0 (_data_->detached_ids);
				_g_object_unref0 (_data_->local_folder);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
			_g_object_unref0 (_data_->imap_account);
		}
		_g_object_unref0 (_data_->detached_ids);
	}
	_data_->_tmp29_ = _data_->local_folder;
	_data_->_state_ = 2;
	geary_imap_db_folder_list_email_by_id_async (_data_->_tmp29_, NULL, 1, GEARY_EMAIL_FIELD_PROPERTIES, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_OLDEST_TO_NEWEST, _data_->cancellable, geary_imap_engine_full_folder_sync_sync_folder_ready, _data_);
	return FALSE;
	_state_2:
	_data_->_tmp30_ = geary_imap_db_folder_list_email_by_id_finish (_data_->_tmp29_, _data_->_res_, &_data_->_inner_error0_);
	_data_->list = _data_->_tmp30_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->local_folder);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->current_oldest = NULL;
	_data_->_tmp32_ = _data_->list;
	if (_data_->_tmp32_ != NULL) {
		_data_->_tmp33_ = _data_->list;
		_data_->_tmp34_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp33_, GEE_TYPE_COLLECTION, GeeCollection));
		_data_->_tmp35_ = _data_->_tmp34_;
		_data_->_tmp31_ = _data_->_tmp35_ > 0;
	} else {
		_data_->_tmp31_ = FALSE;
	}
	if (_data_->_tmp31_) {
		_data_->_tmp36_ = _data_->list;
		_data_->_tmp37_ = gee_list_get (_data_->_tmp36_, 0);
		_g_object_unref0 (_data_->current_oldest);
		_data_->current_oldest = (GearyEmail*) _data_->_tmp37_;
	}
	_data_->_tmp39_ = _data_->current_oldest;
	if (_data_->_tmp39_ != NULL) {
		_data_->_tmp40_ = _data_->current_oldest;
		_data_->_tmp41_ = geary_email_get_properties (_data_->_tmp40_);
		_data_->_tmp42_ = _data_->_tmp41_;
		_data_->_tmp43_ = geary_email_properties_get_date_received (_data_->_tmp42_);
		_data_->_tmp44_ = _data_->_tmp43_;
		_data_->_tmp38_ = _data_->_tmp44_;
	} else {
		_data_->_tmp38_ = NULL;
	}
	_data_->_tmp45_ = _g_date_time_ref0 (_data_->_tmp38_);
	_data_->oldest_date = _data_->_tmp45_;
	_data_->_tmp46_ = _data_->oldest_date;
	if (_data_->_tmp46_ == NULL) {
		_data_->_tmp47_ = g_date_time_new_now_local ();
		_g_date_time_unref0 (_data_->oldest_date);
		_data_->oldest_date = _data_->_tmp47_;
	}
	_data_->_tmp48_ = _data_->oldest_date;
	_data_->_tmp49_ = _g_date_time_ref0 (_data_->_tmp48_);
	_data_->next_epoch = _data_->_tmp49_;
	while (TRUE) {
		_data_->_tmp50_ = _data_->next_epoch;
		if (!(g_date_time_compare (_data_->_tmp50_, _data_->max_epoch) > 0)) {
			break;
		}
		_data_->_tmp51_ = _data_->local_folder;
		_data_->_state_ = 3;
		geary_imap_db_folder_get_email_count_async (_data_->_tmp51_, GEARY_IMAP_DB_FOLDER_LIST_FLAGS_NONE, _data_->cancellable, geary_imap_engine_full_folder_sync_sync_folder_ready, _data_);
		return FALSE;
		_state_3:
		_data_->local_count = geary_imap_db_folder_get_email_count_finish (_data_->_tmp51_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_date_time_unref0 (_data_->next_epoch);
			_g_date_time_unref0 (_data_->oldest_date);
			_g_object_unref0 (_data_->current_oldest);
			_g_object_unref0 (_data_->list);
			_g_object_unref0 (_data_->local_folder);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp52_ = _data_->next_epoch;
		_data_->_tmp53_ = g_date_time_add_months (_data_->_tmp52_, -3);
		_g_date_time_unref0 (_data_->next_epoch);
		_data_->next_epoch = _data_->_tmp53_;
		_data_->_tmp54_ = _data_->next_epoch;
		if (g_date_time_compare (_data_->_tmp54_, _data_->max_epoch) < 0) {
			_data_->_tmp55_ = _g_date_time_ref0 (_data_->max_epoch);
			_g_date_time_unref0 (_data_->next_epoch);
			_data_->next_epoch = _data_->_tmp55_;
		}
		_data_->_tmp56_ = _data_->next_epoch;
		_data_->_tmp57_ = g_date_time_to_string (_data_->_tmp56_);
		_data_->_tmp58_ = _data_->_tmp57_;
		geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Fetching to: %s", _data_->_tmp58_);
		_g_free0 (_data_->_tmp58_);
		_data_->_tmp60_ = geary_imap_engine_folder_operation_get_folder (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_FOLDER_OPERATION, GearyImapEngineFolderOperation));
		_data_->_tmp61_ = _data_->_tmp60_;
		_data_->_tmp62_ = geary_folder_get_properties (_data_->_tmp61_);
		_data_->_tmp63_ = _data_->_tmp62_;
		_data_->_tmp64_ = geary_folder_properties_get_email_total (_data_->_tmp63_);
		_data_->_tmp65_ = _data_->_tmp64_;
		if (_data_->local_count < _data_->_tmp65_) {
			_data_->_tmp66_ = _data_->next_epoch;
			_data_->_tmp59_ = g_date_time_compare (_data_->_tmp66_, _data_->max_epoch) >= 0;
		} else {
			_data_->_tmp59_ = FALSE;
		}
		if (_data_->_tmp59_) {
			_data_->_tmp67_ = _data_->next_epoch;
			_data_->_tmp68_ = geary_imap_engine_folder_sync_get_sync_max_epoch (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_FOLDER_SYNC, GearyImapEngineFolderSync));
			_data_->_tmp69_ = _data_->_tmp68_;
			if (g_date_time_compare (_data_->_tmp67_, _data_->_tmp69_) > 0) {
				_data_->_tmp71_ = _data_->next_epoch;
				_data_->_tmp72_ = _data_->current_oldest;
				_data_->_state_ = 4;
				geary_imap_engine_full_folder_sync_expand_vector (_data_->self, _data_->_tmp71_, _data_->_tmp72_, _data_->cancellable, geary_imap_engine_full_folder_sync_sync_folder_ready, _data_);
				return FALSE;
				_state_4:
				_data_->_tmp73_ = geary_imap_engine_full_folder_sync_expand_vector_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
				_data_->_tmp70_ = _data_->_tmp73_;
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
					_g_date_time_unref0 (_data_->next_epoch);
					_g_date_time_unref0 (_data_->oldest_date);
					_g_object_unref0 (_data_->current_oldest);
					_g_object_unref0 (_data_->list);
					_g_object_unref0 (_data_->local_folder);
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
				_data_->_tmp74_ = _data_->_tmp70_;
				_data_->_tmp70_ = NULL;
				_g_object_unref0 (_data_->current_oldest);
				_data_->current_oldest = _data_->_tmp74_;
				_data_->_tmp76_ = _data_->current_oldest;
				if (_data_->_tmp76_ == NULL) {
					_data_->_tmp77_ = _data_->next_epoch;
					_data_->_tmp75_ = g_date_time_equal (_data_->_tmp77_, _data_->max_epoch);
				} else {
					_data_->_tmp75_ = FALSE;
				}
				if (_data_->_tmp75_) {
					_data_->_tmp78_ = _data_->current_oldest;
					_data_->_state_ = 5;
					geary_imap_engine_full_folder_sync_expand_to_previous (_data_->self, _data_->_tmp78_, _data_->cancellable, geary_imap_engine_full_folder_sync_sync_folder_ready, _data_);
					return FALSE;
					_state_5:
					geary_imap_engine_full_folder_sync_expand_to_previous_finish (_data_->self, _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_->_tmp70_);
						_g_date_time_unref0 (_data_->next_epoch);
						_g_date_time_unref0 (_data_->oldest_date);
						_g_object_unref0 (_data_->current_oldest);
						_g_object_unref0 (_data_->list);
						_g_object_unref0 (_data_->local_folder);
						g_object_unref (_data_->_async_result);
						return FALSE;
					}
					_data_->_tmp79_ = g_date_time_add_days (_data_->max_epoch, -1);
					_g_date_time_unref0 (_data_->next_epoch);
					_data_->next_epoch = _data_->_tmp79_;
				}
				_g_object_unref0 (_data_->_tmp70_);
			} else {
				_data_->_state_ = 6;
				geary_imap_engine_full_folder_sync_expand_complete_vector (_data_->self, _data_->cancellable, geary_imap_engine_full_folder_sync_sync_folder_ready, _data_);
				return FALSE;
				_state_6:
				geary_imap_engine_full_folder_sync_expand_complete_vector_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
					_g_date_time_unref0 (_data_->next_epoch);
					_g_date_time_unref0 (_data_->oldest_date);
					_g_object_unref0 (_data_->current_oldest);
					_g_object_unref0 (_data_->list);
					_g_object_unref0 (_data_->local_folder);
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
				_data_->_tmp80_ = g_date_time_add_days (_data_->max_epoch, -1);
				_g_date_time_unref0 (_data_->next_epoch);
				_data_->next_epoch = _data_->_tmp80_;
			}
		} else {
			_data_->_tmp81_ = g_date_time_add_days (_data_->max_epoch, -1);
			_g_date_time_unref0 (_data_->next_epoch);
			_data_->next_epoch = _data_->_tmp81_;
		}
		_data_->_state_ = 7;
		GEARY_IMAP_ENGINE_FOLDER_SYNC_CLASS (geary_imap_engine_full_folder_sync_parent_class)->sync_folder (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_REFRESH_FOLDER_SYNC, GearyImapEngineRefreshFolderSync), GEARY_IMAP_ENGINE_TYPE_FOLDER_SYNC, GearyImapEngineFolderSync), _data_->max_epoch, _data_->cancellable, geary_imap_engine_full_folder_sync_sync_folder_ready, _data_);
		return FALSE;
		_state_7:
		GEARY_IMAP_ENGINE_FOLDER_SYNC_CLASS (geary_imap_engine_full_folder_sync_parent_class)->sync_folder_finish (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_REFRESH_FOLDER_SYNC, GearyImapEngineRefreshFolderSync), GEARY_IMAP_ENGINE_TYPE_FOLDER_SYNC, GearyImapEngineFolderSync), _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_date_time_unref0 (_data_->next_epoch);
			_g_date_time_unref0 (_data_->oldest_date);
			_g_object_unref0 (_data_->current_oldest);
			_g_object_unref0 (_data_->list);
			_g_object_unref0 (_data_->local_folder);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_g_date_time_unref0 (_data_->next_epoch);
	_g_date_time_unref0 (_data_->oldest_date);
	_g_object_unref0 (_data_->current_oldest);
	_g_object_unref0 (_data_->list);
	_g_object_unref0 (_data_->local_folder);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_engine_full_folder_sync_expand_vector_data_free (gpointer _data)
{
	GearyImapEngineFullFolderSyncExpandVectorData* _data_;
	_data_ = _data;
	_g_date_time_unref0 (_data_->next_epoch);
	_g_object_unref0 (_data_->current_oldest);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapEngineFullFolderSyncExpandVectorData, _data_);
}

static void
geary_imap_engine_full_folder_sync_expand_vector (GearyImapEngineFullFolderSync* self,
                                                  GDateTime* next_epoch,
                                                  GearyEmail* current_oldest,
                                                  GCancellable* cancellable,
                                                  GAsyncReadyCallback _callback_,
                                                  gpointer _user_data_)
{
	GearyImapEngineFullFolderSyncExpandVectorData* _data_;
	GearyImapEngineFullFolderSync* _tmp0_;
	GDateTime* _tmp1_;
	GearyEmail* _tmp2_;
	GCancellable* _tmp3_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_FULL_FOLDER_SYNC (self));
	g_return_if_fail (next_epoch != NULL);
	g_return_if_fail ((current_oldest == NULL) || GEARY_IS_EMAIL (current_oldest));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapEngineFullFolderSyncExpandVectorData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_engine_full_folder_sync_expand_vector_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_date_time_ref0 (next_epoch);
	_g_date_time_unref0 (_data_->next_epoch);
	_data_->next_epoch = _tmp1_;
	_tmp2_ = _g_object_ref0 (current_oldest);
	_g_object_unref0 (_data_->current_oldest);
	_data_->current_oldest = _tmp2_;
	_tmp3_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp3_;
	geary_imap_engine_full_folder_sync_expand_vector_co (_data_);
}

static GearyEmail*
geary_imap_engine_full_folder_sync_expand_vector_finish (GearyImapEngineFullFolderSync* self,
                                                         GAsyncResult* _res_,
                                                         GError** error)
{
	GearyEmail* result;
	GearyImapEngineFullFolderSyncExpandVectorData* _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_engine_full_folder_sync_expand_vector_ready (GObject* source_object,
                                                        GAsyncResult* _res_,
                                                        gpointer _user_data_)
{
	GearyImapEngineFullFolderSyncExpandVectorData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_engine_full_folder_sync_expand_vector_co (_data_);
}

static gboolean
geary_imap_engine_full_folder_sync_expand_vector_co (GearyImapEngineFullFolderSyncExpandVectorData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = g_date_time_to_string (_data_->next_epoch);
	_data_->_tmp1_ = _data_->_tmp0_;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Expanding vector to %s", _data_->_tmp1_);
	_g_free0 (_data_->_tmp1_);
	if (_data_->current_oldest != NULL) {
		_data_->_tmp3_ = geary_email_get_id (_data_->current_oldest);
		_data_->_tmp4_ = _data_->_tmp3_;
		_data_->_tmp2_ = _data_->_tmp4_;
	} else {
		_data_->_tmp2_ = NULL;
	}
	_data_->_tmp6_ = geary_imap_engine_folder_operation_get_folder (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_FOLDER_OPERATION, GearyImapEngineFolderOperation));
	_data_->_tmp7_ = _data_->_tmp6_;
	_data_->_state_ = 1;
	geary_imap_engine_minimal_folder_find_earliest_email_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp7_, GEARY_IMAP_ENGINE_TYPE_MINIMAL_FOLDER, GearyImapEngineMinimalFolder), _data_->next_epoch, _data_->_tmp2_, _data_->cancellable, geary_imap_engine_full_folder_sync_expand_vector_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp8_ = geary_imap_engine_minimal_folder_find_earliest_email_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp7_, GEARY_IMAP_ENGINE_TYPE_MINIMAL_FOLDER, GearyImapEngineMinimalFolder), _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp5_ = _data_->_tmp8_;
	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_->_tmp9_ = _data_->_tmp5_;
	_data_->_tmp5_ = NULL;
	_data_->result = _data_->_tmp9_;
	_g_object_unref0 (_data_->_tmp5_);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_engine_full_folder_sync_expand_to_previous_data_free (gpointer _data)
{
	GearyImapEngineFullFolderSyncExpandToPreviousData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->current_oldest);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapEngineFullFolderSyncExpandToPreviousData, _data_);
}

static void
geary_imap_engine_full_folder_sync_expand_to_previous (GearyImapEngineFullFolderSync* self,
                                                       GearyEmail* current_oldest,
                                                       GCancellable* cancellable,
                                                       GAsyncReadyCallback _callback_,
                                                       gpointer _user_data_)
{
	GearyImapEngineFullFolderSyncExpandToPreviousData* _data_;
	GearyImapEngineFullFolderSync* _tmp0_;
	GearyEmail* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_FULL_FOLDER_SYNC (self));
	g_return_if_fail ((current_oldest == NULL) || GEARY_IS_EMAIL (current_oldest));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapEngineFullFolderSyncExpandToPreviousData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_engine_full_folder_sync_expand_to_previous_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (current_oldest);
	_g_object_unref0 (_data_->current_oldest);
	_data_->current_oldest = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_engine_full_folder_sync_expand_to_previous_co (_data_);
}

static void
geary_imap_engine_full_folder_sync_expand_to_previous_finish (GearyImapEngineFullFolderSync* self,
                                                              GAsyncResult* _res_,
                                                              GError** error)
{
	GearyImapEngineFullFolderSyncExpandToPreviousData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
geary_imap_engine_full_folder_sync_expand_to_previous_ready (GObject* source_object,
                                                             GAsyncResult* _res_,
                                                             gpointer _user_data_)
{
	GearyImapEngineFullFolderSyncExpandToPreviousData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_engine_full_folder_sync_expand_to_previous_co (_data_);
}

static gboolean
geary_imap_engine_full_folder_sync_expand_to_previous_co (GearyImapEngineFullFolderSyncExpandToPreviousData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (_data_->current_oldest != NULL) {
		_data_->_tmp1_ = geary_email_get_id (_data_->current_oldest);
		_data_->_tmp2_ = _data_->_tmp1_;
		_data_->_tmp0_ = _data_->_tmp2_;
	} else {
		_data_->_tmp0_ = NULL;
	}
	_data_->_tmp3_ = _g_object_ref0 (_data_->_tmp0_);
	_data_->id = _data_->_tmp3_;
	_data_->_tmp5_ = _data_->id;
	if (_data_->_tmp5_ != NULL) {
		_data_->_tmp4_ = " earlier than oldest local";
	} else {
		_data_->_tmp4_ = "";
	}
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Unable to locate epoch messages on remote folder%s, fetching one past " \
"oldest...", _data_->_tmp4_);
	_data_->_tmp6_ = geary_imap_engine_folder_operation_get_folder (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_FOLDER_OPERATION, GearyImapEngineFolderOperation));
	_data_->_tmp7_ = _data_->_tmp6_;
	_data_->_tmp8_ = _data_->id;
	_data_->_state_ = 1;
	geary_folder_list_email_by_id_async (_data_->_tmp7_, _data_->_tmp8_, 1, GEARY_EMAIL_FIELD_NONE, GEARY_FOLDER_LIST_FLAGS_NONE, _data_->cancellable, geary_imap_engine_full_folder_sync_expand_to_previous_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp9_ = geary_folder_list_email_by_id_finish (_data_->_tmp7_, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp10_ = _data_->_tmp9_;
	_g_object_unref0 (_data_->_tmp10_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->id);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_object_unref0 (_data_->id);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

static void
geary_imap_engine_full_folder_sync_expand_complete_vector (GearyImapEngineFullFolderSync* self,
                                                           GCancellable* cancellable,
                                                           GAsyncReadyCallback _callback_,
                                                           gpointer _user_data_)
{
	GearyImapEngineFullFolderSyncExpandCompleteVectorData* _data_;
	GearyImapEngineFullFolderSync* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_FULL_FOLDER_SYNC (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyImapEngineFullFolderSyncExpandCompleteVectorData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_engine_full_folder_sync_expand_complete_vector_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_engine_full_folder_sync_expand_complete_vector_co (_data_);
}

static void
geary_imap_engine_full_folder_sync_expand_complete_vector_finish (GearyImapEngineFullFolderSync* self,
                                                                  GAsyncResult* _res_,
                                                                  GError** error)
{
	GearyImapEngineFullFolderSyncExpandCompleteVectorData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
geary_imap_engine_full_folder_sync_expand_complete_vector_ready (GObject* source_object,
                                                                 GAsyncResult* _res_,
                                                                 gpointer _user_data_)
{
	GearyImapEngineFullFolderSyncExpandCompleteVectorData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_engine_full_folder_sync_expand_complete_vector_co (_data_);
}

static gboolean
geary_imap_engine_full_folder_sync_expand_complete_vector_co (GearyImapEngineFullFolderSyncExpandCompleteVectorData* _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_engine_folder_sync_get_sync_max_epoch (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_FOLDER_SYNC, GearyImapEngineFolderSync));
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = g_date_time_to_string (_data_->_tmp1_);
	_data_->_tmp3_ = _data_->_tmp2_;
	geary_logging_source_debug (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_LOGGING_TYPE_SOURCE, GearyLoggingSource), "Reached max epoch of %s, fetching all mail", _data_->_tmp3_);
	_g_free0 (_data_->_tmp3_);
	_data_->_tmp4_ = geary_imap_engine_folder_operation_get_folder (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_FOLDER_OPERATION, GearyImapEngineFolderOperation));
	_data_->_tmp5_ = _data_->_tmp4_;
	_data_->_state_ = 1;
	geary_folder_list_email_by_id_async (_data_->_tmp5_, NULL, G_MAXINT, GEARY_EMAIL_FIELD_NONE, GEARY_FOLDER_LIST_FLAGS_NONE, _data_->cancellable, geary_imap_engine_full_folder_sync_expand_complete_vector_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp6_ = geary_folder_list_email_by_id_finish (_data_->_tmp5_, _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_unref (_data_->_async_result);
		return FALSE;
	}
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_engine_full_folder_sync_class_init (GearyImapEngineFullFolderSyncClass * klass,
                                               gpointer klass_data)
{
	geary_imap_engine_full_folder_sync_parent_class = g_type_class_peek_parent (klass);
	((GearyImapEngineFolderSyncClass *) klass)->sync_folder = (void (*) (GearyImapEngineFolderSync*, GDateTime*, GCancellable*, GAsyncReadyCallback, gpointer)) geary_imap_engine_full_folder_sync_real_sync_folder;
	((GearyImapEngineFolderSyncClass *) klass)->sync_folder_finish = (void (*) (GearyImapEngineFolderSync*, GAsyncResult*, GError**)) geary_imap_engine_full_folder_sync_sync_folder_finish;
}

static void
geary_imap_engine_full_folder_sync_instance_init (GearyImapEngineFullFolderSync * self,
                                                  gpointer klass)
{
}

/**
 * Refreshes folder contents and ensures its vector extends to the epoch.
 *
 * This synchronisation process performs the same work as its base
 * class, but also ensures enough mail has been fetched to satisfy the
 * account's prefetch period, by checking the earliest mail in the
 * folder and if later than the maximum prefetch epoch, expands the
 * folder's vector until it does.
 *
 * It also truncates email that extends past the epoch, ensuring no
 * more email is stored than is desired.
 */
 G_GNUC_NO_INLINE static GType
geary_imap_engine_full_folder_sync_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapEngineFullFolderSyncClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_engine_full_folder_sync_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapEngineFullFolderSync), 0, (GInstanceInitFunc) geary_imap_engine_full_folder_sync_instance_init, NULL };
	GType geary_imap_engine_full_folder_sync_type_id;
	geary_imap_engine_full_folder_sync_type_id = g_type_register_static (GEARY_IMAP_ENGINE_TYPE_REFRESH_FOLDER_SYNC, "GearyImapEngineFullFolderSync", &g_define_type_info, 0);
	return geary_imap_engine_full_folder_sync_type_id;
}

GType
geary_imap_engine_full_folder_sync_get_type (void)
{
	static gsize geary_imap_engine_full_folder_sync_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_engine_full_folder_sync_type_id__once)) {
		GType geary_imap_engine_full_folder_sync_type_id;
		geary_imap_engine_full_folder_sync_type_id = geary_imap_engine_full_folder_sync_get_type_once ();
		g_once_init_leave (&geary_imap_engine_full_folder_sync_type_id__once, geary_imap_engine_full_folder_sync_type_id);
	}
	return geary_imap_engine_full_folder_sync_type_id__once;
}

static inline gpointer
geary_imap_engine_truncate_to_epoch_folder_sync_get_instance_private (GearyImapEngineTruncateToEpochFolderSync* self)
{
	return G_STRUCT_MEMBER_P (self, GearyImapEngineTruncateToEpochFolderSync_private_offset);
}

GearyImapEngineTruncateToEpochFolderSync*
geary_imap_engine_truncate_to_epoch_folder_sync_construct (GType object_type,
                                                           GearyImapEngineGenericAccount* account,
                                                           GearyImapEngineMinimalFolder* folder,
                                                           GDateTime* sync_max_epoch,
                                                           GearyImapEngineIdleGarbageCollection* post_idle_detach_op)
{
	GearyImapEngineTruncateToEpochFolderSync * self = NULL;
	GearyImapEngineIdleGarbageCollection* _tmp0_;
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_GENERIC_ACCOUNT (account), NULL);
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_MINIMAL_FOLDER (folder), NULL);
	g_return_val_if_fail (sync_max_epoch != NULL, NULL);
	g_return_val_if_fail ((post_idle_detach_op == NULL) || GEARY_IMAP_ENGINE_IS_IDLE_GARBAGE_COLLECTION (post_idle_detach_op), NULL);
	self = (GearyImapEngineTruncateToEpochFolderSync*) geary_imap_engine_folder_sync_construct (object_type, account, folder, sync_max_epoch, GEARY_FOLDER_OPEN_FLAGS_NONE);
	_tmp0_ = _g_object_ref0 (post_idle_detach_op);
	_g_object_unref0 (self->priv->post_idle_detach_op);
	self->priv->post_idle_detach_op = _tmp0_;
	return self;
}

GearyImapEngineTruncateToEpochFolderSync*
geary_imap_engine_truncate_to_epoch_folder_sync_new (GearyImapEngineGenericAccount* account,
                                                     GearyImapEngineMinimalFolder* folder,
                                                     GDateTime* sync_max_epoch,
                                                     GearyImapEngineIdleGarbageCollection* post_idle_detach_op)
{
	return geary_imap_engine_truncate_to_epoch_folder_sync_construct (GEARY_IMAP_ENGINE_TYPE_TRUNCATE_TO_EPOCH_FOLDER_SYNC, account, folder, sync_max_epoch, post_idle_detach_op);
}

static void
geary_imap_engine_truncate_to_epoch_folder_sync_real_sync_folder_data_free (gpointer _data)
{
	GearyImapEngineTruncateToEpochFolderSyncSyncFolderData* _data_;
	_data_ = _data;
	_g_date_time_unref0 (_data_->max_epoch);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyImapEngineTruncateToEpochFolderSyncSyncFolderData, _data_);
}

static void
geary_imap_engine_truncate_to_epoch_folder_sync_real_sync_folder (GearyImapEngineFolderSync* base,
                                                                  GDateTime* max_epoch,
                                                                  GCancellable* cancellable,
                                                                  GAsyncReadyCallback _callback_,
                                                                  gpointer _user_data_)
{
	GearyImapEngineTruncateToEpochFolderSync * self;
	GearyImapEngineTruncateToEpochFolderSyncSyncFolderData* _data_;
	GearyImapEngineTruncateToEpochFolderSync* _tmp0_;
	GDateTime* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (max_epoch != NULL);
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_TYPE_TRUNCATE_TO_EPOCH_FOLDER_SYNC, GearyImapEngineTruncateToEpochFolderSync);
	_data_ = g_slice_new0 (GearyImapEngineTruncateToEpochFolderSyncSyncFolderData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_engine_truncate_to_epoch_folder_sync_real_sync_folder_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_date_time_ref0 (max_epoch);
	_g_date_time_unref0 (_data_->max_epoch);
	_data_->max_epoch = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	geary_imap_engine_truncate_to_epoch_folder_sync_real_sync_folder_co (_data_);
}

static void
geary_imap_engine_truncate_to_epoch_folder_sync_sync_folder_finish (GearyImapEngineFolderSync* base,
                                                                    GAsyncResult* _res_,
                                                                    GError** error)
{
	GearyImapEngineTruncateToEpochFolderSyncSyncFolderData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
geary_imap_engine_truncate_to_epoch_folder_sync_sync_folder_ready (GObject* source_object,
                                                                   GAsyncResult* _res_,
                                                                   gpointer _user_data_)
{
	GearyImapEngineTruncateToEpochFolderSyncSyncFolderData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_engine_truncate_to_epoch_folder_sync_real_sync_folder_co (_data_);
}

static gboolean
geary_imap_engine_truncate_to_epoch_folder_sync_real_sync_folder_co (GearyImapEngineTruncateToEpochFolderSyncSyncFolderData* _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_engine_folder_operation_get_folder (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_FOLDER_OPERATION, GearyImapEngineFolderOperation));
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = geary_imap_engine_minimal_folder_get_local_folder (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, GEARY_IMAP_ENGINE_TYPE_MINIMAL_FOLDER, GearyImapEngineMinimalFolder));
	_data_->_tmp3_ = _data_->_tmp2_;
	_data_->_tmp4_ = _g_object_ref0 (_data_->_tmp3_);
	_data_->local_folder = _data_->_tmp4_;
	_data_->_tmp5_ = geary_imap_engine_account_operation_get_account (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, GearyImapEngineAccountOperation));
	_data_->_tmp6_ = _data_->_tmp5_;
	_data_->_tmp7_ = geary_account_get_information (_data_->_tmp6_);
	_data_->_tmp8_ = _data_->_tmp7_;
	_data_->_tmp9_ = geary_account_information_get_prefetch_period_days (_data_->_tmp8_);
	_data_->_tmp10_ = _data_->_tmp9_;
	if (_data_->_tmp10_ >= 0) {
		_data_->_tmp11_ = _data_->local_folder;
		_data_->_state_ = 1;
		geary_imap_db_folder_detach_emails_before_timestamp (_data_->_tmp11_, _data_->max_epoch, _data_->cancellable, geary_imap_engine_truncate_to_epoch_folder_sync_sync_folder_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp12_ = geary_imap_db_folder_detach_emails_before_timestamp_finish (_data_->_tmp11_, _data_->_res_, &_data_->_inner_error0_);
		_data_->detached_ids = _data_->_tmp12_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->local_folder);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp13_ = _data_->detached_ids;
		if (_data_->_tmp13_ != NULL) {
			_data_->_tmp14_ = geary_imap_engine_account_operation_get_account (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, GearyImapEngineAccountOperation));
			_data_->_tmp15_ = _data_->_tmp14_;
			_data_->_tmp16_ = geary_imap_engine_folder_operation_get_folder (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_FOLDER_OPERATION, GearyImapEngineFolderOperation));
			_data_->_tmp17_ = _data_->_tmp16_;
			_data_->_tmp18_ = _data_->detached_ids;
			g_signal_emit_by_name (_data_->_tmp15_, "email-locally-removed", _data_->_tmp17_, _data_->_tmp18_);
			_data_->_tmp19_ = geary_imap_engine_folder_operation_get_folder (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_FOLDER_OPERATION, GearyImapEngineFolderOperation));
			_data_->_tmp20_ = _data_->_tmp19_;
			_data_->_tmp21_ = _data_->detached_ids;
			g_signal_emit_by_name (_data_->_tmp20_, "email-locally-removed", _data_->_tmp21_);
			_data_->_tmp22_ = _data_->self->priv->post_idle_detach_op;
			geary_imap_engine_idle_garbage_collection_messages_detached (_data_->_tmp22_);
		}
		_g_object_unref0 (_data_->detached_ids);
	}
	_g_object_unref0 (_data_->local_folder);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_imap_engine_truncate_to_epoch_folder_sync_class_init (GearyImapEngineTruncateToEpochFolderSyncClass * klass,
                                                            gpointer klass_data)
{
	geary_imap_engine_truncate_to_epoch_folder_sync_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GearyImapEngineTruncateToEpochFolderSync_private_offset);
	((GearyImapEngineFolderSyncClass *) klass)->sync_folder = (void (*) (GearyImapEngineFolderSync*, GDateTime*, GCancellable*, GAsyncReadyCallback, gpointer)) geary_imap_engine_truncate_to_epoch_folder_sync_real_sync_folder;
	((GearyImapEngineFolderSyncClass *) klass)->sync_folder_finish = (void (*) (GearyImapEngineFolderSync*, GAsyncResult*, GError**)) geary_imap_engine_truncate_to_epoch_folder_sync_sync_folder_finish;
	G_OBJECT_CLASS (klass)->finalize = geary_imap_engine_truncate_to_epoch_folder_sync_finalize;
}

static void
geary_imap_engine_truncate_to_epoch_folder_sync_instance_init (GearyImapEngineTruncateToEpochFolderSync * self,
                                                               gpointer klass)
{
	self->priv = geary_imap_engine_truncate_to_epoch_folder_sync_get_instance_private (self);
}

static void
geary_imap_engine_truncate_to_epoch_folder_sync_finalize (GObject * obj)
{
	GearyImapEngineTruncateToEpochFolderSync * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_IMAP_ENGINE_TYPE_TRUNCATE_TO_EPOCH_FOLDER_SYNC, GearyImapEngineTruncateToEpochFolderSync);
	_g_object_unref0 (self->priv->post_idle_detach_op);
	G_OBJECT_CLASS (geary_imap_engine_truncate_to_epoch_folder_sync_parent_class)->finalize (obj);
}

/**
 * Removes any email locally from folder that extends past the epoch.
 *
 * This synchronisation operation ensures that the folder's vector
 * does not extend pass the epoch, ensuring no more email is stored
 * than is desired.
 */
 G_GNUC_NO_INLINE static GType
geary_imap_engine_truncate_to_epoch_folder_sync_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapEngineTruncateToEpochFolderSyncClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_engine_truncate_to_epoch_folder_sync_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapEngineTruncateToEpochFolderSync), 0, (GInstanceInitFunc) geary_imap_engine_truncate_to_epoch_folder_sync_instance_init, NULL };
	GType geary_imap_engine_truncate_to_epoch_folder_sync_type_id;
	geary_imap_engine_truncate_to_epoch_folder_sync_type_id = g_type_register_static (GEARY_IMAP_ENGINE_TYPE_FOLDER_SYNC, "GearyImapEngineTruncateToEpochFolderSync", &g_define_type_info, 0);
	GearyImapEngineTruncateToEpochFolderSync_private_offset = g_type_add_instance_private (geary_imap_engine_truncate_to_epoch_folder_sync_type_id, sizeof (GearyImapEngineTruncateToEpochFolderSyncPrivate));
	return geary_imap_engine_truncate_to_epoch_folder_sync_type_id;
}

GType
geary_imap_engine_truncate_to_epoch_folder_sync_get_type (void)
{
	static gsize geary_imap_engine_truncate_to_epoch_folder_sync_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_engine_truncate_to_epoch_folder_sync_type_id__once)) {
		GType geary_imap_engine_truncate_to_epoch_folder_sync_type_id;
		geary_imap_engine_truncate_to_epoch_folder_sync_type_id = geary_imap_engine_truncate_to_epoch_folder_sync_get_type_once ();
		g_once_init_leave (&geary_imap_engine_truncate_to_epoch_folder_sync_type_id__once, geary_imap_engine_truncate_to_epoch_folder_sync_type_id);
	}
	return geary_imap_engine_truncate_to_epoch_folder_sync_type_id__once;
}

GearyImapEngineForegroundGarbageCollection*
geary_imap_engine_foreground_garbage_collection_construct (GType object_type,
                                                           GearyImapEngineGenericAccount* account)
{
	GearyImapEngineForegroundGarbageCollection * self = NULL;
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_GENERIC_ACCOUNT (account), NULL);
	self = (GearyImapEngineForegroundGarbageCollection*) geary_imap_engine_account_operation_construct (object_type, G_TYPE_CHECK_INSTANCE_CAST (account, GEARY_TYPE_ACCOUNT, GearyAccount));
	return self;
}

GearyImapEngineForegroundGarbageCollection*
geary_imap_engine_foreground_garbage_collection_new (GearyImapEngineGenericAccount* account)
{
	return geary_imap_engine_foreground_garbage_collection_construct (GEARY_IMAP_ENGINE_TYPE_FOREGROUND_GARBAGE_COLLECTION, account);
}

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

static void
geary_imap_engine_foreground_garbage_collection_real_execute (GearyImapEngineAccountOperation* base,
                                                              GCancellable* cancellable,
                                                              GAsyncReadyCallback _callback_,
                                                              gpointer _user_data_)
{
	GearyImapEngineForegroundGarbageCollection * self;
	GearyImapEngineForegroundGarbageCollectionExecuteData* _data_;
	GearyImapEngineForegroundGarbageCollection* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_TYPE_FOREGROUND_GARBAGE_COLLECTION, GearyImapEngineForegroundGarbageCollection);
	_data_ = g_slice_new0 (GearyImapEngineForegroundGarbageCollectionExecuteData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_engine_foreground_garbage_collection_real_execute_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_engine_foreground_garbage_collection_real_execute_co (_data_);
}

static void
geary_imap_engine_foreground_garbage_collection_execute_finish (GearyImapEngineAccountOperation* base,
                                                                GAsyncResult* _res_,
                                                                GError** error)
{
	GearyImapEngineForegroundGarbageCollectionExecuteData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
geary_imap_engine_foreground_garbage_collection_execute_ready (GObject* source_object,
                                                               GAsyncResult* _res_,
                                                               gpointer _user_data_)
{
	GearyImapEngineForegroundGarbageCollectionExecuteData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_imap_engine_foreground_garbage_collection_real_execute_co (_data_);
}

static gboolean
geary_imap_engine_foreground_garbage_collection_real_execute_co (GearyImapEngineForegroundGarbageCollectionExecuteData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (g_cancellable_is_cancelled (_data_->cancellable)) {
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp0_ = geary_imap_engine_account_operation_get_account (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, GearyImapEngineAccountOperation));
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, GEARY_IMAP_ENGINE_TYPE_GENERIC_ACCOUNT, GearyImapEngineGenericAccount));
	_data_->generic_account = _data_->_tmp2_;
	_data_->_tmp3_ = _data_->generic_account;
	_data_->_tmp4_ = geary_imap_engine_generic_account_get_local (_data_->_tmp3_);
	_data_->_tmp5_ = _data_->_tmp4_;
	_data_->_tmp6_ = geary_imap_db_account_get_db (_data_->_tmp5_);
	_data_->_tmp7_ = _data_->_tmp6_;
	_data_->_state_ = 1;
	geary_imap_db_database_run_gc (_data_->_tmp7_, GEARY_IMAP_DB_DATABASE_GARBAGE_COLLECTION_OPTIONS_NONE, NULL, _data_->cancellable, geary_imap_engine_foreground_garbage_collection_execute_ready, _data_);
	return FALSE;
	_state_1:
	geary_imap_db_database_run_gc_finish (_data_->_tmp7_, _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_->generic_account);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_object_unref0 (_data_->generic_account);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static gboolean
geary_imap_engine_foreground_garbage_collection_real_equal_to (GearyImapEngineAccountOperation* base,
                                                               GearyImapEngineAccountOperation* op)
{
	GearyImapEngineForegroundGarbageCollection * self;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_TYPE_FOREGROUND_GARBAGE_COLLECTION, GearyImapEngineForegroundGarbageCollection);
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_ACCOUNT_OPERATION (op), FALSE);
	if (op != NULL) {
		gboolean _tmp2_ = FALSE;
		if (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, GearyImapEngineAccountOperation) == op) {
			_tmp2_ = TRUE;
		} else {
			_tmp2_ = G_TYPE_FROM_INSTANCE (G_TYPE_CHECK_INSTANCE_CAST (self, G_TYPE_OBJECT, GObject)) == G_TYPE_FROM_INSTANCE (G_TYPE_CHECK_INSTANCE_CAST (op, G_TYPE_OBJECT, GObject));
		}
		_tmp1_ = _tmp2_;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		GearyAccount* _tmp3_;
		GearyAccount* _tmp4_;
		GearyAccount* _tmp5_;
		GearyAccount* _tmp6_;
		_tmp3_ = geary_imap_engine_account_operation_get_account (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, GearyImapEngineAccountOperation));
		_tmp4_ = _tmp3_;
		_tmp5_ = geary_imap_engine_account_operation_get_account (op);
		_tmp6_ = _tmp5_;
		_tmp0_ = _tmp4_ == _tmp6_;
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

static void
geary_imap_engine_foreground_garbage_collection_class_init (GearyImapEngineForegroundGarbageCollectionClass * klass,
                                                            gpointer klass_data)
{
	geary_imap_engine_foreground_garbage_collection_parent_class = g_type_class_peek_parent (klass);
	((GearyImapEngineAccountOperationClass *) klass)->execute = (void (*) (GearyImapEngineAccountOperation*, GCancellable*, GAsyncReadyCallback, gpointer)) geary_imap_engine_foreground_garbage_collection_real_execute;
	((GearyImapEngineAccountOperationClass *) klass)->execute_finish = (void (*) (GearyImapEngineAccountOperation*, GAsyncResult*, GError**)) geary_imap_engine_foreground_garbage_collection_execute_finish;
	((GearyImapEngineAccountOperationClass *) klass)->equal_to = (gboolean (*) (GearyImapEngineAccountOperation*, GearyImapEngineAccountOperation*)) geary_imap_engine_foreground_garbage_collection_real_equal_to;
}

static void
geary_imap_engine_foreground_garbage_collection_instance_init (GearyImapEngineForegroundGarbageCollection * self,
                                                               gpointer klass)
{
}

/**
 * Kicks off garbage collection after old messages have been removed.
 *
 * Queues a basic GC run which will run if old messages were detached
 * after a folder became available. Not used for backgrounded account
 * storage operations, which are handled instead by the
 * {@link IdleGarbageCollection}.
 */
 G_GNUC_NO_INLINE static GType
geary_imap_engine_foreground_garbage_collection_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapEngineForegroundGarbageCollectionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_engine_foreground_garbage_collection_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapEngineForegroundGarbageCollection), 0, (GInstanceInitFunc) geary_imap_engine_foreground_garbage_collection_instance_init, NULL };
	GType geary_imap_engine_foreground_garbage_collection_type_id;
	geary_imap_engine_foreground_garbage_collection_type_id = g_type_register_static (GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, "GearyImapEngineForegroundGarbageCollection", &g_define_type_info, 0);
	return geary_imap_engine_foreground_garbage_collection_type_id;
}

GType
geary_imap_engine_foreground_garbage_collection_get_type (void)
{
	static gsize geary_imap_engine_foreground_garbage_collection_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_engine_foreground_garbage_collection_type_id__once)) {
		GType geary_imap_engine_foreground_garbage_collection_type_id;
		geary_imap_engine_foreground_garbage_collection_type_id = geary_imap_engine_foreground_garbage_collection_get_type_once ();
		g_once_init_leave (&geary_imap_engine_foreground_garbage_collection_type_id__once, geary_imap_engine_foreground_garbage_collection_type_id);
	}
	return geary_imap_engine_foreground_garbage_collection_type_id__once;
}

static inline gpointer
geary_imap_engine_idle_garbage_collection_get_instance_private (GearyImapEngineIdleGarbageCollection* self)
{
	return G_STRUCT_MEMBER_P (self, GearyImapEngineIdleGarbageCollection_private_offset);
}

GearyImapEngineIdleGarbageCollection*
geary_imap_engine_idle_garbage_collection_construct (GType object_type,
                                                     GearyImapEngineGenericAccount* account)
{
	GearyImapEngineIdleGarbageCollection * self = NULL;
	g_return_val_if_fail (GEARY_IMAP_ENGINE_IS_GENERIC_ACCOUNT (account), NULL);
	self = (GearyImapEngineIdleGarbageCollection*) geary_imap_engine_account_operation_construct (object_type, G_TYPE_CHECK_INSTANCE_CAST (account, GEARY_TYPE_ACCOUNT, GearyAccount));
	return self;
}

GearyImapEngineIdleGarbageCollection*
geary_imap_engine_idle_garbage_collection_new (GearyImapEngineGenericAccount* account)
{
	return geary_imap_engine_idle_garbage_collection_construct (GEARY_IMAP_ENGINE_TYPE_IDLE_GARBAGE_COLLECTION, account);
}

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

static void
geary_imap_engine_idle_garbage_collection_real_execute (GearyImapEngineAccountOperation* base,
                                                        GCancellable* cancellable,
                                                        GAsyncReadyCallback _callback_,
                                                        gpointer _user_data_)
{
	GearyImapEngineIdleGarbageCollection * self;
	GearyImapEngineIdleGarbageCollectionExecuteData* _data_;
	GearyImapEngineIdleGarbageCollection* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_ENGINE_TYPE_IDLE_GARBAGE_COLLECTION, GearyImapEngineIdleGarbageCollection);
	_data_ = g_slice_new0 (GearyImapEngineIdleGarbageCollectionExecuteData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_imap_engine_idle_garbage_collection_real_execute_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_engine_idle_garbage_collection_real_execute_co (_data_);
}

static void
geary_imap_engine_idle_garbage_collection_execute_finish (GearyImapEngineAccountOperation* base,
                                                          GAsyncResult* _res_,
                                                          GError** error)
{
	GearyImapEngineIdleGarbageCollectionExecuteData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static gboolean
geary_imap_engine_idle_garbage_collection_real_execute_co (GearyImapEngineIdleGarbageCollectionExecuteData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (g_cancellable_is_cancelled (_data_->cancellable)) {
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp0_ = geary_imap_engine_account_operation_get_account (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, GearyImapEngineAccountOperation));
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, GEARY_IMAP_ENGINE_TYPE_GENERIC_ACCOUNT, GearyImapEngineGenericAccount));
	_data_->generic_account = _data_->_tmp2_;
	_data_->_tmp3_ = _data_->generic_account;
	_data_->_tmp4_ = geary_imap_engine_generic_account_get_local (_data_->_tmp3_);
	_data_->_tmp5_ = _data_->_tmp4_;
	_data_->_tmp6_ = geary_imap_db_account_get_db (_data_->_tmp5_);
	_data_->_tmp7_ = _data_->_tmp6_;
	_data_->_tmp8_ = _data_->generic_account;
	_data_->_tmp9_ = geary_imap_engine_generic_account_get_imap (_data_->_tmp8_);
	_data_->_tmp10_ = _data_->_tmp9_;
	_data_->_tmp11_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp10_, GEARY_TYPE_CLIENT_SERVICE, GearyClientService));
	_data_->_tmp12_ = _data_->generic_account;
	_data_->_tmp13_ = geary_imap_engine_generic_account_get_smtp (_data_->_tmp12_);
	_data_->_tmp14_ = _data_->_tmp13_;
	_data_->_tmp15_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp14_, GEARY_TYPE_CLIENT_SERVICE, GearyClientService));
	_data_->_tmp16_ = g_new0 (GearyClientService*, 2 + 1);
	_data_->_tmp16_[0] = _data_->_tmp11_;
	_data_->_tmp16_[1] = _data_->_tmp15_;
	_data_->_tmp17_ = gee_array_list_new_wrap (GEARY_TYPE_CLIENT_SERVICE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->_tmp16_, 2, NULL, NULL, NULL);
	_data_->_tmp18_ = _data_->_tmp17_;
	geary_imap_db_database_run_gc (_data_->_tmp7_, _data_->self->priv->options, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp18_, GEE_TYPE_COLLECTION, GeeCollection), _data_->cancellable, NULL, NULL);
	_g_object_unref0 (_data_->_tmp18_);
	_g_object_unref0 (_data_->generic_account);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

void
geary_imap_engine_idle_garbage_collection_messages_detached (GearyImapEngineIdleGarbageCollection* self)
{
	g_return_if_fail (GEARY_IMAP_ENGINE_IS_IDLE_GARBAGE_COLLECTION (self));
	self->priv->options = self->priv->options | GEARY_IMAP_DB_DATABASE_GARBAGE_COLLECTION_OPTIONS_FORCE_REAP;
}

static void
geary_imap_engine_idle_garbage_collection_class_init (GearyImapEngineIdleGarbageCollectionClass * klass,
                                                      gpointer klass_data)
{
	geary_imap_engine_idle_garbage_collection_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GearyImapEngineIdleGarbageCollection_private_offset);
	((GearyImapEngineAccountOperationClass *) klass)->execute = (void (*) (GearyImapEngineAccountOperation*, GCancellable*, GAsyncReadyCallback, gpointer)) geary_imap_engine_idle_garbage_collection_real_execute;
	((GearyImapEngineAccountOperationClass *) klass)->execute_finish = (void (*) (GearyImapEngineAccountOperation*, GAsyncResult*, GError**)) geary_imap_engine_idle_garbage_collection_execute_finish;
	G_OBJECT_CLASS (klass)->finalize = geary_imap_engine_idle_garbage_collection_finalize;
}

static void
geary_imap_engine_idle_garbage_collection_instance_init (GearyImapEngineIdleGarbageCollection * self,
                                                         gpointer klass)
{
	self->priv = geary_imap_engine_idle_garbage_collection_get_instance_private (self);
	self->priv->options = GEARY_IMAP_DB_DATABASE_GARBAGE_COLLECTION_OPTIONS_ALLOW_VACUUM;
}

static void
geary_imap_engine_idle_garbage_collection_finalize (GObject * obj)
{
	GearyImapEngineIdleGarbageCollection * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_IMAP_ENGINE_TYPE_IDLE_GARBAGE_COLLECTION, GearyImapEngineIdleGarbageCollection);
	G_OBJECT_CLASS (geary_imap_engine_idle_garbage_collection_parent_class)->finalize (obj);
}

/**
 * Performs garbage collection after old messages have been removed during
 * backgrounded idle cleanup.
 *
 * Queues a GC run after a cleanup of messages has occurred while the
 * app is idle in the background. Vacuuming will be permitted and if
 * messages have been removed a reap will be forced.
 */
 G_GNUC_NO_INLINE static GType
geary_imap_engine_idle_garbage_collection_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapEngineIdleGarbageCollectionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_engine_idle_garbage_collection_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapEngineIdleGarbageCollection), 0, (GInstanceInitFunc) geary_imap_engine_idle_garbage_collection_instance_init, NULL };
	GType geary_imap_engine_idle_garbage_collection_type_id;
	geary_imap_engine_idle_garbage_collection_type_id = g_type_register_static (GEARY_IMAP_ENGINE_TYPE_ACCOUNT_OPERATION, "GearyImapEngineIdleGarbageCollection", &g_define_type_info, 0);
	GearyImapEngineIdleGarbageCollection_private_offset = g_type_add_instance_private (geary_imap_engine_idle_garbage_collection_type_id, sizeof (GearyImapEngineIdleGarbageCollectionPrivate));
	return geary_imap_engine_idle_garbage_collection_type_id;
}

GType
geary_imap_engine_idle_garbage_collection_get_type (void)
{
	static gsize geary_imap_engine_idle_garbage_collection_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_engine_idle_garbage_collection_type_id__once)) {
		GType geary_imap_engine_idle_garbage_collection_type_id;
		geary_imap_engine_idle_garbage_collection_type_id = geary_imap_engine_idle_garbage_collection_get_type_once ();
		g_once_init_leave (&geary_imap_engine_idle_garbage_collection_type_id__once, geary_imap_engine_idle_garbage_collection_type_id);
	}
	return geary_imap_engine_idle_garbage_collection_type_id__once;
}

