about summary refs log tree commit diff
path: root/blaze822.c
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-07-13 18:00:09 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-07-13 18:00:09 +0200
commitd687378b628d037ef9e7ac6c57bd28462bafdea5 (patch)
tree3acb1e3e28b7860f1f85c7734d2887fd7fece8ea /blaze822.c
parent91e83c5ee8ebea7034e9306f670af68a0115e25a (diff)
downloadmblaze-d687378b628d037ef9e7ac6c57bd28462bafdea5.tar.gz
mblaze-d687378b628d037ef9e7ac6c57bd28462bafdea5.tar.xz
mblaze-d687378b628d037ef9e7ac6c57bd28462bafdea5.zip
blaze822: give in and actually unfold the lines
Diffstat (limited to 'blaze822.c')
-rw-r--r--blaze822.c32
1 files changed, 22 insertions, 10 deletions
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 *