dovecot-1.0: Handle initial syncing errors better.

dovecot at dovecot.org dovecot at dovecot.org
Fri Aug 24 19:56:48 EEST 2007


details:   http://hg.dovecot.org/dovecot-1.0/rev/2c3124d7d2c2
changeset: 5387:2c3124d7d2c2
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Aug 24 19:56:40 2007 +0300
description:
Handle initial syncing errors better.

diffstat:

1 file changed, 26 insertions(+), 10 deletions(-)
src/pop3/client.c |   36 ++++++++++++++++++++++++++----------

diffs (94 lines):

diff -r dfbe444f6fab -r 2c3124d7d2c2 src/pop3/client.c
--- a/src/pop3/client.c	Fri Aug 24 19:36:02 2007 +0300
+++ b/src/pop3/client.c	Fri Aug 24 19:56:40 2007 +0300
@@ -50,7 +50,7 @@ static int sync_mailbox(struct mailbox *
 	return mailbox_sync_deinit(&ctx, status);
 }
 
-static int init_mailbox(struct client *client)
+static bool init_mailbox(struct client *client, const char **error_r)
 {
 	struct mail_search_arg search_arg;
         struct mailbox_transaction_context *t;
@@ -58,15 +58,16 @@ static int init_mailbox(struct client *c
         struct mailbox_status status;
 	struct mail *mail;
 	buffer_t *message_sizes_buf;
+	uint32_t failed_uid = 0;
 	int i;
-	bool failed;
+	bool failed, expunged;
 
 	message_sizes_buf = buffer_create_dynamic(default_pool, 512);
 
 	memset(&search_arg, 0, sizeof(search_arg));
 	search_arg.type = SEARCH_ALL;
 
-	for (i = 0; i < 2; i++) {
+	for (i = 0; i < 3; i++) {
 		if (sync_mailbox(client->mailbox, &status) < 0) {
 			client_send_storage_error(client);
 			break;
@@ -80,12 +81,20 @@ static int init_mailbox(struct client *c
 		client->total_size = 0;
 		buffer_set_used_size(message_sizes_buf, 0);
 
+		expunged = FALSE;
 		failed = FALSE;
 		mail = mail_alloc(t, MAIL_FETCH_VIRTUAL_SIZE, NULL);
 		while (mailbox_search_next(ctx, mail) > 0) {
 			uoff_t size = mail_get_virtual_size(mail);
 
 			if (size == (uoff_t)-1) {
+				if (failed_uid == mail->uid) {
+					i_error("Getting size of message "
+						"UID=%u failed", mail->uid);
+					break;
+				}
+				failed_uid = mail->uid;
+				expunged = mail->expunged;
 				failed = TRUE;
 				break;
 			}
@@ -100,7 +109,7 @@ static int init_mailbox(struct client *c
 			message_sizes_buf->used / sizeof(uoff_t);
 
 		mail_free(&mail);
-		if (mailbox_search_deinit(&ctx) < 0) {
+		if (mailbox_search_deinit(&ctx) < 0 || (failed && !expunged)) {
 			client_send_storage_error(client);
 			(void)mailbox_transaction_commit(&t, 0);
 			break;
@@ -118,8 +127,17 @@ static int init_mailbox(struct client *c
 		(void)mailbox_transaction_commit(&t, 0);
 	}
 
-	if (i == 2)
-		client_send_line(client, "-ERR [IN-USE] Couldn't sync mailbox.");
+	if (expunged) {
+		client_send_line(client,
+				 "-ERR [IN-USE] Couldn't sync mailbox.");
+		*error_r = "Can't sync mailbox: Messages keep getting expunged";
+	} else {
+		bool syntax_error, temporary_error;
+
+		*error_r = mail_storage_get_last_error(client->storage,
+						       &syntax_error,
+						       &temporary_error);
+	}
 	buffer_free(message_sizes_buf);
 	return FALSE;
 }
@@ -168,10 +186,8 @@ struct client *client_create(int fd_in, 
 		return NULL;
 	}
 
-	if (!init_mailbox(client)) {
-		i_error("Couldn't init INBOX: %s",
-			mail_storage_get_last_error(storage, &syntax_error,
-						    &temporary_error));
+	if (!init_mailbox(client, &errmsg)) {
+		i_error("Couldn't init INBOX: %s", errmsg);
 		client_destroy(client, "Mailbox init failed");
 		return NULL;
 	}


More information about the dovecot-cvs mailing list