about summary refs log tree commit diff
path: root/html.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--html.c47
1 files changed, 37 insertions, 10 deletions
diff --git a/html.c b/html.c
index 9067450..85b6f6b 100644
--- a/html.c
+++ b/html.c
@@ -28,17 +28,19 @@ static const char *Mailto = {
 	"mailto:[mailbox]@[host]?subject=[re][subject]&In-Reply-To=[messageID]"
 };
 
-static const char *Envelope = TEMPLATE(
-	<details id="[messageID]">
+static const char *Summary = TEMPLATE(
+	<details class="message" id="[messageID]">
 	<summary>
-		<h1><a href="#[messageID]">[subject]</a></h1>
-		<address>
-			<a href="[mailto]">[from]</a>
-		</address>
+		<h1 class="subject"><a href="#[messageID]">[subject]</a></h1>
+		<address class="from"><a href="[mailto]">[from]</a></address>
 		<time datetime="[utc]">[date]</time>
 	</summary>
 );
 
+static const char *Address = TEMPLATE(
+	<li><address class="[class]">[name]</address></li>
+);
+
 int htmlEnvelope(FILE *file, const struct Envelope *envelope) {
 	struct Variable mailtoVars[] = {
 		{ "mailbox", envelope->replyTo.mailbox },
@@ -73,7 +75,7 @@ int htmlEnvelope(FILE *file, const struct Envelope *envelope) {
 	char date[256];
 	strftime(date, sizeof(date), "%c %z", &envelope->date);
 
-	struct Variable vars[] = {
+	struct Variable summaryVars[] = {
 		{ "messageID", envelope->messageID },
 		{ "subject", envelope->subject },
 		{ "mailto", mailto },
@@ -82,8 +84,33 @@ int htmlEnvelope(FILE *file, const struct Envelope *envelope) {
 		{ "date", date },
 		{0},
 	};
-	error = templateRender(file, Envelope, vars, escapeXML);
-
+	error = templateRender(file, Summary, summaryVars, escapeXML);
 	free(mailto);
-	return error;
+	if (error) return error;
+
+	if (0 > fprintf(file, "<dl><dt>To:</dt><dd><ul>")) return -1;
+	for (size_t i = 0; i < envelope->to.len; ++i) {
+		struct Address addr = envelope->to.addrs[i];
+		struct Variable vars[] = {
+			{ "class", "to" },
+			{ "name", (addr.name ? addr.name : addr.mailbox) },
+			{0},
+		};
+		error = templateRender(file, Address, vars, escapeXML);
+		if (error) return error;
+	}
+	if (0 > fprintf(file, "</ul></dd><dt>Cc:</dt><dd><ul>")) return -1;
+	for (size_t i = 0; i < envelope->cc.len; ++i) {
+		struct Address addr = envelope->cc.addrs[i];
+		struct Variable vars[] = {
+			{ "class", "cc" },
+			{ "name", (addr.name ? addr.name : addr.mailbox) },
+			{0},
+		};
+		error = templateRender(file, Address, vars, escapeXML);
+		if (error) return error;
+	}
+	if (0 > fprintf(file, "</ul></dd></dl>")) return -1;
+
+	return 0;
 }