about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-14 16:43:10 -0400
committerJune McEnroe <june@causal.agency>2020-04-14 16:43:10 -0400
commitb948fb3edca6f60efc8da77ff672760acad7e3e3 (patch)
tree909a7582ddc330d703df2ba70cae6588cd8a8c81
parentBuild a list of body parts parallel to structure (diff)
downloadbubger-b948fb3edca6f60efc8da77ff672760acad7e3e3.tar.gz
bubger-b948fb3edca6f60efc8da77ff672760acad7e3e3.zip
Add bodyPartType helper
-rw-r--r--archive.h8
-rw-r--r--parse.c6
2 files changed, 11 insertions, 3 deletions
diff --git a/archive.h b/archive.h
index 911b7e4..c48d8e3 100644
--- a/archive.h
+++ b/archive.h
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <strings.h>
 #include <time.h>
 
 #include "imap.h"
@@ -100,6 +101,13 @@ struct BodyPart {
 	struct List location;
 };
 
+static inline bool bodyPartType(
+	const struct BodyPart *part, const char *type, const char *subtype
+) {
+	const char *partType = (part->multipart ? "multipart" : part->type);
+	return !strcasecmp(partType, type) && !strcasecmp(part->subtype, subtype);
+}
+
 static inline void bodyPartFree(struct BodyPart part) {
 	if (part.multipart) {
 		for (size_t i = 0; i < part.parts.len; ++i) {
diff --git a/parse.c b/parse.c
index d491e53..5c4eba0 100644
--- a/parse.c
+++ b/parse.c
@@ -18,6 +18,7 @@
 #include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <strings.h>
 #include <sysexits.h>
 
 #include "archive.h"
@@ -63,7 +64,6 @@ void parseEnvelope(struct Envelope *envelope, struct List list) {
 	if (list.len < EnvelopeLen) {
 		errx(EX_PROTOCOL, "missing envelope structure fields");
 	}
-
 	
 	struct tm time;
 	const char *date = dataCheck(list.ptr[Date], String).string;
@@ -142,7 +142,7 @@ static void parseNonMultipart(struct BodyPart *part, struct List list) {
 	list.len -= BasicLen;
 	list.ptr += BasicLen;
 
-	if (!strcmp(part->type, "MESSAGE") && !strcmp(part->subtype, "RFC822")) {
+	if (bodyPartType(part, "message", "rfc822")) {
 		enum { Envelope, BodyStructure, Lines, MessageLen };
 		if (list.len < MessageLen) {
 			errx(EX_PROTOCOL, "missing body part message fields");
@@ -167,7 +167,7 @@ static void parseNonMultipart(struct BodyPart *part, struct List list) {
 		list.ptr += MessageLen;
 	}
 
-	if (!strcmp(part->type, "TEXT")) {
+	if (!strcasecmp(part->type, "text")) {
 		if (!list.len) errx(EX_PROTOCOL, "missing body part text lines");
 		part->text.lines = dataCheck(list.ptr[0], Number).number;
 		list.len--;