[dovecot-cvs] dovecot/src/imap cmd-append.c, 1.49, 1.50 cmd-store.c, 1.27, 1.28 commands-util.c, 1.37, 1.38 commands-util.h, 1.17, 1.18 imap-fetch.c, 1.32, 1.33 imap-fetch.h, 1.11, 1.12 imap-sync.c, 1.5, 1.6

cras at dovecot.org cras at dovecot.org
Sun Dec 26 11:12:43 EET 2004


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

Modified Files:
	cmd-append.c cmd-store.c commands-util.c commands-util.h 
	imap-fetch.c imap-fetch.h imap-sync.c 
Log Message:
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.



Index: cmd-append.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-append.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- cmd-append.c	11 Nov 2004 22:10:56 -0000	1.49
+++ cmd-append.c	26 Dec 2004 09:12:39 -0000	1.50
@@ -166,7 +166,9 @@
 	struct cmd_append_context *ctx = client->cmd_context;
 	struct imap_arg *args;
 	struct imap_arg_list *flags_list;
-	struct mail_full_flags flags;
+	enum mail_flags flags;
+	const char *const *keywords_list;
+	struct mail_keywords *keywords;
 	const char *internal_date_str;
 	time_t internal_date;
 	int ret, timezone_offset, nonsync;
@@ -228,10 +230,13 @@
 
 	if (flags_list != NULL) {
 		if (!client_parse_mail_flags(client, flags_list->args,
-					     &client->keywords, &flags))
+					     &flags, &keywords_list))
 			return cmd_append_cancel(ctx, nonsync);
+		keywords = keywords_list == NULL ? NULL :
+			mailbox_keywords_create(ctx->t, keywords_list);
 	} else {
-		memset(&flags, 0, sizeof(flags));
+		flags = 0;
+		keywords = NULL;
 	}
 
 	if (internal_date_str == NULL) {
@@ -263,8 +268,8 @@
 	ctx->input = i_stream_create_limit(default_pool, client->input,
 					   client->input->v_offset,
 					   ctx->msg_size);
-	ctx->save_ctx = mailbox_save_init(ctx->t, &flags, internal_date,
-					  timezone_offset, NULL,
+	ctx->save_ctx = mailbox_save_init(ctx->t, flags, keywords,
+					  internal_date, timezone_offset, NULL,
 					  ctx->input, FALSE);
 
 	client->command_pending = TRUE;

Index: cmd-store.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-store.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- cmd-store.c	29 Aug 2004 07:52:02 -0000	1.27
+++ cmd-store.c	26 Dec 2004 09:12:40 -0000	1.28
@@ -38,7 +38,9 @@
 int cmd_store(struct client *client)
 {
 	struct imap_arg *args;
-	struct mail_full_flags flags;
+	enum mail_flags flags;
+	const char *const *keywords_list;
+	struct mail_keywords *keywords;
 	enum modify_type modify_type;
 	struct mailbox *box;
 	struct mail_search_arg *search_arg;
@@ -69,11 +71,11 @@
 	if (args[2].type == IMAP_ARG_LIST) {
 		if (!client_parse_mail_flags(client,
 					     IMAP_ARG_LIST(&args[2])->args,
-					     &client->keywords, &flags))
+					     &flags, &keywords_list))
 			return TRUE;
 	} else {
 		if (!client_parse_mail_flags(client, args+2,
-					     &client->keywords, &flags))
+					     &flags, &keywords_list))
 			return TRUE;
 	}
 
@@ -83,14 +85,25 @@
 		return TRUE;
 
 	t = mailbox_transaction_begin(box, silent);
