[dovecot-cvs] dovecot/src/imap client.h,1.15,1.16 cmd-copy.c,1.9,1.10 cmd-store.c,1.14,1.15 imap-fetch.c,1.6,1.7 imap-fetch.h,1.2,1.3 mail-storage-callbacks.c,1.6,1.7

cras at procontrol.fi cras at procontrol.fi
Wed Jul 23 05:44:18 EEST 2003


Update of /home/cvs/dovecot/src/imap
In directory danu:/tmp/cvs-serv15228/imap

Modified Files:
	client.h cmd-copy.c cmd-store.c imap-fetch.c imap-fetch.h 
	mail-storage-callbacks.c 
Log Message:
API change for updating message flags.



Index: client.h
===================================================================
RCS file: /home/cvs/dovecot/src/imap/client.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- client.h	14 May 2003 17:23:11 -0000	1.15
+++ client.h	23 Jul 2003 01:44:16 -0000	1.16
@@ -39,7 +39,6 @@
 
 	unsigned int cmd_error:1;
 	unsigned int cmd_uid:1; /* used UID command */
-	unsigned int sync_flags_send_uid:1;
 	unsigned int rawlog:1;
 	unsigned int input_skip_line:1; /* skip all the data until we've
 					   found a new line */

Index: cmd-copy.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/cmd-copy.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- cmd-copy.c	23 Jul 2003 00:40:49 -0000	1.9
+++ cmd-copy.c	23 Jul 2003 01:44:16 -0000	1.10
@@ -12,7 +12,7 @@
 	int failed = FALSE;
 
 	fetch_ctx = box->fetch_init(box, MAIL_FETCH_STREAM_HEADER |
-				    MAIL_FETCH_STREAM_BODY, NULL,
+				    MAIL_FETCH_STREAM_BODY, FALSE,
 				    messageset, uidset);
 	if (fetch_ctx == NULL)
 		return FALSE;

Index: cmd-store.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/cmd-store.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- cmd-store.c	15 Jun 2003 03:42:28 -0000	1.14
+++ cmd-store.c	23 Jul 2003 01:44:16 -0000	1.15
@@ -32,13 +32,37 @@
 	return TRUE;
 }
 
+static int mail_send_flags(struct client *client, struct mail *mail)
+{
+	const struct mail_full_flags *flags;
+	const char *str;
+
+	flags = mail->get_flags(mail);
+	if (flags == NULL)
+		return FALSE;
+
+	t_push();
+	str = imap_write_flags(flags);
+	str = t_strdup_printf(client->cmd_uid ?
+			      "* %u FETCH (FLAGS (%s) UID %u)" :
+			      "* %u FETCH (FLAGS (%s))",
+			      mail->seq, str, mail->uid);
+	client_send_line(client, str);
+	t_pop();
+
+	return TRUE;
+}
+
 int cmd_store(struct client *client)
 {
 	struct imap_arg *args;
 	struct mail_full_flags flags;
 	enum modify_type modify_type;
+	struct mailbox *box;
+	struct mail_fetch_context *fetch_ctx;
+	struct mail *mail;
 	const char *messageset, *item;
-	int silent, all_found;
+	int silent, all_found, failed;
 
 	if (!client_read_args(client, 0, 0, &args))
 		return FALSE;
@@ -70,10 +94,32 @@
 	}
 
 	/* and update the flags */
-	client->sync_flags_send_uid = client->cmd_uid;
-	if (client->mailbox->update_flags(client->mailbox, messageset,
-					  client->cmd_uid, &flags,
-					  modify_type, !silent, &all_found)) {
+	box = client->mailbox;
+	fetch_ctx = box->fetch_init(box, MAIL_FETCH_FLAGS, TRUE,
+				    messageset, client->cmd_uid);
+	if (fetch_ctx == NULL)
+		failed = TRUE;
+	else {
+		failed = FALSE;
+		while ((mail = box->fetch_next(fetch_ctx)) != NULL) {
+			if (!mail->update_flags(mail, &flags, modify_type)) {
+				failed = TRUE;
+				break;
+			}
+
+			if (!silent) {
+				if (!mail_send_flags(client, mail)) {
+					failed = TRUE;
+					break;
+				}
+			}
+		}
+	}
+
+	if (!box->fetch_deinit(fetch_ctx, &all_found))
+		failed = TRUE;
+
+	if (!failed) {
 		if (client->cmd_uid)
 			client_sync_full_fast(client);
 		else
@@ -84,6 +130,5 @@
 		client_send_storage_error(client);
 	}
 
-	client->sync_flags_send_uid = FALSE;
 	return TRUE;
 }

Index: imap-fetch.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/imap-fetch.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- imap-fetch.c	4 Jun 2003 15:57:58 -0000	1.6
+++ imap-fetch.c	23 Jul 2003 01:44:16 -0000	1.7
@@ -17,17 +17,16 @@
 	str_printfa(ctx->str, "UID %u ", mail->uid);
 }
 
-static int fetch_flags(struct imap_fetch_context *ctx, struct mail *mail)
+static int fetch_flags(struct imap_fetch_context *ctx, struct mail *mail,
+		       const struct mail_full_flags *flags)
 {
-	const struct mail_full_flags *flags;
-
-	flags = mail->get_flags(mail);
-	if (flags == NULL)
-		return FALSE;
+	if (flags == NULL) {
+		flags = mail->get_flags(mail);
+		if (flags == NULL)
+			return FALSE;
+	}
 
-	str_printfa(ctx->str, "FLAGS (%s) ",
-		    imap_write_flags(flags->flags, flags->custom_flags,
-				     flags->custom_flags_count));
+	str_printfa(ctx->str, "FLAGS (%s) ", imap_write_flags(flags));
 	return TRUE;
 }
 
