about summary refs log tree commit diff
path: root/html.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--html.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/html.c b/html.c
index 9e37db8..2d24ce2 100644
--- a/html.c
+++ b/html.c
@@ -164,6 +164,33 @@ int htmlInline(FILE *file, const struct BodyPart *part, const char *content) {
 	return templateRender(file, template, vars, escapeXML);
 }
 
+static char *htmlAttachmentURL(const struct Attachment *attach) {
+	struct Variable vars[] = {
+		{ "path0", attach->path[0] },
+		{ "path1", attach->path[1] },
+		{ "path2", attach->path[2] },
+		{0},
+	};
+	return templateURL("../attachment/[path0]/[path1]/[path2]", vars);
+}
+
+int htmlAttachment(
+	FILE *file, const struct BodyPart *part, const struct Attachment *attach
+) {
+	const char *template = TEMPLATE(
+		<a class="attachment" href="[url]">[name]</a>
+	);
+	char *url = htmlAttachmentURL(attach);
+	struct Variable vars[] = {
+		{ "url", url },
+		{ "name", attach->path[2] }, // FIXME: Show intended name or type.
+		{0},
+	};
+	int error = templateRender(file, template, vars, escapeXML);
+	free(url);
+	return error;
+}
+
 int htmlMessageClose(FILE *file) {
 	return templateRender(file, TEMPLATE(</article>), NULL, NULL);
 }