summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-16 16:58:18 -0400
committerJune McEnroe <june@causal.agency>2020-04-16 16:58:18 -0400
commitcc28798aa7aae19b74f1892a2c29ffe4fe1cd88c (patch)
tree91d8196ea42aa41b0c8254d27f8127e047dff396
parentParse encoded-word and convert charsets (diff)
downloadbubger-cc28798aa7aae19b74f1892a2c29ffe4fe1cd88c.tar.gz
bubger-cc28798aa7aae19b74f1892a2c29ffe4fe1cd88c.zip
Decode Q encoding
-rw-r--r--decode.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/decode.c b/decode.c
index 654cf22..1645a66 100644
--- a/decode.c
+++ b/decode.c
@@ -85,11 +85,30 @@ static void convertCharset(
 	iconv_close(conv);
 }
 
+static void decodeQ(struct Buffer *dst, const char *src, size_t len) {
+	while (len) {
+		if (*src == '=') {
+			if (len < 3) break;
+			*bufferDest(dst, 1) = strtoul(&src[1], NULL, 16);
+			len -= 3;
+			src += 3;
+		} else {
+			*bufferDest(dst, 1) = (*src == '_' ? ' ' : *src);
+			len--;
+			src++;
+		}
+	}
+}
+
 static void decodeEncoding(
 	struct Buffer *dst, const char *encoding, const char *src, size_t len
 ) {
-	// TODO
-	bufferCopy(dst, src, len);
+	if (!strcasecmp(encoding, "Q")) {
+		decodeQ(dst, src, len);
+	} else {
+		// TODO
+		bufferCopy(dst, src, len);
+	}
 }
 
 static void decode(