[dovecot-cvs] dovecot/src/imap commands-util.c, 1.44, 1.45 commands-util.h, 1.23, 1.24 imap-sync.c, 1.11, 1.12

cras at dovecot.org cras at dovecot.org
Sat Jul 23 13:13:57 EEST 2005


Update of /var/lib/cvs/dovecot/src/imap
In directory talvi:/tmp/cvs-serv8006

Modified Files:
	commands-util.c commands-util.h imap-sync.c 
Log Message:
Send untagged FLAGS / PERMANENTFLAGS replies if keywords list changed.



Index: commands-util.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/commands-util.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- commands-util.c	4 Jul 2005 11:32:19 -0000	1.44
+++ commands-util.c	23 Jul 2005 10:13:54 -0000	1.45
@@ -159,10 +159,12 @@
 	unsigned int i, count;
 
 	/* if it already exists, skip validity checks */
-	names = array_get(&cmd->client->keywords.keywords, &count);
-	for (i = 0; i < count; i++) {
-		if (strcasecmp(names[i], keyword) == 0)
-			return TRUE;
+	if (array_is_created(&cmd->client->keywords.keywords)) {
+		names = array_get(&cmd->client->keywords.keywords, &count);
+		for (i = 0; i < count; i++) {
+			if (strcasecmp(names[i], keyword) == 0)
+				return TRUE;
+		}
 	}
 
 	if (strlen(keyword) > max_keyword_length) {
@@ -283,23 +285,47 @@
 	}
 }
 
-void client_save_keywords(struct mailbox_keywords *dest,
-			  const array_t *keywords)
+int client_save_keywords(struct mailbox_keywords *dest,
+			 const array_t *keywords)
 {
 	ARRAY_SET_TYPE(keywords, const char *);
-	const char *const *names;
-	unsigned int i, count;
+	const char *const *names, *const *old_names;
+	unsigned int i, count, old_count;
+	int changed;
+
+	names = array_get(keywords, &count);
+
+	/* first check if anything changes */
+	if (!array_is_created(&dest->keywords))
+		changed = count != 0;
+	else {
+		old_names = array_get(&dest->keywords, &old_count);
+		if (count != old_count)
+			changed = TRUE;
+		else {
+			changed = FALSE;
+			for (i = 0; i < count; i++) {
+				if (strcmp(names[i], old_names[i]) != 0) {
+					changed = TRUE;
+					break;
+				}
+			}
+		}
+	}
+
+	if (!changed)
+		return FALSE;
 
 	p_clear(dest->pool);
 	ARRAY_CREATE(&dest->keywords, dest->pool,
 		     const char *, array_count(keywords));
 
-	names = array_get(keywords, &count);
 	for (i = 0; i < count; i++) {
 		const char *name = p_strdup(dest->pool, names[i]);
 
 		array_append(&dest->keywords, &name, 1);
 	}
+	return TRUE;
 }
 
 int mailbox_equals(struct mailbox *box1, struct mail_storage *storage2,

Index: commands-util.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/commands-util.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- commands-util.h	2 Apr 2005 21:08:56 -0000	1.23
+++ commands-util.h	23 Jul 2005 10:13:54 -0000	1.24
@@ -46,9 +46,10 @@
 void client_send_mailbox_flags(struct client *client, struct mailbox *box,
 			       const array_t *keywords);
 
-/* Copy keywords into dest. dest must have been initialized. */
-void client_save_keywords(struct mailbox_keywords *dest,
-			  const array_t *keywords);
+/* Copy keywords into dest. dest must have been initialized. Returns TRUE if
+   keywords changed. */
+int client_save_keywords(struct mailbox_keywords *dest,
+			 const array_t *keywords);
 
 int mailbox_equals(struct mailbox *box1, struct mail_storage *storage2,
 		   const char *name2);

Index: imap-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/imap-sync.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- imap-sync.c	8 May 2005 10:09:43 -0000	1.11
+++ imap-sync.c	23 Jul 2005 10:13:54 -0000	1.12
@@ -33,6 +33,7 @@
 	       enum mailbox_sync_flags flags)
 {
 	struct imap_sync_context *ctx;
+	struct mailbox_status status;
 
 	i_assert(client->mailbox == box);
 
@@ -44,6 +45,13 @@
 	ctx->t = mailbox_transaction_begin(box, 0);
 	ctx->mail = mail_alloc(ctx->t, MAIL_FETCH_FLAGS, 0);
 	ctx->messages_count = client->messages_count;
+
+	/* if keyword list changed, send the new list before flag changes */
+	if (mailbox_get_status(ctx->box, STATUS_KEYWORDS, &status) == 0) {
+		if (client_save_keywords(&client->keywords, status.keywords))
+			client_send_mailbox_flags(client, box, status.keywords);
+	}
+
 	return ctx;
 }
 
@@ -74,9 +82,6 @@
 			t_strdup_printf("* %u RECENT", status.recent));
 	}
 
-	/*FIXME:client_save_keywords(&client->keywords, keywords, keywords_count);
-	client_send_mailbox_flags(client, mailbox, keywords, keywords_count);*/
-
 	t_pop();
 	i_free(ctx);
 	return 0;



More information about the dovecot-cvs mailing list