changeset 22936:2cc04e280ced

lib-storage: Set $Has[No]Attachment earlier among other cached data
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 19 Apr 2018 16:38:22 +0300
parents dc05b2f6a4dd
children 857e225da9f2
files src/lib-storage/index/index-mail.c src/lib-storage/mail-storage.c
diffstat 2 files changed, 13 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/index-mail.c	Wed Apr 25 11:04:08 2018 +0300
+++ b/src/lib-storage/index/index-mail.c	Thu Apr 19 16:38:22 2018 +0300
@@ -1050,6 +1050,8 @@
 			     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_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 @@
 	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 @@
 			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 =
--- a/src/lib-storage/mail-storage.c	Wed Apr 25 11:04:08 2018 +0300
+++ b/src/lib-storage/mail-storage.c	Thu Apr 19 16:38:22 2018 +0300
@@ -2424,8 +2424,6 @@
 {
 	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 @@
 		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);