]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Added mail_save_copy_default_metadata()
authorTimo Sirainen <tss@iki.fi>
Wed, 22 Aug 2012 12:19:19 +0000 (15:19 +0300)
committerTimo Sirainen <tss@iki.fi>
Wed, 22 Aug 2012 12:19:19 +0000 (15:19 +0300)
src/lib-storage/mail-copy.c
src/lib-storage/mail-copy.h

index ce4e60ad58a4010940219f010751aa64fc5c6670..baed72e30075859031e67fb523248fa5746ab27f 100644 (file)
@@ -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;
index 94f691967185d4e5a095bb8cfe6e27f6e1f8a461..02048db6b476cb8144140ffe67e3f5620c9b2cac 100644 (file)
@@ -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,