dovecot: Make sure we do a mailbox sync after flag updates (STOR...

dovecot at dovecot.org dovecot at dovecot.org
Sat Sep 22 13:55:44 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/b5e6543b4385
changeset: 6454:b5e6543b4385
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Sep 22 13:55:36 2007 +0300
description:
Make sure we do a mailbox sync after flag updates (STORE, FETCH). Also added
a new IMAP_SYNC_FLAG_SAFE which is used to figure out if appends and
expunges are safe to send to client when delay-newmail workaround is
enabled.

diffstat:

11 files changed, 34 insertions(+), 19 deletions(-)
src/imap/cmd-append.c  |   16 +++++++++++-----
src/imap/cmd-check.c   |    3 ++-
src/imap/cmd-copy.c    |    6 ++++--
src/imap/cmd-expunge.c |   14 ++++++++------
src/imap/cmd-fetch.c   |    3 ++-
src/imap/cmd-noop.c    |    2 +-
src/imap/cmd-store.c   |    2 +-
src/imap/imap-fetch.c  |    1 +
src/imap/imap-fetch.h  |    1 +
src/imap/imap-sync.c   |    2 +-
src/imap/imap-sync.h   |    3 ++-

diffs (184 lines):

diff -r d98617723bc2 -r b5e6543b4385 src/imap/cmd-append.c
--- a/src/imap/cmd-append.c	Sat Sep 22 13:45:14 2007 +0300
+++ b/src/imap/cmd-append.c	Sat Sep 22 13:55:36 2007 +0300
@@ -235,6 +235,7 @@ static bool cmd_append_continue_parsing(
 	if (args->type == IMAP_ARG_EOL) {
 		/* last message */
 		enum mailbox_sync_flags sync_flags;
+		enum imap_sync_flags imap_flags;
 		uint32_t uid_validity, uid1, uid2;
 		const char *msg;
 
@@ -267,11 +268,16 @@ static bool cmd_append_continue_parsing(
 					      uid_validity, uid1, uid2);
 		}
 
-		sync_flags = ctx->box == cmd->client->mailbox ?
-			0 : MAILBOX_SYNC_FLAG_FAST;
-
-		cmd_append_finish(ctx);
-		return cmd_sync(cmd, sync_flags, 0, msg);
+		if (ctx->box == cmd->client->mailbox) {
+			sync_flags = 0;
+			imap_flags = IMAP_SYNC_FLAG_SAFE;
+		} else {
+			sync_flags = MAILBOX_SYNC_FLAG_FAST;
+			imap_flags = 0;
+		}
+
+		cmd_append_finish(ctx);
+		return cmd_sync(cmd, sync_flags, imap_flags, msg);
 	}
 
 	if (!validate_args(args, &flags_list, &internal_date_str,
diff -r d98617723bc2 -r b5e6543b4385 src/imap/cmd-check.c
--- a/src/imap/cmd-check.c	Sat Sep 22 13:45:14 2007 +0300
+++ b/src/imap/cmd-check.c	Sat Sep 22 13:55:36 2007 +0300
@@ -9,5 +9,6 @@ bool cmd_check(struct client_command_con
 		return TRUE;
 
 	return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FULL_READ |
-			MAILBOX_SYNC_FLAG_FULL_WRITE, 0, "OK Check completed.");
+			MAILBOX_SYNC_FLAG_FULL_WRITE, IMAP_SYNC_FLAG_SAFE,
+			"OK Check completed.");
 }
diff -r d98617723bc2 -r b5e6543b4385 src/imap/cmd-copy.c
--- a/src/imap/cmd-copy.c	Sat Sep 22 13:45:14 2007 +0300
+++ b/src/imap/cmd-copy.c	Sat Sep 22 13:55:36 2007 +0300
@@ -92,7 +92,8 @@ bool cmd_copy(struct client_command_cont
 	struct mailbox_transaction_context *t;
         struct mail_search_arg *search_arg;
 	const char *messageset, *mailbox, *src_uidset, *msg = NULL;
-        enum mailbox_sync_flags sync_flags = 0;
+	enum mailbox_sync_flags sync_flags = 0;
+	enum imap_sync_flags imap_flags = 0;
 	unsigned int copy_count;
 	uint32_t uid_validity, uid1, uid2;
 	int ret;
@@ -159,11 +160,12 @@ bool cmd_copy(struct client_command_cont
 
 	if (destbox != client->mailbox) {
 		sync_flags |= MAILBOX_SYNC_FLAG_FAST;
+		imap_flags |= IMAP_SYNC_FLAG_SAFE;
 		mailbox_close(&destbox);
 	}
 
 	if (ret > 0)
-		return cmd_sync(cmd, sync_flags, 0, msg);
+		return cmd_sync(cmd, sync_flags, imap_flags, msg);
 	else if (ret == 0) {
 		/* some messages were expunged, sync them */
 		return cmd_sync(cmd, 0, 0,
diff -r d98617723bc2 -r b5e6543b4385 src/imap/cmd-expunge.c
--- a/src/imap/cmd-expunge.c	Sat Sep 22 13:45:14 2007 +0300
+++ b/src/imap/cmd-expunge.c	Sat Sep 22 13:55:36 2007 +0300
@@ -28,9 +28,10 @@ bool cmd_uid_expunge(struct client_comma
 	if (search_arg == NULL)
 		return TRUE;
 
-	if (imap_expunge(client->mailbox, search_arg))
-		return cmd_sync(cmd, 0, 0, "OK Expunge completed.");
-	else {
+	if (imap_expunge(client->mailbox, search_arg)) {
+		return cmd_sync(cmd, 0, IMAP_SYNC_FLAG_SAFE,
+				"OK Expunge completed.");
+	} else {
 		client_send_storage_error(cmd,
 					  mailbox_get_storage(client->mailbox));
 		return TRUE;
@@ -44,9 +45,10 @@ bool cmd_expunge(struct client_command_c
 	if (!client_verify_open_mailbox(cmd))
 		return TRUE;
 
-	if (imap_expunge(client->mailbox, NULL))
-		return cmd_sync(cmd, 0, 0, "OK Expunge completed.");
-	else {
+	if (imap_expunge(client->mailbox, NULL)) {
+		return cmd_sync(cmd, 0, IMAP_SYNC_FLAG_SAFE,
+				"OK Expunge completed.");
+	} else {
 		client_send_storage_error(cmd,
 					  mailbox_get_storage(client->mailbox));
 		return TRUE;
diff -r d98617723bc2 -r b5e6543b4385 src/imap/cmd-fetch.c
--- a/src/imap/cmd-fetch.c	Sat Sep 22 13:45:14 2007 +0300
+++ b/src/imap/cmd-fetch.c	Sat Sep 22 13:55:36 2007 +0300
@@ -95,7 +95,8 @@ static bool cmd_fetch_finish(struct imap
 		return TRUE;
 	}
 
-	return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FAST |
+	return cmd_sync(cmd,
+			(ctx->seen_flags_changed ? MAILBOX_SYNC_FLAG_FAST : 0) |
 			(cmd->uid ? 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES), 0,
 			ok_message);
 }
diff -r d98617723bc2 -r b5e6543b4385 src/imap/cmd-noop.c
--- a/src/imap/cmd-noop.c	Sat Sep 22 13:45:14 2007 +0300
+++ b/src/imap/cmd-noop.c	Sat Sep 22 13:55:36 2007 +0300
@@ -5,5 +5,5 @@
 
 bool cmd_noop(struct client_command_context *cmd)
 {
-	return cmd_sync(cmd, 0, 0, "OK NOOP completed.");
+	return cmd_sync(cmd, 0, IMAP_SYNC_FLAG_SAFE, "OK NOOP completed.");
 }
diff -r d98617723bc2 -r b5e6543b4385 src/imap/cmd-store.c
--- a/src/imap/cmd-store.c	Sat Sep 22 13:45:14 2007 +0300
+++ b/src/imap/cmd-store.c	Sat Sep 22 13:55:36 2007 +0300
@@ -123,7 +123,7 @@ bool cmd_store(struct client_command_con
 		   flag changes that were caused by UID STORE and those that
 		   came externally, so we'll just send the UID for all flag
 		   changes that we see. */
-		return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FAST |
+		return cmd_sync(cmd,
 				(cmd->uid ? 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES),
 				cmd->uid && !silent ?
 				IMAP_SYNC_FLAG_SEND_UID : 0,
diff -r d98617723bc2 -r b5e6543b4385 src/imap/imap-fetch.c
--- a/src/imap/imap-fetch.c	Sat Sep 22 13:45:14 2007 +0300
+++ b/src/imap/imap-fetch.c	Sat Sep 22 13:55:36 2007 +0300
@@ -511,6 +511,7 @@ static int fetch_flags(struct imap_fetch
 
 	if (ctx->flags_update_seen && (flags & MAIL_SEEN) == 0) {
 		/* Add \Seen flag */
+		ctx->seen_flags_changed = TRUE;
 		flags |= MAIL_SEEN;
 		mail_update_flags(mail, MODIFY_ADD, MAIL_SEEN);
 	} else if (ctx->flags_show_only_seen_changes) {
diff -r d98617723bc2 -r b5e6543b4385 src/imap/imap-fetch.h
--- a/src/imap/imap-fetch.h	Sat Sep 22 13:45:14 2007 +0300
+++ b/src/imap/imap-fetch.h	Sat Sep 22 13:55:36 2007 +0300
@@ -55,6 +55,7 @@ struct imap_fetch_context {
 
 	unsigned int flags_have_handler:1;
 	unsigned int flags_update_seen:1;
+	unsigned int seen_flags_changed:1;
 	unsigned int flags_show_only_seen_changes:1;
 	unsigned int update_partial:1;
 	unsigned int cur_have_eoh:1;
diff -r d98617723bc2 -r b5e6543b4385 src/imap/imap-sync.c
--- a/src/imap/imap-sync.c	Sat Sep 22 13:45:14 2007 +0300
+++ b/src/imap/imap-sync.c	Sat Sep 22 13:55:36 2007 +0300
@@ -244,7 +244,7 @@ bool cmd_sync(struct client_command_cont
 	}
 
 	no_newmail = (client_workarounds & WORKAROUND_DELAY_NEWMAIL) != 0 &&
-		(flags & MAILBOX_SYNC_FLAG_FAST) != 0;
+		(imap_flags & IMAP_SYNC_FLAG_SAFE) == 0;
 	if (no_newmail) {
 		/* expunges might break the client just as badly as new mail
 		   notifications. */
diff -r d98617723bc2 -r b5e6543b4385 src/imap/imap-sync.h
--- a/src/imap/imap-sync.h	Sat Sep 22 13:45:14 2007 +0300
+++ b/src/imap/imap-sync.h	Sat Sep 22 13:55:36 2007 +0300
@@ -2,7 +2,8 @@
 #define IMAP_SYNC_H
 
 enum imap_sync_flags {
-	IMAP_SYNC_FLAG_SEND_UID	= 0x01
+	IMAP_SYNC_FLAG_SEND_UID	= 0x01,
+	IMAP_SYNC_FLAG_SAFE	= 0x02
 };
 
 struct client;


More information about the dovecot-cvs mailing list