dovecot-2.2: imap-msgpart-url: Attempt to reuse selected mailbox...

dovecot at dovecot.org dovecot at dovecot.org
Sun Sep 2 17:19:04 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/dd1a04580289
changeset: 15010:dd1a04580289
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Sep 02 17:18:41 2012 +0300
description:
imap-msgpart-url: Attempt to reuse selected mailbox instead of reallocating a new one.
Besides giving slightly better performace, this also fixes CATENATE for mbox
when source and destination mailboxes are the same.

diffstat:

 src/lib-imap-storage/imap-msgpart-url.c |  16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diffs (57 lines):

diff -r e4d5c3ba305b -r dd1a04580289 src/lib-imap-storage/imap-msgpart-url.c
--- a/src/lib-imap-storage/imap-msgpart-url.c	Sun Sep 02 17:15:09 2012 +0300
+++ b/src/lib-imap-storage/imap-msgpart-url.c	Sun Sep 02 17:18:41 2012 +0300
@@ -18,6 +18,7 @@
 	uoff_t partial_offset, partial_size;
 
 	struct mail_user *user;
+	struct mailbox *selected_box;
 	struct mailbox *box;
 	struct mailbox_transaction_context *trans;
 	struct mail *mail;
@@ -78,6 +79,7 @@
 		return 0;
 	}
 	*url_r = imap_msgpart_url_create(user, url);
+	(*url_r)->selected_box = selected_box;
 	return 1;
 }
 
@@ -108,11 +110,16 @@
 	}
 
 	/* open mailbox */
-	box = mailbox_alloc(ns->list, mpurl->mailbox, flags);
+	if (mpurl->selected_box != NULL &&
+	    mailbox_equals(mpurl->selected_box, ns, mpurl->mailbox))
+		box = mpurl->selected_box;
+	else
+		box = mailbox_alloc(ns->list, mpurl->mailbox, flags);
 	if (mailbox_open(box) < 0) {
 		*error_r = mail_storage_get_last_error(mailbox_get_storage(box),
 						       &error_code);
-		mailbox_free(&box);
+		if (box != mpurl->selected_box)
+			mailbox_free(&box);
 		return error_code == MAIL_ERROR_TEMP ? -1 : 0;
 	}
 
@@ -121,7 +128,8 @@
 	if (mpurl->uidvalidity > 0 &&
 	    box_status.uidvalidity != mpurl->uidvalidity) {
 		*error_r = "Invalid UIDVALIDITY";
-		mailbox_free(&box);
+		if (box != mpurl->selected_box)
+			mailbox_free(&box);
 		return 0;
 	}
 	mpurl->box = box;
@@ -247,7 +255,7 @@
 		mail_free(&mpurl->mail);
 	if (mpurl->trans != NULL)
 		mailbox_transaction_rollback(&mpurl->trans);
-	if (mpurl->box != NULL)
+	if (mpurl->box != NULL && mpurl->box != mpurl->selected_box)
 		mailbox_free(&mpurl->box);	
 	if (mpurl->section != NULL)
 		i_free(mpurl->section);


More information about the dovecot-cvs mailing list