]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Set $Has[No]Attachment earlier among other cached data
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 19 Apr 2018 13:38:22 +0000 (16:38 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 30 Apr 2018 13:05:53 +0000 (16:05 +0300)
src/lib-storage/index/index-mail.c
src/lib-storage/mail-storage.c

index 2e546f628e1147b9b1defff9e29a0c8ed5eca39a..c520cfdf730dc8ec5dc5941adabe029d7820b300 100644 (file)
@@ -1050,6 +1050,8 @@ index_mail_parse_body_finish(struct index_mail *mail,
                             enum index_cache_field field, bool success)
 {
        struct istream *parser_input = mail->data.parser_input;
+       const struct mail_storage_settings *mail_set =
+               mailbox_get_settings(mail->mail.mail.box);
        const char *error = NULL;
        int ret;
 
@@ -1113,6 +1115,12 @@ index_mail_parse_body_finish(struct index_mail *mail,
        index_mail_body_parsed_cache_bodystructure(mail, field);
        index_mail_cache_sizes(mail);
        index_mail_cache_dates(mail);
+       if (mail_set->parsed_mail_attachment_detection_add_flags_on_save &&
+           !mail_has_attachment_keywords(&mail->mail.mail)) {
+               i_assert(mail->data.parts != NULL);
+               i_assert(mail->data.parsed_bodystructure);
+               (void)mail_set_attachment_keywords(&mail->mail.mail);
+       }
        return 0;
 }
 
@@ -1754,6 +1762,7 @@ void index_mail_update_access_parts_pre(struct mail *_mail)
        struct mail_storage *storage = _mail->box->storage;
        const struct mail_cache_field *cache_fields = mail->ibox->cache_fields;
        struct mail_cache_view *cache_view = _mail->transaction->cache_view;
+       const struct mail_storage_settings *mail_set = _mail->box->storage->set;
 
        if (_mail->seq == 0) {
                /* mail_add_temp_wanted_fields() called before mail_set_seq*().
@@ -1846,6 +1855,10 @@ void index_mail_update_access_parts_pre(struct mail *_mail)
                        data->save_sent_date = TRUE;
                }
        }
+       if (mail_set->parsed_mail_attachment_detection_add_flags_on_save) {
+               data->save_bodystructure_header = TRUE;
+               data->save_bodystructure_body = TRUE;
+       }
        if ((data->wanted_fields & MAIL_FETCH_BODY_SNIPPET) != 0 &&
            (storage->nonbody_access_fields & MAIL_FETCH_BODY_SNIPPET) == 0) {
                const unsigned int cache_field =
index 458b0e31d2e12fd12fb30ec2c3c0ed430cb624a0..f810e8010404c0e04d27152f9b3a7266d44741ff 100644 (file)
@@ -2424,8 +2424,6 @@ int mailbox_save_finish(struct mail_save_context **_ctx)
 {
        struct mail_save_context *ctx = *_ctx;
        struct mailbox_transaction_context *t = ctx->transaction;
-       const struct mail_storage_settings *mail_set =
-               mailbox_get_settings(t->box);
        /* we need to keep a copy of this because save_finish implementations
           will likely zero the data structure during cleanup */
        struct mail_keywords *keywords = ctx->data.keywords;
@@ -2456,10 +2454,6 @@ int mailbox_save_finish(struct mail_save_context **_ctx)
                t->save_count++;
        }
 
-       if (mail_set->parsed_mail_attachment_detection_add_flags_on_save &&
-           !mail_has_attachment_keywords(ctx->dest_mail))
-               (void)mail_set_attachment_keywords(ctx->dest_mail);
-
        if (keywords != NULL)
                mailbox_keywords_unref(&keywords);
        mailbox_save_context_reset(ctx, TRUE);