]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imapc: Update mail size also when RFC822.SIZE is smaller than fetched header size
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 15 Mar 2018 11:19:53 +0000 (13:19 +0200)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Fri, 16 Mar 2018 07:19:22 +0000 (09:19 +0200)
If this isn't done, istream-mail will detect that the fetched header is
larger than RFC822.SIZE and fail with "Cached message size smaller than
expected"

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

index 4d1be864273007aaf186aba74885a2b0f8be7b2a..52ba6f694df0ca92cf18de330120f3d62de162e5 100644 (file)
@@ -585,13 +585,18 @@ void imapc_mail_init_stream(struct imapc_mail *mail)
                        return;
                }
        }
-       if (mail->body_fetched) {
-               ret = i_stream_get_size(imail->data.stream, TRUE, &size);
-               if (ret < 0) {
-                       index_mail_close_streams(imail);
-                       return;
-               }
-               i_assert(ret != 0);
+       ret = i_stream_get_size(imail->data.stream, TRUE, &size);
+       if (ret < 0) {
+               index_mail_close_streams(imail);
+               return;
+       }
+       i_assert(ret != 0);
+       /* Once message body is fetched, we can be sure of what its size is.
+          If we had already received RFC822.SIZE, overwrite it here in case
+          it's wrong. Also in more special cases the RFC822.SIZE may be
+          smaller than the fetched message header. In this case change the
+          size as well, otherwise reading via istream-mail will fail. */
+       if (mail->body_fetched || imail->data.physical_size < size) {
                imail->data.physical_size = size;
                /* we'll assume that the remote server is working properly and
                   sending CRLF linefeeds */