about summary refs log tree commit diff
path: root/html.c
diff options
context:
space:
mode:
Diffstat (limited to 'html.c')
-rw-r--r--html.c60
1 files changed, 31 insertions, 29 deletions
diff --git a/html.c b/html.c
index 2d24ce2..403caef 100644
--- a/html.c
+++ b/html.c
@@ -94,10 +94,11 @@ static char *htmlFragment(const struct Envelope *envelope) {
 
 static char *htmlMbox(const struct Envelope *envelope) {
 	struct Variable vars[] = {
-		{ "name", pathSafe(envelope->messageID) },
+		{ "messageID", envelope->messageID },
+		{ "type", "mbox" },
 		{0},
 	};
-	return templateURL("../message/[name].mbox", vars);
+	return templateURL("../" PATH_MESSAGE, vars);
 }
 
 int htmlMessageOpen(FILE *file, const struct Envelope *envelope) {
@@ -164,26 +165,20 @@ 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
+	FILE *file, const struct BodyPart *part, const struct Variable *path
 ) {
 	const char *template = TEMPLATE(
-		<a class="attachment" href="[url]">[name]</a>
+		<a class="attachment" href="[url]">[name][type][/][subtype]</a>
 	);
-	char *url = htmlAttachmentURL(attach);
+	char *url = templateURL("../" PATH_ATTACHMENT, path);
+	const char *name = paramGet(part->disposition.params, "filename");
 	struct Variable vars[] = {
 		{ "url", url },
-		{ "name", attach->path[2] }, // FIXME: Show intended name or type.
+		{ "name", (name ? name : "") },
+		{ "type", (name ? "" : part->type) },
+		{ "/", (name ? "" : "/") },
+		{ "subtype", (name ? "" : part->subtype) },
 		{0},
 	};
 	int error = templateRender(file, template, vars, escapeXML);
@@ -197,12 +192,13 @@ int htmlMessageClose(FILE *file) {
 
 const char *htmlTitle;
 
-static char *htmlThreadURL(const struct Envelope *envelope) {
+static char *htmlThreadURL(const struct Envelope *envelope, const char *type) {
 	struct Variable vars[] = {
-		{ "name", pathSafe(envelope->messageID) },
+		{ "messageID", envelope->messageID },
+		{ "type", type },
 		{0},
 	};
-	return templateURL("[name]", vars);
+	return templateURL("../" PATH_THREAD, vars);
 }
 
 int htmlThreadHead(FILE *file, const struct Envelope *envelope) {
@@ -210,18 +206,21 @@ int htmlThreadHead(FILE *file, const struct Envelope *envelope) {
 		<!DOCTYPE html>
 		<meta charset="utf-8">
 		<title>[subject] &middot; [title]</title>
-		<link rel="alternate" type="application/atom+xml" href="[url].atom">
-		<link rel="alternate" type="application/mbox" href="[url].mbox">
+		<link rel="alternate" type="application/atom+xml" href="[atom]">
+		<link rel="alternate" type="application/mbox" href="[mbox]">
 	);
-	char *url = htmlThreadURL(envelope);
+	char *atom = htmlThreadURL(envelope, "atom");
+	char *mbox = htmlThreadURL(envelope, "mbox");
 	struct Variable vars[] = {
 		{ "subject", envelope->subject },
 		{ "title", htmlTitle },
-		{ "url", url },
+		{ "atom", atom },
+		{ "mbox", mbox },
 		{0},
 	};
 	int error = templateRender(file, template, vars, escapeXML);
-	free(url);
+	free(atom);
+	free(mbox);
 	return error;
 }
 
@@ -231,21 +230,24 @@ int htmlThreadOpen(FILE *file, const struct Envelope *envelope) {
 			<h1>[subject]</h1>
 			<nav>
 				<ul>
-					<li><a href="[url].atom">follow</a></li>
-					<li><a href="[url].mbox">download</a></li>
+					<li><a href="[atom]">follow</a></li>
+					<li><a href="[mbox]">download</a></li>
 				</ul>
 			</nav>
 		</header>
 		<main class="thread">
 	);
-	char *url = htmlThreadURL(envelope);
+	char *atom = htmlThreadURL(envelope, "atom");
+	char *mbox = htmlThreadURL(envelope, "mbox");
 	struct Variable vars[] = {
 		{ "subject", envelope->subject },
-		{ "url", url },
+		{ "atom", atom },
+		{ "mbox", mbox },
 		{0},
 	};
 	int error = templateRender(file, template, vars, escapeXML);
-	free(url);
+	free(atom);
+	free(mbox);
 	return error;
 }