dovecot: Use mailbox_sync() instead of our own implementation.

dovecot at dovecot.org dovecot at dovecot.org
Sat Sep 22 16:25:21 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/aeee5076f99f
changeset: 6463:aeee5076f99f
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Sep 22 16:21:20 2007 +0300
description:
Use mailbox_sync() instead of our own implementation.

diffstat:

8 files changed, 20 insertions(+), 82 deletions(-)
src/imap/cmd-select.c                      |    8 ++++----
src/imap/imap-status.c                     |   28 +++++++++++-----------------
src/imap/imap-sync.c                       |   11 -----------
src/imap/imap-sync.h                       |    2 --
src/plugins/convert/convert-storage.c      |   13 +------------
src/plugins/mbox-snarf/mbox-snarf-plugin.c |   13 +------------
src/plugins/trash/trash-plugin.c           |   13 +------------
src/pop3/client.c                          |   14 ++------------

diffs (223 lines):

diff -r 60a34f26c35a -r aeee5076f99f src/imap/cmd-select.c
--- a/src/imap/cmd-select.c	Sat Sep 22 16:21:09 2007 +0300
+++ b/src/imap/cmd-select.c	Sat Sep 22 16:21:20 2007 +0300
@@ -36,15 +36,15 @@ bool cmd_select_full(struct client_comma
 		return TRUE;
 	}
 
-	if (imap_sync_nonselected(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
+	if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ,
+			 STATUS_MESSAGES | STATUS_RECENT |
+			 STATUS_FIRST_UNSEEN_SEQ | STATUS_UIDVALIDITY |
+			 STATUS_UIDNEXT | STATUS_KEYWORDS, &status) < 0) {
 		client_send_storage_error(cmd, storage);
 		mailbox_close(&box);
 		return TRUE;
 	}
 
-	mailbox_get_status(box, STATUS_MESSAGES | STATUS_RECENT |
-			   STATUS_FIRST_UNSEEN_SEQ | STATUS_UIDVALIDITY |
-			   STATUS_UIDNEXT | STATUS_KEYWORDS, &status);
 	client_save_keywords(&client->keywords, status.keywords);
 	client->messages_count = status.messages;
 	client->recent_count = status.recent;
