changeset 22899:093ef44c44e6

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"
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 15 Mar 2018 13:19:53 +0200
parents 68e071667d10
children cfadc7f52953
files src/lib-storage/index/imapc/imapc-mail-fetch.c
diffstat 1 files changed, 12 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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 */