[evolution-data-server] IMAPX: optionally download the messages in descending order. TODO: Add advanced UI options for the s
- From: Chenthill Palanisamy <pchen src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] IMAPX: optionally download the messages in descending order. TODO: Add advanced UI options for the s
- Date: Fri, 20 May 2011 10:34:20 +0000 (UTC)
commit 4134d0ad40e0df0d75b1f3463bd2c47033e258cc
Author: Chenthill Palanisamy <pchenthill novell com>
Date: Fri May 20 15:59:29 2011 +0530
IMAPX: optionally download the messages in descending order.
TODO: Add advanced UI options for the same.
Document all the url parameters in a common place.
camel/providers/imapx/camel-imapx-server.c | 77 ++++++++++++++++++++++++----
camel/providers/imapx/camel-imapx-server.h | 3 +
2 files changed, 69 insertions(+), 11 deletions(-)
---
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index c4640f7..d265799 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -314,7 +314,7 @@ static void imapx_job_done (CamelIMAPXServer *is, CamelIMAPXJob *job);
static gboolean imapx_run_job (CamelIMAPXServer *is, CamelIMAPXJob *job, GError **error);
static void imapx_job_fetch_new_messages_start (CamelIMAPXServer *is, CamelIMAPXJob *job);
static void imapx_command_copy_messages_step_done (CamelIMAPXServer *is, CamelIMAPXCommand *ic);
-static gint imapx_refresh_info_uid_cmp (gconstpointer ap, gconstpointer bp);
+static gint imapx_refresh_info_uid_cmp (gconstpointer ap, gconstpointer bp, gboolean ascending);
static gint imapx_uids_array_cmp (gconstpointer ap, gconstpointer bp);
static gboolean imapx_server_sync_changes (CamelIMAPXServer *is, CamelFolder *folder, gint pri, GCancellable *cancellable, GError **error);
@@ -362,6 +362,27 @@ 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)
@@ -1550,7 +1571,7 @@ imapx_untagged (CamelIMAPXServer *imap,
mid = (min + max)/2;
r = &g_array_index (infos, struct _refresh_info, mid);
- cmp = imapx_uid_cmp (finfo->uid, r->uid, NULL);
+ cmp = imapx_refresh_info_uid_cmp (finfo->uid, r->uid, !imap->descending);
if (cmp > 0)
min = mid + 1;
@@ -3623,7 +3644,7 @@ imapx_job_append_message_start (CamelIMAPXServer *is,
/* ********************************************************************** */
static gint
-imapx_refresh_info_uid_cmp (gconstpointer ap, gconstpointer bp)
+imapx_refresh_info_uid_cmp (gconstpointer ap, gconstpointer bp, gboolean ascending)
{
guint av, bv;
@@ -3631,9 +3652,9 @@ imapx_refresh_info_uid_cmp (gconstpointer ap, gconstpointer bp)
bv = g_ascii_strtoull ((const gchar *) bp, NULL, 10);
if (av<bv)
- return -1;
+ return ascending ? -1 : 1;
else if (av>bv)
- return 1;
+ return ascending ? 1 : -1;
else
return 0;
}
@@ -3644,7 +3665,7 @@ imapx_uids_array_cmp (gconstpointer ap, gconstpointer bp)
const gchar **a = (const gchar **) ap;
const gchar **b = (const gchar **) bp;
- return imapx_refresh_info_uid_cmp (*a, *b);
+ return imapx_refresh_info_uid_cmp (*a, *b, TRUE);
}
static gint
@@ -3653,7 +3674,17 @@ imapx_refresh_info_cmp (gconstpointer ap, gconstpointer bp)
const struct _refresh_info *a = ap;
const struct _refresh_info *b = bp;
- return imapx_refresh_info_uid_cmp (a->uid, b->uid);
+ return imapx_refresh_info_uid_cmp (a->uid, b->uid, TRUE);
+}
+
+static gint
+imapx_refresh_info_cmp_descending (gconstpointer ap, gconstpointer bp)
+{
+ const struct _refresh_info *a = ap;
+ const struct _refresh_info *b = bp;
+
+ return imapx_refresh_info_uid_cmp (a->uid, b->uid, FALSE);
+
}
/* skips over non-server uids (pending appends) */
@@ -3939,7 +3970,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, BATCH_FETCH_COUNT, 0);
+ imapx_uidset_init (&job->u.refresh_info.uidset, get_batch_fetch_count (is), 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;
@@ -4045,6 +4076,17 @@ exception:
}
static void
+imapx_command_fetch_new_uids_done (CamelIMAPXServer *is,
+ CamelIMAPXCommand *ic)
+{
+ CamelIMAPXJob *job = ic->job;
+ GArray *infos = job->u.refresh_info.infos;
+
+ qsort (infos->data, infos->len, sizeof (struct _refresh_info), imapx_refresh_info_cmp_descending);
+ imapx_command_step_fetch_done (is, ic);
+}
+
+static void
imapx_job_fetch_new_messages_start (CamelIMAPXServer *is,
CamelIMAPXJob *job)
{
@@ -4071,14 +4113,18 @@ imapx_job_fetch_new_messages_start (CamelIMAPXServer *is,
_("Fetching summary information for new messages in %s"),
camel_folder_get_display_name (folder));
- if (diff > BATCH_FETCH_COUNT) {
+ if (diff > get_batch_fetch_count (is) || is->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, BATCH_FETCH_COUNT, 0);
+ imapx_uidset_init (&job->u.refresh_info.uidset, get_batch_fetch_count (is), 0);
job->u.refresh_info.infos = g_array_new (0, 0, sizeof (struct _refresh_info));
ic->pri = job->pri;
- ic->complete = imapx_command_step_fetch_done;
+
+ if (is->descending)
+ ic->complete = imapx_command_fetch_new_uids_done;
+ else
+ ic->complete = imapx_command_step_fetch_done;
} else {
ic = camel_imapx_command_new (
is, "FETCH", job->folder, job->cancellable,
@@ -5153,6 +5199,7 @@ 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);
@@ -5162,6 +5209,14 @@ 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 d89dfb7..22d573c 100644
--- a/camel/providers/imapx/camel-imapx-server.h
+++ b/camel/providers/imapx/camel-imapx-server.h
@@ -119,6 +119,9 @@ 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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]