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)
io_send_qstring (s);
/* body parameter parenthesized list: Content-type attributes */
if (ws.ws_wordc > 1 || text_plain)
if (ws.ws_wordc > 1)
{
int space = 0;
char *lvalue = NULL;
int have_charset = 0;
int i;
io_sendf (" (");
......@@ -429,8 +428,6 @@ bodystructure (mu_message_t msg, int extension)
default:
lvalue = ws.ws_wordv[i];
if (mu_c_strcasecmp (lvalue, "charset") == 0)
have_charset = 1;
}
}
......@@ -440,13 +437,7 @@ bodystructure (mu_message_t msg, int extension)
io_sendf (" ");
io_send_qstring (lvalue);
}
if (!have_charset && text_plain)
{
if (space)
io_sendf (" ");
io_sendf ("\"CHARSET\" \"US-ASCII\"");
}
io_sendf (")");
}
else
......@@ -726,15 +717,10 @@ fetch_get_part_rfc822 (struct fetch_function_closure *ffc,
if (rc == 0)
{
mu_body_t body;
mu_stream_t str;
if (mu_message_get_body (msg, &body) ||
mu_body_get_streamref (body, &str))
return NULL;
rc = mu_stream_to_message (str, &retmsg);
mu_stream_unref (str);
rc = mu_message_unencapsulate (msg, &retmsg, NULL);
if (rc)
mu_error (_("%s failed: %s"), "mu_message_unencapsulate",
mu_strerror (rc));
}
}
......
......@@ -346,7 +346,7 @@ mu_message_unencapsulate (mu_message_t msg, mu_message_t *newmsg,
{
int ret = 0;
mu_header_t hdr;
mu_stream_t istream, ostream;
mu_stream_t istream;
if (msg == NULL)
return EINVAL;
......@@ -364,18 +364,10 @@ mu_message_unencapsulate (mu_message_t msg, mu_message_t *newmsg,
}
if ((ret = _attachment_setup (&info, msg, &istream)) != 0)
return ret;
if (info->msg == NULL)
ret = mu_message_create (&info->msg, NULL);
if (ret == 0)
{
mu_message_get_streamref (info->msg, &ostream);
mu_stream_seek (ostream, 0, MU_SEEK_SET, NULL);
ret = mu_stream_copy (ostream, istream, 0, NULL);
mu_stream_destroy (&ostream);
}
ret = mu_stream_to_message (istream, &info->msg);
mu_stream_unref (istream);
if (ret == 0)
*newmsg = info->msg;
mu_stream_destroy (&istream);
_attachment_free (info, ret && ret != EAGAIN);
return ret;
}
......