Commit 0fac46ab 0fac46ab0e306070a46c5016cf2cf52c776c791c by Sergey Poznyakoff

Fixes in message_stream.

* libmailutils/mailbox/message.c (_message_stream_seek): Fix
ESPIPE conditional.
(_message_stream_read): Keep running until buffer is full
or _mss_eof state is reached.
(_message_stream_readdelim): Keep running until buffer is full,
_mss_eof state is reached or delimiter is found.
1 parent 9e863ef5
......@@ -159,9 +159,8 @@ _message_stream_seek (struct _mu_stream *str, mu_off_t off, mu_off_t *ppos)
return rc;
mu_header_size (sp->msg->header, &hsize);
mu_body_size (sp->msg->body, &size);
size += hsize;
if (off < 0 || off >= size)
if (off < 0 || off >= size + hsize)
return ESPIPE;
switch (sp->state)
......@@ -224,6 +223,10 @@ _message_stream_read (struct _mu_stream *str, char *buf, size_t bufsize,
if (sp->state == _mss_eof)
break;
rc = mu_stream_read (sp->transport, buf, bufsize, &n);
if (rc)
break;
if (n == 0)
continue;
nread += n;
buf += n;
bufsize -= n;
......@@ -249,9 +252,13 @@ _message_stream_readdelim (struct _mu_stream *str, char *buf, size_t bufsize,
if (sp->state == _mss_eof)
break;
rc = mu_stream_readdelim (sp->transport, buf, bufsize, delim, &n);
if (rc || n == 0)
if (rc)
break;
if (n == 0)
continue;
nread += n;
if (buf[n-1] == delim)
break;
buf += n;
bufsize -= n;
}
......