[dovecot-cvs] dovecot/src/imap client.h, 1.28, 1.29 cmd-append.c, 1.59, 1.60 cmd-select.c, 1.36, 1.37 commands-util.c, 1.42, 1.43 commands-util.h, 1.22, 1.23

cras at dovecot.org cras at dovecot.org
Sun Apr 3 00:08:59 EEST 2005


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

Modified Files:
	client.h cmd-append.c cmd-select.c commands-util.c 
	commands-util.h 
Log Message:
Keywords are now stored in X-Keywords headers in mbox. Did several related
API changes to get better performance.



Index: client.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/client.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- client.h	5 Feb 2005 18:07:26 -0000	1.28
+++ client.h	2 Apr 2005 21:08:56 -0000	1.29
@@ -11,8 +11,7 @@
 struct mailbox_keywords {
 	pool_t pool; /* will be p_clear()ed when changed */
 
-	char **keywords;
-        unsigned int keywords_count;
+	array_t ARRAY_DEFINE(keywords, const char *);
 };
 
 struct client_command_context {

Index: cmd-append.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-append.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- cmd-append.c	29 Mar 2005 13:33:08 -0000	1.59
+++ cmd-append.c	2 Apr 2005 21:08:56 -0000	1.60
@@ -393,8 +393,8 @@
 			mailbox_close(ctx->box);
 			ctx->box = NULL;
 		} else {
-			client_save_keywords(&client->keywords, status.keywords,
-					     status.keywords_count);
+			client_save_keywords(&client->keywords,
+					     status.keywords);
 		}
 		ctx->t = ctx->box == NULL ? NULL :
 			mailbox_transaction_begin(ctx->box,

Index: cmd-select.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-select.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- cmd-select.c	29 Mar 2005 13:33:08 -0000	1.36
+++ cmd-select.c	2 Apr 2005 21:08:56 -0000	1.37
@@ -51,8 +51,7 @@
 		return TRUE;
 	}
 
-	client_save_keywords(&client->keywords,
-			     status.keywords, status.keywords_count);
+	client_save_keywords(&client->keywords, status.keywords);
 	client->messages_count = status.messages;
 	client->recent_count = status.recent;
 
@@ -61,8 +60,7 @@
 	client->mailbox = box;
 	client->select_counter++;
 
-	client_send_mailbox_flags(client, box, status.keywords,
-				  status.keywords_count);
+	client_send_mailbox_flags(client, box, status.keywords);
 
 	client_send_line(client,
 		t_strdup_printf("* %u EXISTS", status.messages));

Index: commands-util.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/commands-util.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- commands-util.c	15 Mar 2005 21:52:07 -0000	1.42
+++ commands-util.c	2 Apr 2005 21:08:56 -0000	1.43
@@ -154,13 +154,13 @@
 static int is_valid_keyword(struct client_command_context *cmd,
 			    const char *keyword)
 {
-	struct mailbox_keywords *keywords = &cmd->client->keywords;
-	size_t i;
+	const char *const *names;
+	unsigned int i, count;
 
 	/* if it already exists, skip validity checks */
-	for (i = 0; i < keywords->keywords_count; i++) {
-		if (keywords->keywords[i] != NULL &&
-		    strcasecmp(keywords->keywords[i], keyword) == 0)
+	names = array_get(&cmd->client->keywords.keywords, &count);
+	for (i = 0; i < count; i++) {
+		if (strcasecmp(names[i], keyword) == 0)
 			return TRUE;
 	}
 
@@ -241,27 +241,21 @@
 	return TRUE;
 }
 
-static const char *
-get_keywords_string(const char *const keywords[], unsigned int keywords_count)
+static const char *get_keywords_string(const array_t *keywords)
 {
+	ARRAY_SET_TYPE(keywords, const char *);
 	string_t *str;
-	unsigned int i;
-
-	/* first see if there even is keywords */
-	for (i = 0; i < keywords_count; i++) {
-		if (keywords[i] != NULL)
-			break;
-	}
+	const char *const *names;
+	unsigned int i, count;
 
-	if (i == keywords_count)
+	if (array_count(keywords) == 0)
 		return "";
 
 	str = t_str_new(256);
-	for (; i < keywords_count; i++) {
-		if (keywords[i] != NULL) {
-			str_append_c(str, ' ');
-			str_append(str, keywords[i]);
-		}
+	names = array_get(keywords, &count);
+	for (i = 0; i < count; i++) {
+		str_append_c(str, ' ');
+		str_append(str, names[i]);
 	}
 	return str_c(str);
 }
@@ -269,12 +263,11 @@
 #define SYSTEM_FLAGS "\\Answered \\Flagged \\Deleted \\Seen \\Draft"
 
 void client_send_mailbox_flags(struct client *client, struct mailbox *box,
-			       const char *const keywords[],
-			       unsigned int keywords_count)
+			       const array_t *keywords)
 {
 	const char *str;
 
-	str = get_keywords_string(keywords, keywords_count);
+	str = get_keywords_string(keywords);
 	client_send_line(client,
 		t_strconcat("* FLAGS ("SYSTEM_FLAGS, str, ")", NULL));
 
@@ -290,24 +283,22 @@
 }
 
 void client_save_keywords(struct mailbox_keywords *dest,
-			  const char *const keywords[],
-			  unsigned int keywords_count)
+			  const array_t *keywords)
 {
-	unsigned int i;
+	ARRAY_SET_TYPE(keywords, const char *);
+	const char *const *names;
+	unsigned int i, count;
 
 	p_clear(dest->pool);
+	ARRAY_CREATE(&dest->keywords, dest->pool,
+		     const char *, array_count(keywords));
 
-	if (keywords_count == 0) {
-		dest->keywords = NULL;
-		dest->keywords_count = 0;
-		return;
-	}
-
-	dest->keywords = p_new(dest->pool, char *, keywords_count);
-	dest->keywords_count = keywords_count;
+	names = array_get(keywords, &count);
+	for (i = 0; i < count; i++) {
+		const char *name = p_strdup(dest->pool, names[i]);
 
-	for (i = 0; i < keywords_count; i++)
-		dest->keywords[i] = p_strdup(dest->pool, keywords[i]);
+		array_append(&dest->keywords, &name, 1);
+	}
 }
 
 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.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- commands-util.h	15 Mar 2005 21:52:07 -0000	1.22
+++ commands-util.h	2 Apr 2005 21:08:56 -0000	1.23
@@ -44,13 +44,11 @@
 
 /* Send FLAGS + PERMANENTFLAGS to client. */
 void client_send_mailbox_flags(struct client *client, struct mailbox *box,
-			       const char *const keywords[],
-			       unsigned int keywords_count);
+			       const array_t *keywords);
 
 /* Copy keywords into dest. dest must have been initialized. */
 void client_save_keywords(struct mailbox_keywords *dest,
-			  const char *const keywords[],
-			  unsigned int keywords_count);
+			  const array_t *keywords);
 
 int mailbox_equals(struct mailbox *box1, struct mail_storage *storage2,
 		   const char *name2);



More information about the dovecot-cvs mailing list