diff -r 60a34f26c35a -r aeee5076f99f src/imap/imap-status.c
--- a/src/imap/imap-status.c	Sat Sep 22 16:21:09 2007 +0300
+++ b/src/imap/imap-status.c	Sat Sep 22 16:21:20 2007 +0300
@@ -49,31 +49,25 @@ bool imap_status_get(struct client *clie
 		     struct mailbox_status *status_r)
 {
 	struct mailbox *box;
-	bool failed = FALSE;
+	int ret;
 
 	if (client->mailbox != NULL &&
 	    mailbox_equals(client->mailbox, storage, mailbox)) {
 		/* this mailbox is selected */
 		box = client->mailbox;
-	} else {
-		/* open the mailbox */
-		box = mailbox_open(storage, mailbox, NULL, MAILBOX_OPEN_FAST |
-				   MAILBOX_OPEN_READONLY |
-				   MAILBOX_OPEN_KEEP_RECENT);
-		if (box == NULL)
-			return FALSE;
-
-		if (imap_sync_nonselected(box, 0) < 0)
-			failed = TRUE;
+		mailbox_get_status(box, items, status_r);
+		return TRUE;
 	}
 
-	if (!failed)
-		mailbox_get_status(box, items, status_r);
+	/* open the mailbox */
+	box = mailbox_open(storage, mailbox, NULL, MAILBOX_OPEN_FAST |
+			   MAILBOX_OPEN_READONLY | MAILBOX_OPEN_KEEP_RECENT);
+	if (box == NULL)
+		return FALSE;
 
-	if (box != client->mailbox)
-		mailbox_close(&box);
-
-	return !failed;
+	ret = mailbox_sync(box, 0, items, status_r);
+	mailbox_close(&box);
+	return ret == 0;
 }
 
 void imap_status_send(struct client *client, const char *mailbox,
diff -r 60a34f26c35a -r aeee5076f99f src/imap/imap-sync.c
--- a/src/imap/imap-sync.c	Sat Sep 22 16:21:09 2007 +0300
+++ b/src/imap/imap-sync.c	Sat Sep 22 16:21:20 2007 +0300
@@ -191,17 +191,6 @@ int imap_sync_more(struct imap_sync_cont
 	return ret;
 }
 
-int imap_sync_nonselected(struct mailbox *box, enum mailbox_sync_flags flags)
-{
-	struct mailbox_sync_context *ctx;
-        struct mailbox_sync_rec sync_rec;
-
-	ctx = mailbox_sync_init(box, flags);
-	while (mailbox_sync_next(ctx, &sync_rec))
-		;
-	return mailbox_sync_deinit(&ctx, 0, NULL);
-}
-
 static bool cmd_sync_continue(struct client_command_context *cmd)
 {
 	struct cmd_sync_context *ctx = cmd->context;
diff -r 60a34f26c35a -r aeee5076f99f src/imap/imap-sync.h
--- a/src/imap/imap-sync.h	Sat Sep 22 16:21:09 2007 +0300
+++ b/src/imap/imap-sync.h	Sat Sep 22 16:21:20 2007 +0300
@@ -14,8 +14,6 @@ int imap_sync_deinit(struct imap_sync_co
 int imap_sync_deinit(struct imap_sync_context *ctx);
 int imap_sync_more(struct imap_sync_context *ctx);
 
-int imap_sync_nonselected(struct mailbox *box, enum mailbox_sync_flags flags);
-
 bool cmd_sync(struct client_command_context *cmd, enum mailbox_sync_flags flags,
 	      enum imap_sync_flags imap_flags, const char *tagline);
 
diff -r 60a34f26c35a -r aeee5076f99f src/plugins/convert/convert-storage.c
--- a/src/plugins/convert/convert-storage.c	Sat Sep 22 16:21:09 2007 +0300
+++ b/src/plugins/convert/convert-storage.c	Sat Sep 22 16:21:20 2007 +0300
@@ -25,17 +25,6 @@ struct dotlock_settings dotlock_settings
 	MEMBER(use_excl_lock) FALSE
 };
 
-static int sync_mailbox(struct mailbox *box)
-{
-	struct mailbox_sync_context *ctx;
-        struct mailbox_sync_rec sync_rec;
-
-	ctx = mailbox_sync_init(box, MAILBOX_SYNC_FLAG_FULL_READ);
-	while (mailbox_sync_next(ctx, &sync_rec))
-		;
-	return mailbox_sync_deinit(&ctx, 0, NULL);
-}
-
 static int mailbox_copy_mails(struct mailbox *srcbox, struct mailbox *destbox,
 			      struct dotlock *dotlock)
 {
@@ -45,7 +34,7 @@ static int mailbox_copy_mails(struct mai
 	struct mail_search_arg search_arg;
 	int ret = 0;
 
-	if (sync_mailbox(srcbox) < 0)
+	if (mailbox_sync(srcbox, MAILBOX_SYNC_FLAG_FULL_READ, 0, NULL) < 0)
 		return -1;
 
 	memset(&search_arg, 0, sizeof(search_arg));
diff -r 60a34f26c35a -r aeee5076f99f src/plugins/mbox-snarf/mbox-snarf-plugin.c
--- a/src/plugins/mbox-snarf/mbox-snarf-plugin.c	Sat Sep 22 16:21:09 2007 +0300
+++ b/src/plugins/mbox-snarf/mbox-snarf-plugin.c	Sat Sep 22 16:21:20 2007 +0300
@@ -35,17 +35,6 @@ static MODULE_CONTEXT_DEFINE_INIT(mbox_s
 static MODULE_CONTEXT_DEFINE_INIT(mbox_snarf_storage_module,
 				  &mail_storage_module_register);
 
-static int sync_mailbox(struct mailbox *box)
-{
-	struct mailbox_sync_context *ctx;
-        struct mailbox_sync_rec sync_rec;
-
-	ctx = mailbox_sync_init(box, MAILBOX_SYNC_FLAG_FULL_READ);
-	while (mailbox_sync_next(ctx, &sync_rec))
-		;
-	return mailbox_sync_deinit(&ctx, 0, NULL);
-}
-
 static int mbox_snarf(struct mailbox *srcbox, struct mailbox *destbox)
 {
 	struct mail_search_arg search_arg;
@@ -54,7 +43,7 @@ static int mbox_snarf(struct mailbox *sr
 	struct mail *mail;
 	int ret;
 
-	if (sync_mailbox(srcbox) < 0)
+	if (mailbox_sync(srcbox, MAILBOX_SYNC_FLAG_FULL_READ, 0, NULL) < 0)
 		return -1;
 
 	memset(&search_arg, 0, sizeof(search_arg));
diff -r 60a34f26c35a -r aeee5076f99f src/plugins/trash/trash-plugin.c
--- a/src/plugins/trash/trash-plugin.c	Sat Sep 22 16:21:09 2007 +0300
+++ b/src/plugins/trash/trash-plugin.c	Sat Sep 22 16:21:20 2007 +0300
@@ -42,17 +42,6 @@ static pool_t config_pool;
 /* trash_boxes ordered by priority, highest first */
 static ARRAY_DEFINE(trash_boxes, struct trash_mailbox);
 
-static int sync_mailbox(struct mailbox *box)
-{
-	struct mailbox_sync_context *ctx;
-        struct mailbox_sync_rec sync_rec;
-
-	ctx = mailbox_sync_init(box, MAILBOX_SYNC_FLAG_FULL_READ);
-	while (mailbox_sync_next(ctx, &sync_rec))
-		;
-	return mailbox_sync_deinit(&ctx, 0, NULL);
-}
-
 static int trash_clean_mailbox_open(struct trash_mailbox *trash)
 {
 	trash->box = mailbox_open(trash->storage, trash->name, NULL,
@@ -60,7 +49,7 @@ static int trash_clean_mailbox_open(stru
 	if (trash->box == NULL)
 		return 0;
 
-	if (sync_mailbox(trash->box) < 0)
+	if (mailbox_sync(trash->box, MAILBOX_SYNC_FLAG_FULL_READ, 0, NULL) < 0)
 		return -1;
 
 	trash->trans = mailbox_transaction_begin(trash->box, 0);
diff -r 60a34f26c35a -r aeee5076f99f src/pop3/client.c
--- a/src/pop3/client.c	Sat Sep 22 16:21:09 2007 +0300
+++ b/src/pop3/client.c	Sat Sep 22 16:21:20 2007 +0300
@@ -38,17 +38,6 @@ static void client_input(struct client *
 static void client_input(struct client *client);
 static int client_output(struct client *client);
 
-static int sync_mailbox(struct mailbox *box, struct mailbox_status *status)
-{
-	struct mailbox_sync_context *ctx;
-        struct mailbox_sync_rec sync_rec;
-
-	ctx = mailbox_sync_init(box, MAILBOX_SYNC_FLAG_FULL_READ);
-	while (mailbox_sync_next(ctx, &sync_rec))
-		;
-	return mailbox_sync_deinit(&ctx, STATUS_UIDVALIDITY, status);
-}
-
 static bool init_mailbox(struct client *client, const char **error_r)
 {
 	struct mail_search_arg search_arg;
@@ -68,7 +57,8 @@ static bool init_mailbox(struct client *
 	search_arg.type = SEARCH_ALL;
 
 	for (i = 0; i < 2; i++) {
-		if (sync_mailbox(client->mailbox, &status) < 0) {
+		if (mailbox_sync(client->mailbox, MAILBOX_SYNC_FLAG_FULL_READ,
+				 STATUS_UIDVALIDITY, &status) < 0) {
 			client_send_storage_error(client);
 			break;
 		}


More information about the dovecot-cvs mailing list