From d687378b628d037ef9e7ac6c57bd28462bafdea5 Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Wed, 13 Jul 2016 18:00:09 +0200 Subject: blaze822: give in and actually unfold the lines --- blaze822.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'blaze822.c') diff --git a/blaze822.c b/blaze822.c index 1e44bb3..db56d03 100644 --- a/blaze822.c +++ b/blaze822.c @@ -225,13 +225,16 @@ static void unfold_hdr(char *buf, char *end) { char *s = buf; + *end = 0; while (s < end && *s != ':') { *s = lc(*s); s++; } + /// XXX can we turn both loops into one? for (; s < end; s++) { + /// XXX use strchr here if (*s == 0) // sanitize nul bytes in headers *s = ' '; @@ -243,18 +246,9 @@ unfold_hdr(char *buf, char *end) } } - if (iswsp(*s)) { - // change prior \n to spaces - int j; - for (j = 1; s - j >= buf && *(s-j) == '\n'; j++) - *(s-j) = ' '; - } - if (*s == '\n') { s++; - if (iswsp(*s)) { - *(s-1) = ' '; - } else { + if (!iswsp(*s)) { *(s-1) = 0; if (s-2 > buf && *(s-2) == '\n') // ex-crlf *(s-2) = 0; @@ -265,6 +259,24 @@ unfold_hdr(char *buf, char *end) } } } + + for (s = buf; s < end; ) { + char *t, *h; + size_t l = strlen(s) + 1; + + if ((t = h = strchr(s, '\n'))) { + while (*h) { + if (*h == '\n') { + *t++ = ' '; + while (*h && isfws(*h)) + h++; + } + *t++ = *h++; + } + *t = 0; + } + s += l; + } } struct message * -- cgit 1.4.1