Commit 0d6303f8 0d6303f869ef2525c0bda2cbeae92668ccf95308 by Sergey Poznyakoff

imap4d: fix FETCH (BODYSTRUCTURE)

* imap4d/fetch.c (bodystructure): Do not emit CHARSET pair if there is
none in the Content-Type header.
(fetch_get_part_rfc822): Use mu_message_unencapsulate
* libmailutils/mime/attachment.c (mu_message_unencapsulate): Use
mu_stream_to_message to create destination message.  This ensures that
the latter can be handled by other MU functions (e.g. mu_header_*
family).
1 parent 30594fa8
...@@ -393,11 +393,10 @@ bodystructure (mu_message_t msg, int extension) ...@@ -393,11 +393,10 @@ bodystructure (mu_message_t msg, int extension)
393 io_send_qstring (s); 393 io_send_qstring (s);
394 394
395 /* body parameter parenthesized list: Content-type attributes */ 395 /* body parameter parenthesized list: Content-type attributes */
396 if (ws.ws_wordc > 1 || text_plain) 396 if (ws.ws_wordc > 1)
397 { 397 {
398 int space = 0; 398 int space = 0;
399 char *lvalue = NULL; 399 char *lvalue = NULL;
400 int have_charset = 0;
401 int i; 400 int i;
402 401
403 io_sendf (" ("); 402 io_sendf (" (");
...@@ -429,8 +428,6 @@ bodystructure (mu_message_t msg, int extension) ...@@ -429,8 +428,6 @@ bodystructure (mu_message_t msg, int extension)
429 428
430 default: 429 default:
431 lvalue = ws.ws_wordv[i]; 430 lvalue = ws.ws_wordv[i];
432 if (mu_c_strcasecmp (lvalue, "charset") == 0)
433 have_charset = 1;
434 } 431 }
435 } 432 }
436 433
...@@ -440,13 +437,7 @@ bodystructure (mu_message_t msg, int extension) ...@@ -440,13 +437,7 @@ bodystructure (mu_message_t msg, int extension)
440 io_sendf (" "); 437 io_sendf (" ");
441 io_send_qstring (lvalue); 438 io_send_qstring (lvalue);
442 } 439 }
443 440
444 if (!have_charset && text_plain)
445 {
446 if (space)
447 io_sendf (" ");
448 io_sendf ("\"CHARSET\" \"US-ASCII\"");
449 }
450 io_sendf (")"); 441 io_sendf (")");
451 } 442 }
452 else 443 else
...@@ -726,15 +717,10 @@ fetch_get_part_rfc822 (struct fetch_function_closure *ffc, ...@@ -726,15 +717,10 @@ fetch_get_part_rfc822 (struct fetch_function_closure *ffc,
726 717
727 if (rc == 0) 718 if (rc == 0)
728 { 719 {
729 mu_body_t body; 720 rc = mu_message_unencapsulate (msg, &retmsg, NULL);
730 mu_stream_t str; 721 if (rc)
731 722 mu_error (_("%s failed: %s"), "mu_message_unencapsulate",
732 if (mu_message_get_body (msg, &body) || 723 mu_strerror (rc));
733 mu_body_get_streamref (body, &str))
734 return NULL;
735
736 rc = mu_stream_to_message (str, &retmsg);
737 mu_stream_unref (str);
738 } 724 }
739 } 725 }
740 726
......
...@@ -346,7 +346,7 @@ mu_message_unencapsulate (mu_message_t msg, mu_message_t *newmsg, ...@@ -346,7 +346,7 @@ mu_message_unencapsulate (mu_message_t msg, mu_message_t *newmsg,
346 { 346 {
347 int ret = 0; 347 int ret = 0;
348 mu_header_t hdr; 348 mu_header_t hdr;
349 mu_stream_t istream, ostream; 349 mu_stream_t istream;
350 350
351 if (msg == NULL) 351 if (msg == NULL)
352 return EINVAL; 352 return EINVAL;
...@@ -364,18 +364,10 @@ mu_message_unencapsulate (mu_message_t msg, mu_message_t *newmsg, ...@@ -364,18 +364,10 @@ mu_message_unencapsulate (mu_message_t msg, mu_message_t *newmsg,
364 } 364 }
365 if ((ret = _attachment_setup (&info, msg, &istream)) != 0) 365 if ((ret = _attachment_setup (&info, msg, &istream)) != 0)
366 return ret; 366 return ret;
367 if (info->msg == NULL) 367 ret = mu_stream_to_message (istream, &info->msg);
368 ret = mu_message_create (&info->msg, NULL); 368 mu_stream_unref (istream);
369 if (ret == 0)
370 {
371 mu_message_get_streamref (info->msg, &ostream);
372 mu_stream_seek (ostream, 0, MU_SEEK_SET, NULL);
373 ret = mu_stream_copy (ostream, istream, 0, NULL);
374 mu_stream_destroy (&ostream);
375 }
376 if (ret == 0) 369 if (ret == 0)
377 *newmsg = info->msg; 370 *newmsg = info->msg;
378 mu_stream_destroy (&istream);
379 _attachment_free (info, ret && ret != EAGAIN); 371 _attachment_free (info, ret && ret != EAGAIN);
380 return ret; 372 return ret;
381 } 373 }
......