]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Try to add missing attachment flags when fetching MIME parts or BODYSTRU...
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 10 Sep 2020 13:38:11 +0000 (16:38 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Wed, 7 Oct 2020 11:43:37 +0000 (11:43 +0000)
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.

src/lib-storage/index/index-mail.c
src/lib-storage/mail-storage-settings.c
src/lib-storage/mail-storage-settings.h

index 4d2398ad00d9be664f8bc335eeefda7883014055..b79da9c17fb4e8a361d5e61b9a2d06f12434f967 100644 (file)
@@ -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;
 }
 
index 2a0cd38da4b2055562185ec52025bf4d5373267f..8853fa182b3352be946cebfdb98f62dca186db7c 100644 (file)
@@ -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=")) {
index 078afe6bd68693667fcddf4172814aadf4622679..30dfcc242603c172dde873f2ea499aad1d03cf60 100644 (file)
@@ -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 {