From: Timo Sirainen Date: Wed, 22 Aug 2012 12:19:19 +0000 (+0300) Subject: lib-storage: Added mail_save_copy_default_metadata() X-Git-Tag: 2.2.alpha1~291 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc9bac02a4b62a82ee9458ca50f191028bb41eb4;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Added mail_save_copy_default_metadata() --- diff --git a/src/lib-storage/mail-copy.c b/src/lib-storage/mail-copy.c index ce4e60ad58..baed72e300 100644 --- a/src/lib-storage/mail-copy.c +++ b/src/lib-storage/mail-copy.c @@ -20,26 +20,12 @@ mail_copy_set_failed(struct mail_save_context *ctx, struct mail *mail, 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 @@ mail_storage_try_copy(struct mail_save_context **_ctx, struct mail *mail) 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 --git a/src/lib-storage/mail-copy.h b/src/lib-storage/mail-copy.h index 94f6919671..02048db6b4 100644 --- a/src/lib-storage/mail-copy.h +++ b/src/lib-storage/mail-copy.h @@ -7,6 +7,11 @@ struct mailbox; 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,