about summary refs log tree commit diff
path: root/export.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-20 11:27:27 -0400
committerJune McEnroe <june@causal.agency>2020-04-20 11:27:27 -0400
commitb3b0956b7ea43fcc88528727e7ed57c0278e1c19 (patch)
tree725ebedabd48c28918e3fb6b1763a1025d2d5847 /export.c
parentUse template system for paths and URLs (diff)
downloadbubger-b3b0956b7ea43fcc88528727e7ed57c0278e1c19.tar.gz
bubger-b3b0956b7ea43fcc88528727e7ed57c0278e1c19.zip
Put attachments inside <ul>
Diffstat (limited to 'export.c')
-rw-r--r--export.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/export.c b/export.c
index 873870c..799bd7c 100644
--- a/export.c
+++ b/export.c
@@ -103,6 +103,11 @@ static bool isInline(const struct BodyPart *part) {
 	return !strcasecmp(part->disposition.type, "inline");
 }
 
+static bool isAttachment(const struct BodyPart *part) {
+	if (isInline(part)) return false;
+	return !part->multipart && !part->message.structure;
+}
+
 static void exportAtom(
 	uint32_t uid, const struct Envelope *envelope,
 	const struct BodyPart *structure, struct Data body
@@ -202,10 +207,21 @@ static int exportHTMLBody(
 		);
 
 	} else if (part->multipart) {
+		int error;
+		bool attached = false;
 		for (size_t i = 0; i < part->parts.len; ++i) {
+			if (!attached && isAttachment(&part->parts.ptr[i])) {
+				attached = true;
+				error = htmlAttachmentOpen(file);
+				if (error) return error;
+			} else if (attached && !isAttachment(&part->parts.ptr[i])) {
+				attached = false;
+				error = htmlAttachmentClose(file);
+				if (error) return error;
+			}
 			struct Data num = { .type = Number, .number = 1 + i };
 			listPush(section, num);
-			int error = exportHTMLBody(
+			error = exportHTMLBody(
 				file, envelope, section,
 				&part->parts.ptr[i], dataCheck(body, List).list.ptr[i]
 			);