Commit 85b56e79 85b56e79be1935ba99df3574cf47cf19179cc3fe by Sergey Poznyakoff

Fix readmsg.

Readmsg passes all tests successfully.

* readmsg/msglist.c (msglist): Check return from mu_message_get_streamref.
* readmsg/readmsg.c (print_header, print_body): Check return values.
1 parent 11c14a01
......@@ -118,13 +118,19 @@ msglist (mu_mailbox_t mbox, int show_all, int argc, char **argv,
int found = 0;
for (j = 1; j <= total; j++)
{
int status;
char buf[128];
size_t len = 0;
mu_message_t msg = NULL;
mu_stream_t stream = NULL;
mu_mailbox_get_message (mbox, j, &msg);
mu_message_get_streamref (msg, &stream);
status = mu_message_get_streamref (msg, &stream);
if (status)
mu_error (_("cannot read message: %s"),
mu_strerror (status));
else
{
while (mu_stream_readline (stream, buf, sizeof buf, &len) == 0
&& len > 0)
{
......@@ -136,6 +142,7 @@ msglist (mu_mailbox_t mbox, int show_all, int argc, char **argv,
}
}
mu_stream_destroy (&stream);
}
if (found && !show_all)
break;
}
......
......@@ -222,10 +222,17 @@ print_header (mu_message_t message, int unix_header, int weedc, char **weedv)
}
else
{
int status;
size_t count;
size_t i;
mu_header_get_field_count (header, &count);
status = mu_header_get_field_count (header, &count);
if (status)
{
mu_error (_("cannot get number of headers: %s"),
mu_strerror (status));
return;
}
for (i = 1; i <= count; i++)
{
......@@ -259,6 +266,7 @@ print_header (mu_message_t message, int unix_header, int weedc, char **weedv)
static void
print_body (mu_message_t message)
{
int status;
char buf[128];
mu_body_t body = NULL;
mu_stream_t stream = NULL;
......@@ -266,7 +274,12 @@ print_body (mu_message_t message)
mu_message_get_body (message, &body);
/* FIXME: Use mu_stream_copy */
mu_body_get_streamref (body, &stream);
status = mu_body_get_streamref (body, &stream);
if (status)
{
mu_error (_("cannot get body stream: %s"), mu_strerror (status));
return;
}
while (mu_stream_read (stream, buf, sizeof (buf) - 1, &len) == 0
&& len != 0)
......