[evolution-data-server] Add CamelIMAPXSettings.



commit 52ed819e1d773a54671ff26973331b579170e13e
Author: Matthew Barnes <mbarnes redhat com>
Date:   Mon Jul 4 00:13:19 2011 -0400

    Add CamelIMAPXSettings.
    
    CamelIMAPXSettings replaces the various URL parameters used in
    CamelIMAPXStore with equivalent GObject properties.
    
    Adapt the imapx provider to use CamelIMAPXSettings.

 camel/camel-enums.h                              |   16 +
 camel/providers/imapx/Makefile.am                |   24 +-
 camel/providers/imapx/camel-imapx-conn-manager.c |   26 +-
 camel/providers/imapx/camel-imapx-conn-manager.h |    3 -
 camel/providers/imapx/camel-imapx-folder.c       |   31 +-
 camel/providers/imapx/camel-imapx-provider.c     |   38 +-
 camel/providers/imapx/camel-imapx-server.c       |  118 ++-
 camel/providers/imapx/camel-imapx-server.h       |    3 -
 camel/providers/imapx/camel-imapx-settings.c     | 1112 ++++++++++++++++++++++
 camel/providers/imapx/camel-imapx-settings.h     |  132 +++
 camel/providers/imapx/camel-imapx-store.c        |  246 ++----
 camel/providers/imapx/camel-imapx-store.h        |   30 +-
 12 files changed, 1481 insertions(+), 298 deletions(-)
---
diff --git a/camel/camel-enums.h b/camel/camel-enums.h
index 7b48241..e347ca0 100644
--- a/camel/camel-enums.h
+++ b/camel/camel-enums.h
@@ -273,6 +273,22 @@ typedef enum {
 	CAMEL_SESSION_ALERT_ERROR
 } CamelSessionAlertType;
 
