Commit ee136061 ee13606174e66a21ad033bd929e9a7b0554a98e0 by Sergey Poznyakoff

(mh_check_message): New function.

(mh_body_size,mh_check_message,mh_header_size)
(mh_header_lines): Use mh_check_message() to make sure
the message has been scanned.
1 parent f2462a1c
...@@ -1037,7 +1037,6 @@ mh_scan0 (mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notify) ...@@ -1037,7 +1037,6 @@ mh_scan0 (mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notify)
1037 if (do_notify) 1037 if (do_notify)
1038 for (msg = mhd->msg_head; msg; msg = msg->next) 1038 for (msg = mhd->msg_head; msg; msg = msg->next)
1039 { 1039 {
1040
1041 DISPATCH_ADD_MSG(mailbox, mhd); 1040 DISPATCH_ADD_MSG(mailbox, mhd);
1042 } 1041 }
1043 1042
...@@ -1186,9 +1185,7 @@ mh_message_stream_open (struct _mh_message *mhm) ...@@ -1186,9 +1185,7 @@ mh_message_stream_open (struct _mh_message *mhm)
1186 status = stream_open (mhm->stream); 1185 status = stream_open (mhm->stream);
1187 1186
1188 if (status != 0) 1187 if (status != 0)
1189 {
1190 stream_destroy (&mhm->stream, NULL); 1188 stream_destroy (&mhm->stream, NULL);
1191 }
1192 1189
1193 if (status == 0) 1190 if (status == 0)
1194 status = mh_scan_message (mhm); 1191 status = mh_scan_message (mhm);
...@@ -1207,6 +1204,13 @@ mh_message_stream_close (struct _mh_message *mhm) ...@@ -1207,6 +1204,13 @@ mh_message_stream_close (struct _mh_message *mhm)
1207 } 1204 }
1208 } 1205 }
1209 1206
1207 void
1208 mh_check_message (struct _mh_message *mhm)
1209 {
1210 if (mhm->body_end == 0)
1211 mh_pool_open (mhm);
1212 }
1213
1210 /* Reading functions */ 1214 /* Reading functions */
1211 1215
1212 static int 1216 static int
...@@ -1295,12 +1299,12 @@ mh_body_size (body_t body, size_t *psize) ...@@ -1295,12 +1299,12 @@ mh_body_size (body_t body, size_t *psize)
1295 struct _mh_message *mhm = message_get_owner (msg); 1299 struct _mh_message *mhm = message_get_owner (msg);
1296 if (mhm == NULL) 1300 if (mhm == NULL)
1297 return EINVAL; 1301 return EINVAL;
1302 mh_check_message (mhm);
1298 if (psize) 1303 if (psize)
1299 *psize = mhm->body_end - mhm->body_start; 1304 *psize = mhm->body_end - mhm->body_start;
1300 return 0; 1305 return 0;
1301 } 1306 }
1302 1307
1303
1304 static int 1308 static int
1305 mh_body_lines (body_t body, size_t *plines) 1309 mh_body_lines (body_t body, size_t *plines)
1306 { 1310 {
...@@ -1308,6 +1312,7 @@ mh_body_lines (body_t body, size_t *plines) ...@@ -1308,6 +1312,7 @@ mh_body_lines (body_t body, size_t *plines)
1308 struct _mh_message *mhm = message_get_owner (msg); 1312 struct _mh_message *mhm = message_get_owner (msg);
1309 if (mhm == NULL) 1313 if (mhm == NULL)
1310 return EINVAL; 1314 return EINVAL;
1315 mh_check_message (mhm);
1311 if (plines) 1316 if (plines)
1312 *plines = mhm->body_lines; 1317 *plines = mhm->body_lines;
1313 return 0; 1318 return 0;
...@@ -1342,6 +1347,7 @@ mh_header_size (header_t header, size_t *psize) ...@@ -1342,6 +1347,7 @@ mh_header_size (header_t header, size_t *psize)
1342 struct _mh_message *mhm = message_get_owner (msg); 1347 struct _mh_message *mhm = message_get_owner (msg);
1343 if (mhm == NULL) 1348 if (mhm == NULL)
1344 return EINVAL; 1349 return EINVAL;
1350 mh_check_message (mhm);
1345 if (psize) 1351 if (psize)
1346 *psize = mhm->body_start; 1352 *psize = mhm->body_start;
1347 return 0; 1353 return 0;
...@@ -1354,6 +1360,7 @@ mh_header_lines (header_t header, size_t *plines) ...@@ -1354,6 +1360,7 @@ mh_header_lines (header_t header, size_t *plines)
1354 struct _mh_message *mhm = message_get_owner (msg); 1360 struct _mh_message *mhm = message_get_owner (msg);
1355 if (mhm == NULL) 1361 if (mhm == NULL)
1356 return EINVAL; 1362 return EINVAL;
1363 mh_check_message (mhm);
1357 if (plines) 1364 if (plines)
1358 *plines = mhm->header_lines; 1365 *plines = mhm->header_lines;
1359 return 0; 1366 return 0;
......