summary refs log tree commit diff
path: root/export.c
diff options
context:
space:
mode:
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]
 			);