+/**
+ * CamelSortType:
+ * @CAMEL_SORT_ASCENDING:
+ *   Sorting is in ascending order.
+ * @CAMEL_SORT_DESCENDING:
+ *   Sorting is in descending order.
+ *
+ * Determines the direction of a sort.
+ *
+ * Since: 3.2
+ **/
+typedef enum {
+	CAMEL_SORT_ASCENDING,
+	CAMEL_SORT_DESCENDING
+} CamelSortType;
+
 typedef enum { /*< flags >*/
 	CAMEL_STORE_SUBSCRIPTIONS    = 1 << 0,
 	CAMEL_STORE_VTRASH           = 1 << 1,
diff --git a/camel/providers/imapx/Makefile.am b/camel/providers/imapx/Makefile.am
index a8ae7be..3098e60 100644
--- a/camel/providers/imapx/Makefile.am
+++ b/camel/providers/imapx/Makefile.am
@@ -11,24 +11,26 @@ libcamelimapx_la_CPPFLAGS = \
 	-DG_LOG_DOMAIN=\"camel-imapx\"
 
 libcamelimapx_la_SOURCES =			\
-	camel-imapx-stream.c			\
-	camel-imapx-utils.c			\
+	camel-imapx-conn-manager.c		\
+	camel-imapx-folder.c			\
 	camel-imapx-provider.c			\
+	camel-imapx-server.c			\
+	camel-imapx-settings.c			\
 	camel-imapx-store-summary.c		\
-	camel-imapx-summary.c			\
 	camel-imapx-store.c			\
-	camel-imapx-folder.c			\
-	camel-imapx-server.c			\
-	camel-imapx-conn-manager.c
+	camel-imapx-stream.c			\
+	camel-imapx-summary.c			\
+	camel-imapx-utils.c
 
 noinst_HEADERS =				\
-	camel-imapx-stream.h			\
-	camel-imapx-store-summary.h		\
-	camel-imapx-summary.h			\
+	camel-imapx-conn-manager.h		\
 	camel-imapx-folder.h			\
-	camel-imapx-store.h			\
 	camel-imapx-server.h			\
-	camel-imapx-conn-manager.h		\
+	camel-imapx-settings.h			\
+	camel-imapx-store-summary.h		\
+	camel-imapx-store.h			\
+	camel-imapx-stream.h			\
+	camel-imapx-summary.h			\
 	camel-imapx-utils.h
 
 camel-imapx-tokenise.h: camel-imapx-tokens.txt
diff --git a/camel/providers/imapx/camel-imapx-conn-manager.c b/camel/providers/imapx/camel-imapx-conn-manager.c
index 219a258..f874e12 100644
--- a/camel/providers/imapx/camel-imapx-conn-manager.c
+++ b/camel/providers/imapx/camel-imapx-conn-manager.c
@@ -20,6 +20,7 @@
  */
 
 #include "camel-imapx-conn-manager.h"
+#include "camel-imapx-settings.h"
 #include "camel-imapx-utils.h"
 
 #define c(...) camel_imapx_debug(conman, __VA_ARGS__)
@@ -38,7 +39,6 @@ G_DEFINE_TYPE (
 
 struct _CamelIMAPXConnManagerPrivate {
 	GSList *connections;
-	guint n_connections;
 	gpointer store;  /* weak pointer */
 	GStaticRecMutex con_man_lock;
 	gboolean clearing_connections;
@@ -194,8 +194,6 @@ camel_imapx_conn_manager_init (CamelIMAPXConnManager *con_man)
 {
 	con_man->priv = CAMEL_IMAPX_CONN_MANAGER_GET_PRIVATE (con_man);
 
-	/* default is 1 connection */
-	con_man->priv->n_connections = 1;
 	g_static_rec_mutex_init (&con_man->priv->con_man_lock);
 
 	con_man->priv->clearing_connections = FALSE;
@@ -281,10 +279,20 @@ imapx_find_connection (CamelIMAPXConnManager *con_man, const gchar *folder_name)
 	guint i = 0, prev_len = -1, n = -1;
 	GSList *l;
 	CamelIMAPXServer *conn = NULL;
+	CamelService *service;
+	CamelSettings *settings;
 	ConnectionInfo *cinfo = NULL;
+	guint concurrent_connections;
 
 	CON_LOCK (con_man);
 
+	service = CAMEL_SERVICE (con_man->priv->store);
+	settings = camel_service_get_settings (service);
+
+	concurrent_connections =
+		camel_imapx_settings_get_concurrent_connections (
+		CAMEL_IMAPX_SETTINGS (settings));
+
 	/* Have a dedicated connection for INBOX ? */
 	for (l = con_man->priv->connections, i = 0; l != NULL; l = g_slist_next (l), i++) {
 		IMAPXJobQueueInfo *jinfo = NULL;
@@ -312,7 +320,7 @@ imapx_find_connection (CamelIMAPXConnManager *con_man, const gchar *folder_name)
 		}
 	}
 
-	if (!conn && n != -1 && (!folder_name || con_man->priv->n_connections == g_slist_length (con_man->priv->connections))) {
+	if (!conn && n != -1 && (!folder_name || concurrent_connections == g_slist_length (con_man->priv->connections))) {
 		cinfo = g_slist_nth_data (con_man->priv->connections, n);
 		conn = g_object_ref (cinfo->conn);
 
@@ -323,7 +331,7 @@ imapx_find_connection (CamelIMAPXConnManager *con_man, const gchar *folder_name)
 	}
 
 	if (camel_debug_flag (conman))
-		g_assert (!(con_man->priv->n_connections == g_slist_length (con_man->priv->connections) && !conn));
+		g_assert (!(concurrent_connections == g_slist_length (con_man->priv->connections) && !conn));
 
 	CON_UNLOCK (con_man);
 
@@ -401,14 +409,6 @@ camel_imapx_conn_manager_get_store (CamelIMAPXConnManager *con_man)
 	return CAMEL_STORE (con_man->priv->store);
 }
 
-void
-camel_imapx_conn_manager_set_n_connections (CamelIMAPXConnManager *con_man, guint n_connections)
-{
-	g_return_if_fail (CAMEL_IS_IMAPX_CONN_MANAGER (con_man));
-
-	con_man->priv->n_connections = n_connections;
-}
-
 CamelIMAPXServer *
 camel_imapx_conn_manager_get_connection (CamelIMAPXConnManager *con_man,
                                          const gchar *folder_name,
diff --git a/camel/providers/imapx/camel-imapx-conn-manager.h b/camel/providers/imapx/camel-imapx-conn-manager.h
index 7cb95e0..6d753fb 100644
--- a/camel/providers/imapx/camel-imapx-conn-manager.h
+++ b/camel/providers/imapx/camel-imapx-conn-manager.h
@@ -60,9 +60,6 @@ CamelIMAPXConnManager *
 		camel_imapx_conn_manager_new	(CamelStore *store);
 CamelStore *	camel_imapx_conn_manager_get_store
 						(CamelIMAPXConnManager *con_man);
-void		camel_imapx_conn_manager_set_n_connections
-						(CamelIMAPXConnManager *con_man,
-						 guint n_connections);
 CamelIMAPXServer *
 		camel_imapx_conn_manager_get_connection
 						(CamelIMAPXConnManager *con_man,
diff --git a/camel/providers/imapx/camel-imapx-folder.c b/camel/providers/imapx/camel-imapx-folder.c
index 10604bc..2bf683d 100644
--- a/camel/providers/imapx/camel-imapx-folder.c
+++ b/camel/providers/imapx/camel-imapx-folder.c
@@ -44,13 +44,27 @@ CamelFolder *
 camel_imapx_folder_new (CamelStore *store, const gchar *folder_dir, const gchar *folder_name, GError **error)
 {
 	CamelFolder *folder;
+	CamelService *service;
+	CamelSettings *settings;
 	CamelIMAPXFolder *ifolder;
 	const gchar *short_name;
 	gchar *summary_file, *state_file;
-	CamelIMAPXStore *istore;
+	gboolean filter_inbox;
+	gboolean filter_junk;
+	gboolean filter_junk_inbox;
 
 	d("opening imap folder '%s'\n", folder_dir);
 
+	service = CAMEL_SERVICE (store);
+	settings = camel_service_get_settings (service);
+
+	g_object_get (
+		settings,
+		"filter-inbox", &filter_inbox,
+		"filter-junk", &filter_junk,
+		"filter-junk-inbox", &filter_junk_inbox,
+		NULL);
+
 	short_name = strrchr (folder_name, '/');
 	if (short_name)
 		short_name++;
@@ -98,23 +112,12 @@ camel_imapx_folder_new (CamelStore *store, const gchar *folder_dir, const gchar
 	ifolder->modseq_on_server = 0;
 	ifolder->uidnext_on_server = 0;
 
-	istore = (CamelIMAPXStore *) store;
 	if (!g_ascii_strcasecmp (folder_name, "INBOX")) {
-		CamelService *service;
-		CamelSettings *settings;
-		gboolean filter_inbox;
-
-		service = CAMEL_SERVICE (store);
-		settings = camel_service_get_settings (service);
-
-		filter_inbox = camel_store_settings_get_filter_inbox (
-			CAMEL_STORE_SETTINGS (settings));
-
 		if (filter_inbox)
 			folder->folder_flags |= CAMEL_FOLDER_FILTER_RECENT;
-		if ((istore->rec_options & IMAPX_FILTER_JUNK))
+		if (filter_junk)
 			folder->folder_flags |= CAMEL_FOLDER_FILTER_JUNK;
-	} else if ((istore->rec_options & (IMAPX_FILTER_JUNK | IMAPX_FILTER_JUNK_INBOX)) == IMAPX_FILTER_JUNK)
+	} else if (filter_junk && !filter_junk_inbox)
 			folder->folder_flags |= CAMEL_FOLDER_FILTER_JUNK;
 
 	g_free (summary_file);
diff --git a/camel/providers/imapx/camel-imapx-provider.c b/camel/providers/imapx/camel-imapx-provider.c
index c47c430..d5a7fce 100644
--- a/camel/providers/imapx/camel-imapx-provider.c
+++ b/camel/providers/imapx/camel-imapx-provider.c
@@ -36,57 +36,57 @@ static guint imapx_url_hash (gconstpointer key);
 static gint  imapx_url_equal (gconstpointer a, gconstpointer b);
 
 CamelProviderConfEntry imapx_conf_entries[] = {
-		{ CAMEL_PROVIDER_CONF_SECTION_START, "mailcheck", NULL,
+	{ CAMEL_PROVIDER_CONF_SECTION_START, "mailcheck", NULL,
 	  N_("Checking for New Mail") },
-	{ CAMEL_PROVIDER_CONF_CHECKBOX, "use_qresync", NULL,
+	{ CAMEL_PROVIDER_CONF_CHECKBOX, "use-qresync", NULL,
 	  N_("Use _Quick Resync if the server supports it"), "1" },
-	{ CAMEL_PROVIDER_CONF_CHECKBOX, "use_idle", NULL,
+	{ CAMEL_PROVIDER_CONF_CHECKBOX, "use-idle", NULL,
 	  N_("Use I_dle if the server supports it"), "1" },
-	{ CAMEL_PROVIDER_CONF_CHECKBOX, "check_all", NULL,
+	{ CAMEL_PROVIDER_CONF_CHECKBOX, "check-all", NULL,
 	  N_("C_heck for new messages in all folders"), "1" },
-	{ CAMEL_PROVIDER_CONF_CHECKBOX, "check_lsub", NULL,
+	{ CAMEL_PROVIDER_CONF_CHECKBOX, "check-subscribed", NULL,
 	  N_("Ch_eck for new messages in subscribed folders"), "0" },
 	{ CAMEL_PROVIDER_CONF_SECTION_END },
 #ifndef G_OS_WIN32
 	{ CAMEL_PROVIDER_CONF_SECTION_START, "cmdsection", NULL,
 	  N_("Connection to Server") },
-	{ CAMEL_PROVIDER_CONF_CHECKBOX, "use_command", NULL,
+	{ CAMEL_PROVIDER_CONF_CHECKBOX, "use-shell-command", NULL,
 	  N_("_Use custom command to connect to server"), "0" },
-	{ CAMEL_PROVIDER_CONF_ENTRY, "command", "use_command",
+	{ CAMEL_PROVIDER_CONF_ENTRY, "shell-command", "use-shell-command",
 	  N_("Command:"), "ssh -C -l %u %h exec /usr/sbin/dovecot --exec-mail imap" },
-	{ CAMEL_PROVIDER_CONF_CHECKSPIN, "cachedconn", NULL,
+	{ CAMEL_PROVIDER_CONF_CHECKSPIN, "concurrent-connections", NULL,
 	  N_("Numbe_r of cached connections to use"), "y:1:5:7" },
 	{ CAMEL_PROVIDER_CONF_SECTION_END },
 #endif
 	{ CAMEL_PROVIDER_CONF_SECTION_START, "folders", NULL,
 	  N_("Folders") },
-	{ CAMEL_PROVIDER_CONF_CHECKBOX, "use_lsub", NULL,
+	{ CAMEL_PROVIDER_CONF_CHECKBOX, "use-subscriptions", NULL,
 	  N_("_Show only subscribed folders"), "1" },
 #if 0
-	{ CAMEL_PROVIDER_CONF_CHECKBOX, "override_namespace", NULL,
+	{ CAMEL_PROVIDER_CONF_CHECKBOX, "use-namespace", NULL,
 	  N_("O_verride server-supplied folder namespace"), "0" },
-	{ CAMEL_PROVIDER_CONF_ENTRY, "namespace", "override_namespace",
+	{ CAMEL_PROVIDER_CONF_ENTRY, "namespace", "use-namespace",
 	  N_("Namespace:") },
 #endif
 	{ CAMEL_PROVIDER_CONF_SECTION_END },
 	{ CAMEL_PROVIDER_CONF_SECTION_START, "general", NULL, N_("Options") },
-	{ CAMEL_PROVIDER_CONF_CHECKBOX, "filter", NULL,
+	{ CAMEL_PROVIDER_CONF_CHECKBOX, "filter-inbox", NULL,
 	  N_("_Apply filters to new messages in Inbox on this server"), "1" },
-	{ CAMEL_PROVIDER_CONF_CHECKBOX, "filter_junk", NULL,
+	{ CAMEL_PROVIDER_CONF_CHECKBOX, "filter-junk", NULL,
 	  N_("Check new messages for Jun_k contents"), "0" },
-	{ CAMEL_PROVIDER_CONF_CHECKBOX, "filter_junk_inbox", "filter_junk",
+	{ CAMEL_PROVIDER_CONF_CHECKBOX, "filter-junk-inbox", "filter-junk",
 	  N_("Only check for Junk messages in the IN_BOX folder"), "0" },
-	{ CAMEL_PROVIDER_CONF_CHECKBOX, "sync_offline", NULL,
+	{ CAMEL_PROVIDER_CONF_CHECKBOX, "stay-synchronized", NULL,
 	  N_("Automatically synchroni_ze remote mail locally"), "0" },
 	{ CAMEL_PROVIDER_CONF_SECTION_END },
 	{ CAMEL_PROVIDER_CONF_END }
 };
 
 CamelProviderPortEntry imapx_port_entries[] = {
-						{ 143, N_("Default IMAP port"), FALSE },
-						{ 993, N_("IMAP over SSL"), TRUE },
-						{ 0, NULL, 0 }
-					      };
+	{ 143, N_("Default IMAP port"), FALSE },
+	{ 993, N_("IMAP over SSL"), TRUE },
+	{ 0, NULL, 0 }
+};
 
 static CamelProvider imapx_provider = {
 	"imapx",
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index 2d2b5d8..3ebaa89 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -41,6 +41,7 @@
 #include "camel-imapx-stream.h"
 #include "camel-imapx-server.h"
 #include "camel-imapx-folder.h"
+#include "camel-imapx-settings.h"
 #include "camel-imapx-store.h"
 #include "camel-imapx-summary.h"
 
@@ -68,9 +69,6 @@
 /* How many outstanding commands do we allow before we just queue them? */
 #define MAX_COMMANDS (10)
 
-/* How many message headers to fetch at a time update summary for new messages*/
-#define BATCH_FETCH_COUNT 500
-
 #define MAX_COMMAND_LEN 1000
 
 extern gint camel_application_is_exiting;
@@ -361,26 +359,6 @@ static gboolean imapx_select (CamelIMAPXServer *is, CamelFolder *folder, gboolea
 
 G_DEFINE_TYPE (CamelIMAPXServer, camel_imapx_server, CAMEL_TYPE_OBJECT)
 
-static guint
-get_batch_fetch_count (CamelIMAPXServer *is)
-{
-	static guint count = 0;
-	const gchar *fetch_count;
-
-	if (count)
-		return count;
-
-	/* TODO document all the param's in some common place */
-	fetch_count = camel_url_get_param (is->url, "batch-fetch-count");
-	if (fetch_count)
-		count = strtoul (fetch_count, NULL, 10);
-
-	if (count <= 0)
-		count = BATCH_FETCH_COUNT;
-
-	return count;
-}
-
 /*
   this creates a uid (or sequence number) set directly into a command,
   if total is set, then we break it up into total uids. (i.e. command time)
@@ -1326,12 +1304,21 @@ imapx_untagged (CamelIMAPXServer *imap,
                 GCancellable *cancellable,
                 GError **error)
 {
+	CamelService *service;
+	CamelSettings *settings;
+	CamelSortType fetch_order;
 	guint id, len;
 	guchar *token, *p, c;
 	gint tok;
 	gboolean lsub = FALSE;
 	struct _status_info *sinfo;
 
+	service = CAMEL_SERVICE (imap->store);
+	settings = camel_service_get_settings (service);
+
+	fetch_order = camel_imapx_settings_get_fetch_order (
+		CAMEL_IMAPX_SETTINGS (settings));
+
 	e(imap->tagprefix, "got untagged response\n");
 	id = 0;
 	tok = camel_imapx_stream_token (imap->stream, &token, &len, cancellable, error);
@@ -1597,7 +1584,7 @@ imapx_untagged (CamelIMAPXServer *imap,
 
 							mid = (min + max)/2;
 							r = &g_array_index (infos, struct _refresh_info, mid);
-							cmp = imapx_refresh_info_uid_cmp (finfo->uid, r->uid, !imap->descending);
+							cmp = imapx_refresh_info_uid_cmp (finfo->uid, r->uid, fetch_order == CAMEL_SORT_ASCENDING);
 
 							if (cmp > 0)
 								min = mid + 1;
@@ -2860,10 +2847,11 @@ imapx_connect_to_server (CamelIMAPXServer *is,
                          GCancellable *cancellable,
                          GError **error)
 {
-	CamelNetworkService *network_service;
 	CamelNetworkSecurityMethod method;
 	CamelStream * tcp_stream = NULL;
 	CamelSockOptData sockopt;
+	CamelSettings *settings;
+	CamelService *service;
 	guint len;
 	guchar *token;
 	gint tok;
@@ -2871,10 +2859,24 @@ imapx_connect_to_server (CamelIMAPXServer *is,
 	GError *local_error = NULL;
 
 #ifndef G_OS_WIN32
-	const gchar *command;
+	gboolean use_shell_command;
+	const gchar *command = NULL;
+#endif
 
-	if (camel_url_get_param(is->url, "use_command") &&
-	    (command = camel_url_get_param(is->url, "command"))) {
+	service = CAMEL_SERVICE (is->store);
+	settings = camel_service_get_settings (service);
+
+	g_object_get (settings, "security-method", &method, NULL);
+
+#ifndef G_OS_WIN32
+	use_shell_command = camel_imapx_settings_get_use_shell_command (
+		CAMEL_IMAPX_SETTINGS (settings));
+
+	if (use_shell_command)
+		command = camel_imapx_settings_get_shell_command (
+			CAMEL_IMAPX_SETTINGS (settings));
+
+	if (command != NULL) {
 		if (!connect_to_server_process (is, command, &local_error))
 			goto exit;
 		else
@@ -2882,9 +2884,6 @@ imapx_connect_to_server (CamelIMAPXServer *is,
 	}
 #endif
 
-	network_service = CAMEL_NETWORK_SERVICE (is->store);
-	method = camel_network_service_get_security_method (network_service);
-
 	tcp_stream = camel_network_service_connect_sync (
 		CAMEL_NETWORK_SERVICE (is->store), cancellable, error);
 
@@ -3049,14 +3048,24 @@ imapx_reconnect (CamelIMAPXServer *is,
 	CamelIMAPXCommand *ic;
 	gchar *errbuf = NULL;
 	CamelService *service;
+	CamelSettings *settings;
 	CamelURL *url;
 	gboolean authenticated = FALSE;
 	CamelServiceAuthType *authtype = NULL;
 	guint32 prompt_flags = CAMEL_SESSION_PASSWORD_SECRET;
 	gboolean need_password = FALSE;
+	gboolean use_idle;
+	gboolean use_qresync;
 
 	service = CAMEL_SERVICE (is->store);
 	url = camel_service_get_camel_url (service);
+	settings = camel_service_get_settings (service);
+
+	use_idle = camel_imapx_settings_get_use_idle (
+		CAMEL_IMAPX_SETTINGS (settings));
+
+	use_qresync = camel_imapx_settings_get_use_qresync (
+		CAMEL_IMAPX_SETTINGS (settings));
 
 	while (!authenticated) {
 		CamelSasl *sasl = NULL;
@@ -3210,10 +3219,7 @@ imapx_reconnect (CamelIMAPXServer *is,
 	is->state = IMAPX_AUTHENTICATED;
 
  preauthed:
-	if (((CamelIMAPXStore *) is->store)->rec_options & IMAPX_USE_IDLE)
-		is->use_idle = TRUE;
-	else
-		is->use_idle = FALSE;
+	is->use_idle = use_idle;
 
 	if (imapx_idle_supported (is))
 		imapx_init_idle (is);
@@ -3233,8 +3239,7 @@ imapx_reconnect (CamelIMAPXServer *is,
 		camel_imapx_command_free (ic);
 	}
 
-	if (((CamelIMAPXStore *) is->store)->rec_options & IMAPX_USE_QRESYNC &&
-	    is->cinfo->capa & IMAPX_CAPABILITY_QRESYNC) {
+	if (use_qresync && is->cinfo->capa & IMAPX_CAPABILITY_QRESYNC) {
 		ic = camel_imapx_command_new (
 			is, "ENABLE", NULL, cancellable,
 			"ENABLE CONDSTORE QRESYNC");
@@ -3808,8 +3813,17 @@ imapx_job_scan_changes_done (CamelIMAPXServer *is,
                              CamelIMAPXCommand *ic)
 {
 	CamelIMAPXJob *job = ic->job;
+	CamelService *service;
+	CamelSettings *settings;
 	gint i;
 	GArray *infos = job->u.refresh_info.infos;
+	guint uidset_size;
+
+	service = CAMEL_SERVICE (is->store);
+	settings = camel_service_get_settings (service);
+
+	uidset_size = camel_imapx_settings_get_batch_fetch_count (
+		CAMEL_IMAPX_SETTINGS (settings));
 
 	if (ic->error == NULL && ic->status->result == IMAPX_OK) {
 		GCompareDataFunc uid_cmp = imapx_uid_cmp;
@@ -3939,7 +3953,7 @@ imapx_job_scan_changes_done (CamelIMAPXServer *is,
 				job->cancellable,
 				_("Fetching summary information for new messages in %s"),
 				camel_folder_get_display_name (job->folder));
-			imapx_uidset_init (&job->u.refresh_info.uidset, get_batch_fetch_count (is), 0);
+			imapx_uidset_init (&job->u.refresh_info.uidset, uidset_size, 0);
 			/* These are new messages which arrived since we last knew the unseen count;
 			   update it as they arrive. */
 			job->u.refresh_info.update_unseen = TRUE;
@@ -4062,9 +4076,22 @@ imapx_job_fetch_new_messages_start (CamelIMAPXServer *is,
 	CamelIMAPXCommand *ic;
 	CamelFolder *folder = job->folder;
 	CamelIMAPXFolder *ifolder = (CamelIMAPXFolder *) folder;
+	CamelService *service;
+	CamelSettings *settings;
+	CamelSortType fetch_order;
 	guint32 total, diff;
+	guint uidset_size;
 	gchar *uid = NULL;
 
+	service = CAMEL_SERVICE (is->store);
+	settings = camel_service_get_settings (service);
+
+	fetch_order = camel_imapx_settings_get_fetch_order (
+		CAMEL_IMAPX_SETTINGS (settings));
+
+	uidset_size = camel_imapx_settings_get_batch_fetch_count (
+		CAMEL_IMAPX_SETTINGS (settings));
+
 	total = camel_folder_summary_count (folder->summary);
 	diff = ifolder->exists_on_server - total;
 
@@ -4082,15 +4109,15 @@ imapx_job_fetch_new_messages_start (CamelIMAPXServer *is,
 		_("Fetching summary information for new messages in %s"),
 		camel_folder_get_display_name (folder));
 
-	if (diff > get_batch_fetch_count (is) || is->descending) {
+	if (diff > uidset_size || fetch_order == CAMEL_SORT_DESCENDING) {
 		ic = camel_imapx_command_new (
 			is, "FETCH", job->folder, job->cancellable,
 			"UID FETCH %s:* (UID FLAGS)", uid);
-		imapx_uidset_init (&job->u.refresh_info.uidset, get_batch_fetch_count (is), 0);
+		imapx_uidset_init (&job->u.refresh_info.uidset, uidset_size, 0);
 		job->u.refresh_info.infos = g_array_new (0, 0, sizeof (struct _refresh_info));
 		ic->pri = job->pri;
 
-		if (is->descending)
+		if (fetch_order == CAMEL_SORT_DESCENDING)
 			ic->complete = imapx_command_fetch_new_uids_done;
 		else
 			ic->complete = imapx_command_step_fetch_done;
@@ -5173,7 +5200,6 @@ camel_imapx_server_new (CamelStore *store, CamelURL *url)
 	CamelService *service;
 	CamelSession *session;
 	CamelIMAPXServer *is;
-	const gchar *order;
 
 	service = CAMEL_SERVICE (store);
 	session = camel_service_get_session (service);
@@ -5183,14 +5209,6 @@ camel_imapx_server_new (CamelStore *store, CamelURL *url)
 	is->store = store;
 	is->url = camel_url_copy (url);
 
-	/* TODO add UI options in advanced window */
-	/* order in which new messages should be fetched */
-	order = camel_url_get_param (url, "fetch-order");
-	if (order && !strcmp (order, "descending"))
-		is->descending = TRUE;
-	else
-		is->descending = FALSE;
-
 	return is;
 }
 
diff --git a/camel/providers/imapx/camel-imapx-server.h b/camel/providers/imapx/camel-imapx-server.h
index 22d573c..d89dfb7 100644
--- a/camel/providers/imapx/camel-imapx-server.h
+++ b/camel/providers/imapx/camel-imapx-server.h
@@ -119,9 +119,6 @@ struct _CamelIMAPXServer {
 
 	gboolean use_qresync;
 
-	/* order in which new messages would be fetched */
-	gboolean descending;
-
 	/* used to synchronize duplicate get_message requests */
 	GCond *fetch_cond;
 	GMutex *fetch_mutex;
diff --git a/camel/providers/imapx/camel-imapx-settings.c b/camel/providers/imapx/camel-imapx-settings.c
new file mode 100644
index 0000000..07333f5
--- /dev/null
+++ b/camel/providers/imapx/camel-imapx-settings.c
@@ -0,0 +1,1112 @@
+/*
+ * camel-imapx-settings.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "camel-imapx-settings.h"
+
+#define MIN_CONCURRENT_CONNECTIONS 1
+#define MAX_CONCURRENT_CONNECTIONS 7
+
+#define CAMEL_IMAPX_SETTINGS_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_IMAPX_SETTINGS, CamelIMAPXSettingsPrivate))
+
+struct _CamelIMAPXSettingsPrivate {
+	gchar *namespace;
+	gchar *shell_command;
+
+	guint batch_fetch_count;
+	guint concurrent_connections;
+
+	gboolean check_all;
+	gboolean check_subscribed;
+	gboolean filter_junk;
+	gboolean filter_junk_inbox;
+	gboolean use_idle;
+	gboolean use_namespace;
+	gboolean use_qresync;
+	gboolean use_shell_command;
+	gboolean use_subscriptions;
+
+	CamelSortType fetch_order;
+};
+
+enum {
+	PROP_0,
+	PROP_BATCH_FETCH_COUNT,
+	PROP_CHECK_ALL,
+	PROP_CHECK_SUBSCRIBED,
+	PROP_CONCURRENT_CONNECTIONS,
+	PROP_FETCH_ORDER,
+	PROP_FILTER_JUNK,
+	PROP_FILTER_JUNK_INBOX,
+	PROP_NAMESPACE,
+	PROP_SECURITY_METHOD,
+	PROP_SHELL_COMMAND,
+	PROP_USE_IDLE,
+	PROP_USE_NAMESPACE,
+	PROP_USE_QRESYNC,
+	PROP_USE_SHELL_COMMAND,
+	PROP_USE_SUBSCRIPTIONS
+};
+
+G_DEFINE_TYPE_WITH_CODE (
+	CamelIMAPXSettings,
+	camel_imapx_settings,
+	CAMEL_TYPE_OFFLINE_SETTINGS,
+	G_IMPLEMENT_INTERFACE (
+		CAMEL_TYPE_NETWORK_SETTINGS, NULL))
+
+static void
+imapx_settings_set_property (GObject *object,
+                             guint property_id,
+                             const GValue *value,
+                             GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_BATCH_FETCH_COUNT:
+			camel_imapx_settings_set_batch_fetch_count (
+				CAMEL_IMAPX_SETTINGS (object),
+				g_value_get_uint (value));
+			return;
+
+		case PROP_CHECK_ALL:
+			camel_imapx_settings_set_check_all (
+				CAMEL_IMAPX_SETTINGS (object),
+				g_value_get_boolean (value));
+			return;
+
+		case PROP_CHECK_SUBSCRIBED:
+			camel_imapx_settings_set_check_subscribed (
+				CAMEL_IMAPX_SETTINGS (object),
+				g_value_get_boolean (value));
+			return;
+
+		case PROP_CONCURRENT_CONNECTIONS:
+			camel_imapx_settings_set_concurrent_connections (
+				CAMEL_IMAPX_SETTINGS (object),
+				g_value_get_uint (value));
+			return;
+
+		case PROP_FETCH_ORDER:
+			camel_imapx_settings_set_fetch_order (
+				CAMEL_IMAPX_SETTINGS (object),
+				g_value_get_enum (value));
+			return;
+
+		case PROP_FILTER_JUNK:
+			camel_imapx_settings_set_filter_junk (
+				CAMEL_IMAPX_SETTINGS (object),
+				g_value_get_boolean (value));
+			return;
+
+		case PROP_FILTER_JUNK_INBOX:
+			camel_imapx_settings_set_filter_junk_inbox (
+				CAMEL_IMAPX_SETTINGS (object),
+				g_value_get_boolean (value));
+			return;
+
+		case PROP_NAMESPACE:
+			camel_imapx_settings_set_namespace (
+				CAMEL_IMAPX_SETTINGS (object),
+				g_value_get_string (value));
+			return;
+
+		case PROP_SECURITY_METHOD:
+			camel_network_settings_set_security_method (
+				CAMEL_NETWORK_SETTINGS (object),
+				g_value_get_enum (value));
+			return;
+
+		case PROP_SHELL_COMMAND:
+			camel_imapx_settings_set_shell_command (
+				CAMEL_IMAPX_SETTINGS (object),
+				g_value_get_string (value));
+			return;
+
+		case PROP_USE_IDLE:
+			camel_imapx_settings_set_use_idle (
+				CAMEL_IMAPX_SETTINGS (object),
+				g_value_get_boolean (value));
+			return;
+
+		case PROP_USE_NAMESPACE:
+			camel_imapx_settings_set_use_namespace (
+				CAMEL_IMAPX_SETTINGS (object),
+				g_value_get_boolean (value));
+			return;
+
+		case PROP_USE_QRESYNC:
+			camel_imapx_settings_set_use_qresync (
+				CAMEL_IMAPX_SETTINGS (object),
+				g_value_get_boolean (value));
+			return;
+
+		case PROP_USE_SHELL_COMMAND:
+			camel_imapx_settings_set_use_shell_command (
+				CAMEL_IMAPX_SETTINGS (object),
+				g_value_get_boolean (value));
+			return;
+
+		case PROP_USE_SUBSCRIPTIONS:
+			camel_imapx_settings_set_use_subscriptions (
+				CAMEL_IMAPX_SETTINGS (object),
+				g_value_get_boolean (value));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+imapx_settings_get_property (GObject *object,
+                             guint property_id,
+                             GValue *value,
+                             GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_BATCH_FETCH_COUNT:
+			g_value_set_uint (
+				value,
+				camel_imapx_settings_get_batch_fetch_count (
+				CAMEL_IMAPX_SETTINGS (object)));
+			return;
+
+		case PROP_CHECK_ALL:
+			g_value_set_boolean (
+				value,
+				camel_imapx_settings_get_check_all (
+				CAMEL_IMAPX_SETTINGS (object)));
+			return;
+
+		case PROP_CHECK_SUBSCRIBED:
+			g_value_set_boolean (
+				value,
+				camel_imapx_settings_get_check_subscribed (
+				CAMEL_IMAPX_SETTINGS (object)));
+			return;
+
+		case PROP_CONCURRENT_CONNECTIONS:
+			g_value_set_uint (
+				value,
+				camel_imapx_settings_get_concurrent_connections (
+				CAMEL_IMAPX_SETTINGS (object)));
+			return;
+
+		case PROP_FETCH_ORDER:
+			g_value_set_enum (
+				value,
+				camel_imapx_settings_get_fetch_order (
+				CAMEL_IMAPX_SETTINGS (object)));
+			return;
+
+		case PROP_FILTER_JUNK:
+			g_value_set_boolean (
+				value,
+				camel_imapx_settings_get_filter_junk (
+				CAMEL_IMAPX_SETTINGS (object)));
+			return;
+
+		case PROP_FILTER_JUNK_INBOX:
+			g_value_set_boolean (
+				value,
+				camel_imapx_settings_get_filter_junk_inbox (
+				CAMEL_IMAPX_SETTINGS (object)));
+			return;
+
+		case PROP_NAMESPACE:
+			g_value_set_string (
+				value,
+				camel_imapx_settings_get_namespace (
+				CAMEL_IMAPX_SETTINGS (object)));
+			return;
+
+		case PROP_SECURITY_METHOD:
+			g_value_set_enum (
+				value,
+				camel_network_settings_get_security_method (
+				CAMEL_NETWORK_SETTINGS (object)));
+			return;
+
+		case PROP_SHELL_COMMAND:
+			g_value_set_string (
+				value,
+				camel_imapx_settings_get_shell_command (
+				CAMEL_IMAPX_SETTINGS (object)));
+			return;
+
+		case PROP_USE_IDLE:
+			g_value_set_boolean (
+				value,
+				camel_imapx_settings_get_use_idle (
+				CAMEL_IMAPX_SETTINGS (object)));
+			return;
+
+		case PROP_USE_NAMESPACE:
+			g_value_set_boolean (
+				value,
+				camel_imapx_settings_get_use_namespace (
+				CAMEL_IMAPX_SETTINGS (object)));
+			return;
+
+		case PROP_USE_QRESYNC:
+			g_value_set_boolean (
+				value,
+				camel_imapx_settings_get_use_qresync (
+				CAMEL_IMAPX_SETTINGS (object)));
+			return;
+
+		case PROP_USE_SHELL_COMMAND:
+			g_value_set_boolean (
+				value,
+				camel_imapx_settings_get_use_shell_command (
+				CAMEL_IMAPX_SETTINGS (object)));
+			return;
+
+		case PROP_USE_SUBSCRIPTIONS:
+			g_value_set_boolean (
+				value,
+				camel_imapx_settings_get_use_subscriptions (
+				CAMEL_IMAPX_SETTINGS (object)));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+imapx_settings_finalize (GObject *object)
+{
+	CamelIMAPXSettingsPrivate *priv;
+
+	priv = CAMEL_IMAPX_SETTINGS_GET_PRIVATE (object);
+
+	g_free (priv->namespace);
+	g_free (priv->shell_command);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (camel_imapx_settings_parent_class)->finalize (object);
+}
+
+static void
+camel_imapx_settings_class_init (CamelIMAPXSettingsClass *class)
+{
+	GObjectClass *object_class;
+
+	g_type_class_add_private (class, sizeof (CamelIMAPXSettingsPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->set_property = imapx_settings_set_property;
+	object_class->get_property = imapx_settings_get_property;
+	object_class->finalize = imapx_settings_finalize;
+
+	g_object_class_install_property (
+		object_class,
+		PROP_BATCH_FETCH_COUNT,
+		g_param_spec_uint (
+			"batch-fetch-count",
+			"Batch Fetch Count",
+			"Number of envelopes to fetch at once",
+			0,
+			G_MAXUINT,
+			500,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			G_PARAM_STATIC_STRINGS));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_CHECK_ALL,
+		g_param_spec_boolean (
+			"check-all",
+			"Check All",
+			"Check all folders for new messages",
+			FALSE,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			G_PARAM_STATIC_STRINGS));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_CHECK_SUBSCRIBED,
+		g_param_spec_boolean (
+			"check-subscribed",
+			"Check Subscribed",
+			"Check only subscribed folders for new messages",
+			FALSE,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			G_PARAM_STATIC_STRINGS));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_CONCURRENT_CONNECTIONS,
+		g_param_spec_uint (
+			"concurrent-connections",
+			"Concurrent Connections",
+			"Number of concurrent IMAP connections to use",
+			MIN_CONCURRENT_CONNECTIONS,
+			MAX_CONCURRENT_CONNECTIONS,
+			5,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			G_PARAM_STATIC_STRINGS));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_FETCH_ORDER,
+		g_param_spec_enum (
+			"fetch-order",
+			"Fetch Order",
+			"Order in which new messages should be fetched",
+			CAMEL_TYPE_SORT_TYPE,
+			CAMEL_SORT_ASCENDING,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			G_PARAM_STATIC_STRINGS));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_FILTER_JUNK,
+		g_param_spec_boolean (
+			"filter-junk",
+			"Filter Junk",
+			"Whether to filter junk from all folders",
+			FALSE,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			G_PARAM_STATIC_STRINGS));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_FILTER_JUNK_INBOX,
+		g_param_spec_boolean (
+			"filter-junk-inbox",
+			"Filter Junk Inbox",
+			"Whether to filter junk from Inbox only",
+			FALSE,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			G_PARAM_STATIC_STRINGS));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_NAMESPACE,
+		g_param_spec_string (
+			"namespace",
+			"Namespace",
+			"Custom IMAP namespace",
+			NULL,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			G_PARAM_STATIC_STRINGS));
+
+	/* Inherited from CamelNetworkSettings. */
+	g_object_class_override_property (
+		object_class,
+		PROP_SECURITY_METHOD,
+		"security-method");
+
+	g_object_class_install_property (
+		object_class,
+		PROP_SHELL_COMMAND,
+		g_param_spec_string (
+			"shell-command",
+			"Shell Command",
+			"Shell command for connecting to the server",
+			"ssh -C -l %u %h exec /usr/sbin/imapd",
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			G_PARAM_STATIC_STRINGS));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_USE_IDLE,
+		g_param_spec_boolean (
+			"use-idle",
+			"Use IDLE",
+			"Whether to use the IDLE IMAP extension",
+			TRUE,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			G_PARAM_STATIC_STRINGS));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_USE_NAMESPACE,
+		g_param_spec_boolean (
+			"use-namespace",
+			"Use Namespace",
+			"Whether to use a custom IMAP namespace",
+			FALSE,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			G_PARAM_STATIC_STRINGS));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_USE_QRESYNC,
+		g_param_spec_boolean (
+			"use-qresync",
+			"Use QRESYNC",
+			"Whether to use the QRESYNC IMAP extension",
+			TRUE,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			G_PARAM_STATIC_STRINGS));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_USE_SHELL_COMMAND,
+		g_param_spec_boolean (
+			"use-shell-command",
+			"Use Shell Command",
+			"Whether to use a custom shell "
+			"command to connect to the server",
+			FALSE,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			G_PARAM_STATIC_STRINGS));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_USE_SUBSCRIPTIONS,
+		g_param_spec_boolean (
+			"use-subscriptions",
+			"Use Subscriptions",
+			"Whether to honor folder subscriptions",
+			TRUE,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			G_PARAM_STATIC_STRINGS));
+}
+
+static void
+camel_imapx_settings_init (CamelIMAPXSettings *settings)
+{
+	settings->priv = CAMEL_IMAPX_SETTINGS_GET_PRIVATE (settings);
+}
+
+/**
+ * camel_imapx_settings_get_batch_fetch_count:
+ * @settings: a #CamelIMAPXSettings
+ *
+ * Returns the number of message envelopes to fetch at once.
+ *
+ * This is a tunable performance parameter and probably should not be
+ * exposed in a graphical user interface.
+ *
+ * Returns: number of message envelopes to fetch at once
+ *
+ * Since: 3.2
+ **/
+guint
+camel_imapx_settings_get_batch_fetch_count (CamelIMAPXSettings *settings)
+{
+	g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), 0);
+
+	return settings->priv->batch_fetch_count;
+}
+
+/**
+ * camel_imapx_settings_set_batch_fetch_count:
+ * @settings: a #CamelIMAPXSettings
+ * @batch_fetch_count: number of message envelopes to fetch at once
+ *
+ * Sets the number of message envelopes to fetch at once.
+ *
+ * This is a tunable performance parameter and probably should not be
+ * exposed in a graphical user interface.
+ *
+ * Since: 3.2
+ **/
+void
+camel_imapx_settings_set_batch_fetch_count (CamelIMAPXSettings *settings,
+                                            guint batch_fetch_count)
+{
+	g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
+
+	settings->priv->batch_fetch_count = batch_fetch_count;
+
+	g_object_notify (G_OBJECT (settings), "batch-fetch-count");
+}
+
+/**
+ * camel_imapx_settings_get_check_all:
+ * @settings: a #CamelIMAPXSettings
+ *
+ * Returns whether to check all folders for new messages.
+ *
+ * Returns: whether to check all folders for new messages
+ *
+ * Since: 3.2
+ **/
+gboolean
+camel_imapx_settings_get_check_all (CamelIMAPXSettings *settings)
+{
+	g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
+
+	return settings->priv->check_all;
+}
+
+/**
+ * camel_imapx_settings_set_check_all:
+ * @settings: a #CamelIMAPXSettings
+ * @check_all: whether to check all folders for new messages
+ *
+ * Sets whether to check all folders for new messages.
+ *
+ * Since: 3.2
+ **/
+void
+camel_imapx_settings_set_check_all (CamelIMAPXSettings *settings,
+                                    gboolean check_all)
+{
+	g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
+
+	settings->priv->check_all = check_all;
+
+	g_object_notify (G_OBJECT (settings), "check-all");
+}
+
+/**
+ * camel_imapx_settings_get_check_subscribed:
+ * @settings: a #CamelIMAPXSettings
+ *
+ * Returns whether to check only subscribed folders for new messages.
+ * Note that #CamelIMAPXSettings:check-all, if %TRUE, overrides this setting.
+ *
+ * Returns: whether to check only subscribed folders for new messages
+ *
+ * Since: 3.2
+ **/
+gboolean
+camel_imapx_settings_get_check_subscribed (CamelIMAPXSettings *settings)
+{
+	g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
+
+	return settings->priv->check_subscribed;
+}
+
+/**
+ * camel_imapx_settings_set_check_subscribed:
+ * @settings: a #CamelIMAPXSettings
+ * @check_subscribed: whether to check only subscribed folders for new messages
+ *
+ * Sets whether to check only subscribed folders for new messages.  Note
+ * that #CamelIMAPXSettings:check-all, if %TRUE, overrides this setting.
+ *
+ * Since: 3.2
+ **/
+void
+camel_imapx_settings_set_check_subscribed (CamelIMAPXSettings *settings,
+                                           gboolean check_subscribed)
+{
+	g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
+
+	settings->priv->check_subscribed = check_subscribed;
+
+	g_object_notify (G_OBJECT (settings), "check-subscribed");
+}
+
+/**
+ * camel_imapx_settings_get_concurrent_connections:
+ * @settings: a #CamelIMAPXSettings
+ * 
+ * Returns the number of concurrent network connections to the IMAP server
+ * to use for faster command/response processing.
+ *
+ * Returns: the number of concurrent connections to use
+ *
+ * Since: 3.2
+ **/
+guint
+camel_imapx_settings_get_concurrent_connections (CamelIMAPXSettings *settings)
+{
+	g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), 1);
+
+	return settings->priv->concurrent_connections;
+}
+
+/**
+ * camel_imapx_settings_set_concurrent_connections:
+ * @settings: a #CamelIMAPXSettings
+ * @concurrent_connections: the number of concurrent connections to use
+ *
+ * Sets the number of concurrent network connections to the IMAP server to
+ * use for faster command/response processing.
+ *
+ * The minimum number of connections is 1, the maximum is 7.  The
+ * @concurrent_connections value will be clamped to these limits if
+ * necessary.
+ *
+ * Since: 3.2
+ **/
+void
+camel_imapx_settings_set_concurrent_connections (CamelIMAPXSettings *settings,
+                                                 guint concurrent_connections)
+{
+	g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
+
+	concurrent_connections = CLAMP (
+		concurrent_connections,
+		MIN_CONCURRENT_CONNECTIONS,
+		MAX_CONCURRENT_CONNECTIONS);
+
+	settings->priv->concurrent_connections = concurrent_connections;
+
+	g_object_notify (G_OBJECT (settings), "concurrent-connections");
+}
+
+/**
+ * camel_imapx_settings_get_fetch_order:
+ * @settings: a #CamelIMAPXSettings
+ *
+ * Returns the order in which new messages should be fetched.
+ *
+ * Returns: the order in which new messages should be fetched
+ *
+ * Since: 3.2
+ **/
+CamelSortType
+camel_imapx_settings_get_fetch_order (CamelIMAPXSettings *settings)
+{
+	g_return_val_if_fail (
+		CAMEL_IS_IMAPX_SETTINGS (settings),
+		CAMEL_SORT_ASCENDING);
+
+	return settings->priv->fetch_order;
+}
+
+/**
+ * camel_imapx_settings_set_fetch_order:
+ * @settings: a #CamelIMAPXSettings
+ * @fetch_order: the order in which new messages should be fetched
+ *
+ * Sets the order in which new messages should be fetched.
+ *
+ * Since: 3.2
+ **/
+void
+camel_imapx_settings_set_fetch_order (CamelIMAPXSettings *settings,
+                                      CamelSortType fetch_order)
+{
+	g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
+
+	settings->priv->fetch_order = fetch_order;
+
+	g_object_notify (G_OBJECT (settings), "fetch-order");
+}
+
+/**
+ * camel_imapx_settings_get_filter_junk:
+ * @settings: a #CamelIMAPXSettings
+ *
+ * Returns whether to automatically find and tag junk messages amongst new
+ * messages in all folders.
+ *
+ * Returns: whether to filter junk in all folders
+ *
+ * Since: 3.2
+ **/
+gboolean
+camel_imapx_settings_get_filter_junk (CamelIMAPXSettings *settings)
+{
+	g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
+
+	return settings->priv->filter_junk;
+}
+
+/**
+ * camel_imapx_settings_set_filter_junk:
+ * @settings: a #CamelIMAPXSettings
+ * @filter_junk: whether to filter junk in all folders
+ *
+ * Sets whether to automatically find and tag junk messages amongst new
+ * messages in all folders.
+ *
+ * Since: 3.2
+ **/
+void
+camel_imapx_settings_set_filter_junk (CamelIMAPXSettings *settings,
+                                      gboolean filter_junk)
+{
+	g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
+
+	settings->priv->filter_junk = filter_junk;
+
+	g_object_notify (G_OBJECT (settings), "filter-junk");
+}
+
+/**
+ * camel_imapx_settings_get_filter_junk_inbox:
+ * @settings: a #CamelIMAPXSettings
+ *
+ * Returns whether to automatically find and tag junk messages amongst new
+ * messages in the Inbox folder only.
+ *
+ * Returns: whether to filter junk in Inbox only
+ *
+ * Since: 3.2
+ **/
+gboolean
+camel_imapx_settings_get_filter_junk_inbox (CamelIMAPXSettings *settings)
+{
+	g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
+
+	return settings->priv->filter_junk_inbox;
+}
+
+/**
+ * camel_imapx_settings_set_filter_junk_inbox:
+ * @settings: a #CamelIMAPXSettings
+ * @filter_junk_inbox: whether to filter junk in Inbox only
+ *
+ * Sets whether to automatically find and tag junk messages amongst new
+ * messages in the Inbox folder only.
+ *
+ * Since: 3.2
+ **/
+void
+camel_imapx_settings_set_filter_junk_inbox (CamelIMAPXSettings *settings,
+                                            gboolean filter_junk_inbox)
+{
+	g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
+
+	settings->priv->filter_junk_inbox = filter_junk_inbox;
+
+	g_object_notify (G_OBJECT (settings), "filter-junk-inbox");
+}
+
+/**
+ * camel_imapx_settings_get_namespace:
+ * @settings: a #CamelIMAPXSettings
+ *
+ * Returns the custom IMAP namespace in which to find folders.
+ *
+ * Returns: the custom IMAP namespace, or %NULL
+ *
+ * Since: 3.2
+ **/
+const gchar *
+camel_imapx_settings_get_namespace (CamelIMAPXSettings *settings)
+{
+	g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), NULL);
+
+	return settings->priv->namespace;
+}
+
+/**
+ * camel_imapx_settings_set_namespace:
+ * @settings: a #CamelIMAPXSettings
+ * @namespace: an IMAP namespace, or %NULL
+ *
+ * Sets the custom IMAP namespace in which to find folders.  If @namespace
+ * is %NULL, the default namespace is used.
+ *
+ * Since: 3.2
+ **/
+void
+camel_imapx_settings_set_namespace (CamelIMAPXSettings *settings,
+                                    const gchar *namespace)
+{
+	g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
+
+	/* The default namespace is an empty string. */
+	if (namespace == NULL)
+		namespace = "";
+
+	g_free (settings->priv->namespace);
+	settings->priv->namespace = g_strdup (namespace);
+
+	g_object_notify (G_OBJECT (settings), "namespace");
+}
+
+/**
+ * camel_imapx_settings_get_shell_command:
+ * @settings: a #CamelIMAPXSettings
+ *
+ * Returns an optional shell command used to establish an input/output
+ * stream with an IMAP server.  Normally the input/output stream is
+ * established through a network socket.
+ *
+ * This option is useful only to a select few advanced users who likely
+ * administer their own IMAP server.  Most users will not understand what
+ * this option menas or how to use it.  Probably not worth exposing in a
+ * graphical interface.
+ *
+ * Returns: shell command for connecting to the server, or %NULL
+ *
+ * Since: 3.2
+ **/
+const gchar *
+camel_imapx_settings_get_shell_command (CamelIMAPXSettings *settings)
+{
+	g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), NULL);
+
+	return settings->priv->shell_command;
+}
+
+/**
+ * camel_imapx_settings_set_shell_command:
+ * @settings: a #CamelIMAPXSettings
+ * @shell_command: shell command for connecting to the server, or %NULL
+ *
+ * Sets an optional shell command used to establish an input/output stream
+ * with an IMAP server.  Normally the input/output stream is established
+ * through a network socket.
+ *
+ * This option is useful only to a select few advanced users who likely
+ * administer their own IMAP server.  Most users will not understand what
+ * this option means or how to use it.  Probably not worth exposing in a
+ * graphical interface.
+ *
+ * Since: 3.2
+ **/
+void
+camel_imapx_settings_set_shell_command (CamelIMAPXSettings *settings,
+                                        const gchar *shell_command)
+{
+	g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
+
+	/* An empty string is equivalent to NULL. */
+	if (shell_command != NULL && *shell_command == '\0')
+		shell_command = NULL;
+
+	g_free (settings->priv->shell_command);
+	settings->priv->shell_command = g_strdup (shell_command);
+
+	g_object_notify (G_OBJECT (settings), "shell-command");
+}
+
+/**
+ * camel_imapx_settings_get_use_idle:
+ * @settings: a #CamelIMAPXSettings
+ *
+ * Returns whether to use the IMAP IDLE extension if the server supports
+ * it.  See RFC 2177 for more details.
+ *
+ * Returns: whether to use the IDLE extension
+ *
+ * Since: 3.2
+ **/
+gboolean
+camel_imapx_settings_get_use_idle (CamelIMAPXSettings *settings)
+{
+	g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
+
+	return settings->priv->use_idle;
+}
+
+/**
+ * camel_imapx_settings_set_use_idle:
+ * @settings: a #CamelIMAPXSettings
+ * @use_idle: whether to use the IDLE extension
+ *
+ * Sets whether to use the IMAP IDLE extension if the server supports it.
+ * See RFC 2177 for more details.
+ *
+ * Since: 3.2
+ **/
+void
+camel_imapx_settings_set_use_idle (CamelIMAPXSettings *settings,
+                                   gboolean use_idle)
+{
+	g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
+
+	settings->priv->use_idle = use_idle;
+
+	g_object_notify (G_OBJECT (settings), "use-idle");
+}
+
+/**
+ * camel_imapx_settings_get_use_namespace:
+ * @settings: a #CamelIMAPXSettings
+ *
+ * Returns whether to use a custom IMAP namespace to find folders.  The
+ * namespace itself is given by the #CamelIMAPStore:namespace property.
+ *
+ * Returns: whether to use a custom IMAP namespace
+ *
+ * Since: 3.2
+ **/
+gboolean
+camel_imapx_settings_get_use_namespace (CamelIMAPXSettings *settings)
+{
+	g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
+
+	return settings->priv->use_namespace;
+}
+
+/**
+ * camel_imapx_settings_set_use_namespace:
+ * @settings: a #CamelIMAPXSettings
+ * @use_namespace: whether to use a custom IMAP namespace
+ *
+ * Sets whether to use a custom IMAP namespace to find folders.  The
+ * namespace itself is given by the #CamelIMAPXSettings:namespace property.
+ *
+ * Since: 3.2
+ **/
+void
+camel_imapx_settings_set_use_namespace (CamelIMAPXSettings *settings,
+                                        gboolean use_namespace)
+{
+	g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
+
+	settings->priv->use_namespace = use_namespace;
+
+	g_object_notify (G_OBJECT (settings), "use-namespace");
+}
+
+/**
+ * camel_imapx_settings_get_use_qresync:
+ * @settings: a #CamelIMAPXSettings
+ *
+ * Returns whether to use the Quick Mailbox Resynchronization (QRESYNC)
+ * IMAP extension if the server supports it.  See RFC 5162 for more
+ * details.
+ *
+ * Returns: whether to use the QRESYNC extension
+ *
+ * Since: 3.2
+ **/
+gboolean
+camel_imapx_settings_get_use_qresync (CamelIMAPXSettings *settings)
+{
+	g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
+
+	return settings->priv->use_qresync;
+}
+
+/**
+ * camel_imapx_settings_set_use_qresync:
+ * @settings: a #CamelIMAPXSettings
+ * @use_qresync: whether to use the QRESYNC extension
+ *
+ * Sets whether to use the Quick Mailbox Resynchronization (QRESYNC)
+ * IMAP extension if the server supports it.  See RFC 5162 for more
+ * details.
+ *
+ * Since: 3.2
+ **/
+void
+camel_imapx_settings_set_use_qresync (CamelIMAPXSettings *settings,
+                                      gboolean use_qresync)
+{
+	g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
+
+	settings->priv->use_qresync = use_qresync;
+
+	g_object_notify (G_OBJECT (settings), "use-qresync");
+}
+
+/**
+ * camel_imapx_settings_get_use_shell_command:
+ * @settings: a #CamelIMAPXSettings
+ *
+ * Returns whether to use a custom shell command to establish an input/output
+ * stream with an IMAP server, instead of the more common method of opening a
+ * network socket.  The shell command itself is given by the
+ * #CamelIMAPXSettings:shell-command property.
+ *
+ * This option is useful only to a select few advanced users who likely
+ * administer their own IMAP server.  Most users will not understand what
+ * this option means or how to use it.  Probably not worth exposing in a
+ * graphical interface.
+ *
+ * Returns: whether to use a custom shell command to connect to the server
+ *
+ * Since: 3.2
+ **/
+gboolean
+camel_imapx_settings_get_use_shell_command (CamelIMAPXSettings *settings)
+{
+	g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
+
+	return settings->priv->use_shell_command;
+}
+
+/**
+ * camel_imapx_settings_set_use_shell_command:
+ * @settings: a #CamelIMAPXSettings
+ * @use_shell_command: whether to use a custom shell command to connect
+ *                     to the server
+ *
+ * Sets whether to use a custom shell command to establish an input/output
+ * stream with an IMAP server, instead of the more common method of opening
+ * a network socket.  The shell command itself is given by the
+ * #CamelIMAPXSettings:shell-command property.
+ *
+ * This option is useful only to a select few advanced users who likely
+ * administer their own IMAP server.  Most users will not understand what
+ * this option means or how to use it.  Probably not worth exposing in a
+ * graphical interface.
+ *
+ * Since: 3.2
+ **/
+void
+camel_imapx_settings_set_use_shell_command (CamelIMAPXSettings *settings,
+                                            gboolean use_shell_command)
+{
+	g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
+
+	settings->priv->use_shell_command = use_shell_command;
+
+	g_object_notify (G_OBJECT (settings), "use-shell-command");
+}
+
+/**
+ * camel_imapx_settings_get_use_subscriptions:
+ * @settings: a #CamelIMAPXSettings
+ *
+ * Returns whether to list and operate only on subscribed folders, or to
+ * list and operate on all available folders regardless of subscriptions.
+ *
+ * Returns: whether to honor folder subscriptions
+ *
+ * Since: 3.2
+ **/
+gboolean
+camel_imapx_settings_get_use_subscriptions (CamelIMAPXSettings *settings)
+{
+	g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
+
+	return settings->priv->use_subscriptions;
+}
+
+/**
+ * camel_imapx_settings_set_use_subscriptions:
+ * @settings: a #CamelIMAPXSettings
+ * @use_subscriptions: whether to honor folder subscriptions
+ *
+ * Sets whether to list and operate only on subscribed folders, or to
+ * list and operate on all available folders regardless of subscriptions.
+ *
+ * Since: 3.2
+ **/
+void
+camel_imapx_settings_set_use_subscriptions (CamelIMAPXSettings *settings,
+                                            gboolean use_subscriptions)
+{
+	g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
+
+	settings->priv->use_subscriptions = use_subscriptions;
+
+	g_object_notify (G_OBJECT (settings), "use-subscriptions");
+}
+
diff --git a/camel/providers/imapx/camel-imapx-settings.h b/camel/providers/imapx/camel-imapx-settings.h
new file mode 100644
index 0000000..e63a01a
--- /dev/null
+++ b/camel/providers/imapx/camel-imapx-settings.h
@@ -0,0 +1,132 @@
+/*
+ * camel-imapx-settings.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef CAMEL_IMAPX_SETTINGS_H
+#define CAMEL_IMAPX_SETTINGS_H
+
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_IMAPX_SETTINGS \
+	(camel_imapx_settings_get_type ())
+#define CAMEL_IMAPX_SETTINGS(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_IMAPX_SETTINGS, CamelIMAPXSettings))
+#define CAMEL_IMAPX_SETTINGS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_IMAPX_SETTINGS, CamelIMAPXSettingsClass))
+#define CAMEL_IS_IMAPX_SETTINGS(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_IMAPX_SETTINGS))
+#define CAMEL_IS_IMAPX_SETTINGS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_IMAPX_SETTINGS))
+#define CAMEL_IMAPX_SETTINGS_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_IMAPX_SETTINGS, CamelIMAPXSettingsClass))
+
+G_BEGIN_DECLS
+
+typedef struct _CamelIMAPXSettings CamelIMAPXSettings;
+typedef struct _CamelIMAPXSettingsClass CamelIMAPXSettingsClass;
+typedef struct _CamelIMAPXSettingsPrivate CamelIMAPXSettingsPrivate;
+
+struct _CamelIMAPXSettings {
+	CamelOfflineSettings parent;
+	CamelIMAPXSettingsPrivate *priv;
+};
+
+struct _CamelIMAPXSettingsClass {
+	CamelOfflineSettingsClass parent_class;
+};
+
+GType		camel_imapx_settings_get_type	(void) G_GNUC_CONST;
+guint		camel_imapx_settings_get_batch_fetch_count
+						(CamelIMAPXSettings *settings);
+void		camel_imapx_settings_set_batch_fetch_count
+						(CamelIMAPXSettings *settings,
+						 guint batch_fetch_count);
+gboolean	camel_imapx_settings_get_check_all
+						(CamelIMAPXSettings *settings);
+void		camel_imapx_settings_set_check_all
+						(CamelIMAPXSettings *settings,
+						 gboolean check_all);
+gboolean	camel_imapx_settings_get_check_subscribed
+						(CamelIMAPXSettings *settings);
+void		camel_imapx_settings_set_check_subscribed
+						(CamelIMAPXSettings *settings,
+						 gboolean check_subscribed);
+guint		camel_imapx_settings_get_concurrent_connections
+						(CamelIMAPXSettings *settings);
+void		camel_imapx_settings_set_concurrent_connections
+						(CamelIMAPXSettings *settings,
+						 guint concurrent_connections);
+CamelSortType	camel_imapx_settings_get_fetch_order
+						(CamelIMAPXSettings *settings);
+void		camel_imapx_settings_set_fetch_order
+						(CamelIMAPXSettings *settings,
+						 CamelSortType fetch_order);
+gboolean	camel_imapx_settings_get_filter_junk
+						(CamelIMAPXSettings *settings);
+void		camel_imapx_settings_set_filter_junk
+						(CamelIMAPXSettings *settings,
+						 gboolean filter_junk);
+gboolean	camel_imapx_settings_get_filter_junk_inbox
+						(CamelIMAPXSettings *settings);
+void		camel_imapx_settings_set_filter_junk_inbox
+						(CamelIMAPXSettings *settings,
+						 gboolean filter_junk_inbox);
+const gchar *	camel_imapx_settings_get_namespace
+						(CamelIMAPXSettings *settings);
+void		camel_imapx_settings_set_namespace
+						(CamelIMAPXSettings *settings,
+						 const gchar *namespace_);
+const gchar *	camel_imapx_settings_get_shell_command
+						(CamelIMAPXSettings *settings);
+void		camel_imapx_settings_set_shell_command
+						(CamelIMAPXSettings *settings,
+						 const gchar *shell_command);
+gboolean	camel_imapx_settings_get_use_idle
+						(CamelIMAPXSettings *settings);
+void		camel_imapx_settings_set_use_idle
+						(CamelIMAPXSettings *settings,
+						 gboolean use_idle);
+gboolean	camel_imapx_settings_get_use_namespace
+						(CamelIMAPXSettings *settings);
+void		camel_imapx_settings_set_use_namespace
+						(CamelIMAPXSettings *settings,
+						 gboolean use_namespace);
+gboolean	camel_imapx_settings_get_use_qresync
+						(CamelIMAPXSettings *settings);
+void		camel_imapx_settings_set_use_qresync
+						(CamelIMAPXSettings *settings,
+						 gboolean use_qresync);
+gboolean	camel_imapx_settings_get_use_shell_command
+						(CamelIMAPXSettings *settings);
+void		camel_imapx_settings_set_use_shell_command
+						(CamelIMAPXSettings *settings,
+						 gboolean use_shell_command);
+gboolean	camel_imapx_settings_get_use_subscriptions
+						(CamelIMAPXSettings *settings);
+void		camel_imapx_settings_set_use_subscriptions
+						(CamelIMAPXSettings *settings,
+						 gboolean use_subscriptions);
+
+G_END_DECLS
+
+#endif /* CAMEL_IMAPX_SETTINGS_H */
diff --git a/camel/providers/imapx/camel-imapx-store.c b/camel/providers/imapx/camel-imapx-store.c
index e32d8bd..034d2af 100644
--- a/camel/providers/imapx/camel-imapx-store.c
+++ b/camel/providers/imapx/camel-imapx-store.c
@@ -39,11 +39,12 @@
 #include <glib/gstdio.h>
 #include <glib/gi18n-lib.h>
 
-#include "camel-imapx-store.h"
 #include "camel-imapx-folder.h"
-#include "camel-imapx-utils.h"
 #include "camel-imapx-server.h"
+#include "camel-imapx-settings.h"
+#include "camel-imapx-store.h"
 #include "camel-imapx-summary.h"
+#include "camel-imapx-utils.h"
 
 /* Specified in RFC 2060 section 2.1 */
 #define IMAP_PORT 143
@@ -68,13 +69,6 @@ G_DEFINE_TYPE_WITH_CODE (
 		CAMEL_TYPE_NETWORK_SERVICE,
 		camel_network_service_init))
 
-enum {
-	PROP_0,
-	PROP_DEFAULT_PORT,
-	PROP_SECURITY_METHOD,
-	PROP_SERVICE_NAME
-};
-
 static guint
 imapx_name_hash (gconstpointer key)
 {
@@ -97,91 +91,26 @@ imapx_name_equal (gconstpointer a, gconstpointer b)
 }
 
 static void
-imapx_parse_receiving_options (CamelIMAPXStore *istore, CamelURL *url)
+imapx_store_dispose (GObject *object)
 {
-	const gchar *val;
-
-	if (camel_url_get_param (url, "use_lsub"))
-		istore->rec_options |= IMAPX_SUBSCRIPTIONS;
-
-	if (camel_url_get_param (url, "override_namespace") && camel_url_get_param (url, "namespace")) {
-		istore->rec_options |= IMAPX_OVERRIDE_NAMESPACE;
-		g_free (istore->namespace);
-		istore->namespace = g_strdup (camel_url_get_param (url, "namespace"));
-	}
-
-	if (camel_url_get_param (url, "check_all"))
-		istore->rec_options |= IMAPX_CHECK_ALL;
-
-	if (camel_url_get_param (url, "check_lsub"))
-		istore->rec_options |= IMAPX_CHECK_LSUB;
-
-	if (camel_url_get_param (url, "filter_junk"))
-		istore->rec_options |= IMAPX_FILTER_JUNK;
-
-	if (camel_url_get_param (url, "filter_junk_inbox"))
-		istore->rec_options |= IMAPX_FILTER_JUNK_INBOX;
-
-	if (camel_url_get_param (url, "use_idle"))
-		istore->rec_options |= IMAPX_USE_IDLE;
-
-	if (camel_url_get_param (url, "use_qresync"))
-		istore->rec_options |= IMAPX_USE_QRESYNC;
-
-	val = camel_url_get_param (url, "cachedconn");
-	if (val) {
-		guint n = strtod (val, NULL);
-		camel_imapx_conn_manager_set_n_connections (istore->con_man, n);
-	}
-}
+	CamelIMAPXStore *imapx_store = CAMEL_IMAPX_STORE (object);
 
-static void
-imapx_store_set_property (GObject *object,
-                          guint property_id,
-                          const GValue *value,
-                          GParamSpec *pspec)
-{
-	switch (property_id) {
-		case PROP_SECURITY_METHOD:
-			camel_network_service_set_security_method (
-				CAMEL_NETWORK_SERVICE (object),
-				g_value_get_enum (value));
-			return;
+	/* Force disconnect so we dont have it run later,
+	 * after we've cleaned up some stuff. */
+	if (imapx_store->con_man != NULL) {
+		camel_service_disconnect_sync (
+			CAMEL_SERVICE (imapx_store), TRUE, NULL);
+		g_object_unref (imapx_store->con_man);
+		imapx_store->con_man = NULL;
 	}
 
-	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-}
-
-static void
-imapx_store_get_property (GObject *object,
-                          guint property_id,
-                          GValue *value,
-                          GParamSpec *pspec)
-{
-	switch (property_id) {
-		case PROP_DEFAULT_PORT:
-			g_value_set_uint (
-				value,
-				camel_network_service_get_default_port (
-				CAMEL_NETWORK_SERVICE (object)));
-			return;
-
-		case PROP_SECURITY_METHOD:
-			g_value_set_enum (
-				value,
-				camel_network_service_get_security_method (
-				CAMEL_NETWORK_SERVICE (object)));
-			return;
-
-		case PROP_SERVICE_NAME:
-			g_value_set_string (
-				value,
-				camel_network_service_get_service_name (
-				CAMEL_NETWORK_SERVICE (object)));
-			return;
+	if (imapx_store->summary != NULL) {
+		g_object_unref (imapx_store->summary);
+		imapx_store->summary = NULL;
 	}
 
-	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (camel_imapx_store_parent_class)->dispose (object);
 }
 
 static void
@@ -189,52 +118,14 @@ imapx_store_finalize (GObject *object)
 {
 	CamelIMAPXStore *imapx_store = CAMEL_IMAPX_STORE (object);
 
-	/* force disconnect so we dont have it run later, after we've cleaned up some stuff */
-	/* SIGH */
-
-	camel_service_disconnect_sync (
-		(CamelService *) imapx_store, TRUE, NULL);
-	if (imapx_store->con_man) {
-		g_object_unref (imapx_store->con_man);
-		imapx_store->con_man = NULL;
-	}
 	g_mutex_free (imapx_store->get_finfo_lock);
 
 	g_free (imapx_store->base_url);
 
-	if (imapx_store->summary)
-		g_object_unref (imapx_store->summary);
-
 	/* Chain up to parent's finalize() method. */
 	G_OBJECT_CLASS (camel_imapx_store_parent_class)->finalize (object);
 }
 
-static void
-imapx_store_constructed (GObject *object)
-{
-	CamelURL *url;
-	const gchar *use_ssl;
-
-	/* Chain up to parent's constructed() method. */
-	G_OBJECT_CLASS (camel_imapx_store_parent_class)->constructed (object);
-
-	url = camel_service_get_camel_url (CAMEL_SERVICE (object));
-	use_ssl = camel_url_get_param (url, "use_ssl");
-
-	if (g_strcmp0 (use_ssl, "never") == 0)
-		camel_network_service_set_security_method (
-			CAMEL_NETWORK_SERVICE (object),
-			CAMEL_NETWORK_SECURITY_METHOD_NONE);
-	else if (g_strcmp0 (use_ssl, "always") == 0)
-		camel_network_service_set_security_method (
-			CAMEL_NETWORK_SERVICE (object),
-			CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT);
-	else if (g_strcmp0 (use_ssl, "when-possible") == 0)
-		camel_network_service_set_security_method (
-			CAMEL_NETWORK_SERVICE (object),
-			CAMEL_NETWORK_SECURITY_METHOD_STARTTLS_ON_STANDARD_PORT);
-}
-
 static gchar *
 imapx_get_name (CamelService *service, gboolean brief)
 {
@@ -717,12 +608,25 @@ get_folder_info_offline (CamelStore *store, const gchar *top,
 			 guint32 flags, GError **error)
 {
 	CamelIMAPXStore *imapx_store = CAMEL_IMAPX_STORE (store);
+	CamelService *service;
+	CamelSettings *settings;
 	gboolean include_inbox = FALSE;
 	CamelFolderInfo *fi;
 	GPtrArray *folders;
 	gchar *pattern, *name;
+	gboolean use_namespace;
+	gboolean use_subscriptions;
 	gint i;
 
+	service = CAMEL_SERVICE (store);
+	settings = camel_service_get_settings (service);
+
+	use_namespace = camel_imapx_settings_get_use_namespace (
+		CAMEL_IMAPX_SETTINGS (settings));
+
+	use_subscriptions = camel_imapx_settings_get_use_subscriptions (
+		CAMEL_IMAPX_SETTINGS (settings));
+
 	/* FIXME: obey other flags */
 
 	folders = g_ptr_array_new ();
@@ -734,7 +638,13 @@ get_folder_info_offline (CamelStore *store, const gchar *top,
 
 	/* get starting point */
 	if (top[0] == 0) {
-		if (imapx_store->namespace && imapx_store->namespace[0]) {
+		const gchar *namespace = NULL;
+
+		if (use_namespace)
+			namespace = camel_imapx_settings_get_namespace (
+				CAMEL_IMAPX_SETTINGS (settings));
+
+		if (namespace != NULL) {
 			name = g_strdup (imapx_store->summary->namespaces->personal->full_name);
 			top = imapx_store->summary->namespaces->personal->path;
 		} else
@@ -772,7 +682,7 @@ get_folder_info_offline (CamelStore *store, const gchar *top,
 		if ((g_str_equal (name, full_name)
 		     || imapx_match_pattern (ns, pattern, full_name)
 		     || (include_inbox && !g_ascii_strcasecmp (full_name, "INBOX")))
-		    && ( ((imapx_store->rec_options & IMAPX_SUBSCRIPTIONS) == 0
+		    && ( (!use_subscriptions
 			    || (flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIBED) == 0)
 			|| (si->flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED)
 			|| (flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIPTION_LIST) != 0)) {
@@ -1108,19 +1018,30 @@ imapx_can_refresh_folder (CamelStore *store,
                           CamelFolderInfo *info,
                           GError **error)
 {
+	CamelService *service;
+	CamelSettings *settings;
 	CamelStoreClass *store_class;
-	CamelURL *url;
+	gboolean check_all;
+	gboolean check_subscribed;
+	gboolean subscribed;
 	gboolean res;
 	GError *local_error = NULL;
 
 	store_class = CAMEL_STORE_CLASS (camel_imapx_store_parent_class);
 
-	url = camel_service_get_camel_url (CAMEL_SERVICE (store));
+	service = CAMEL_SERVICE (store);
+	settings = camel_service_get_settings (service);
+
+	check_all = camel_imapx_settings_get_check_all (
+		CAMEL_IMAPX_SETTINGS (settings));
+
+	check_subscribed = camel_imapx_settings_get_check_subscribed (
+		CAMEL_IMAPX_SETTINGS (settings));
+
+	subscribed = ((info->flags & CAMEL_FOLDER_SUBSCRIBED) != 0);
 
 	res = store_class->can_refresh_folder (store, info, &local_error) ||
-		(camel_url_get_param (url, "check_all") != NULL) ||
-		(camel_url_get_param (url, "check_lsub") != NULL &&
-		(info->flags & CAMEL_FOLDER_SUBSCRIBED) != 0);
+		check_all || (check_subscribed && subscribed);
 
 	if (!res && local_error == NULL && CAMEL_IS_IMAPX_STORE (store)) {
 		CamelStoreInfo *si;
@@ -1190,11 +1111,19 @@ imapx_store_get_folder_info_sync (CamelStore *store,
 {
 	CamelIMAPXStore *istore = (CamelIMAPXStore *) store;
 	CamelFolderInfo * fi= NULL;
+	CamelService *service;
 	CamelSession *session;
+	CamelSettings *settings;
 	gboolean initial_setup = FALSE;
+	gboolean use_subscriptions;
 	gchar *pattern;
 
-	session = camel_service_get_session (CAMEL_SERVICE (store));
+	service = CAMEL_SERVICE (store);
+	session = camel_service_get_session (service);
+	settings = camel_service_get_settings (service);
+
+	use_subscriptions = camel_imapx_settings_get_use_subscriptions (
+		CAMEL_IMAPX_SETTINGS (settings));
 
 	if (top == NULL)
 		top = "";
@@ -1265,7 +1194,7 @@ imapx_store_get_folder_info_sync (CamelStore *store,
 	camel_store_summary_save ((CamelStoreSummary *) istore->summary);
 
 	/* ensure the INBOX is subscribed if lsub was preferred*/
-	if (initial_setup && istore->rec_options & IMAPX_SUBSCRIPTIONS)
+	if (initial_setup && use_subscriptions)
 		discover_inbox (store, cancellable);
 
 	fi = get_folder_info_offline (store, top, flags, error);
@@ -1474,13 +1403,19 @@ imapx_store_rename_folder_sync (CamelStore *store,
 	CamelIMAPXStore *istore = (CamelIMAPXStore *) store;
 	CamelIMAPXServer *server;
 	CamelService *service;
+	CamelSettings *settings;
 	const gchar *user_data_dir;
 	gchar *oldpath, *newpath, *storage_path;
+	gboolean use_subscriptions;
 	gboolean success = FALSE;
 
 	service = CAMEL_SERVICE (store);
+	settings = camel_service_get_settings (service);
 	user_data_dir = camel_service_get_user_data_dir (service);
 
+	use_subscriptions = camel_imapx_settings_get_use_subscriptions (
+		CAMEL_IMAPX_SETTINGS (settings));
+
 	if (!camel_offline_store_get_online (CAMEL_OFFLINE_STORE (store))) {
 		g_set_error (
 			error, CAMEL_SERVICE_ERROR,
@@ -1489,7 +1424,7 @@ imapx_store_rename_folder_sync (CamelStore *store,
 		return FALSE;
 	}
 
-	if (istore->rec_options & IMAPX_SUBSCRIPTIONS)
+	if (use_subscriptions)
 		imapx_unsubscribe_folder (store, old, FALSE, cancellable, NULL);
 
 	/* Use INBOX connection as the implementation would try to select inbox to ensure
@@ -1509,7 +1444,7 @@ imapx_store_rename_folder_sync (CamelStore *store,
 	/* rename summary, and handle broken server */
 	rename_folder_info (istore, old, new);
 
-	if (istore->rec_options & IMAPX_SUBSCRIPTIONS)
+	if (use_subscriptions)
 		success = imapx_subscribe_folder (
 			store, new, FALSE, cancellable, error);
 
@@ -1601,7 +1536,6 @@ imapx_store_initable_init (GInitable *initable,
 	store->base_url = camel_url_to_string (
 		url, CAMEL_URL_HIDE_PASSWORD |
 		CAMEL_URL_HIDE_PARAMS | CAMEL_URL_HIDE_AUTH);
-	imapx_parse_receiving_options (store, url);
 
 	store->summary = camel_imapx_store_summary_new ();
 
@@ -1618,13 +1552,11 @@ imapx_store_initable_init (GInitable *initable,
 }
 
 static const gchar *
-imapx_store_get_service_name (CamelNetworkService *service)
+imapx_store_get_service_name (CamelNetworkService *service,
+                              CamelNetworkSecurityMethod method)
 {
-	CamelNetworkSecurityMethod method;
 	const gchar *service_name;
 
-	method = camel_network_service_get_security_method (service);
-
 	switch (method) {
 		case CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT:
 			service_name = "imaps";
@@ -1639,13 +1571,11 @@ imapx_store_get_service_name (CamelNetworkService *service)
 }
 
 static guint16
-imapx_store_get_default_port (CamelNetworkService *service)
+imapx_store_get_default_port (CamelNetworkService *service,
+                              CamelNetworkSecurityMethod method)
 {
-	CamelNetworkSecurityMethod method;
 	guint16 default_port;
 
-	method = camel_network_service_get_security_method (service);
-
 	switch (method) {
 		case CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT:
 			default_port = IMAPS_PORT;
@@ -1667,12 +1597,11 @@ camel_imapx_store_class_init (CamelIMAPXStoreClass *class)
 	CamelStoreClass *store_class;
 
 	object_class = G_OBJECT_CLASS (class);
-	object_class->set_property = imapx_store_set_property;
-	object_class->get_property = imapx_store_get_property;
+	object_class->dispose = imapx_store_dispose;
 	object_class->finalize = imapx_store_finalize;
-	object_class->constructed = imapx_store_constructed;
 
 	service_class = CAMEL_SERVICE_CLASS (class);
+	service_class->settings_type = CAMEL_TYPE_IMAPX_SETTINGS;
 	service_class->get_name = imapx_get_name;
 	service_class->connect_sync = imapx_connect_sync;
 	service_class->disconnect_sync = imapx_disconnect_sync;
@@ -1694,24 +1623,6 @@ camel_imapx_store_class_init (CamelIMAPXStoreClass *class)
 	store_class->subscribe_folder_sync = imapx_store_subscribe_folder_sync;
 	store_class->unsubscribe_folder_sync = imapx_store_unsubscribe_folder_sync;
 	store_class->noop_sync = imapx_store_noop_sync;
-
-	/* Inherited from CamelNetworkService. */
-	g_object_class_override_property (
-		object_class,
-		PROP_DEFAULT_PORT,
-		"default-port");
-
-	/* Inherited from CamelNetworkService. */
-	g_object_class_override_property (
-		object_class,
-		PROP_SECURITY_METHOD,
-		"security-method");
-
-	/* Inherited from CamelNetworkService. */
-	g_object_class_override_property (
-		object_class,
-		PROP_SERVICE_NAME,
-		"service-name");
 }
 
 static void
@@ -1740,3 +1651,4 @@ camel_imapx_store_init (CamelIMAPXStore *istore)
 	istore->dir_sep = '/';
 	istore->con_man = camel_imapx_conn_manager_new (store);
 }
+
diff --git a/camel/providers/imapx/camel-imapx-store.h b/camel/providers/imapx/camel-imapx-store.h
index 83c883a..5324311 100644
--- a/camel/providers/imapx/camel-imapx-store.h
+++ b/camel/providers/imapx/camel-imapx-store.h
@@ -49,27 +49,20 @@
 	(G_TYPE_INSTANCE_GET_CLASS \
 	((obj), CAMEL_TYPE_IMAPX_STORE, CamelIMAPXStoreClass))
 
-#define IMAPX_OVERRIDE_NAMESPACE	(1 << 0)
-#define IMAPX_CHECK_ALL			(1 << 1)
-#define IMAPX_FILTER_JUNK		(1 << 2)
-#define IMAPX_FILTER_JUNK_INBOX		(1 << 3)
-#define IMAPX_SUBSCRIPTIONS		(1 << 4)
-#define IMAPX_CHECK_LSUB		(1 << 5)
-#define IMAPX_USE_IDLE			(1 << 6)
-#define IMAPX_USE_QRESYNC		(1 << 7)
-
 G_BEGIN_DECLS
 
 typedef struct _CamelIMAPXStore CamelIMAPXStore;
 typedef struct _CamelIMAPXStoreClass CamelIMAPXStoreClass;
+typedef struct _CamelIMAPXStorePrivate CamelIMAPXStorePrivate;
 
 struct _CamelIMAPXStore {
 	CamelOfflineStore parent;
+	CamelIMAPXStorePrivate *priv;
 
 	CamelIMAPXConnManager *con_man;
 
 	CamelIMAPXStoreSummary *summary; /* in-memory list of folders */
-	gchar *namespace, dir_sep, *base_url;
+	gchar dir_sep, *base_url;
 
 	guint32 rec_options;
 
@@ -91,14 +84,15 @@ struct _CamelIMAPXStoreClass {
 	CamelOfflineStoreClass parent_class;
 };
 
-GType			camel_imapx_store_get_type	(void);
-CamelIMAPXServer *	camel_imapx_store_get_server	(CamelIMAPXStore *store,
-							const gchar *folder_name,
-							GCancellable *cancellable,
-							GError **error);
-void			camel_imapx_store_op_done	(CamelIMAPXStore *istore,
-							CamelIMAPXServer *server,
-							const gchar *folder_name);
+GType		camel_imapx_store_get_type	(void);
+CamelIMAPXServer *
+		camel_imapx_store_get_server	(CamelIMAPXStore *store,
+						const gchar *folder_name,
+						GCancellable *cancellable,
+						GError **error);
+void		camel_imapx_store_op_done	(CamelIMAPXStore *istore,
+						CamelIMAPXServer *server,
+						const gchar *folder_name);
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]