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,24 +118,31 @@ msglist (mu_mailbox_t mbox, int show_all, int argc, char **argv, ...@@ -118,24 +118,31 @@ msglist (mu_mailbox_t mbox, int show_all, int argc, char **argv,
118 int found = 0; 118 int found = 0;
119 for (j = 1; j <= total; j++) 119 for (j = 1; j <= total; j++)
120 { 120 {
121 int status;
121 char buf[128]; 122 char buf[128];
122 size_t len = 0; 123 size_t len = 0;
123 mu_message_t msg = NULL; 124 mu_message_t msg = NULL;
124 mu_stream_t stream = NULL; 125 mu_stream_t stream = NULL;
125 126
126 mu_mailbox_get_message (mbox, j, &msg); 127 mu_mailbox_get_message (mbox, j, &msg);
127 mu_message_get_streamref (msg, &stream); 128 status = mu_message_get_streamref (msg, &stream);
128 while (mu_stream_readline (stream, buf, sizeof buf, &len) == 0 129 if (status)
129 && len > 0) 130 mu_error (_("cannot read message: %s"),
131 mu_strerror (status));
132 else
130 { 133 {
131 if (strstr (buf, argv[i]) != NULL) 134 while (mu_stream_readline (stream, buf, sizeof buf, &len) == 0
135 && len > 0)
132 { 136 {
133 addset (set, n, j); 137 if (strstr (buf, argv[i]) != NULL)
134 found = 1; 138 {
135 break; 139 addset (set, n, j);
140 found = 1;
141 break;
142 }
136 } 143 }
144 mu_stream_destroy (&stream);
137 } 145 }
138 mu_stream_destroy (&stream);
139 if (found && !show_all) 146 if (found && !show_all)
140 break; 147 break;
141 } 148 }
......
...@@ -222,11 +222,18 @@ print_header (mu_message_t message, int unix_header, int weedc, char **weedv) ...@@ -222,11 +222,18 @@ print_header (mu_message_t message, int unix_header, int weedc, char **weedv)
222 } 222 }
223 else 223 else
224 { 224 {
225 int status;
225 size_t count; 226 size_t count;
226 size_t i; 227 size_t i;
227 228
228 mu_header_get_field_count (header, &count); 229 status = mu_header_get_field_count (header, &count);
229 230 if (status)
231 {
232 mu_error (_("cannot get number of headers: %s"),
233 mu_strerror (status));
234 return;
235 }
236
230 for (i = 1; i <= count; i++) 237 for (i = 1; i <= count; i++)
231 { 238 {
232 int j; 239 int j;
...@@ -259,6 +266,7 @@ print_header (mu_message_t message, int unix_header, int weedc, char **weedv) ...@@ -259,6 +266,7 @@ print_header (mu_message_t message, int unix_header, int weedc, char **weedv)
259 static void 266 static void
260 print_body (mu_message_t message) 267 print_body (mu_message_t message)
261 { 268 {
269 int status;
262 char buf[128]; 270 char buf[128];
263 mu_body_t body = NULL; 271 mu_body_t body = NULL;
264 mu_stream_t stream = NULL; 272 mu_stream_t stream = NULL;
...@@ -266,7 +274,12 @@ print_body (mu_message_t message) ...@@ -266,7 +274,12 @@ print_body (mu_message_t message)
266 mu_message_get_body (message, &body); 274 mu_message_get_body (message, &body);
267 275
268 /* FIXME: Use mu_stream_copy */ 276 /* FIXME: Use mu_stream_copy */
269 mu_body_get_streamref (body, &stream); 277 status = mu_body_get_streamref (body, &stream);
278 if (status)
279 {
280 mu_error (_("cannot get body stream: %s"), mu_strerror (status));
281 return;
282 }
270 283
271 while (mu_stream_read (stream, buf, sizeof (buf) - 1, &len) == 0 284 while (mu_stream_read (stream, buf, sizeof (buf) - 1, &len) == 0
272 && len != 0) 285 && len != 0)
......