about summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--decode.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/decode.c b/decode.c
index d158c5d..0dbed27 100644
--- a/decode.c
+++ b/decode.c
@@ -28,6 +28,7 @@
 #include <err.h>
 #include <errno.h>
 #include <iconv.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -243,13 +244,20 @@ static void decodeWord(struct Buffer *dst, const char *src, size_t len) {
 
 char *decodeHeader(const char *header) {
 	struct Buffer buf = bufferAlloc(strlen(header) + 1);
+	bool pair = false;
 	while (*header) {
-		size_t len = strcspn(header, " ");
-		if (!strncmp(header, "=?", 2)) {
+		size_t len = strcspn(header, " \t");
+		if (!len) {
+			len = strspn(header, " \t");
+			if (!pair || strncmp(&header[len], "=?", 2)) {
+				bufferCopy(&buf, header, len);
+			}
+		} else if (!strncmp(header, "=?", 2)) {
 			decodeWord(&buf, header, len);
+			pair = true;
 		} else {
-			if (header[len]) len++;
 			bufferCopy(&buf, header, len);
+			pair = false;
 		}
 		header += len;
 	}