]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Try to add missing attachment flags when opening mail stream
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 3 Sep 2020 22:58:58 +0000 (01:58 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Wed, 7 Oct 2020 11:43:37 +0000 (11:43 +0000)
Since the message body is being opened in any case, it's pretty inexpensive
to add missing attachment flags. Do this only when
mail_attachment_detection_options has add-flags-on-save but no
no-flags-on-fetch.

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

index b79da9c17fb4e8a361d5e61b9a2d06f12434f967..428f5c58d9945c8595a48dd09d3a11c16a780ea9 100644 (file)
@@ -1316,12 +1316,17 @@ int index_mail_init_stream(struct index_mail *mail,
                        index_mail_stream_destroy_callback, mail);
        }
 
+       bool want_attachment_kw =
+               index_mail_want_attachment_keywords_on_fetch(mail);
+       if (want_attachment_kw)
+               data->access_part |= PARSE_HDR | PARSE_BODY;
+
        if (hdr_size != NULL || body_size != NULL)
                (void)get_cached_msgpart_sizes(mail);
 
-       if (hdr_size != NULL || body_size != NULL) {
+       if (hdr_size != NULL || body_size != NULL || want_attachment_kw) {
                i_stream_seek(data->stream, 0);
-               if (!data->hdr_size_set) {
+               if (!data->hdr_size_set || want_attachment_kw) {
                        if ((data->access_part & PARSE_HDR) != 0) {
                                (void)get_cached_parts(mail);
                                if (index_mail_parse_headers_internal(mail, NULL) < 0)
@@ -1341,10 +1346,10 @@ int index_mail_init_stream(struct index_mail *mail,
                        *hdr_size = data->hdr_size;
        }
 
-       if (body_size != NULL) {
-               if (!data->body_size_set)
+       if (body_size != NULL || want_attachment_kw) {
+               if (!data->body_size_set && body_size != NULL)
                        index_mail_get_cached_body_size(mail);
-               if (!data->body_size_set) {
+               if (!data->body_size_set || want_attachment_kw) {
                        i_stream_seek(data->stream,
                                      data->hdr_size.physical_size);
                        if ((data->access_part & PARSE_BODY) != 0) {
@@ -1362,7 +1367,8 @@ int index_mail_init_stream(struct index_mail *mail,
                        body_size_from_stream = TRUE;
                }
 
-               *body_size = data->body_size;
+               if (body_size != NULL)
+                       *body_size = data->body_size;
        }
 
        if (data->hdr_size_set && data->body_size_set) {