# HG changeset patch # User Timo Sirainen # Date 1521112793 -7200 # Node ID 093ef44c44e670ea8f32f213309909c2ed040930 # Parent 68e071667d1051080899eea30341af4481e71d15 imapc: Update mail size also when RFC822.SIZE is smaller than fetched header size 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" diff -r 68e071667d10 -r 093ef44c44e6 src/lib-storage/index/imapc/imapc-mail-fetch.c --- a/src/lib-storage/index/imapc/imapc-mail-fetch.c Thu Mar 15 12:20:14 2018 +0200 +++ b/src/lib-storage/index/imapc/imapc-mail-fetch.c Thu Mar 15 13:19:53 2018 +0200 @@ -585,13 +585,18 @@ 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 */