From: Timo Sirainen Date: Thu, 10 Sep 2020 13:38:11 +0000 (+0300) Subject: lib-storage: Try to add missing attachment flags when fetching MIME parts or BODYSTRU... X-Git-Tag: 2.3.13~150 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=194dcaa65cdd247393633f2daa4b40fd12985440;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Try to add missing attachment flags when fetching MIME parts or BODYSTRUCTURE This happens only if both mime.parts and imap.bodystructure are already in cache and mail_attachment_detection_options has add-flags-on-save but no no-flags-on-fetch. The no-flags-on-fetch option may be removed in a future release once it's known that it's not causing any unexpected performance issues. --- diff --git a/src/lib-storage/index/index-mail.c b/src/lib-storage/index/index-mail.c index 4d2398ad00..b79da9c17f 100644 --- a/src/lib-storage/index/index-mail.c +++ b/src/lib-storage/index/index-mail.c @@ -96,6 +96,25 @@ int index_mail_cache_lookup_field(struct index_mail *mail, buffer_t *buf, return ret; } +static void index_mail_try_set_attachment_keywords(struct index_mail *mail) +{ + enum mail_lookup_abort orig_lookup_abort = mail->mail.mail.lookup_abort; + mail->mail.mail.lookup_abort = MAIL_LOOKUP_ABORT_NOT_IN_CACHE; + (void)mail_set_attachment_keywords(&mail->mail.mail); + mail->mail.mail.lookup_abort = orig_lookup_abort; +} + +static bool +index_mail_want_attachment_keywords_on_fetch(struct index_mail *mail) +{ + const struct mail_storage_settings *mail_set = + mailbox_get_settings(mail->mail.mail.box); + + return mail_set->parsed_mail_attachment_detection_add_flags_on_save && + !mail_set->parsed_mail_attachment_detection_no_flags_on_fetch && + !mail_has_attachment_keywords(&mail->mail.mail); +} + static int get_serialized_parts(struct index_mail *mail, buffer_t **part_buf_r) { const unsigned int field_idx = @@ -160,6 +179,8 @@ static bool get_cached_parts(struct index_mail *mail) } mail->data.parts = part; + if (index_mail_want_attachment_keywords_on_fetch(mail)) + index_mail_try_set_attachment_keywords(mail); return TRUE; } @@ -1163,11 +1184,8 @@ index_mail_parse_body_finish(struct index_mail *mail, index_mail_cache_sizes(mail); index_mail_cache_dates(mail); if (mail_set->parsed_mail_attachment_detection_add_flags_on_save && - mail->data.parsed_bodystructure && - !mail_has_attachment_keywords(&mail->mail.mail)) { - i_assert(mail->data.parts != NULL); - (void)mail_set_attachment_keywords(&mail->mail.mail); - } + !mail_has_attachment_keywords(&mail->mail.mail)) + index_mail_try_set_attachment_keywords(mail); return 0; } @@ -1557,6 +1575,8 @@ bool index_mail_get_cached_bodystructure(struct index_mail *mail, } *value_r = data->bodystructure = str_c(str); + if (index_mail_want_attachment_keywords_on_fetch(mail)) + index_mail_try_set_attachment_keywords(mail); return TRUE; } diff --git a/src/lib-storage/mail-storage-settings.c b/src/lib-storage/mail-storage-settings.c index 2a0cd38da4..8853fa182b 100644 --- a/src/lib-storage/mail-storage-settings.c +++ b/src/lib-storage/mail-storage-settings.c @@ -553,6 +553,8 @@ static bool mail_storage_settings_check(void *_set, pool_t pool, if (strcmp(opt, "add-flags-on-save") == 0) { set->parsed_mail_attachment_detection_add_flags_on_save = TRUE; + } else if (strcmp(opt, "no-flags-on-fetch") == 0) { + set->parsed_mail_attachment_detection_no_flags_on_fetch = TRUE; } else if (strcmp(opt, "exclude-inlined") == 0) { set->parsed_mail_attachment_exclude_inlined = TRUE; } else if (str_begins(opt, "content-type=")) { diff --git a/src/lib-storage/mail-storage-settings.h b/src/lib-storage/mail-storage-settings.h index 078afe6bd6..30dfcc2426 100644 --- a/src/lib-storage/mail-storage-settings.h +++ b/src/lib-storage/mail-storage-settings.h @@ -82,6 +82,7 @@ struct mail_storage_settings { const char *const *parsed_mail_attachment_content_type_filter; bool parsed_mail_attachment_exclude_inlined; bool parsed_mail_attachment_detection_add_flags_on_save; + bool parsed_mail_attachment_detection_no_flags_on_fetch; }; struct mail_namespace_settings {