Skip to content

Commit

Permalink
imapc: Don't trust mail stream to have correct CRLFs
Browse files Browse the repository at this point in the history
It's not that expensive to just recalculate them. If they're not correct in
the stream, it can result in e.g. truncated emails due to wrong virtual_size
being used in body_size calculation. The wrong CRLFs can especially happen
if plugins modify the stream in istream_opened() hook.
  • Loading branch information
sirainen committed Jun 18, 2018
1 parent d1d8792 commit 75ae0b7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/lib-storage/index/imapc/imapc-mail-fetch.c
Expand Up @@ -589,12 +589,15 @@ void imapc_mail_init_stream(struct imapc_mail *mail)
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) {
if (mail->body_fetched)
if (mail->body_fetched) {
imail->data.inexact_total_sizes = FALSE;
/* Don't trust any existing virtual_size. Also don't
set it to size, because there's no guarantees about
the content having proper CRLF newlines, especially
not if istream_opened() has changed the stream. */
imail->data.virtual_size = (uoff_t)-1;
}
imail->data.physical_size = size;
/* we'll assume that the remote server is working properly and
sending CRLF linefeeds */
imail->data.virtual_size = size;
}

imail->data.stream_has_only_header = !mail->body_fetched;
Expand Down

0 comments on commit 75ae0b7

Please sign in to comment.