summary refs log tree commit diff
path: root/html.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-21 12:18:25 -0400
committerJune McEnroe <june@causal.agency>2020-04-21 12:18:25 -0400
commit3b0ea6d60f1d22802301b4db7fc67813563c5276 (patch)
tree20af419fc261efdedd90bbf1a9dac609570128c4 /html.c
parentPut attachments inside <ul> (diff)
downloadbubger-3b0ea6d60f1d22802301b4db7fc67813563c5276.tar.gz
bubger-3b0ea6d60f1d22802301b4db7fc67813563c5276.zip
Add parent links to message nav
Diffstat (limited to '')
-rw-r--r--html.c49
1 files changed, 36 insertions, 13 deletions
diff --git a/html.c b/html.c
index b0e00c2..62376d5 100644
--- a/html.c
+++ b/html.c
@@ -84,23 +84,53 @@ static char *htmlMailto(const struct Envelope *envelope) {
 	return templateURL(template, vars);
 }
 
-static char *htmlFragment(const struct Envelope *envelope) {
+static char *htmlFragment(const char *messageID) {
 	struct Variable vars[] = {
-		{ "messageID", envelope->messageID },
+		{ "messageID", messageID },
 		{0},
 	};
 	return templateURL("#[messageID]", vars);
 }
 
-static char *htmlMbox(const struct Envelope *envelope) {
+static char *htmlMbox(const char *messageID) {
 	struct Variable vars[] = {
-		{ "messageID", envelope->messageID },
+		{ "messageID", messageID },
 		{ "type", "mbox" },
 		{0},
 	};
 	return templateURL("../" PATH_MESSAGE, vars);
 }
 
+int htmlMessageNav(FILE *file, const struct Envelope *envelope) {
+	int error = templateRender(file, TEMPLATE(<nav><ul>), NULL, NULL);
+	if (error) return error;
+	if (envelope->inReplyTo) {
+		const char *template = TEMPLATE(
+			<li><a href="[fragment]">parent</a></li>
+		);
+		char *fragment = htmlFragment(envelope->inReplyTo);
+		struct Variable vars[] = {
+			{ "fragment", fragment },
+			{0},
+		};
+		error = templateRender(file, template, vars, escapeXML);
+		free(fragment);
+		if (error) return error;
+	}
+	const char *template = TEMPLATE(
+		<li><a href="[mbox]">download</a></li>
+	);
+	char *mbox = htmlMbox(envelope->messageID);
+	struct Variable vars[] = {
+		{ "mbox", mbox },
+		{0},
+	};
+	error = templateRender(file, template, vars, escapeXML);
+	free(mbox);
+	if (error) return error;
+	return templateRender(file, TEMPLATE(</ul></nav>), NULL, NULL);
+}
+
 int htmlMessageOpen(FILE *file, const struct Envelope *envelope) {
 	// TODO: Conditionally include mailto: link.
 	const char *template = TEMPLATE(
@@ -111,15 +141,9 @@ int htmlMessageOpen(FILE *file, const struct Envelope *envelope) {
 				<a href="[mailto]">[from]</a>
 			</address>
 			<time datetime="[utc]">[date]</time>
-			<nav>
-				<ul>
-					<li><a href="[mbox]">download</a></li>
-				</ul>
-			</nav>
 	);
-	char *fragment = htmlFragment(envelope);
+	char *fragment = htmlFragment(envelope->messageID);
 	char *mailto = htmlMailto(envelope);
-	char *mbox = htmlMbox(envelope);
 	char utc[sizeof("0000-00-00T00:00:00Z")];
 	strftime(utc, sizeof(utc), "%FT%TZ", gmtime(&envelope->time));
 	struct Variable vars[] = {
@@ -130,17 +154,16 @@ int htmlMessageOpen(FILE *file, const struct Envelope *envelope) {
 		{ "from", addressName(envelope->from) },
 		{ "utc", utc },
 		{ "date", envelope->date },
-		{ "mbox", mbox },
 		{0},
 	};
 	int error = 0
 		|| templateRender(file, template, vars, escapeXML)
+		|| htmlMessageNav(file, envelope)
 		|| htmlAddressList(file, "to", envelope->to)
 		|| htmlAddressList(file, "cc", envelope->cc)
 		|| templateRender(file, TEMPLATE(</header>), NULL, NULL);
 	free(mailto);
 	free(fragment);
-	free(mbox);
 	return error;
 }