Commit 8984de56 8984de567ab8a517deedf4aa99a879ccd945c034 by Sergey Poznyakoff

(_mime_parse_mpart_message): One more fix

1 parent 030678a1
...@@ -334,24 +334,34 @@ _mime_parse_mpart_message (mu_mime_t mime) ...@@ -334,24 +334,34 @@ _mime_parse_mpart_message (mu_mime_t mime)
334 { 334 {
335 mime->parser_state = MIME_STATE_HEADERS; 335 mime->parser_state = MIME_STATE_HEADERS;
336 mime->flags &= ~MIME_PARSER_HAVE_CR; 336 mime->flags &= ~MIME_PARSER_HAVE_CR;
337 mb_length = mime->cur_offset - 337 mb_length = mime->cur_offset
338 mb_offset - mime->line_ndx; 338 - mb_offset
339 - mime->line_ndx;
339 if (mime->header_length) 340 if (mime->header_length)
340 /* this skips the preamble */ 341 /* this skips the preamble */
342 {
341 /* RFC 1521 [Page 30]: 343 /* RFC 1521 [Page 30]:
342 NOTE: The CRLF preceding the encapsulation line 344 NOTE: The CRLF preceding the encapsulation
343 is conceptually attached to the boundary so 345 line is conceptually attached to the boundary
344 that it is possible to have a part that does 346 so that it is possible to have a part that
345 not end with a CRLF (line break). Body parts 347 does not end with a CRLF (line break). Body
346 that must be considered to end with line 348 parts that must be considered to end with line
347 breaks, therefore, must have two CRLFs 349 breaks, therefore, must have two CRLFs
348 preceding the encapsulation line, the first 350 preceding the encapsulation line, the first
349 of which is part of the preceding body part, 351 of which is part of the preceding body part,
350 and the second of which is part of the 352 and the second of which is part of the
351 encapsulation boundary. */ 353 encapsulation boundary. */
354
355 if (mb_lines)
356 /* to prevent negative values in case of a
357 malformed message */
358 mb_lines--;
359
352 _mime_append_part (mime, NULL, 360 _mime_append_part (mime, NULL,
353 mb_offset, mb_length, 361 mb_offset, mb_length,
354 mb_lines - 1); 362 mb_lines);
363 }
364
355 if ((&mime->cur_line[mime->line_ndx] - cp2 - 1 > 365 if ((&mime->cur_line[mime->line_ndx] - cp2 - 1 >
356 blength 366 blength
357 && !strncasecmp (cp2 + blength + 2, "--", 2)) 367 && !strncasecmp (cp2 + blength + 2, "--", 2))
...@@ -361,13 +371,15 @@ _mime_parse_mpart_message (mu_mime_t mime) ...@@ -361,13 +371,15 @@ _mime_parse_mpart_message (mu_mime_t mime)
361 { /* last boundary */ 371 { /* last boundary */
362 mime->parser_state = MIME_STATE_BEGIN_LINE; 372 mime->parser_state = MIME_STATE_BEGIN_LINE;
363 mime->header_length = 0; 373 mime->header_length = 0;
364 break;
365 } 374 }
366 mime->line_ndx = -1; /* headers parsing requires empty line */ 375 else
376 mime->line_ndx = -1; /* headers parsing requires
377 empty line */
367 break; 378 break;
368 } 379 }
369 } 380 }
370 else if (mime->header_length) 381
382 if (mime->header_length)
371 mb_lines++; 383 mb_lines++;
372 384
373 mime->line_ndx = 0; 385 mime->line_ndx = 0;
......