changeset 7633:27a0de620b0c HEAD

If CONDSTORE is enabled only after mailbox has been selected, send HIGHESTMODSEQ so client knows if it had missed some changes.
author Timo Sirainen <tss@iki.fi>
date Sun, 16 Mar 2008 07:25:40 +0200
parents 6e2e4e5c52f3
children 3980292275ab
files src/imap/client.c src/imap/cmd-select.c
diffstat 2 files changed, 27 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/client.c	Sun Mar 16 07:18:06 2008 +0200
+++ b/src/imap/client.c	Sun Mar 16 07:25:40 2008 +0200
@@ -782,9 +782,25 @@
 
 void client_enable(struct client *client, enum mailbox_feature features)
 {
+	struct mailbox_status status;
+
+	if ((client->enabled_features & features) == features)
+		return;
+
 	client->enabled_features |= features;
-	if (client->mailbox != NULL)
-		mailbox_enable(client->mailbox, features);
+	if (client->mailbox == NULL)
+		return;
+
+	mailbox_enable(client->mailbox, features);
+	if ((features & MAILBOX_FEATURE_CONDSTORE) != 0) {
+		/* CONDSTORE being enabled while mailbox is selected.
+		   Notify client of the latest HIGHESTMODSEQ. */
+		mailbox_get_status(client->mailbox,
+				   STATUS_HIGHESTMODSEQ, &status);
+		client_send_line(client, t_strdup_printf(
+			"* OK [HIGHESTMODSEQ %llu]",
+			(unsigned long long)status.highest_modseq));
+	}
 }
 
 void clients_init(void)
--- a/src/imap/cmd-select.c	Sun Mar 16 07:18:06 2008 +0200
+++ b/src/imap/cmd-select.c	Sun Mar 16 07:25:40 2008 +0200
@@ -22,6 +22,8 @@
 	ARRAY_TYPE(seq_range) qresync_known_uids;
 	ARRAY_TYPE(uint32_t) qresync_sample_seqset;
 	ARRAY_TYPE(uint32_t) qresync_sample_uidset;
+
+	unsigned int condstore:1;
 };
 
 static int select_qresync_get_uids(struct imap_select_context *ctx,
@@ -157,8 +159,7 @@
 		args++;
 
 		if (strcmp(name, "CONDSTORE") == 0)
-			client_enable(ctx->cmd->client,
-				      MAILBOX_FEATURE_CONDSTORE);
+			ctx->condstore = TRUE;
 		else if (strcmp(name, "QRESYNC") == 0) {
 			if (!select_parse_qresync(ctx, args))
 				return FALSE;
@@ -367,6 +368,12 @@
 		client_send_line(client, "* OK [CLOSED]");
 	}
 
+	if (ctx->condstore) {
+		/* Enable while no mailbox is opened to avoid sending
+		   HIGHESTMODSEQ for previously opened mailbox */
+		client_enable(client, MAILBOX_FEATURE_CONDSTORE);
+	}
+
 	ret = select_open(ctx, mailbox, readonly);
 	cmd_select_finish(ctx, ret);
 	return TRUE;