@@ -165,9 +164,27 @@
 
 static int fetch_mail(struct imap_fetch_context *ctx, struct mail *mail)
 {
+	const struct mail_full_flags *flags;
 	struct imap_fetch_body_data *body;
 	size_t len, orig_len;
-	int failed, data_written;
+	int failed, data_written, seen_updated = FALSE;
+
+	if (!ctx->update_seen)
+		flags = NULL;
+	else {
+		flags = mail->get_flags(mail);
+		if (flags == NULL)
+			return FALSE;
+
+		if ((flags->flags & MAIL_SEEN) == 0) {
+			if (!mail->update_flags(mail, &ctx->seen_flag,
+						MODIFY_ADD))
+				return FALSE;
+
+			flags = NULL; /* \Seen won't update automatically */
+			seen_updated = TRUE;
+		}
+	}
 
 	t_push();
 
@@ -181,8 +198,8 @@
 		/* write the data into temp string */
 		if (ctx->imap_data & IMAP_FETCH_UID)
 			fetch_uid(ctx, mail);
-		if ((ctx->fetch_data & MAIL_FETCH_FLAGS) || mail->seen_updated)
-			if (!fetch_flags(ctx, mail))
+		if ((ctx->fetch_data & MAIL_FETCH_FLAGS) || seen_updated)
+			if (!fetch_flags(ctx, mail, flags))
 				break;
 		if (ctx->fetch_data & MAIL_FETCH_RECEIVED_DATE)
 			if (!fetch_internaldate(ctx, mail))
@@ -247,7 +264,15 @@
 {
 	struct imap_fetch_context ctx;
 	struct mail *mail;
-	int all_found, update_seen = FALSE;
+	int all_found;
+
+	memset(&ctx, 0, sizeof(ctx));
+	ctx.fetch_data = fetch_data;
+	ctx.imap_data = imap_data;
+	ctx.bodies = bodies;
+	ctx.output = client->output;
+	ctx.select_counter = client->select_counter;
+	ctx.seen_flag.flags = MAIL_SEEN;
 
 	if (!client->mailbox->readonly) {
 		/* If we have any BODY[..] sections, \Seen flag is added for
@@ -256,24 +281,17 @@
 
 		for (body = bodies; body != NULL; body = body->next) {
 			if (!body->peek) {
-				update_seen = TRUE;
+				ctx.update_seen = TRUE;
 				break;
 			}
 		}
 
 		if (imap_data & (IMAP_FETCH_RFC822|IMAP_FETCH_RFC822_TEXT))
-			update_seen = TRUE;
+			ctx.update_seen = TRUE;
 	}
 
-	memset(&ctx, 0, sizeof(ctx));
-	ctx.fetch_data = fetch_data;
-	ctx.imap_data = imap_data;
-	ctx.bodies = bodies;
-	ctx.output = client->output;
-	ctx.select_counter = client->select_counter;
-
 	ctx.fetch_ctx = client->mailbox->
-		fetch_init(client->mailbox, fetch_data, &update_seen,
+		fetch_init(client->mailbox, fetch_data, ctx.update_seen,
 			   messageset, uidset);
 	if (ctx.fetch_ctx == NULL)
 		return -1;

Index: imap-fetch.h
===================================================================
RCS file: /home/cvs/dovecot/src/imap/imap-fetch.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- imap-fetch.h	21 Jan 2003 05:37:35 -0000	1.2
+++ imap-fetch.h	23 Jul 2003 01:44:16 -0000	1.3
@@ -30,6 +30,9 @@
 	const char *prefix;
 	unsigned int select_counter;
 
+	int update_seen;
+	struct mail_full_flags seen_flag;
+
 	int first, failed;
 };
 

Index: mail-storage-callbacks.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/mail-storage-callbacks.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- mail-storage-callbacks.c	14 Feb 2003 08:00:52 -0000	1.6
+++ mail-storage-callbacks.c	23 Jul 2003 01:44:16 -0000	1.7
@@ -46,9 +46,8 @@
 }
 
 static void update_flags(struct mailbox *mailbox,
-			 unsigned int seq, unsigned int uid,
-			 enum mail_flags flags, const char *custom_flags[],
-			 unsigned int custom_flags_count, void *context)
+			 unsigned int seq, unsigned int uid __attr_unused__,
+			 const struct mail_full_flags *flags, void *context)
 {
 	struct client *client = context;
 	const char *str;
@@ -57,15 +56,8 @@
 		return;
 
 	t_push();
-	str = imap_write_flags(flags, custom_flags, custom_flags_count);
-
-	if (client->sync_flags_send_uid) {
-		str = t_strdup_printf("* %u FETCH (FLAGS (%s) UID %u)",
-				      seq, str, uid);
-	} else {
-		str = t_strdup_printf("* %u FETCH (FLAGS (%s))", seq, str);
-	}
-
+	str = imap_write_flags(flags);
+	str = t_strdup_printf("* %u FETCH (FLAGS (%s))", seq, str);
 	client_send_line(client, str);
 	t_pop();
 }



More information about the dovecot-cvs mailing list