dovecot-2.2: lib-storage: Added mail_save_copy_default_metadata()

dovecot at dovecot.org dovecot at dovecot.org
Wed Aug 22 15:19:27 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/5b89c50164de
changeset: 14949:5b89c50164de
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Aug 22 15:19:19 2012 +0300
description:
lib-storage: Added mail_save_copy_default_metadata()

diffstat:

 src/lib-storage/mail-copy.c |  40 ++++++++++++++++++++++++----------------
 src/lib-storage/mail-copy.h |   5 +++++
 2 files changed, 29 insertions(+), 16 deletions(-)

diffs (76 lines):

diff -r 5cf1cedb75e6 -r 5b89c50164de src/lib-storage/mail-copy.c
--- a/src/lib-storage/mail-copy.c	Wed Aug 22 15:18:39 2012 +0300
+++ b/src/lib-storage/mail-copy.c	Wed Aug 22 15:19:19 2012 +0300
@@ -20,26 +20,12 @@
 			       t_strdup_printf("%s (%s)", errstr, func));
 }
 
-static int
-mail_storage_try_copy(struct mail_save_context **_ctx, struct mail *mail)
+int mail_save_copy_default_metadata(struct mail_save_context *ctx,
+				    struct mail *mail)
 {
-	struct mail_save_context *ctx = *_ctx;
-	struct mail_private *pmail = (struct mail_private *)mail;
-	struct istream *input;
 	const char *from_envelope, *guid;
 	time_t received_date;
 
-	ctx->copying_via_save = TRUE;
-
-	/* we need to open the file in any case. caching metadata is unlikely
-	   to help anything. */
-	pmail->v.set_uid_cache_updates(mail, TRUE);
-
-	if (mail_get_stream(mail, NULL, NULL, &input) < 0) {
-		mail_copy_set_failed(ctx, mail, "stream");
-		return -1;
-	}
-
 	if (ctx->received_date == (time_t)-1) {
 		if (mail_get_received_date(mail, &received_date) < 0) {
 			mail_copy_set_failed(ctx, mail, "received-date");
@@ -64,6 +50,28 @@
 		if (*guid != '\0')
 			mailbox_save_set_guid(ctx, guid);
 	}
+	return 0;
+}
+
+static int
+mail_storage_try_copy(struct mail_save_context **_ctx, struct mail *mail)
+{
+	struct mail_save_context *ctx = *_ctx;
+	struct mail_private *pmail = (struct mail_private *)mail;
+	struct istream *input;
+
+	ctx->copying_via_save = TRUE;
+
+	/* we need to open the file in any case. caching metadata is unlikely
+	   to help anything. */
+	pmail->v.set_uid_cache_updates(mail, TRUE);
+
+	if (mail_get_stream(mail, NULL, NULL, &input) < 0) {
+		mail_copy_set_failed(ctx, mail, "stream");
+		return -1;
+	}
+	if (mail_save_copy_default_metadata(ctx, mail) < 0)
+		return -1;
 
 	if (mailbox_save_begin(_ctx, input) < 0)
 		return -1;
diff -r 5cf1cedb75e6 -r 5b89c50164de src/lib-storage/mail-copy.h
--- a/src/lib-storage/mail-copy.h	Wed Aug 22 15:18:39 2012 +0300
+++ b/src/lib-storage/mail-copy.h	Wed Aug 22 15:19:19 2012 +0300
@@ -7,6 +7,11 @@
 
 int mail_storage_copy(struct mail_save_context *ctx, struct mail *mail);
 
+/* If save context already doesn't have some metadata fields set, copy them
+   from the given mail (e.g. received date, from envelope, guid). */
+int mail_save_copy_default_metadata(struct mail_save_context *ctx,
+				    struct mail *mail);
+
 /* Returns TRUE if mail can be copied using hard linking from src to dest.
    (Assuming the storage itself supports this.) */
 bool mail_storage_copy_can_use_hardlink(struct mailbox *src,


More information about the dovecot-cvs mailing list