dovecot-2.2: lib-storage: Bypass virtual storage when copying ma...

dovecot at dovecot.org dovecot at dovecot.org
Fri Jan 4 01:44:09 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/5bb879b6e3f3
changeset: 15497:5bb879b6e3f3
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jan 04 01:43:59 2013 +0200
description:
lib-storage: Bypass virtual storage when copying mail to allow optimizations.
As a side effect this also causes all plugins to see the backend mail
instead of the virtual mail. This probably isn't bad in most situations, but
for those where it's unwanted mail_private.vmail can be used to access the
virtual mail. mail_log plugin does this to log the original virtual mailbox
name for copy operations.

diffstat:

 src/lib-storage/mail-storage-private.h |  6 ++++++
 src/lib-storage/mail-storage.c         |  6 +++++-
 src/plugins/mail-log/mail-log-plugin.c |  9 ++++++++-
 src/plugins/virtual/virtual-mail.c     |  4 ++++
 4 files changed, 23 insertions(+), 2 deletions(-)

diffs (82 lines):

diff -r 5d90e2aa1ba8 -r 5bb879b6e3f3 src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h	Fri Jan 04 01:13:05 2013 +0200
+++ b/src/lib-storage/mail-storage-private.h	Fri Jan 04 01:43:59 2013 +0200
@@ -398,6 +398,12 @@
 struct mail_private {
 	struct mail mail;
 	struct mail_vfuncs v, *vlast;
+	/* normally NULL, but in case this is a "backend mail" for a mail
+	   created by virtual storage, this points back to the original virtual
+	   mail. at least mailbox_copy() bypasses the virtual storage, so this
+	   allows mail_log plugin to log the copy operation using the original
+	   mailbox name. */
+	struct mail *vmail;
 
 	uint32_t seq_pvt;
 
diff -r 5d90e2aa1ba8 -r 5bb879b6e3f3 src/lib-storage/mail-storage.c
--- a/src/lib-storage/mail-storage.c	Fri Jan 04 01:13:05 2013 +0200
+++ b/src/lib-storage/mail-storage.c	Fri Jan 04 01:43:59 2013 +0200
@@ -1942,6 +1942,7 @@
 	struct mail_save_context *ctx = *_ctx;
 	struct mailbox *box = ctx->transaction->box;
 	struct mail_keywords *keywords = ctx->data.keywords;
+	struct mail *real_mail;
 	int ret;
 
 	*_ctx = NULL;
@@ -1952,7 +1953,10 @@
 		return -1;
 	}
 
-	ret = ctx->transaction->box->v.copy(ctx, mail);
+	/* bypass virtual storage, so hard linking can be used whenever
+	   possible */
+	real_mail = mail_get_real_mail(mail);
+	ret = ctx->transaction->box->v.copy(ctx, real_mail);
 	if (keywords != NULL)
 		mailbox_keywords_unref(&keywords);
 	return ret;
diff -r 5d90e2aa1ba8 -r 5bb879b6e3f3 src/plugins/mail-log/mail-log-plugin.c
--- a/src/plugins/mail-log/mail-log-plugin.c	Fri Jan 04 01:13:05 2013 +0200
+++ b/src/plugins/mail-log/mail-log-plugin.c	Fri Jan 04 01:43:59 2013 +0200
@@ -360,10 +360,17 @@
 {
 	struct mail_log_mail_txn_context *ctx =
 		(struct mail_log_mail_txn_context *)txn;
+	struct mail_private *src_pmail = (struct mail_private *)src;
+	struct mailbox *src_box = src->box;
 	const char *desc;
 
+	if (src_pmail->vmail != NULL) {
+		/* copying a mail from virtual storage. src points to the
+		   backend mail, but we want to log the virtual mailbox name. */
+		src_box = src_pmail->vmail->box;
+	}
 	desc = t_strdup_printf("copy from %s",
-			       str_sanitize(mailbox_get_vname(src->box),
+			       str_sanitize(mailbox_get_vname(src_box),
 					    MAILBOX_NAME_LOG_LEN));
 	mail_log_append_mail_message(ctx, dst,
 				     MAIL_LOG_EVENT_COPY, desc);
diff -r 5d90e2aa1ba8 -r 5bb879b6e3f3 src/plugins/virtual/virtual-mail.c
--- a/src/plugins/virtual/virtual-mail.c	Fri Jan 04 01:13:05 2013 +0200
+++ b/src/plugins/virtual/virtual-mail.c	Fri Jan 04 01:43:59 2013 +0200
@@ -90,6 +90,7 @@
 			      struct virtual_backend_box *bbox)
 {
 	struct virtual_mail *vmail = (struct virtual_mail *)mail;
+	struct mail_private *backend_pmail;
 	struct mailbox_transaction_context *backend_trans;
 	struct mailbox_header_lookup_ctx *backend_headers;
 
@@ -102,6 +103,9 @@
 					 backend_headers);
 	if (backend_headers != NULL)
 		mailbox_header_lookup_unref(&backend_headers);
+
+	backend_pmail = (struct mail_private *)vmail->backend_mail;
+	backend_pmail->vmail = mail;
 	array_append(&vmail->backend_mails, &vmail->backend_mail, 1);
 	return vmail->backend_mail;
 }


More information about the dovecot-cvs mailing list