summary refs log tree commit diff
path: root/decode.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--decode.c14
1 files changed, 2 insertions, 12 deletions
diff --git a/decode.c b/decode.c
index 35e6dfd..2604f73 100644
--- a/decode.c
+++ b/decode.c
@@ -244,25 +244,15 @@ char *decodeHeader(const char *header) {
 	return bufferString(&buf);
 }
 
-static const char *partCharset(const struct BodyPart *part) {
-	const char *charset = NULL;
-	for (size_t i = 0; i + 1 < part->params.len; i += 2) {
-		const char *key = dataCheck(part->params.ptr[i], String).string;
-		if (strcasecmp(key, "charset")) continue;
-		charset = dataCheck(part->params.ptr[i + 1], String).string;
-	}
-	return charset;
-}
-
 char *decodeToString(const struct BodyPart *part, const char *src) {
 	struct Buffer dst = bufferAlloc(strlen(src) + 1);
-	decode(&dst, part->encoding, partCharset(part), src);
+	decode(&dst, part->encoding, paramGet(part->params, "charset"), src);
 	return bufferString(&dst);
 }
 
 int decodeToFile(FILE *file, const struct BodyPart *part, const char *src) {
 	struct Buffer dst = bufferAlloc(strlen(src));
-	decode(&dst, part->encoding, partCharset(part), src);
+	decode(&dst, part->encoding, paramGet(part->params, "charset"), src);
 	size_t n = fwrite(dst.ptr, dst.len, 1, file);
 	free(dst.ptr);
 	return (n ? 0 : -1);