+	keywords = keywords_list == NULL ? NULL :
+		mailbox_keywords_create(t, keywords_list);
 	search_ctx = mailbox_search_init(t, NULL, search_arg, NULL,
 					 MAIL_FETCH_FLAGS, NULL);
 
 	failed = FALSE;
 	while ((mail = mailbox_search_next(search_ctx)) != NULL) {
-		if (mail->update_flags(mail, &flags, modify_type) < 0) {
-			failed = TRUE;
-			break;
+		if (modify_type == MODIFY_REPLACE || flags != 0) {
+			if (mail->update_flags(mail, modify_type, flags) < 0) {
+				failed = TRUE;
+				break;
+			}
+		}
+		if (modify_type == MODIFY_REPLACE || keywords != NULL) {
+			if (mail->update_keywords(mail, modify_type,
+						  keywords) < 0) {
+				failed = TRUE;
+				break;
+			}
 		}
 	}
 

Index: commands-util.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/commands-util.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- commands-util.c	8 Oct 2004 17:51:47 -0000	1.37
+++ commands-util.c	26 Dec 2004 09:12:40 -0000	1.38
@@ -3,11 +3,11 @@
 #include "common.h"
 #include "buffer.h"
 #include "str.h"
-#include "commands-util.h"
-#include "imap-util.h"
 #include "mail-storage.h"
+#include "commands-util.h"
 #include "imap-parser.h"
 #include "imap-sync.h"
+#include "imap-util.h"
 #include "namespace.h"
 
 /* Maximum length for mailbox name, including it's path. This isn't fully
@@ -150,16 +150,14 @@
 			 t_strconcat(syntax ? "* BAD " : "* NO ", error, NULL));
 }
 
-static int is_valid_keyword(struct client *client,
-			    const struct mailbox_keywords *old_keywords,
-			    const char *keyword)
+static int is_valid_keyword(struct client *client, const char *keyword)
 {
 	size_t i;
 
 	/* if it already exists, skip validity checks */
-	for (i = 0; i < old_keywords->keywords_count; i++) {
-		if (old_keywords->keywords[i] != NULL &&
-		    strcasecmp(old_keywords->keywords[i], keyword) == 0)
+	for (i = 0; i < client->keywords.keywords_count; i++) {
+		if (client->keywords.keywords[i] != NULL &&
+		    strcasecmp(client->keywords.keywords[i], keyword) == 0)
 			return TRUE;
 	}
 
@@ -175,15 +173,16 @@
 }
 
 int client_parse_mail_flags(struct client *client, struct imap_arg *args,
-                            const struct mailbox_keywords *old_keywords,
-			    struct mail_full_flags *flags)
+			    enum mail_flags *flags_r,
+			    const char *const **keywords_r)
 {
 	const char *const *keywords;
 	char *atom;
 	buffer_t *buffer;
 	size_t size, i;
 
-	memset(flags, 0, sizeof(*flags));
+	*flags_r = 0;
+	*keywords_r = NULL;
 	buffer = buffer_create_dynamic(client->cmd_pool, 256);
 
 	while (args->type != IMAP_ARG_EOL) {
@@ -198,15 +197,15 @@
 			/* system flag */
 			str_ucase(atom);
 			if (strcmp(atom, "\\ANSWERED") == 0)
-				flags->flags |= MAIL_ANSWERED;
+				*flags_r |= MAIL_ANSWERED;
 			else if (strcmp(atom, "\\FLAGGED") == 0)
-				flags->flags |= MAIL_FLAGGED;
+				*flags_r |= MAIL_FLAGGED;
 			else if (strcmp(atom, "\\DELETED") == 0)
-				flags->flags |= MAIL_DELETED;
+				*flags_r |= MAIL_DELETED;
 			else if (strcmp(atom, "\\SEEN") == 0)
-				flags->flags |= MAIL_SEEN;
+				*flags_r |= MAIL_SEEN;
 			else if (strcmp(atom, "\\DRAFT") == 0)
-				flags->flags |= MAIL_DRAFT;
+				*flags_r |= MAIL_DRAFT;
 			else {
 				client_send_tagline(client, t_strconcat(
 					"BAD Invalid system flag ",
@@ -223,8 +222,7 @@
 			}
 
 			if (i == size) {
-				if (!is_valid_keyword(client, old_keywords,
-						      atom))
+				if (!is_valid_keyword(client, atom))
 					return FALSE;
 				buffer_append(buffer, &atom, sizeof(atom));
 			}
@@ -233,8 +231,9 @@
 		args++;
 	}
 
-	flags->keywords = buffer_get_modifyable_data(buffer, &size);
-	flags->keywords_count = size / sizeof(const char *);
+	atom = NULL;
+	buffer_append(buffer, &atom, sizeof(atom));
+	*keywords_r = buffer_get_data(buffer, NULL);
 	return TRUE;
 }
 

Index: commands-util.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/commands-util.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- commands-util.h	18 Aug 2004 23:53:39 -0000	1.17
+++ commands-util.h	26 Dec 2004 09:12:40 -0000	1.18
@@ -37,8 +37,8 @@
 /* Parse flags. Returns TRUE if successful, if not sends an error message to
    client. */
 int client_parse_mail_flags(struct client *client, struct imap_arg *args,
-                            const struct mailbox_keywords *old_keywords,
-			    struct mail_full_flags *flags);
+			    enum mail_flags *flags_r,
+			    const char *const **keywords_r);
 
 /* Send FLAGS + PERMANENTFLAGS to client. */
 void client_send_mailbox_flags(struct client *client, struct mailbox *box,
@@ -47,7 +47,8 @@
 
 /* Copy keywords into dest. dest must have been initialized. */
 void client_save_keywords(struct mailbox_keywords *dest,
-			  const char *keywords[], unsigned int keywords_count);
+			  const char *const keywords[],
+			  unsigned int keywords_count);
 
 int mailbox_name_equals(const char *box1, const char *box2);
 

Index: imap-fetch.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/imap-fetch.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- imap-fetch.c	14 Oct 2004 12:27:09 -0000	1.32
+++ imap-fetch.c	26 Dec 2004 09:12:40 -0000	1.33
@@ -90,7 +90,6 @@
 	ctx->box = client->mailbox;
 
 	ctx->cur_str = str_new(default_pool, 8192);
-	ctx->seen_flag.flags = MAIL_SEEN;
 	ctx->all_headers_buf = buffer_create_dynamic(client->cmd_pool, 128);
 	ctx->handlers = buffer_create_dynamic(client->cmd_pool, 128);
 	ctx->line_finished = TRUE;
@@ -374,27 +373,23 @@
 static int fetch_flags(struct imap_fetch_context *ctx, struct mail *mail,
 		       void *context __attr_unused__)
 {
-	const struct mail_full_flags *flags;
-	struct mail_full_flags full_flags;
+	enum mail_flags flags;
+	const char *const *keywords;
 
 	flags = mail->get_flags(mail);
-	if (flags == NULL)
-		return -1;
+	keywords = mail->get_keywords(mail);
 
-	if (ctx->flags_update_seen && (flags->flags & MAIL_SEEN) == 0) {
+	if (ctx->flags_update_seen && (flags & MAIL_SEEN) == 0) {
 		/* Add \Seen flag */
-		full_flags = *flags;
-		full_flags.flags |= MAIL_SEEN;
-		flags = &full_flags;
-
-		if (mail->update_flags(mail, &ctx->seen_flag, MODIFY_ADD) < 0)
+		flags |= MAIL_SEEN;
+		if (mail->update_flags(mail, MAIL_SEEN, MODIFY_ADD) < 0)
 			return -1;
 	} else if (ctx->flags_show_only_seen_changes) {
 		return 1;
 	}
 
 	str_append(ctx->cur_str, "FLAGS (");
-	imap_write_flags(ctx->cur_str, flags);
+	imap_write_flags(ctx->cur_str, flags, keywords);
 	str_append(ctx->cur_str, ") ");
 	return 1;
 }

Index: imap-fetch.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/imap-fetch.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- imap-fetch.h	3 Oct 2004 12:28:57 -0000	1.11
+++ imap-fetch.h	26 Dec 2004 09:12:40 -0000	1.12
@@ -44,8 +44,6 @@
 
 	unsigned int select_counter;
 
-	struct mail_full_flags seen_flag;
-
 	unsigned int flags_have_handler:1;
 	unsigned int flags_update_seen:1;
 	unsigned int flags_show_only_seen_changes:1;

Index: imap-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/imap-sync.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- imap-sync.c	13 Nov 2004 23:08:07 -0000	1.5
+++ imap-sync.c	26 Dec 2004 09:12:40 -0000	1.6
@@ -2,8 +2,8 @@
 
 #include "common.h"
 #include "str.h"
-#include "imap-util.h"
 #include "mail-storage.h"
+#include "imap-util.h"
 #include "imap-sync.h"
 #include "commands.h"
 
@@ -81,7 +81,8 @@
 int imap_sync_more(struct imap_sync_context *ctx)
 {
 	struct mail *mail;
-        const struct mail_full_flags *mail_flags;
+	enum mail_flags flags;
+	const char *const *keywords;
 	string_t *str;
 
 	t_push();
@@ -97,6 +98,7 @@
 
 		switch (ctx->sync_rec.type) {
 		case MAILBOX_SYNC_TYPE_FLAGS:
+		case MAILBOX_SYNC_TYPE_KEYWORDS:
 			if (ctx->seq == 0)
 				ctx->seq = ctx->sync_rec.seq1;
 
@@ -104,14 +106,13 @@
 				mail = mailbox_fetch(ctx->t, ctx->seq,
 						     MAIL_FETCH_FLAGS);
 
-				mail_flags = mail->get_flags(mail);
-				if (mail_flags == NULL)
-					continue;
+				flags = mail->get_flags(mail);
+				keywords = mail->get_keywords(mail);
 
 				str_truncate(str, 0);
 				str_printfa(str, "* %u FETCH (FLAGS (",
 					    ctx->seq);
-				imap_write_flags(str, mail_flags);
+				imap_write_flags(str, flags, keywords);
 				str_append(str, "))");
 				if (!client_send_line(ctx->client,
 						      str_c(str))) {



More information about the dovecot-cvs mailing list