]> 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>
Tue, 20 Mar 2018 10:51:13 +0000 (12:51 +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 9478c5cbd4303da3c5ebf8465b6a6687ba7ec9c3..16af70933e9fb4432952d7242f9d4c667a850547 100644 (file)
@@ -577,13 +577,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 */