summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--archive.h2
-rw-r--r--export.c18
-rw-r--r--html.c10
3 files changed, 28 insertions, 2 deletions
diff --git a/archive.h b/archive.h
index 532ef47..03ee4f2 100644
--- a/archive.h
+++ b/archive.h
@@ -194,9 +194,11 @@ int atomFeedClose(FILE *file);
 extern const char *htmlTitle;
 int htmlMessageOpen(FILE *file, const struct Envelope *envelope);
 int htmlInline(FILE *file, const struct BodyPart *part, const char *content);
+int htmlAttachmentOpen(FILE *file);
 int htmlAttachment(
 	FILE *file, const struct BodyPart *part, const struct Variable pathVars[]
 );
+int htmlAttachmentClose(FILE *file);
 int htmlMessageClose(FILE *file);
 int htmlThreadHead(FILE *file, const struct Envelope *envelope);
 int htmlThreadOpen(FILE *file, const struct Envelope *envelope);
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]
 			);
diff --git a/html.c b/html.c
index 403caef..b0e00c2 100644
--- a/html.c
+++ b/html.c
@@ -165,11 +165,15 @@ int htmlInline(FILE *file, const struct BodyPart *part, const char *content) {
 	return templateRender(file, template, vars, escapeXML);
 }
 
+int htmlAttachmentOpen(FILE *file) {
+	return templateRender(file, TEMPLATE(<ul class="attachment">), NULL, NULL);
+}
+
 int htmlAttachment(
 	FILE *file, const struct BodyPart *part, const struct Variable *path
 ) {
 	const char *template = TEMPLATE(
-		<a class="attachment" href="[url]">[name][type][/][subtype]</a>
+		<li><a href="[url]">[name][type][/][subtype]</a></li>
 	);
 	char *url = templateURL("../" PATH_ATTACHMENT, path);
 	const char *name = paramGet(part->disposition.params, "filename");
@@ -186,6 +190,10 @@ int htmlAttachment(
 	return error;
 }
 
+int htmlAttachmentClose(FILE *file) {
+	return templateRender(file, TEMPLATE(</ul>), NULL, NULL);
+}
+
 int htmlMessageClose(FILE *file) {
 	return templateRender(file, TEMPLATE(</article>), NULL, NULL);
 }