]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: When copying mails, copy also empty cache fields
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 6 Nov 2017 16:59:34 +0000 (18:59 +0200)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Wed, 8 Nov 2017 07:12:57 +0000 (09:12 +0200)
This mainly means that it copies cache fields for nonexistent message
headers. Those are still important, because otherwise Dovecot doesn't know
whether they exist or not.

src/lib-storage/index/index-storage.c

index 2280e8adfa5541f60a85676a8da52fa3cc7722ac..7a7209a5a280df03e94ae4584c95d327ac2c1b0e 100644 (file)
@@ -935,6 +935,7 @@ mail_copy_cache_field(struct mail_save_context *ctx, struct mail *src_mail,
        const struct mail_cache_field *dest_field;
        unsigned int src_field_idx, dest_field_idx;
        uint32_t t;
+       bool add = FALSE;
 
        src_field_idx = mail_cache_register_lookup(src_mail->box->cache, name);
        i_assert(src_field_idx != UINT_MAX);
@@ -957,12 +958,14 @@ mail_copy_cache_field(struct mail_save_context *ctx, struct mail *src_mail,
                /* save date must update when mail is copied */
                t = ioloop_time;
                buffer_append(buf, &t, sizeof(t));
+               add = TRUE;
+       } else if (mail_cache_lookup_field(src_mail->transaction->cache_view, buf,
+                                          src_mail->seq, src_field_idx) <= 0) {
+               /* error / not found */
+               buffer_set_used_size(buf, 0);
        } else {
-               if (mail_cache_lookup_field(src_mail->transaction->cache_view, buf,
-                                           src_mail->seq, src_field_idx) <= 0)
-                       buffer_set_used_size(buf, 0);
-               else if (strcmp(name, "size.physical") == 0 ||
-                        strcmp(name, "size.virtual") == 0) {
+               if (strcmp(name, "size.physical") == 0 ||
+                   strcmp(name, "size.virtual") == 0) {
                        /* FIXME: until mail_cache_lookup() can read unwritten
                           cached data from buffer, we'll do this optimization
                           to make quota plugin's work faster */
@@ -977,8 +980,11 @@ mail_copy_cache_field(struct mail_save_context *ctx, struct mail *src_mail,
                        else
                                imail->data.virtual_size = size;
                }
+               /* NOTE: we'll want to add also nonexistent headers, which
+                  will keep the buf empty */
+               add = TRUE;
        }
-       if (buf->used > 0) {
+       if (add) {
                mail_cache_add(dest_trans->cache_trans, dest_seq,
                               dest_field_idx, buf->data, buf->used);
        }