Sat 05 Sep 2015 07:27:22 PM UTC, comment #1:
mu_string_unfold is not expected to handle ASCII CR (\r) symbols. All Mailutils functions assume that lines in multiline text are terminated with a single LF (\n) character. The same applies to mu_string_unfold.
Your proposed modification will make the function work for your particular implementation, but will break its expected behaviour elsewhere. Besides, it assumes that \r is always followed by \n, which might not always be the case.
The CRLF->LF translation is built-in into the Mailutils transport level. If, for some reason, you need to process CRLF-terminated text, be sure
to translate it using the "CRLF" filter as shown in the example below (mailutils 2.99.x is assumed):
char *p
crlf_unfold (char *text)
{
mu_stream_t flt;
mu_stream_t input;
size_t len;
char *p = malloc (strlen (text)+1);
mu_static_memory_stream_create (&input, text, strlen (text));
mu_filter_create (&flt, input, "CRLF", MU_FILTER_DECODE, MU_STREAM_READ);
mu_stream_unref (input);
mu_stream_read (flt, p, sizeof (p), &len);
p[len] = 0;
int rc = mu_string_unfold (p, &len);
mu_stream_destroy (&flt);
if (rc)
{
free (p);
p = NULL;
}
return p;
}
For more info on CRLF filter, refer to http://mailutils.org/wiki/CRLF_%28filter%29
|