Fix QRESYNC protocol violation (RH #648082)
authorDavid Woodhouse <David.Woodhouse@intel.com>
Thu, 11 Nov 2010 01:34:18 +0000 (01:34 +0000)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Thu, 11 Nov 2010 01:34:18 +0000 (01:34 +0000)
The sequence-set '1:*' isn't valid in QRESYNC, and newer versions of
Dovecot (>=2.0) have started to object to it.

Ideally we'd omit the parameter completely, since it's supposed to be
optional — but *older* versions of Dovecot (<=1.2.13) require it.

We only really care about messages which we already knew about. For any
*new* messages, we're going to fetch the headers and the flags in an
explicit FETCH command anyway, and we'll ignore anything that QRESYNC
tells us about them. So just use the first and last UID from our existing
summary cache as the range for the QRESYNC command.

Fix a shadow declaration of the 'uid' variable in an inner block, while
we're at it.

camel/providers/imapx/camel-imapx-server.c

index d8d72dd..30a8ecd 100644 (file)
@@ -2602,14 +2602,28 @@ imapx_select (CamelIMAPXServer *is,
                CamelIMAPXSummary *isum = (CamelIMAPXSummary *)folder->summary;
                CamelIMAPXFolder *ifolder = (CamelIMAPXFolder *)folder;
                gint total = camel_folder_summary_count (folder->summary);
-               gchar *uid = NULL;
+               gchar *firstuid = NULL, *lastuid = NULL;
 
-               if (total)
-                       uid = camel_folder_summary_uid_from_index (folder->summary, 0);
+               if (total) {
+                       firstuid = camel_folder_summary_uid_from_index (folder->summary, 0);
+                       lastuid = camel_folder_summary_uid_from_index (folder->summary, total - 1);
+               }
 
                if (isum->modseq && ifolder->uidvalidity_on_server) {
-                       c(is->tagprefix, "SELECT QRESYNC %" G_GUINT64_FORMAT " %" G_GUINT64_FORMAT "\n", ifolder->uidvalidity_on_server, isum->modseq);
-                       camel_imapx_command_add(ic, " (QRESYNC (%" G_GUINT64_FORMAT " %" G_GUINT64_FORMAT " %s:*", ifolder->uidvalidity_on_server, isum->modseq, uid?uid:"1");
+                       c(is->tagprefix, "SELECT QRESYNC %" G_GUINT64_FORMAT
+                         " %" G_GUINT64_FORMAT "\n",
+                         ifolder->uidvalidity_on_server, isum->modseq);
+
+                       camel_imapx_command_add(ic, " (QRESYNC (%"
+                                               G_GUINT64_FORMAT " %"
+                                               G_GUINT64_FORMAT " %s:%s",
+                                               ifolder->uidvalidity_on_server,
+                                               isum->modseq,
+                                               firstuid?firstuid:"1",
+                                               lastuid?lastuid:"1");
+
+                       g_free (firstuid);
+                       g_free (lastuid);
 
                        if (total > 10) {
                                gint i;
@@ -2657,7 +2671,6 @@ imapx_select (CamelIMAPXServer *is,
                        }
                        camel_imapx_command_add(ic, "))");
                }
-               g_free (uid);
        }
 
        ic->complete = imapx_command_select_done;